diff --git a/app/Events/BaccaratPoolUpdated.php b/app/Events/BaccaratPoolUpdated.php new file mode 100644 index 0000000..0b828ec --- /dev/null +++ b/app/Events/BaccaratPoolUpdated.php @@ -0,0 +1,66 @@ + + */ + public function broadcastOn(): array + { + return [new PresenceChannel('room.1')]; + } + + /** + * 广播事件名(前端监听 .baccarat.pool_updated)。 + */ + public function broadcastAs(): string + { + return 'baccarat.pool_updated'; + } + + /** + * 广播数据。 + * + * @return array + */ + public function broadcastWith(): array + { + return [ + 'round_id' => $this->round->id, + 'bet_count_big' => $this->round->bet_count_big, + 'bet_count_small' => $this->round->bet_count_small, + 'bet_count_triple' => $this->round->bet_count_triple, + ]; + } +} diff --git a/app/Http/Controllers/BaccaratController.php b/app/Http/Controllers/BaccaratController.php index 8def4d8..c95b3a2 100644 --- a/app/Http/Controllers/BaccaratController.php +++ b/app/Http/Controllers/BaccaratController.php @@ -56,6 +56,9 @@ class BaccaratController extends Controller 'total_bet_big' => $round->total_bet_big, 'total_bet_small' => $round->total_bet_small, 'total_bet_triple' => $round->total_bet_triple, + 'bet_count_big' => $round->bet_count_big, + 'bet_count_small' => $round->bet_count_small, + 'bet_count_triple' => $round->bet_count_triple, 'my_bet' => $myBet ? [ 'bet_type' => $myBet->bet_type, 'amount' => $myBet->amount, @@ -139,9 +142,14 @@ class BaccaratController extends Controller // 更新局次汇总统计 $field = 'total_bet_'.$data['bet_type']; + $countField = 'bet_count_'.$data['bet_type']; $round->increment($field, $data['amount']); + $round->increment($countField); $round->increment('bet_count'); + // 广播各选项的最新押注人数 + event(new \App\Events\BaccaratPoolUpdated($round)); + $betLabel = match ($data['bet_type']) { 'big' => '大', 'small' => '小', default => '豹子' }; diff --git a/app/Models/BaccaratRound.php b/app/Models/BaccaratRound.php index 4db19e0..885e9bd 100644 --- a/app/Models/BaccaratRound.php +++ b/app/Models/BaccaratRound.php @@ -24,6 +24,7 @@ class BaccaratRound extends Model 'bet_opens_at', 'bet_closes_at', 'settled_at', 'total_bet_big', 'total_bet_small', 'total_bet_triple', 'total_payout', 'bet_count', + 'bet_count_big', 'bet_count_small', 'bet_count_triple', ]; /** @@ -44,6 +45,9 @@ class BaccaratRound extends Model 'total_bet_triple' => 'integer', 'total_payout' => 'integer', 'bet_count' => 'integer', + 'bet_count_big' => 'integer', + 'bet_count_small' => 'integer', + 'bet_count_triple' => 'integer', ]; } diff --git a/database/migrations/2026_03_28_164112_add_bet_counts_to_baccarat_rounds_table.php b/database/migrations/2026_03_28_164112_add_bet_counts_to_baccarat_rounds_table.php new file mode 100644 index 0000000..8a0a7f4 --- /dev/null +++ b/database/migrations/2026_03_28_164112_add_bet_counts_to_baccarat_rounds_table.php @@ -0,0 +1,36 @@ +unsignedInteger('bet_count_big')->default(0)->after('bet_count')->comment('押大人数'); + $table->unsignedInteger('bet_count_small')->default(0)->after('bet_count_big')->comment('押小人数'); + $table->unsignedInteger('bet_count_triple')->default(0)->after('bet_count_small')->comment('押豹子人数'); + }); + } + + /** + * 回滚迁移。 + */ + public function down(): void + { + Schema::table('baccarat_rounds', function (Blueprint $table) { + $table->dropColumn(['bet_count_big', 'bet_count_small', 'bet_count_triple']); + }); + } +}; diff --git a/resources/js/chat.js b/resources/js/chat.js index c66df4d..ac20521 100644 --- a/resources/js/chat.js +++ b/resources/js/chat.js @@ -116,6 +116,12 @@ export function initChat(roomId) { new CustomEvent("chat:baccarat.opened", { detail: e }), ); }) + .listen(".baccarat.pool_updated", (e) => { + console.log("百家乐押注更新:", e); + window.dispatchEvent( + new CustomEvent("chat:baccarat.pool_updated", { detail: e }), + ); + }) .listen(".baccarat.settled", (e) => { console.log("百家乐结算:", e); window.dispatchEvent( diff --git a/resources/views/chat/partials/games/baccarat-panel.blade.php b/resources/views/chat/partials/games/baccarat-panel.blade.php index f5eb862..e6b22af 100644 --- a/resources/views/chat/partials/games/baccarat-panel.blade.php +++ b/resources/views/chat/partials/games/baccarat-panel.blade.php @@ -124,7 +124,10 @@ 'border:2px solid #1d4ed8; background:#1d4ed8; color:#fff; transform:scale(1.05); box-shadow:0 4px 14px rgba(29,78,216,.3);' : 'border:2px solid #bfdbfe; background:#eff6ff; color:#1d4ed8;'">
🔵
-
+
+ + +
11~17点 • 1:1
{{-- 小 --}} @@ -135,7 +138,10 @@ 'border:2px solid #d97706; background:#d97706; color:#fff; transform:scale(1.05); box-shadow:0 4px 14px rgba(217,119,6,.3);' : 'border:2px solid #fde68a; background:#fffbeb; color:#b45309;'">
🟡
-
+
+ + +
4~10点 • 1:1
{{-- 豹子 --}} @@ -146,7 +152,10 @@ 'border:2px solid #7c3aed; background:#7c3aed; color:#fff; transform:scale(1.05); box-shadow:0 4px 14px rgba(124,58,237,.3);' : 'border:2px solid #ddd6fe; background:#f5f3ff; color:#7c3aed;'">
💥
-
豹子
+
+ 豹子 + +
三同 • 1:24
@@ -165,20 +174,21 @@ - {{-- 自定义金额 --}} - - + {{-- 下注按钮 --}} - @@ -407,6 +417,11 @@ totalBetBig: 0, totalBetSmall: 0, totalBetTriple: 0, + + // 押注人数统计 + betCountBig: 0, + betCountSmall: 0, + betCountTriple: 0, // 本人下注 myBet: false, @@ -448,6 +463,9 @@ this.settledDice = []; this.selectedType = ''; this.betAmount = 100; + this.betCountBig = 0; + this.betCountSmall = 0; + this.betCountTriple = 0; this.show = true; this.loadCurrentRound(); @@ -466,6 +484,9 @@ this.totalBetBig = data.round.total_bet_big; this.totalBetSmall = data.round.total_bet_small; this.totalBetTriple = data.round.total_bet_triple; + this.betCountBig = data.round.bet_count_big; + this.betCountSmall = data.round.bet_count_small; + this.betCountTriple = data.round.bet_count_triple; if (data.round.my_bet) { this.myBet = true; this.myBetType = data.round.my_bet.bet_type; @@ -493,7 +514,7 @@ * 提交下注 */ async submitBet() { - if (!this.selectedType || this.betAmount < 100 || this.submitting) return; + if (!this.roundId || !this.selectedType || this.betAmount < 100 || this.submitting) return; this.submitting = true; try { @@ -512,11 +533,15 @@ }); const data = await res.json(); - if (data.ok) { + if (res.ok && data.ok) { this.myBet = true; this.myBetType = data.bet_type; this.myBetAmount = data.amount; window.chatDialog?.alert(data.message, '下注成功', '#336699'); + } else if (res.status === 422 && data.errors) { + // 取出第一条 Laravel 验证失败原因 + const firstError = Object.values(data.errors)[0][0]; + window.chatDialog?.alert(firstError, '下注验证失败', '#ef4444'); } else { window.chatDialog?.alert(data.message || '下注失败', '提示', '#ef4444'); } @@ -627,6 +652,21 @@ if (panel) Alpine.$data(panel).showResult(e.detail); }); + /** 收到下注池更新:更新押注人数 */ + window.addEventListener('chat:baccarat.pool_updated', (e) => { + const panel = document.getElementById('baccarat-panel'); + if (panel) { + const pd = Alpine.$data(panel); + const data = e.detail; + // 判断 round_id 是否一致 + if (pd.roundId === data.round_id) { + pd.betCountBig = data.bet_count_big; + pd.betCountSmall = data.bet_count_small; + pd.betCountTriple = data.bet_count_triple; + } + } + }); + /** 页面加载时:检查是否有进行中的局,有则自动恢复面板 */ document.addEventListener('DOMContentLoaded', async () => { try { @@ -656,6 +696,9 @@ panelData.totalBetBig = round.total_bet_big; panelData.totalBetSmall = round.total_bet_small; panelData.totalBetTriple = round.total_bet_triple; + panelData.betCountBig = round.bet_count_big; + panelData.betCountSmall = round.bet_count_small; + panelData.betCountTriple = round.bet_count_triple; if (round.my_bet) { panelData.myBet = true;