LoginController.php 5.8 KB

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