修复勤务日榜时长膨胀:重建session时用now()而非旧in_time,补updated_at刷新防误关,视图标签改为所有
This commit is contained in:
@@ -293,13 +293,23 @@ class AutoSaveExp extends Command
|
|||||||
if ($openLog) {
|
if ($openLog) {
|
||||||
DB::table('position_duty_logs')
|
DB::table('position_duty_logs')
|
||||||
->where('id', $openLog->id)
|
->where('id', $openLog->id)
|
||||||
->update(['duration_seconds' => DB::raw('GREATEST(0, TIMESTAMPDIFF(SECOND, login_at, NOW()))')]);
|
->update([
|
||||||
|
'duration_seconds' => DB::raw('GREATEST(0, TIMESTAMPDIFF(SECOND, login_at, NOW()))'),
|
||||||
|
'updated_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ② 今日无开放日志 → 新建(login_at 优先用今日进房时间,跨天则用 now())
|
// ② 今日无开放日志 → 新建
|
||||||
$loginAt = ($user->in_time && $user->in_time->isToday())
|
// 若今日已有已关闭的日志(是重建场景),必须用 now(),防止重用旧 in_time 累积膨胀
|
||||||
|
$hasClosedToday = PositionDutyLog::query()
|
||||||
|
->where('user_id', $user->id)
|
||||||
|
->whereDate('login_at', today())
|
||||||
|
->whereNotNull('logout_at')
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
$loginAt = (! $hasClosedToday && $user->in_time && $user->in_time->isToday())
|
||||||
? $user->in_time
|
? $user->in_time
|
||||||
: now();
|
: now();
|
||||||
|
|
||||||
|
|||||||
@@ -1065,15 +1065,27 @@ class ChatController extends Controller
|
|||||||
if ($openLog) {
|
if ($openLog) {
|
||||||
DB::table('position_duty_logs')
|
DB::table('position_duty_logs')
|
||||||
->where('id', $openLog->id)
|
->where('id', $openLog->id)
|
||||||
->update(['duration_seconds' => DB::raw('GREATEST(0, TIMESTAMPDIFF(SECOND, login_at, NOW()))')]);
|
->update([
|
||||||
|
'duration_seconds' => DB::raw('GREATEST(0, TIMESTAMPDIFF(SECOND, login_at, NOW()))'),
|
||||||
|
// DB::table raw update 不自动刷 updated_at,必须手动设置,
|
||||||
|
// 否则 CloseStaleDutyLogs 会误判此 session 为掉线而提前关闭。
|
||||||
|
'updated_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ② 今日是否已有任意日志(含已关闭的)?
|
// ② 若今日已有「已关闭」的日志段,说明是 CloseStaleDutyLogs 关闭后重建:
|
||||||
// 若有:说明用户本次是重新进房,已经有历史记录,直接新建本次进房的日志段
|
// 必须用 now() 作为 login_at,防止重用旧的 in_time(如今日 00:00)导致
|
||||||
// 若无:说明今天第一次进房,新建,login_at 优先用 in_time
|
// 每次重建的 duration_seconds 都从午夜算起,累加成等差数列(产生 249h 等异常值)。
|
||||||
$loginAt = ($user->in_time && $user->in_time->isToday())
|
// 只有今日首次创建(无任何历史日志段)时,才用 in_time 保留真实进房时刻。
|
||||||
|
$hasClosedToday = PositionDutyLog::query()
|
||||||
|
->where('user_id', $user->id)
|
||||||
|
->whereDate('login_at', today())
|
||||||
|
->whereNotNull('logout_at')
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
$loginAt = (! $hasClosedToday && $user->in_time && $user->in_time->isToday())
|
||||||
? $user->in_time
|
? $user->in_time
|
||||||
: now();
|
: now();
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
<div class="text-2xl font-bold text-green-600">
|
<div class="text-2xl font-bold text-green-600">
|
||||||
{{ gmdate('H', $logs->sum('duration_seconds')) }}h {{ gmdate('i', $logs->sum('duration_seconds')) }}m
|
{{ gmdate('H', $logs->sum('duration_seconds')) }}h {{ gmdate('i', $logs->sum('duration_seconds')) }}m
|
||||||
</div>
|
</div>
|
||||||
<div class="text-xs text-gray-500 mt-1">累计在线时长(当前页)</div>
|
<div class="text-xs text-gray-500 mt-1">累计在线时长(所有)</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="bg-white rounded-xl p-5 border shadow-sm text-center">
|
<div class="bg-white rounded-xl p-5 border shadow-sm text-center">
|
||||||
<div class="text-2xl font-bold text-orange-600">{{ $userPosition->total_rewarded_coins }}</div>
|
<div class="text-2xl font-bold text-orange-600">{{ $userPosition->total_rewarded_coins }}</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user