From a97ff3fb2be69814057d57fe220598abf6b2ea91 Mon Sep 17 00:00:00 2001 From: lion <120344285@qq.com> Date: Fri, 22 May 2026 17:59:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B8=E9=94=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/GateController.php | 62 +++++++++++++++++-- public/admin/index.html | 2 +- ...5a1ac5.css => chunk-604ecf7d.f0b703ac.css} | 2 +- .../js/{app.a8fd346e.js => app.7b49a23e.js} | 2 +- ...d3208d6c.js => chunk-604ecf7d.458cf088.js} | 2 +- 5 files changed, 60 insertions(+), 10 deletions(-) rename public/admin/static/css/{chunk-698f6f63.195a1ac5.css => chunk-604ecf7d.f0b703ac.css} (79%) rename public/admin/static/js/{app.a8fd346e.js => app.7b49a23e.js} (99%) rename public/admin/static/js/{chunk-698f6f63.d3208d6c.js => chunk-604ecf7d.458cf088.js} (50%) diff --git a/app/Http/Controllers/Admin/GateController.php b/app/Http/Controllers/Admin/GateController.php index 9fb9d2a..73248c8 100755 --- a/app/Http/Controllers/Admin/GateController.php +++ b/app/Http/Controllers/Admin/GateController.php @@ -122,9 +122,50 @@ class GateController extends CommonController } $list = $list->paginate($all['page_size'] ?? 20); + $today = Carbon::now()->format('Y-m-d'); + $list->getCollection()->transform(function ($visit) use ($today) { + if ((int) $visit->long_time === 1) { + $visit->setAttribute('gate_verify_type', $this->computeLongTermGateVerifyType($visit, $today)); + } + + return $visit; + }); + return $this->success($list); } + /** + * 长期访客:单条门岗流水的业务日期(与自然日核销口径一致,缺 biz_date 时用创建时间换算应用时区) + */ + protected function gateLogBizDateForLongTerm(GateLog $log): string + { + if (!empty($log->biz_date)) { + return Carbon::parse((string) $log->biz_date)->format('Y-m-d'); + } + + return Carbon::parse((string) $log->created_at)->timezone(config('app.timezone'))->format('Y-m-d'); + } + + /** + * 长期访客:门岗建议本次核销 1 进厂 / 2 离厂(与 useCode 长期规则对齐) + */ + protected function computeLongTermGateVerifyType(Visit $visit, string $today): int + { + $latestGateLog = GateLog::where('visit_id', $visit->id)->orderByDesc('id')->first(); + if (!$latestGateLog && !empty($visit->code)) { + $latestGateLog = GateLog::where('code', $visit->code)->orderByDesc('id')->first(); + } + if (!$latestGateLog) { + return 1; + } + if ((int) $latestGateLog->action === 2) { + return 1; + } + $biz = $this->gateLogBizDateForLongTerm($latestGateLog); + + return $biz < $today ? 1 : 2; + } + /** * @OA\Get( * path="/api/admin/gate/use-code", @@ -195,18 +236,27 @@ class GateController extends CommonController if ($today < $check->start_date || $today > $check->end_date) { return $this->fail([ResponseCode::ERROR_BUSINESS, '当前不在长期访客有效周期内']); } - // 进/离异以整条预约「最新一条门岗流水」为主:与会话 audit_status「已进厂」一致; - // 昨日进今日离:最后一条仍为进厂时允许核销离厂(biz_date 仍记当日); - // 当日可先离再进——离后最新为离厂,仍可再核销进厂。 + // 长期访客:以「全局最新流水」判断是否仍在厂未离;但以「本条进厂的 biz_date」决定能否核销离厂 + // ——昨日进今日第一次操作须先核销进厂(记入今日),不能直接核销离厂;当日先离仍可再核进。 $latestGateLog = GateLog::where('visit_id', $check->id)->orderByDesc('id')->first(); if (!$latestGateLog && !empty($check->code)) { $latestGateLog = GateLog::where('code', $check->code)->orderByDesc('id')->first(); } if ((int)$all['type'] === 1 && $latestGateLog && (int)$latestGateLog->action === 1) { - return $this->fail([ResponseCode::ERROR_BUSINESS, '上次进厂尚未离厂,请先核销离厂后再进厂']); + $enterBizDate = $this->gateLogBizDateForLongTerm($latestGateLog); + if ($enterBizDate >= $today) { + return $this->fail([ResponseCode::ERROR_BUSINESS, '今日已进厂尚未离厂,请先核销离厂后再进厂']); + } + // 未离开的进厂业务日早于今日:视为跨日未完成场次,允许再核销一笔「当日进厂」 } - if ((int)$all['type'] === 2 && (!$latestGateLog || (int)$latestGateLog->action !== 1)) { - return $this->fail([ResponseCode::ERROR_BUSINESS, '无有效未离厂的进厂记录,无法核销离厂。请先核销进厂后再离厂']); + if ((int)$all['type'] === 2) { + if (!$latestGateLog || (int)$latestGateLog->action !== 1) { + return $this->fail([ResponseCode::ERROR_BUSINESS, '无有效未离厂的进厂记录,无法核销离厂。请先核销进厂后再离厂']); + } + $enterBizDate = $this->gateLogBizDateForLongTerm($latestGateLog); + if ($enterBizDate !== $today) { + return $this->fail([ResponseCode::ERROR_BUSINESS, '当前未离厂的进厂记录不属于今日,请先核销当日进厂后再离厂']); + } } } $remark = '进厂'; diff --git a/public/admin/index.html b/public/admin/index.html index d1cb64c..a5135eb 100644 --- a/public/admin/index.html +++ b/public/admin/index.html @@ -1,3 +1,3 @@