添加权限检查到管理员登录逻辑

This commit is contained in:
mkm 2024-05-24 11:14:59 +08:00
parent 70e58fe432
commit c7fd3bd5f2
3 changed files with 14 additions and 1 deletions

View File

@ -18,7 +18,9 @@ use app\common\logic\BaseLogic;
use app\common\model\auth\Admin;
use app\admin\service\AdminTokenService;
use app\common\service\FileService;
use think\facade\Db;
use Webman\Config;
use support\exception\BusinessException;
/**
* 登录逻辑
@ -41,7 +43,12 @@ class LoginLogic extends BaseLogic
{
$time = time();
$admin = Admin::where('account', '=', $params['account'])->find();
if(isset($params['is_admin']) &&$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 BusinessException('该账户没有权限', 1);
}
}
//用户表登录信息更新
$admin->login_time = $time;
$admin->login_ip = request()->getLocalIp();

View File

@ -58,6 +58,7 @@ class LoginMiddleware implements MiddlewareInterface
//给request赋值用于控制器
$request->adminInfo = $adminInfo;
$request->adminId = $adminInfo['admin_id'] ?? 0;
$request->supplierId = $adminInfo['supplier_id'] ?? 0;
return $handler($request);
}

View File

@ -9,6 +9,7 @@ use app\common\model\auth\AdminSession;
use app\common\model\auth\SystemRole;
use app\common\model\BaseModel;
use support\Cache;
use think\facade\Db;
class AdminTokenCache extends BaseCache
{
@ -65,6 +66,9 @@ class AdminTokenCache extends BaseCache
$roleName = '系统管理员';
} else {
foreach ($admin['role_id'] as $roleId) {
if($roleId==1){
$auth_shop=Db::name('user_auth_shop')->where(['admin_id'=>$admin['id'],'status'=>1,'apply_status'=>1,'type'=>2])->find();
}
$roleName .= $roleLists[$roleId] ?? '';
$roleName .= '/';
}
@ -73,6 +77,7 @@ class AdminTokenCache extends BaseCache
$adminInfo = [
'admin_id' => $admin->id,
'supplier_id' => $auth_shop?$auth_shop['id']:0,
'root' => $admin->root,
'name' => $admin->name,
'account' => $admin->account,