LoginController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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\master_worker_register\MasterWorkerRegister;
  18. use app\common\model\notice\NoticeSetting;
  19. use app\common\service\wechat\WeChatOaService;
  20. use app\workerapi\logic\DictLogic;
  21. use app\workerapi\logic\LoginLogic;
  22. use app\workerapi\validate\LoginAccountValidate;
  23. use app\workerapi\validate\RegisterValidate;
  24. /**
  25. * 登录注册
  26. * Class LoginController
  27. * @package app\workerapi\controller
  28. */
  29. class LoginController extends BaseApiController
  30. {
  31. public array $notNeedLogin = ['register', 'account', 'logout','testWeChat','getCredentialName'];
  32. /**
  33. * @notes 注册账号
  34. * @return \think\response\Json
  35. * @author 段誉
  36. * @date 2022/9/7 15:38
  37. */
  38. public function register()
  39. {
  40. $params = (new RegisterValidate())->post()->goCheck('register');
  41. $res = LoginLogic::confirmMobile($params);
  42. $resCredential = LoginLogic::confirmCredential($params);
  43. if(!$res || !$resCredential){
  44. return $this->fail(LoginLogic::getError());
  45. }
  46. $result = LoginLogic::register($params);
  47. if (true === $result) {
  48. // 发送通知给平台配置的审核人(公众号通知)
  49. event('Notice', [
  50. 'scene_id' => 108,
  51. 'params' => [
  52. 'user_id' => 0,
  53. 'thing1' => $params['name'],
  54. 'time2' => date('Y-m-d H:i:s')
  55. ]
  56. ]);
  57. // 工程师提交入驻申请后-发送短信通知
  58. event('Notice', [
  59. 'scene_id' => 109,
  60. 'params' => [
  61. 'user_id' => 0,
  62. 'mobile' => $params['mobile'],
  63. ]
  64. ]);
  65. return $this->success('注册成功', [], 1, 1);
  66. }
  67. return $this->fail(LoginLogic::getError());
  68. }
  69. /**
  70. * 获取证件信息
  71. * @return \think\response\Json
  72. */
  73. public function getCredentialName()
  74. {
  75. $res = DictLogic::groupData(['type'=>'credential_name']);
  76. return $this->success('', $res);
  77. }
  78. /**
  79. * 获取注册id
  80. */
  81. public function getRegisterId()
  82. {
  83. $params = request()->get();
  84. return $this->success('', ['openid'=>LoginLogic::getRegisterId($params)]);
  85. }
  86. /**
  87. * @notes 账号密码/手机号密码/手机号验证码登录
  88. * @return \think\response\Json
  89. * @author 段誉
  90. * @date 2022/9/16 10:42
  91. */
  92. public function account()
  93. {
  94. $params = (new LoginAccountValidate())->post()->goCheck();
  95. $worker_register = MasterWorkerRegister::where('mobile',$params['account'])->findOrEmpty();
  96. if($worker_register->isEmpty()) {
  97. return $this->fail('请点击下方的工程师入驻',[],402);
  98. }
  99. $result = LoginLogic::login($params);
  100. if (false === $result) {
  101. return $this->fail(LoginLogic::getError());
  102. }
  103. //if(!empty($params['wx_code']) and $params['terminal']==1){
  104. if(!empty($params['wx_code'])){
  105. $params['code'] = $params['wx_code'];
  106. $params['user_id'] = MasterWorker::where('sn',$result['sn'])->value('id');
  107. $wx_result = LoginLogic::mnpAuthLogin($params);
  108. if ($wx_result === false) {
  109. return $this->fail(LoginLogic::getError());
  110. }
  111. }
  112. return $this->data($result);
  113. }
  114. /**
  115. * @notes 退出登录
  116. * @return \think\response\Json
  117. * @throws \think\db\exception\DataNotFoundException
  118. * @throws \think\db\exception\DbException
  119. * @throws \think\db\exception\ModelNotFoundException
  120. * @author 段誉
  121. * @date 2022/9/16 10:42
  122. */
  123. public function logout()
  124. {
  125. LoginLogic::logout($this->userInfo);
  126. return $this->success();
  127. }
  128. }