LoginController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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\enum\notice\NoticeEnum;
  16. use app\common\model\master_worker\MasterWorker;
  17. use app\common\model\notice\NoticeSetting;
  18. use app\workerapi\logic\LoginLogic;
  19. use app\workerapi\validate\LoginAccountValidate;
  20. use app\workerapi\validate\RegisterValidate;
  21. /**
  22. * 登录注册
  23. * Class LoginController
  24. * @package app\workerapi\controller
  25. */
  26. class LoginController extends BaseApiController
  27. {
  28. public array $notNeedLogin = ['register', 'account', 'logout'];
  29. /**
  30. * @notes 注册账号
  31. * @return \think\response\Json
  32. * @author 段誉
  33. * @date 2022/9/7 15:38
  34. */
  35. public function register()
  36. {
  37. $params = (new RegisterValidate())->post()->goCheck('register');
  38. $res = LoginLogic::confirmMobile($params);
  39. if(!$res){
  40. return $this->fail(LoginLogic::getError());
  41. }
  42. $result = LoginLogic::register($params);
  43. if (true === $result) {
  44. // 发送通知给平台配置的审核人
  45. $noticeSetting = NoticeSetting::where('scene_id', NoticeEnum::WORKER_EXAMINE)->findOrEmpty()->toArray();
  46. if($noticeSetting['oa_notice']['designated_user']??0 && $noticeSetting['oa_notice']['designated_user']){
  47. event('Notice', [
  48. 'scene_id' => NoticeEnum::WORKER_EXAMINE,
  49. 'params' => [
  50. 'user_id' => 0,
  51. 'openid' => $noticeSetting['oa_notice']['designated_user'],
  52. ]
  53. ]);
  54. }
  55. return $this->success('注册成功', [], 1, 1);
  56. }
  57. return $this->fail(LoginLogic::getError());
  58. }
  59. /**
  60. * @notes 账号密码/手机号密码/手机号验证码登录
  61. * @return \think\response\Json
  62. * @author 段誉
  63. * @date 2022/9/16 10:42
  64. */
  65. public function account()
  66. {
  67. $params = (new LoginAccountValidate())->post()->goCheck();
  68. $result = LoginLogic::login($params);
  69. if (false === $result) {
  70. return $this->fail(LoginLogic::getError());
  71. }
  72. if(!empty($params['wx_code']) and $params['terminal']==1){
  73. $params['code'] = $params['wx_code'];
  74. $params['user_id'] = MasterWorker::where('sn',$result['sn'])->value('id');
  75. $wx_result = LoginLogic::mnpAuthLogin($params);
  76. if ($wx_result === false) {
  77. return $this->fail(LoginLogic::getError());
  78. }
  79. }
  80. return $this->data($result);
  81. }
  82. /**
  83. * @notes 退出登录
  84. * @return \think\response\Json
  85. * @throws \think\db\exception\DataNotFoundException
  86. * @throws \think\db\exception\DbException
  87. * @throws \think\db\exception\ModelNotFoundException
  88. * @author 段誉
  89. * @date 2022/9/16 10:42
  90. */
  91. public function logout()
  92. {
  93. LoginLogic::logout($this->userInfo);
  94. return $this->success();
  95. }
  96. }