1
0

LoginController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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\notice\NoticeSetting;
  18. use app\common\service\wechat\WeChatOaService;
  19. use app\workerapi\logic\LoginLogic;
  20. use app\workerapi\validate\LoginAccountValidate;
  21. use app\workerapi\validate\RegisterValidate;
  22. /**
  23. * 登录注册
  24. * Class LoginController
  25. * @package app\workerapi\controller
  26. */
  27. class LoginController extends BaseApiController
  28. {
  29. public array $notNeedLogin = ['register', 'account', 'logout','testWeChat'];
  30. /**
  31. * @notes 注册账号
  32. * @return \think\response\Json
  33. * @author 段誉
  34. * @date 2022/9/7 15:38
  35. */
  36. public function register()
  37. {
  38. $params = (new RegisterValidate())->post()->goCheck('register');
  39. $res = LoginLogic::confirmMobile($params);
  40. if(!$res){
  41. return $this->fail(LoginLogic::getError());
  42. }
  43. $result = LoginLogic::register($params);
  44. if (true === $result) {
  45. // 发送通知给平台配置的审核人
  46. $noticeSetting = NoticeSetting::where('scene_id', NoticeEnum::WORKER_EXAMINE)->findOrEmpty()->toArray();
  47. if($noticeSetting['oa_notice']['designated_user']??0 && $noticeSetting['oa_notice']['designated_user']){
  48. event('Notice', [
  49. 'scene_id' => NoticeEnum::WORKER_EXAMINE,
  50. 'params' => [
  51. 'user_id' => 0,
  52. 'openid' => $noticeSetting['oa_notice']['designated_user'],
  53. ]
  54. ]);
  55. }
  56. return $this->success('注册成功', [], 1, 1);
  57. }
  58. return $this->fail(LoginLogic::getError());
  59. }
  60. /**
  61. * @notes 账号密码/手机号密码/手机号验证码登录
  62. * @return \think\response\Json
  63. * @author 段誉
  64. * @date 2022/9/16 10:42
  65. */
  66. public function account()
  67. {
  68. $params = (new LoginAccountValidate())->post()->goCheck();
  69. $result = LoginLogic::login($params);
  70. if (false === $result) {
  71. return $this->fail(LoginLogic::getError());
  72. }
  73. if(!empty($params['wx_code']) and $params['terminal']==1){
  74. $params['code'] = $params['wx_code'];
  75. $params['user_id'] = MasterWorker::where('sn',$result['sn'])->value('id');
  76. $wx_result = LoginLogic::mnpAuthLogin($params);
  77. if ($wx_result === false) {
  78. return $this->fail(LoginLogic::getError());
  79. }
  80. }
  81. return $this->data($result);
  82. }
  83. /**
  84. * @notes 退出登录
  85. * @return \think\response\Json
  86. * @throws \think\db\exception\DataNotFoundException
  87. * @throws \think\db\exception\DbException
  88. * @throws \think\db\exception\ModelNotFoundException
  89. * @author 段誉
  90. * @date 2022/9/16 10:42
  91. */
  92. public function logout()
  93. {
  94. LoginLogic::logout($this->userInfo);
  95. return $this->success();
  96. }
  97. public function testWeChat()
  98. {
  99. try {
  100. // 发送通知给平台配置的审核人
  101. $noticeSetting = NoticeSetting::where('scene_id', NoticeEnum::WORKER_EXAMINE)->findOrEmpty()->toArray();
  102. if($noticeSetting['oa_notice']['designated_user']??0 && $noticeSetting['oa_notice']['designated_user']){
  103. (new WeChatOaService())->sendTemplateMessage([
  104. 'scene_id' => NoticeEnum::WORKER_EXAMINE,
  105. 'params' => [
  106. 'user_id' => 0,
  107. 'openid' => $noticeSetting['oa_notice']['designated_user'],
  108. ]
  109. ]);
  110. /*event('Notice', [
  111. 'scene_id' => NoticeEnum::WORKER_EXAMINE,
  112. 'params' => [
  113. 'user_id' => 0,
  114. 'openid' => $noticeSetting['oa_notice']['designated_user'],
  115. ]
  116. ]);*/
  117. }
  118. } catch (\Exception $e) {
  119. dd($e->getMessage());
  120. }
  121. }
  122. }