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 @@
{{-- 选中勾选 --}}
-
- ✓
+
+
+
-
+
+ 我的押注
+
注池:
@@ -119,49 +128,66 @@
{{-- 已下注状态 --}}
-
+ style="background:linear-gradient(135deg,#e7fbe8,#f6fff7); border:2px solid #86efac; border-radius:14px;
+ padding:14px 16px; text-align:center; margin-bottom:10px; box-shadow:0 10px 24px rgba(34,197,94,.10);">
+
✅ 已押注「」
金币
-
等待开跑…
+
等待开跑…
{{-- 下注区 --}}
{{-- 快捷金额 --}}
-
+
{{-- 下注按钮 --}}
+ {{-- ── 未开始阶段 ── --}}
+
+
+
+
🐎
+
游戏还没开始
+
+ 当前暂无进行中的赛马场次。
+ 请等待系统开场后再来下注。
+
+
+
+
+
{{-- ── 跑马阶段 ── --}}
{{-- 马匹图标(跟随进度) --}}
-
@@ -346,7 +374,7 @@
function horseRacePanel() {
return {
show: false,
- phase: 'betting', // betting | running | settled
+ phase: 'idle', // idle | betting | running | settled
raceId: null,
totalSeconds: 90,
@@ -429,9 +457,16 @@
this.myBet = true;
this.myBetHorseId = data.race.my_bet.horse_id;
this.myBetAmount = data.race.my_bet.amount;
+ this.selectedHorse = data.race.my_bet.horse_id;
const h = this.horses.find(h => h.id === this.myBetHorseId);
this.myBetHorseName = h ? h.emoji + h.name : '';
}
+ } else {
+ this.phase = 'idle';
+ this.raceId = null;
+ this.horses = [];
+ this.totalPool = 0;
+ this.countdown = 0;
}
} catch {}
},
@@ -476,10 +511,11 @@
if (data.ok) {
this.myBet = true;
this.myBetHorseId = data.horse_id;
+ this.selectedHorse = data.horse_id;
this.myBetAmount = data.amount;
const h = this.horses.find(h => h.id === data.horse_id);
this.myBetHorseName = h ? h.emoji + h.name : '';
- window.chatDialog?.alert(data.message, '下注成功', '#f59e0b');
+ await this.loadCurrentRace();
} else {
window.chatDialog?.alert(data.message || '下注失败', '提示', '#ef4444');
}
@@ -506,6 +542,7 @@
clearInterval(this.countdownTimer);
this.phase = 'settled';
this.show = true;
+ this.totalPool = data.total_pool || this.totalPool;
// 找出获胜马匹信息
const winner = this.horses.find(h => h.id === data.winner_horse_id);
@@ -596,9 +633,16 @@
}
} else {
// 当前无进行中场次,重置状态
+ clearInterval(this.countdownTimer);
this.raceId = null;
this.horses = [];
- this.phase = 'betting';
+ this.totalPool = 0;
+ this.myBet = false;
+ this.myBetHorseId = null;
+ this.myBetHorseName = '';
+ this.myBetAmount = 0;
+ this.selectedHorse = null;
+ this.phase = 'idle';
this.countdown = 0;
}
} catch (e) {
@@ -669,7 +713,16 @@
panelData.countdown = seconds;
} else if (race.status === 'running') {
panelData.phase = 'running';
+ } else {
+ panelData.phase = 'settled';
}
+ } else if (panel) {
+ const panelData = Alpine.$data(panel);
+ panelData.phase = 'idle';
+ panelData.raceId = null;
+ panelData.horses = [];
+ panelData.totalPool = 0;
+ panelData.countdown = 0;
}
} catch (e) {
console.warn('[赛马] 初始化失败', e);