123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace app\admin\controller;
- use app\BaseController;
- use think\App;
- use think\facade\Db;
- //订单用途
- class Orderuse extends BaseController
- {
- public $post="";
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post=$this->request->post();
- }
- public function create(){
- $order_use = isset($this->post['order_use']) && $this->post['order_use']!=="" ? trim($this->post['order_use']):"";
- if($order_use==""){
- return error_show(1002,"参数order_use不能为空");
- }
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(1005,"参数token不能为空");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(1002,"创建人数据不存在");
- }
- $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"0";
- $data =[
- "order_use"=>$order_use,
- "creater"=>$creater,
- "createrid"=>$createrid,
- "status"=>0,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $datainfo = Db::name('order_use')->insert($data);
- if($datainfo){
- return error_show(0,"新建成功");
- }else{
- return error_show(1002,"新建失败");
- }
- }
- public function list(){
- $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
- $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
- $where =[['ou.is_del',"=",0]];
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
- if($status !==""){
- $where [] = ['ou.status',"=",$status];
- }
- $order_use = isset($this->post['order_use']) && $this->post['order_use'] !=="" ? trim($this->post['order_use']):"";
- if($order_use !==""){
- $where [] =['ou.order_use',"like","%$order_use%"];
- }
- $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
- if($creater !==""){
- $where [] =['ou.creater',"like","%$creater%"];
- }
- $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
- if($start!==""){
- $where[]=['ou.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
- }
- $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
- if($end!==""){
- $where[]=['ou.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
- }
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
- if ($company_name !== "") $where[] = ["ou.createrid", 'in', get_company_item_user_by_name($company_name)];
- $count = Db::name('order_use')
- ->alias('ou')
- ->where($where)
- ->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total :$page;
- $list = Db::name('order_use')
- ->alias('ou')
- ->field('ou.*,u.itemid')
- ->leftJoin("depart_user u", "u.uid=ou.createrid AND u.is_del=0")
- ->where($where)
- ->page($page, $size)
- ->append(['company_name'])
- ->withAttr('company_name', function ($val, $data) {
- return implode('/', array_column(GetPart($data['itemid']), 'name'));
- })
- ->order("addtime desc")
- ->select()
- ->toArray();
- return app_show(0, "获取成功", ["list" => $list, "count" => $count]);
- }
- public function edit(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- $info =Db::name('order_use')->where(['id'=>$id,'is_del'=>0])->find();
- if($info==""){
- return error_show(1004,"未找到数据");
- }
- $order_use = isset($this->post['order_use']) && $this->post['order_use'] !==""? trim($this->post['order_use']):"";
- if ($order_use==""){
- return error_show(1002,"参数order_use不能为空");
- }
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"0";
- $data =[
- "id"=>$id,
- "order_use"=>$order_use,
- "is_del"=>0,
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $datainfo = Db::name("order_use")->save($data);
- if($datainfo){
- return error_show(0,"编辑成功");
- }else{
- return error_show(1002,"编辑失败");
- }
- }
- public function dele(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- $info = Db::name('order_use')->where(['id'=>$id,'is_del'=>0])->find();
- if(empty($info)){
- return error_show(1004,"未找到数据");
- }
- $item = Db::name('order_use')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("y-m-d H:i:s")]);
- if($item){
- return error_show(0,"删除成功");
- }else{
- return error_show(1002,"删除失败");
- }
- }
- public function status(){
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- $info = Db::name("order_use")->where([["id","=",$id],["is_del","=",0]])->find();
- if(!$info){
- return error_show(1002,"未找到对应数据");
- }
- $msg = $info['status']==0? "启用":"禁用";
- $info['status'] = $info['status']==0?1:0;
- $info['updatetime'] =date("Y-m-d H:i:s");
- $in =Db::name("order_use")->save($info);
- if($in){
- return app_show(0,"{$msg}成功");
- }else{
- return error_show(1004,"{$msg}失败");
- }
- }
- public function info(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- $info = Db::name('order_use')->where(['id'=>$id,'is_del'=>0])->find();
- if(empty($info)){
- return error_show(1004,'未找到数据');
- }
- return app_show(0,"获取成功",$info);
- }
- }
|