正在显示
5 个修改的文件
包含
65 行增加
和
55 行删除
| @@ -4,6 +4,7 @@ namespace App\Console\Commands\YesterdayCount; | @@ -4,6 +4,7 @@ namespace App\Console\Commands\YesterdayCount; | ||
| 4 | 4 | ||
| 5 | use App\Helper\Common; | 5 | use App\Helper\Common; |
| 6 | use App\Helper\FormGlobalsoApi; | 6 | use App\Helper\FormGlobalsoApi; |
| 7 | +use App\Http\Logic\Aside\Project\ProjectLogic; | ||
| 7 | use App\Models\CustomerVisit\CustomerVisitItem; | 8 | use App\Models\CustomerVisit\CustomerVisitItem; |
| 8 | use App\Models\Project\DeployBuild; | 9 | use App\Models\Project\DeployBuild; |
| 9 | use Carbon\Carbon; | 10 | use Carbon\Carbon; |
| @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside; | @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside; | ||
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Http\Logic\Bside\User\UserLogic; | 6 | use App\Http\Logic\Bside\User\UserLogic; |
| 7 | +use App\Http\Logic\Bside\User\UserLoginLogic; | ||
| 7 | use App\Models\Project\Project; | 8 | use App\Models\Project\Project; |
| 8 | use App\Models\Project\Project as ProjectModel; | 9 | use App\Models\Project\Project as ProjectModel; |
| 9 | use App\Models\SmsLog; | 10 | use App\Models\SmsLog; |
| @@ -33,7 +34,7 @@ class ComController extends BaseController | @@ -33,7 +34,7 @@ class ComController extends BaseController | ||
| 33 | 'password.required'=>'内容必须填写', | 34 | 'password.required'=>'内容必须填写', |
| 34 | 'mobile.regex' => '请输入正确的手机号码', | 35 | 'mobile.regex' => '请输入正确的手机号码', |
| 35 | ]); | 36 | ]); |
| 36 | - $userLogic = new UserLogic(); | 37 | + $userLogic = new UserLoginLogic(); |
| 37 | $res = $userLogic->login(); | 38 | $res = $userLogic->login(); |
| 38 | $this->response('请求成功',Code::SUCCESS,$res); | 39 | $this->response('请求成功',Code::SUCCESS,$res); |
| 39 | } | 40 | } |
| @@ -35,10 +35,8 @@ class BaseLogic extends Logic | @@ -35,10 +35,8 @@ class BaseLogic extends Logic | ||
| 35 | $this->request = request(); | 35 | $this->request = request(); |
| 36 | $this->requestAll = request()->all(); | 36 | $this->requestAll = request()->all(); |
| 37 | $this->user = Cache::get(request()->header('token')); | 37 | $this->user = Cache::get(request()->header('token')); |
| 38 | - if(!empty($this->user)){ | ||
| 39 | $this->project = (new ProjectLogic())->getInfo($this->user['project_id']); | 38 | $this->project = (new ProjectLogic())->getInfo($this->user['project_id']); |
| 40 | } | 39 | } |
| 41 | - } | ||
| 42 | 40 | ||
| 43 | 41 | ||
| 44 | /** | 42 | /** |
| @@ -16,7 +16,6 @@ class UserLogic extends BaseLogic | @@ -16,7 +16,6 @@ class UserLogic extends BaseLogic | ||
| 16 | public function __construct() | 16 | public function __construct() |
| 17 | { | 17 | { |
| 18 | parent::__construct(); | 18 | parent::__construct(); |
| 19 | - | ||
| 20 | $this->model = new User(); | 19 | $this->model = new User(); |
| 21 | $this->param = $this->requestAll; | 20 | $this->param = $this->requestAll; |
| 22 | } | 21 | } |
| @@ -106,57 +105,6 @@ class UserLogic extends BaseLogic | @@ -106,57 +105,6 @@ class UserLogic extends BaseLogic | ||
| 106 | return $this->success(); | 105 | return $this->success(); |
| 107 | } | 106 | } |
| 108 | 107 | ||
| 109 | - /*** | ||
| 110 | - * @name :登录 | ||
| 111 | - * @return void | ||
| 112 | - * @author :liyuhang | ||
| 113 | - * @method | ||
| 114 | - */ | ||
| 115 | - public function login(){ | ||
| 116 | - //验证账号密码 | ||
| 117 | - $password = base64_encode(md5($this->param['password'])); | ||
| 118 | - $info = $this->model->read(['mobile'=>$this->param['mobile'],'password'=>$password,'status'=>0], ['id','mobile','role_id','token','name','project_id']); | ||
| 119 | - if($info === false){ | ||
| 120 | - //账号密码没通过时,验证验证码 | ||
| 121 | - $info = $this->model->read(['mobile'=>$this->param['mobile'],'status'=>0], ['id','mobile','role_id','token','name','project_id']); | ||
| 122 | - if($info === false){ | ||
| 123 | - $this->fail('账号密码错误',Code::USER_REGISTER_ERROE); | ||
| 124 | - } | ||
| 125 | - //验证验证码是否准备 | ||
| 126 | - $last_sms = SmsLog::getLastLog($this->param['mobile'], SmsLog::TYPE_LOGIN); | ||
| 127 | - if($this->param['password'] != $last_sms->code){ | ||
| 128 | - $this->fail('账号密码错误',Code::USER_REGISTER_ERROE); | ||
| 129 | - } | ||
| 130 | - } | ||
| 131 | - //当前用户角色是否被禁用 | ||
| 132 | - $projectRoleModel = new ProjectRoleModel(); | ||
| 133 | - $role_info = $projectRoleModel->read(['id'=>$info['role_id'],'status'=>0]); | ||
| 134 | - if($role_info === false){ | ||
| 135 | - $this->fail('当前用户角色被禁用',Code::USER_REGISTER_ERROE); | ||
| 136 | - } | ||
| 137 | - if(isset($info['token']) && !empty($info['token'])){ | ||
| 138 | - //清除上一次用户缓存 | ||
| 139 | - Cache::pull($info['token']); | ||
| 140 | - } | ||
| 141 | - //生成新token | ||
| 142 | - $token = md5(uniqid().$info['id']); | ||
| 143 | - //存储缓存 | ||
| 144 | - $info['token'] = $token; | ||
| 145 | - Cache::add($token,$info); | ||
| 146 | - $rs = $this->model->edit(['token'=>$token],['id'=>$info['id']]); | ||
| 147 | - if($rs === false){ | ||
| 148 | - $this->fail('系统错误,请联系管理员'); | ||
| 149 | - } | ||
| 150 | - $project = (new ProjectLogic())->getInfo($info['project_id']); | ||
| 151 | - $info['company'] = $project['company'] ?? ''; | ||
| 152 | - $info['plan'] = $project['deploy_build']['plan'][0] ?? ''; | ||
| 153 | - $info['domain'] = !empty($project['deploy_optimize']['domain']) ? $project['deploy_optimize']['domain'] : ($project['deploy_build']['test_domain'] ?? ''); | ||
| 154 | - //写入日志 | ||
| 155 | - Common::set_user_login(['user_id'=>$info['id'],'ip'=>request()->ip()]); | ||
| 156 | - return $this->success($info); | ||
| 157 | - } | ||
| 158 | - | ||
| 159 | - | ||
| 160 | /** | 108 | /** |
| 161 | * @param $param | 109 | * @param $param |
| 162 | * @name :编辑管理员 | 110 | * @name :编辑管理员 |
app/Http/Logic/Bside/User/UserLoginLogic.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Logic\Bside\User; | ||
| 4 | + | ||
| 5 | +use App\Enums\Common\Code; | ||
| 6 | +use App\Helper\Common; | ||
| 7 | +use App\Http\Logic\Aside\Project\ProjectLogic; | ||
| 8 | +use App\Models\SmsLog; | ||
| 9 | +use App\Models\User\ProjectRole as ProjectRoleModel; | ||
| 10 | +use Illuminate\Support\Facades\Cache; | ||
| 11 | + | ||
| 12 | +class UserLoginLogic | ||
| 13 | +{ | ||
| 14 | + /*** | ||
| 15 | + * @name :登录 | ||
| 16 | + * @author :liyuhang | ||
| 17 | + * @method | ||
| 18 | + */ | ||
| 19 | + public function login(){ | ||
| 20 | + //验证账号密码 | ||
| 21 | + $password = base64_encode(md5($this->param['password'])); | ||
| 22 | + $info = $this->model->read(['mobile'=>$this->param['mobile'],'password'=>$password,'status'=>0], ['id','mobile','role_id','token','name','project_id']); | ||
| 23 | + if($info === false){ | ||
| 24 | + //账号密码没通过时,验证验证码 | ||
| 25 | + $info = $this->model->read(['mobile'=>$this->param['mobile'],'status'=>0], ['id','mobile','role_id','token','name','project_id']); | ||
| 26 | + if($info === false){ | ||
| 27 | + $this->fail('账号密码错误',Code::USER_REGISTER_ERROE); | ||
| 28 | + } | ||
| 29 | + //验证验证码是否准备 | ||
| 30 | + $last_sms = SmsLog::getLastLog($this->param['mobile'], SmsLog::TYPE_LOGIN); | ||
| 31 | + if($this->param['password'] != $last_sms->code){ | ||
| 32 | + $this->fail('账号密码错误',Code::USER_REGISTER_ERROE); | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + //当前用户角色是否被禁用 | ||
| 36 | + $projectRoleModel = new ProjectRoleModel(); | ||
| 37 | + $role_info = $projectRoleModel->read(['id'=>$info['role_id'],'status'=>0]); | ||
| 38 | + if($role_info === false){ | ||
| 39 | + $this->fail('当前用户角色被禁用',Code::USER_REGISTER_ERROE); | ||
| 40 | + } | ||
| 41 | + if(isset($info['token']) && !empty($info['token'])){ | ||
| 42 | + //清除上一次用户缓存 | ||
| 43 | + Cache::pull($info['token']); | ||
| 44 | + } | ||
| 45 | + //生成新token | ||
| 46 | + $token = md5(uniqid().$info['id']); | ||
| 47 | + //存储缓存 | ||
| 48 | + $info['token'] = $token; | ||
| 49 | + Cache::add($token,$info); | ||
| 50 | + $rs = $this->model->edit(['token'=>$token],['id'=>$info['id']]); | ||
| 51 | + if($rs === false){ | ||
| 52 | + $this->fail('系统错误,请联系管理员'); | ||
| 53 | + } | ||
| 54 | + $project = (new ProjectLogic())->getInfo($info['project_id']); | ||
| 55 | + $info['company'] = $project['company'] ?? ''; | ||
| 56 | + $info['plan'] = $project['deploy_build']['plan'][0] ?? ''; | ||
| 57 | + $info['domain'] = !empty($project['deploy_optimize']['domain']) ? $project['deploy_optimize']['domain'] : ($project['deploy_build']['test_domain'] ?? ''); | ||
| 58 | + //写入日志 | ||
| 59 | + Common::set_user_login(['user_id'=>$info['id'],'ip'=>request()->ip()]); | ||
| 60 | + return $this->success($info); | ||
| 61 | + } | ||
| 62 | +} |
-
请 注册 或 登录 后发表评论