LoginController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\controller\BaseApiController;
  17. use app\workerapi\logic\LoginLogic;
  18. use app\workerapi\validate\LoginAccountValidate;
  19. use app\workerapi\validate\RegisterValidate;
  20. /**
  21. * 登录注册
  22. * Class LoginController
  23. * @package app\api\controller
  24. */
  25. class LoginController extends BaseApiController
  26. {
  27. public array $notNeedLogin = ['register', 'account', 'logout'];
  28. /**
  29. * @notes 注册账号
  30. * @return \think\response\Json
  31. * @author 段誉
  32. * @date 2022/9/7 15:38
  33. */
  34. public function register()
  35. {
  36. $params = (new RegisterValidate())->post()->goCheck('register');
  37. $res = LoginLogic::confirmMobile($params);
  38. if(!$res){
  39. return $this->fail(LoginLogic::getError());
  40. }
  41. $result = LoginLogic::register($params);
  42. if (true === $result) {
  43. return $this->success('注册成功', [], 1, 1);
  44. }
  45. return $this->fail(LoginLogic::getError());
  46. }
  47. /**
  48. * @notes 账号密码/手机号密码/手机号验证码登录
  49. * @return \think\response\Json
  50. * @author 段誉
  51. * @date 2022/9/16 10:42
  52. */
  53. public function account()
  54. {
  55. $params = (new LoginAccountValidate())->post()->goCheck();
  56. $result = LoginLogic::login($params);
  57. if (false === $result) {
  58. return $this->fail(LoginLogic::getError());
  59. }
  60. if(!empty($params['wx_code']) and $params['terminal']==1){
  61. $params['code'] = $params['wx_code'];
  62. $params['user_id'] = MasterWorker::where('sn',$result['sn'])->value('id');
  63. $wx_result = LoginLogic::mnpAuthLogin($params);
  64. if ($wx_result === false) {
  65. return $this->fail(LoginLogic::getError());
  66. }
  67. }
  68. return $this->data($result);
  69. }
  70. /**
  71. * @notes 退出登录
  72. * @return \think\response\Json
  73. * @throws \think\db\exception\DataNotFoundException
  74. * @throws \think\db\exception\DbException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. * @author 段誉
  77. * @date 2022/9/16 10:42
  78. */
  79. public function logout()
  80. {
  81. LoginLogic::logout($this->userInfo);
  82. return $this->success();
  83. }
  84. }