- 在 SyncAdminAuthorizationCommand 中新增对代理线路和结算菜单操作的同步功能,确保缺失的菜单操作行能够被创建。 - 更新多个控制器中的权限检查逻辑,使用 hasPermissionCode 替代原有的权限验证方式,提升权限管理的灵活性。 - 在 AdminPlayerStoreController 中引入对玩家创建能力的验证,确保只有具备相应权限的管理员能够创建玩家。 - 更新请求验证逻辑,新增 credit_limit、rebate_rate 和 extra_rebate_rate 字段,以支持更细粒度的玩家管理。 - 在 AdminUser 和 AgentNode 模型中增强角色与用户的权限管理功能,支持更细粒度的权限控制。
102 lines
3.7 KiB
PHP
102 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Support\AdminAgentLineSettlementPermissionMenuActionSync;
|
|
use App\Support\AdminAgentPermissionMenuActionSync;
|
|
use App\Support\AdminAuthorizationRegistry;
|
|
use App\Support\AdminDrawPermissionMenuActionSync;
|
|
|
|
final class SyncAdminAuthorizationCommand extends Command
|
|
{
|
|
protected $signature = 'lottery:admin-auth-sync
|
|
{--audit : 同步完成后立即执行后台权限体检}';
|
|
|
|
protected $description = '根据后台统一注册表同步 admin_api_resources 与 resource_bindings';
|
|
|
|
public function handle(): int
|
|
{
|
|
$now = Carbon::now();
|
|
$agentCreated = AdminAgentPermissionMenuActionSync::syncMissing();
|
|
if ($agentCreated > 0) {
|
|
$this->info(sprintf('Created %d missing agent menu_action row(s).', $agentCreated));
|
|
}
|
|
|
|
$lineSettlementCreated = AdminAgentLineSettlementPermissionMenuActionSync::syncMissing();
|
|
if ($lineSettlementCreated > 0) {
|
|
$this->info(sprintf('Created %d missing agent line/settlement menu_action row(s).', $lineSettlementCreated));
|
|
}
|
|
|
|
$drawCreated = AdminDrawPermissionMenuActionSync::syncMissing();
|
|
if ($drawCreated > 0) {
|
|
$this->info(sprintf('Created %d missing draw menu_action row(s).', $drawCreated));
|
|
}
|
|
|
|
$menuActionIds = DB::table('admin_menu_actions')->pluck('id', 'permission_code');
|
|
|
|
foreach (AdminAuthorizationRegistry::resources() as $resource) {
|
|
$resourceId = DB::table('admin_api_resources')
|
|
->where('code', $resource['code'])
|
|
->value('id');
|
|
|
|
$payload = [
|
|
'module_code' => $resource['module_code'],
|
|
'name' => $resource['name'],
|
|
'http_method' => $resource['http_method'],
|
|
'uri_pattern' => $resource['uri_pattern'],
|
|
'route_name' => $resource['route_name'],
|
|
'auth_mode' => $resource['auth_mode'],
|
|
'is_audit_required' => $resource['is_audit_required'],
|
|
'status' => 1,
|
|
'meta_json' => null,
|
|
'updated_at' => $now,
|
|
];
|
|
|
|
if ($resourceId === null) {
|
|
$resourceId = DB::table('admin_api_resources')->insertGetId($payload + [
|
|
'code' => $resource['code'],
|
|
'created_at' => $now,
|
|
]);
|
|
} else {
|
|
DB::table('admin_api_resources')
|
|
->where('id', (int) $resourceId)
|
|
->update($payload);
|
|
}
|
|
|
|
DB::table('admin_api_resource_bindings')
|
|
->where('api_resource_id', (int) $resourceId)
|
|
->delete();
|
|
|
|
foreach ($resource['permission_codes'] as $permissionCode) {
|
|
$menuActionId = $menuActionIds[$permissionCode] ?? null;
|
|
if ($menuActionId === null) {
|
|
$this->warn(sprintf('跳过未找到的 permission_code: %s', $permissionCode));
|
|
|
|
continue;
|
|
}
|
|
|
|
DB::table('admin_api_resource_bindings')->insert([
|
|
'api_resource_id' => (int) $resourceId,
|
|
'menu_action_id' => (int) $menuActionId,
|
|
'created_at' => $now,
|
|
'updated_at' => $now,
|
|
]);
|
|
}
|
|
}
|
|
|
|
$this->info(sprintf(
|
|
'Admin authorization synced: %d resources.',
|
|
count(AdminAuthorizationRegistry::resources()),
|
|
));
|
|
|
|
if ((bool) $this->option('audit')) {
|
|
return $this->call('lottery:admin-auth-audit');
|
|
}
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|