LoginController.php 5.1 KB

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