LoginController.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | whitef快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/whitef
  8. // | github下载:https://github.com/likeshop-github/whitef
  9. // | 访问官网:https://www.whitef.cn
  10. // | whitef团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: whitefTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\workerapi\controller;
  15. use app\common\model\master_worker\MasterWorker;
  16. use app\workerapi\logic\LoginLogic;
  17. use app\workerapi\validate\LoginAccountValidate;
  18. use app\workerapi\validate\RegisterValidate;
  19. /**
  20. * 登录注册
  21. * Class LoginController
  22. * @package app\workerapi\controller
  23. */
  24. class LoginController extends BaseApiController
  25. {
  26. public array $notNeedLogin = ['register', 'account', 'logout'];
  27. /**
  28. * @notes 注册账号
  29. * @return \think\response\Json
  30. * @author 段誉
  31. * @date 2022/9/7 15:38
  32. */
  33. public function register()
  34. {
  35. $params = (new RegisterValidate())->post()->goCheck('register');
  36. $res = LoginLogic::confirmMobile($params);
  37. if(!$res){
  38. return $this->fail(LoginLogic::getError());
  39. }
  40. $result = LoginLogic::register($params);
  41. if (true === $result) {
  42. return $this->success('注册成功', [], 1, 1);
  43. }
  44. return $this->fail(LoginLogic::getError());
  45. }
  46. /**
  47. * @notes 账号密码/手机号密码/手机号验证码登录
  48. * @return \think\response\Json
  49. * @author 段誉
  50. * @date 2022/9/16 10:42
  51. */
  52. public function account()
  53. {
  54. $params = (new LoginAccountValidate())->post()->goCheck();
  55. $result = LoginLogic::login($params);
  56. if (false === $result) {
  57. return $this->fail(LoginLogic::getError());
  58. }
  59. if(!empty($params['wx_code']) and $params['terminal']==1){
  60. $params['code'] = $params['wx_code'];
  61. $params['user_id'] = MasterWorker::where('sn',$result['sn'])->value('id');
  62. $wx_result = LoginLogic::mnpAuthLogin($params);
  63. if ($wx_result === false) {
  64. return $this->fail(LoginLogic::getError());
  65. }
  66. }
  67. return $this->data($result);
  68. }
  69. /**
  70. * @notes 退出登录
  71. * @return \think\response\Json
  72. * @throws \think\db\exception\DataNotFoundException
  73. * @throws \think\db\exception\DbException
  74. * @throws \think\db\exception\ModelNotFoundException
  75. * @author 段誉
  76. * @date 2022/9/16 10:42
  77. */
  78. public function logout()
  79. {
  80. LoginLogic::logout($this->userInfo);
  81. return $this->success();
  82. }
  83. }