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;
}