Files
chatroom/app/Events/EnvelopeClaimed.php
lkddi 4f49fb7ce8 功能:婚姻系统第8&10步(Controllers + Events + 路由)
- 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 层)
2026-03-01 15:09:33 +08:00

65 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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';
}
}