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

66 lines
1.6 KiB
PHP
Raw Permalink 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 MarriageDivorced implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* @param Marriage $marriage 婚姻记录
* @param string $divorceType 离婚类型mutual|forced|auto|admin
*/
public function __construct(
public readonly Marriage $marriage,
public readonly string $divorceType,
) {}
/**
* 广播至全房间。
*
* @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', 'partner:id,username']);
return [
'user_username' => $this->marriage->user?->username,
'partner_username' => $this->marriage->partner?->username,
'divorce_type' => $this->divorceType,
];
}
/** 广播事件名称。 */
public function broadcastAs(): string
{
return 'marriage.divorced';
}
}