修复:勤务日榜在线时长统计虚高(142小时)+ UI文字调整
Bug修复: - closeDutyLog 增加 whereDate 限制,只关闭今日日志,历史遗留记录置0,避免跨天时长被计入榜单 - tickDutyLog(ChatController/AutoSaveExp)找不到今日开放日志时不再盲目新建,避免同一 login_at 产生几十条重复记录后 SUM 叠加导致虚假142小时 - AppointmentService 撤职时 closeDutyLog 同步增加今日/历史遗留区分处理 UI调整: - 登录页版权文字「飘落的流星」→「流星」 - 后台布局标题「飘落流星 控制台」→「控制台」 - 后台侧边栏移除非超管查看各模块时的「(只读)」标注
This commit is contained in:
@@ -919,13 +919,25 @@ class ChatController extends Controller
|
||||
*/
|
||||
private function closeDutyLog(int $userId): void
|
||||
{
|
||||
// 将今日开放日志关闭并结算实际时长
|
||||
PositionDutyLog::query()
|
||||
->where('user_id', $userId)
|
||||
->whereNull('logout_at')
|
||||
->whereDate('login_at', today())
|
||||
->update([
|
||||
'logout_at' => now(),
|
||||
'logout_at' => now(),
|
||||
'duration_seconds' => DB::raw('GREATEST(0, TIMESTAMPDIFF(SECOND, login_at, NOW()))'),
|
||||
]);
|
||||
|
||||
// 清理历史遭留未关闭的日志(login_at 非今日),直接将它们的时长置 0,避免被算入任何榜单
|
||||
PositionDutyLog::query()
|
||||
->where('user_id', $userId)
|
||||
->whereNull('logout_at')
|
||||
->whereDate('login_at', '<', today())
|
||||
->update([
|
||||
'logout_at' => DB::raw('login_at'), // 时长 = 0
|
||||
'duration_seconds' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -947,7 +959,7 @@ class ChatController extends Controller
|
||||
return;
|
||||
}
|
||||
|
||||
// 今日是否已有开放日志
|
||||
// ① 优先找今日未关闭的开放日志,直接刷新时长
|
||||
$openLog = PositionDutyLog::query()
|
||||
->where('user_id', $user->id)
|
||||
->whereNull('logout_at')
|
||||
@@ -955,8 +967,6 @@ class ChatController extends Controller
|
||||
->first();
|
||||
|
||||
if ($openLog) {
|
||||
// 刷新实时在线时长
|
||||
// 绕过模型 cast(integer),使用 DB::table 直接执行 SQL 表达式
|
||||
DB::table('position_duty_logs')
|
||||
->where('id', $openLog->id)
|
||||
->update(['duration_seconds' => DB::raw('GREATEST(0, TIMESTAMPDIFF(SECOND, login_at, NOW()))')]);
|
||||
@@ -964,17 +974,19 @@ class ChatController extends Controller
|
||||
return;
|
||||
}
|
||||
|
||||
// 今日无日志 → 新建,login_at 优先用进房时间
|
||||
$loginAt = $user->in_time && $user->in_time->isToday()
|
||||
// ② 今日是否已有任意日志(含已关闭的)?
|
||||
// 若有:说明用户本次是重新进房,已经有历史记录,直接新建本次进房的日志段
|
||||
// 若无:说明今天第一次进房,新建,login_at 优先用 in_time
|
||||
$loginAt = ($user->in_time && $user->in_time->isToday())
|
||||
? $user->in_time
|
||||
: now();
|
||||
|
||||
PositionDutyLog::create([
|
||||
'user_id' => $user->id,
|
||||
'user_id' => $user->id,
|
||||
'user_position_id' => $activeUP->id,
|
||||
'login_at' => $loginAt,
|
||||
'ip_address' => request()->ip(),
|
||||
'room_id' => $roomId,
|
||||
'login_at' => $loginAt,
|
||||
'ip_address' => request()->ip(),
|
||||
'room_id' => $roomId,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user