feat: 增强代理和玩家管理功能

- 在多个控制器中更新权限检查逻辑,确保管理员能够更灵活地管理代理和玩家。
- 在 AdminPlayerStoreController 中引入对玩家创建能力的验证,确保只有具备相应权限的管理员能够创建玩家。
- 更新请求验证逻辑,新增 credit_limit、rebate_rate 和 extra_rebate_rate 字段,以支持更细粒度的玩家管理。
- 在 AgentNodeProfileController 中添加对父代理能力授予的验证,确保子代理的权限在父代理范围内。
- 引入 AgentProfileFieldRules 以简化代理资料更新请求的规则定义,提升代码复用性。
This commit is contained in:
2026-06-04 18:00:50 +08:00
parent 96545f87f6
commit a44679665d
183 changed files with 10054 additions and 857 deletions

View File

@@ -11,7 +11,7 @@ beforeEach(function (): void {
$this->artisan('lottery:admin-auth-sync')->assertExitCode(0);
});
test('super admin can provision agent line with aligned root code', function (): void {
test('super admin can provision root agent on existing integration site', function (): void {
$admin = AdminUser::query()->create([
'username' => 'line_super',
'name' => 'Line Super',
@@ -23,21 +23,29 @@ test('super admin can provision agent line with aligned root code', function ():
$token = $admin->createToken('test', ['*'], now()->addDay())->plainTextToken;
$this->withHeader('Authorization', 'Bearer '.$token)
->postJson('/api/v1/admin/integration-sites', [
'code' => 'line-alpha',
'name' => 'Line Alpha Site',
'status' => 1,
])
->assertCreated()
->assertJsonPath('data.code', 'line-alpha');
$response = $this->withHeader('Authorization', 'Bearer '.$token)
->postJson('/api/v1/admin/agent-lines', [
'site_code' => 'line-alpha',
'code' => 'line-alpha',
'name' => 'Line Alpha',
'username' => 'line_alpha_owner',
'password' => 'secret-strong',
'currency_code' => 'NPR',
'status' => 1,
])
->assertCreated()
->assertJsonPath('data.code', 'line-alpha')
->assertJsonPath('data.agent_node.code', 'line-alpha')
->assertJsonPath('data.line_root.site_code', 'line-alpha')
->assertJsonPath('data.secrets.sso_jwt_secret', fn ($v) => is_string($v) && $v !== '')
->assertJsonPath('data.secrets.wallet_api_key', fn ($v) => is_string($v) && $v !== '');
->assertJsonMissingPath('data.secrets');
$siteId = (int) DB::table('admin_sites')->where('code', 'line-alpha')->value('id');
expect($siteId)->toBeGreaterThan(0);
@@ -55,7 +63,48 @@ test('super admin can provision agent line with aligned root code', function ():
)->toBe(1);
});
test('non super admin cannot create integration site directly', function (): void {
test('agent line provision rejects site that already has root', function (): void {
$admin = AdminUser::query()->create([
'username' => 'line_super2',
'name' => 'Line Super 2',
'email' => null,
'password' => Hash::make('secret-strong'),
'status' => 0,
]);
grantSuperAdminRole($admin);
$token = $admin->createToken('test', ['*'], now()->addDay())->plainTextToken;
$this->withHeader('Authorization', 'Bearer '.$token)
->postJson('/api/v1/admin/integration-sites', [
'code' => 'line-beta',
'name' => 'Line Beta Site',
])
->assertCreated();
$this->withHeader('Authorization', 'Bearer '.$token)
->postJson('/api/v1/admin/agent-lines', [
'site_code' => 'line-beta',
'code' => 'line-beta',
'name' => 'Line Beta',
'username' => 'line_beta_owner',
'password' => 'secret-strong',
])
->assertCreated();
$this->withHeader('Authorization', 'Bearer '.$token)
->postJson('/api/v1/admin/agent-lines', [
'site_code' => 'line-beta',
'code' => 'line-beta-2',
'name' => 'Line Beta 2',
'username' => 'line_beta_owner2',
'password' => 'secret-strong',
])
->assertStatus(422)
->assertJsonPath('data.errors.site_code.0', 'site_root_exists');
});
test('integration manager with site.manage can create integration site', function (): void {
$siteId = (int) DB::table('admin_sites')->where('is_default', true)->value('id');
$admin = AdminUser::query()->create([
'username' => 'line_ops',
@@ -98,8 +147,9 @@ test('non super admin cannot create integration site directly', function (): voi
$this->withHeader('Authorization', 'Bearer '.$token)
->postJson('/api/v1/admin/integration-sites', [
'code' => 'blocked-site',
'name' => 'Blocked',
'code' => 'ops-site',
'name' => 'Ops Site',
])
->assertForbidden();
->assertCreated()
->assertJsonPath('data.code', 'ops-site');
});