1
0

LoginController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. if(!$res){
  43. return $this->fail(LoginLogic::getError());
  44. }
  45. $result = LoginLogic::register($params);
  46. if (true === $result) {
  47. // 发送通知给平台配置的审核人
  48. event('Notice', [
  49. 'scene_id' => NoticeEnum::WORKER_EXAMINE,
  50. 'params' => [
  51. 'user_id' => 0,
  52. ]
  53. ]);
  54. // 工程师提交入驻申请后-发送短信通知
  55. event('Notice', [
  56. 'scene_id' => 109,
  57. 'params' => [
  58. 'user_id' => 0,
  59. 'mobile' => $params['mobile'],
  60. ]
  61. ]);
  62. return $this->success('注册成功', [], 1, 1);
  63. }
  64. return $this->fail(LoginLogic::getError());
  65. }
  66. /**
  67. * 获取证件信息
  68. * @return \think\response\Json
  69. */
  70. public function getCredentialName()
  71. {
  72. $res = DictLogic::groupData(['type'=>'credential_name']);
  73. return $this->success('', $res);
  74. }
  75. /**
  76. * @notes 账号密码/手机号密码/手机号验证码登录
  77. * @return \think\response\Json
  78. * @author 段誉
  79. * @date 2022/9/16 10:42
  80. */
  81. public function account()
  82. {
  83. $params = (new LoginAccountValidate())->post()->goCheck();
  84. $worker_register = MasterWorkerRegister::where('mobile',$params['account'])->findOrEmpty();
  85. if($worker_register->isEmpty()) {
  86. return $this->fail('请点击下方的工程师入驻',[],402);
  87. }
  88. $result = LoginLogic::login($params);
  89. if (false === $result) {
  90. return $this->fail(LoginLogic::getError());
  91. }
  92. //if(!empty($params['wx_code']) and $params['terminal']==1){
  93. if(!empty($params['wx_code'])){
  94. $params['code'] = $params['wx_code'];
  95. $params['user_id'] = MasterWorker::where('sn',$result['sn'])->value('id');
  96. $wx_result = LoginLogic::mnpAuthLogin($params);
  97. if ($wx_result === false) {
  98. return $this->fail(LoginLogic::getError());
  99. }
  100. }
  101. return $this->data($result);
  102. }
  103. /**
  104. * @notes 退出登录
  105. * @return \think\response\Json
  106. * @throws \think\db\exception\DataNotFoundException
  107. * @throws \think\db\exception\DbException
  108. * @throws \think\db\exception\ModelNotFoundException
  109. * @author 段誉
  110. * @date 2022/9/16 10:42
  111. */
  112. public function logout()
  113. {
  114. LoginLogic::logout($this->userInfo);
  115. return $this->success();
  116. }
  117. public function testWeChat()
  118. {
  119. try {
  120. // 发送通知给平台配置的审核人
  121. $noticeSetting = NoticeSetting::where('scene_id', NoticeEnum::WORKER_EXAMINE)->findOrEmpty()->toArray();
  122. if($noticeSetting['oa_notice']['designated_user']??0 && $noticeSetting['oa_notice']['designated_user']){
  123. (new WeChatOaService())->sendTemplateMessage([
  124. 'scene_id' => NoticeEnum::WORKER_EXAMINE,
  125. 'params' => [
  126. 'user_id' => 0,
  127. 'openid' => $noticeSetting['oa_notice']['designated_user'],
  128. ]
  129. ]);
  130. /*event('Notice', [
  131. 'scene_id' => NoticeEnum::WORKER_EXAMINE,
  132. 'params' => [
  133. 'user_id' => 0,
  134. 'openid' => $noticeSetting['oa_notice']['designated_user'],
  135. ]
  136. ]);*/
  137. }
  138. } catch (\Exception $e) {
  139. dd($e->getMessage());
  140. }
  141. }
  142. }