PermissionServer.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Servers;
  3. use App\Models\Menu;
  4. use App\Models\MenuUrl;
  5. use App\Models\Role;
  6. use App\Models\ShopMenu;
  7. use App\Models\ShopMenuApp;
  8. use App\Models\ShopRole;
  9. /**
  10. * 权限验证
  11. */
  12. class PermissionServer
  13. {
  14. public static function verifyPermission($role_id, $clientRoute,$type=1)
  15. {
  16. $url_list = [
  17. 'admin.index',
  18. 'admin.ajaxIndex',
  19. 'admin.not.permission',
  20. 'admin.oneImage',
  21. 'admin.good.select',
  22. 'admin.send_code',
  23. 'admin.auth.password',
  24. 'admin.auth.password.save',
  25. 'admin.menu.parentMenu',
  26. ];
  27. if (in_array($clientRoute, $url_list)) {
  28. return true;
  29. }
  30. // return true;
  31. $client_id = MenuUrl::where('url', $clientRoute)->where('type',$type)->value('menu_id');
  32. // dd($client_id,$clientRoute);
  33. if (empty($client_id)) {
  34. $client_info = MenuUrl::create([
  35. 'url_name' => '',
  36. 'url' => $clientRoute,
  37. 'menu_id' => 0,
  38. 'status' => 0,
  39. 'type' => $type,
  40. ]);
  41. $client_id = $client_info->{'id'};
  42. }
  43. $cache_name = 'role_url_ids' . $role_id;
  44. $url_ids=RedisDataServer::creatServer()->getData($cache_name,'json');
  45. if(empty($url_ids)){
  46. $permission_ids = Role::where('id', $role_id)->value('permission_ids');
  47. $url_ids = explode(',', $permission_ids);
  48. RedisDataServer::creatServer()->setData($cache_name,$url_ids,'json',30);
  49. }
  50. if (empty($url_ids) || !in_array($client_id, $url_ids)) {
  51. return false;
  52. }
  53. return true;
  54. }
  55. }