- 在多个控制器中更新权限检查逻辑,确保管理员能够更灵活地管理代理和玩家。 - 在 AdminPlayerStoreController 中引入对玩家创建能力的验证,确保只有具备相应权限的管理员能够创建玩家。 - 更新请求验证逻辑,新增 credit_limit、rebate_rate 和 extra_rebate_rate 字段,以支持更细粒度的玩家管理。 - 在 AgentNodeProfileController 中添加对父代理能力授予的验证,确保子代理的权限在父代理范围内。 - 引入 AgentProfileFieldRules 以简化代理资料更新请求的规则定义,提升代码复用性。
91 lines
2.8 KiB
PHP
91 lines
2.8 KiB
PHP
<?php
|
|
|
|
use App\Models\AdminUser;
|
|
use App\Models\Player;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
test('admin can write off player bill bad debt and complete period when all settled', function (): void {
|
|
$site = DB::table('admin_sites')->where('is_default', true)->first();
|
|
$agentId = (int) DB::table('agent_nodes')->where('depth', 0)->value('id');
|
|
|
|
$periodId = (int) DB::table('settlement_periods')->insertGetId([
|
|
'admin_site_id' => (int) $site->id,
|
|
'period_start' => now()->subDays(7),
|
|
'period_end' => now(),
|
|
'status' => 'closed',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$player = Player::query()->create([
|
|
'site_code' => (string) $site->code,
|
|
'agent_node_id' => $agentId,
|
|
'site_player_id' => 'bd-p1',
|
|
'auth_source' => 'lottery_native',
|
|
'funding_mode' => 'credit',
|
|
'username' => 'bduser',
|
|
'nickname' => null,
|
|
'default_currency' => 'NPR',
|
|
'status' => 0,
|
|
]);
|
|
|
|
$billId = (int) DB::table('settlement_bills')->insertGetId([
|
|
'settlement_period_id' => $periodId,
|
|
'bill_type' => 'player',
|
|
'owner_type' => 'player',
|
|
'owner_id' => $player->id,
|
|
'counterparty_type' => 'agent',
|
|
'counterparty_id' => $agentId,
|
|
'gross_win_loss' => 10000,
|
|
'rebate_amount' => 0,
|
|
'adjustment_amount' => 0,
|
|
'platform_rounding_adjustment' => 0,
|
|
'net_amount' => 10000,
|
|
'paid_amount' => 0,
|
|
'unpaid_amount' => 10000,
|
|
'status' => 'overdue',
|
|
'confirmed_at' => now(),
|
|
'locked_at' => now(),
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$admin = AdminUser::query()->create([
|
|
'username' => 'bad_debt_super',
|
|
'name' => 'Bad Debt',
|
|
'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/settlement-bills/'.$billId.'/bad-debt-write-off', [
|
|
'reason' => 'uncollectible',
|
|
])
|
|
->assertOk()
|
|
->assertJsonPath('data.original_bill_id', $billId);
|
|
|
|
$this->assertDatabaseHas('settlement_bills', [
|
|
'id' => $billId,
|
|
'status' => 'settled',
|
|
'unpaid_amount' => 0,
|
|
]);
|
|
|
|
$this->assertDatabaseHas('settlement_adjustments', [
|
|
'original_bill_id' => $billId,
|
|
'adjustment_type' => 'bad_debt',
|
|
'amount' => 10000,
|
|
]);
|
|
|
|
$this->assertDatabaseHas('settlement_periods', [
|
|
'id' => $periodId,
|
|
'status' => 'completed',
|
|
]);
|
|
});
|