yingzi 2 rokov pred
rodič
commit
55b1263c4e

+ 1 - 1
app/api/controller/User.php

@@ -112,7 +112,7 @@ class User extends BaseController
         $post["pageSize"]  = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
         $post["pageSize"]  = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
         $post["page"]      = $post["page"]<=0     ? 1  : (int)$post["page"];
         $post["page"]      = $post["page"]<=0     ? 1  : (int)$post["page"];
         $post["parent_uid"]= $request->user["uid"];
         $post["parent_uid"]= $request->user["uid"];
-        $data = (new UserModel)->getDataList($post,"uid,mobile,nickname");
+        $data = (new UserModel)->getDataList($post,"u.uid,u.mobile,u.nickname");
         return app('json')->success($data);
         return app('json')->success($data);
     }
     }
     
     

+ 42 - 12
app/model/api/User.php

@@ -258,33 +258,55 @@ class User extends BaseModel
      * @param type $field
      * @param type $field
      * @return type
      * @return type
      */
      */
-    public function getDataList($post,$field="*"){
+    public function getDataList($post,$field="*",$is_admin=0){
         $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
         $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
         $post["page"]     = $post["page"]<=0     ? 1  : (int)$post["page"];
         $post["page"]     = $post["page"]<=0     ? 1  : (int)$post["page"];
         $where=[];
         $where=[];
-        if(isset($post["status"]) && in_array((string)$post["status"], ["0","1"])){
-            $where[]=["status","=",(int)$post["status"]];
+        //用户uid
+        if(!empty($post['uid'])){
+            $where[]=["u.uid","=",$post['uid']];
         }
         }
-        
+        //状态
+        if(isset($post["status"]) && in_array((string)$post["status"], ["0","1","-1"])){
+            $where[]=["u.status","=",(int)$post["status"]];
+        }
+        //昵称
         if(!empty($post["nickname"])){
         if(!empty($post["nickname"])){
-            $where[]=["nickname","like","%{$post["nickname"]}%"];
+            $where[]=["u.nickname","like","%{$post["nickname"]}%"];
         }
         }
-        
+        //手机号码
         if(!empty($post["mobile"])){
         if(!empty($post["mobile"])){
-            $where[]=["mobile","=",$post["mobile"]];
+            $where[]=["u.mobile","=",$post["mobile"]];
         }
         }
-        
+        //父级uid
         if(!empty($post["parent_uid"])){
         if(!empty($post["parent_uid"])){
-            $where[]=["parent_uid","=",$post["parent_uid"]];
+            $where[]=["u.parent_uid","=",$post["parent_uid"]];
+        }
+        //注册时间
+        if(!empty($post['time']) && !empty($post['time'][0]) && !empty($post['time'][1])) {
+            $startTime = strtotime($post['time'][0]);
+            $endTime = strtotime($post['time'][1]);
+            $where[]=["u.regtime","between","{$startTime},{$endTime}"];
+        }
+        if($is_admin=1){
+            $field = "u.*"
+                    . ",p.nickname as p_nickname,p.mobile as p_mobile"
+                    . ",wt.title as work_type_title"
+                    . ",(select count(*) from table_user_show_template where uid = u.uid) as showTempCount"
+                    . ",(select count(*) from table_info_audit where uid = u.uid and status = 1) as is_info_audit"
+                    . ",(select count(*) from table_type_audit where uid = u.uid and status = 1) as is_type_audit"
+                    . ",(select count(*) from table_user where parent_uid = u.uid) as branchCount";
         }
         }
-        
-        $totalCount = $this->where($where)->count();
+        $totalCount = $this->alias("u")->where($where)->count();
         $data=null;
         $data=null;
         if($totalCount>0){
         if($totalCount>0){
             $data = $this
             $data = $this
+                ->alias("u")
                 ->field($field)
                 ->field($field)
+                ->leftJoin("user p","p.uid = u.parent_uid")
+                ->leftJoin("user_work_type wt", "wt.id  = u.work_type_id")//职称
                 ->where($where)
                 ->where($where)
-                ->order("uid", "desc")
+                ->order("u.uid", "desc")
                 ->page($post["page"], $post["pageSize"])
                 ->page($post["page"], $post["pageSize"])
                 ->select();
                 ->select();
             if(!empty($data)){
             if(!empty($data)){
@@ -292,6 +314,14 @@ class User extends BaseModel
             }
             }
         }
         }
         $data = empty($data)?[]:$data;
         $data = empty($data)?[]:$data;
+        foreach($data as $k=>$v){
+            if(!empty($v["regtime"])){
+                $data[$k]["regtime"]  = date("Y-m-d H:i:s",$v["regtime"]);
+            }
+            if(!empty($v["parent_time"])){
+                $data[$k]["parent_time"]  = date("Y-m-d H:i:s",$v["parent_time"]);
+            }
+        }
         return ["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount];
         return ["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount];
     }
     }
     
     

+ 6 - 53
app/system/controller/Member.php

@@ -36,6 +36,7 @@ class Member extends BaseController
         $pageSize = 50;
         $pageSize = 50;
         $post =  UtilService::getMore([
         $post =  UtilService::getMore([
             ['page',1],
             ['page',1],
+            ['pageSize',50],
             ['nickname',''],
             ['nickname',''],
             ['uid',''],
             ['uid',''],
             ['parent_uid',''],
             ['parent_uid',''],
@@ -43,60 +44,12 @@ class Member extends BaseController
             ['status',''],
             ['status',''],
             ['time',[]],
             ['time',[]],
         ],$request);
         ],$request);
-        $where = [];
-        //创建时间
-        $startTime="";
-        $endTime="";
-        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
-            $startTime = strtotime($post['time'][0]);
-            $endTime = strtotime($post['time'][1]);
-            $where[]=["u.regtime","between","{$startTime},{$endTime}"];
-        }
-        if(!empty($post['nickname'])){
-            $where[]=["u.nickname","like","%{$post['nickname']}%"];
-        }
-        if(!empty($post['uid'])){
-            $where[]=["u.uid","=",$post['uid']];
-        }
-        if(!empty($post['mobile'])){
-            $where[]=["u.mobile","=",$post['mobile']];
-        }
-
-        if(!empty($post['parent_uid'])){
-            $where[]=["u.parent_uid","=",$post['parent_uid']];
-        }
-        if(in_array((string)$post["status"],['1','0','-1'])){
-            $where[]=["u.status","=",(int)$post["status"]];
-        }
-        $data = (new UserModel)
-                ->field("u.uid,u.nickname,u.name,u.regtime,u.score,u.money,u.status,u.avatar,u.mobile,u.parent_uid,u.work_type_id"
-                        . ",p.nickname as p_nickname,p.mobile as p_mobile"
-                        . ",wt.title as work_type_title"
-                        . ",(select count(*) from table_user_show_template where uid = u.uid) as showTempCount"
-                        . ",(select count(*) from table_info_audit where uid = u.uid and status = 1) as is_info_audit"
-                        . ",(select count(*) from table_type_audit where uid = u.uid and status = 1) as is_type_audit"
-                        . ",(select count(*) from table_user where parent_uid = u.uid) as branchCount")
-                ->alias("u")
-                ->leftJoin("user p","p.uid = u.parent_uid")
-                ->leftJoin("user_work_type wt", "wt.id  = u.work_type_id")//职称
-                ->where($where)
-                ->page((int)$post["page"], (int)$pageSize)
-                ->order("u.uid","desc")
-                ->select()
-                ->toArray();
-        $pageCount = (new UserModel)->alias("u")->where($where)->count();
-        $data = empty($data)?[]:$data;
-        foreach($data as $k=>$v){
-            $data[$k]["regtime"]  = date("Y-m-d H:i:s",$v["regtime"]);
-            $data[$k]["mobile"]   = empty($v["mobile"])  ?"未绑定":$v["mobile"];
-            $data[$k]["p_mobile"] = empty($v["p_mobile"])?"未绑定":$v["p_mobile"];
-            
-        }
+        $data = (new UserModel)->getDataList($post,"*",1);
         return app('json')->success([
         return app('json')->success([
-            'list'      => $data,
-            'pageCount' => $pageCount,
-            'pageSize'  => $pageSize,
-            'page'      => $post["page"],
+            'list'      => $data["list"],
+            'pageCount' => $data["totalCount"],
+            'pageSize'  => $data["pageSize"],
+            'page'      => $data["page"],
         ]);
         ]);
     }
     }