优化存点

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
+7 -3
View File
@@ -23,6 +23,7 @@ use App\Models\PositionDutyLog;
use App\Models\Sysparam;
use App\Models\User;
use App\Services\ChatStateService;
use App\Services\ChatUserPresenceService;
use App\Services\UserCurrencyService;
use App\Services\VipService;
use Illuminate\Console\Command;
@@ -46,6 +47,7 @@ class AutoSaveExp extends Command
*/
public function __construct(
private readonly ChatStateService $chatState,
private readonly ChatUserPresenceService $chatUserPresenceService,
private readonly VipService $vipService,
private readonly UserCurrencyService $currencyService,
) {
@@ -164,7 +166,7 @@ class AutoSaveExp extends Command
);
}
$user->refresh(); // 刷新获取最新属性(service 已原子更新)
$user->load('activePosition.position'); // 确保职务及职位关联已加载
$user->load(['activePosition.position.department', 'vipLevel']); // 存点通知需要展示部门、职务与会员身份。
// 3. 自动升降级逻辑
// - 有在职职务的用户:等级固定为职务对应等级,不随经验变化
@@ -229,9 +231,11 @@ class AutoSaveExp extends Command
$jjbDisplay = $user->jjb ?? 0;
$gainStr = ! empty($gainParts) ? ' 本次获得:'.implode('', $gainParts) : '';
// 格式:⏰ 自动存点 · LV.100 · 经验 10,468 · 金币 8,345 · 已满级 · 本次获得:经验+1,金币+3
$identitySummary = $this->chatUserPresenceService->buildIdentitySummary($user);
// 格式:⏰ 自动存点 · 部门 X · 职务 Y · 会员 Z · LV.100 · 经验 10,468 · 金币 8,345 · 已满级 · 本次获得:经验+1,金币+3
$statusTag = $user->user_level >= $superLevel ? ' · 已满级 ✓' : '';
$content = "⏰ 自动存点 · LV.{$user->user_level} · 经验 {$user->exp_num} · 金币 {$jjbDisplay}{$statusTag}{$gainStr}";
$content = "⏰ 自动存点 · {$identitySummary['inline']} · LV.{$user->user_level} · 经验 {$user->exp_num} · 金币 {$jjbDisplay}{$statusTag}{$gainStr}";
$noticeMsg = [
'id' => $this->chatState->nextMessageId($roomId),
+6
View File
@@ -634,6 +634,7 @@ class ChatController extends Controller
} elseif ($user->user_level >= $superLevel) {
$title = '管理员';
}
$identitySummary = $this->chatUserPresenceService->buildIdentitySummary($user);
return response()->json([
'status' => 'success',
@@ -644,6 +645,11 @@ class ChatController extends Controller
'jjb_gain' => $actualJjbGain,
'user_level' => $user->user_level,
'title' => $title,
'identity_summary' => $identitySummary['inline'],
'department_name' => $identitySummary['department_name'],
'position_name' => $identitySummary['position_name'],
'vip_name' => $identitySummary['vip_name'],
'vip_icon' => $identitySummary['vip_icon'],
'leveled_up' => $leveledUp,
'is_max_level' => $user->user_level >= $superLevel,
'auto_event' => $autoEvent ? $autoEvent->renderText($user->username) : null,
+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}",
];
}
/**
* 读取用户当前仍然有效的当日状态。
*