@pisell/pisellos 0.0.324 → 0.0.326
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/effects/index.d.ts +2 -2
- package/dist/modules/Account/index.js +2 -3
- package/dist/modules/BaseModule.d.ts +3 -0
- package/dist/modules/BaseModule.js +15 -0
- package/dist/modules/Customer/index.js +9 -10
- package/dist/modules/Customer/types.d.ts +1 -1
- package/dist/modules/Discount/index.js +1 -1
- package/dist/modules/Guests/index.js +9 -9
- package/dist/modules/Payment/index.js +18 -18
- package/dist/modules/Payment/types.d.ts +7 -7
- package/dist/modules/Payment/walletpass.js +4 -1
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +2 -3
- package/dist/modules/Resource/index.js +1 -1
- package/dist/modules/Rules/index.js +2 -3
- package/dist/modules/Rules/types.d.ts +1 -1
- package/dist/modules/Schedule/type.d.ts +7 -7
- package/dist/modules/Schedule/types.d.ts +9 -9
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.js +2 -2
- package/dist/solution/BookingByStep/utils/resources.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +7 -7
- package/dist/solution/BuyTickets/index.js +7 -8
- package/dist/solution/Checkout/index.js +29 -29
- package/dist/solution/ShopDiscount/index.js +1 -1
- package/dist/solution/ShopDiscount/types.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/utils/task.d.ts +2 -2
- package/dist/utils/watch.d.ts +2 -2
- package/lib/core/index.js +28 -27
- package/lib/effects/index.d.ts +2 -2
- package/lib/effects/index.js +7 -3
- package/lib/modules/Account/index.js +12 -12
- package/lib/modules/AccountList/index.js +11 -14
- package/lib/modules/BaseModule.d.ts +3 -0
- package/lib/modules/BaseModule.js +12 -6
- package/lib/modules/Cart/index.js +9 -14
- package/lib/modules/Cart/utils/cartProduct.js +6 -3
- package/lib/modules/Customer/constants.js +1 -1
- package/lib/modules/Customer/index.js +24 -28
- package/lib/modules/Customer/types.d.ts +1 -1
- package/lib/modules/Date/index.js +6 -10
- package/lib/modules/Date/types.js +0 -1
- package/lib/modules/Discount/index.js +7 -12
- package/lib/modules/Guests/index.js +24 -19
- package/lib/modules/Order/index.js +9 -11
- package/lib/modules/Payment/cash.js +1 -1
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +1 -1
- package/lib/modules/Payment/eftpos.js +1 -1
- package/lib/modules/Payment/index.js +86 -97
- package/lib/modules/Payment/types.d.ts +7 -7
- package/lib/modules/Payment/utils.js +6 -3
- package/lib/modules/Payment/walletpass.js +34 -32
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Product/index.js +5 -6
- package/lib/modules/ProductList/index.js +5 -8
- package/lib/modules/Resource/index.js +13 -9
- package/lib/modules/Rules/index.js +19 -15
- package/lib/modules/Rules/types.d.ts +1 -1
- package/lib/modules/Schedule/index.js +5 -8
- package/lib/modules/Schedule/type.d.ts +7 -7
- package/lib/modules/Schedule/types.d.ts +9 -9
- package/lib/modules/Schedule/utils.js +4 -2
- package/lib/modules/Step/index.js +4 -7
- package/lib/modules/Summary/index.js +4 -9
- package/lib/plugins/request.js +33 -34
- package/lib/plugins/window.js +113 -101
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +105 -71
- package/lib/solution/BookingByStep/utils/capacity.js +15 -10
- package/lib/solution/BookingByStep/utils/resources.d.ts +1 -1
- package/lib/solution/BookingByStep/utils/resources.js +8 -4
- package/lib/solution/BookingByStep/utils/stock.js +6 -3
- package/lib/solution/BookingByStep/utils/timeslots.js +27 -24
- package/lib/solution/BookingTicket/index.js +20 -25
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +3 -3
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +6 -6
- package/lib/solution/BookingTicket/utils/scan/index.js +1 -3
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +9 -10
- package/lib/solution/BuyTickets/index.js +22 -23
- package/lib/solution/Checkout/index.js +227 -234
- package/lib/solution/Checkout/utils/index.js +22 -18
- package/lib/solution/ShopDiscount/index.js +12 -16
- package/lib/solution/ShopDiscount/types.d.ts +1 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/utils/task.d.ts +2 -2
- package/lib/utils/task.js +3 -3
- package/lib/utils/watch.d.ts +2 -2
- package/lib/utils/watch.js +7 -5
- package/package.json +1 -1
|
@@ -37,7 +37,7 @@ function formatAmount(amount) {
|
|
|
37
37
|
const decimal = new import_decimal.Decimal(amount);
|
|
38
38
|
return decimal.toFixed(2);
|
|
39
39
|
} catch (error) {
|
|
40
|
-
console.warn(`[PaymentModule]
|
|
40
|
+
console.warn(`[PaymentModule] 金额格式化失败: ${amount},使用默认值 0.00`);
|
|
41
41
|
return "0.00";
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -54,23 +54,12 @@ function generateRequestUniqueId() {
|
|
|
54
54
|
return `${year}${month}${day}${hour}${minute}${second}${millisecond}${randomDigits}`;
|
|
55
55
|
}
|
|
56
56
|
var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
57
|
-
defaultName = "pay";
|
|
58
|
-
defaultVersion = "1.0.0";
|
|
59
|
-
request;
|
|
60
|
-
app;
|
|
61
|
-
// App instance
|
|
62
|
-
store;
|
|
63
|
-
dbManager;
|
|
64
|
-
// IndexDBManager 实例
|
|
65
|
-
logger;
|
|
66
|
-
// LoggerManager 实例
|
|
67
|
-
otherParams = {};
|
|
68
|
-
// 支付方式实例
|
|
69
|
-
cash;
|
|
70
|
-
eftpos;
|
|
71
|
-
wallet;
|
|
72
57
|
constructor(name, version) {
|
|
73
58
|
super(name, version);
|
|
59
|
+
this.defaultName = "pay";
|
|
60
|
+
this.defaultVersion = "1.0.0";
|
|
61
|
+
// LoggerManager 实例
|
|
62
|
+
this.otherParams = {};
|
|
74
63
|
this.cash = new import_cash.CashPaymentImpl(this);
|
|
75
64
|
this.eftpos = new import_eftpos.EftposPaymentImpl(this);
|
|
76
65
|
this.wallet = new import_walletpass.WalletPassPaymentImpl(this);
|
|
@@ -82,17 +71,17 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
82
71
|
this.request = core.getPlugin("request");
|
|
83
72
|
const appPlugin = core.getPlugin("app");
|
|
84
73
|
if (!this.request) {
|
|
85
|
-
throw new Error("
|
|
74
|
+
throw new Error("支付模块需要 request 插件支持");
|
|
86
75
|
}
|
|
87
76
|
if (!appPlugin) {
|
|
88
|
-
throw new Error("
|
|
77
|
+
throw new Error("支付模块需要 app 插件支持");
|
|
89
78
|
}
|
|
90
79
|
this.app = appPlugin.getApp();
|
|
91
80
|
this.dbManager = this.app.dbManager;
|
|
92
81
|
this.logger = this.app.logger;
|
|
93
82
|
await this.ensurePaymentTables();
|
|
94
83
|
this.registerNetworkHandlers();
|
|
95
|
-
console.log("[PaymentModule]
|
|
84
|
+
console.log("[PaymentModule] 初始化完成");
|
|
96
85
|
this.logInfo("PaymentModule initialized successfully");
|
|
97
86
|
}
|
|
98
87
|
/**
|
|
@@ -167,7 +156,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
167
156
|
const network = this.app.plugins.get("network");
|
|
168
157
|
this.logInfo("Registering network status listener");
|
|
169
158
|
network == null ? void 0 : network.addListener("networkStatusChange", async (status) => {
|
|
170
|
-
console.log("
|
|
159
|
+
console.log("网络状态:", status.connected);
|
|
171
160
|
this.logInfo("Network status changed", {
|
|
172
161
|
connected: status.connected,
|
|
173
162
|
previousStatus: status.previousStatus
|
|
@@ -187,7 +176,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
187
176
|
try {
|
|
188
177
|
cachedMethods = await this.dbManager.getAll("pay_method");
|
|
189
178
|
} catch (dbError) {
|
|
190
|
-
console.warn("[PaymentModule] pay_method
|
|
179
|
+
console.warn("[PaymentModule] pay_method 表不存在,将从服务器获取数据");
|
|
191
180
|
}
|
|
192
181
|
const hasCache = cachedMethods.length > 0;
|
|
193
182
|
if (hasCache) {
|
|
@@ -201,10 +190,10 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
201
190
|
await this.dbManager.update("pay_method", method);
|
|
202
191
|
}
|
|
203
192
|
} catch (dbError) {
|
|
204
|
-
console.warn("[PaymentModule]
|
|
193
|
+
console.warn("[PaymentModule] 无法缓存支付方式,pay_method 表不存在");
|
|
205
194
|
}
|
|
206
195
|
await this.core.effects.emit(
|
|
207
|
-
|
|
196
|
+
`${this.name}:onPaymentMethodsLoaded`,
|
|
208
197
|
payMethods
|
|
209
198
|
);
|
|
210
199
|
this.logInfo("getPayMethodListAsync completed successfully", {
|
|
@@ -213,7 +202,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
213
202
|
});
|
|
214
203
|
return payMethods;
|
|
215
204
|
} catch (error) {
|
|
216
|
-
console.error("[PaymentModule]
|
|
205
|
+
console.error("[PaymentModule] 获取支付方式列表失败", error);
|
|
217
206
|
this.logError("getPayMethodListAsync failed", error);
|
|
218
207
|
return [];
|
|
219
208
|
}
|
|
@@ -226,7 +215,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
226
215
|
cachedMethodsCount: cachedMethods.length
|
|
227
216
|
});
|
|
228
217
|
try {
|
|
229
|
-
console.log("[PaymentModule]
|
|
218
|
+
console.log("[PaymentModule] 后台刷新支付方式列表...");
|
|
230
219
|
const response = await this.request.get("/pay/custom-payment/available", { channel: "pos" });
|
|
231
220
|
const newPayMethods = response.data || [];
|
|
232
221
|
const hasChanges = this.hasPaymentMethodsChanged(
|
|
@@ -234,7 +223,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
234
223
|
newPayMethods
|
|
235
224
|
);
|
|
236
225
|
if (hasChanges) {
|
|
237
|
-
console.log("[PaymentModule]
|
|
226
|
+
console.log("[PaymentModule] 支付方式列表已更新");
|
|
238
227
|
this.logInfo("Payment methods updated in background", {
|
|
239
228
|
oldCount: cachedMethods.length,
|
|
240
229
|
newCount: newPayMethods.length
|
|
@@ -247,21 +236,21 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
247
236
|
await this.dbManager.update("pay_method", method);
|
|
248
237
|
}
|
|
249
238
|
} catch (dbError) {
|
|
250
|
-
console.warn("[PaymentModule]
|
|
239
|
+
console.warn("[PaymentModule] 无法更新支付方式缓存", dbError);
|
|
251
240
|
}
|
|
252
241
|
const eventData = {
|
|
253
242
|
oldMethods: cachedMethods,
|
|
254
243
|
newMethods: newPayMethods
|
|
255
244
|
};
|
|
256
245
|
await this.core.effects.emit(
|
|
257
|
-
|
|
246
|
+
`${this.name}:onPaymentMethodsChanged`,
|
|
258
247
|
eventData
|
|
259
248
|
);
|
|
260
249
|
} else {
|
|
261
|
-
console.log("[PaymentModule]
|
|
250
|
+
console.log("[PaymentModule] 支付方式列表无变化");
|
|
262
251
|
}
|
|
263
252
|
} catch (error) {
|
|
264
|
-
console.error("[PaymentModule]
|
|
253
|
+
console.error("[PaymentModule] 后台刷新支付方式失败", error);
|
|
265
254
|
}
|
|
266
255
|
}
|
|
267
256
|
/**
|
|
@@ -280,7 +269,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
280
269
|
return true;
|
|
281
270
|
}
|
|
282
271
|
if (oldMethod.code !== newMethod.code || oldMethod.name !== newMethod.name || oldMethod.type !== newMethod.type || oldMethod.description !== newMethod.description || oldMethod.status !== newMethod.status || oldMethod.disable !== newMethod.disable || oldMethod.is_surcharge !== newMethod.is_surcharge || oldMethod.fixed !== newMethod.fixed || oldMethod.percentage !== newMethod.percentage || oldMethod.enabled !== newMethod.enabled || JSON.stringify(oldMethod.channel_application || []) !== JSON.stringify(newMethod.channel_application || []) || JSON.stringify(oldMethod.companies || []) !== JSON.stringify(newMethod.companies || []) || JSON.stringify(oldMethod.metadata || {}) !== JSON.stringify(newMethod.metadata || {})) {
|
|
283
|
-
console.log(`[PaymentModule]
|
|
272
|
+
console.log(`[PaymentModule] 支付方式 ${newMethod.id} (${newMethod.code}) 发生变化:`, {
|
|
284
273
|
id: newMethod.id,
|
|
285
274
|
changes: {
|
|
286
275
|
code: oldMethod.code !== newMethod.code ? { old: oldMethod.code, new: newMethod.code } : void 0,
|
|
@@ -310,7 +299,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
310
299
|
try {
|
|
311
300
|
return await this.dbManager.getAll("order");
|
|
312
301
|
} catch (error) {
|
|
313
|
-
console.error("[PaymentModule]
|
|
302
|
+
console.error("[PaymentModule] 获取订单列表失败", error);
|
|
314
303
|
return [];
|
|
315
304
|
}
|
|
316
305
|
}
|
|
@@ -321,7 +310,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
321
310
|
try {
|
|
322
311
|
return await this.dbManager.get("order", orderUuid);
|
|
323
312
|
} catch (error) {
|
|
324
|
-
console.error("[PaymentModule]
|
|
313
|
+
console.error("[PaymentModule] 获取支付订单失败", error);
|
|
325
314
|
return null;
|
|
326
315
|
}
|
|
327
316
|
}
|
|
@@ -349,7 +338,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
349
338
|
this.recalculateOrderAmount(existingOrder);
|
|
350
339
|
await this.dbManager.update("order", existingOrder);
|
|
351
340
|
await this.core.effects.emit(
|
|
352
|
-
|
|
341
|
+
`${this.name}:onOrderUpdated`,
|
|
353
342
|
existingOrder
|
|
354
343
|
);
|
|
355
344
|
return existingOrder;
|
|
@@ -369,7 +358,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
369
358
|
deposit_amount: params.deposit_amount || "0.00"
|
|
370
359
|
};
|
|
371
360
|
await this.dbManager.add("order", newOrder);
|
|
372
|
-
this.core.effects.emit(
|
|
361
|
+
this.core.effects.emit(`${this.name}:onOrderAdded`, newOrder);
|
|
373
362
|
this.logInfo("createPaymentOrderAsync completed - new payment order created", {
|
|
374
363
|
orderUuid: newOrder.uuid,
|
|
375
364
|
orderId: newOrder.id
|
|
@@ -377,7 +366,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
377
366
|
return newOrder;
|
|
378
367
|
}
|
|
379
368
|
} catch (error) {
|
|
380
|
-
console.error("[PaymentModule]
|
|
369
|
+
console.error("[PaymentModule] 创建支付订单失败", error);
|
|
381
370
|
this.logError("createPaymentOrderAsync failed", error, {
|
|
382
371
|
orderId: params.order_id
|
|
383
372
|
});
|
|
@@ -392,11 +381,11 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
392
381
|
const order = await this.dbManager.get("order", orderUuid);
|
|
393
382
|
if (order) {
|
|
394
383
|
await this.dbManager.delete("order", orderUuid);
|
|
395
|
-
await this.core.effects.emit(
|
|
396
|
-
console.log("[PaymentModule]
|
|
384
|
+
await this.core.effects.emit(`${this.name}:onOrderDeleted`, order);
|
|
385
|
+
console.log("[PaymentModule] 支付订单删除成功:", orderUuid);
|
|
397
386
|
}
|
|
398
387
|
} catch (error) {
|
|
399
|
-
console.error("[PaymentModule]
|
|
388
|
+
console.error("[PaymentModule] 删除支付订单失败", error);
|
|
400
389
|
throw error;
|
|
401
390
|
}
|
|
402
391
|
}
|
|
@@ -410,15 +399,15 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
410
399
|
const updatedOrder = { ...order, ...params };
|
|
411
400
|
this.recalculateOrderAmount(updatedOrder);
|
|
412
401
|
await this.dbManager.update("order", updatedOrder);
|
|
413
|
-
await this.core.effects.emit(
|
|
414
|
-
await this.core.effects.emit(
|
|
402
|
+
await this.core.effects.emit(`${this.name}:onOrderUpdated`, updatedOrder);
|
|
403
|
+
await this.core.effects.emit(`${this.name}:onOrderChanged`, {
|
|
415
404
|
action: "update",
|
|
416
405
|
order: updatedOrder,
|
|
417
406
|
originalOrder: order
|
|
418
407
|
});
|
|
419
408
|
}
|
|
420
409
|
} catch (error) {
|
|
421
|
-
console.error("[PaymentModule]
|
|
410
|
+
console.error("[PaymentModule] 更新订单失败", error);
|
|
422
411
|
throw error;
|
|
423
412
|
}
|
|
424
413
|
}
|
|
@@ -452,7 +441,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
452
441
|
newOrderId,
|
|
453
442
|
existingOrderUuid: duplicateOrder.uuid
|
|
454
443
|
});
|
|
455
|
-
throw new Error(
|
|
444
|
+
throw new Error(`订单ID ${newOrderId} 已存在`);
|
|
456
445
|
}
|
|
457
446
|
const originalOrderId = existingOrder.id;
|
|
458
447
|
const updatedOrder = {
|
|
@@ -469,8 +458,8 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
469
458
|
}
|
|
470
459
|
};
|
|
471
460
|
await this.dbManager.update("order", updatedOrder);
|
|
472
|
-
await this.core.effects.emit(
|
|
473
|
-
await this.core.effects.emit(
|
|
461
|
+
await this.core.effects.emit(`${this.name}:onOrderUpdated`, updatedOrder);
|
|
462
|
+
await this.core.effects.emit(`${this.name}:onOrderChanged`, {
|
|
474
463
|
action: "order_id_replaced",
|
|
475
464
|
order: updatedOrder,
|
|
476
465
|
originalOrder: existingOrder,
|
|
@@ -484,10 +473,10 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
484
473
|
originalOrderId,
|
|
485
474
|
newOrderId
|
|
486
475
|
});
|
|
487
|
-
console.log(`[PaymentModule]
|
|
476
|
+
console.log(`[PaymentModule] 订单ID替换成功: ${originalOrderId} → ${newOrderId}`);
|
|
488
477
|
return updatedOrder;
|
|
489
478
|
} catch (error) {
|
|
490
|
-
console.error("[PaymentModule]
|
|
479
|
+
console.error("[PaymentModule] 替换订单ID失败", error);
|
|
491
480
|
this.logError("replaceOrderIdByUuidAsync failed", error, {
|
|
492
481
|
orderUuid,
|
|
493
482
|
newOrderId
|
|
@@ -547,7 +536,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
547
536
|
}, new import_decimal.Decimal(0));
|
|
548
537
|
const expectedDepositAmount = new import_decimal.Decimal(order.deposit_amount || "0").sub(paidDepositAmount);
|
|
549
538
|
if (expectAmount.lte(0) && expectedDepositAmount.eq(0)) {
|
|
550
|
-
const warningMessage =
|
|
539
|
+
const warningMessage = `订单 ${orderUuid} 待付金额已为0,不允许添加新的支付项`;
|
|
551
540
|
console.warn("[PaymentModule] Payment lock triggered:", {
|
|
552
541
|
orderUuid,
|
|
553
542
|
expectAmount: order.expect_amount,
|
|
@@ -587,7 +576,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
587
576
|
order.payment.push(newPaymentItem);
|
|
588
577
|
this.recalculateOrderAmount(order);
|
|
589
578
|
await this.dbManager.update("order", order);
|
|
590
|
-
await this.core.effects.emit(
|
|
579
|
+
await this.core.effects.emit(`${this.name}:onPaymentAdded`, {
|
|
591
580
|
orderUuid,
|
|
592
581
|
payment: newPaymentItem
|
|
593
582
|
});
|
|
@@ -605,7 +594,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
605
594
|
changeGivenAmount: (_c = newPaymentItem.metadata) == null ? void 0 : _c.change_given_amount
|
|
606
595
|
});
|
|
607
596
|
} catch (error) {
|
|
608
|
-
console.error("[PaymentModule]
|
|
597
|
+
console.error("[PaymentModule] 添加支付项失败", error);
|
|
609
598
|
this.logError("addPaymentItemAsync failed", error, {
|
|
610
599
|
orderUuid,
|
|
611
600
|
paymentItem
|
|
@@ -621,33 +610,33 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
621
610
|
try {
|
|
622
611
|
const order = await this.dbManager.get("order", orderUuid);
|
|
623
612
|
if (!order) {
|
|
624
|
-
throw new Error("
|
|
613
|
+
throw new Error("订单不存在");
|
|
625
614
|
}
|
|
626
615
|
const paymentItem = order.payment.find(
|
|
627
616
|
(payment) => payment.uuid === paymentUuid
|
|
628
617
|
);
|
|
629
618
|
if (!paymentItem) {
|
|
630
|
-
throw new Error(
|
|
619
|
+
throw new Error(`支付项不存在: ${paymentUuid}`);
|
|
631
620
|
}
|
|
632
621
|
if (paymentItem.status === "voided") {
|
|
633
|
-
console.warn(`[PaymentModule]
|
|
622
|
+
console.warn(`[PaymentModule] 支付项 ${paymentUuid} 已经被删除,跳过操作`);
|
|
634
623
|
return;
|
|
635
624
|
}
|
|
636
625
|
paymentItem.status = "voided";
|
|
637
626
|
paymentItem.origin_amount = paymentItem.amount;
|
|
638
627
|
paymentItem.amount = "0.00";
|
|
639
|
-
console.log(`[PaymentModule]
|
|
628
|
+
console.log(`[PaymentModule] 支付项标记为删除:`, {
|
|
640
629
|
uuid: paymentItem.uuid,
|
|
641
630
|
originalAmount: paymentItem.origin_amount,
|
|
642
631
|
status: paymentItem.status
|
|
643
632
|
});
|
|
644
633
|
this.recalculateOrderAmount(order);
|
|
645
634
|
await this.dbManager.update("order", order);
|
|
646
|
-
await this.core.effects.emit(
|
|
635
|
+
await this.core.effects.emit(`${this.name}:onPaymentDeleted`, {
|
|
647
636
|
order,
|
|
648
637
|
paymentItem
|
|
649
638
|
});
|
|
650
|
-
await this.core.effects.emit(
|
|
639
|
+
await this.core.effects.emit(`${this.name}:onOrderChanged`, {
|
|
651
640
|
action: "payment_delete",
|
|
652
641
|
order,
|
|
653
642
|
paymentItem
|
|
@@ -659,7 +648,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
659
648
|
newExpectAmount: order.expect_amount
|
|
660
649
|
});
|
|
661
650
|
} catch (error) {
|
|
662
|
-
console.error("[PaymentModule]
|
|
651
|
+
console.error("[PaymentModule] 删除支付项失败", error);
|
|
663
652
|
this.logError("deletePaymentAsync failed", error, {
|
|
664
653
|
orderUuid,
|
|
665
654
|
paymentUuid
|
|
@@ -687,12 +676,12 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
687
676
|
try {
|
|
688
677
|
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
689
678
|
if (!order) {
|
|
690
|
-
throw new Error(
|
|
679
|
+
throw new Error(`订单不存在: ${orderUuid}`);
|
|
691
680
|
}
|
|
692
681
|
const existingVoucherItems = order.payment.filter(
|
|
693
682
|
(payment) => payment.voucher_id && payment.status !== "voided" && !payment.isSynced
|
|
694
683
|
);
|
|
695
|
-
console.log("[PaymentModule]
|
|
684
|
+
console.log("[PaymentModule] 发现现有代金券支付项:", {
|
|
696
685
|
orderUuid,
|
|
697
686
|
existingVoucherCount: existingVoucherItems.length,
|
|
698
687
|
existingItems: existingVoucherItems.map((item) => ({
|
|
@@ -704,18 +693,18 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
704
693
|
}))
|
|
705
694
|
});
|
|
706
695
|
for (const voucherItem of existingVoucherItems) {
|
|
707
|
-
console.log(`[PaymentModule]
|
|
696
|
+
console.log(`[PaymentModule] 删除现有代金券支付项: ${voucherItem.uuid}`);
|
|
708
697
|
await this.deletePaymentAsync(orderUuid, voucherItem.uuid);
|
|
709
698
|
}
|
|
710
|
-
console.log("[PaymentModule]
|
|
699
|
+
console.log("[PaymentModule] 添加新的代金券支付项:", {
|
|
711
700
|
orderUuid,
|
|
712
701
|
newItemCount: voucherPaymentItems.length
|
|
713
702
|
});
|
|
714
703
|
for (const voucherItem of voucherPaymentItems) {
|
|
715
704
|
if (!voucherItem.voucher_id) {
|
|
716
|
-
throw new Error(
|
|
705
|
+
throw new Error(`代金券支付项缺少 voucher_id: ${JSON.stringify(voucherItem)}`);
|
|
717
706
|
}
|
|
718
|
-
console.log(`[PaymentModule]
|
|
707
|
+
console.log(`[PaymentModule] 添加代金券支付项:`, {
|
|
719
708
|
code: voucherItem.code,
|
|
720
709
|
amount: voucherItem.amount,
|
|
721
710
|
voucher_id: voucherItem.voucher_id,
|
|
@@ -724,7 +713,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
724
713
|
await this.addPaymentItemAsync(orderUuid, voucherItem);
|
|
725
714
|
}
|
|
726
715
|
const updatedOrder = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
727
|
-
await this.core.effects.emit(
|
|
716
|
+
await this.core.effects.emit(`${this.name}:onPaymentAdded`, {
|
|
728
717
|
orderUuid,
|
|
729
718
|
order: updatedOrder,
|
|
730
719
|
payment: null
|
|
@@ -737,7 +726,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
737
726
|
finalExpectAmount: updatedOrder == null ? void 0 : updatedOrder.expect_amount
|
|
738
727
|
});
|
|
739
728
|
} catch (error) {
|
|
740
|
-
console.error("[PaymentModule]
|
|
729
|
+
console.error("[PaymentModule] 批量更新代金券支付项失败:", error);
|
|
741
730
|
this.logError("updateVoucherPaymentItemsAsync failed", error, {
|
|
742
731
|
orderUuid,
|
|
743
732
|
voucherPaymentItems
|
|
@@ -752,7 +741,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
752
741
|
try {
|
|
753
742
|
const order = await this.dbManager.get("order", orderUuid);
|
|
754
743
|
if (!order) {
|
|
755
|
-
throw new Error("
|
|
744
|
+
throw new Error("订单不存在");
|
|
756
745
|
}
|
|
757
746
|
const paymentItem = order.payment.find(
|
|
758
747
|
(payment) => payment.uuid === paymentUuid
|
|
@@ -765,18 +754,18 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
765
754
|
Object.assign(paymentItem, formattedParams);
|
|
766
755
|
this.recalculateOrderAmount(order);
|
|
767
756
|
await this.dbManager.update("order", order);
|
|
768
|
-
await this.core.effects.emit(
|
|
757
|
+
await this.core.effects.emit(`${this.name}:onPaymentUpdated`, {
|
|
769
758
|
order,
|
|
770
759
|
paymentItem
|
|
771
760
|
});
|
|
772
|
-
await this.core.effects.emit(
|
|
761
|
+
await this.core.effects.emit(`${this.name}:onOrderChanged`, {
|
|
773
762
|
action: "payment_update",
|
|
774
763
|
order,
|
|
775
764
|
paymentItem
|
|
776
765
|
});
|
|
777
766
|
}
|
|
778
767
|
} catch (error) {
|
|
779
|
-
console.error("[PaymentModule]
|
|
768
|
+
console.error("[PaymentModule] 更新支付项失败", error);
|
|
780
769
|
throw error;
|
|
781
770
|
}
|
|
782
771
|
}
|
|
@@ -806,7 +795,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
806
795
|
});
|
|
807
796
|
return result;
|
|
808
797
|
} catch (error) {
|
|
809
|
-
console.error("[PaymentModule]
|
|
798
|
+
console.error("[PaymentModule] 提交支付失败", error);
|
|
810
799
|
this.logError("submitPayAsync failed", error, { orderUuid });
|
|
811
800
|
return { status: "failed" };
|
|
812
801
|
}
|
|
@@ -839,31 +828,31 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
839
828
|
if (totalPaidAmount.gte(orderTotalAmount)) {
|
|
840
829
|
order.payment_status = import_types.PaymentStatus.Finished;
|
|
841
830
|
console.log(
|
|
842
|
-
`[PaymentModule]
|
|
831
|
+
`[PaymentModule] 订单 ${order.uuid} 支付完成,金额: ${totalPaidAmount.toString()}/${orderTotalAmount.toString()}`
|
|
843
832
|
);
|
|
844
833
|
} else {
|
|
845
834
|
order.payment_status = import_types.PaymentStatus.PartiallyPaid;
|
|
846
835
|
console.log(
|
|
847
|
-
`[PaymentModule]
|
|
836
|
+
`[PaymentModule] 订单 ${order.uuid} 部分支付,金额: ${totalPaidAmount.toString()}/${orderTotalAmount.toString()}`
|
|
848
837
|
);
|
|
849
838
|
}
|
|
850
839
|
paymentData.payment_status = order.payment_status === import_types.PaymentStatus.Finished ? "paid" : "partially_paid";
|
|
851
840
|
await this.dbManager.update("order", order);
|
|
852
841
|
if (paymentData.payments.length === 0) {
|
|
853
|
-
console.log(`[PaymentModule]
|
|
842
|
+
console.log(`[PaymentModule] 订单 ${order.uuid} 支付列表为空,跳过支付处理`);
|
|
854
843
|
this.logWarning("Empty payment list", {
|
|
855
844
|
orderUuid: order.uuid,
|
|
856
845
|
orderId: order.order_id
|
|
857
846
|
});
|
|
858
847
|
return;
|
|
859
848
|
}
|
|
860
|
-
await this.core.effects.emit(
|
|
861
|
-
await this.core.effects.emit(
|
|
849
|
+
await this.core.effects.emit(`${this.name}:onPaymentSubmitted`, order);
|
|
850
|
+
await this.core.effects.emit(`${this.name}:onOrderChanged`, {
|
|
862
851
|
action: "submit",
|
|
863
852
|
order
|
|
864
853
|
});
|
|
865
854
|
} catch (error) {
|
|
866
|
-
console.error(`[PaymentModule]
|
|
855
|
+
console.error(`[PaymentModule] 订单 ${order.uuid} 支付提交失败`, error);
|
|
867
856
|
throw error;
|
|
868
857
|
}
|
|
869
858
|
}
|
|
@@ -873,7 +862,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
873
862
|
async getRemainingOrderAmountAsync(orderUuid) {
|
|
874
863
|
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
875
864
|
if (!order) {
|
|
876
|
-
throw new Error("
|
|
865
|
+
throw new Error("订单不存在");
|
|
877
866
|
}
|
|
878
867
|
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
879
868
|
}
|
|
@@ -883,7 +872,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
883
872
|
async getRemainingOrderAmountWithInputAsync(inputAmount, orderUuid) {
|
|
884
873
|
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
885
874
|
if (!order) {
|
|
886
|
-
throw new Error("
|
|
875
|
+
throw new Error("订单不存在");
|
|
887
876
|
}
|
|
888
877
|
if (inputAmount === null || inputAmount === void 0) {
|
|
889
878
|
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
@@ -896,7 +885,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
896
885
|
if (typeof inputAmount === "number") {
|
|
897
886
|
if (isNaN(inputAmount) || !isFinite(inputAmount)) {
|
|
898
887
|
console.warn(
|
|
899
|
-
`[PaymentModule]
|
|
888
|
+
`[PaymentModule] 输入金额不是有效数字: ${inputAmount},返回原始待付金额`
|
|
900
889
|
);
|
|
901
890
|
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
902
891
|
}
|
|
@@ -906,7 +895,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
906
895
|
return new import_decimal.Decimal(order.expect_amount).minus(inputDecimal).toNumber();
|
|
907
896
|
} catch (error) {
|
|
908
897
|
console.warn(
|
|
909
|
-
`[PaymentModule]
|
|
898
|
+
`[PaymentModule] 输入金额格式无效: ${inputAmount},返回原始待付金额`
|
|
910
899
|
);
|
|
911
900
|
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
912
901
|
}
|
|
@@ -927,7 +916,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
927
916
|
const effectiveAmount = paymentAmount.plus(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
|
|
928
917
|
return sum.plus(effectiveAmount);
|
|
929
918
|
} catch (error) {
|
|
930
|
-
console.warn(`[PaymentModule]
|
|
919
|
+
console.warn(`[PaymentModule] 无效的支付金额: amount=${payment.amount}, rounding_amount=${payment.rounding_amount},跳过计算`);
|
|
931
920
|
return sum;
|
|
932
921
|
}
|
|
933
922
|
},
|
|
@@ -935,7 +924,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
935
924
|
);
|
|
936
925
|
const remainingAmount = order.is_deposit === 1 ? new import_decimal.Decimal(order.deposit_amount).minus(paidAmount) : totalAmount.minus(paidAmount);
|
|
937
926
|
order.expect_amount = import_decimal.Decimal.max(0, remainingAmount).toFixed(2);
|
|
938
|
-
console.log(`[PaymentModule]
|
|
927
|
+
console.log(`[PaymentModule] 重新计算订单金额:`, {
|
|
939
928
|
orderUuid: order.uuid,
|
|
940
929
|
totalAmount: order.total_amount,
|
|
941
930
|
effectivePaidAmount: paidAmount.toFixed(2),
|
|
@@ -948,7 +937,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
948
937
|
rounding_amount: p.rounding_amount || "0.00",
|
|
949
938
|
effective_amount: new import_decimal.Decimal(p.amount || 0).plus(new import_decimal.Decimal(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || 0).abs()).toFixed(2)
|
|
950
939
|
})),
|
|
951
|
-
|
|
940
|
+
说明: "有效支付金额包含抹零计算(amount + |rounding_amount|)"
|
|
952
941
|
});
|
|
953
942
|
}
|
|
954
943
|
/**
|
|
@@ -961,7 +950,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
961
950
|
(method) => method.code === import_types.PaymentMethodType.Cash
|
|
962
951
|
) || null;
|
|
963
952
|
} catch (error) {
|
|
964
|
-
console.error("[PaymentModule]
|
|
953
|
+
console.error("[PaymentModule] 获取现金支付方式失败", error);
|
|
965
954
|
return null;
|
|
966
955
|
}
|
|
967
956
|
}
|
|
@@ -975,7 +964,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
975
964
|
(method) => method.code === import_types.PaymentMethodType.Eftpos
|
|
976
965
|
) || null;
|
|
977
966
|
} catch (error) {
|
|
978
|
-
console.error("[PaymentModule]
|
|
967
|
+
console.error("[PaymentModule] 获取Eftpos支付方式失败", error);
|
|
979
968
|
return null;
|
|
980
969
|
}
|
|
981
970
|
}
|
|
@@ -989,7 +978,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
989
978
|
(method) => method.code === import_types.PaymentMethodType.Wallet
|
|
990
979
|
) || null;
|
|
991
980
|
} catch (error) {
|
|
992
|
-
console.error("[PaymentModule]
|
|
981
|
+
console.error("[PaymentModule] 获取钱包支付方式失败", error);
|
|
993
982
|
return null;
|
|
994
983
|
}
|
|
995
984
|
}
|
|
@@ -1001,7 +990,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1001
990
|
await this.dbManager.getAll("pay_method");
|
|
1002
991
|
} catch (error) {
|
|
1003
992
|
console.warn(
|
|
1004
|
-
"[PaymentModule] pay_method
|
|
993
|
+
"[PaymentModule] pay_method 表不存在,请在数据库配置中添加以下配置:"
|
|
1005
994
|
);
|
|
1006
995
|
console.warn('{ name: "pay_method", keyPath: "id" }');
|
|
1007
996
|
}
|
|
@@ -1009,7 +998,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1009
998
|
await this.dbManager.getAll("order");
|
|
1010
999
|
} catch (error) {
|
|
1011
1000
|
console.warn(
|
|
1012
|
-
"[PaymentModule] order
|
|
1001
|
+
"[PaymentModule] order 表不存在,请在数据库配置中添加以下配置:"
|
|
1013
1002
|
);
|
|
1014
1003
|
console.warn('{ name: "order", keyPath: "uuid" }');
|
|
1015
1004
|
}
|
|
@@ -1024,7 +1013,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1024
1013
|
(order) => order.payment_status === import_types.PaymentStatus.PartiallyPaid
|
|
1025
1014
|
);
|
|
1026
1015
|
} catch (error) {
|
|
1027
|
-
console.error("[PaymentModule]
|
|
1016
|
+
console.error("[PaymentModule] 获取部分支付订单失败", error);
|
|
1028
1017
|
return [];
|
|
1029
1018
|
}
|
|
1030
1019
|
}
|
|
@@ -1044,15 +1033,15 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1044
1033
|
const amount = new import_decimal.Decimal(originalAmount);
|
|
1045
1034
|
const roundingInterval = new import_decimal.Decimal(interval);
|
|
1046
1035
|
if (roundingInterval.lte(0)) {
|
|
1047
|
-
throw new Error("
|
|
1036
|
+
throw new Error("舍入间隔必须大于 0");
|
|
1048
1037
|
}
|
|
1049
1038
|
const supportedIntervals = [0.05, 0.1, 0.5, 1];
|
|
1050
1039
|
const intervalValue = roundingInterval.toNumber();
|
|
1051
1040
|
if (!supportedIntervals.includes(intervalValue)) {
|
|
1052
|
-
console.warn(`[PaymentModule]
|
|
1041
|
+
console.warn(`[PaymentModule] 不支持的舍入间隔: ${intervalValue}, 支持的间隔: ${supportedIntervals.join(", ")}`);
|
|
1053
1042
|
}
|
|
1054
1043
|
const baseValue = amount.div(roundingInterval);
|
|
1055
|
-
console.log(`[PaymentModule]
|
|
1044
|
+
console.log(`[PaymentModule] 舍入计算 - 原始金额: ${amount.toString()}, 间隔: ${intervalValue}, 基础值: ${baseValue.toString()}, 规则: ${rule}`);
|
|
1056
1045
|
let roundedValue;
|
|
1057
1046
|
switch (rule) {
|
|
1058
1047
|
case import_types.RoundingRule.Standard:
|
|
@@ -1072,12 +1061,12 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1072
1061
|
roundedValue = baseValue.floor();
|
|
1073
1062
|
break;
|
|
1074
1063
|
default:
|
|
1075
|
-
throw new Error(
|
|
1064
|
+
throw new Error(`不支持的舍入规则: ${rule}`);
|
|
1076
1065
|
}
|
|
1077
1066
|
const finalAmount = roundedValue.mul(roundingInterval);
|
|
1078
1067
|
const originalAmountStr = amount.toFixed(2);
|
|
1079
1068
|
if (finalAmount.eq(0)) {
|
|
1080
|
-
console.log(`[PaymentModule]
|
|
1069
|
+
console.log(`[PaymentModule] 最终金额为0,返回原始金额: ${originalAmountStr}`);
|
|
1081
1070
|
return {
|
|
1082
1071
|
originalAmount: originalAmountStr,
|
|
1083
1072
|
roundedAmount: originalAmountStr,
|
|
@@ -1087,15 +1076,15 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1087
1076
|
const roundedAmountStr = finalAmount.toFixed(2);
|
|
1088
1077
|
const roundingDifference = finalAmount.sub(amount);
|
|
1089
1078
|
const roundingDifferenceStr = roundingDifference.toFixed(2);
|
|
1090
|
-
console.log(`[PaymentModule]
|
|
1079
|
+
console.log(`[PaymentModule] 舍入结果 - 原始金额: ${originalAmountStr}, 舍入后金额: ${roundedAmountStr}, 舍入差额: ${roundingDifferenceStr}`);
|
|
1091
1080
|
return {
|
|
1092
1081
|
originalAmount: originalAmountStr,
|
|
1093
1082
|
roundedAmount: roundedAmountStr,
|
|
1094
1083
|
roundingDifference: roundingDifferenceStr
|
|
1095
1084
|
};
|
|
1096
1085
|
} catch (error) {
|
|
1097
|
-
console.error("[PaymentModule]
|
|
1098
|
-
throw new Error(
|
|
1086
|
+
console.error("[PaymentModule] 金额舍入失败:", error);
|
|
1087
|
+
throw new Error(`金额舍入失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
1099
1088
|
}
|
|
1100
1089
|
}
|
|
1101
1090
|
/**
|
|
@@ -581,12 +581,12 @@ export declare enum PaymentHooks {
|
|
|
581
581
|
OnOrderAmountChanged = "payment:onOrderAmountChanged",
|
|
582
582
|
OnPaymentSyncError = "payment:onPaymentSyncError",
|
|
583
583
|
OnPaymentSyncSuccess = "payment:onPaymentSyncSuccess",
|
|
584
|
-
OnWalletRecommendListUpdated =
|
|
585
|
-
OnWalletRecommendListCleared =
|
|
586
|
-
OnUserIdentificationCodesUpdated =
|
|
587
|
-
OnUserIdentificationCodesCleared =
|
|
588
|
-
OnWalletCacheCleared =
|
|
589
|
-
OnSearchIdentificationCodeCompleted =
|
|
584
|
+
OnWalletRecommendListUpdated = "wallet:onWalletRecommendListUpdated",
|
|
585
|
+
OnWalletRecommendListCleared = "wallet:onWalletRecommendListCleared",
|
|
586
|
+
OnUserIdentificationCodesUpdated = "wallet:onUserIdentificationCodesUpdated",
|
|
587
|
+
OnUserIdentificationCodesCleared = "wallet:onUserIdentificationCodesCleared",
|
|
588
|
+
OnWalletCacheCleared = "wallet:onWalletCacheCleared",
|
|
589
|
+
OnSearchIdentificationCodeCompleted = "wallet:onSearchIdentificationCodeCompleted"
|
|
590
590
|
}
|
|
591
591
|
/**
|
|
592
592
|
* 钱包推荐扣款请求参数
|
|
@@ -739,7 +739,7 @@ export interface SearchIdentificationCodeResponse {
|
|
|
739
739
|
/**
|
|
740
740
|
* 搜索识别码结果类型
|
|
741
741
|
*/
|
|
742
|
-
export
|
|
742
|
+
export type SearchIdentificationCodeResult = {
|
|
743
743
|
type: 'walletCode';
|
|
744
744
|
data: SearchIdentificationCodeItem[];
|
|
745
745
|
} | {
|