FilterPermission.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace app\v1\middleware;
  3. use plugin\saiadmin\app\cache\UserInfoCache;
  4. use Webman\Http\Request;
  5. use Webman\Http\Response;
  6. use Webman\MiddlewareInterface;
  7. /**
  8. * 权限检查中间件
  9. */
  10. class FilterPermission implements MiddlewareInterface
  11. {
  12. public function process(Request $request, callable $handler) : Response
  13. {
  14. // 根据用户id获取用户权限
  15. $token = getCurrentInfo();
  16. // 用户权限缓存
  17. $userAuthCache = new UserInfoCache($token['id']);
  18. $user_info = $userAuthCache->getUserInfo();
  19. // 获取游戏数据权限
  20. $auth_game_list = $user_info['game_list'] ?? -1;
  21. // 获取游戏自然量数据权限
  22. $auth_normal_game_list = $user_info['normal_game_list'] ?? -1;
  23. // 获取游戏自然量数据权限
  24. $auth_ad_permission = $user_info['ad_permission'] ?? -1;
  25. $request->setGet(['auth_normal_game_list' => $auth_normal_game_list==='*'?'':$auth_normal_game_list,'auth_game_list' => $auth_game_list==='*'?'':$auth_game_list,'auth_ad_permission' => $auth_ad_permission==='*'?'':$auth_ad_permission]);
  26. return $handler($request);
  27. }
  28. }