新增百家乐游戏:①数据库表+模型 ②OpenBaccaratRoundJob开局(广播+公屏) ③CloseBaccaratRoundJob结算(摇骰+赔付+CAS防并发) ④BaccaratController下注接口 ⑤前端弹窗(倒计时/骰子动画/历史趋势) ⑥调度器每分钟检查开局 ⑦GameConfig管控开关

This commit is contained in:
2026-03-01 20:25:09 +08:00
parent 8a74bfd639
commit ff28775635
15 changed files with 1424 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
<?php
/**
* 文件功能:百家乐开局广播事件
*
* 新局开始时广播给房间所有用户,携带局次 ID 和下注截止时间,
* 前端收到后展示倒计时下注面板。
*
* @author ChatRoom Laravel
*
* @version 1.0.0
*/
namespace App\Events;
use App\Models\BaccaratRound;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class BaccaratRoundOpened implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* @param BaccaratRound $round 本局信息
*/
public function __construct(
public readonly BaccaratRound $round,
) {}
/**
* 广播至房间公共频道。
*
* @return array<Channel>
*/
public function broadcastOn(): array
{
return [new Channel('room.1')];
}
/**
* 广播事件名(前端监听 .baccarat.opened)。
*/
public function broadcastAs(): string
{
return 'baccarat.opened';
}
/**
* 广播数据。
*
* @return array<string, mixed>
*/
public function broadcastWith(): array
{
return [
'round_id' => $this->round->id,
'bet_opens_at' => $this->round->bet_opens_at->toIso8601String(),
'bet_closes_at' => $this->round->bet_closes_at->toIso8601String(),
'bet_seconds' => (int) now()->diffInSeconds($this->round->bet_closes_at),
];
}
}
+69
View File
@@ -0,0 +1,69 @@
<?php
/**
* 文件功能:百家乐结算广播事件
*
* 开奖后广播骰子结果和获奖类型,前端播放骰子动画,
* 并显示用户是否中奖及赔付金额。
*
* @author ChatRoom Laravel
*
* @version 1.0.0
*/
namespace App\Events;
use App\Models\BaccaratRound;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class BaccaratRoundSettled implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* @param BaccaratRound $round 已结算的局次
*/
public function __construct(
public readonly BaccaratRound $round,
) {}
/**
* 广播至房间公共频道。
*
* @return array<Channel>
*/
public function broadcastOn(): array
{
return [new Channel('room.1')];
}
/**
* 广播事件名(前端监听 .baccarat.settled)。
*/
public function broadcastAs(): string
{
return 'baccarat.settled';
}
/**
* 广播数据:骰子点数 + 开奖结果 + 统计。
*
* @return array<string, mixed>
*/
public function broadcastWith(): array
{
return [
'round_id' => $this->round->id,
'dice' => [$this->round->dice1, $this->round->dice2, $this->round->dice3],
'total_points' => $this->round->total_points,
'result' => $this->round->result,
'result_label' => $this->round->resultLabel(),
'total_payout' => $this->round->total_payout,
'bet_count' => $this->round->bet_count,
];
}
}