亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

系統(tǒng)權(quán)限訪問控制

??? 2019-05-09 16:43:17 254
????:<?php namespace app\admin\controller; use think\Controller; use think\facade\Session; use think\Request; use Util\SysDb; class Base extends Controller { &n
<?php
namespace app\admin\controller;

use think\Controller;
use think\facade\Session;
use think\Request;
use Util\SysDb;

class Base extends Controller
{
    public function __construct(Request $request)
    {
        parent::__construct();
        $this->_admin = Session::get('admin');
        if(!$this->_admin) {
            header('Location:/index.php/admin/account/login');
        }
        $this->assign('admin',$this->_admin);
        // 限制用戶訪問權(quán)限
        $group = SysDb::getnstance()->table('admin_groups')->where(['gid'=>$this->_admin['gid']])->item();
        if(!$group) {
            $this->RequestError('對不起,您沒有權(quán)限');
        }
        $rights = json_decode($group['rights']);

        // 當(dāng)前控制名稱
        $controller = $request->controller();
        // 方法名稱
        $method  = $request->action();
        // 獲取菜單表數(shù)據(jù)
        $res = SysDb::getnstance()->table('admin_menus')->where(['controller'=>$controller,'method'=>$method])->item();
        if(!$res) {
            $this->RequestError('對不起,您訪問的功能不存在');
        }

        // 查看是否唄禁用
        if($res['status'] == 1){
            $this->RequestError('對不起,該功能已禁止使用');
        }

        // 查看菜單權(quán)限
        if(!in_array($res['mid'],$rights)) {
            $this->RequestError('對不起,您沒有權(quán)限');
        }

    }

    // 處理返回數(shù)據(jù)
    private function RequestError($msg)
    {
        $request = new  Request();
        if($request->isAjax()) {
            $this->error(['code'=>0,'msg'=>$msg]);
            //exit(['code'=>0,'msg'=>$msg]);
        }
        $this->error($msg);
        //exit($msg);
    }
}


?? ???:查無此人?? ??:2019-05-10 14:13:26
???? ??:完成的不錯。后臺管理系統(tǒng),最主要的就是權(quán)限,以免別人破解。繼續(xù)加油。

??? ??

?? ??