1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace App\Servers;
- use App\Models\Menu;
- use App\Models\MenuUrl;
- use App\Models\Role;
- use App\Models\ShopMenu;
- use App\Models\ShopMenuApp;
- use App\Models\ShopRole;
- /**
- * 权限验证
- */
- class PermissionServer
- {
- public static function verifyPermission($role_id, $clientRoute,$type=1)
- {
- $url_list = [
- 'admin.index',
- 'admin.ajaxIndex',
- 'admin.not.permission',
- 'admin.oneImage',
- 'admin.good.select',
- 'admin.send_code',
- 'admin.auth.password',
- 'admin.auth.password.save',
- 'admin.menu.parentMenu',
- ];
- if (in_array($clientRoute, $url_list)) {
- return true;
- }
- // return true;
- $client_id = MenuUrl::where('url', $clientRoute)->where('type',$type)->value('menu_id');
- // dd($client_id,$clientRoute);
- if (empty($client_id)) {
- $client_info = MenuUrl::create([
- 'url_name' => '',
- 'url' => $clientRoute,
- 'menu_id' => 0,
- 'status' => 0,
- 'type' => $type,
- ]);
- $client_id = $client_info->{'id'};
- }
- $cache_name = 'role_url_ids' . $role_id;
- $url_ids=RedisDataServer::creatServer()->getData($cache_name,'json');
- if(empty($url_ids)){
- $permission_ids = Role::where('id', $role_id)->value('permission_ids');
- $url_ids = explode(',', $permission_ids);
- RedisDataServer::creatServer()->setData($cache_name,$url_ids,'json',30);
- }
- if (empty($url_ids) || !in_array($client_id, $url_ids)) {
- return false;
- }
- return true;
- }
- }
|