wugg há 2 anos atrás
pai
commit
94ba4bbcef
1 ficheiros alterados com 29 adições e 15 exclusões
  1. 29 15
      app/controller/UserInfo.php

+ 29 - 15
app/controller/UserInfo.php

@@ -26,13 +26,19 @@ class UserInfo extends BaseController
 	 */
 	public function UserList()
     {
-        $post=$this->request->only(["nickname"=>"","username"=>"","status"=>"","uid"=>[],"nuid"=>[],"page"=>1,"size"=>10],"post");
+        $post=$this->request->only(["nickname"=>"","username"=>"","status"=>"","companyNo"=>"","uid"=>[],"nuid"=>[],
+        "page"=>1,"size"=>10],"post");
         $condition = [["a.is_del","=",0]];
         isset($post['nickname'])&& $post['nickname']!="" ? $condition[]=["nickname","like","%{$post['nickname']}%"] : "";
         isset($post['username'])&& $post['username']!="" ? $condition[]=["username","like","%{$post['username']}%"] : "";
         isset($post['status'])&& $post['status']!=="" ? $condition[]=["a.status","=",$post['status']] : "";
         isset($post['uid'])&& $post['uid']!=="" ? $condition[]=["a.id","in",$post['uid']] : "";
         isset($post['nuid'])&& $post['nuid']!=="" ? $condition[]=["a.id","not in",$post['nuid']] : "";
+
+        if ($post['companyNo']!=""){
+        	$uid =Db::name("account_company")->where(["companyCode"=>$post['companyNo'],"is_del"=>0])->column("account_id");
+        	$condition[]=["a.id","in",$uid];
+        }
         $page = isset($post['page'])&& $post['page']!=="" ? intval($post['page']) : 1;
         $size = isset($post['size'])&& $post['size']!=="" ? intval($post['size']) : 10;
         $count = Db::name("account")->alias("a")
@@ -42,20 +48,28 @@ class UserInfo extends BaseController
         $page = $total>=$page? $page:$total;
         $list =  Db::name("account")->alias("a")
 			->leftJoin("user b","a.id=b.account_id and b.status=1")
-			->where($condition)->page($page,$size)
+			->append(['plat', 'company_relaton'])
+            ->withAttr('plat', function ($val, $da) {
+                return Db::name("account_plat")
+                    ->alias("a")
+                    ->leftJoin("platform b", "a.plat_code=b.plat_code and b.is_del=0 and b.status=1")
+                    ->where(["a.status" => 1, "a.is_del" => 0, "a.account_id" => $da['id']])
+                    ->field("a.plat_code,plat_name")
+                    ->select()
+                    ->toArray();
+            })
+            ->withAttr('company_relaton', function ($val, $da) {
+                return Db::name("account_company")
+                    ->where(["account_id" => $da['id'], "is_del" => 0])
+                    ->field("companyCode,companyName,company_type,is_main,status")
+                    ->select()
+                    ->toArray();
+            })
+			->where($condition)->page($page,$size)->order("a.id desc")
 			->field("a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime")
-			->cursor();
-        $data=[];
-        foreach ($list as $item){
-        	$item['plat']= Db::name("account_plat")->alias("a")
-        	->leftJoin("platform b","a.plat_code=b.plat_code and b.is_del=0 and b.status=1")
-        	->where(["a.status"=>1,"a.is_del"=>0,"a.account_id"=>$item['id']])->column("a.plat_code,plat_name");
-        	$item['company_relaton'] = Db::name("account_company")->where(["account_id"=>$item['id'],"is_del"=>0,"status"=>1])
-				->column("companyCode,companyName,company_type,is_main,status");
-        	$data[]=$item;
-        }
+			->select()->toArray();
 
-        return json_show(0,"获取成功",["list"=>$data,"count"=>$count]);
+        return json_show(0,"获取成功",["list"=>$list,"count"=>$count]);
       }
 
 	/** @param int $id 账户id
@@ -264,7 +278,7 @@ class UserInfo extends BaseController
        H:i:s")]);
         return $result?json_show(0,"账户{$message}成功") : json_show(1005,"账户{$message}失败");
     }
-
+	//根据业务公司获取用户数据
     public function UserListByCompany()
     {
         $post = $this->request->only(["nickname" => "", "username" => "", "status" => "", "uid" => [], "nuid" => [], "companyNo" => "", "page" => 1, "size" => 10], "post");
@@ -336,7 +350,7 @@ class UserInfo extends BaseController
             ]);
     	 if($validate->check($post)==false) return json_show(1004,$validate->getError());
         Db::startTrans();
-         $uiq = Db::table("sys_account")->where(["mobile"=>$post['mobile']])->find();
+        $uiq = Db::table("sys_account")->where(["mobile"=>$post['mobile']])->find();
         if($uiq){
             return json_show(1002,"手机号已注册!");
         }