修复登录逻辑错误,优化异常信息返回。

This commit is contained in:
mkm 2024-05-24 15:16:44 +08:00
parent 061db1d927
commit 8c137736cd
3 changed files with 8 additions and 2 deletions

@ -12,7 +12,7 @@ class MyBusinessException extends BusinessException
{
// json请求返回json数据
if ($request->expectsJson()) {
return json(['code' => $this->getCode() ?: 500, 'message' => $this->getMessage(),'show'=>1]);
return json(['code' => $this->getCode() ?: 500, 'msg' => $this->getMessage(),'show'=>1]);
}
// 非json请求则返回一个页面
return new Response(200, [], $this->getMessage());

@ -38,6 +38,7 @@ class LoginController extends BaseAdminController
public function account()
{
$params = (new LoginValidate())->post()->goCheck();
$params['is_admin']=$this->request->post('is_admin',1);
return $this->data((new LoginLogic())->login($params));
}

@ -17,6 +17,7 @@ namespace app\admin\logic;
use app\common\logic\BaseLogic;
use app\common\model\auth\Admin;
use app\admin\service\AdminTokenService;
use app\common\model\auth\AdminRole;
use app\common\service\FileService;
use app\MyBusinessException;
use think\facade\Db;
@ -43,12 +44,16 @@ class LoginLogic extends BaseLogic
{
$time = time();
$admin = Admin::where('account', '=', $params['account'])->find();
if(isset($params['is_admin']) &&$params['is_admin'] == 0 &&$admin){
if($params['is_admin'] == 0 &&$admin){
$auth_shop=Db::name('user_auth_shop')->where(['admin_id'=>$admin['id'],'status'=>1,'apply_status'=>1,'type'=>2])->find();
if(!$auth_shop){
throw new MyBusinessException('该账户没有权限');
}
}
if($admin &&$params['is_admin'] == 1){
$role_find=AdminRole::where('admin_id',$admin['id'])->where('role_id',1)->find();
if($role_find) throw new MyBusinessException('请使用供应商后台登录');
}
//用户表登录信息更新
$admin->login_time = $time;
$admin->login_ip = request()->getLocalIp();