您好,欢迎来到化拓教育网。
搜索
您的当前位置:首页群控系统服务端开发模式-应用开发-基础框架开发补充

群控系统服务端开发模式-应用开发-基础框架开发补充

来源:化拓教育网

一、总控制补充

        1、权限验证

    //验证权限
    protected function checkRoleMenu($auth){
        if(empty($this->rules) || empty($this->key) || count($this->butts) == 0) $this->setAuth();
        if(!in_array($auth, $this->butts))throw new BaseError("权限不足,请联系管理员",50000,200);//赋值错误信息 权限验证
    }

        2、获取权限

    //获取权限
    protected function getRoleMenu(){
        if(empty($this->rules) || empty($this->key) || count($this->butts) == 0) $this->setAuth();
        $data['key'] = $this->key;
        $data['butts'] = $this->butts;
        return $data;
    }

        3、设置权限

    //设置权限
    protected function setAuth(){
        $resRole = Role::dataFind(['id' => $this->roleId],'role_key,menu_id,status',true);
        if(empty($resRole) || $resRole['status'] !== 1)throw new BaseError("该用户没有权限",50000,200);//赋值错误信息
        $rules = explode(',',$resRole['menu_id']);
        $butt = Redis::select(config('cache.stores.redis.cache_db'))->get('butt_list'.$this->userId);
        if(empty($butt)){
            $this->isUnserialize = false;
            $list = Menu::getAll([['id', 'in', $rules], ['status', '=', 1], ['is_menu', '=', 0]], 'menuname','sort DESC,id DESC');
            if(empty($list))throw new BaseError("该用户没有权限",50000,200);//赋值错误信息
            $butt = array_column($list,'menuname');
            Redis::select(config('cache.stores.redis.cache_db'))->setex('butt_list'.$this->userId,rand(40,80),serialize($butt));
        }
        $this->rules = $rules;
        $this->key = $resRole['role_key'];
        $this->butts = $this->isUnserialize == true ? unserialize($butt) : $butt;
    }

二、给后端添加、编辑、删除操作设置权限访问

        所有的启禁用控制接口、保存接口、删除接口都需要调用权限验证方法。代码如下

$this->checkRoleMenu('PermissionMenuIndexSave');//验证权限

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo9.cn 版权所有 赣ICP备2023008801号-1

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务