新增功能:
- 礼包系统:superlevel 站长可发 888 数量 10 份礼包,支持金币/经验双类型
- 发包前三按钮选择(金币礼包 / 经验礼包 / 取消),使用 chatBanner 弹窗
- 聊天室系统公告含「立即抢包」按钮,金币红色/经验紫色配色区分
- WebSocket 实时推送红包弹窗卡片至所有在线用户
- Redis LPOP 原子分发 + 数据库 unique 约束防重领,并发安全
- 弹窗打开自动拉取服务端最新状态(剩余数量/已领/过期实时刷新)
- 新增 GET /red-packet/{id}/status 状态查询接口
- 新增 CurrencySource::RED_PACKET_RECV / RED_PACKET_RECV_EXP 枚举
安全加固:
- 后台用户编辑/强杀按钮仅 id=1 超管可见(前端隐藏 + 后端 403 双重拦截)
65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
<?php
|
||
|
||
/**
|
||
* 文件功能:红包领取成功广播事件(广播至领取者私有频道)
|
||
*
|
||
* 触发时机:RedPacketController::claim() 成功后广播,
|
||
* 前端收到后弹出 Toast 通知展示到账金额。
|
||
*
|
||
* @author ChatRoom Laravel
|
||
* @version 1.0.0
|
||
*/
|
||
|
||
namespace App\Events;
|
||
|
||
use App\Models\User;
|
||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||
use Illuminate\Broadcasting\PrivateChannel;
|
||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||
use Illuminate\Foundation\Events\Dispatchable;
|
||
use Illuminate\Queue\SerializesModels;
|
||
|
||
class RedPacketClaimed implements ShouldBroadcastNow
|
||
{
|
||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||
|
||
/**
|
||
* @param User $claimer 领取用户
|
||
* @param int $amount 领取金额
|
||
* @param int $envelopeId 红包 ID
|
||
*/
|
||
public function __construct(
|
||
public readonly User $claimer,
|
||
public readonly int $amount,
|
||
public readonly int $envelopeId,
|
||
) {}
|
||
|
||
/**
|
||
* 广播至领取者私有频道。
|
||
*
|
||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||
*/
|
||
public function broadcastOn(): array
|
||
{
|
||
return [new PrivateChannel('user.'.$this->claimer->id)];
|
||
}
|
||
|
||
/**
|
||
* @return array<string, mixed>
|
||
*/
|
||
public function broadcastWith(): array
|
||
{
|
||
return [
|
||
'envelope_id' => $this->envelopeId,
|
||
'amount' => $this->amount,
|
||
'message' => "🧧 成功抢到 {$this->amount} 金币礼包!",
|
||
];
|
||
}
|
||
|
||
/** 广播事件名称。 */
|
||
public function broadcastAs(): string
|
||
{
|
||
return 'red-packet.claimed';
|
||
}
|
||
}
|