| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <?php
- // +----------------------------------------------------------------------
- // | whitef快速开发前后端分离管理后台(PHP版)
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | gitee下载:https://gitee.com/likeshop_gitee/whitef
- // | github下载:https://github.com/likeshop-github/whitef
- // | 访问官网:https://www.whitef.cn
- // | whitef团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: whitefTeam
- // +----------------------------------------------------------------------
- namespace app\workerapi\controller;
- use app\common\cache\MasterWokerTokenCache;
- use app\common\enum\notice\NoticeEnum;
- use app\common\model\master_worker\MasterWorker;
- use app\common\model\master_worker_register\MasterWorkerRegister;
- use app\common\model\dict\DictData;
- use app\common\model\notice\NoticeSetting;
- use app\common\service\wechat\WeChatOaService;
- use app\workerapi\logic\DictLogic;
- use app\workerapi\logic\LoginLogic;
- use app\workerapi\logic\MasterWorkerLogic;
- use app\workerapi\logic\MasterWorkerRegisterLogic;
- use app\workerapi\validate\LoginAccountValidate;
- use app\workerapi\validate\RegisterValidate;
- use think\facade\Log;
- /**
- * 登录注册
- * Class LoginController
- * @package app\workerapi\controller
- */
- class LoginController extends BaseApiController
- {
- public array $notNeedLogin = ['register', 'account', 'logout','testWeChat','getCredentialName','passedInterview','getRegisterId','mobile','customerPhone','getOpenIdByCode'];
- /**
- * @notes 注册账号
- * @return \think\response\Json
- * @author 段誉
- * @date 2022/9/7 15:38
- */
- public function register()
- {
- $params = (new RegisterValidate())->post()->goCheck('register');
- if(in_array($params['mobile'],['18827381821'])){
- return $this->fail('该手机号禁止入驻');
- }
- $res = LoginLogic::confirmMobile($params);
- $resCredential = LoginLogic::confirmCredential($params);
- if(!$res || !$resCredential){
- return $this->fail(LoginLogic::getError());
- }
- $result = LoginLogic::register($params);
- if (false === $result) {
- return $this->fail(LoginLogic::getError());
- }
- // 发送通知给平台配置的审核人(公众号通知)
- event('Notice', [
- 'scene_id' => 108,
- 'params' => [
- 'user_id' => 0,
- 'thing1' => $params['name'],
- 'time2' => date('Y-m-d H:i:s')
- ]
- ]);
- // 工程师提交入驻申请后-发送短信通知
- event('Notice', [
- 'scene_id' => 109,
- 'params' => [
- 'user_id' => 0,
- 'mobile' => $params['mobile'],
- ]
- ]);
- // TOPIC 临时
- // MasterWorkerRegisterLogic::createMasterWorker(['worker_register_id'=>$result,'is_rinse'=>1]);
- return $this->success('注册成功', ['worker_register_id'=>$result], 1, 1);
- }
- /**
- * 获取证件信息
- * @return \think\response\Json
- */
- public function getCredentialName()
- {
- $res = DictLogic::groupData(['type'=>'credential_name']);
- return $this->success('', $res);
- }
- /**
- * 获取注册id
- */
- public function getRegisterId()
- {
- $params = request()->get();
- return $this->success('', ['worker_register_id'=>LoginLogic::getRegisterId($params)]);
- }
- /**
- * @notes 账号密码/手机号密码/手机号验证码登录
- * @return \think\response\Json
- * @author 段誉
- * @date 2022/9/16 10:42
- */
- public function account()
- {
- $params = (new LoginAccountValidate())->post()->goCheck();
- if(in_array($params['account'],['18827381821'])){
- return $this->fail('该账号号不存在',[],402);
- }
- $worker_register = MasterWorkerRegister::where('mobile',$params['account'])->findOrEmpty();
- if($worker_register->isEmpty()) {
- return $this->fail($params['terminal'] == 5?'工程师不存在':'请点击下方的工程师入驻',[],402);
- }
- if(isset($params['terminal']) && $params['terminal'] == 5 && $worker_register->worker_id > 0){
- if(!MasterWorkerLogic::isReceivingOrders($worker_register->worker_id)){
- return $this->fail('未达到接单条件');
- }
- }
- $result = LoginLogic::login($params);
- if (false === $result) {
- return $this->fail(LoginLogic::getError());
- }
- //if(!empty($params['wx_code']) and $params['terminal']==1){
- if(isset($params['wx_code']) && !empty($params['wx_code'])){
- $params['code'] = $params['wx_code'];
- $params['user_id'] = MasterWorker::where('sn',$result['sn'])->value('id');
- $wx_result = LoginLogic::mnpAuthLogin($params);
- if ($wx_result === false) {
- return $this->fail(LoginLogic::getError());
- }
- }
- return $this->data($result);
- }
- /**
- * @notes 退出登录
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author 段誉
- * @date 2022/9/16 10:42
- */
- public function logout()
- {
- LoginLogic::logout($this->userInfo);
- return $this->success();
- }
- public function passedInterview()
- {
- $params = request()->post();
- $updata['worker_id'] = MasterWorkerRegisterLogic::createMasterWorker($params);
- if($updata['worker_id']==0){
- return $this->fail('审核失败');
- }
- return $this->success('审核通过', ['worker_register_id'=>$params['worker_register_id']], 1, 1);
- }
- /**
- * @notes 临时工程师登录
- * @return \think\response\Json
- */
- public function mobile()
- {
- $params = (new LoginAccountValidate())->post()->goCheck('temporary');
- $result = LoginLogic::temporary($params);
- if (false === $result) {
- return $this->fail(LoginLogic::getError());
- }
- return $this->data($result);
- }
- /**
- * 客服电话
- * @return \think\response\Json
- */
- public function customerPhone()
- {
- $result = DictData::where(['type_value' => 'customer_support'])->column('value', 'name');
- return $this->data($result);
- }
- /**
- * 获取微信用户openid信息
- */
- public function getOpenIdByCode()
- {
- $code = $this->request->get('code');
- $res = \app\api\logic\LoginLogic::getOpenIdByCode(['code'=>$code]);
- if (false === $res) {
- return $this->fail(LoginLogic::getError());
- }
- return $this->success('', $res);
- }
- }
|