model= new Account(); } public function userList(){ $post =$this->request->param(['page'=>1,'size'=>10,'nickname'=>'','username'=>'','level'=>'','itemid'=>'','status'=>''],"post","trim"); $where=[['is_del','=',0]]; if($post['nickname']!='') $where[]=['userInfo.nickname','like',"%{$post['nickname']}%"]; if($post['username']!='') $where[]=['username','like',"%{$post['username']}%"]; if($post['status']!=='')$where[]=['status','=',$post['status']]; if($post['level']!=0) $where[]=['level','=',$post['level']]; if($post['itemid']!=0) $where[]=['accountItem.itemid','=',$post['itemid']]; $list=$this->model->with(['accountItem'=>['itemName'],'company_relaton']) ->withJoin(['userInfo',"account_item"],'left') ->where($where)->order('account.id asc') ->paginate(['list_rows'=>$post['size'],'page'=>$post['page']]); $list->hidden(['userInfo','password','salt','account_item','accountItem']); return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]); } public function userInfo(){ $uid =$this->request->post("id/d"); $info=$this->model->with(['accountItem'=>['itemName'],'company_relaton','userInfo'])->findOrEmpty($uid); $info->hidden(['userInfo','password','salt','accountItem']); return success('获取成功',$info); } //修改账户字段 public function userChange(){ $param =$this->request->param([ 'id'=>"", 'nickname', 'mobile', 'level', 'status'],'post','trim'); $valid = Validate::rule([ "id|账户id"=>"require|number|gt:0", "nickname|账户名称"=>"max:255", "mobile|手机号"=>"mobile", "level|账户级别"=>"number|in:1,2,3", "status|账户状态"=>"number|in:0,1", ]); if($valid->check($param)==false)return error($valid->getError()); $info=$this->model->with(['userInfo'])->findOrEmpty($param['id']); if($info->isEmpty())return error("账户数据不存在"); if(key_exists("nickname",$param)){ $info->userInfo->nickname= $param['nickname']; } if(key_exists('mobile',$param)){ $info->userInfo->mobile= $param['mobile']; $info->mobile= $param['mobile']; $info->username= $param['mobile']; } if(key_exists('status',$param)){ $info->status= $param['status']; } if(key_exists('level',$param)){ $info->level= $param['level']; } $info->save(); $info->userInfo->save(); return success('修改成功',$info); } }