2026-04-21 16:43:17 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文件功能:职务权限码注册表
|
|
|
|
|
* 统一维护聊天室顶部管理菜单可配置的全部权限码、
|
|
|
|
|
* 中文标题、说明文案与默认分配规则,便于后续继续扩展。
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace App\Support;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 类功能:集中定义职务权限元数据与默认权限策略。
|
|
|
|
|
*/
|
|
|
|
|
class PositionPermissionRegistry
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* 房间公告权限。
|
|
|
|
|
*/
|
|
|
|
|
public const ROOM_ANNOUNCEMENT = 'room.announcement';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 房间公屏讲话权限。
|
|
|
|
|
*/
|
|
|
|
|
public const ROOM_PUBLIC_BROADCAST = 'room.public_broadcast';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 房间全员清屏权限。
|
|
|
|
|
*/
|
|
|
|
|
public const ROOM_CLEAR_SCREEN = 'room.clear_screen';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 礼包红包权限。
|
|
|
|
|
*/
|
|
|
|
|
public const ROOM_RED_PACKET = 'room.red_packet';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 百家乐买单活动权限。
|
|
|
|
|
*/
|
|
|
|
|
public const ROOM_BACCARAT_LOSS_COVER = 'room.baccarat_loss_cover';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 全屏特效权限。
|
|
|
|
|
*/
|
|
|
|
|
public const ROOM_FULLSCREEN_EFFECT = 'room.fullscreen_effect';
|
|
|
|
|
|
2026-04-21 18:00:02 +08:00
|
|
|
/**
|
|
|
|
|
* 用户警告权限。
|
|
|
|
|
*/
|
|
|
|
|
public const USER_WARN = 'room.user_warn';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户踢出权限。
|
|
|
|
|
*/
|
|
|
|
|
public const USER_KICK = 'room.user_kick';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户禁言权限。
|
|
|
|
|
*/
|
|
|
|
|
public const USER_MUTE = 'room.user_mute';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户冻结权限。
|
|
|
|
|
*/
|
|
|
|
|
public const USER_FREEZE = 'room.user_freeze';
|
|
|
|
|
|
2026-04-21 16:43:17 +08:00
|
|
|
/**
|
|
|
|
|
* 返回全部权限定义。
|
|
|
|
|
*
|
|
|
|
|
* @return array<string, array{group: string, label: string, description: string}>
|
|
|
|
|
*/
|
|
|
|
|
public static function definitions(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
self::ROOM_ANNOUNCEMENT => [
|
|
|
|
|
'group' => '聊天室管理',
|
|
|
|
|
'label' => '设置公告',
|
|
|
|
|
'description' => '允许修改聊天室顶部滚动公告。',
|
|
|
|
|
],
|
|
|
|
|
self::ROOM_PUBLIC_BROADCAST => [
|
|
|
|
|
'group' => '聊天室管理',
|
|
|
|
|
'label' => '公屏讲话',
|
|
|
|
|
'description' => '允许在聊天室内发送管理员公屏讲话。',
|
|
|
|
|
],
|
|
|
|
|
self::ROOM_CLEAR_SCREEN => [
|
|
|
|
|
'group' => '聊天室管理',
|
|
|
|
|
'label' => '全员清屏',
|
|
|
|
|
'description' => '允许清除当前房间所有人的普通聊天记录。',
|
|
|
|
|
],
|
|
|
|
|
self::ROOM_RED_PACKET => [
|
|
|
|
|
'group' => '活动管理',
|
|
|
|
|
'label' => '礼包红包',
|
|
|
|
|
'description' => '允许在聊天室内发出金币或经验礼包。',
|
|
|
|
|
],
|
|
|
|
|
self::ROOM_BACCARAT_LOSS_COVER => [
|
|
|
|
|
'group' => '活动管理',
|
|
|
|
|
'label' => '买单活动',
|
|
|
|
|
'description' => '允许创建和结束百家乐买单活动。',
|
|
|
|
|
],
|
|
|
|
|
self::ROOM_FULLSCREEN_EFFECT => [
|
|
|
|
|
'group' => '全屏特效',
|
|
|
|
|
'label' => '全屏特效',
|
|
|
|
|
'description' => '允许触发聊天室内全部全屏动画特效。',
|
|
|
|
|
],
|
2026-04-21 18:00:02 +08:00
|
|
|
self::USER_WARN => [
|
|
|
|
|
'group' => '用户管理',
|
|
|
|
|
'label' => '警告用户',
|
|
|
|
|
'description' => '允许在用户名片内对低于自身职务的用户发送警告。',
|
|
|
|
|
],
|
|
|
|
|
self::USER_KICK => [
|
|
|
|
|
'group' => '用户管理',
|
|
|
|
|
'label' => '踢出用户',
|
|
|
|
|
'description' => '允许在用户名片内将低于自身职务的用户踢出当前聊天室。',
|
|
|
|
|
],
|
|
|
|
|
self::USER_MUTE => [
|
|
|
|
|
'group' => '用户管理',
|
|
|
|
|
'label' => '禁言用户',
|
|
|
|
|
'description' => '允许在用户名片内对低于自身职务的用户执行禁言。',
|
|
|
|
|
],
|
|
|
|
|
self::USER_FREEZE => [
|
|
|
|
|
'group' => '用户管理',
|
|
|
|
|
'label' => '冻结用户',
|
|
|
|
|
'description' => '允许在用户名片内冻结低于自身职务的用户账号。',
|
|
|
|
|
],
|
2026-04-21 16:43:17 +08:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回全部权限码列表。
|
|
|
|
|
*
|
|
|
|
|
* @return list<string>
|
|
|
|
|
*/
|
|
|
|
|
public static function codes(): array
|
|
|
|
|
{
|
|
|
|
|
return array_keys(self::definitions());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回权限码到中文标题的映射。
|
|
|
|
|
*
|
|
|
|
|
* @return array<string, string>
|
|
|
|
|
*/
|
|
|
|
|
public static function labelMap(): array
|
|
|
|
|
{
|
|
|
|
|
$labels = [];
|
|
|
|
|
|
|
|
|
|
foreach (self::definitions() as $code => $definition) {
|
|
|
|
|
$labels[$code] = $definition['label'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $labels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 按分组返回权限定义,供后台表单渲染。
|
|
|
|
|
*
|
|
|
|
|
* @return array<string, array<string, array{label: string, description: string}>>
|
|
|
|
|
*/
|
|
|
|
|
public static function groupedDefinitions(): array
|
|
|
|
|
{
|
|
|
|
|
$grouped = [];
|
|
|
|
|
|
|
|
|
|
foreach (self::definitions() as $code => $definition) {
|
|
|
|
|
$grouped[$definition['group']][$code] = [
|
|
|
|
|
'label' => $definition['label'],
|
|
|
|
|
'description' => $definition['description'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $grouped;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将权限码数组转换为中文标题列表。
|
|
|
|
|
*
|
|
|
|
|
* @param list<string> $codes
|
|
|
|
|
* @return list<string>
|
|
|
|
|
*/
|
|
|
|
|
public static function summaryLabels(array $codes): array
|
|
|
|
|
{
|
|
|
|
|
$labels = self::labelMap();
|
|
|
|
|
|
|
|
|
|
return array_values(array_map(
|
|
|
|
|
fn (string $code): string => $labels[$code] ?? $code,
|
|
|
|
|
array_values(array_intersect(self::codes(), $codes))
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据职务等级返回默认权限。
|
|
|
|
|
*
|
|
|
|
|
* 默认策略:
|
|
|
|
|
* - Lv.60 及以上默认拥有「设置公告」
|
|
|
|
|
* - Lv.97 及以上默认拥有顶部管理菜单全部权限
|
|
|
|
|
*
|
|
|
|
|
* @return list<string>
|
|
|
|
|
*/
|
|
|
|
|
public static function defaultPermissionsForLevel(int $level): array
|
|
|
|
|
{
|
|
|
|
|
if ($level >= 97) {
|
|
|
|
|
return self::codes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($level >= 60) {
|
|
|
|
|
return [self::ROOM_ANNOUNCEMENT];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
}
|