From c9cab898c2ebd9f09707e2d045891904bfa170fe Mon Sep 17 00:00:00 2001 From: lkddi Date: Wed, 18 Mar 2026 21:31:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8B=A4=E5=8A=A1=E6=A6=9C=E5=8F=AA=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=B7=B2=E5=85=B3=E9=97=AD=E8=AE=B0=E5=BD=95(whereNot?= =?UTF-8?q?Null=20logout=5Fat)=EF=BC=9B=E6=B8=85=E7=90=86=E4=BB=8A?= =?UTF-8?q?=E6=97=A5=E9=87=8D=E5=A4=8D=E5=9D=8F=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/DutyHallController.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/DutyHallController.php b/app/Http/Controllers/DutyHallController.php index ab69b04..44745d2 100644 --- a/app/Http/Controllers/DutyHallController.php +++ b/app/Http/Controllers/DutyHallController.php @@ -50,17 +50,9 @@ class DutyHallController extends Controller // ① 在线时长(position_duty_logs) $dutyQuery = PositionDutyLog::query() - ->selectRaw(' - user_id, - SUM( - CASE - WHEN logout_at IS NULL - THEN GREATEST(0, TIMESTAMPDIFF(SECOND, login_at, NOW())) - ELSE duration_seconds - END - ) as total_seconds, - COUNT(*) as checkin_count - '); + ->selectRaw('user_id, SUM(duration_seconds) as total_seconds, COUNT(*) as checkin_count') + // 只统计有离开时间的已完结记录,open session 不计入(防止实时计算偏差) + ->whereNotNull('logout_at'); // ② 管理操作(position_authority_logs,排除任命/撤销等人事操作) $authQuery = PositionAuthorityLog::query()