70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 文件功能:百家乐结算广播事件
|
|
*
|
|
* 开奖后广播骰子结果和获奖类型,前端播放骰子动画,
|
|
* 并显示用户是否中奖及赔付金额。
|
|
*
|
|
* @author ChatRoom Laravel
|
|
*
|
|
* @version 1.0.0
|
|
*/
|
|
|
|
namespace App\Events;
|
|
|
|
use App\Models\BaccaratRound;
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
use Illuminate\Broadcasting\PresenceChannel;
|
|
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 PresenceChannel('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,
|
|
];
|
|
}
|
|
}
|