74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 文件功能:任命公告广播事件
|
||
|
|
* 任命操作成功后向对应聊天室 PresenceChannel 推送任命消息,
|
||
|
|
* 前端接收后展示全屏礼花动画和隆重公告弹窗。
|
||
|
|
*
|
||
|
|
* @author ChatRoom Laravel
|
||
|
|
*
|
||
|
|
* @version 1.0.0
|
||
|
|
*/
|
||
|
|
|
||
|
|
namespace App\Events;
|
||
|
|
|
||
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
||
|
|
use Illuminate\Broadcasting\PresenceChannel;
|
||
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
||
|
|
use Illuminate\Queue\SerializesModels;
|
||
|
|
|
||
|
|
class AppointmentAnnounced implements ShouldBroadcastNow
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 构建任命公告事件
|
||
|
|
*
|
||
|
|
* @param int $roomId 广播目标房间 ID
|
||
|
|
* @param string $targetUsername 被任命用户名
|
||
|
|
* @param string $positionIcon 职务图标
|
||
|
|
* @param string $positionName 职务名称
|
||
|
|
* @param string $departmentName 所属部门名称
|
||
|
|
* @param string $operatorName 任命人用户名
|
||
|
|
*/
|
||
|
|
public function __construct(
|
||
|
|
public readonly int $roomId,
|
||
|
|
public readonly string $targetUsername,
|
||
|
|
public readonly string $positionIcon,
|
||
|
|
public readonly string $positionName,
|
||
|
|
public readonly string $departmentName,
|
||
|
|
public readonly string $operatorName,
|
||
|
|
public readonly string $type = 'appoint', // appoint | revoke
|
||
|
|
) {}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 广播至目标房间的 PresenceChannel
|
||
|
|
*
|
||
|
|
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||
|
|
*/
|
||
|
|
public function broadcastOn(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
new PresenceChannel('room.'.$this->roomId),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 广播数据
|
||
|
|
*
|
||
|
|
* @return array<string, mixed>
|
||
|
|
*/
|
||
|
|
public function broadcastWith(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'type' => $this->type,
|
||
|
|
'target_username' => $this->targetUsername,
|
||
|
|
'position_icon' => $this->positionIcon,
|
||
|
|
'position_name' => $this->positionName,
|
||
|
|
'department_name' => $this->departmentName,
|
||
|
|
'operator_name' => $this->operatorName,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|