User.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\user\controller;
  4. use app\user\model\Account;use think\App;use think\facade\Validate;
  5. class User extends Base
  6. {
  7. public function __construct(App $app) {
  8. parent::__construct($app);
  9. $this->model= new Account();
  10. }
  11. public function userList(){
  12. $post =$this->request->param(['page'=>1,'size'=>10,'nickname'=>'','username'=>'','level'=>'','itemid'=>'','status'=>''],"post","trim");
  13. $where=[['is_del','=',0]];
  14. if($post['nickname']!='') $where[]=['userInfo.nickname','like',"%{$post['nickname']}%"];
  15. if($post['username']!='') $where[]=['username','like',"%{$post['username']}%"];
  16. if($post['status']!=='')$where[]=['status','=',$post['status']];
  17. if($post['level']!=0) $where[]=['level','=',$post['level']];
  18. if($post['itemid']!=0) $where[]=['accountItem.itemid','=',$post['itemid']];
  19. $list=$this->model->with(['accountItem'=>['itemName'],'company_relaton'])
  20. ->withJoin(['userInfo',"account_item"],'left')
  21. ->where($where)->order('account.id asc')
  22. ->paginate(['list_rows'=>$post['size'],'page'=>$post['page']]);
  23. $list->hidden(['userInfo','password','salt','account_item','accountItem']);
  24. return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
  25. }
  26. public function userInfo(){
  27. $uid =$this->request->post("id/d");
  28. $info=$this->model->with(['accountItem'=>['itemName'],'company_relaton','userInfo'])->findOrEmpty($uid);
  29. $info->hidden(['userInfo','password','salt','accountItem']);
  30. return success('获取成功',$info);
  31. }
  32. //修改账户字段
  33. public function userChange(){
  34. $param =$this->request->param([
  35. 'id'=>"",
  36. 'nickname',
  37. 'mobile',
  38. 'level',
  39. 'status'],'post','trim');
  40. $valid = Validate::rule([
  41. "id|账户id"=>"require|number|gt:0",
  42. "nickname|账户名称"=>"max:255",
  43. "mobile|手机号"=>"mobile",
  44. "level|账户级别"=>"number|in:1,2,3",
  45. "status|账户状态"=>"number|in:0,1",
  46. ]);
  47. if($valid->check($param)==false)return error($valid->getError());
  48. $info=$this->model->with(['userInfo'])->findOrEmpty($param['id']);
  49. if($info->isEmpty())return error("账户数据不存在");
  50. if(key_exists("nickname",$param)){
  51. $info->userInfo->nickname= $param['nickname'];
  52. }
  53. if(key_exists('mobile',$param)){
  54. $info->userInfo->mobile= $param['mobile'];
  55. $info->mobile= $param['mobile'];
  56. $info->username= $param['mobile'];
  57. }
  58. if(key_exists('status',$param)){
  59. $info->status= $param['status'];
  60. }
  61. if(key_exists('level',$param)){
  62. $info->level= $param['level'];
  63. }
  64. $info->save();
  65. $info->userInfo->save();
  66. return success('修改成功',$info);
  67. }
  68. }