wupengfei 2 years ago
parent
commit
fc8980e9d7
1 changed files with 29 additions and 23 deletions
  1. 29 23
      application/admin/controller/shopro/order/OrderShift.php

+ 29 - 23
application/admin/controller/shopro/order/OrderShift.php

@@ -43,32 +43,38 @@ class OrderShift extends Base
             if ($this->request->request('keyField')) {
                 return $this->selectpage();
             }
+            $filter = $this->request->get("filter", '');
+            $filter = (array)json_decode($filter, true);
+            $filter = $filter ? $filter : [];
             $limit = $this->request->param('limit',10);
             $off_set = $this->request->param('offset',0);
-            $search_time = $this->request->param('createtime',0);
-            var_dump($limit);
-
-            if($search_time) {
-                $search_time = explode(' - ',$search_time);
-                $total =  $this->model
-                    ->where('create_at','> time',$search_time[0])
-                    ->where('create_at','<=',$search_time[1])
-                    ->count();
-                $list= $this->model
-                    ->with('user')
-                    ->where('create_at','> time',$search_time[0])
-                    ->where('create_at','<=',$search_time[1])
-                    ->order('id desc')
-                    ->limit($off_set,$limit)
-                    ->select();
-            }else{
-                $total =  $this->model->count();
-                $list= $this->model
-                    ->with('user')
-                    ->order('id desc')
-                    ->limit($off_set,$limit)
-                    ->select();
+            $sel_where = [];
+            if(isset($filter['createtime'])) {
+                $search_time = explode(' - ',$filter['createtime']);
+                $sel_where[]=['create_at','> time',$search_time[0]];
+                $sel_where[]=['create_at','< time',$search_time[1]];
             }
+            if(isset($filter['sh_status']))$sel_where[] = ['sh_status','=',$filter['sh_status']];
+            if(isset($filter['user_id']))$sel_where[] = ['user_id','=',$filter['user_id']];
+            $name = $this->model->getQuery()->getTable();
+            $tableName = $name . '.';
+            $userTableName = (new \app\admin\model\User())->getQuery()->getTable();
+            $total =  $this->model->where($sel_where)
+                ->where(function ($query)use ($filter,$tableName,$userTableName){
+                    $query = $query->table($userTableName)->where($userTableName . '.id=' . $tableName . 'user_id');
+                    if (isset($filter['nickname']))$query->where('nickname', 'like', "%{$filter['nickname']}%");
+                    if (isset($filter['user_phone']))$query->where('mobile', 'like', "%{$filter['user_phone']}%");
+                })->count();
+            $list= $this->model->with('user')
+                ->where($sel_where)
+                ->where(function ($query)use ($filter,$tableName,$userTableName){
+                    $query = $query->table($userTableName)->where($userTableName . '.id=' . $tableName . 'user_id');
+                    if (isset($filter['nickname']))$query->where('nickname', 'like', "%{$filter['nickname']}%");
+                    if (isset($filter['user_phone']))$query->where('mobile', 'like', "%{$filter['user_phone']}%");
+                })
+                ->order('id desc')
+                ->limit($off_set,$limit)
+                ->select();
             $result = array("total" => $total, "rows" => $list);
             return $this->success('操作成功', null, $result);
         }