From 230418079c9d57b4cb52acf6d28e9c58d1625a34 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Fri, 10 Jul 2026 14:55:42 +0800 Subject: [PATCH] 3 --- gate.lua | 12 ++++++++++-- refillmachine.lua | 10 +++++++++- ticketmachine.lua | 6 +++++- web/ic-card-admin.js | 4 +++- web/ic-card-search.js | 4 +++- web/index.js | 8 ++++++-- web/ticket-board.html | 6 ++++-- web/ticket-route.js | 4 +++- web/ticket-search.js | 4 +++- 9 files changed, 46 insertions(+), 12 deletions(-) diff --git a/gate.lua b/gate.lua index ba05cad..e7a6158 100644 --- a/gate.lua +++ b/gate.lua @@ -992,6 +992,14 @@ local function deductICCardBalance(dev, amount) return false, tostring(detail or "deduct_failed") end +local function currentDeviceId() + local label = os.getComputerLabel() + if label and label ~= "" then + return label + end + return "闸机#" .. tostring(os.getComputerID()) +end + local function syncICCardState(cardId, payload) local id = trim(cardId) if #id == 0 then return false, "missing_card_id" end @@ -1131,7 +1139,7 @@ local function handleICCardScan(scan, side, scanDev) local okSync, syncResp = syncICCardState(cardId, { type = "check", action = usedAction, - device = "gate", + device = currentDeviceId(), ts = syncTs, station_code = exitStation, entry_station = entryStation, @@ -1189,7 +1197,7 @@ local function handleScan(scan, side, scanDev) action = act, station_codes = stationCodesPayload, station_code = stationCodeForSide(side), - device = "gate", + device = currentDeviceId(), ts = os.epoch("utc"), trips_total = hintTripsTotal, trips_remaining = hintTripsRemaining, diff --git a/refillmachine.lua b/refillmachine.lua index 2588be7..2f9e24a 100644 --- a/refillmachine.lua +++ b/refillmachine.lua @@ -115,13 +115,21 @@ local function postJSON(url, payload) end end +local function currentDeviceId() + local label = os.getComputerLabel() + if label and label ~= "" then + return label + end + return "充值机#" .. tostring(os.getComputerID()) +end + local function syncRefillResult(cardInfo, amount, balance) local cardId = trim(cardInfo and cardInfo.cardId or "") if #cardId == 0 then return false, "missing_card_id" end local url = API_BASE .. "/ic-cards/" .. urlEncodeComponent(cardId) .. "/sync" return postJSON(url, { type = "topup", - device = "refill_machine", + device = currentDeviceId(), amount = tonumber(amount) or 0, balance = tonumber(balance) or 0, result = "pass", diff --git a/ticketmachine.lua b/ticketmachine.lua index 7247f37..b352cbd 100644 --- a/ticketmachine.lua +++ b/ticketmachine.lua @@ -237,7 +237,11 @@ local function firstNumber(...) end local function currentDeviceId() - return 'ticket_machine' + local label = os.getComputerLabel() + if label and label ~= "" then + return label + end + return "#" .. tostring(os.getComputerID()) end local function normalizeTrainTypeLabel(v) diff --git a/web/ic-card-admin.js b/web/ic-card-admin.js index 8c64240..da83e03 100644 --- a/web/ic-card-admin.js +++ b/web/ic-card-admin.js @@ -198,7 +198,9 @@ deviceId = '闸机'; } else if (dStr === 'refill_machine') { deviceId = '充值机'; - } else if (dStr === 'ticket_machine' || dStr === 'ticket_vending_machine' || /^#?\d+$/.test(dStr) || dStr.includes('computer') || dStr === 'unknown' || dStr === '---' || dStr === '') { + } else if (dStr === 'ticket_machine' || dStr === 'ticket_vending_machine') { + deviceId = '售票机'; + } else if (dStr === 'unknown' || dStr === '---' || dStr === '') { if (type === 'entry' || action === 'entry' || type === 'exit' || action === 'exit' || type === 'check') { deviceId = '闸机'; } else if (type === 'topup' || type === 'refill' || action === 'topup' || type === '充值') { diff --git a/web/ic-card-search.js b/web/ic-card-search.js index 0bac366..570f543 100644 --- a/web/ic-card-search.js +++ b/web/ic-card-search.js @@ -97,7 +97,9 @@ deviceId = '闸机'; } else if (dStr === 'refill_machine') { deviceId = '充值机'; - } else if (dStr === 'ticket_machine' || dStr === 'ticket_vending_machine' || /^#?\d+$/.test(dStr) || dStr.includes('computer') || dStr === 'unknown' || dStr === '---' || dStr === '') { + } else if (dStr === 'ticket_machine' || dStr === 'ticket_vending_machine') { + deviceId = '售票机'; + } else if (dStr === 'unknown' || dStr === '---' || dStr === '') { if (type === 'entry' || action === 'entry' || type === 'exit' || action === 'exit' || type === 'check') { deviceId = '闸机'; } else if (type === 'topup' || type === 'refill' || action === 'topup' || type === '充值') { diff --git a/web/index.js b/web/index.js index ce5d1cd..0b86d9f 100644 --- a/web/index.js +++ b/web/index.js @@ -355,7 +355,9 @@ createApp({ deviceId = '闸机'; } else if (dStr === 'refill_machine') { deviceId = '充值机'; - } else if (dStr === 'ticket_machine' || dStr === 'ticket_vending_machine' || /^#?\d+$/.test(dStr) || dStr.includes('computer') || dStr === 'unknown' || dStr === '---' || dStr === '') { + } else if (dStr === 'ticket_machine' || dStr === 'ticket_vending_machine') { + deviceId = '售票机'; + } else if (dStr === 'unknown' || dStr === '---' || dStr === '') { if (type === 'entry' || action === 'entry' || type === 'exit' || action === 'exit' || type === 'check') { deviceId = '闸机'; } else { @@ -471,7 +473,9 @@ createApp({ deviceId = '闸机'; } else if (dStr === 'refill_machine') { deviceId = '充值机'; - } else if (dStr === 'ticket_machine' || dStr === 'ticket_vending_machine' || /^#?\d+$/.test(dStr) || dStr.includes('computer') || dStr === 'unknown' || dStr === '---' || dStr === '') { + } else if (dStr === 'ticket_machine' || dStr === 'ticket_vending_machine') { + deviceId = '售票机'; + } else if (dStr === 'unknown' || dStr === '---' || dStr === '') { if (type === 'entry' || action === 'entry' || type === 'exit' || action === 'exit' || type === 'check') { deviceId = '闸机'; } else if (type === 'topup' || type === 'refill' || action === 'topup' || type === '充值') { diff --git a/web/ticket-board.html b/web/ticket-board.html index 1248f6f..e985417 100644 --- a/web/ticket-board.html +++ b/web/ticket-board.html @@ -1,4 +1,4 @@ - + @@ -327,7 +327,9 @@ deviceId = '闸机'; } else if (dStr === 'refill_machine') { deviceId = '充值机'; - } else if (dStr === 'ticket_machine' || dStr === 'ticket_vending_machine' || /^#?\d+$/.test(dStr) || dStr.includes('computer') || dStr === 'unknown' || dStr === '---' || dStr === '') { + } else if (dStr === 'ticket_machine' || dStr === 'ticket_vending_machine') { + deviceId = '售票机'; + } else if (dStr === 'unknown' || dStr === '---' || dStr === '') { if (type === 'entry' || action === 'entry' || type === 'exit' || action === 'exit' || type === 'check') { deviceId = '闸机'; } else if (type === 'topup' || type === 'refill' || action === 'topup' || type === '充值') { diff --git a/web/ticket-route.js b/web/ticket-route.js index a23fa9f..f705391 100644 --- a/web/ticket-route.js +++ b/web/ticket-route.js @@ -235,7 +235,9 @@ createApp({ deviceId = '闸机'; } else if (dStr === 'refill_machine') { deviceId = '充值机'; - } else if (dStr === 'ticket_machine' || dStr === 'ticket_vending_machine' || /^#?\d+$/.test(dStr) || dStr.includes('computer') || dStr === 'unknown' || dStr === '---' || dStr === '') { + } else if (dStr === 'ticket_machine' || dStr === 'ticket_vending_machine') { + deviceId = '售票机'; + } else if (dStr === 'unknown' || dStr === '---' || dStr === '') { if (type === 'entry' || action === 'entry' || type === 'exit' || action === 'exit' || type === 'check') { deviceId = '闸机'; } else { diff --git a/web/ticket-search.js b/web/ticket-search.js index 2fdbeb0..1c79493 100644 --- a/web/ticket-search.js +++ b/web/ticket-search.js @@ -117,7 +117,9 @@ deviceId = '闸机'; } else if (dStr === 'refill_machine') { deviceId = '充值机'; - } else if (dStr === 'ticket_machine' || dStr === 'ticket_vending_machine' || /^#?\d+$/.test(dStr) || dStr.includes('computer') || dStr === 'unknown' || dStr === '---' || dStr === '') { + } else if (dStr === 'ticket_machine' || dStr === 'ticket_vending_machine') { + deviceId = '售票机'; + } else if (dStr === 'unknown' || dStr === '---' || dStr === '') { if (type === 'entry' || action === 'entry' || type === 'exit' || action === 'exit' || type === 'check') { deviceId = '闸机'; } else {