权限表1111111

CREATE TABLE `tbl_permissions` (

`id` int(10) unsigned NOT NULL AUTO_INCREMENT,

`name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,

`module_name` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL,

`display_name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,

`display_order` int(11) DEFAULT NULL COMMENT '显示排序',

`description` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,

`disabled` tinyint(2) NOT NULL DEFAULT '0' COMMENT '废弃状态1废弃0正常',

`created_at` timestamp NULL DEFAULT NULL,

`updated_at` timestamp NULL DEFAULT NULL,

PRIMARY KEY (`id`) USING BTREE,

UNIQUE KEY `permissions_name_unique` (`name`) USING BTREE

) ENGINE=InnoDB AUTO_INCREMENT=206 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPACT COMMENT='权限';

CREATE TABLE `tbl_roles` (

`id` int(10) unsigned NOT NULL AUTO_INCREMENT,

`channel_id` int(10) DEFAULT NULL COMMENT '渠道id',

`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,

`display_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,

`description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,

`status` tinyint(1) DEFAULT '1' COMMENT '1正常 2 冻结',

`created_at` timestamp NULL DEFAULT NULL,

`updated_at` timestamp NULL DEFAULT NULL,

`role_type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '部门的类型1渠道2集团',

`able_id` int(11) DEFAULT NULL COMMENT '关联id',

`able_type` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '关联Models',

PRIMARY KEY (`id`) USING BTREE,

UNIQUE KEY `roles_name_unique` (`name`) USING BTREE

) ENGINE=InnoDB AUTO_INCREMENT=124 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPACT COMMENT='后台角色表';

CREATE TABLE `tbl_permission_role` (

`permission_id` int(10) unsigned NOT NULL,

`role_id` int(10) unsigned NOT NULL,

PRIMARY KEY (`permission_id`,`role_id`) USING BTREE,

KEY `permission_role_role_id_foreign` (`role_id`) USING BTREE

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPACT COMMENT='权限角色关联';

CREATE TABLE `tbl_roles` (

`id` int(10) unsigned NOT NULL AUTO_INCREMENT,

`channel_id` int(10) DEFAULT NULL COMMENT '渠道id',

`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,

`display_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,

`description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,

`status` tinyint(1) DEFAULT '1' COMMENT '1正常 2 冻结',

`created_at` timestamp NULL DEFAULT NULL,

`updated_at` timestamp NULL DEFAULT NULL,

`role_type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '部门的类型1渠道2集团',

`able_id` int(11) DEFAULT NULL COMMENT '关联id',

`able_type` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '关联Models',

PRIMARY KEY (`id`) USING BTREE,

UNIQUE KEY `roles_name_unique` (`name`) USING BTREE

) ENGINE=InnoDB AUTO_INCREMENT=124 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPACT COMMENT='后台角色表';

CREATE TABLE `tbl_role_user` (

`user_id` int(10) unsigned NOT NULL,

`role_id` int(10) unsigned NOT NULL,

PRIMARY KEY (`user_id`,`role_id`) USING BTREE,

KEY `role_user_role_id_foreign` (`role_id`) USING BTREE

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPACT COMMENT='角色用户对应表';

复制代码
 /**获取所有模块
     * @auther ifehrim@gmail.com
     * @return array
     */
    public static function reArray()
    {
        $res = [];
        $res1 = [];
        $data = [];
        $permission = request('permission',false); //区别操作日志模块调用和权限模块调用(权限模块调用传1 )

        $query = NewPermission::where(['disabled'=> 0]);

        if($permission) $query->where('is_show_left',$permission);

        $arr = $query->orderBy('display_order','desc')->get(['id','name','module_name','display_name','display_order','description','disabled','is_show_left'])->toArray();

        if (!empty($arr)) {
            foreach ($arr as $key=>$item) {
                $r = explode(".", $item["name"]);
                if (count($r) == 2) {
                    if (!isset($res[$item["module_name"]][$r[0]])) {
                        $data[$item["module_name"]]['name'] = $item["module_name"];
                        $data[$item["module_name"]]['children'][$item['display_name']][] = $item;
                    }
                }
            }

            foreach ($data as $k=>&$v) {
                if(isset($v['children'])) $res[] = array_values($v['children']);
            }

            foreach ($res as $k1=>&$v1) {
                if(isset($v1[0]) && isset($v1[0][0])){
                    $res1[$k1]['name'] =  $v1[0][0]['module_name'];
                    $res1[$k1]['children'] = $v1;
                }
            }
        }
        return $res1;
    }

}

//左侧栏

复制代码
static public function getUserPermission()
 {
     $user= auth()->user();
     $result = NewRoleUser::getPermissionIds($user->id);
     $permission_ids ['permission_id']= !empty($result) ? array_values(array_unique(array_column($result,'new_permission_id'))) : [];
     $permission_ids['user_info']['username'] = $user['username'];
     $permission_ids['user_info']['phone'] = $user['phone'];
     $permission_ids['user_info']['u_type'] = $user['u_type'];
     $permission_ids['user_info']['cname'] = $user['u_type'] == 3 ? $user['channel_name'] : $user['group_name'];
     if($user['u_type'] == 1)  $permission_ids['user_info']['cname'] = '智能科技发展(上海)有限公司';
     $permission_ids['user_info']['cid'] = '';

     if($user->able_id >= 0 && $user->able_type){
         if($user->able instanceof NewChannel) {
             $permission_ids['user_info']['cname'] =  $user->able->channel_name;
             $permission_ids['user_info']['cid'] =  $user->able->cid;
             $permission_ids['user_info']['group_type'] =  0;
         }
         if($user->able instanceof Bloc) {
             $permission_ids['user_info']['cname'] =  $user->able->full_name;
             $permission_ids['user_info']['cid'] =  $user->able->id;
             $permission_ids['user_info']['group_type'] =  $user->able->id;
         }
     }

     return $permission_ids;
 }
相关推荐
superman超哥23 分钟前
04 深入 Oracle 并发世界:MVCC、锁、闩锁、事务隔离与并发性能优化的探索
数据库·oracle·性能优化·dba
engchina1 小时前
Neo4j 和 Python 初学者指南:如何使用可选关系匹配优化 Cypher 查询
数据库·python·neo4j
engchina1 小时前
使用 Cypher 查询语言在 Neo4j 中查找最短路径
数据库·neo4j
尘浮生1 小时前
Java项目实战II基于Spring Boot的光影视频平台(开发文档+数据库+源码)
java·开发语言·数据库·spring boot·后端·maven·intellij-idea
威哥爱编程1 小时前
SQL Server 数据太多如何优化
数据库·sql·sqlserver
小华同学ai1 小时前
AJ-Report:一款开源且非常强大的数据可视化大屏和报表工具
数据库·信息可视化·开源
Acrelhuang2 小时前
安科瑞5G基站直流叠光监控系统-安科瑞黄安南
大数据·数据库·数据仓库·物联网
十叶知秋2 小时前
【jmeter】jmeter的线程组功能的详细介绍
数据库·jmeter·性能测试
瓜牛_gn4 小时前
mysql特性
数据库·mysql
奶糖趣多多5 小时前
Redis知识点
数据库·redis·缓存