2026-03-01 20:06:53 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文件功能:节日福利开始广播事件
|
|
|
|
|
*
|
|
|
|
|
* 管理员配置的节日活动到达触发时间后,由 TriggerHolidayEventJob 触发,
|
|
|
|
|
* 通过 Reverb WebSocket 广播给房间内所有在线用户,
|
|
|
|
|
* 前端收到后弹出领取弹窗和公屏系统消息。
|
|
|
|
|
*
|
|
|
|
|
* @author ChatRoom Laravel
|
|
|
|
|
*
|
|
|
|
|
* @version 1.0.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace App\Events;
|
|
|
|
|
|
2026-04-21 17:53:11 +08:00
|
|
|
use App\Models\HolidayEventRun;
|
2026-03-01 20:06:53 +08:00
|
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
2026-03-01 20:40:34 +08:00
|
|
|
use Illuminate\Broadcasting\PresenceChannel;
|
2026-03-01 20:06:53 +08:00
|
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
|
|
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
|
2026-04-21 17:53:11 +08:00
|
|
|
/**
|
|
|
|
|
* 类功能:向房间广播节日福利发放批次开始事件。
|
|
|
|
|
*/
|
2026-03-01 20:06:53 +08:00
|
|
|
class HolidayEventStarted implements ShouldBroadcastNow
|
|
|
|
|
{
|
|
|
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-21 17:53:11 +08:00
|
|
|
* @param HolidayEventRun $run 节日福利发放批次
|
2026-03-01 20:06:53 +08:00
|
|
|
*/
|
|
|
|
|
public function __construct(
|
2026-04-21 17:53:11 +08:00
|
|
|
public readonly HolidayEventRun $run,
|
2026-03-01 20:06:53 +08:00
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 广播至房间公共频道(所有在线用户均可收到)。
|
|
|
|
|
*
|
|
|
|
|
* @return array<Channel>
|
|
|
|
|
*/
|
|
|
|
|
public function broadcastOn(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2026-03-01 20:40:34 +08:00
|
|
|
new PresenceChannel('room.1'),
|
2026-03-01 20:06:53 +08:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 广播事件名。
|
|
|
|
|
*/
|
|
|
|
|
public function broadcastAs(): string
|
|
|
|
|
{
|
|
|
|
|
return 'holiday.started';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 广播数据:供前端构建弹窗和公屏消息。
|
|
|
|
|
*
|
|
|
|
|
* @return array<string, mixed>
|
|
|
|
|
*/
|
|
|
|
|
public function broadcastWith(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2026-04-21 17:53:11 +08:00
|
|
|
'run_id' => $this->run->id,
|
|
|
|
|
'event_id' => $this->run->holiday_event_id,
|
|
|
|
|
'name' => $this->run->event_name,
|
|
|
|
|
'description' => $this->run->event_description,
|
|
|
|
|
'total_amount' => $this->run->total_amount,
|
|
|
|
|
'max_claimants' => $this->run->max_claimants,
|
|
|
|
|
'distribute_type' => $this->run->distribute_type,
|
|
|
|
|
'fixed_amount' => $this->run->fixed_amount,
|
|
|
|
|
'claimed_count' => $this->run->claimed_count,
|
|
|
|
|
'expires_at' => $this->run->expires_at?->toIso8601String(),
|
|
|
|
|
'scheduled_for' => $this->run->scheduled_for?->toIso8601String(),
|
|
|
|
|
'repeat_type' => $this->run->repeat_type,
|
2026-03-01 20:06:53 +08:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|