Files
chatroom/app/Events/MarriageAccepted.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

69 lines
1.9 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
/**
* 文件功能:结婚公告事件(广播至全房间)
*
* 触发时机:求婚被接受,正式结婚后广播。
* 前端收到后展示全屏烟花特效 + 婚礼设置弹窗(仅婚姻双方)。
*
* @author ChatRoom Laravel
*
* @version 1.0.0
*/
namespace App\Events;
use App\Models\Marriage;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class MarriageAccepted implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* @param Marriage $marriage 婚姻记录
*/
public function __construct(
public readonly Marriage $marriage,
) {}
/**
* 广播至当前所有房间PresenceChannel room.*)。
* 使用大厅房间 ID=1若业务支持多房间可扩展。
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [new PresenceChannel('room.1')];
}
/**
* 广播数据。
*
* @return array<string, mixed>
*/
public function broadcastWith(): array
{
$this->marriage->load(['user:id,username,headface', 'partner:id,username,headface', 'ringItem:id,name,icon']);
return [
'marriage_id' => $this->marriage->id,
'user' => $this->marriage->user?->only(['id', 'username', 'headface']),
'partner' => $this->marriage->partner?->only(['id', 'username', 'headface']),
'ring' => $this->marriage->ringItem?->only(['name', 'icon']),
'married_at' => $this->marriage->married_at,
];
}
/** 广播事件名称。 */
public function broadcastAs(): string
{
return 'marriage.accepted';
}
}