feat: 支持开奖重开与风险池原子扣减,完善投注部分成功流程

This commit is contained in:
2026-05-18 11:28:11 +08:00
parent 4f143c7cb1
commit 9157dcb6a1
14 changed files with 526 additions and 103 deletions

View File

@@ -251,6 +251,12 @@ test('ticket items index filters by status number and date range', function ():
->assertJsonPath('data.total', 1)
->assertJsonPath('data.items.0.draw_no', '20260512-780');
$this->withHeader('Authorization', 'Bearer dev:'.$player->id)
->getJson('/api/v1/ticket/items?status=settled_win')
->assertOk()
->assertJsonPath('data.total', 1)
->assertJsonPath('data.items.0.draw_no', '20260512-780');
$this->withHeader('Authorization', 'Bearer dev:'.$player->id)
->getJson('/api/v1/ticket/items?number=1234')
->assertOk()
@@ -309,7 +315,7 @@ test('ticket item show returns match result and timeline', function (): void {
->assertJsonPath('data.timeline.4.code', 'settled');
});
test('my-match returns hit numbers when draw published', function (): void {
test('my-match returns hit numbers when draw settled with winning ticket', function (): void {
$uniq = bin2hex(random_bytes(4));
$player = Player::query()->create([
'site_code' => 'test',
@@ -355,11 +361,39 @@ test('my-match returns hit numbers when draw published', function (): void {
])
->assertOk();
ticketItemsPublishAndSettle($draw, '1234');
$this->withHeader('Authorization', 'Bearer dev:'.$player->id)
->getJson('/api/v1/ticket/draws/20260511-778/my-match')
->assertOk()
->assertJsonPath('data.has_bets', true)
->assertJsonPath('data.winning_ticket_count', 1)
->assertJsonPath('data.hit_numbers_4d', ['1234']);
});
test('my-match only highlights settled winning tickets', function (): void {
$player = ticketItemsPlayer();
$draw = Draw::query()->create([
'draw_no' => '20260514-779',
'business_date' => '2026-05-14',
'sequence_no' => 779,
'status' => DrawStatus::Cooldown->value,
'start_time' => now()->subMinutes(20),
'close_time' => now()->subMinutes(10),
'draw_time' => now()->subMinutes(5),
'cooling_end_time' => now()->addMinutes(5),
'result_source' => 'rng',
'current_result_version' => 1,
'settle_version' => 0,
'is_reopened' => false,
]);
$batch = DrawResultBatch::query()->create([
'draw_id' => $draw->id,
'result_version' => 1,
'source_type' => 'rng',
'rng_seed_hash' => 'test',
'rng_seed_hash' => 'pending-match',
'raw_seed_encrypted' => null,
'status' => DrawResultBatchStatus::Published->value,
'created_by' => null,
@@ -368,28 +402,71 @@ test('my-match returns hit numbers when draw published', function (): void {
]);
foreach (DrawPrizeLayout::slots() as $slot) {
$num = $slot['prize_type'] === 'first' ? '1234' : '5678';
DrawResultItem::query()->create([
'draw_id' => $draw->id,
'result_batch_id' => $batch->id,
'prize_type' => $slot['prize_type'],
'prize_index' => $slot['prize_index'],
'number_4d' => $num,
'suffix_3d' => substr($num, -3),
'suffix_2d' => substr($num, -2),
'head_digit' => (int) substr($num, 0, 1),
'tail_digit' => (int) substr($num, 3, 1),
'number_4d' => '1234',
'suffix_3d' => '234',
'suffix_2d' => '34',
'head_digit' => 1,
'tail_digit' => 4,
]);
}
$draw->forceFill([
'status' => DrawStatus::Cooldown->value,
'current_result_version' => 1,
])->save();
$order = TicketOrder::query()->create([
'order_no' => 'ORD-PENDING-MATCH',
'player_id' => $player->id,
'draw_id' => $draw->id,
'currency_code' => 'NPR',
'total_bet_amount' => 10_000,
'total_rebate_amount' => 0,
'total_actual_deduct' => 10_000,
'total_estimated_payout' => 20_000,
'status' => 'placed',
'submit_source' => 'h5',
'client_trace_id' => 'pending-match',
]);
$item = \App\Models\TicketItem::query()->create([
'ticket_no' => 'TKPENDINGMATCH',
'order_id' => $order->id,
'player_id' => $player->id,
'draw_id' => $draw->id,
'original_number' => '1234',
'normalized_number' => '1234',
'play_code' => 'big',
'dimension' => 4,
'digit_slot' => null,
'bet_mode' => 'single',
'unit_bet_amount' => 10_000,
'total_bet_amount' => 10_000,
'rebate_rate_snapshot' => '0.0000',
'commission_rate_snapshot' => '0.0000',
'actual_deduct_amount' => 10_000,
'odds_snapshot_json' => [],
'rule_snapshot_json' => [],
'combination_count' => 1,
'estimated_max_payout' => 20_000,
'risk_locked_amount' => 20_000,
'status' => 'success',
'win_amount' => 0,
'jackpot_win_amount' => 0,
]);
\App\Models\TicketCombination::query()->create([
'ticket_item_id' => $item->id,
'combination_no' => 0,
'number_4d' => '1234',
'bet_amount' => 10_000,
'estimated_payout' => 20_000,
]);
$this->withHeader('Authorization', 'Bearer dev:'.$player->id)
->getJson('/api/v1/ticket/draws/20260511-778/my-match')
->getJson('/api/v1/ticket/draws/20260514-779/my-match')
->assertOk()
->assertJsonPath('data.has_bets', true)
->assertJsonPath('data.hit_numbers_4d', ['1234']);
->assertJsonPath('data.winning_ticket_count', 0)
->assertJsonPath('data.hit_numbers_4d', []);
});