权限分配

This commit is contained in:
liu
2026-06-17 12:49:44 +08:00
parent f63a7db58f
commit a5eb91fadd
2 changed files with 34 additions and 89 deletions
+26 -24
View File
@@ -775,33 +775,35 @@ class SysRuleSeeder extends Seeder
->select(DB::raw('1 as role_id'), 'id')
);
// 创建"商户"角色分配商户门户权限
$merchantRoleExists = DB::table('sys_role')->where('name', '商户')->exists();
if (! $merchantRoleExists) {
$merchantRoleId = DB::table('sys_role')->insertGetId([
'name' => '商户',
'status' => 1,
'created_at' => now(),
'updated_at' => now(),
]);
// 商户角色分配 merchant.portal.* 及 dashboard 权限
$portalRuleIds = DB::table('sys_rule')
->where('status', 1)
->where(function ($query) {
$query->where('key', 'LIKE', 'merchant.portal%')
->orWhere('key', 'dashboard')
->orWhere('key', 'dashboard.analysis');
})
->pluck('id');
// 为商户角色分配 merchant.portal.* 及 dashboard 权限
$portalRuleIds = DB::table('sys_rule')
->where('status', 1)
->where(function ($query) {
$query->where('key', 'LIKE', 'merchant.portal.%')
->orWhere('key', 'dashboard')
->orWhere('key', 'dashboard.analysis');
})
->pluck('id');
$insertData = $portalRuleIds->map(fn ($ruleId) => [
'role_id' => $merchantRoleId,
DB::table('sys_role_rule')->insert(
$portalRuleIds->map(fn ($ruleId) => [
'role_id' => 3,
'rule_id' => $ruleId,
])->toArray();
])->toArray()
);
DB::table('sys_role_rule')->insert($insertData);
}
// 为管理员角色分配所有启用权限,排除 merchant.portal.*(商户门户权限)
$adminRuleIds = DB::table('sys_rule')
->where('status', 1)
->where('key', 'NOT LIKE', 'merchant.portal%')
->pluck('id');
DB::table('sys_role_rule')->insert(
$adminRuleIds->map(fn ($ruleId) => [
'role_id' => 2,
'rule_id' => $ruleId,
])->toArray()
);
}
/**