- MarriageController:propose/accept/reject/divorce/confirmDivorce/status
- WeddingController:tiers/setup(立即触发)/claim/envelopeStatus
- 8个 WebSocket Events:
Marriage{Proposed|Accepted|Rejected|Expired|Divorced|DivorceRequested}
WeddingCelebration / EnvelopeClaimed
- 前台路由:marriage.* + wedding.*
- 后台路由:admin.marriages.*(superlevel 层)
65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
<?php
|
||
|
||
/**
|
||
* 文件功能:婚礼红包领取成功事件(广播至领取者私人频道)
|
||
*
|
||
* 触发时机:WeddingController::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 EnvelopeClaimed implements ShouldBroadcastNow
|
||
{
|
||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||
|
||
/**
|
||
* @param User $claimer 领取用户
|
||
* @param int $amount 领取金额
|
||
* @param int $ceremonyId 婚礼仪式 ID
|
||
*/
|
||
public function __construct(
|
||
public readonly User $claimer,
|
||
public readonly int $amount,
|
||
public readonly int $ceremonyId,
|
||
) {}
|
||
|
||
/**
|
||
* 广播至领取者私人频道。
|
||
*
|
||
* @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 [
|
||
'ceremony_id' => $this->ceremonyId,
|
||
'amount' => $this->amount,
|
||
'message' => "🎉 成功领取 {$this->amount} 金币婚礼红包!",
|
||
];
|
||
}
|
||
|
||
/** 广播事件名称。 */
|
||
public function broadcastAs(): string
|
||
{
|
||
return 'envelope.claimed';
|
||
}
|
||
}
|