wugg 1 jaar geleden
bovenliggende
commit
37a0de1603
2 gewijzigde bestanden met toevoegingen van 50 en 5 verwijderingen
  1. 48 3
      app/controller/User.php
  2. 2 2
      app/model/Account.php

+ 48 - 3
app/controller/User.php

@@ -361,13 +361,58 @@ class User extends Base
    }
    
    public function AccountQuery(){
-   	$param = $this->request->only(['nickname' => '', 'username' => '',"is_wx"=>"",'level'=>'', 'status' => '', 'page'=> 1,'size'=>10], 'post', 'trim');
+   	$param = $this->request->only(['nickname' => '', 'username' => '',"is_wx"=>"",'level'=>'', 'status' => '',
+   	'page'=> 1,'size'=>30], 'post', 'trim');
    	    $where=[];
    	    $param['nickname']==''?? $where[]=['userinfo.nickname','like',"%{$param['nickname']}%"];
     	$param['status']==''?? $where[]=['account.status','=',$param['status']];
     	$param['level']==''?? $where[]=['account.level','=',$param['level']];
     	$param['username']==''?? $where[]=['username','like',"%{$param['username']}%"];
-   	  $acc = $this->model->with(['userinfo'])->where($where)->order('id desc')->paginate(['page'=>$param['page'],'list_rows'=>$param['size']]);
-   	  $this->success('获取成功',['list'=>$acc->items(),'count'=>$acc->total()]);
+   	  $acc = $this->model->with(['userinfo'])->where($where)->order('id desc')
+   	  ->paginate(['page'=>$param['page'],'list_rows'=>$param['size']]);
+   	  $tenmp=[];
+   	  foreach ($acc->items() as $value){
+   	  	$temp=[];
+   	  	$temp['id'] = $value->id;
+   	  	$temp['nickname'] = $value->nickname;
+   	  	$temp['mobile'] = substr_replace($value->mobile,"****",-4);
+//   	  	$temp['mobile1'] = substr($value->mobile,-4,4);
+   	  	$tenmp[]=$temp;
+   	  }
+   	  $this->success('获取成功',['list'=>$tenmp,'count'=>$acc->total()],0);
+   }
+   
+   
+    public function BindWx(){
+   	$param = $this->request->only(['id' => '', 'openId' => '','lastCode'=>''], 'post', 'trim');
+    $valid =Validate::rule(["id|账户主键"=>"require|number|egt:0","openId|微信openid"=>"require|max:255","lastCode|手机号后四位"=>"require|number|length:4"]);
+    if($valid->check($param)==false) $this->error($valid->getError());
+   	$acc = $this->model->withJoin(['userinfo','accountitem'],'left')->findOrEmpty($param['id']);
+   	if($acc->isEmpty())$this->error("账户信息不存在",1004);
+   	if(substr($acc->mobile,-4,4)!=$param['lastCode'])$this->error('手机后四位不正确!',1004);
+   	if($param['openId']==''&& $acc->userinfo->openId!=$param['openId'] ){
+	        $acc->userinfo->openId=$param['openId'];
+	        $this->model->userinfo()->save($acc->userinfo->toArray());
+   	  }
+   	 $userinfo=[
+        	'id'=>$acc->id,
+        	'username'=>$acc->username,
+        	'mobile'=>$acc->mobile,
+        	'source'=>$acc->source,
+        	'nickname'=>$acc->userinfo->nickname,
+        	'sex'=>$acc->userinfo->sex,
+        	'email'=>$acc->userinfo->email,
+        	'level'=>$acc->level,
+        	'itemid'=>$acc->accountitem->itemid??0,
+        	'position'=>$acc->accountitem->position??'',
+        	'depart_name'=>$acc->depart_name,
+        	'company_relaton'=>$acc->company_relaton,
+        	];
+   	   $token = makeToken($userinfo);
+        if ($token == '') $this->error('token生成失败',1003);
+        $cache = Cache::store('redis')->set("user:info:{$token}", $userinfo, $this->token_time);
+        if ($cache == false)$this->error('token保存失败',1003);
+        $userinfo['token'] = $token;
+   	 $this->success('获取成功',$userinfo,0);
    }
 }

+ 2 - 2
app/model/Account.php

@@ -32,11 +32,11 @@ class Account extends Model
         return $company;
 	}
 	public function UserInfo(){
-    	return $this->belongsTo(User::class,'id','account_id');
+    	return $this->belongsTo(User::class,'id','account_id')->bind(["nickname","openId"]);
 	}
 	
 	public function AccountItem(){
-    	return $this->belongsTo(AccountItem::class,'id','account_id');
+    	return $this->belongsTo(AccountItem::class,'id','account_id')->bind(["itemid"]);
 	}
 	
 	public function getIsWxAttr($v,$row){