key_name . '_' . $roles_id; $list = RedisDataServer::creatServer()->getData($key_name, 'json'); if (empty($list)) { if ($roles_id > 0) { //获取对应角色授权ID $permission_ids = Role::where('id', $roles_id)->value('permission_ids'); if (empty($permission_ids)) $permission_ids = [0]; else $permission_ids = explode(',', $permission_ids); } else { $permission_ids = []; } $list = Menu::where('p_id', 0)->where('is_del',0)->where('version',1)->where(function ($query) use ($permission_ids) { if ($permission_ids) { $p_ids= Menu::whereIn('id', $permission_ids)->where('level',1)->pluck('p_id')->toArray(); if(empty($p_ids))$p_ids=[0]; $query->whereIn('id', $p_ids); } })->select(['id', 'menu_name', 'label_name'])->orderBy('sort','desc')->get()->toArray(); foreach ($list as &$item) { $item['items'] = Menu::where('p_id', $item['id'])->where('is_del',0)->where('version',1)->where(function ($query) use ($permission_ids) { if ($permission_ids) $query->whereIn('id', $permission_ids); })->select(['id', 'menu_name', 'url_name'])->orderBy('sort','desc')->get()->toArray(); } RedisDataServer::creatServer()->setData($key_name, $list, 'json', $this->cache_time); } return $list; } /** * 根据角色传递菜单信息 * @param $roles_id */ function sendMenu($roles_id = '') { if (!request()->ajax()) { view()->composer('layouts.admin.menu', function ($view) use ($roles_id) { $menu_list = self::creatServer()->getMenu($roles_id); $view->with('menu_list', $menu_list); }); } } function getPermissionsMenu($r_p) { //当前角色已授权信息 if (is_string($r_p)) { $r_p = explode(',', $r_p); } $permission=[]; //权限信息 $one_p = Menu::where('p_id', 0)->select(['id', 'menu_name as label'])->get(); foreach ($one_p as $key => $item) { $item->{'id'}.=''; $two_list = Menu::where('p_id', $item['id'])->select(['id', 'menu_name as label'])->get(); foreach ($two_list as $t_v) { $t_v->{'id'}.=''; $three_list= Menu::where('p_id', $t_v['id'])->select(['id', 'menu_name as label'])->get(); foreach ($three_list as $three_v){ $three_v->{'id'}.=''; } $t_v->{'children'}=$three_list->toArray(); } $item->{'children'}=$two_list->toArray(); $permission[]=[$item->toArray()]; } return $permission; } /** * 获取系统后台角色对应权限节点 * @param $role_id * @return false|mixed|string[] */ function getRole($role_id){ //获取该角色的权限节点 $key_name = 'role_ids_' . $role_id; $url_ids = RedisDataServer::creatServer()->getData($key_name,'json'); if(empty($url_ids)){ $permission_ids = Role::where('id', $role_id)->value('permission_ids'); $url_ids = explode(',', $permission_ids); RedisDataServer::creatServer()->setData($key_name,$url_ids,'json',7200); } if (empty($url_ids)) { return false; } return $url_ids; } }