User.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace app\Admin\controller;
  3. use app\Admin\model\AdminAccount;
  4. use app\BaseController;
  5. use think\facade\Db;
  6. class User extends BaseController
  7. {
  8. /**
  9. * @param token
  10. * @return \think\response\Json
  11. * @throws \think\exception\DbException
  12. */
  13. public function userInfo(){
  14. $post =$this->request->post();
  15. $token = isset($post['token']) ? trim($post['token']) : "";
  16. if($token==""){
  17. return app_show(101,'token不能为空');
  18. }
  19. $effetc = VerifyTokens($token);
  20. if(!empty($effetc) && $effetc['code']!=0){
  21. return app_show($effetc['code'],$effetc['message']);
  22. }
  23. $userinfo=GetUserInfo($token);
  24. if(empty($userinfo)||$userinfo['code']!=0){
  25. return app_show(1002,"员工信息不存在");
  26. }
  27. $data = $userinfo['data'];
  28. $role = Db::name("role")->where("id","=",$data['roleid'])->find();
  29. $data['role_name']=isset($role['role_name']) ? $role['role_name'] :"";
  30. return app_show(0,"获取成功",$data);
  31. }
  32. /**
  33. * @param token
  34. * @param passwd
  35. * @return \think\response\Json
  36. * @throws \think\exception\DbException
  37. */
  38. public function resetPwd(){
  39. $post =$this->request->post();
  40. $token = isset($post['token']) ? trim($post['token']) : "";
  41. if($token==""){
  42. return error_show(101,'token不能为空');
  43. }
  44. $effetc = verfiyToken($token);
  45. if(!empty($effetc) && $effetc['code']!=0){
  46. return error_show($effetc['code'],$effetc['message']);
  47. }
  48. $newPwd= isset($post['passwd']) ? trim($post['passwd']) : "";
  49. if($newPwd==""){
  50. return error_show(1001,'新密码不能为空');
  51. }
  52. $oldpasswd= isset($post['oldpasswd']) ? trim($post['oldpasswd']) : "";
  53. if($oldpasswd==""){
  54. return error_show(1001,'旧密码不能为空');
  55. }
  56. $account =model("AdminAccount")->GetAccountByUid($effetc['user']['id']);
  57. if(!empty ($account) && $account->status!=1){
  58. return error_show(10005, '账户已被禁止登录');
  59. }
  60. if($account->password!=sha1($oldpasswd.$account->salt)){
  61. return error_show(10005, '旧密码错误!');
  62. }
  63. $salt=makeSalt();
  64. $data=['password'=>sha1($newPwd.$salt),'salt'=>$salt,"updatetime"=>date("Y-m-d H:i:s")];
  65. return AdminAccount::update($data,["id"=>$account->id]) ? app_show(0, '密码修改成功') : error_show(1001,"密码修改失败");
  66. }
  67. public function userAll(){
  68. $post =$this->request->post();
  69. $token = isset($post['token']) ? trim($post['token']) : "";
  70. if($token==""){
  71. return app_show(101,'token不能为空');
  72. }
  73. $effetc = VerifyTokens($token);
  74. if(!empty($effetc) && $effetc['code']!=0){
  75. return app_show($effetc['code'],$effetc['message']);
  76. }
  77. $userinfo=GetAccountall($token);
  78. if(empty($userinfo)||$userinfo['code']!=0){
  79. return app_show(1002,"员工信息不存在");
  80. }
  81. $data = $userinfo['data'];
  82. $role = Db::name("role")->column("role_name","id");
  83. $role[0]="";
  84. $list=[];
  85. foreach ($data as $value){
  86. $value["role_name"] = isset($role[$value["roleid"]]) ? $role[$value["roleid"]]:"";
  87. $list[]=$value;
  88. }
  89. return app_show(0,"获取成功",$list);
  90. }
  91. /**
  92. * @return \think\response\Json|void
  93. * @throws \think\db\exception\DataNotFoundException
  94. * @throws \think\db\exception\DbException
  95. * @throws \think\db\exception\ModelNotFoundException
  96. * @throws \think\exception\DbException
  97. */
  98. public function userList(){
  99. $post =$this->request->post();
  100. $token = isset($post['token']) ? trim($post['token']) : "";
  101. if($token==""){
  102. return app_show(101,'token不能为空');
  103. }
  104. $effetc = VerifyTokens($token);
  105. if(!empty($effetc) && $effetc['code']!=0){
  106. return app_show($effetc['code'],$effetc['message']);
  107. }
  108. $userinfo=GetList($token,$post);
  109. if(empty($userinfo)||$userinfo['code']!=0){
  110. return app_show($userinfo['code'],$userinfo['msg']);
  111. }
  112. $data = $userinfo['data']['list'];
  113. $role = Db::name("role")->column("role_name","id");
  114. $role[0]="";
  115. $list=[];
  116. foreach ($data as $value){
  117. $value["role_name"] = isset($role[$value["roleid"]]) ? $role[$value["roleid"]]:"";
  118. $list[]=$value;
  119. }
  120. return app_show(0,"获取成功",["list"=>$list,"count"=>$userinfo['data']["count"]]);
  121. }
  122. }