LoginController.php 5.1 KB

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