@pisell/pisellos 0.0.320 → 0.0.324
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/Customer/types.d.ts +1 -1
- package/dist/modules/Discount/index.d.ts +2 -0
- package/dist/modules/Discount/index.js +67 -35
- package/dist/modules/Discount/types.d.ts +5 -0
- package/dist/modules/Payment/types.d.ts +7 -7
- package/dist/modules/ProductList/index.js +2 -1
- 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/utils/resources.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/ShopDiscount/index.d.ts +4 -0
- package/dist/solution/ShopDiscount/index.js +190 -101
- package/dist/solution/ShopDiscount/types.d.ts +5 -2
- package/dist/solution/ShopDiscount/utils.d.ts +48 -0
- package/dist/solution/ShopDiscount/utils.js +281 -0
- 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 +27 -28
- package/lib/effects/index.d.ts +2 -2
- package/lib/effects/index.js +3 -7
- package/lib/modules/Account/index.js +9 -10
- package/lib/modules/AccountList/index.js +14 -11
- package/lib/modules/BaseModule.js +6 -3
- package/lib/modules/Cart/index.js +14 -9
- package/lib/modules/Cart/utils/cartProduct.js +3 -6
- package/lib/modules/Customer/constants.js +1 -1
- package/lib/modules/Customer/index.js +18 -15
- package/lib/modules/Customer/types.d.ts +1 -1
- package/lib/modules/Date/index.js +10 -6
- package/lib/modules/Date/types.js +1 -0
- package/lib/modules/Discount/index.d.ts +2 -0
- package/lib/modules/Discount/index.js +28 -9
- package/lib/modules/Discount/types.d.ts +5 -0
- package/lib/modules/Guests/index.js +10 -15
- package/lib/modules/Order/index.js +11 -9
- 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 +80 -69
- package/lib/modules/Payment/types.d.ts +7 -7
- package/lib/modules/Payment/utils.js +3 -6
- package/lib/modules/Payment/walletpass.js +31 -31
- package/lib/modules/Product/index.js +6 -5
- package/lib/modules/ProductList/index.js +7 -4
- package/lib/modules/Resource/index.js +8 -12
- package/lib/modules/Rules/index.js +12 -17
- package/lib/modules/Rules/types.d.ts +1 -1
- package/lib/modules/Schedule/index.js +8 -5
- package/lib/modules/Schedule/type.d.ts +7 -7
- package/lib/modules/Schedule/types.d.ts +9 -9
- package/lib/modules/Schedule/utils.js +2 -4
- package/lib/modules/Step/index.js +7 -4
- package/lib/modules/Summary/index.js +9 -4
- package/lib/plugins/request.js +34 -33
- package/lib/plugins/window.js +101 -113
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +70 -104
- package/lib/solution/BookingByStep/utils/capacity.js +10 -15
- package/lib/solution/BookingByStep/utils/resources.d.ts +1 -1
- package/lib/solution/BookingByStep/utils/resources.js +4 -8
- package/lib/solution/BookingByStep/utils/stock.js +3 -6
- package/lib/solution/BookingByStep/utils/timeslots.js +24 -27
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +19 -14
- 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 +3 -1
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +10 -9
- package/lib/solution/BuyTickets/index.js +15 -15
- package/lib/solution/Checkout/index.js +206 -199
- package/lib/solution/Checkout/utils/index.js +18 -22
- package/lib/solution/ShopDiscount/index.d.ts +4 -0
- package/lib/solution/ShopDiscount/index.js +59 -16
- package/lib/solution/ShopDiscount/types.d.ts +5 -2
- package/lib/solution/ShopDiscount/utils.d.ts +48 -0
- package/lib/solution/ShopDiscount/utils.js +172 -0
- 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 +5 -7
- 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] \u91D1\u989D\u683C\u5F0F\u5316\u5931\u8D25: ${amount}\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u503C 0.00`);
|
|
41
41
|
return "0.00";
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -54,12 +54,23 @@ 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;
|
|
57
72
|
constructor(name, version) {
|
|
58
73
|
super(name, version);
|
|
59
|
-
this.defaultName = "pay";
|
|
60
|
-
this.defaultVersion = "1.0.0";
|
|
61
|
-
// LoggerManager 实例
|
|
62
|
-
this.otherParams = {};
|
|
63
74
|
this.cash = new import_cash.CashPaymentImpl(this);
|
|
64
75
|
this.eftpos = new import_eftpos.EftposPaymentImpl(this);
|
|
65
76
|
this.wallet = new import_walletpass.WalletPassPaymentImpl(this);
|
|
@@ -71,17 +82,17 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
71
82
|
this.request = core.getPlugin("request");
|
|
72
83
|
const appPlugin = core.getPlugin("app");
|
|
73
84
|
if (!this.request) {
|
|
74
|
-
throw new Error("
|
|
85
|
+
throw new Error("\u652F\u4ED8\u6A21\u5757\u9700\u8981 request \u63D2\u4EF6\u652F\u6301");
|
|
75
86
|
}
|
|
76
87
|
if (!appPlugin) {
|
|
77
|
-
throw new Error("
|
|
88
|
+
throw new Error("\u652F\u4ED8\u6A21\u5757\u9700\u8981 app \u63D2\u4EF6\u652F\u6301");
|
|
78
89
|
}
|
|
79
90
|
this.app = appPlugin.getApp();
|
|
80
91
|
this.dbManager = this.app.dbManager;
|
|
81
92
|
this.logger = this.app.logger;
|
|
82
93
|
await this.ensurePaymentTables();
|
|
83
94
|
this.registerNetworkHandlers();
|
|
84
|
-
console.log("[PaymentModule]
|
|
95
|
+
console.log("[PaymentModule] \u521D\u59CB\u5316\u5B8C\u6210");
|
|
85
96
|
this.logInfo("PaymentModule initialized successfully");
|
|
86
97
|
}
|
|
87
98
|
/**
|
|
@@ -156,7 +167,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
156
167
|
const network = this.app.plugins.get("network");
|
|
157
168
|
this.logInfo("Registering network status listener");
|
|
158
169
|
network == null ? void 0 : network.addListener("networkStatusChange", async (status) => {
|
|
159
|
-
console.log("
|
|
170
|
+
console.log("\u7F51\u7EDC\u72B6\u6001:", status.connected);
|
|
160
171
|
this.logInfo("Network status changed", {
|
|
161
172
|
connected: status.connected,
|
|
162
173
|
previousStatus: status.previousStatus
|
|
@@ -176,7 +187,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
176
187
|
try {
|
|
177
188
|
cachedMethods = await this.dbManager.getAll("pay_method");
|
|
178
189
|
} catch (dbError) {
|
|
179
|
-
console.warn("[PaymentModule] pay_method
|
|
190
|
+
console.warn("[PaymentModule] pay_method \u8868\u4E0D\u5B58\u5728\uFF0C\u5C06\u4ECE\u670D\u52A1\u5668\u83B7\u53D6\u6570\u636E");
|
|
180
191
|
}
|
|
181
192
|
const hasCache = cachedMethods.length > 0;
|
|
182
193
|
if (hasCache) {
|
|
@@ -190,7 +201,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
190
201
|
await this.dbManager.update("pay_method", method);
|
|
191
202
|
}
|
|
192
203
|
} catch (dbError) {
|
|
193
|
-
console.warn("[PaymentModule]
|
|
204
|
+
console.warn("[PaymentModule] \u65E0\u6CD5\u7F13\u5B58\u652F\u4ED8\u65B9\u5F0F\uFF0Cpay_method \u8868\u4E0D\u5B58\u5728");
|
|
194
205
|
}
|
|
195
206
|
await this.core.effects.emit(
|
|
196
207
|
import_types.PaymentHooks.OnPaymentMethodsLoaded,
|
|
@@ -202,7 +213,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
202
213
|
});
|
|
203
214
|
return payMethods;
|
|
204
215
|
} catch (error) {
|
|
205
|
-
console.error("[PaymentModule]
|
|
216
|
+
console.error("[PaymentModule] \u83B7\u53D6\u652F\u4ED8\u65B9\u5F0F\u5217\u8868\u5931\u8D25", error);
|
|
206
217
|
this.logError("getPayMethodListAsync failed", error);
|
|
207
218
|
return [];
|
|
208
219
|
}
|
|
@@ -215,7 +226,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
215
226
|
cachedMethodsCount: cachedMethods.length
|
|
216
227
|
});
|
|
217
228
|
try {
|
|
218
|
-
console.log("[PaymentModule]
|
|
229
|
+
console.log("[PaymentModule] \u540E\u53F0\u5237\u65B0\u652F\u4ED8\u65B9\u5F0F\u5217\u8868...");
|
|
219
230
|
const response = await this.request.get("/pay/custom-payment/available", { channel: "pos" });
|
|
220
231
|
const newPayMethods = response.data || [];
|
|
221
232
|
const hasChanges = this.hasPaymentMethodsChanged(
|
|
@@ -223,7 +234,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
223
234
|
newPayMethods
|
|
224
235
|
);
|
|
225
236
|
if (hasChanges) {
|
|
226
|
-
console.log("[PaymentModule]
|
|
237
|
+
console.log("[PaymentModule] \u652F\u4ED8\u65B9\u5F0F\u5217\u8868\u5DF2\u66F4\u65B0");
|
|
227
238
|
this.logInfo("Payment methods updated in background", {
|
|
228
239
|
oldCount: cachedMethods.length,
|
|
229
240
|
newCount: newPayMethods.length
|
|
@@ -236,7 +247,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
236
247
|
await this.dbManager.update("pay_method", method);
|
|
237
248
|
}
|
|
238
249
|
} catch (dbError) {
|
|
239
|
-
console.warn("[PaymentModule]
|
|
250
|
+
console.warn("[PaymentModule] \u65E0\u6CD5\u66F4\u65B0\u652F\u4ED8\u65B9\u5F0F\u7F13\u5B58", dbError);
|
|
240
251
|
}
|
|
241
252
|
const eventData = {
|
|
242
253
|
oldMethods: cachedMethods,
|
|
@@ -247,10 +258,10 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
247
258
|
eventData
|
|
248
259
|
);
|
|
249
260
|
} else {
|
|
250
|
-
console.log("[PaymentModule]
|
|
261
|
+
console.log("[PaymentModule] \u652F\u4ED8\u65B9\u5F0F\u5217\u8868\u65E0\u53D8\u5316");
|
|
251
262
|
}
|
|
252
263
|
} catch (error) {
|
|
253
|
-
console.error("[PaymentModule]
|
|
264
|
+
console.error("[PaymentModule] \u540E\u53F0\u5237\u65B0\u652F\u4ED8\u65B9\u5F0F\u5931\u8D25", error);
|
|
254
265
|
}
|
|
255
266
|
}
|
|
256
267
|
/**
|
|
@@ -269,7 +280,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
269
280
|
return true;
|
|
270
281
|
}
|
|
271
282
|
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 || {})) {
|
|
272
|
-
console.log(`[PaymentModule]
|
|
283
|
+
console.log(`[PaymentModule] \u652F\u4ED8\u65B9\u5F0F ${newMethod.id} (${newMethod.code}) \u53D1\u751F\u53D8\u5316:`, {
|
|
273
284
|
id: newMethod.id,
|
|
274
285
|
changes: {
|
|
275
286
|
code: oldMethod.code !== newMethod.code ? { old: oldMethod.code, new: newMethod.code } : void 0,
|
|
@@ -299,7 +310,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
299
310
|
try {
|
|
300
311
|
return await this.dbManager.getAll("order");
|
|
301
312
|
} catch (error) {
|
|
302
|
-
console.error("[PaymentModule]
|
|
313
|
+
console.error("[PaymentModule] \u83B7\u53D6\u8BA2\u5355\u5217\u8868\u5931\u8D25", error);
|
|
303
314
|
return [];
|
|
304
315
|
}
|
|
305
316
|
}
|
|
@@ -310,7 +321,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
310
321
|
try {
|
|
311
322
|
return await this.dbManager.get("order", orderUuid);
|
|
312
323
|
} catch (error) {
|
|
313
|
-
console.error("[PaymentModule]
|
|
324
|
+
console.error("[PaymentModule] \u83B7\u53D6\u652F\u4ED8\u8BA2\u5355\u5931\u8D25", error);
|
|
314
325
|
return null;
|
|
315
326
|
}
|
|
316
327
|
}
|
|
@@ -366,7 +377,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
366
377
|
return newOrder;
|
|
367
378
|
}
|
|
368
379
|
} catch (error) {
|
|
369
|
-
console.error("[PaymentModule]
|
|
380
|
+
console.error("[PaymentModule] \u521B\u5EFA\u652F\u4ED8\u8BA2\u5355\u5931\u8D25", error);
|
|
370
381
|
this.logError("createPaymentOrderAsync failed", error, {
|
|
371
382
|
orderId: params.order_id
|
|
372
383
|
});
|
|
@@ -382,10 +393,10 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
382
393
|
if (order) {
|
|
383
394
|
await this.dbManager.delete("order", orderUuid);
|
|
384
395
|
await this.core.effects.emit(import_types.PaymentHooks.OnOrderDeleted, order);
|
|
385
|
-
console.log("[PaymentModule]
|
|
396
|
+
console.log("[PaymentModule] \u652F\u4ED8\u8BA2\u5355\u5220\u9664\u6210\u529F:", orderUuid);
|
|
386
397
|
}
|
|
387
398
|
} catch (error) {
|
|
388
|
-
console.error("[PaymentModule]
|
|
399
|
+
console.error("[PaymentModule] \u5220\u9664\u652F\u4ED8\u8BA2\u5355\u5931\u8D25", error);
|
|
389
400
|
throw error;
|
|
390
401
|
}
|
|
391
402
|
}
|
|
@@ -407,7 +418,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
407
418
|
});
|
|
408
419
|
}
|
|
409
420
|
} catch (error) {
|
|
410
|
-
console.error("[PaymentModule]
|
|
421
|
+
console.error("[PaymentModule] \u66F4\u65B0\u8BA2\u5355\u5931\u8D25", error);
|
|
411
422
|
throw error;
|
|
412
423
|
}
|
|
413
424
|
}
|
|
@@ -441,7 +452,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
441
452
|
newOrderId,
|
|
442
453
|
existingOrderUuid: duplicateOrder.uuid
|
|
443
454
|
});
|
|
444
|
-
throw new Error(
|
|
455
|
+
throw new Error(`\u8BA2\u5355ID ${newOrderId} \u5DF2\u5B58\u5728`);
|
|
445
456
|
}
|
|
446
457
|
const originalOrderId = existingOrder.id;
|
|
447
458
|
const updatedOrder = {
|
|
@@ -473,10 +484,10 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
473
484
|
originalOrderId,
|
|
474
485
|
newOrderId
|
|
475
486
|
});
|
|
476
|
-
console.log(`[PaymentModule]
|
|
487
|
+
console.log(`[PaymentModule] \u8BA2\u5355ID\u66FF\u6362\u6210\u529F: ${originalOrderId} \u2192 ${newOrderId}`);
|
|
477
488
|
return updatedOrder;
|
|
478
489
|
} catch (error) {
|
|
479
|
-
console.error("[PaymentModule]
|
|
490
|
+
console.error("[PaymentModule] \u66FF\u6362\u8BA2\u5355ID\u5931\u8D25", error);
|
|
480
491
|
this.logError("replaceOrderIdByUuidAsync failed", error, {
|
|
481
492
|
orderUuid,
|
|
482
493
|
newOrderId
|
|
@@ -536,7 +547,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
536
547
|
}, new import_decimal.Decimal(0));
|
|
537
548
|
const expectedDepositAmount = new import_decimal.Decimal(order.deposit_amount || "0").sub(paidDepositAmount);
|
|
538
549
|
if (expectAmount.lte(0) && expectedDepositAmount.eq(0)) {
|
|
539
|
-
const warningMessage =
|
|
550
|
+
const warningMessage = `\u8BA2\u5355 ${orderUuid} \u5F85\u4ED8\u91D1\u989D\u5DF2\u4E3A0\uFF0C\u4E0D\u5141\u8BB8\u6DFB\u52A0\u65B0\u7684\u652F\u4ED8\u9879`;
|
|
540
551
|
console.warn("[PaymentModule] Payment lock triggered:", {
|
|
541
552
|
orderUuid,
|
|
542
553
|
expectAmount: order.expect_amount,
|
|
@@ -594,7 +605,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
594
605
|
changeGivenAmount: (_c = newPaymentItem.metadata) == null ? void 0 : _c.change_given_amount
|
|
595
606
|
});
|
|
596
607
|
} catch (error) {
|
|
597
|
-
console.error("[PaymentModule]
|
|
608
|
+
console.error("[PaymentModule] \u6DFB\u52A0\u652F\u4ED8\u9879\u5931\u8D25", error);
|
|
598
609
|
this.logError("addPaymentItemAsync failed", error, {
|
|
599
610
|
orderUuid,
|
|
600
611
|
paymentItem
|
|
@@ -610,22 +621,22 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
610
621
|
try {
|
|
611
622
|
const order = await this.dbManager.get("order", orderUuid);
|
|
612
623
|
if (!order) {
|
|
613
|
-
throw new Error("
|
|
624
|
+
throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728");
|
|
614
625
|
}
|
|
615
626
|
const paymentItem = order.payment.find(
|
|
616
627
|
(payment) => payment.uuid === paymentUuid
|
|
617
628
|
);
|
|
618
629
|
if (!paymentItem) {
|
|
619
|
-
throw new Error(
|
|
630
|
+
throw new Error(`\u652F\u4ED8\u9879\u4E0D\u5B58\u5728: ${paymentUuid}`);
|
|
620
631
|
}
|
|
621
632
|
if (paymentItem.status === "voided") {
|
|
622
|
-
console.warn(`[PaymentModule]
|
|
633
|
+
console.warn(`[PaymentModule] \u652F\u4ED8\u9879 ${paymentUuid} \u5DF2\u7ECF\u88AB\u5220\u9664\uFF0C\u8DF3\u8FC7\u64CD\u4F5C`);
|
|
623
634
|
return;
|
|
624
635
|
}
|
|
625
636
|
paymentItem.status = "voided";
|
|
626
637
|
paymentItem.origin_amount = paymentItem.amount;
|
|
627
638
|
paymentItem.amount = "0.00";
|
|
628
|
-
console.log(`[PaymentModule]
|
|
639
|
+
console.log(`[PaymentModule] \u652F\u4ED8\u9879\u6807\u8BB0\u4E3A\u5220\u9664:`, {
|
|
629
640
|
uuid: paymentItem.uuid,
|
|
630
641
|
originalAmount: paymentItem.origin_amount,
|
|
631
642
|
status: paymentItem.status
|
|
@@ -648,7 +659,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
648
659
|
newExpectAmount: order.expect_amount
|
|
649
660
|
});
|
|
650
661
|
} catch (error) {
|
|
651
|
-
console.error("[PaymentModule]
|
|
662
|
+
console.error("[PaymentModule] \u5220\u9664\u652F\u4ED8\u9879\u5931\u8D25", error);
|
|
652
663
|
this.logError("deletePaymentAsync failed", error, {
|
|
653
664
|
orderUuid,
|
|
654
665
|
paymentUuid
|
|
@@ -676,12 +687,12 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
676
687
|
try {
|
|
677
688
|
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
678
689
|
if (!order) {
|
|
679
|
-
throw new Error(
|
|
690
|
+
throw new Error(`\u8BA2\u5355\u4E0D\u5B58\u5728: ${orderUuid}`);
|
|
680
691
|
}
|
|
681
692
|
const existingVoucherItems = order.payment.filter(
|
|
682
693
|
(payment) => payment.voucher_id && payment.status !== "voided" && !payment.isSynced
|
|
683
694
|
);
|
|
684
|
-
console.log("[PaymentModule]
|
|
695
|
+
console.log("[PaymentModule] \u53D1\u73B0\u73B0\u6709\u4EE3\u91D1\u5238\u652F\u4ED8\u9879:", {
|
|
685
696
|
orderUuid,
|
|
686
697
|
existingVoucherCount: existingVoucherItems.length,
|
|
687
698
|
existingItems: existingVoucherItems.map((item) => ({
|
|
@@ -693,18 +704,18 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
693
704
|
}))
|
|
694
705
|
});
|
|
695
706
|
for (const voucherItem of existingVoucherItems) {
|
|
696
|
-
console.log(`[PaymentModule]
|
|
707
|
+
console.log(`[PaymentModule] \u5220\u9664\u73B0\u6709\u4EE3\u91D1\u5238\u652F\u4ED8\u9879: ${voucherItem.uuid}`);
|
|
697
708
|
await this.deletePaymentAsync(orderUuid, voucherItem.uuid);
|
|
698
709
|
}
|
|
699
|
-
console.log("[PaymentModule]
|
|
710
|
+
console.log("[PaymentModule] \u6DFB\u52A0\u65B0\u7684\u4EE3\u91D1\u5238\u652F\u4ED8\u9879:", {
|
|
700
711
|
orderUuid,
|
|
701
712
|
newItemCount: voucherPaymentItems.length
|
|
702
713
|
});
|
|
703
714
|
for (const voucherItem of voucherPaymentItems) {
|
|
704
715
|
if (!voucherItem.voucher_id) {
|
|
705
|
-
throw new Error(
|
|
716
|
+
throw new Error(`\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u7F3A\u5C11 voucher_id: ${JSON.stringify(voucherItem)}`);
|
|
706
717
|
}
|
|
707
|
-
console.log(`[PaymentModule]
|
|
718
|
+
console.log(`[PaymentModule] \u6DFB\u52A0\u4EE3\u91D1\u5238\u652F\u4ED8\u9879:`, {
|
|
708
719
|
code: voucherItem.code,
|
|
709
720
|
amount: voucherItem.amount,
|
|
710
721
|
voucher_id: voucherItem.voucher_id,
|
|
@@ -726,7 +737,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
726
737
|
finalExpectAmount: updatedOrder == null ? void 0 : updatedOrder.expect_amount
|
|
727
738
|
});
|
|
728
739
|
} catch (error) {
|
|
729
|
-
console.error("[PaymentModule]
|
|
740
|
+
console.error("[PaymentModule] \u6279\u91CF\u66F4\u65B0\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u5931\u8D25:", error);
|
|
730
741
|
this.logError("updateVoucherPaymentItemsAsync failed", error, {
|
|
731
742
|
orderUuid,
|
|
732
743
|
voucherPaymentItems
|
|
@@ -741,7 +752,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
741
752
|
try {
|
|
742
753
|
const order = await this.dbManager.get("order", orderUuid);
|
|
743
754
|
if (!order) {
|
|
744
|
-
throw new Error("
|
|
755
|
+
throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728");
|
|
745
756
|
}
|
|
746
757
|
const paymentItem = order.payment.find(
|
|
747
758
|
(payment) => payment.uuid === paymentUuid
|
|
@@ -765,7 +776,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
765
776
|
});
|
|
766
777
|
}
|
|
767
778
|
} catch (error) {
|
|
768
|
-
console.error("[PaymentModule]
|
|
779
|
+
console.error("[PaymentModule] \u66F4\u65B0\u652F\u4ED8\u9879\u5931\u8D25", error);
|
|
769
780
|
throw error;
|
|
770
781
|
}
|
|
771
782
|
}
|
|
@@ -795,7 +806,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
795
806
|
});
|
|
796
807
|
return result;
|
|
797
808
|
} catch (error) {
|
|
798
|
-
console.error("[PaymentModule]
|
|
809
|
+
console.error("[PaymentModule] \u63D0\u4EA4\u652F\u4ED8\u5931\u8D25", error);
|
|
799
810
|
this.logError("submitPayAsync failed", error, { orderUuid });
|
|
800
811
|
return { status: "failed" };
|
|
801
812
|
}
|
|
@@ -828,18 +839,18 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
828
839
|
if (totalPaidAmount.gte(orderTotalAmount)) {
|
|
829
840
|
order.payment_status = import_types.PaymentStatus.Finished;
|
|
830
841
|
console.log(
|
|
831
|
-
`[PaymentModule]
|
|
842
|
+
`[PaymentModule] \u8BA2\u5355 ${order.uuid} \u652F\u4ED8\u5B8C\u6210\uFF0C\u91D1\u989D: ${totalPaidAmount.toString()}/${orderTotalAmount.toString()}`
|
|
832
843
|
);
|
|
833
844
|
} else {
|
|
834
845
|
order.payment_status = import_types.PaymentStatus.PartiallyPaid;
|
|
835
846
|
console.log(
|
|
836
|
-
`[PaymentModule]
|
|
847
|
+
`[PaymentModule] \u8BA2\u5355 ${order.uuid} \u90E8\u5206\u652F\u4ED8\uFF0C\u91D1\u989D: ${totalPaidAmount.toString()}/${orderTotalAmount.toString()}`
|
|
837
848
|
);
|
|
838
849
|
}
|
|
839
850
|
paymentData.payment_status = order.payment_status === import_types.PaymentStatus.Finished ? "paid" : "partially_paid";
|
|
840
851
|
await this.dbManager.update("order", order);
|
|
841
852
|
if (paymentData.payments.length === 0) {
|
|
842
|
-
console.log(`[PaymentModule]
|
|
853
|
+
console.log(`[PaymentModule] \u8BA2\u5355 ${order.uuid} \u652F\u4ED8\u5217\u8868\u4E3A\u7A7A\uFF0C\u8DF3\u8FC7\u652F\u4ED8\u5904\u7406`);
|
|
843
854
|
this.logWarning("Empty payment list", {
|
|
844
855
|
orderUuid: order.uuid,
|
|
845
856
|
orderId: order.order_id
|
|
@@ -852,7 +863,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
852
863
|
order
|
|
853
864
|
});
|
|
854
865
|
} catch (error) {
|
|
855
|
-
console.error(`[PaymentModule]
|
|
866
|
+
console.error(`[PaymentModule] \u8BA2\u5355 ${order.uuid} \u652F\u4ED8\u63D0\u4EA4\u5931\u8D25`, error);
|
|
856
867
|
throw error;
|
|
857
868
|
}
|
|
858
869
|
}
|
|
@@ -862,7 +873,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
862
873
|
async getRemainingOrderAmountAsync(orderUuid) {
|
|
863
874
|
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
864
875
|
if (!order) {
|
|
865
|
-
throw new Error("
|
|
876
|
+
throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728");
|
|
866
877
|
}
|
|
867
878
|
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
868
879
|
}
|
|
@@ -872,7 +883,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
872
883
|
async getRemainingOrderAmountWithInputAsync(inputAmount, orderUuid) {
|
|
873
884
|
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
874
885
|
if (!order) {
|
|
875
|
-
throw new Error("
|
|
886
|
+
throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728");
|
|
876
887
|
}
|
|
877
888
|
if (inputAmount === null || inputAmount === void 0) {
|
|
878
889
|
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
@@ -885,7 +896,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
885
896
|
if (typeof inputAmount === "number") {
|
|
886
897
|
if (isNaN(inputAmount) || !isFinite(inputAmount)) {
|
|
887
898
|
console.warn(
|
|
888
|
-
`[PaymentModule]
|
|
899
|
+
`[PaymentModule] \u8F93\u5165\u91D1\u989D\u4E0D\u662F\u6709\u6548\u6570\u5B57: ${inputAmount}\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D`
|
|
889
900
|
);
|
|
890
901
|
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
891
902
|
}
|
|
@@ -895,7 +906,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
895
906
|
return new import_decimal.Decimal(order.expect_amount).minus(inputDecimal).toNumber();
|
|
896
907
|
} catch (error) {
|
|
897
908
|
console.warn(
|
|
898
|
-
`[PaymentModule]
|
|
909
|
+
`[PaymentModule] \u8F93\u5165\u91D1\u989D\u683C\u5F0F\u65E0\u6548: ${inputAmount}\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D`
|
|
899
910
|
);
|
|
900
911
|
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
901
912
|
}
|
|
@@ -916,7 +927,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
916
927
|
const effectiveAmount = paymentAmount.plus(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
|
|
917
928
|
return sum.plus(effectiveAmount);
|
|
918
929
|
} catch (error) {
|
|
919
|
-
console.warn(`[PaymentModule]
|
|
930
|
+
console.warn(`[PaymentModule] \u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: amount=${payment.amount}, rounding_amount=${payment.rounding_amount}\uFF0C\u8DF3\u8FC7\u8BA1\u7B97`);
|
|
920
931
|
return sum;
|
|
921
932
|
}
|
|
922
933
|
},
|
|
@@ -924,7 +935,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
924
935
|
);
|
|
925
936
|
const remainingAmount = order.is_deposit === 1 ? new import_decimal.Decimal(order.deposit_amount).minus(paidAmount) : totalAmount.minus(paidAmount);
|
|
926
937
|
order.expect_amount = import_decimal.Decimal.max(0, remainingAmount).toFixed(2);
|
|
927
|
-
console.log(`[PaymentModule]
|
|
938
|
+
console.log(`[PaymentModule] \u91CD\u65B0\u8BA1\u7B97\u8BA2\u5355\u91D1\u989D:`, {
|
|
928
939
|
orderUuid: order.uuid,
|
|
929
940
|
totalAmount: order.total_amount,
|
|
930
941
|
effectivePaidAmount: paidAmount.toFixed(2),
|
|
@@ -937,7 +948,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
937
948
|
rounding_amount: p.rounding_amount || "0.00",
|
|
938
949
|
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)
|
|
939
950
|
})),
|
|
940
|
-
|
|
951
|
+
\u8BF4\u660E: "\u6709\u6548\u652F\u4ED8\u91D1\u989D\u5305\u542B\u62B9\u96F6\u8BA1\u7B97\uFF08amount + |rounding_amount|\uFF09"
|
|
941
952
|
});
|
|
942
953
|
}
|
|
943
954
|
/**
|
|
@@ -950,7 +961,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
950
961
|
(method) => method.code === import_types.PaymentMethodType.Cash
|
|
951
962
|
) || null;
|
|
952
963
|
} catch (error) {
|
|
953
|
-
console.error("[PaymentModule]
|
|
964
|
+
console.error("[PaymentModule] \u83B7\u53D6\u73B0\u91D1\u652F\u4ED8\u65B9\u5F0F\u5931\u8D25", error);
|
|
954
965
|
return null;
|
|
955
966
|
}
|
|
956
967
|
}
|
|
@@ -964,7 +975,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
964
975
|
(method) => method.code === import_types.PaymentMethodType.Eftpos
|
|
965
976
|
) || null;
|
|
966
977
|
} catch (error) {
|
|
967
|
-
console.error("[PaymentModule]
|
|
978
|
+
console.error("[PaymentModule] \u83B7\u53D6Eftpos\u652F\u4ED8\u65B9\u5F0F\u5931\u8D25", error);
|
|
968
979
|
return null;
|
|
969
980
|
}
|
|
970
981
|
}
|
|
@@ -978,7 +989,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
978
989
|
(method) => method.code === import_types.PaymentMethodType.Wallet
|
|
979
990
|
) || null;
|
|
980
991
|
} catch (error) {
|
|
981
|
-
console.error("[PaymentModule]
|
|
992
|
+
console.error("[PaymentModule] \u83B7\u53D6\u94B1\u5305\u652F\u4ED8\u65B9\u5F0F\u5931\u8D25", error);
|
|
982
993
|
return null;
|
|
983
994
|
}
|
|
984
995
|
}
|
|
@@ -990,7 +1001,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
990
1001
|
await this.dbManager.getAll("pay_method");
|
|
991
1002
|
} catch (error) {
|
|
992
1003
|
console.warn(
|
|
993
|
-
"[PaymentModule] pay_method
|
|
1004
|
+
"[PaymentModule] pay_method \u8868\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5728\u6570\u636E\u5E93\u914D\u7F6E\u4E2D\u6DFB\u52A0\u4EE5\u4E0B\u914D\u7F6E\uFF1A"
|
|
994
1005
|
);
|
|
995
1006
|
console.warn('{ name: "pay_method", keyPath: "id" }');
|
|
996
1007
|
}
|
|
@@ -998,7 +1009,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
998
1009
|
await this.dbManager.getAll("order");
|
|
999
1010
|
} catch (error) {
|
|
1000
1011
|
console.warn(
|
|
1001
|
-
"[PaymentModule] order
|
|
1012
|
+
"[PaymentModule] order \u8868\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5728\u6570\u636E\u5E93\u914D\u7F6E\u4E2D\u6DFB\u52A0\u4EE5\u4E0B\u914D\u7F6E\uFF1A"
|
|
1002
1013
|
);
|
|
1003
1014
|
console.warn('{ name: "order", keyPath: "uuid" }');
|
|
1004
1015
|
}
|
|
@@ -1013,7 +1024,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1013
1024
|
(order) => order.payment_status === import_types.PaymentStatus.PartiallyPaid
|
|
1014
1025
|
);
|
|
1015
1026
|
} catch (error) {
|
|
1016
|
-
console.error("[PaymentModule]
|
|
1027
|
+
console.error("[PaymentModule] \u83B7\u53D6\u90E8\u5206\u652F\u4ED8\u8BA2\u5355\u5931\u8D25", error);
|
|
1017
1028
|
return [];
|
|
1018
1029
|
}
|
|
1019
1030
|
}
|
|
@@ -1033,15 +1044,15 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1033
1044
|
const amount = new import_decimal.Decimal(originalAmount);
|
|
1034
1045
|
const roundingInterval = new import_decimal.Decimal(interval);
|
|
1035
1046
|
if (roundingInterval.lte(0)) {
|
|
1036
|
-
throw new Error("
|
|
1047
|
+
throw new Error("\u820D\u5165\u95F4\u9694\u5FC5\u987B\u5927\u4E8E 0");
|
|
1037
1048
|
}
|
|
1038
1049
|
const supportedIntervals = [0.05, 0.1, 0.5, 1];
|
|
1039
1050
|
const intervalValue = roundingInterval.toNumber();
|
|
1040
1051
|
if (!supportedIntervals.includes(intervalValue)) {
|
|
1041
|
-
console.warn(`[PaymentModule]
|
|
1052
|
+
console.warn(`[PaymentModule] \u4E0D\u652F\u6301\u7684\u820D\u5165\u95F4\u9694: ${intervalValue}, \u652F\u6301\u7684\u95F4\u9694: ${supportedIntervals.join(", ")}`);
|
|
1042
1053
|
}
|
|
1043
1054
|
const baseValue = amount.div(roundingInterval);
|
|
1044
|
-
console.log(`[PaymentModule]
|
|
1055
|
+
console.log(`[PaymentModule] \u820D\u5165\u8BA1\u7B97 - \u539F\u59CB\u91D1\u989D: ${amount.toString()}, \u95F4\u9694: ${intervalValue}, \u57FA\u7840\u503C: ${baseValue.toString()}, \u89C4\u5219: ${rule}`);
|
|
1045
1056
|
let roundedValue;
|
|
1046
1057
|
switch (rule) {
|
|
1047
1058
|
case import_types.RoundingRule.Standard:
|
|
@@ -1061,12 +1072,12 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1061
1072
|
roundedValue = baseValue.floor();
|
|
1062
1073
|
break;
|
|
1063
1074
|
default:
|
|
1064
|
-
throw new Error(
|
|
1075
|
+
throw new Error(`\u4E0D\u652F\u6301\u7684\u820D\u5165\u89C4\u5219: ${rule}`);
|
|
1065
1076
|
}
|
|
1066
1077
|
const finalAmount = roundedValue.mul(roundingInterval);
|
|
1067
1078
|
const originalAmountStr = amount.toFixed(2);
|
|
1068
1079
|
if (finalAmount.eq(0)) {
|
|
1069
|
-
console.log(`[PaymentModule]
|
|
1080
|
+
console.log(`[PaymentModule] \u6700\u7EC8\u91D1\u989D\u4E3A0\uFF0C\u8FD4\u56DE\u539F\u59CB\u91D1\u989D: ${originalAmountStr}`);
|
|
1070
1081
|
return {
|
|
1071
1082
|
originalAmount: originalAmountStr,
|
|
1072
1083
|
roundedAmount: originalAmountStr,
|
|
@@ -1076,15 +1087,15 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1076
1087
|
const roundedAmountStr = finalAmount.toFixed(2);
|
|
1077
1088
|
const roundingDifference = finalAmount.sub(amount);
|
|
1078
1089
|
const roundingDifferenceStr = roundingDifference.toFixed(2);
|
|
1079
|
-
console.log(`[PaymentModule]
|
|
1090
|
+
console.log(`[PaymentModule] \u820D\u5165\u7ED3\u679C - \u539F\u59CB\u91D1\u989D: ${originalAmountStr}, \u820D\u5165\u540E\u91D1\u989D: ${roundedAmountStr}, \u820D\u5165\u5DEE\u989D: ${roundingDifferenceStr}`);
|
|
1080
1091
|
return {
|
|
1081
1092
|
originalAmount: originalAmountStr,
|
|
1082
1093
|
roundedAmount: roundedAmountStr,
|
|
1083
1094
|
roundingDifference: roundingDifferenceStr
|
|
1084
1095
|
};
|
|
1085
1096
|
} catch (error) {
|
|
1086
|
-
console.error("[PaymentModule]
|
|
1087
|
-
throw new Error(
|
|
1097
|
+
console.error("[PaymentModule] \u91D1\u989D\u820D\u5165\u5931\u8D25:", error);
|
|
1098
|
+
throw new Error(`\u91D1\u989D\u820D\u5165\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
1088
1099
|
}
|
|
1089
1100
|
}
|
|
1090
1101
|
/**
|
|
@@ -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 = 0,
|
|
585
|
+
OnWalletRecommendListCleared = 0,
|
|
586
|
+
OnUserIdentificationCodesUpdated = 0,
|
|
587
|
+
OnUserIdentificationCodesCleared = 0,
|
|
588
|
+
OnWalletCacheCleared = 0,
|
|
589
|
+
OnSearchIdentificationCodeCompleted = 0
|
|
590
590
|
}
|
|
591
591
|
/**
|
|
592
592
|
* 钱包推荐扣款请求参数
|
|
@@ -739,7 +739,7 @@ export interface SearchIdentificationCodeResponse {
|
|
|
739
739
|
/**
|
|
740
740
|
* 搜索识别码结果类型
|
|
741
741
|
*/
|
|
742
|
-
export type SearchIdentificationCodeResult = {
|
|
742
|
+
export declare type SearchIdentificationCodeResult = {
|
|
743
743
|
type: 'walletCode';
|
|
744
744
|
data: SearchIdentificationCodeItem[];
|
|
745
745
|
} | {
|
|
@@ -46,12 +46,9 @@ var sortUserIdentificationCodeList = (list) => {
|
|
|
46
46
|
var _a;
|
|
47
47
|
const errorCode = (_a = item.unified_error_code) == null ? void 0 : _a.toString();
|
|
48
48
|
const availableStatus = item.unified_available_status;
|
|
49
|
-
if (errorCode && middlePriorityErrorCodes.includes(errorCode))
|
|
50
|
-
|
|
51
|
-
if (availableStatus ===
|
|
52
|
-
return 3;
|
|
53
|
-
if (availableStatus === 1)
|
|
54
|
-
return 1;
|
|
49
|
+
if (errorCode && middlePriorityErrorCodes.includes(errorCode)) return 2;
|
|
50
|
+
if (availableStatus === 0) return 3;
|
|
51
|
+
if (availableStatus === 1) return 1;
|
|
55
52
|
return 0;
|
|
56
53
|
};
|
|
57
54
|
const aPriority = getPriority(a);
|