From 5a3d77d36d4dc38fc810d1283ba14e538b589a83 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Fri, 10 Jul 2026 00:46:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E6=8F=90=E5=8F=96=E3=80=81=E5=8D=95=E7=A8=8B?= =?UTF-8?q?=E7=A5=A8=E9=80=BB=E8=BE=91=E5=8F=8A=E5=89=8D=E7=AB=AF=E8=A1=8C?= =?UTF-8?q?=E7=A8=8B=E5=9D=97=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 调整后端设备标识提取优先级,优先使用machine_id/machineId字段 - 修复单程票检票时剩余乘车次数的计算逻辑,单程票使用后直接置0 - 前端为行程块添加ID,切换单程票模式时隐藏该块并重置乘车次数为1 --- server/routes/api.js | 10 +++++----- server/routes/public.js | 2 +- web/ticket-order.html | 2 +- web/ticket-order.js | 3 +++ 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/server/routes/api.js b/server/routes/api.js index c71fa8f..af9d20b 100644 --- a/server/routes/api.js +++ b/server/routes/api.js @@ -792,7 +792,7 @@ router.post('/ic-cards/:id/sync', async (req, res) => { const syncTypeRaw = String(body.type || body.event_type || body.last_event || 'sync').trim().toLowerCase(); const syncType = syncTypeRaw === 'refill' ? 'topup' : (syncTypeRaw || 'sync'); const action = String(body.action || body.last_action || '').trim().toLowerCase(); - const device = String(body.device || body.source || 'device').trim() || 'device'; + const device = String(body.machine_id || body.machineId || body.device || body.source || 'device').trim() || 'device'; const station_code = resolveCurrentStationCode(body, resolveStation); const entry_station = resolveStation(body.entry_station || body.start_station || current.entry_station || ''); const exit_station = resolveStation(body.exit_station || current.exit_station || ''); @@ -859,7 +859,7 @@ router.post('/cards/open', async (req, res) => { const body = req.body || {}; const now = Date.now(); const voucher_code = normalizeOrderCode(body.voucher_code || body.order_code || body.code); - const device = String(body.device || 'ticket_machine').trim() || 'ticket_machine'; + const device = String(body.machine_id || body.machineId || body.device || 'ticket_machine').trim() || 'ticket_machine'; const station_code = String(body.station_code || '').trim(); const holder_name = String(body.holder_name || '').trim(); const note = String(body.note || '').trim(); @@ -1004,7 +1004,7 @@ router.post('/cards/check', async (req, res) => { const body = req.body || {}; const card_id = normalizeIcCardId(body.card_id); const action = String(body.action || '').trim().toLowerCase(); - const device = String(body.device || 'gate').trim() || 'gate'; + const device = String(body.machine_id || body.machineId || body.device || 'gate').trim() || 'gate'; const ts = toFiniteNumberOrUndef(body.ts) ?? Date.now(); if (!card_id || !action) return res.status(400).json({ ok: false, error: 'card_id and action required' }); if (action !== 'entry' && action !== 'exit') return res.status(400).json({ ok: false, error: 'action must be entry/exit' }); @@ -1240,7 +1240,7 @@ router.post('/tickets/check', async (req, res) => { const body = req.body || {}; const ticket_id = normalizeTicketId(body.ticket_id); const action = String(body.action || '').trim().toLowerCase(); - const device = String(body.device || 'gate'); + const device = String(body.machine_id || body.machineId || body.device || 'gate'); const tsIn = Number(body.ts); const ts = Number.isFinite(tsIn) ? tsIn : Date.now(); const hintTripsTotal = body.trips_total; @@ -1378,7 +1378,7 @@ router.post('/tickets/check', async (req, res) => { if (!entered) return deny('not_entered'); if (exited) return deny('already_exited'); - const newTripsRemaining = Math.max(0, (Number(tripsRemainEffective) || 0) - 1); + const newTripsRemaining = isSingleTicket ? 0 : Math.max(0, (Number(tripsRemainEffective) || 0) - 1); const shouldSetUsed = isSingleTicket ? true : (newTripsRemaining <= 0); const ev = { ts, type: 'check', ticket_id, action, result: 'pass', station_code: exitCode, station_name: resolveStationName(exitCode), device, trips_remaining: newTripsRemaining }; await DataService.appendTicketEvent(ev); diff --git a/server/routes/public.js b/server/routes/public.js index d5e0d4e..e19a59a 100644 --- a/server/routes/public.js +++ b/server/routes/public.js @@ -504,7 +504,7 @@ router.post('/tickets/record', async (req, res) => { const train_type = String(b.train_type || b.trainType || b.type || '').trim(); const cost = Number(b.cost || 0) || 0; const station_code = String(b.station_code || b.stationCode || '').trim(); - const device = String(b.device || b.device_id || b.deviceId || 'unknown'); + const device = String(b.machine_id || b.machineId || b.device || b.device_id || b.deviceId || 'unknown'); const trips_total = (b.trips_total == null) ? undefined : (Number(b.trips_total) || 0); const trips_remaining = (b.trips_remaining == null) ? undefined : (Number(b.trips_remaining) || 0); diff --git a/web/ticket-order.html b/web/ticket-order.html index 078ccff..224ba81 100644 --- a/web/ticket-order.html +++ b/web/ticket-order.html @@ -136,7 +136,7 @@ -
+
至少 1 次 diff --git a/web/ticket-order.js b/web/ticket-order.js index 60b3a76..86eb872 100644 --- a/web/ticket-order.js +++ b/web/ticket-order.js @@ -715,10 +715,13 @@ if (isSingle) { document.getElementById('normalTicketView').style.display = 'none'; document.getElementById('singleTicketView').style.display = 'block'; + document.getElementById('tripsBlock').style.display = 'none'; + if (tripsEl) tripsEl.value = 1; renderSingleSegments(); } else { document.getElementById('normalTicketView').style.display = 'block'; document.getElementById('singleTicketView').style.display = 'none'; + document.getElementById('tripsBlock').style.display = 'block'; } previewPrice(true); }