作者 lyh

gx

@@ -6,6 +6,7 @@ use App\Enums\Common\Code; @@ -6,6 +6,7 @@ use App\Enums\Common\Code;
6 use App\Http\Logic\Aside\LoginLogic; 6 use App\Http\Logic\Aside\LoginLogic;
7 use App\Models\Manage\Group; 7 use App\Models\Manage\Group;
8 use App\Models\Manage\Manage; 8 use App\Models\Manage\Manage;
  9 +use App\Models\Manage\Menu;
9 use Closure; 10 use Closure;
10 use Illuminate\Http\Request; 11 use Illuminate\Http\Request;
11 use Illuminate\Support\Facades\Route; 12 use Illuminate\Support\Facades\Route;
@@ -32,7 +33,44 @@ class LoginAuthMiddleware @@ -32,7 +33,44 @@ class LoginAuthMiddleware
32 return response(['code'=> Code::USER_LOGIN_ERROE,'msg'=>'当前用户被禁用']); 33 return response(['code'=> Code::USER_LOGIN_ERROE,'msg'=>'当前用户被禁用']);
33 } 34 }
34 } 35 }
35 - //TODO::查看当前角色是否被禁用 36 + $groupInfo = $this->getGroup($manage);
  37 + //获取当前操作的路由name
  38 + $action = Route::currentRouteName();
  39 + //TODO::操作权限
  40 + $this->viewOperateAuth($groupInfo,$action);
36 return $next($request); 41 return $next($request);
37 } 42 }
  43 +
  44 + /**
  45 + * @remark :查看角色是否被禁用
  46 + * @name :getGroup
  47 + * @author :lyh
  48 + * @method :post
  49 + * @time :2023/7/28 15:26
  50 + */
  51 + public function getGroup($manage){
  52 + $groupModel = new Group();
  53 + $groupInfo = $groupModel->read(['id'=>$manage['gid']]);
  54 + if($groupInfo['status'] != 0){
  55 + return response(['code'=> Code::USER_LOGIN_ERROE,'msg'=>'当前用户角色被禁用']);
  56 + }
  57 + return $groupInfo;
  58 + }
  59 +
  60 + /**
  61 + * @remark :查看操作权限
  62 + * @name :viewOperateAuth
  63 + * @author :lyh
  64 + * @method :post
  65 + * @time :2023/7/28 14:56
  66 + */
  67 + public function viewOperateAuth($groupInfo,$action){
  68 + $menuModel = new Menu();
  69 + $menu_id = $menuModel->read(['route_name'=>$action],['id']);
  70 + if($menu_id !== false){
  71 + if(strpos($groupInfo['rights'], $menu_id['id']) < 0){
  72 + return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'当前用户没有权限']);
  73 + }
  74 + }
  75 + }
38 } 76 }
@@ -28,7 +28,7 @@ class LoginAuthMiddleware @@ -28,7 +28,7 @@ class LoginAuthMiddleware
28 return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'当前用户未登录']); 28 return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'当前用户未登录']);
29 } 29 }
30 $role_info = $this->setRole($info); 30 $role_info = $this->setRole($info);
31 - //获取当前操作的控制器与方法 31 + //获取当前操作的路由name
32 $action = Route::currentRouteName(); 32 $action = Route::currentRouteName();
33 //查询当前用户是否拥有权限操作 33 //查询当前用户是否拥有权限操作
34 $this->viewOperateAuth($role_info,$action); 34 $this->viewOperateAuth($role_info,$action);