优化存点

This commit is contained in:
2026-04-25 02:24:24 +08:00
parent 5bfcd75442
commit 8bd1dae9e1
6 changed files with 221 additions and 9 deletions
+42 -2
View File
@@ -11,6 +11,9 @@ use App\Models\Sysparam;
use App\Models\User;
use App\Support\ChatDailyStatusCatalog;
/**
* 类功能:统一生成聊天室在线用户与身份展示相关载荷。
*/
class ChatUserPresenceService
{
/**
@@ -21,8 +24,8 @@ class ChatUserPresenceService
public function build(User $user): array
{
$superLevel = (int) Sysparam::getValue('superlevel', '100');
$activePosition = $user->activePosition;
$position = $activePosition?->position;
$user->loadMissing(['activePosition.position.department', 'vipLevel']);
$position = $user->activePosition?->position;
$payload = [
'id' => $user->id,
'user_id' => $user->id,
@@ -64,6 +67,43 @@ class ChatUserPresenceService
return $payload;
}
/**
* 构建用户部门、职务与会员展示信息。
*
* @return array{
* department_name: string,
* position_icon: string,
* position_name: string,
* vip_icon: string,
* vip_name: string,
* vip_label: string,
* inline: string
* }
*/
public function buildIdentitySummary(User $user): array
{
$user->loadMissing(['activePosition.position.department', 'vipLevel']);
$position = $user->activePosition?->position;
$departmentName = $position?->department?->name ?? '无部门';
$positionIcon = $position?->icon ?? '';
$positionName = $position?->name ?? '无职务';
$vipIcon = $user->vipIcon();
$vipName = $user->vipName() ?: '普通会员';
$vipLabel = trim($vipIcon.' '.$vipName);
$positionLabel = trim($positionIcon.' '.$positionName);
return [
'department_name' => $departmentName,
'position_icon' => $positionIcon,
'position_name' => $positionName,
'vip_icon' => $vipIcon,
'vip_name' => $vipName,
'vip_label' => $vipLabel,
'inline' => "部门 {$departmentName} · 职务 {$positionLabel} · 会员 {$vipLabel}",
];
}
/**
* 读取用户当前仍然有效的当日状态。
*