fix(pricing): 统一将计价计算从向下取整改为四舍五入

统一修复所有计价相关模块的取整逻辑:将Lua计价函数中的直接返回改为四舍五入取整,同时将前后端代码中的Math.floor替换为Math.round,确保全链路的票价计算采用标准四舍五入规则,避免出现不合理的定价偏差。
This commit is contained in:
2026-07-09 23:40:08 +08:00
parent e07536e8c0
commit b3fdf36f84
6 changed files with 27 additions and 8 deletions
+9 -2
View File
@@ -9,6 +9,12 @@ const svgGenerator = require('../services/svg-generator');
// Helper to get IP
const getIp = (req) => (req.headers['x-forwarded-for'] || '').toString().split(',')[0].trim() || req.ip || req.connection?.remoteAddress || '';
const resolveStationName = (code) => {
if (!code) return '';
const s = (DataService.getStations?.() || []).find(x => String(x.code).trim().toLowerCase() === String(code).trim().toLowerCase());
return s ? (s.name || s.cn_name || code) : code;
};
const appendReqLog = (req, { category, type, detail, source, level } = {}) => {
const entry = {
ts: new Date().toISOString(),
@@ -196,8 +202,8 @@ router.get('/fares/query', (req, res) => {
const discount = Number.isFinite(discountRaw) && discountRaw > 0 ? discountRaw : 1;
const regularBase = Number(result.regular);
const expressBase = Number(result.express);
const regularDiscounted = Number.isFinite(regularBase) ? Math.floor(regularBase * discount) : null;
const expressDiscounted = Number.isFinite(expressBase) ? Math.floor(expressBase * discount) : null;
const regularDiscounted = Number.isFinite(regularBase) ? Math.round(regularBase * discount) : null;
const expressDiscounted = Number.isFinite(expressBase) ? Math.round(expressBase * discount) : null;
appendReqLog(req, { category: 'public', type: 'fare_query', detail: { from, to, from_code: fromCode, to_code: toCode, ok: true } });
res.json({
from_code: fromCode || null,
@@ -502,6 +508,7 @@ router.post('/tickets/record', async (req, res) => {
train_type,
cost,
station_code,
station_name: resolveStationName(station_code),
device,
trips_total,
trips_remaining