@pisell/pisellos 0.0.373 → 0.0.376
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/model/strategy/adapter/walletPass/utils.js +7 -2
- package/dist/model/strategy/type.d.ts +1 -1
- package/dist/modules/Customer/types.d.ts +1 -1
- package/dist/modules/Payment/index.js +35 -7
- package/dist/modules/Payment/types.d.ts +9 -7
- package/dist/modules/Product/index.d.ts +1 -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 +2 -2
- package/dist/solution/BookingByStep/utils/resources.d.ts +1 -1
- package/dist/solution/Checkout/index.js +31 -2
- package/dist/solution/Checkout/types.d.ts +2 -0
- package/dist/solution/ShopDiscount/types.d.ts +1 -1
- package/dist/solution/ShopDiscount/utils.d.ts +2 -2
- 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/model/strategy/adapter/walletPass/evaluator.js +2 -3
- package/lib/model/strategy/adapter/walletPass/example.js +21 -21
- package/lib/model/strategy/adapter/walletPass/index.js +4 -2
- package/lib/model/strategy/adapter/walletPass/locales.js +10 -10
- package/lib/model/strategy/adapter/walletPass/utils.js +9 -4
- package/lib/model/strategy/index.js +10 -7
- package/lib/model/strategy/strategy-example.js +19 -19
- package/lib/model/strategy/type.d.ts +1 -1
- package/lib/modules/Account/index.js +10 -9
- package/lib/modules/AccountList/index.js +11 -14
- package/lib/modules/BaseModule.js +3 -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 +15 -18
- 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 +6 -11
- package/lib/modules/Guests/index.js +15 -10
- 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 +94 -86
- package/lib/modules/Payment/types.d.ts +9 -7
- package/lib/modules/Payment/utils.js +6 -3
- package/lib/modules/Payment/walletpass.js +33 -33
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Product/index.js +5 -6
- package/lib/modules/ProductList/index.js +3 -5
- package/lib/modules/Resource/index.js +12 -8
- package/lib/modules/Rules/index.js +21 -16
- 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 +2 -2
- package/lib/solution/BookingByStep/index.js +129 -86
- 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 +14 -19
- 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 +15 -15
- package/lib/solution/Checkout/index.js +233 -217
- package/lib/solution/Checkout/types.d.ts +2 -0
- package/lib/solution/Checkout/utils/index.js +22 -18
- package/lib/solution/RegisterAndLogin/config.js +2 -2
- package/lib/solution/RegisterAndLogin/index.js +110 -114
- package/lib/solution/RegisterAndLogin/utils.js +9 -9
- package/lib/solution/ShopDiscount/index.js +13 -16
- package/lib/solution/ShopDiscount/types.d.ts +1 -1
- package/lib/solution/ShopDiscount/utils.d.ts +2 -2
- 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 +18 -17
|
@@ -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,25 +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
|
-
window;
|
|
64
|
-
// WindowPlugin 实例
|
|
65
|
-
dbManager;
|
|
66
|
-
// IndexDBManager 实例
|
|
67
|
-
logger;
|
|
68
|
-
// LoggerManager 实例
|
|
69
|
-
otherParams = {};
|
|
70
|
-
// 支付方式实例
|
|
71
|
-
cash;
|
|
72
|
-
eftpos;
|
|
73
|
-
wallet;
|
|
74
57
|
constructor(name, version) {
|
|
75
58
|
super(name || "payment", version);
|
|
59
|
+
this.defaultName = "pay";
|
|
60
|
+
this.defaultVersion = "1.0.0";
|
|
61
|
+
// LoggerManager 实例
|
|
62
|
+
this.otherParams = {};
|
|
76
63
|
this.cash = new import_cash.CashPaymentImpl(this);
|
|
77
64
|
this.eftpos = new import_eftpos.EftposPaymentImpl(this);
|
|
78
65
|
this.wallet = new import_walletpass.WalletPassPaymentImpl(this);
|
|
@@ -85,17 +72,17 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
85
72
|
const appPlugin = core.getPlugin("app");
|
|
86
73
|
this.window = core.getPlugin("window");
|
|
87
74
|
if (!this.request) {
|
|
88
|
-
throw new Error("
|
|
75
|
+
throw new Error("支付模块需要 request 插件支持");
|
|
89
76
|
}
|
|
90
77
|
if (!appPlugin) {
|
|
91
|
-
throw new Error("
|
|
78
|
+
throw new Error("支付模块需要 app 插件支持");
|
|
92
79
|
}
|
|
93
80
|
this.app = appPlugin.getApp();
|
|
94
81
|
this.dbManager = this.app.dbManager;
|
|
95
82
|
this.logger = this.app.logger;
|
|
96
83
|
await this.ensurePaymentTables();
|
|
97
84
|
this.registerNetworkHandlers();
|
|
98
|
-
console.log("[PaymentModule]
|
|
85
|
+
console.log("[PaymentModule] 初始化完成");
|
|
99
86
|
this.logInfo("PaymentModule initialized successfully");
|
|
100
87
|
}
|
|
101
88
|
/**
|
|
@@ -170,7 +157,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
170
157
|
const network = this.app.plugins.get("network");
|
|
171
158
|
this.logInfo("Registering network status listener");
|
|
172
159
|
network == null ? void 0 : network.addListener("networkStatusChange", async (status) => {
|
|
173
|
-
console.log("
|
|
160
|
+
console.log("网络状态:", status.connected);
|
|
174
161
|
this.logInfo("Network status changed", {
|
|
175
162
|
connected: status.connected,
|
|
176
163
|
previousStatus: status.previousStatus
|
|
@@ -190,7 +177,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
190
177
|
try {
|
|
191
178
|
cachedMethods = await this.dbManager.getAll("pay_method");
|
|
192
179
|
} catch (dbError) {
|
|
193
|
-
console.warn("[PaymentModule] pay_method
|
|
180
|
+
console.warn("[PaymentModule] pay_method 表不存在,将从服务器获取数据");
|
|
194
181
|
}
|
|
195
182
|
const hasCache = cachedMethods.length > 0;
|
|
196
183
|
if (hasCache) {
|
|
@@ -204,7 +191,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
204
191
|
await this.dbManager.update("pay_method", method);
|
|
205
192
|
}
|
|
206
193
|
} catch (dbError) {
|
|
207
|
-
console.warn("[PaymentModule]
|
|
194
|
+
console.warn("[PaymentModule] 无法缓存支付方式,pay_method 表不存在");
|
|
208
195
|
}
|
|
209
196
|
await this.core.effects.emit(
|
|
210
197
|
`${this.name}:onPaymentMethodsLoaded`,
|
|
@@ -216,7 +203,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
216
203
|
});
|
|
217
204
|
return payMethods;
|
|
218
205
|
} catch (error) {
|
|
219
|
-
console.error("[PaymentModule]
|
|
206
|
+
console.error("[PaymentModule] 获取支付方式列表失败", error);
|
|
220
207
|
this.logError("getPayMethodListAsync failed", error);
|
|
221
208
|
return [];
|
|
222
209
|
}
|
|
@@ -229,7 +216,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
229
216
|
cachedMethodsCount: cachedMethods.length
|
|
230
217
|
});
|
|
231
218
|
try {
|
|
232
|
-
console.log("[PaymentModule]
|
|
219
|
+
console.log("[PaymentModule] 后台刷新支付方式列表...");
|
|
233
220
|
const response = await this.request.get("/pay/custom-payment/available", { channel: "pos" });
|
|
234
221
|
const newPayMethods = response.data || [];
|
|
235
222
|
const hasChanges = this.hasPaymentMethodsChanged(
|
|
@@ -237,7 +224,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
237
224
|
newPayMethods
|
|
238
225
|
);
|
|
239
226
|
if (hasChanges) {
|
|
240
|
-
console.log("[PaymentModule]
|
|
227
|
+
console.log("[PaymentModule] 支付方式列表已更新");
|
|
241
228
|
this.logInfo("Payment methods updated in background", {
|
|
242
229
|
oldCount: cachedMethods.length,
|
|
243
230
|
newCount: newPayMethods.length
|
|
@@ -250,7 +237,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
250
237
|
await this.dbManager.update("pay_method", method);
|
|
251
238
|
}
|
|
252
239
|
} catch (dbError) {
|
|
253
|
-
console.warn("[PaymentModule]
|
|
240
|
+
console.warn("[PaymentModule] 无法更新支付方式缓存", dbError);
|
|
254
241
|
}
|
|
255
242
|
const eventData = {
|
|
256
243
|
oldMethods: cachedMethods,
|
|
@@ -261,10 +248,10 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
261
248
|
eventData
|
|
262
249
|
);
|
|
263
250
|
} else {
|
|
264
|
-
console.log("[PaymentModule]
|
|
251
|
+
console.log("[PaymentModule] 支付方式列表无变化");
|
|
265
252
|
}
|
|
266
253
|
} catch (error) {
|
|
267
|
-
console.error("[PaymentModule]
|
|
254
|
+
console.error("[PaymentModule] 后台刷新支付方式失败", error);
|
|
268
255
|
}
|
|
269
256
|
}
|
|
270
257
|
/**
|
|
@@ -283,7 +270,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
283
270
|
return true;
|
|
284
271
|
}
|
|
285
272
|
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 || {})) {
|
|
286
|
-
console.log(`[PaymentModule]
|
|
273
|
+
console.log(`[PaymentModule] 支付方式 ${newMethod.id} (${newMethod.code}) 发生变化:`, {
|
|
287
274
|
id: newMethod.id,
|
|
288
275
|
changes: {
|
|
289
276
|
code: oldMethod.code !== newMethod.code ? { old: oldMethod.code, new: newMethod.code } : void 0,
|
|
@@ -313,7 +300,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
313
300
|
try {
|
|
314
301
|
return await this.dbManager.getAll("order");
|
|
315
302
|
} catch (error) {
|
|
316
|
-
console.error("[PaymentModule]
|
|
303
|
+
console.error("[PaymentModule] 获取订单列表失败", error);
|
|
317
304
|
return [];
|
|
318
305
|
}
|
|
319
306
|
}
|
|
@@ -324,7 +311,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
324
311
|
try {
|
|
325
312
|
return await this.dbManager.get("order", orderUuid, true);
|
|
326
313
|
} catch (error) {
|
|
327
|
-
console.error("[PaymentModule]
|
|
314
|
+
console.error("[PaymentModule] 获取支付订单失败", error);
|
|
328
315
|
return null;
|
|
329
316
|
}
|
|
330
317
|
}
|
|
@@ -351,6 +338,27 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
351
338
|
is_deposit: params.is_deposit || 0,
|
|
352
339
|
deposit_amount: params.deposit_amount || "0.00"
|
|
353
340
|
};
|
|
341
|
+
if (params.existPayment && params.existPayment.length > 0) {
|
|
342
|
+
newOrder.payment = params.existPayment.map((payment) => ({
|
|
343
|
+
...payment,
|
|
344
|
+
isSynced: true,
|
|
345
|
+
// 标记为已同步
|
|
346
|
+
status: payment.status || "active"
|
|
347
|
+
}));
|
|
348
|
+
this.recalculateOrderAmount(newOrder);
|
|
349
|
+
this.logInfo("创建订单时包含云端支付项", {
|
|
350
|
+
orderId: params.order_id,
|
|
351
|
+
existPaymentCount: params.existPayment.length,
|
|
352
|
+
totalAmount: newOrder.total_amount,
|
|
353
|
+
expectAmount: newOrder.expect_amount,
|
|
354
|
+
paymentDetails: params.existPayment.map((p) => ({
|
|
355
|
+
uuid: p.uuid,
|
|
356
|
+
code: p.code,
|
|
357
|
+
amount: p.amount,
|
|
358
|
+
status: p.status
|
|
359
|
+
}))
|
|
360
|
+
});
|
|
361
|
+
}
|
|
354
362
|
const dbAddStartTime = Date.now();
|
|
355
363
|
await this.dbManager.add("order", newOrder, true);
|
|
356
364
|
const dbAddDuration = Date.now() - dbAddStartTime;
|
|
@@ -367,7 +375,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
367
375
|
}, 0);
|
|
368
376
|
return newOrder;
|
|
369
377
|
} catch (error) {
|
|
370
|
-
console.error("[PaymentModule]
|
|
378
|
+
console.error("[PaymentModule] 创建支付订单失败", error);
|
|
371
379
|
this.logError("createPaymentOrderAsync failed", error, {
|
|
372
380
|
orderId: params.order_id
|
|
373
381
|
});
|
|
@@ -383,10 +391,10 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
383
391
|
if (order) {
|
|
384
392
|
await this.dbManager.delete("order", orderUuid);
|
|
385
393
|
await this.core.effects.emit(`${this.name}:onOrderDeleted`, order);
|
|
386
|
-
console.log("[PaymentModule]
|
|
394
|
+
console.log("[PaymentModule] 支付订单删除成功:", orderUuid);
|
|
387
395
|
}
|
|
388
396
|
} catch (error) {
|
|
389
|
-
console.error("[PaymentModule]
|
|
397
|
+
console.error("[PaymentModule] 删除支付订单失败", error);
|
|
390
398
|
throw error;
|
|
391
399
|
}
|
|
392
400
|
}
|
|
@@ -408,7 +416,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
408
416
|
});
|
|
409
417
|
}
|
|
410
418
|
} catch (error) {
|
|
411
|
-
console.error("[PaymentModule]
|
|
419
|
+
console.error("[PaymentModule] 更新订单失败", error);
|
|
412
420
|
throw error;
|
|
413
421
|
}
|
|
414
422
|
}
|
|
@@ -442,7 +450,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
442
450
|
newOrderId,
|
|
443
451
|
existingOrderUuid: duplicateOrder.uuid
|
|
444
452
|
});
|
|
445
|
-
throw new Error(
|
|
453
|
+
throw new Error(`订单ID ${newOrderId} 已存在`);
|
|
446
454
|
}
|
|
447
455
|
const originalOrderId = existingOrder.id;
|
|
448
456
|
const updatedOrder = {
|
|
@@ -474,10 +482,10 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
474
482
|
originalOrderId,
|
|
475
483
|
newOrderId
|
|
476
484
|
});
|
|
477
|
-
console.log(`[PaymentModule]
|
|
485
|
+
console.log(`[PaymentModule] 订单ID替换成功: ${originalOrderId} → ${newOrderId}`);
|
|
478
486
|
return updatedOrder;
|
|
479
487
|
} catch (error) {
|
|
480
|
-
console.error("[PaymentModule]
|
|
488
|
+
console.error("[PaymentModule] 替换订单ID失败", error);
|
|
481
489
|
this.logError("replaceOrderIdByUuidAsync failed", error, {
|
|
482
490
|
orderUuid,
|
|
483
491
|
newOrderId
|
|
@@ -524,11 +532,11 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
524
532
|
orderPaymentType: paymentItem.order_payment_type
|
|
525
533
|
});
|
|
526
534
|
try {
|
|
527
|
-
this.logInfo("
|
|
535
|
+
this.logInfo("准备获取订单", {
|
|
528
536
|
orderUuid
|
|
529
537
|
});
|
|
530
538
|
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
531
|
-
this.logInfo("
|
|
539
|
+
this.logInfo("获取订单信息成功", {
|
|
532
540
|
orderUuid,
|
|
533
541
|
order
|
|
534
542
|
});
|
|
@@ -544,7 +552,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
544
552
|
}, new import_decimal.Decimal(0));
|
|
545
553
|
const expectedDepositAmount = new import_decimal.Decimal(order.deposit_amount || "0").sub(paidDepositAmount);
|
|
546
554
|
if (expectAmount.lte(0) && expectedDepositAmount.eq(0)) {
|
|
547
|
-
const warningMessage =
|
|
555
|
+
const warningMessage = `订单 ${orderUuid} 待付金额已为0,不允许添加新的支付项`;
|
|
548
556
|
console.warn("[PaymentModule] Payment lock triggered:", {
|
|
549
557
|
orderUuid,
|
|
550
558
|
expectAmount: order.expect_amount,
|
|
@@ -588,12 +596,12 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
588
596
|
};
|
|
589
597
|
order.payment.push(newPaymentItem);
|
|
590
598
|
this.recalculateOrderAmount(order);
|
|
591
|
-
this.logInfo("
|
|
599
|
+
this.logInfo("开始更新订单支付项", {
|
|
592
600
|
orderUuid,
|
|
593
601
|
order
|
|
594
602
|
});
|
|
595
603
|
await this.dbManager.update("order", order, true);
|
|
596
|
-
this.logInfo("
|
|
604
|
+
this.logInfo("更新订单支付项完成", {
|
|
597
605
|
orderUuid
|
|
598
606
|
});
|
|
599
607
|
this.core.effects.emit(`${this.name}:onPaymentAdded`, {
|
|
@@ -614,7 +622,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
614
622
|
changeGivenAmount: (_d = newPaymentItem.metadata) == null ? void 0 : _d.change_given_amount
|
|
615
623
|
});
|
|
616
624
|
} catch (error) {
|
|
617
|
-
console.error("[PaymentModule]
|
|
625
|
+
console.error("[PaymentModule] 添加支付项失败", error);
|
|
618
626
|
this.logError("addPaymentItemAsync failed", error, {
|
|
619
627
|
orderUuid,
|
|
620
628
|
paymentItem
|
|
@@ -630,22 +638,22 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
630
638
|
try {
|
|
631
639
|
const order = await this.dbManager.get("order", orderUuid);
|
|
632
640
|
if (!order) {
|
|
633
|
-
throw new Error("
|
|
641
|
+
throw new Error("订单不存在");
|
|
634
642
|
}
|
|
635
643
|
const paymentItem = order.payment.find(
|
|
636
644
|
(payment) => payment.uuid === paymentUuid
|
|
637
645
|
);
|
|
638
646
|
if (!paymentItem) {
|
|
639
|
-
throw new Error(
|
|
647
|
+
throw new Error(`支付项不存在: ${paymentUuid}`);
|
|
640
648
|
}
|
|
641
649
|
if (paymentItem.status === "voided") {
|
|
642
|
-
console.warn(`[PaymentModule]
|
|
650
|
+
console.warn(`[PaymentModule] 支付项 ${paymentUuid} 已经被删除,跳过操作`);
|
|
643
651
|
return;
|
|
644
652
|
}
|
|
645
653
|
paymentItem.status = "voided";
|
|
646
654
|
paymentItem.origin_amount = paymentItem.amount;
|
|
647
655
|
paymentItem.amount = "0.00";
|
|
648
|
-
console.log(`[PaymentModule]
|
|
656
|
+
console.log(`[PaymentModule] 支付项标记为删除:`, {
|
|
649
657
|
uuid: paymentItem.uuid,
|
|
650
658
|
originalAmount: paymentItem.origin_amount,
|
|
651
659
|
status: paymentItem.status
|
|
@@ -668,7 +676,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
668
676
|
newExpectAmount: order.expect_amount
|
|
669
677
|
});
|
|
670
678
|
} catch (error) {
|
|
671
|
-
console.error("[PaymentModule]
|
|
679
|
+
console.error("[PaymentModule] 删除支付项失败", error);
|
|
672
680
|
this.logError("deletePaymentAsync failed", error, {
|
|
673
681
|
orderUuid,
|
|
674
682
|
paymentUuid
|
|
@@ -696,12 +704,12 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
696
704
|
try {
|
|
697
705
|
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
698
706
|
if (!order) {
|
|
699
|
-
throw new Error(
|
|
707
|
+
throw new Error(`订单不存在: ${orderUuid}`);
|
|
700
708
|
}
|
|
701
709
|
const existingVoucherItems = order.payment.filter(
|
|
702
710
|
(payment) => payment.voucher_id && payment.status !== "voided" && !payment.isSynced
|
|
703
711
|
);
|
|
704
|
-
console.log("[PaymentModule]
|
|
712
|
+
console.log("[PaymentModule] 发现现有代金券支付项:", {
|
|
705
713
|
orderUuid,
|
|
706
714
|
existingVoucherCount: existingVoucherItems.length,
|
|
707
715
|
existingItems: existingVoucherItems.map((item) => ({
|
|
@@ -713,18 +721,18 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
713
721
|
}))
|
|
714
722
|
});
|
|
715
723
|
for (const voucherItem of existingVoucherItems) {
|
|
716
|
-
console.log(`[PaymentModule]
|
|
724
|
+
console.log(`[PaymentModule] 删除现有代金券支付项: ${voucherItem.uuid}`);
|
|
717
725
|
await this.deletePaymentAsync(orderUuid, voucherItem.uuid);
|
|
718
726
|
}
|
|
719
|
-
console.log("[PaymentModule]
|
|
727
|
+
console.log("[PaymentModule] 添加新的代金券支付项:", {
|
|
720
728
|
orderUuid,
|
|
721
729
|
newItemCount: voucherPaymentItems.length
|
|
722
730
|
});
|
|
723
731
|
for (const voucherItem of voucherPaymentItems) {
|
|
724
732
|
if (!voucherItem.voucher_id) {
|
|
725
|
-
throw new Error(
|
|
733
|
+
throw new Error(`代金券支付项缺少 voucher_id: ${JSON.stringify(voucherItem)}`);
|
|
726
734
|
}
|
|
727
|
-
console.log(`[PaymentModule]
|
|
735
|
+
console.log(`[PaymentModule] 添加代金券支付项:`, {
|
|
728
736
|
code: voucherItem.code,
|
|
729
737
|
amount: voucherItem.amount,
|
|
730
738
|
voucher_id: voucherItem.voucher_id,
|
|
@@ -746,7 +754,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
746
754
|
finalExpectAmount: updatedOrder == null ? void 0 : updatedOrder.expect_amount
|
|
747
755
|
});
|
|
748
756
|
} catch (error) {
|
|
749
|
-
console.error("[PaymentModule]
|
|
757
|
+
console.error("[PaymentModule] 批量更新代金券支付项失败:", error);
|
|
750
758
|
this.logError("updateVoucherPaymentItemsAsync failed", error, {
|
|
751
759
|
orderUuid,
|
|
752
760
|
voucherPaymentItems
|
|
@@ -761,7 +769,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
761
769
|
try {
|
|
762
770
|
const order = await this.dbManager.get("order", orderUuid);
|
|
763
771
|
if (!order) {
|
|
764
|
-
throw new Error("
|
|
772
|
+
throw new Error("订单不存在");
|
|
765
773
|
}
|
|
766
774
|
const paymentItem = order.payment.find(
|
|
767
775
|
(payment) => payment.uuid === paymentUuid
|
|
@@ -785,7 +793,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
785
793
|
});
|
|
786
794
|
}
|
|
787
795
|
} catch (error) {
|
|
788
|
-
console.error("[PaymentModule]
|
|
796
|
+
console.error("[PaymentModule] 更新支付项失败", error);
|
|
789
797
|
throw error;
|
|
790
798
|
}
|
|
791
799
|
}
|
|
@@ -815,7 +823,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
815
823
|
});
|
|
816
824
|
return result;
|
|
817
825
|
} catch (error) {
|
|
818
|
-
console.error("[PaymentModule]
|
|
826
|
+
console.error("[PaymentModule] 提交支付失败", error);
|
|
819
827
|
this.logError("submitPayAsync failed", error, { orderUuid });
|
|
820
828
|
return { status: "failed" };
|
|
821
829
|
}
|
|
@@ -848,18 +856,18 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
848
856
|
if (totalPaidAmount.gte(orderTotalAmount)) {
|
|
849
857
|
order.payment_status = import_types.PaymentStatus.Finished;
|
|
850
858
|
console.log(
|
|
851
|
-
`[PaymentModule]
|
|
859
|
+
`[PaymentModule] 订单 ${order.uuid} 支付完成,金额: ${totalPaidAmount.toString()}/${orderTotalAmount.toString()}`
|
|
852
860
|
);
|
|
853
861
|
} else {
|
|
854
862
|
order.payment_status = import_types.PaymentStatus.PartiallyPaid;
|
|
855
863
|
console.log(
|
|
856
|
-
`[PaymentModule]
|
|
864
|
+
`[PaymentModule] 订单 ${order.uuid} 部分支付,金额: ${totalPaidAmount.toString()}/${orderTotalAmount.toString()}`
|
|
857
865
|
);
|
|
858
866
|
}
|
|
859
867
|
paymentData.payment_status = order.payment_status === import_types.PaymentStatus.Finished ? "paid" : "partially_paid";
|
|
860
868
|
await this.dbManager.update("order", order);
|
|
861
869
|
if (paymentData.payments.length === 0) {
|
|
862
|
-
console.log(`[PaymentModule]
|
|
870
|
+
console.log(`[PaymentModule] 订单 ${order.uuid} 支付列表为空,跳过支付处理`);
|
|
863
871
|
this.logWarning("Empty payment list", {
|
|
864
872
|
orderUuid: order.uuid,
|
|
865
873
|
orderId: order.order_id
|
|
@@ -872,7 +880,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
872
880
|
order
|
|
873
881
|
});
|
|
874
882
|
} catch (error) {
|
|
875
|
-
console.error(`[PaymentModule]
|
|
883
|
+
console.error(`[PaymentModule] 订单 ${order.uuid} 支付提交失败`, error);
|
|
876
884
|
throw error;
|
|
877
885
|
}
|
|
878
886
|
}
|
|
@@ -882,7 +890,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
882
890
|
async getRemainingOrderAmountAsync(orderUuid) {
|
|
883
891
|
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
884
892
|
if (!order) {
|
|
885
|
-
throw new Error("
|
|
893
|
+
throw new Error("订单不存在");
|
|
886
894
|
}
|
|
887
895
|
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
888
896
|
}
|
|
@@ -892,7 +900,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
892
900
|
async getRemainingOrderAmountWithInputAsync(inputAmount, orderUuid) {
|
|
893
901
|
const order = await this.getPaymentOrderByUuidAsync(orderUuid);
|
|
894
902
|
if (!order) {
|
|
895
|
-
throw new Error("
|
|
903
|
+
throw new Error("订单不存在");
|
|
896
904
|
}
|
|
897
905
|
if (inputAmount === null || inputAmount === void 0) {
|
|
898
906
|
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
@@ -905,7 +913,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
905
913
|
if (typeof inputAmount === "number") {
|
|
906
914
|
if (isNaN(inputAmount) || !isFinite(inputAmount)) {
|
|
907
915
|
console.warn(
|
|
908
|
-
`[PaymentModule]
|
|
916
|
+
`[PaymentModule] 输入金额不是有效数字: ${inputAmount},返回原始待付金额`
|
|
909
917
|
);
|
|
910
918
|
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
911
919
|
}
|
|
@@ -915,7 +923,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
915
923
|
return new import_decimal.Decimal(order.expect_amount).minus(inputDecimal).toNumber();
|
|
916
924
|
} catch (error) {
|
|
917
925
|
console.warn(
|
|
918
|
-
`[PaymentModule]
|
|
926
|
+
`[PaymentModule] 输入金额格式无效: ${inputAmount},返回原始待付金额`
|
|
919
927
|
);
|
|
920
928
|
return new import_decimal.Decimal(order.expect_amount).toNumber();
|
|
921
929
|
}
|
|
@@ -936,7 +944,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
936
944
|
const effectiveAmount = paymentAmount.plus(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
|
|
937
945
|
return sum.plus(effectiveAmount);
|
|
938
946
|
} catch (error) {
|
|
939
|
-
console.warn(`[PaymentModule]
|
|
947
|
+
console.warn(`[PaymentModule] 无效的支付金额: amount=${payment.amount}, rounding_amount=${payment.rounding_amount},跳过计算`);
|
|
940
948
|
return sum;
|
|
941
949
|
}
|
|
942
950
|
},
|
|
@@ -944,7 +952,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
944
952
|
);
|
|
945
953
|
const remainingAmount = order.is_deposit === 1 ? new import_decimal.Decimal(order.deposit_amount).minus(paidAmount) : totalAmount.minus(paidAmount);
|
|
946
954
|
order.expect_amount = import_decimal.Decimal.max(0, remainingAmount).toFixed(2);
|
|
947
|
-
console.log(`[PaymentModule]
|
|
955
|
+
console.log(`[PaymentModule] 重新计算订单金额:`, {
|
|
948
956
|
orderUuid: order.uuid,
|
|
949
957
|
totalAmount: order.total_amount,
|
|
950
958
|
effectivePaidAmount: paidAmount.toFixed(2),
|
|
@@ -957,7 +965,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
957
965
|
rounding_amount: p.rounding_amount || "0.00",
|
|
958
966
|
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)
|
|
959
967
|
})),
|
|
960
|
-
|
|
968
|
+
说明: "有效支付金额包含抹零计算(amount + |rounding_amount|)"
|
|
961
969
|
});
|
|
962
970
|
}
|
|
963
971
|
/**
|
|
@@ -970,7 +978,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
970
978
|
(method) => method.code === import_types.PaymentMethodType.Cash
|
|
971
979
|
) || null;
|
|
972
980
|
} catch (error) {
|
|
973
|
-
console.error("[PaymentModule]
|
|
981
|
+
console.error("[PaymentModule] 获取现金支付方式失败", error);
|
|
974
982
|
return null;
|
|
975
983
|
}
|
|
976
984
|
}
|
|
@@ -984,7 +992,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
984
992
|
(method) => method.code === import_types.PaymentMethodType.Eftpos
|
|
985
993
|
) || null;
|
|
986
994
|
} catch (error) {
|
|
987
|
-
console.error("[PaymentModule]
|
|
995
|
+
console.error("[PaymentModule] 获取Eftpos支付方式失败", error);
|
|
988
996
|
return null;
|
|
989
997
|
}
|
|
990
998
|
}
|
|
@@ -998,7 +1006,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
998
1006
|
(method) => method.code === import_types.PaymentMethodType.Wallet
|
|
999
1007
|
) || null;
|
|
1000
1008
|
} catch (error) {
|
|
1001
|
-
console.error("[PaymentModule]
|
|
1009
|
+
console.error("[PaymentModule] 获取钱包支付方式失败", error);
|
|
1002
1010
|
return null;
|
|
1003
1011
|
}
|
|
1004
1012
|
}
|
|
@@ -1010,7 +1018,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1010
1018
|
await this.dbManager.getAll("pay_method");
|
|
1011
1019
|
} catch (error) {
|
|
1012
1020
|
console.warn(
|
|
1013
|
-
"[PaymentModule] pay_method
|
|
1021
|
+
"[PaymentModule] pay_method 表不存在,请在数据库配置中添加以下配置:"
|
|
1014
1022
|
);
|
|
1015
1023
|
console.warn('{ name: "pay_method", keyPath: "id" }');
|
|
1016
1024
|
}
|
|
@@ -1018,7 +1026,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1018
1026
|
await this.dbManager.getAll("order");
|
|
1019
1027
|
} catch (error) {
|
|
1020
1028
|
console.warn(
|
|
1021
|
-
"[PaymentModule] order
|
|
1029
|
+
"[PaymentModule] order 表不存在,请在数据库配置中添加以下配置:"
|
|
1022
1030
|
);
|
|
1023
1031
|
console.warn('{ name: "order", keyPath: "uuid" }');
|
|
1024
1032
|
}
|
|
@@ -1033,7 +1041,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1033
1041
|
(order) => order.payment_status === import_types.PaymentStatus.PartiallyPaid
|
|
1034
1042
|
);
|
|
1035
1043
|
} catch (error) {
|
|
1036
|
-
console.error("[PaymentModule]
|
|
1044
|
+
console.error("[PaymentModule] 获取部分支付订单失败", error);
|
|
1037
1045
|
return [];
|
|
1038
1046
|
}
|
|
1039
1047
|
}
|
|
@@ -1053,15 +1061,15 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1053
1061
|
const amount = new import_decimal.Decimal(originalAmount);
|
|
1054
1062
|
const roundingInterval = new import_decimal.Decimal(interval);
|
|
1055
1063
|
if (roundingInterval.lte(0)) {
|
|
1056
|
-
throw new Error("
|
|
1064
|
+
throw new Error("舍入间隔必须大于 0");
|
|
1057
1065
|
}
|
|
1058
1066
|
const supportedIntervals = [0.05, 0.1, 0.5, 1];
|
|
1059
1067
|
const intervalValue = roundingInterval.toNumber();
|
|
1060
1068
|
if (!supportedIntervals.includes(intervalValue)) {
|
|
1061
|
-
console.warn(`[PaymentModule]
|
|
1069
|
+
console.warn(`[PaymentModule] 不支持的舍入间隔: ${intervalValue}, 支持的间隔: ${supportedIntervals.join(", ")}`);
|
|
1062
1070
|
}
|
|
1063
1071
|
const baseValue = amount.div(roundingInterval);
|
|
1064
|
-
console.log(`[PaymentModule]
|
|
1072
|
+
console.log(`[PaymentModule] 舍入计算 - 原始金额: ${amount.toString()}, 间隔: ${intervalValue}, 基础值: ${baseValue.toString()}, 规则: ${rule}`);
|
|
1065
1073
|
let roundedValue;
|
|
1066
1074
|
switch (rule) {
|
|
1067
1075
|
case import_types.RoundingRule.Standard:
|
|
@@ -1081,12 +1089,12 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1081
1089
|
roundedValue = baseValue.floor();
|
|
1082
1090
|
break;
|
|
1083
1091
|
default:
|
|
1084
|
-
throw new Error(
|
|
1092
|
+
throw new Error(`不支持的舍入规则: ${rule}`);
|
|
1085
1093
|
}
|
|
1086
1094
|
const finalAmount = roundedValue.mul(roundingInterval);
|
|
1087
1095
|
const originalAmountStr = amount.toFixed(2);
|
|
1088
1096
|
if (finalAmount.eq(0)) {
|
|
1089
|
-
console.log(`[PaymentModule]
|
|
1097
|
+
console.log(`[PaymentModule] 最终金额为0,返回原始金额: ${originalAmountStr}`);
|
|
1090
1098
|
return {
|
|
1091
1099
|
originalAmount: originalAmountStr,
|
|
1092
1100
|
roundedAmount: originalAmountStr,
|
|
@@ -1096,15 +1104,15 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1096
1104
|
const roundedAmountStr = finalAmount.toFixed(2);
|
|
1097
1105
|
const roundingDifference = finalAmount.sub(amount);
|
|
1098
1106
|
const roundingDifferenceStr = roundingDifference.toFixed(2);
|
|
1099
|
-
console.log(`[PaymentModule]
|
|
1107
|
+
console.log(`[PaymentModule] 舍入结果 - 原始金额: ${originalAmountStr}, 舍入后金额: ${roundedAmountStr}, 舍入差额: ${roundingDifferenceStr}`);
|
|
1100
1108
|
return {
|
|
1101
1109
|
originalAmount: originalAmountStr,
|
|
1102
1110
|
roundedAmount: roundedAmountStr,
|
|
1103
1111
|
roundingDifference: roundingDifferenceStr
|
|
1104
1112
|
};
|
|
1105
1113
|
} catch (error) {
|
|
1106
|
-
console.error("[PaymentModule]
|
|
1107
|
-
throw new Error(
|
|
1114
|
+
console.error("[PaymentModule] 金额舍入失败:", error);
|
|
1115
|
+
throw new Error(`金额舍入失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
1108
1116
|
}
|
|
1109
1117
|
}
|
|
1110
1118
|
/**
|
|
@@ -200,6 +200,8 @@ export interface PushOrderParams {
|
|
|
200
200
|
deposit_amount?: string;
|
|
201
201
|
/** 原始订单数据(可选,由 Checkout 模块传入) */
|
|
202
202
|
order_info?: any;
|
|
203
|
+
/** 云端已存在的支付项(可选,用于处理订单在其他设备或云端生成的场景) */
|
|
204
|
+
existPayment?: PaymentItem[];
|
|
203
205
|
}
|
|
204
206
|
/**
|
|
205
207
|
* 更新订单参数
|
|
@@ -581,12 +583,12 @@ export declare enum PaymentHooks {
|
|
|
581
583
|
OnOrderAmountChanged = "payment:onOrderAmountChanged",
|
|
582
584
|
OnPaymentSyncError = "payment:onPaymentSyncError",
|
|
583
585
|
OnPaymentSyncSuccess = "payment:onPaymentSyncSuccess",
|
|
584
|
-
OnWalletRecommendListUpdated =
|
|
585
|
-
OnWalletRecommendListCleared =
|
|
586
|
-
OnUserIdentificationCodesUpdated =
|
|
587
|
-
OnUserIdentificationCodesCleared =
|
|
588
|
-
OnWalletCacheCleared =
|
|
589
|
-
OnSearchIdentificationCodeCompleted =
|
|
586
|
+
OnWalletRecommendListUpdated = "wallet:onWalletRecommendListUpdated",
|
|
587
|
+
OnWalletRecommendListCleared = "wallet:onWalletRecommendListCleared",
|
|
588
|
+
OnUserIdentificationCodesUpdated = "wallet:onUserIdentificationCodesUpdated",
|
|
589
|
+
OnUserIdentificationCodesCleared = "wallet:onUserIdentificationCodesCleared",
|
|
590
|
+
OnWalletCacheCleared = "wallet:onWalletCacheCleared",
|
|
591
|
+
OnSearchIdentificationCodeCompleted = "wallet:onSearchIdentificationCodeCompleted"
|
|
590
592
|
}
|
|
591
593
|
/**
|
|
592
594
|
* 钱包推荐扣款请求参数
|
|
@@ -749,7 +751,7 @@ export interface SearchIdentificationCodeResponse {
|
|
|
749
751
|
/**
|
|
750
752
|
* 搜索识别码结果类型
|
|
751
753
|
*/
|
|
752
|
-
export
|
|
754
|
+
export type SearchIdentificationCodeResult = {
|
|
753
755
|
type: 'walletCode';
|
|
754
756
|
data: SearchIdentificationCodeItem[];
|
|
755
757
|
} | {
|
|
@@ -49,9 +49,12 @@ var sortUserIdentificationCodeList = (list) => {
|
|
|
49
49
|
var _a;
|
|
50
50
|
const errorCode = (_a = item.unified_error_code) == null ? void 0 : _a.toString();
|
|
51
51
|
const availableStatus = item.unified_available_status;
|
|
52
|
-
if (errorCode && middlePriorityErrorCodes.includes(errorCode))
|
|
53
|
-
|
|
54
|
-
if (availableStatus ===
|
|
52
|
+
if (errorCode && middlePriorityErrorCodes.includes(errorCode))
|
|
53
|
+
return 2;
|
|
54
|
+
if (availableStatus === 0)
|
|
55
|
+
return 3;
|
|
56
|
+
if (availableStatus === 1)
|
|
57
|
+
return 1;
|
|
55
58
|
return 0;
|
|
56
59
|
};
|
|
57
60
|
const aPriority = getPriority(a);
|