LoginController.php 6.5 KB

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