权限表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;
 }
相关推荐
了一li1 小时前
Qt中的QProcess与Boost.Interprocess:实现多进程编程
服务器·数据库·qt
码农君莫笑2 小时前
信管通低代码信息管理系统应用平台
linux·数据库·windows·低代码·c#·.net·visual studio
别致的影分身2 小时前
使用C语言连接MySQL
数据库·mysql
京东零售技术4 小时前
“慢”增长时代的企业数据体系建设:超越数据中台
数据库
sdaxue.com4 小时前
帝国CMS:如何去掉帝国CMS登录界面的认证码登录
数据库·github·网站·帝国cms·认证码
o(╥﹏╥)5 小时前
linux(ubuntu )卡死怎么强制重启
linux·数据库·ubuntu·系统安全
阿里嘎多学长5 小时前
docker怎么部署高斯数据库
运维·数据库·docker·容器
Yuan_o_5 小时前
Linux 基本使用和程序部署
java·linux·运维·服务器·数据库·后端
Sunyanhui15 小时前
牛客网 SQL36查找后排序
数据库·sql·mysql
老王笔记5 小时前
MHA binlog server
数据库·mysql