feat: 增强奖池与钱包服务的多币种支持能力
更新 JackpotManualBurstService:在解析头奖中奖者时支持币种代码处理。 重构 SettlementBatchWorkflowService:按币种聚合玩家派奖金额,确保各币种结算准确入账。 修改 SettlementOrchestrator:按币种分别处理奖池爆奖流程,提升派奖准确性。 优化 TicketWalletService:在派奖幂等键中加入币种信息,避免多币种场景下的重复处理问题。 新增测试用例,验证多币种派奖场景及待处理交易的正确处理逻辑。
This commit is contained in:
@@ -411,3 +411,195 @@ test('settlement reject reverts tickets to pending_draw and allows re-settlement
|
||||
expect($item->status)->toBe('settled_win')
|
||||
->and($draw->status)->toBe(DrawStatus::Settled->value);
|
||||
});
|
||||
|
||||
test('payout credits same player separately per currency', function (): void {
|
||||
$uniq = bin2hex(random_bytes(4));
|
||||
$player = Player::query()->create([
|
||||
'site_code' => 'test',
|
||||
'site_player_id' => 'settle-multi-currency-'.$uniq,
|
||||
'username' => 'smc_'.$uniq,
|
||||
'nickname' => null,
|
||||
'default_currency' => 'NPR',
|
||||
'status' => 0,
|
||||
]);
|
||||
PlayerWallet::query()->create([
|
||||
'player_id' => $player->id,
|
||||
'wallet_type' => 'lottery',
|
||||
'currency_code' => 'NPR',
|
||||
'balance' => 100_000,
|
||||
'frozen_balance' => 0,
|
||||
'status' => 0,
|
||||
'version' => 0,
|
||||
]);
|
||||
PlayerWallet::query()->create([
|
||||
'player_id' => $player->id,
|
||||
'wallet_type' => 'lottery',
|
||||
'currency_code' => 'USD',
|
||||
'balance' => 200_000,
|
||||
'frozen_balance' => 0,
|
||||
'status' => 0,
|
||||
'version' => 0,
|
||||
]);
|
||||
|
||||
$draw = Draw::query()->create([
|
||||
'draw_no' => '20260511-990',
|
||||
'business_date' => '2026-05-11',
|
||||
'sequence_no' => 990,
|
||||
'status' => DrawStatus::Settling->value,
|
||||
'start_time' => now()->subMinutes(10),
|
||||
'close_time' => now()->subMinutes(5),
|
||||
'draw_time' => now()->subMinutes(4),
|
||||
'cooling_end_time' => null,
|
||||
'result_source' => null,
|
||||
'current_result_version' => 1,
|
||||
'settle_version' => 1,
|
||||
'is_reopened' => false,
|
||||
]);
|
||||
$resultBatch = DrawResultBatch::query()->create([
|
||||
'draw_id' => $draw->id,
|
||||
'result_version' => 1,
|
||||
'source_type' => 'rng',
|
||||
'rng_seed_hash' => 'multi-currency',
|
||||
'raw_seed_encrypted' => null,
|
||||
'status' => DrawResultBatchStatus::Published->value,
|
||||
'created_by' => null,
|
||||
'confirmed_by' => null,
|
||||
'confirmed_at' => now(),
|
||||
]);
|
||||
|
||||
$orderNpr = TicketOrder::query()->create([
|
||||
'order_no' => 'TO-NPR-'.$uniq,
|
||||
'player_id' => $player->id,
|
||||
'draw_id' => $draw->id,
|
||||
'currency_code' => 'NPR',
|
||||
'total_bet_amount' => 1000,
|
||||
'total_rebate_amount' => 0,
|
||||
'total_actual_deduct' => 1000,
|
||||
'total_estimated_payout' => 0,
|
||||
'status' => 'placed',
|
||||
'submit_source' => 'h5',
|
||||
'client_trace_id' => null,
|
||||
'play_config_version_no' => 1,
|
||||
'odds_version_no' => 1,
|
||||
'risk_cap_version_no' => 1,
|
||||
]);
|
||||
$orderUsd = TicketOrder::query()->create([
|
||||
'order_no' => 'TO-USD-'.$uniq,
|
||||
'player_id' => $player->id,
|
||||
'draw_id' => $draw->id,
|
||||
'currency_code' => 'USD',
|
||||
'total_bet_amount' => 2000,
|
||||
'total_rebate_amount' => 0,
|
||||
'total_actual_deduct' => 2000,
|
||||
'total_estimated_payout' => 0,
|
||||
'status' => 'placed',
|
||||
'submit_source' => 'h5',
|
||||
'client_trace_id' => null,
|
||||
'play_config_version_no' => 1,
|
||||
'odds_version_no' => 1,
|
||||
'risk_cap_version_no' => 1,
|
||||
]);
|
||||
|
||||
$itemNpr = TicketItem::query()->create([
|
||||
'ticket_no' => 'TK-NPR-'.$uniq,
|
||||
'order_id' => $orderNpr->id,
|
||||
'player_id' => $player->id,
|
||||
'draw_id' => $draw->id,
|
||||
'original_number' => '1234',
|
||||
'normalized_number' => '1234',
|
||||
'play_code' => 'big',
|
||||
'dimension' => 'D4',
|
||||
'digit_slot' => null,
|
||||
'bet_mode' => 'single',
|
||||
'unit_bet_amount' => 1000,
|
||||
'total_bet_amount' => 1000,
|
||||
'rebate_rate_snapshot' => 0,
|
||||
'commission_rate_snapshot' => 0,
|
||||
'actual_deduct_amount' => 1000,
|
||||
'odds_snapshot_json' => [],
|
||||
'rule_snapshot_json' => [],
|
||||
'combination_count' => 1,
|
||||
'estimated_max_payout' => 0,
|
||||
'risk_locked_amount' => 0,
|
||||
'status' => 'pending_payout',
|
||||
'fail_reason_code' => null,
|
||||
'fail_reason_text' => null,
|
||||
'win_amount' => 5000,
|
||||
'jackpot_win_amount' => 0,
|
||||
'settled_at' => null,
|
||||
]);
|
||||
$itemUsd = TicketItem::query()->create([
|
||||
'ticket_no' => 'TK-USD-'.$uniq,
|
||||
'order_id' => $orderUsd->id,
|
||||
'player_id' => $player->id,
|
||||
'draw_id' => $draw->id,
|
||||
'original_number' => '5678',
|
||||
'normalized_number' => '5678',
|
||||
'play_code' => 'big',
|
||||
'dimension' => 'D4',
|
||||
'digit_slot' => null,
|
||||
'bet_mode' => 'single',
|
||||
'unit_bet_amount' => 2000,
|
||||
'total_bet_amount' => 2000,
|
||||
'rebate_rate_snapshot' => 0,
|
||||
'commission_rate_snapshot' => 0,
|
||||
'actual_deduct_amount' => 2000,
|
||||
'odds_snapshot_json' => [],
|
||||
'rule_snapshot_json' => [],
|
||||
'combination_count' => 1,
|
||||
'estimated_max_payout' => 0,
|
||||
'risk_locked_amount' => 0,
|
||||
'status' => 'pending_payout',
|
||||
'fail_reason_code' => null,
|
||||
'fail_reason_text' => null,
|
||||
'win_amount' => 8000,
|
||||
'jackpot_win_amount' => 0,
|
||||
'settled_at' => null,
|
||||
]);
|
||||
|
||||
$batch = SettlementBatch::query()->create([
|
||||
'draw_id' => $draw->id,
|
||||
'result_batch_id' => $resultBatch->id,
|
||||
'settle_version' => 1,
|
||||
'status' => 'approved',
|
||||
'review_status' => 'approved',
|
||||
'reviewed_by' => null,
|
||||
'reviewed_at' => now(),
|
||||
'review_remark' => null,
|
||||
'started_at' => now()->subMinute(),
|
||||
'finished_at' => now(),
|
||||
]);
|
||||
$batch->details()->create([
|
||||
'ticket_item_id' => $itemNpr->id,
|
||||
'matched_prize_tier' => 'first',
|
||||
'win_amount' => 5000,
|
||||
'jackpot_allocation_amount' => 0,
|
||||
'match_detail_json' => [],
|
||||
]);
|
||||
$batch->details()->create([
|
||||
'ticket_item_id' => $itemUsd->id,
|
||||
'matched_prize_tier' => 'first',
|
||||
'win_amount' => 8000,
|
||||
'jackpot_allocation_amount' => 0,
|
||||
'match_detail_json' => [],
|
||||
]);
|
||||
|
||||
app(SettlementBatchWorkflowService::class)->payout($batch->fresh());
|
||||
|
||||
$walletNpr = PlayerWallet::query()
|
||||
->where('player_id', $player->id)
|
||||
->where('currency_code', 'NPR')
|
||||
->firstOrFail();
|
||||
$walletUsd = PlayerWallet::query()
|
||||
->where('player_id', $player->id)
|
||||
->where('currency_code', 'USD')
|
||||
->firstOrFail();
|
||||
|
||||
expect((int) $walletNpr->balance)->toBe(105_000)
|
||||
->and((int) $walletUsd->balance)->toBe(208_000);
|
||||
|
||||
expect(WalletTxn::query()
|
||||
->where('biz_type', 'settle_payout')
|
||||
->where('player_id', $player->id)
|
||||
->count())->toBe(2);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user