From ef9926dc582cacd3972150bc4f5e9ae00d8855f4 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sun, 28 Jun 2026 16:54:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor(id=E7=94=9F=E6=88=90):=20=E6=8F=90?= =?UTF-8?q?=E5=8F=96=E5=85=AC=E5=85=B1=E6=95=B0=E5=AD=97=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=87=BD=E6=95=B0=E7=AE=80=E5=8C=96=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将原有的分散在generateCardId和generateTicketId中的ID生成逻辑统一调用通用函数,同时调整工单ID的前缀为固定TK。 --- ticketmachine.lua | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ticketmachine.lua b/ticketmachine.lua index 18c3cfa..64e49b4 100644 --- a/ticketmachine.lua +++ b/ticketmachine.lua @@ -541,9 +541,15 @@ local function buildFinalCardData(payload, respData) } end +local function generateNumericCode(prefix, digits) + local width = math.max(1, math.floor(tonumber(digits) or 1)) + local maxValue = (10 ^ width) - 1 + local num = string.format('%0' .. tostring(width) .. 'd', math.random(0, maxValue)) + return tostring(prefix or 'ID'):upper() .. '-' .. num +end + local function generateCardId() - local num = string.format('%06d', math.random(0, 999999)) - return 'IC-' .. num + return generateNumericCode('IC', 6) end local function issueTicketFromPeripheral(fromNameEnArg, toNameEnArg, apiType, rides, cost, startStationArg, terminalStationArg, fromNameCnUArg, toNameCnUArg, fallbackTicketId) @@ -2002,12 +2008,7 @@ local function showPrePrintCheck() end local function generateTicketId() - local function randLetter() - return string.char(string.byte('A') + math.random(0, 25)) - end - local prefix = randLetter() .. randLetter() - local num = string.format('%08d', math.random(0, 99999999)) - return prefix .. '-' .. num + return generateNumericCode('TK', 8) end local function ensureTicketIdFormat(id)