2023-01-29 10:26:52 +08:00

105 lines
3.1 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | 小说系统 [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
namespace app\common\controller;
use app\common\model\AuthGroup;
use app\common\model\AuthRule;
class Admin extends Base {
public function _initialize() {
parent::_initialize();
//此处为解决Uploadify出现http 302错误 重新设置SESSION
if(isset($_POST['session'])) {
session_id($_POST['session']);
session_start();
}
if (!is_login() and !in_array($this->url, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
$this->redirect('admin/index/login');
}
if (!in_array($this->url, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
//获取公众号
$this->assign('site','');
//菜单设置
$this->setMenu();
$this->setMeta();
}
}
final protected function checkRule($group,$url) {
$is = false;
$RuleId = db('auth_rule')->where('name',$url)->value('id');
if(empty($RuleId)){
return false;
}
$Rules = db('auth_group')->where('id',$group)->value('rules');
$Rules = explode(',',$Rules);
foreach($Rules as $k=>$v){
if($RuleId==$v){
$is = true;
}
}
return $is;
}
protected function setMenu() {
//一级分类
$category = array();
$controller = $this->url;
$where['pid'] = 0;
$where['hide'] = 0;
$where['type'] = 'admin';
$category = db('menu')->field('id,title,url,icon,"" as style')->where($where)->order('sort asc')->select();
$categoryisid = session('user_auth.uid');
$u_group = session('user_auth.group');
foreach ($category as $key => $value) {
$isOneRule = $this->checkRule($u_group,$value['url']);
if ($u_group != 999 && $isOneRule==false) {
unset($category[$key]);
continue; //继续循环
}
}
foreach ($category as $k => $v ) {
if (strpos($v['url'],$controller) !==false) {
$category [$k]['style'] = "active";
}
$where = array();
$where['pid'] = $v['id'];
$where['hide'] = 0;
$second_urls = db('Menu')->where($where)->field('id,pid,title,url,icon,tip')->order('sort')->select();
// 检测2级菜单权限
$to_check_urls = array();
foreach ($second_urls as $key=>$value) {
if ($controller == $value['url']) {
$second_urls[$key]['style'] = "active";
}else{
$pid = db('Menu')->where(['url'=>$controller,'hide'=>0])->where('group','')->value('pid');
if($pid){
$third_url = db('Menu')->where(['id'=>$pid,'hide'=>0])->value('url');
if($third_url == $value['url']){
$second_urls[$key]['style'] = "active";
}else{
$second_urls[$key]['style'] = "";
}
}else{
$second_urls[$key]['style'] = "";
}
}
$isTreeRule = $this->checkRule($u_group,$value['url']);
if ($u_group !=999 && $isTreeRule==false) {
unset($second_urls[$key]);
continue; //继续循环
}
}
$category [$k]['doc'] = $second_urls;
}
$this->assign('__menu__', $category);
}
}