diff --git a/app/Http/Controllers/HorseRaceController.php b/app/Http/Controllers/HorseRaceController.php index a6f18ea..bf97723 100644 --- a/app/Http/Controllers/HorseRaceController.php +++ b/app/Http/Controllers/HorseRaceController.php @@ -17,9 +17,12 @@ namespace App\Http\Controllers; use App\Enums\CurrencySource; +use App\Events\MessageSent; +use App\Jobs\SaveMessageJob; use App\Models\GameConfig; use App\Models\HorseBet; use App\Models\HorseRace; +use App\Services\ChatStateService; use App\Services\UserCurrencyService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -180,6 +183,24 @@ class HorseRaceController extends Controller 'status' => 'pending', ]); + $chatState = app(ChatStateService::class); + $formattedAmount = number_format($data['amount']); + $content = "🌟 🐎 {$user->username} 押注了 {$formattedAmount} 金币({$horseName})!✨"; + $msg = [ + 'id' => $chatState->nextMessageId(1), + 'room_id' => 1, + 'from_user' => '系统传音', + 'to_user' => '大家', + 'content' => $content, + 'is_secret' => false, + 'font_color' => '#d97706', + 'action' => '', + 'sent_at' => now()->toDateTimeString(), + ]; + $chatState->pushMessage(1, $msg); + event(new MessageSent(1, $msg)); + SaveMessageJob::dispatch($msg); + return response()->json([ 'ok' => true, 'message' => "✅ 已押注「{$horseName}」{$data['amount']} 金币,等待开跑!", diff --git a/resources/js/chat.js b/resources/js/chat.js index ac20521..312eeec 100644 --- a/resources/js/chat.js +++ b/resources/js/chat.js @@ -127,6 +127,25 @@ export function initChat(roomId) { window.dispatchEvent( new CustomEvent("chat:baccarat.settled", { detail: e }), ); + }) + // ─── 赛马:开场 / 进度 / 结算 ──────────────────────────────── + .listen(".horse.opened", (e) => { + console.log("赛马开场:", e); + window.dispatchEvent( + new CustomEvent("chat:horse.opened", { detail: e }), + ); + }) + .listen(".horse.progress", (e) => { + console.log("赛马进度:", e); + window.dispatchEvent( + new CustomEvent("chat:horse.progress", { detail: e }), + ); + }) + .listen(".horse.settled", (e) => { + console.log("赛马结算:", e); + window.dispatchEvent( + new CustomEvent("chat:horse.settled", { detail: e }), + ); }); } diff --git a/resources/views/chat/partials/games/baccarat-panel.blade.php b/resources/views/chat/partials/games/baccarat-panel.blade.php index 25a5fe0..380557c 100644 --- a/resources/views/chat/partials/games/baccarat-panel.blade.php +++ b/resources/views/chat/partials/games/baccarat-panel.blade.php @@ -27,7 +27,8 @@
🎲 百家乐
- 第 局 + + 等待开局中
{{-- 倒计时 --}} @@ -42,6 +43,9 @@
+
+
未开始
+
{{-- 进度条 --}} @@ -74,6 +78,23 @@ {{-- ─── 主体内容(白底) ─── --}}
+ {{-- 未开局状态 --}} +
+
+ 🎲 +
+
游戏还没开启
+
+ 当前暂无进行中的百家乐局次 +
+ 请等待系统开局后再来下注 +
+
+ {{-- 押注阶段 --}}
@@ -354,9 +375,12 @@ openPanel() { const panel = document.getElementById('baccarat-panel'); - if (!panel) return; + if (!panel) { + return; + } const p = Alpine.$data(panel); p.show = true; + p.loadCurrentRound(); if (p.phase === 'betting' && p.countdown > 0 && !p.countdownTimer) { p.startCountdown(); } @@ -408,7 +432,7 @@ function baccaratPanel() { return { show: false, - phase: 'betting', // betting | waiting | settled + phase: 'idle', // idle | betting | waiting | settled roundId: null, totalSeconds: 60, @@ -451,6 +475,36 @@ autoCloseTimer: null, autoCloseCountdown: 0, + /** + * 重置为未开局空状态 + */ + setIdleState() { + clearInterval(this.countdownTimer); + clearInterval(this.autoCloseTimer); + this.phase = 'idle'; + this.roundId = null; + this.countdown = 0; + this.autoCloseCountdown = 0; + this.totalBetBig = 0; + this.totalBetSmall = 0; + this.totalBetTriple = 0; + this.betCountBig = 0; + this.betCountSmall = 0; + this.betCountTriple = 0; + this.myBet = false; + this.myBetType = ''; + this.myBetAmount = 0; + this.selectedType = ''; + this.settledDice = []; + this.settledTotal = 0; + this.settledResult = ''; + this.resultLabel = ''; + this.diceEmoji = ''; + this.myWon = false; + this.myPayout = 0; + this.updateFab(false); + }, + /** * 开局:填充局次数据并开始倒计时 */ @@ -482,7 +536,10 @@ try { const res = await fetch('/baccarat/current'); const data = await res.json(); - if (data.round) { + if (data.round && (data.round.seconds_left || 0) > 0) { + this.phase = 'betting'; + this.roundId = data.round.id; + this.countdown = data.round.seconds_left || this.countdown || 0; this.totalBetBig = data.round.total_bet_big; this.totalBetSmall = data.round.total_bet_small; this.totalBetTriple = data.round.total_bet_triple; @@ -493,9 +550,17 @@ this.myBet = true; this.myBetType = data.round.my_bet.bet_type; this.myBetAmount = data.round.my_bet.amount; + } else { + this.myBet = false; + this.myBetType = ''; + this.myBetAmount = 0; } + } else { + this.setIdleState(); } - } catch {} + } catch { + this.setIdleState(); + } }, /** @@ -710,7 +775,11 @@ // 只显示悬浮按钮,不自动弹出全屏(避免打扰刚进入的用户) panelData.updateFab(true); + } else { + panelData.setIdleState(); } + } else if (panel) { + Alpine.$data(panel).setIdleState(); } } catch (e) { console.warn('[百家乐] 初始化失败', e); diff --git a/resources/views/chat/partials/games/horse-race-panel.blade.php b/resources/views/chat/partials/games/horse-race-panel.blade.php index 8dda32a..d43c476 100644 --- a/resources/views/chat/partials/games/horse-race-panel.blade.php +++ b/resources/views/chat/partials/games/horse-race-panel.blade.php @@ -84,22 +84,31 @@