Files
lotteryLaravel/database/seeders/AdminRbacAndUserSeeder.php
kang 395e1c7400 feat: refactor super admin to use is_super_admin flag and enhance site deletion logic
- Changed super admin detection from role-based to `is_super_admin` flag in AdminUser model
- Added `requireDefaultAdminSiteId()` method to throw validation error when no integration site exists
- Enhanced site deletion to migrate platform role bindings to fallback site and auto-delete site-specific admin accounts
- Made agent line code optional with auto-generation fallback using `{site_code}-agent-{counter}` format
2026-06-12 20:47:40 +08:00

42 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace Database\Seeders;
use App\Models\AdminUser;
use Illuminate\Database\Seeder;
use App\Support\AdminAgentPermissionMenuActionSync;
use App\Support\AdminDrawPermissionMenuActionSync;
use App\Support\PlatformSystemRoles;
use App\Support\SuperAdminAccount;
/**
* 后台 RBAC平台固定角色 super_admin / agent。
*
* 演示账号 **admin** / **123456**(仅限非 production
*/
final class AdminRbacAndUserSeeder extends Seeder
{
public function run(): void
{
AdminAgentPermissionMenuActionSync::syncMissing();
AdminDrawPermissionMenuActionSync::syncMissing();
PlatformSystemRoles::ensureAll();
$username = 'admin';
AdminUser::query()->updateOrCreate(
['username' => $username],
[
'name' => '超级管理员',
'email' => null,
'password' => '123456',
'status' => 0,
],
);
/** @var AdminUser $admin */
$admin = AdminUser::query()->where('username', $username)->firstOrFail();
SuperAdminAccount::assign($admin);
}
}