Refine horse race pool and quick entry
This commit is contained in:
@@ -59,6 +59,7 @@ class HorseRaceOpened implements ShouldBroadcastNow
|
||||
return [
|
||||
'race_id' => $this->race->id,
|
||||
'horses' => $this->race->horses,
|
||||
'total_pool' => $this->race->total_pool,
|
||||
'bet_opens_at' => $this->race->bet_opens_at->toIso8601String(),
|
||||
'bet_closes_at' => $this->race->bet_closes_at->toIso8601String(),
|
||||
'bet_seconds' => (int) now()->diffInSeconds($this->race->bet_closes_at),
|
||||
|
||||
@@ -70,7 +70,7 @@ class HorseRaceSettled implements ShouldBroadcastNow
|
||||
'race_id' => $this->race->id,
|
||||
'winner_horse_id' => $this->race->winner_horse_id,
|
||||
'winner_name' => $winnerName,
|
||||
'total_pool' => $this->race->total_pool,
|
||||
'total_pool' => (int) $this->race->total_pool,
|
||||
'settled_at' => $this->race->settled_at?->toIso8601String(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ class OpenHorseRaceJob implements ShouldQueue
|
||||
$horseCount = (int) ($config['horse_count'] ?? 4);
|
||||
$minBet = (int) ($config['min_bet'] ?? 100);
|
||||
$maxBet = (int) ($config['max_bet'] ?? 100000);
|
||||
$seedPool = (int) ($config['seed_pool'] ?? 0);
|
||||
|
||||
$now = now();
|
||||
$closesAt = $now->copy()->addSeconds($betSeconds);
|
||||
@@ -63,6 +64,7 @@ class OpenHorseRaceJob implements ShouldQueue
|
||||
'bet_opens_at' => $now,
|
||||
'bet_closes_at' => $closesAt,
|
||||
'horses' => $horses,
|
||||
'total_pool' => $seedPool,
|
||||
]);
|
||||
|
||||
// 广播开赛事件
|
||||
|
||||
@@ -70,12 +70,16 @@ class RunHorseRaceJob implements ShouldQueue
|
||||
fn ($h) => "{$h['emoji']}{$h['name']}",
|
||||
$race->horses ?? []
|
||||
));
|
||||
$quickOpenButton = '<button type="button" '
|
||||
.'onclick="event.preventDefault(); Alpine.$data(document.getElementById(\'horse-race-panel\')).openFromHall();" '
|
||||
.'style="margin-left:8px; padding:2px 8px; border:1px solid #d97706; border-radius:999px; background:#fff7ed; color:#b45309; font-size:12px; font-weight:bold; cursor:pointer;">'
|
||||
.'快速参与赌马</button>';
|
||||
$startMsg = [
|
||||
'id' => $chatState->nextMessageId(1),
|
||||
'room_id' => 1,
|
||||
'from_user' => '系统传音',
|
||||
'to_user' => '大家',
|
||||
'content' => "🏇 【赛马】第 #{$race->id} 场押注截止!马匹已进入跑道,比赛开始!参赛阵容:{$horseList}",
|
||||
'content' => "🏇 【赛马】第 #{$race->id} 场押注截止!马匹已进入跑道,比赛开始!参赛阵容:{$horseList}{$quickOpenButton}",
|
||||
'is_secret' => false,
|
||||
'font_color' => '#336699',
|
||||
'action' => '大声宣告',
|
||||
@@ -87,6 +91,7 @@ class RunHorseRaceJob implements ShouldQueue
|
||||
|
||||
$config = GameConfig::forGame('horse_racing')?->params ?? [];
|
||||
$raceDuration = (int) ($config['race_duration'] ?? 30);
|
||||
$seedPool = (int) ($config['seed_pool'] ?? 0);
|
||||
$horses = $race->horses ?? [];
|
||||
$horseCount = count($horses);
|
||||
|
||||
@@ -147,7 +152,7 @@ class RunHorseRaceJob implements ShouldQueue
|
||||
|
||||
// 计算注池统计
|
||||
$totalBets = HorseBet::query()->where('race_id', $race->id)->count();
|
||||
$totalPool = HorseBet::query()->where('race_id', $race->id)->sum('amount');
|
||||
$totalPool = $seedPool + HorseBet::query()->where('race_id', $race->id)->sum('amount');
|
||||
|
||||
$race->update([
|
||||
'total_bets' => $totalBets,
|
||||
|
||||
@@ -399,6 +399,7 @@
|
||||
this.countdown = data.bet_seconds || 90;
|
||||
this.totalSeconds = this.countdown;
|
||||
this.horses = data.horses || [];
|
||||
this.totalPool = data.total_pool || 0;
|
||||
this.myBet = false;
|
||||
this.myBetHorseId = null;
|
||||
this.myBetHorseName = '';
|
||||
|
||||
@@ -51,7 +51,7 @@ class HorseRaceControllerTest extends TestCase
|
||||
['id' => 2, 'name' => 'Horse B', 'emoji' => '🏇'],
|
||||
],
|
||||
'total_bets' => 0,
|
||||
'total_pool' => 0,
|
||||
'total_pool' => 10000,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->getJson(route('horse-race.current'));
|
||||
@@ -61,6 +61,46 @@ class HorseRaceControllerTest extends TestCase
|
||||
$this->assertEquals($race->id, $response->json('race.id'));
|
||||
}
|
||||
|
||||
public function test_current_race_total_pool_includes_seed_pool(): void
|
||||
{
|
||||
GameConfig::updateOrCreate(
|
||||
['game_key' => 'horse_racing'],
|
||||
[
|
||||
'name' => 'Horse Racing',
|
||||
'icon' => 'horse',
|
||||
'description' => 'Horse Racing Game',
|
||||
'enabled' => true,
|
||||
'params' => [
|
||||
'min_bet' => 100,
|
||||
'max_bet' => 100000,
|
||||
'house_take_percent' => 5,
|
||||
'seed_pool' => 10000,
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create();
|
||||
|
||||
$race = HorseRace::create([
|
||||
'status' => 'betting',
|
||||
'bet_opens_at' => now(),
|
||||
'bet_closes_at' => now()->addMinutes(1),
|
||||
'horses' => [
|
||||
['id' => 1, 'name' => 'Horse A', 'emoji' => '🐎'],
|
||||
['id' => 2, 'name' => 'Horse B', 'emoji' => '🏇'],
|
||||
],
|
||||
'total_bets' => 0,
|
||||
'total_pool' => 0,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->getJson(route('horse-race.current'));
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertSame($race->id, $response->json('race.id'));
|
||||
$this->assertSame(10000, $response->json('race.total_pool'));
|
||||
}
|
||||
|
||||
public function test_can_bet()
|
||||
{
|
||||
Event::fake();
|
||||
|
||||
Reference in New Issue
Block a user