fix(settlement): 操作记录分页、流水动作与坏账幂等加固
- 新增 settlement-operations 合并列表 API,收付/调账接口改为标准分页 - actionable_only 流水在内存过滤后正确分页 - 已结账单流水不再展示补差/冲正快捷动作 - 坏账核销支持 idempotency_key 并写入 result_bill_id - 补充操作记录、流水与坏账幂等相关测试
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
<?php
|
||||
|
||||
use App\Models\AdminUser;
|
||||
use App\Models\Player;
|
||||
use App\Models\AdminUser;
|
||||
use App\Models\PlayerWallet;
|
||||
use App\Models\TransferOrder;
|
||||
use App\Services\AgentSettlement\AgentSettlementBadDebtService;
|
||||
use App\Services\AgentSettlement\SettlementPaymentService;
|
||||
use App\Services\Wallet\LotteryTransferService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use App\Services\Wallet\LotteryTransferService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use App\Services\AgentSettlement\SettlementPaymentService;
|
||||
use App\Services\AgentSettlement\AgentSettlementBadDebtService;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
@@ -215,6 +215,70 @@ test('bad debt write off is idempotent when retried', function (): void {
|
||||
->and(DB::table('settlement_adjustments')->where('original_bill_id', $billId)->count())->toBe(1);
|
||||
});
|
||||
|
||||
test('bad debt write off idempotency key prevents duplicate records', 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-idem-key',
|
||||
'auth_source' => 'lottery_native',
|
||||
'funding_mode' => 'credit',
|
||||
'username' => 'bdidemkey',
|
||||
'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' => 5000,
|
||||
'rebate_amount' => 0,
|
||||
'adjustment_amount' => 0,
|
||||
'net_amount' => 5000,
|
||||
'paid_amount' => 0,
|
||||
'unpaid_amount' => 5000,
|
||||
'status' => 'overdue',
|
||||
'confirmed_at' => now(),
|
||||
'locked_at' => now(),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$admin = AdminUser::query()->create([
|
||||
'username' => 'bad_debt_key_admin',
|
||||
'name' => 'Bad Debt Key',
|
||||
'email' => null,
|
||||
'password' => Hash::make('secret-strong'),
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
$service = app(AgentSettlementBadDebtService::class);
|
||||
$key = 'bd-idem-key-1';
|
||||
$first = $service->writeOff($billId, 'uncollectible', (int) $admin->id, $key);
|
||||
$second = $service->writeOff($billId, 'uncollectible', (int) $admin->id, $key);
|
||||
|
||||
expect($second)->toBe($first)
|
||||
->and(DB::table('settlement_adjustments')->where('original_bill_id', $billId)->count())->toBe(1)
|
||||
->and(DB::table('settlement_adjustments')->where('original_bill_id', $billId)->value('idempotency_key'))
|
||||
->toBe($key);
|
||||
});
|
||||
|
||||
test('out pending reconcile reverse still credits lottery wallet once', function (): void {
|
||||
$player = Player::query()->create([
|
||||
'site_code' => 'main',
|
||||
@@ -258,4 +322,4 @@ test('out pending reconcile reverse still credits lottery wallet once', function
|
||||
|
||||
expect((int) $wallet->balance)->toBe(1_400)
|
||||
->and($order->status)->toBe('reversed');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user