权限管理
并不是类,只是自己瞎琢磨出来的方法,放在common里面的,反正emmmm….能用就行
use think\Request;
use think\Controller;
use think\Session;
use app\admin\model\RbacUser;
use app\admin\model\RbacRole;
use app\admin\model\RbacAccess;
use app\admin\model\RbacRoleAccess;
use app\admin\model\RbacUserRole;
function getRolePrivilege(){
$rbac_user = new RbacUser();
$rbac_access = new RbacAccess();
$rbac_role_access = new RbacRoleAccess();
$rbac_role = new RbacRole();
$rbac_user_role = new RbacUserRole();
$id = Session::get('u_id');
$role_user = $rbac_user_role->selUserRole($id);
$r_id = $role_user['r_id'];
$access = $rbac_role_access->selRoleAccess($r_id);
$access_url = explode(';', $access['a_id']);
$urls = $rbac_access->selAccessUrl($access_url);
if (!empty($urls)) {
foreach ($urls as $key => $value) {
if ((strpos($value['urls'], ';')) !== false) {
$merge[$key] = explode(';', $value['urls']);
} else {
$url[$key] = $value['urls'];
}
}
$pathData = $_SERVER['REQUEST_URI'];
$data = parse_url($pathData);
$path = $data['path'];
$p = '/';
$pos = newstripos($path, $p, 4);
if ($pos) {
$path = str_replace(substr($path, $pos), '', $path) ;
}
if (!empty($url)) {
array_unshift($merge,$url);
foreach ($merge as $key => $value) {
foreach ($value as $key1 => $value1) {
$url_value[]= $value1;
}
}
if (!in_array($path, $url_value)) {
header("Location:/admin/index/error_page");
die;
}
} else {
foreach ($merge as $key => $value) {
foreach ($value as $key1 => $value1) {
$url_value[]= $value1;
}
}
if (!in_array($path, $url_value)) {
header("Location:/admin/index/error_page");
die;
}
}
}
}
function newstripos($str, $find, $count, $offset=0)
{
$pos = stripos($str, $find, $offset);
$count--;
if ($count > 0 && $pos !== FALSE)
{
$pos = newstripos($str, $find ,$count, $pos+1);
}
return $pos;
}