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
This commit is contained in:
2026-06-12 20:47:40 +08:00
parent 980f3c9593
commit 395e1c7400
36 changed files with 1193 additions and 153 deletions

View File

@@ -57,3 +57,80 @@ test('credit player wallet logs reads credit_ledger not wallet_txns', function (
->assertJsonPath('data.items.0.biz_type', 'bet_hold')
->assertJsonPath('data.items.0.ledger_source', 'credit_ledger');
});
test('credit player wallet logs distinguish win credit from bill settlement', function (): void {
$player = Player::query()->create([
'site_code' => 'default_site',
'site_player_id' => 'native:logs-2',
'auth_source' => PlayerAuthSource::LOTTERY_NATIVE,
'funding_mode' => PlayerFundingMode::CREDIT,
'username' => 'credit_logs_2',
'default_currency' => 'NPR',
'status' => 0,
]);
DB::table('player_credit_accounts')->insert([
'player_id' => $player->id,
'credit_limit' => 500,
'used_credit' => 0,
'frozen_credit' => 0,
'created_at' => now(),
'updated_at' => now(),
]);
DB::table('credit_ledger')->insert([
[
'owner_type' => 'player',
'owner_id' => $player->id,
'amount' => 3600,
'reason' => 'settlement_payout',
'ref_type' => 'settlement_bill',
'ref_id' => 25,
'created_at' => now()->subMinute(),
'updated_at' => now()->subMinute(),
],
[
'owner_type' => 'player',
'owner_id' => $player->id,
'amount' => 1200,
'reason' => 'game_settlement_win',
'ref_type' => 'ticket_item',
'ref_id' => 99,
'created_at' => now(),
'updated_at' => now(),
],
]);
$response = $this->withHeader('Authorization', 'Bearer dev:'.$player->id)
->getJson('/api/v1/wallet/logs?page=1&size=10');
$response->assertOk()
->assertJsonPath('data.total', 2)
->assertJsonPath('data.items.0.type', 'win_credit')
->assertJsonPath('data.items.0.biz_type', 'game_settlement_win')
->assertJsonPath('data.items.0.affects_available_credit', true)
->assertJsonPath('data.items.1.type', 'bill_settlement')
->assertJsonPath('data.items.1.biz_type', 'settlement_payout')
->assertJsonPath('data.items.1.affects_available_credit', false)
->assertJsonPath('data.items.1.balance_after', null);
expect($response->json('data.items.0.balance_after'))->not->toBeNull();
$this->withHeader('Authorization', 'Bearer dev:'.$player->id)
->getJson('/api/v1/wallet/logs?type=bill_settlement')
->assertOk()
->assertJsonPath('data.total', 1)
->assertJsonPath('data.items.0.type', 'bill_settlement');
$this->withHeader('Authorization', 'Bearer dev:'.$player->id)
->getJson('/api/v1/wallet/logs?type=win_credit')
->assertOk()
->assertJsonPath('data.total', 1)
->assertJsonPath('data.items.0.type', 'win_credit');
$this->withHeader('Authorization', 'Bearer dev:'.$player->id)
->getJson('/api/v1/wallet/logs?type=credit_release')
->assertOk()
->assertJsonPath('data.total', 1)
->assertJsonPath('data.items.0.type', 'win_credit');
});