Commit 0b4be6e3 by 朱继来

调整权限

parent 290575fb
......@@ -5,6 +5,7 @@
use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Illuminate\Support\Facades\Redis;
class PermController extends Controller
{
......@@ -21,21 +22,60 @@
if (!$userPerms) return false;
$parse_url = parse_url($request->url()); // 页面url
$path = $parse_url['path']; // path路径
if (preg_match('/\/web\//', $path)) {
$permId = str_replace('/web/','',$path);
} else {
$permId = str_replace('/', '', $path);
}
$permId = $permId . '_check'; // 路径查看权限
if (!isset($parse_url['path'])) {
if (in_array('apply_access', $userPerms)) return true; // 访问权限存在,则返回true
}
$key = Config('perm_args.perm_menus_data');
$redis = Redis::connection('read');
$menus = $redis->get($key);
if (!$menus) {
$menuconfig = DB::table('config')->where('config_title', '订单系统')->first();
if (!$menuconfig) return false;
$menus = json_decode($menuconfig->config_data);
$menu_href = [];
$this->getAllMenus($menus, $menu_href); // 获取所有菜单href
$expire = Config('perm_args.perm_menus_data_expire'); // 缓存两小时
Redis::setex($key, $expire, json_encode($menu_href));
} else {
$menu_href = json_decode($menus);
}
$path = $parse_url['path']; // path路径
if (in_array('apply_access', $userPerms) && in_array($permId, $userPerms)) return true; // 访问及路径权限存在,则返回true
if (in_array($path, $menu_href)) {
if (preg_match('/\/web\//', $path)) {
$permId = str_replace('/web/','',$path);
} else {
$permId = str_replace('/', '', $path);
}
$permId = $permId . '_check'; // 路径查看权限
if (in_array('apply_access', $userPerms) && in_array($permId, $userPerms)) return true; // 访问及路径权限存在,则返回true
} else {
if (in_array('apply_access', $userPerms)) return true; // 访问权限存在,则返回true
}
return false;
}
// 检查路径是否存在于菜单
public function getAllMenus($menus, &$menu_href)
{
foreach ($menus as $k => $v) {
if (count($v->childs) > 0) $this->getAllMenus($v->childs, $menu_href);
if (strlen($v->href) > 1) $menu_href[] = $v->href;
}
}
// 获取系统信息
public function getBusinessInfo()
{
......
......@@ -67,4 +67,8 @@ return [
// 自营角色 无法查看联营订单
'self_roles' => [6, 7, 10, 11, 12],
// 菜单key
'perm_menus_data' => 'order_menus_href_data',
'perm_menus_data_expire' => 7200,
];
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment