优化 ai小班长百家乐押注

This commit is contained in:
2026-04-19 12:36:23 +08:00
parent b98ae7f94e
commit bd97ed0b73
3 changed files with 118 additions and 13 deletions
+70
View File
@@ -136,4 +136,74 @@ class AiBaccaratBetJobTest extends TestCase
'bank_jjb' => 200000,
]);
}
/**
* 买单活动时间窗口命中时,即使 AI 返回观望,系统也会强制切回本地策略完成下注。
*/
public function test_ai_still_places_bet_when_loss_cover_time_window_is_active_and_ai_returns_pass(): void
{
Event::fake();
Queue::fake([SaveMessageJob::class]);
$this->mock(ChatStateService::class, function (MockInterface $mock): void {
$mock->shouldReceive('nextMessageId')->andReturn(1);
$mock->shouldReceive('pushMessage')->zeroOrMoreTimes();
$mock->shouldReceive('getAllActiveRoomIds')->andReturn([1]);
});
$this->mock(BaccaratPredictionService::class, function (MockInterface $mock): void {
$mock->shouldReceive('predict')
->once()
->andReturn([
'action' => 'pass',
'percentage' => 0,
'reason' => '常规风控建议先观望',
]);
});
$aiUser = User::factory()->create([
'username' => 'AI小班长',
'jjb' => 600000,
'bank_jjb' => 0,
]);
$event = BaccaratLossCoverEvent::factory()->create([
'status' => 'active',
'starts_at' => now()->subMinutes(2),
'ends_at' => now()->addMinutes(10),
]);
$round = BaccaratRound::forceCreate([
'status' => 'betting',
'bet_opens_at' => now()->subSeconds(10),
'bet_closes_at' => now()->addMinute(),
'total_bet_big' => 0,
'total_bet_small' => 0,
'total_bet_triple' => 0,
'bet_count' => 0,
'bet_count_big' => 0,
'bet_count_small' => 0,
'bet_count_triple' => 0,
'total_payout' => 0,
]);
$job = new AiBaccaratBetJob($round);
$job->handle(app(\App\Services\UserCurrencyService::class), app(\App\Services\AiFinanceService::class));
$bet = \App\Models\BaccaratBet::query()
->where('round_id', $round->id)
->where('user_id', $aiUser->id)
->first();
$this->assertNotNull($bet);
$this->assertContains($bet->bet_type, ['big', 'small', 'triple']);
$this->assertSame(50000, (int) $bet->amount);
$this->assertSame($event->id, $bet->loss_cover_event_id);
$this->assertDatabaseHas('baccarat_loss_cover_records', [
'event_id' => $event->id,
'user_id' => $aiUser->id,
'total_bet_amount' => 50000,
]);
}
}