@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
|
@@ -43,30 +43,23 @@ var import_utils = require("./utils");
|
|
|
43
43
|
var import_utils2 = require("../../modules/Cart/utils");
|
|
44
44
|
__reExport(Checkout_exports, require("./types"), module.exports);
|
|
45
45
|
var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
46
|
-
defaultName = "checkout";
|
|
47
|
-
defaultVersion = "1.0.0";
|
|
48
|
-
isSolution = true;
|
|
49
|
-
request;
|
|
50
|
-
store;
|
|
51
|
-
otherParams = {};
|
|
52
|
-
logger;
|
|
53
|
-
// LoggerManager 实例
|
|
54
|
-
// 直接挂载的模块
|
|
55
|
-
order;
|
|
56
|
-
payment;
|
|
57
46
|
constructor(name, version) {
|
|
58
47
|
super(name || "checkout", version || "1.0.0");
|
|
48
|
+
this.defaultName = "checkout";
|
|
49
|
+
this.defaultVersion = "1.0.0";
|
|
50
|
+
this.isSolution = true;
|
|
51
|
+
this.otherParams = {};
|
|
59
52
|
}
|
|
60
53
|
async initialize(core, options) {
|
|
61
54
|
this.core = core;
|
|
62
55
|
this.otherParams = options.otherParams || {};
|
|
63
56
|
this.request = core.getPlugin("request");
|
|
64
57
|
if (!this.request) {
|
|
65
|
-
throw new Error("Checkout
|
|
58
|
+
throw new Error("Checkout 解决方案需要 request 插件支持");
|
|
66
59
|
}
|
|
67
60
|
const appPlugin = core.getPlugin("app");
|
|
68
61
|
if (!appPlugin) {
|
|
69
|
-
throw new Error("Checkout
|
|
62
|
+
throw new Error("Checkout 解决方案需要 app 插件支持");
|
|
70
63
|
}
|
|
71
64
|
const app = appPlugin.getApp();
|
|
72
65
|
this.logger = app.logger;
|
|
@@ -84,8 +77,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
84
77
|
await this.initializeSubModules(core, options);
|
|
85
78
|
await this.preloadPaymentMethods();
|
|
86
79
|
await this.cleanupExpiredOrdersAsync();
|
|
87
|
-
console.log("[Checkout]
|
|
88
|
-
await this.core.effects.emit(
|
|
80
|
+
console.log("[Checkout] 初始化完成");
|
|
81
|
+
await this.core.effects.emit(`${this.name}:onCheckoutInitialized`, {
|
|
89
82
|
timestamp: Date.now()
|
|
90
83
|
});
|
|
91
84
|
this.logInfo("CheckoutModule initialized successfully");
|
|
@@ -160,14 +153,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
160
153
|
this.core.effects.on(
|
|
161
154
|
import_types2.PaymentHooks.OnPaymentMethodsLoaded,
|
|
162
155
|
async (methods) => {
|
|
163
|
-
console.log("[Checkout]
|
|
156
|
+
console.log("[Checkout] 收到支付方式加载完成事件:", methods.length);
|
|
164
157
|
this.store.paymentMethods = methods;
|
|
165
158
|
}
|
|
166
159
|
);
|
|
167
160
|
this.core.effects.on(
|
|
168
161
|
import_types2.PaymentHooks.OnPaymentMethodsChanged,
|
|
169
162
|
async (data) => {
|
|
170
|
-
console.log("[Checkout]
|
|
163
|
+
console.log("[Checkout] 收到支付方式变更事件:", {
|
|
171
164
|
oldCount: data.oldMethods.length,
|
|
172
165
|
newCount: data.newMethods.length
|
|
173
166
|
});
|
|
@@ -190,11 +183,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
190
183
|
if (!validation.valid) {
|
|
191
184
|
throw (0, import_utils.createCheckoutError)(
|
|
192
185
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
193
|
-
|
|
186
|
+
`参数验证失败: ${validation.errors.join(", ")}`
|
|
194
187
|
);
|
|
195
188
|
}
|
|
196
189
|
this.store.cartItems = params.cartItems;
|
|
197
|
-
console.log("[Checkout]
|
|
190
|
+
console.log("[Checkout] 结账流程初始化完成");
|
|
198
191
|
} catch (error) {
|
|
199
192
|
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
200
193
|
throw error;
|
|
@@ -254,13 +247,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
254
247
|
if (this.store.isOrderSynced) {
|
|
255
248
|
walletBusinessData.payment_order_id = (_f = this.store.currentOrder) == null ? void 0 : _f.order_id;
|
|
256
249
|
}
|
|
257
|
-
this.logInfo("
|
|
250
|
+
this.logInfo("开始拉取:initializeWalletDataFromBusinessAsync", {
|
|
258
251
|
walletBusinessData
|
|
259
252
|
});
|
|
260
253
|
await this.payment.wallet.initializeWalletDataFromBusinessAsync(
|
|
261
254
|
walletBusinessData
|
|
262
255
|
);
|
|
263
|
-
this.logInfo("
|
|
256
|
+
this.logInfo("调用结束:initializeWalletDataFromBusinessAsync", {
|
|
264
257
|
walletBusinessData
|
|
265
258
|
});
|
|
266
259
|
if (!this.store.currentOrder) {
|
|
@@ -269,7 +262,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
269
262
|
this.logInfo("initWalletData currentOrder found", {
|
|
270
263
|
currentOrder: this.store.currentOrder
|
|
271
264
|
});
|
|
272
|
-
await this.core.effects.emit(
|
|
265
|
+
await this.core.effects.emit(`${this.name}:onWalletDataInitialized`, {
|
|
273
266
|
orderUuid: (_g = this.store.currentOrder) == null ? void 0 : _g.uuid,
|
|
274
267
|
customerId: walletBusinessData.customer_id,
|
|
275
268
|
walletBusinessData: {
|
|
@@ -356,7 +349,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
356
349
|
if (!validation.valid) {
|
|
357
350
|
throw (0, import_utils.createCheckoutError)(
|
|
358
351
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
359
|
-
|
|
352
|
+
`订单数据验证失败: ${validation.errors.join(", ")}`
|
|
360
353
|
);
|
|
361
354
|
}
|
|
362
355
|
const localOrderId = (0, import_utils.generateLocalOrderId)();
|
|
@@ -375,10 +368,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
375
368
|
};
|
|
376
369
|
if (customerInfo.customer_id || customerInfo.customer_name) {
|
|
377
370
|
this.store.currentCustomer = customerInfo;
|
|
378
|
-
console.log("[Checkout]
|
|
371
|
+
console.log("[Checkout] 保存客户信息:", customerInfo);
|
|
379
372
|
} else {
|
|
380
373
|
this.store.currentCustomer = void 0;
|
|
381
|
-
console.log("[Checkout]
|
|
374
|
+
console.log("[Checkout] 未提供客户信息");
|
|
382
375
|
}
|
|
383
376
|
const isNeedDeposit = this.checkIsNeedDepositAsync(
|
|
384
377
|
params.orderData.bookings,
|
|
@@ -403,12 +396,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
403
396
|
this.store.currentOrder = paymentOrder;
|
|
404
397
|
if (params.autoPayment) {
|
|
405
398
|
}
|
|
406
|
-
this.core.effects.emit(
|
|
399
|
+
this.core.effects.emit(`${this.name}:onOrderCreated`, {
|
|
407
400
|
order: paymentOrder,
|
|
408
401
|
timestamp: Date.now()
|
|
409
402
|
});
|
|
410
403
|
await this.updateStateAmountToRemaining(false);
|
|
411
|
-
this.logInfo("
|
|
404
|
+
this.logInfo("本地订单创建成功:", {
|
|
412
405
|
localOrderId,
|
|
413
406
|
uuid: paymentOrder.uuid,
|
|
414
407
|
totalAmount: amountInfo.totalAmount,
|
|
@@ -423,8 +416,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
423
416
|
error,
|
|
424
417
|
import_types.CheckoutErrorType.OrderCreationFailed
|
|
425
418
|
);
|
|
426
|
-
this.logError("
|
|
427
|
-
this.core.effects.emit(
|
|
419
|
+
this.logError("本地订单创建失败:", error);
|
|
420
|
+
this.core.effects.emit(`${this.name}:onOrderCreationFailed`, {
|
|
428
421
|
error: this.store.lastError,
|
|
429
422
|
timestamp: Date.now()
|
|
430
423
|
});
|
|
@@ -450,7 +443,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
450
443
|
if (!validation.valid) {
|
|
451
444
|
throw (0, import_utils.createCheckoutError)(
|
|
452
445
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
453
|
-
|
|
446
|
+
`订单数据验证失败: ${validation.errors.join(", ")}`
|
|
454
447
|
);
|
|
455
448
|
}
|
|
456
449
|
const amountInfo = (0, import_utils.extractAmountFromCartSummary)(params.cartSummary);
|
|
@@ -514,18 +507,18 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
514
507
|
if (!updated)
|
|
515
508
|
throw (0, import_utils.createCheckoutError)(
|
|
516
509
|
import_types.CheckoutErrorType.UnknownError,
|
|
517
|
-
"
|
|
510
|
+
"订单更新失败"
|
|
518
511
|
);
|
|
519
512
|
this.store.currentOrder = updated;
|
|
520
513
|
await this.updateStateAmountToRemaining(false);
|
|
521
|
-
this.logInfo("
|
|
514
|
+
this.logInfo("本地订单更新成功(保留支付项):", {
|
|
522
515
|
orderId: params.orderId,
|
|
523
516
|
uuid: updated.uuid,
|
|
524
517
|
payments: ((_m = updated.payment) == null ? void 0 : _m.length) || 0,
|
|
525
518
|
totalAmount: updated.total_amount,
|
|
526
519
|
expectAmount: updated.expect_amount
|
|
527
520
|
});
|
|
528
|
-
await this.core.effects.emit(
|
|
521
|
+
await this.core.effects.emit(`${this.name}:onOrderCreated`, {
|
|
529
522
|
order: updated,
|
|
530
523
|
timestamp: Date.now()
|
|
531
524
|
});
|
|
@@ -578,7 +571,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
578
571
|
if (!this.store.currentOrder) {
|
|
579
572
|
throw (0, import_utils.createCheckoutError)(
|
|
580
573
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
581
|
-
"
|
|
574
|
+
"未找到当前订单"
|
|
582
575
|
);
|
|
583
576
|
}
|
|
584
577
|
const order = await this.payment.getPaymentOrderByUuidAsync(
|
|
@@ -587,15 +580,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
587
580
|
if (!order || order.payment_status !== import_types2.PaymentStatus.Finished) {
|
|
588
581
|
throw (0, import_utils.createCheckoutError)(
|
|
589
582
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
590
|
-
"
|
|
583
|
+
"订单支付未完成,无法完成结账"
|
|
591
584
|
);
|
|
592
585
|
}
|
|
593
586
|
this.payment.wallet.clearAllCache();
|
|
594
|
-
await this.core.effects.emit(
|
|
587
|
+
await this.core.effects.emit(`${this.name}:onCheckoutCompleted`, {
|
|
595
588
|
orderId: order.id,
|
|
596
589
|
timestamp: Date.now()
|
|
597
590
|
});
|
|
598
|
-
console.log("[Checkout]
|
|
591
|
+
console.log("[Checkout] 结账流程完成:", order.id);
|
|
599
592
|
await this.resetStoreStateAsync();
|
|
600
593
|
return {
|
|
601
594
|
success: true,
|
|
@@ -622,7 +615,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
622
615
|
try {
|
|
623
616
|
const { currentOrder, cartItems, localOrderData } = this.store;
|
|
624
617
|
if (!currentOrder) {
|
|
625
|
-
console.log("[Checkout]
|
|
618
|
+
console.log("[Checkout] 当前没有活跃订单");
|
|
626
619
|
return null;
|
|
627
620
|
}
|
|
628
621
|
const orderInfo = currentOrder.order_info || {};
|
|
@@ -645,7 +638,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
645
638
|
};
|
|
646
639
|
return result;
|
|
647
640
|
} catch (error) {
|
|
648
|
-
console.error("[Checkout]
|
|
641
|
+
console.error("[Checkout] 获取当前订单基础信息失败:", error);
|
|
649
642
|
return null;
|
|
650
643
|
}
|
|
651
644
|
}
|
|
@@ -658,7 +651,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
658
651
|
try {
|
|
659
652
|
const { currentOrder } = this.store;
|
|
660
653
|
if (!currentOrder) {
|
|
661
|
-
console.log("[Checkout]
|
|
654
|
+
console.log("[Checkout] 当前没有活跃订单,无法获取支付项");
|
|
662
655
|
return [];
|
|
663
656
|
}
|
|
664
657
|
const paymentItems = await this.payment.getPaymentItemsAsync(
|
|
@@ -666,7 +659,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
666
659
|
);
|
|
667
660
|
return paymentItems;
|
|
668
661
|
} catch (error) {
|
|
669
|
-
console.error("[Checkout]
|
|
662
|
+
console.error("[Checkout] 获取当前订单支付项失败:", error);
|
|
670
663
|
return [];
|
|
671
664
|
}
|
|
672
665
|
}
|
|
@@ -693,7 +686,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
693
686
|
async replaceLocalOrderIdAsync(newOrderId) {
|
|
694
687
|
try {
|
|
695
688
|
if (!this.store.currentOrder) {
|
|
696
|
-
console.warn("[Checkout]
|
|
689
|
+
console.warn("[Checkout] 没有当前订单,无法替换订单ID");
|
|
697
690
|
return null;
|
|
698
691
|
}
|
|
699
692
|
const updatedOrder = await this.payment.replaceOrderIdByUuidAsync(
|
|
@@ -702,11 +695,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
702
695
|
);
|
|
703
696
|
if (updatedOrder) {
|
|
704
697
|
this.store.currentOrder = updatedOrder;
|
|
705
|
-
await this.core.effects.emit(
|
|
698
|
+
await this.core.effects.emit(`${this.name}:onOrderCreated`, {
|
|
706
699
|
order: updatedOrder,
|
|
707
700
|
timestamp: Date.now()
|
|
708
701
|
});
|
|
709
|
-
console.log("[Checkout]
|
|
702
|
+
console.log("[Checkout] 本地订单ID替换成功:", {
|
|
710
703
|
uuid: updatedOrder.uuid,
|
|
711
704
|
newOrderId: updatedOrder.id
|
|
712
705
|
});
|
|
@@ -715,7 +708,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
715
708
|
}
|
|
716
709
|
return updatedOrder;
|
|
717
710
|
} catch (error) {
|
|
718
|
-
console.error("[Checkout]
|
|
711
|
+
console.error("[Checkout] 替换订单ID失败:", error);
|
|
719
712
|
await this.handleError(error, import_types.CheckoutErrorType.UnknownError);
|
|
720
713
|
return null;
|
|
721
714
|
}
|
|
@@ -731,26 +724,26 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
731
724
|
try {
|
|
732
725
|
const numAmount = parseFloat(amount);
|
|
733
726
|
if (isNaN(numAmount) || numAmount < 0) {
|
|
734
|
-
throw new Error(
|
|
727
|
+
throw new Error(`无效的支付金额: ${amount}`);
|
|
735
728
|
}
|
|
736
729
|
const oldAmount = this.store.stateAmount;
|
|
737
730
|
const formattedAmount = numAmount.toFixed(2);
|
|
738
731
|
if (oldAmount === formattedAmount) {
|
|
739
732
|
return;
|
|
740
733
|
}
|
|
741
|
-
this.logInfo("[Checkout]
|
|
734
|
+
this.logInfo("[Checkout] 设置自定义支付金额:", {
|
|
742
735
|
oldAmount,
|
|
743
736
|
newAmount: formattedAmount
|
|
744
737
|
});
|
|
745
738
|
this.store.stateAmount = formattedAmount;
|
|
746
|
-
await this.core.effects.emit(
|
|
739
|
+
await this.core.effects.emit(`${this.name}:onStateAmountChanged`, {
|
|
747
740
|
oldAmount,
|
|
748
741
|
newAmount: formattedAmount,
|
|
749
742
|
timestamp: Date.now()
|
|
750
743
|
});
|
|
751
744
|
} catch (error) {
|
|
752
|
-
const errorMessage = error instanceof Error ? error.message : "
|
|
753
|
-
console.error("[Checkout]
|
|
745
|
+
const errorMessage = error instanceof Error ? error.message : "设置支付金额失败";
|
|
746
|
+
console.error("[Checkout] 设置自定义支付金额失败:", errorMessage);
|
|
754
747
|
await this.handleError(
|
|
755
748
|
new Error(errorMessage),
|
|
756
749
|
import_types.CheckoutErrorType.ValidationFailed
|
|
@@ -785,10 +778,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
785
778
|
*/
|
|
786
779
|
getCartSummary() {
|
|
787
780
|
if (!this.store.cartSummary || this.store.cartSummary.length === 0) {
|
|
788
|
-
console.warn("[Checkout]
|
|
781
|
+
console.warn("[Checkout] 没有可用的购物车小计数据");
|
|
789
782
|
return null;
|
|
790
783
|
}
|
|
791
|
-
this.logInfo("
|
|
784
|
+
this.logInfo("获取购物车小计数据:", {
|
|
792
785
|
itemCount: this.store.cartSummary.length,
|
|
793
786
|
items: this.store.cartSummary.map((item) => ({
|
|
794
787
|
key: item.key,
|
|
@@ -809,20 +802,20 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
809
802
|
async getPaymentMethodsAsync() {
|
|
810
803
|
if (this.store.paymentMethods && this.store.paymentMethods.length > 0) {
|
|
811
804
|
this.logInfo(
|
|
812
|
-
|
|
805
|
+
`使用缓存的支付方式数据,共 ${this.store.paymentMethods.length} 种`
|
|
813
806
|
);
|
|
814
807
|
return this.store.paymentMethods;
|
|
815
808
|
}
|
|
816
|
-
this.logInfo("store
|
|
809
|
+
this.logInfo("store 中无缓存,从 Payment 模块获取支付方式...");
|
|
817
810
|
try {
|
|
818
811
|
const methods = await this.payment.getPayMethodListAsync();
|
|
819
812
|
this.store.paymentMethods = methods;
|
|
820
813
|
this.logInfo(
|
|
821
|
-
|
|
814
|
+
`从 Payment 模块获取到 ${methods.length} 种支付方式,已更新缓存`
|
|
822
815
|
);
|
|
823
816
|
return methods;
|
|
824
817
|
} catch (error) {
|
|
825
|
-
this.logError("
|
|
818
|
+
this.logError("获取支付方式失败:", error);
|
|
826
819
|
return [];
|
|
827
820
|
}
|
|
828
821
|
}
|
|
@@ -841,7 +834,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
841
834
|
if (!this.store.currentOrder) {
|
|
842
835
|
throw (0, import_utils.createCheckoutError)(
|
|
843
836
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
844
|
-
"
|
|
837
|
+
"未找到当前订单,无法添加支付项"
|
|
845
838
|
);
|
|
846
839
|
}
|
|
847
840
|
const orderPaymentType = this.store.currentOrder.is_deposit === 1 ? "deposit" : "normal";
|
|
@@ -860,41 +853,41 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
860
853
|
this.store.currentOrder.uuid,
|
|
861
854
|
paymentItemWithType
|
|
862
855
|
);
|
|
863
|
-
this.logInfo("
|
|
856
|
+
this.logInfo("支付项添加成功");
|
|
864
857
|
await this.updateStateAmountToRemaining();
|
|
865
858
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
866
859
|
if (Number(remainingAmount) > 0) {
|
|
867
|
-
this.logInfo("
|
|
860
|
+
this.logInfo("订单金额还有待付的,同步 EFTPOS 支付");
|
|
868
861
|
const isEftposPayment = ((_a = paymentItem.type) == null ? void 0 : _a.toLowerCase()) === "eftpos" || ((_b = paymentItem.code) == null ? void 0 : _b.toUpperCase().includes("EFTPOS"));
|
|
869
862
|
const isCashPayment2 = paymentItem.code === "CASHMANUAL";
|
|
870
863
|
const isCustomePayment = paymentItem.type === "custom";
|
|
871
|
-
this.logInfo("EFTPOS
|
|
864
|
+
this.logInfo("EFTPOS 支付检查:", {
|
|
872
865
|
paymentCode: paymentItem.code,
|
|
873
866
|
paymentType: paymentItem.type,
|
|
874
867
|
isEftposPayment,
|
|
875
868
|
currentOrderSynced: this.store.isOrderSynced
|
|
876
869
|
});
|
|
877
870
|
if (isEftposPayment || isCashPayment2 || isCustomePayment) {
|
|
878
|
-
this.logInfo("
|
|
871
|
+
this.logInfo("检测到 EFTPOS 支付,立即同步订单到后端...");
|
|
879
872
|
try {
|
|
880
873
|
const syncResult = await this.syncOrderToBackendWithReturn(true);
|
|
881
|
-
this.logInfo("EFTPOS
|
|
874
|
+
this.logInfo("EFTPOS 支付后订单同步完成 (已标记为手动同步):", {
|
|
882
875
|
orderId: syncResult.orderId,
|
|
883
876
|
isOrderSynced: this.store.isOrderSynced,
|
|
884
877
|
backendResponse: syncResult.response
|
|
885
878
|
});
|
|
886
879
|
} catch (error) {
|
|
887
|
-
this.logError("EFTPOS
|
|
880
|
+
this.logError("EFTPOS 支付后订单同步失败:", error);
|
|
888
881
|
await this.handleError(
|
|
889
882
|
new Error(
|
|
890
|
-
`EFTPOS
|
|
883
|
+
`EFTPOS 支付后订单同步失败: ${error instanceof Error ? error.message : String(error)}`
|
|
891
884
|
),
|
|
892
885
|
import_types.CheckoutErrorType.OrderCreationFailed
|
|
893
886
|
);
|
|
894
887
|
}
|
|
895
888
|
}
|
|
896
889
|
}
|
|
897
|
-
this.core.effects.emit(
|
|
890
|
+
this.core.effects.emit(`${this.name}:onPaymentItemAdded`, {
|
|
898
891
|
orderUuid: this.store.currentOrder.uuid,
|
|
899
892
|
paymentMethodCode: paymentItem.code,
|
|
900
893
|
paymentMethodName: paymentItem.name,
|
|
@@ -902,7 +895,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
902
895
|
timestamp: Date.now()
|
|
903
896
|
});
|
|
904
897
|
} catch (error) {
|
|
905
|
-
this.logError("
|
|
898
|
+
this.logError("添加支付项失败:", error);
|
|
906
899
|
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
907
900
|
throw error;
|
|
908
901
|
}
|
|
@@ -921,10 +914,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
921
914
|
if (!this.store.currentOrder) {
|
|
922
915
|
throw (0, import_utils.createCheckoutError)(
|
|
923
916
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
924
|
-
"
|
|
917
|
+
"当前没有活跃订单,无法删除支付项"
|
|
925
918
|
);
|
|
926
919
|
}
|
|
927
|
-
this.logWarning("
|
|
920
|
+
this.logWarning("开始删除支付项:", {
|
|
928
921
|
orderUuid: this.store.currentOrder.uuid,
|
|
929
922
|
paymentUuid
|
|
930
923
|
});
|
|
@@ -937,10 +930,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
937
930
|
if (!paymentItem) {
|
|
938
931
|
throw (0, import_utils.createCheckoutError)(
|
|
939
932
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
940
|
-
|
|
933
|
+
`支付项不存在: ${paymentUuid}`
|
|
941
934
|
);
|
|
942
935
|
}
|
|
943
|
-
this.logInfo("
|
|
936
|
+
this.logInfo("找到要删除的支付项:", {
|
|
944
937
|
uuid: paymentItem.uuid,
|
|
945
938
|
code: paymentItem.code,
|
|
946
939
|
amount: paymentItem.amount,
|
|
@@ -950,7 +943,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
950
943
|
this.store.currentOrder.uuid,
|
|
951
944
|
paymentUuid
|
|
952
945
|
);
|
|
953
|
-
this.logInfo("Payment
|
|
946
|
+
this.logInfo("Payment支付项删除完成", paymentItem);
|
|
954
947
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
955
948
|
const isCurrentOrderReal = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
956
949
|
const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(
|
|
@@ -959,7 +952,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
959
952
|
if (updatedOrder) {
|
|
960
953
|
if (isCurrentOrderReal && (0, import_utils.isVirtualOrderId)(updatedOrder.order_id)) {
|
|
961
954
|
this.logWarning(
|
|
962
|
-
"[Checkout] deletePaymentItemAsync:
|
|
955
|
+
"[Checkout] deletePaymentItemAsync: 检测到订单ID回退,保护真实订单ID:",
|
|
963
956
|
{
|
|
964
957
|
currentRealId: currentOrderId,
|
|
965
958
|
retrievedVirtualId: updatedOrder.order_id
|
|
@@ -970,7 +963,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
970
963
|
this.store.currentOrder = updatedOrder;
|
|
971
964
|
}
|
|
972
965
|
await this.updateStateAmountToRemaining(false);
|
|
973
|
-
await this.core.effects.emit(
|
|
966
|
+
await this.core.effects.emit(`${this.name}:onPaymentStarted`, {
|
|
974
967
|
orderUuid: this.store.currentOrder.uuid,
|
|
975
968
|
paymentMethodCode: paymentItem.code,
|
|
976
969
|
amount: `-${paymentItem.amount}`,
|
|
@@ -978,7 +971,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
978
971
|
timestamp: Date.now()
|
|
979
972
|
});
|
|
980
973
|
} catch (error) {
|
|
981
|
-
this.logError("
|
|
974
|
+
this.logError("删除支付项失败:", error);
|
|
982
975
|
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
983
976
|
throw error;
|
|
984
977
|
}
|
|
@@ -998,7 +991,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
998
991
|
if (!this.store.currentOrder) {
|
|
999
992
|
throw (0, import_utils.createCheckoutError)(
|
|
1000
993
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
1001
|
-
"
|
|
994
|
+
"当前没有活跃订单,无法更新代金券支付项"
|
|
1002
995
|
);
|
|
1003
996
|
}
|
|
1004
997
|
const paymentItems = await this.payment.getPaymentItemsAsync(
|
|
@@ -1009,7 +1002,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1009
1002
|
const remainingValue = new import_decimal.default(remainingAmount);
|
|
1010
1003
|
const isOrderSynced = this.store.isOrderSynced;
|
|
1011
1004
|
if (remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0 && allPaymentItemsSynced) {
|
|
1012
|
-
this.logInfo("
|
|
1005
|
+
this.logInfo("订单已同步且支付完成,跳过清空代金券操作避免重复同步:", {
|
|
1013
1006
|
orderUuid: this.store.currentOrder.uuid,
|
|
1014
1007
|
orderId: this.store.currentOrder.order_id,
|
|
1015
1008
|
remainingAmount,
|
|
@@ -1019,7 +1012,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1019
1012
|
});
|
|
1020
1013
|
return;
|
|
1021
1014
|
}
|
|
1022
|
-
this.logInfo("
|
|
1015
|
+
this.logInfo("开始批量更新代金券支付项:", {
|
|
1023
1016
|
voucherPaymentItems
|
|
1024
1017
|
});
|
|
1025
1018
|
const orderPaymentType = this.store.currentOrder.is_deposit === 1 ? "deposit" : "normal";
|
|
@@ -1027,7 +1020,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1027
1020
|
if (!item.voucher_id) {
|
|
1028
1021
|
throw (0, import_utils.createCheckoutError)(
|
|
1029
1022
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
1030
|
-
|
|
1023
|
+
`代金券支付项缺少 voucher_id: ${JSON.stringify(item)}`
|
|
1031
1024
|
);
|
|
1032
1025
|
}
|
|
1033
1026
|
const metadata = {
|
|
@@ -1053,7 +1046,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1053
1046
|
if (updatedOrder) {
|
|
1054
1047
|
if (isCurrentOrderReal && (0, import_utils.isVirtualOrderId)(updatedOrder.order_id)) {
|
|
1055
1048
|
this.logWarning(
|
|
1056
|
-
"updateVoucherPaymentItemsAsync:
|
|
1049
|
+
"updateVoucherPaymentItemsAsync: 检测到订单ID回退,保护真实订单ID:",
|
|
1057
1050
|
{
|
|
1058
1051
|
currentRealId: currentOrderId,
|
|
1059
1052
|
retrievedVirtualId: updatedOrder.order_id
|
|
@@ -1064,15 +1057,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1064
1057
|
this.store.currentOrder = updatedOrder;
|
|
1065
1058
|
}
|
|
1066
1059
|
await this.updateStateAmountToRemaining(false);
|
|
1067
|
-
await this.core.effects.emit(
|
|
1060
|
+
await this.core.effects.emit(`${this.name}:onPaymentStarted`, {
|
|
1068
1061
|
orderUuid: this.store.currentOrder.uuid,
|
|
1069
1062
|
paymentMethodCode: "VOUCHER_BATCH",
|
|
1070
1063
|
amount: voucherPaymentItems.reduce((sum, item) => sum + parseFloat(String(item.amount)), 0).toFixed(2),
|
|
1071
1064
|
timestamp: Date.now()
|
|
1072
1065
|
});
|
|
1073
|
-
this.logInfo("
|
|
1066
|
+
this.logInfo("代金券支付项批量更新成功");
|
|
1074
1067
|
} catch (error) {
|
|
1075
|
-
this.logError("[Checkout]
|
|
1068
|
+
this.logError("[Checkout] 批量更新代金券支付项失败:", error);
|
|
1076
1069
|
await this.handleError(error, import_types.CheckoutErrorType.PaymentFailed);
|
|
1077
1070
|
throw error;
|
|
1078
1071
|
}
|
|
@@ -1090,19 +1083,19 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1090
1083
|
if (isDeposit !== 0 && isDeposit !== 1) {
|
|
1091
1084
|
throw (0, import_utils.createCheckoutError)(
|
|
1092
1085
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
1093
|
-
"isDeposit
|
|
1086
|
+
"isDeposit 参数只能是 0(全款订单)或 1(定金订单)"
|
|
1094
1087
|
);
|
|
1095
1088
|
}
|
|
1096
1089
|
if (!this.store.currentOrder) {
|
|
1097
1090
|
throw (0, import_utils.createCheckoutError)(
|
|
1098
1091
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
1099
|
-
"
|
|
1092
|
+
"未找到当前订单,无法修改定金状态"
|
|
1100
1093
|
);
|
|
1101
1094
|
}
|
|
1102
1095
|
const newDepositValue = isDeposit;
|
|
1103
1096
|
const oldDepositValue = this.store.currentOrder.is_deposit;
|
|
1104
1097
|
if (oldDepositValue === newDepositValue) {
|
|
1105
|
-
console.log("[Checkout]
|
|
1098
|
+
console.log("[Checkout] 定金状态无变化,跳过更新");
|
|
1106
1099
|
return;
|
|
1107
1100
|
}
|
|
1108
1101
|
let deposit_amount = this.store.currentOrder.deposit_amount || "0.00";
|
|
@@ -1125,16 +1118,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1125
1118
|
this.store.localOrderData.is_deposit = newDepositValue;
|
|
1126
1119
|
}
|
|
1127
1120
|
this.updateStateAmountToRemaining(false);
|
|
1128
|
-
await this.core.effects.emit(
|
|
1121
|
+
await this.core.effects.emit(`${this.name}:onOrderCreated`, {
|
|
1129
1122
|
order: this.store.currentOrder,
|
|
1130
1123
|
timestamp: Date.now()
|
|
1131
1124
|
});
|
|
1132
|
-
this.logInfo("
|
|
1125
|
+
this.logInfo("订单定金状态更新成功:", {
|
|
1133
1126
|
isDeposit: newDepositValue,
|
|
1134
1127
|
depositAmount: this.store.currentOrder.deposit_amount
|
|
1135
1128
|
});
|
|
1136
1129
|
} catch (error) {
|
|
1137
|
-
this.logError("
|
|
1130
|
+
this.logError("更新订单定金状态失败:", error);
|
|
1138
1131
|
await this.handleError(
|
|
1139
1132
|
error,
|
|
1140
1133
|
import_types.CheckoutErrorType.ValidationFailed
|
|
@@ -1164,25 +1157,25 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1164
1157
|
if (depositValue.isNaN() || depositValue.lt(0)) {
|
|
1165
1158
|
throw (0, import_utils.createCheckoutError)(
|
|
1166
1159
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
1167
|
-
|
|
1160
|
+
`无效的定金金额格式: ${depositAmount}`
|
|
1168
1161
|
);
|
|
1169
1162
|
}
|
|
1170
1163
|
if (!this.store.currentOrder) {
|
|
1171
1164
|
throw (0, import_utils.createCheckoutError)(
|
|
1172
1165
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
1173
|
-
"
|
|
1166
|
+
"未找到当前订单,无法设置定金金额"
|
|
1174
1167
|
);
|
|
1175
1168
|
}
|
|
1176
1169
|
const formattedDepositAmount = depositValue.toFixed(2);
|
|
1177
1170
|
const oldDepositAmount = this.store.currentOrder.deposit_amount || "0.00";
|
|
1178
1171
|
if (formattedDepositAmount === oldDepositAmount) {
|
|
1179
|
-
this.logInfo("
|
|
1172
|
+
this.logInfo("定金金额无变化,跳过更新:", {
|
|
1180
1173
|
currentAmount: oldDepositAmount,
|
|
1181
1174
|
newAmount: formattedDepositAmount
|
|
1182
1175
|
});
|
|
1183
1176
|
return;
|
|
1184
1177
|
}
|
|
1185
|
-
this.logInfo("
|
|
1178
|
+
this.logInfo("开始设置订单定金金额:", {
|
|
1186
1179
|
orderUuid: this.store.currentOrder.uuid,
|
|
1187
1180
|
orderId: this.store.currentOrder.order_id,
|
|
1188
1181
|
oldDepositAmount,
|
|
@@ -1194,10 +1187,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1194
1187
|
};
|
|
1195
1188
|
if (depositValue.gt(0) && this.store.currentOrder.is_deposit !== 1) {
|
|
1196
1189
|
updateParams.is_deposit = 1;
|
|
1197
|
-
this.logInfo("
|
|
1190
|
+
this.logInfo("定金金额大于0,自动设置为定金订单");
|
|
1198
1191
|
} else if (depositValue.eq(0) && this.store.currentOrder.is_deposit === 1) {
|
|
1199
1192
|
updateParams.is_deposit = 0;
|
|
1200
|
-
this.logInfo("
|
|
1193
|
+
this.logInfo("定金金额为0,自动设置为全款订单");
|
|
1201
1194
|
}
|
|
1202
1195
|
await this.payment.updateOrderAsync(
|
|
1203
1196
|
this.store.currentOrder.uuid,
|
|
@@ -1216,11 +1209,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1216
1209
|
}
|
|
1217
1210
|
}
|
|
1218
1211
|
this.updateStateAmountToRemaining(false);
|
|
1219
|
-
await this.core.effects.emit(
|
|
1212
|
+
await this.core.effects.emit(`${this.name}:onOrderCreated`, {
|
|
1220
1213
|
order: this.store.currentOrder,
|
|
1221
1214
|
timestamp: Date.now()
|
|
1222
1215
|
});
|
|
1223
|
-
this.logInfo("
|
|
1216
|
+
this.logInfo("订单定金金额设置成功:", {
|
|
1224
1217
|
orderUuid: this.store.currentOrder.uuid,
|
|
1225
1218
|
orderId: this.store.currentOrder.order_id,
|
|
1226
1219
|
oldDepositAmount,
|
|
@@ -1229,7 +1222,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1229
1222
|
totalAmount: this.store.currentOrder.total_amount
|
|
1230
1223
|
});
|
|
1231
1224
|
} catch (error) {
|
|
1232
|
-
this.logError("
|
|
1225
|
+
this.logError("设置订单定金金额失败:", error);
|
|
1233
1226
|
await this.handleError(
|
|
1234
1227
|
error,
|
|
1235
1228
|
import_types.CheckoutErrorType.ValidationFailed
|
|
@@ -1256,22 +1249,22 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1256
1249
|
if (!this.store.currentOrder) {
|
|
1257
1250
|
return {
|
|
1258
1251
|
success: false,
|
|
1259
|
-
message: "
|
|
1252
|
+
message: "当前没有活跃订单,无法同步"
|
|
1260
1253
|
};
|
|
1261
1254
|
}
|
|
1262
1255
|
const orderUuid = this.store.currentOrder.uuid;
|
|
1263
1256
|
const oldOrderId = this.store.currentOrder.order_id;
|
|
1264
1257
|
if (this.store.isOrderSynced) {
|
|
1265
|
-
this.logInfo("
|
|
1258
|
+
this.logInfo("订单已同步过,将执行更新操作");
|
|
1266
1259
|
}
|
|
1267
|
-
this.logInfo("
|
|
1260
|
+
this.logInfo("开始手动同步订单到后端:", {
|
|
1268
1261
|
orderUuid,
|
|
1269
1262
|
orderId: oldOrderId,
|
|
1270
1263
|
totalAmount: this.store.currentOrder.total_amount,
|
|
1271
1264
|
remainingAmount: await this.calculateRemainingAmountAsync()
|
|
1272
1265
|
});
|
|
1273
1266
|
const syncResult = await this.syncOrderToBackendWithReturn(true);
|
|
1274
|
-
this.logInfo("
|
|
1267
|
+
this.logInfo("手动同步订单完成:", {
|
|
1275
1268
|
orderUuid,
|
|
1276
1269
|
syncResult,
|
|
1277
1270
|
oldOrderId,
|
|
@@ -1281,11 +1274,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1281
1274
|
const finalOrderId = this.store.currentOrder.order_id;
|
|
1282
1275
|
const finalIsVirtual = (0, import_utils.isVirtualOrderId)(finalOrderId);
|
|
1283
1276
|
if (finalIsVirtual) {
|
|
1284
|
-
this.logError("
|
|
1277
|
+
this.logError("严重警告:手动同步完成后订单ID仍为虚拟ID!");
|
|
1285
1278
|
}
|
|
1286
1279
|
if (syncResult.orderId !== finalOrderId) {
|
|
1287
1280
|
this.logError(
|
|
1288
|
-
"[Checkout]
|
|
1281
|
+
"[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!"
|
|
1289
1282
|
);
|
|
1290
1283
|
}
|
|
1291
1284
|
let newRes = {
|
|
@@ -1295,11 +1288,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1295
1288
|
await this.updateStateAmountToRemaining(false);
|
|
1296
1289
|
return newRes;
|
|
1297
1290
|
} catch (error) {
|
|
1298
|
-
this.logError("
|
|
1299
|
-
const errorMessage = error instanceof Error ? error.message : "
|
|
1291
|
+
this.logError("手动同步订单失败:", error);
|
|
1292
|
+
const errorMessage = error instanceof Error ? error.message : "同步失败";
|
|
1300
1293
|
return {
|
|
1301
1294
|
success: false,
|
|
1302
|
-
message:
|
|
1295
|
+
message: `订单同步失败: ${errorMessage}`,
|
|
1303
1296
|
orderUuid: (_e = this.store.currentOrder) == null ? void 0 : _e.uuid
|
|
1304
1297
|
};
|
|
1305
1298
|
}
|
|
@@ -1311,7 +1304,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1311
1304
|
*/
|
|
1312
1305
|
getOrderNote() {
|
|
1313
1306
|
if (!this.store.localOrderData) {
|
|
1314
|
-
console.log("[Checkout]
|
|
1307
|
+
console.log("[Checkout] 没有本地订单数据,无法获取备注");
|
|
1315
1308
|
return "";
|
|
1316
1309
|
}
|
|
1317
1310
|
return this.store.localOrderData.shop_note || "";
|
|
@@ -1334,11 +1327,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1334
1327
|
*/
|
|
1335
1328
|
isCurrentOrderSynced() {
|
|
1336
1329
|
if (!this.store.currentOrder) {
|
|
1337
|
-
console.log("[Checkout]
|
|
1330
|
+
console.log("[Checkout] 没有当前订单,同步状态为false");
|
|
1338
1331
|
return false;
|
|
1339
1332
|
}
|
|
1340
1333
|
const syncStatus = this.store.isOrderSynced;
|
|
1341
|
-
console.log("[Checkout]
|
|
1334
|
+
console.log("[Checkout] 当前订单同步状态:", {
|
|
1342
1335
|
orderUuid: this.store.currentOrder.uuid,
|
|
1343
1336
|
orderId: this.store.currentOrder.order_id,
|
|
1344
1337
|
isOrderSynced: syncStatus
|
|
@@ -1356,7 +1349,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1356
1349
|
async cancelCurrentOrderAsync(cancelReason) {
|
|
1357
1350
|
var _a, _b;
|
|
1358
1351
|
try {
|
|
1359
|
-
this.logInfo("
|
|
1352
|
+
this.logInfo("开始取消当前本地订单:", {
|
|
1360
1353
|
hasCurrentOrder: !!this.store.currentOrder,
|
|
1361
1354
|
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid,
|
|
1362
1355
|
orderId: (_b = this.store.currentOrder) == null ? void 0 : _b.order_id,
|
|
@@ -1364,34 +1357,34 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1364
1357
|
cancelReason
|
|
1365
1358
|
});
|
|
1366
1359
|
if (!this.store.currentOrder) {
|
|
1367
|
-
this.logInfo("
|
|
1360
|
+
this.logInfo("没有当前订单,无需取消");
|
|
1368
1361
|
return {
|
|
1369
1362
|
success: false,
|
|
1370
|
-
message: "
|
|
1363
|
+
message: "没有当前订单可取消"
|
|
1371
1364
|
};
|
|
1372
1365
|
}
|
|
1373
1366
|
const currentOrderUuid = this.store.currentOrder.uuid;
|
|
1374
1367
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1375
1368
|
const isOrderSynced = this.store.isOrderSynced;
|
|
1376
1369
|
if (isOrderSynced) {
|
|
1377
|
-
this.logInfo("
|
|
1370
|
+
this.logInfo("订单已同步到后端,不能取消:", {
|
|
1378
1371
|
orderId: currentOrderId,
|
|
1379
1372
|
orderUuid: currentOrderUuid
|
|
1380
1373
|
});
|
|
1381
1374
|
return {
|
|
1382
1375
|
success: false,
|
|
1383
|
-
message: "
|
|
1376
|
+
message: "订单已同步到后端,无法取消",
|
|
1384
1377
|
orderId: currentOrderId
|
|
1385
1378
|
};
|
|
1386
1379
|
}
|
|
1387
1380
|
try {
|
|
1388
|
-
this.logInfo("
|
|
1381
|
+
this.logInfo("删除本地订单数据");
|
|
1389
1382
|
await this.payment.deletePaymentOrderAsync(currentOrderUuid);
|
|
1390
|
-
this.logInfo("
|
|
1383
|
+
this.logInfo("本地订单数据删除成功");
|
|
1391
1384
|
} catch (error) {
|
|
1392
|
-
this.logWarning("
|
|
1385
|
+
this.logWarning("删除本地订单数据失败,但继续执行:", error);
|
|
1393
1386
|
}
|
|
1394
|
-
this.logInfo("
|
|
1387
|
+
this.logInfo("清理订单相关状态");
|
|
1395
1388
|
this.store.currentOrder = void 0;
|
|
1396
1389
|
this.store.localOrderData = void 0;
|
|
1397
1390
|
this.store.stateAmount = "0.00";
|
|
@@ -1399,8 +1392,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1399
1392
|
this.store.isOrderSynced = false;
|
|
1400
1393
|
this.store.currentCustomer = void 0;
|
|
1401
1394
|
this.payment.wallet.clearAllCache();
|
|
1402
|
-
this.logInfo("
|
|
1403
|
-
await this.core.effects.emit(
|
|
1395
|
+
this.logInfo("订单状态清理完成,currentOrder已释放");
|
|
1396
|
+
await this.core.effects.emit(`${this.name}:onOrderCancelled`, {
|
|
1404
1397
|
orderUuid: currentOrderUuid,
|
|
1405
1398
|
orderId: currentOrderId,
|
|
1406
1399
|
cancelReason,
|
|
@@ -1408,22 +1401,22 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1408
1401
|
// 只有未同步订单可以被取消
|
|
1409
1402
|
timestamp: Date.now()
|
|
1410
1403
|
});
|
|
1411
|
-
this.logInfo("
|
|
1404
|
+
this.logInfo("本地订单取消完成:", {
|
|
1412
1405
|
orderUuid: currentOrderUuid,
|
|
1413
1406
|
orderId: currentOrderId,
|
|
1414
1407
|
cancelReason
|
|
1415
1408
|
});
|
|
1416
1409
|
return {
|
|
1417
1410
|
success: true,
|
|
1418
|
-
message: "
|
|
1411
|
+
message: "本地订单已成功取消",
|
|
1419
1412
|
orderId: currentOrderId
|
|
1420
1413
|
};
|
|
1421
1414
|
} catch (error) {
|
|
1422
|
-
this.logError("
|
|
1423
|
-
const errorMessage = error instanceof Error ? error.message : "
|
|
1415
|
+
this.logError("取消本地订单失败:", error);
|
|
1416
|
+
const errorMessage = error instanceof Error ? error.message : "未知错误";
|
|
1424
1417
|
return {
|
|
1425
1418
|
success: false,
|
|
1426
|
-
message:
|
|
1419
|
+
message: `取消订单失败: ${errorMessage}`
|
|
1427
1420
|
};
|
|
1428
1421
|
}
|
|
1429
1422
|
}
|
|
@@ -1439,12 +1432,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1439
1432
|
if (!this.store.currentOrder) {
|
|
1440
1433
|
return {
|
|
1441
1434
|
success: false,
|
|
1442
|
-
message: "
|
|
1435
|
+
message: "当前没有活跃订单,无法保存"
|
|
1443
1436
|
};
|
|
1444
1437
|
}
|
|
1445
1438
|
const orderUuid = this.store.currentOrder.uuid;
|
|
1446
1439
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
1447
|
-
this.logInfo("
|
|
1440
|
+
this.logInfo("开始保存订单并稍后支付:", {
|
|
1448
1441
|
orderUuid,
|
|
1449
1442
|
orderId: currentOrderId,
|
|
1450
1443
|
totalAmount: this.store.currentOrder.total_amount
|
|
@@ -1456,7 +1449,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1456
1449
|
true,
|
|
1457
1450
|
allPaymentItems
|
|
1458
1451
|
);
|
|
1459
|
-
this.logInfo("
|
|
1452
|
+
this.logInfo("保存订单完成:", {
|
|
1460
1453
|
orderUuid,
|
|
1461
1454
|
oldOrderId: currentOrderId,
|
|
1462
1455
|
syncResult,
|
|
@@ -1466,17 +1459,17 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1466
1459
|
});
|
|
1467
1460
|
return {
|
|
1468
1461
|
success: true,
|
|
1469
|
-
message: "
|
|
1462
|
+
message: "订单保存成功,可稍后继续支付",
|
|
1470
1463
|
orderId: syncResult.orderId,
|
|
1471
1464
|
orderUuid,
|
|
1472
1465
|
response: syncResult.response
|
|
1473
1466
|
};
|
|
1474
1467
|
} catch (error) {
|
|
1475
|
-
this.logError("
|
|
1476
|
-
const errorMessage = error instanceof Error ? error.message : "
|
|
1468
|
+
this.logError("保存订单失败:", error);
|
|
1469
|
+
const errorMessage = error instanceof Error ? error.message : "保存失败";
|
|
1477
1470
|
return {
|
|
1478
1471
|
success: false,
|
|
1479
|
-
message:
|
|
1472
|
+
message: `订单保存失败: ${errorMessage}`,
|
|
1480
1473
|
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid
|
|
1481
1474
|
};
|
|
1482
1475
|
}
|
|
@@ -1492,10 +1485,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1492
1485
|
if (!this.store.localOrderData) {
|
|
1493
1486
|
throw (0, import_utils.createCheckoutError)(
|
|
1494
1487
|
import_types.CheckoutErrorType.ValidationFailed,
|
|
1495
|
-
"
|
|
1488
|
+
"没有本地订单数据,无法更新备注"
|
|
1496
1489
|
);
|
|
1497
1490
|
}
|
|
1498
|
-
console.log("[Checkout]
|
|
1491
|
+
console.log("[Checkout] 更新订单备注:", {
|
|
1499
1492
|
orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid,
|
|
1500
1493
|
oldNote: this.store.localOrderData.shop_note,
|
|
1501
1494
|
newNote: note
|
|
@@ -1508,27 +1501,27 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1508
1501
|
this.store.currentOrder.uuid
|
|
1509
1502
|
);
|
|
1510
1503
|
if (orderInPayment && orderInPayment.note !== void 0) {
|
|
1511
|
-
console.log("[Checkout]
|
|
1504
|
+
console.log("[Checkout] 同步备注到Payment模块的订单数据中");
|
|
1512
1505
|
}
|
|
1513
1506
|
} catch (syncError) {
|
|
1514
1507
|
console.warn(
|
|
1515
|
-
"[Checkout]
|
|
1508
|
+
"[Checkout] 同步备注到Payment模块失败,但本地更新成功:",
|
|
1516
1509
|
syncError
|
|
1517
1510
|
);
|
|
1518
1511
|
}
|
|
1519
1512
|
}
|
|
1520
|
-
await this.core.effects.emit(
|
|
1513
|
+
await this.core.effects.emit(`${this.name}:onOrderNoteChanged`, {
|
|
1521
1514
|
orderUuid: (_b = this.store.currentOrder) == null ? void 0 : _b.uuid,
|
|
1522
1515
|
oldNote,
|
|
1523
1516
|
newNote: note,
|
|
1524
1517
|
timestamp: Date.now()
|
|
1525
1518
|
});
|
|
1526
|
-
console.log("[Checkout]
|
|
1519
|
+
console.log("[Checkout] 订单备注更新成功:", {
|
|
1527
1520
|
oldNote,
|
|
1528
1521
|
newNote: note
|
|
1529
1522
|
});
|
|
1530
1523
|
} catch (error) {
|
|
1531
|
-
console.error("[Checkout]
|
|
1524
|
+
console.error("[Checkout] 更新订单备注失败:", error);
|
|
1532
1525
|
await this.handleError(
|
|
1533
1526
|
error,
|
|
1534
1527
|
import_types.CheckoutErrorType.ValidationFailed
|
|
@@ -1542,12 +1535,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1542
1535
|
async handleError(error, type) {
|
|
1543
1536
|
const checkoutError = error instanceof Error && "type" in error ? error : (0, import_utils.createCheckoutError)(type, error.message, error);
|
|
1544
1537
|
this.store.lastError = checkoutError;
|
|
1545
|
-
await this.core.effects.emit(
|
|
1538
|
+
await this.core.effects.emit(`${this.name}:onError`, {
|
|
1546
1539
|
error: checkoutError,
|
|
1547
1540
|
context: {},
|
|
1548
1541
|
timestamp: Date.now()
|
|
1549
1542
|
});
|
|
1550
|
-
console.error("[Checkout]
|
|
1543
|
+
console.error("[Checkout] 错误:", checkoutError);
|
|
1551
1544
|
}
|
|
1552
1545
|
/**
|
|
1553
1546
|
* 处理支付成功
|
|
@@ -1555,7 +1548,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1555
1548
|
async handlePaymentSuccess(data) {
|
|
1556
1549
|
var _a;
|
|
1557
1550
|
await this.updateStateAmountToRemaining();
|
|
1558
|
-
await this.core.effects.emit(
|
|
1551
|
+
await this.core.effects.emit(`${this.name}:onPaymentSuccess`, {
|
|
1559
1552
|
orderUuid: data.orderUuid,
|
|
1560
1553
|
paymentMethodCode: "",
|
|
1561
1554
|
amount: ((_a = this.store.currentOrder) == null ? void 0 : _a.total_amount) || "0",
|
|
@@ -1570,13 +1563,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1570
1563
|
var _a;
|
|
1571
1564
|
const error = (0, import_utils.createCheckoutError)(
|
|
1572
1565
|
import_types.CheckoutErrorType.PaymentFailed,
|
|
1573
|
-
data.error || "
|
|
1566
|
+
data.error || "支付同步失败"
|
|
1574
1567
|
);
|
|
1575
1568
|
await this.handleError(
|
|
1576
1569
|
error instanceof Error ? error : new Error(String(error)),
|
|
1577
1570
|
import_types.CheckoutErrorType.PaymentFailed
|
|
1578
1571
|
);
|
|
1579
|
-
await this.core.effects.emit(
|
|
1572
|
+
await this.core.effects.emit(`${this.name}:onPaymentFailed`, {
|
|
1580
1573
|
orderUuid: data.orderUuid,
|
|
1581
1574
|
paymentMethodCode: "",
|
|
1582
1575
|
amount: ((_a = this.store.currentOrder) == null ? void 0 : _a.total_amount) || "0",
|
|
@@ -1644,7 +1637,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1644
1637
|
});
|
|
1645
1638
|
return processedPaymentItem;
|
|
1646
1639
|
} catch (error) {
|
|
1647
|
-
this.logError("
|
|
1640
|
+
this.logError("处理现金支付项时出错:", error);
|
|
1648
1641
|
return paymentItem;
|
|
1649
1642
|
}
|
|
1650
1643
|
}
|
|
@@ -1653,12 +1646,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1653
1646
|
*/
|
|
1654
1647
|
async preloadPaymentMethods() {
|
|
1655
1648
|
try {
|
|
1656
|
-
console.log("[Checkout]
|
|
1649
|
+
console.log("[Checkout] 预加载支付方式...");
|
|
1657
1650
|
const methods = await this.payment.getPayMethodListAsync();
|
|
1658
1651
|
this.store.paymentMethods = methods;
|
|
1659
|
-
console.log(`[Checkout]
|
|
1652
|
+
console.log(`[Checkout] 预加载完成,共 ${methods.length} 种支付方式`);
|
|
1660
1653
|
} catch (error) {
|
|
1661
|
-
console.error("[Checkout]
|
|
1654
|
+
console.error("[Checkout] 预加载支付方式失败:", error);
|
|
1662
1655
|
this.store.paymentMethods = [];
|
|
1663
1656
|
}
|
|
1664
1657
|
}
|
|
@@ -1675,15 +1668,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1675
1668
|
const retentionDays = cleanupConfig.retentionDays || 7;
|
|
1676
1669
|
const maxOrdersToDelete = cleanupConfig.maxOrdersToDelete || 100;
|
|
1677
1670
|
if (!isCleanupEnabled) {
|
|
1678
|
-
console.log("[Checkout]
|
|
1671
|
+
console.log("[Checkout] 订单数据清理功能已禁用");
|
|
1679
1672
|
return;
|
|
1680
1673
|
}
|
|
1681
1674
|
console.log(
|
|
1682
|
-
`[Checkout]
|
|
1675
|
+
`[Checkout] 开始清理过期订单数据(保留 ${retentionDays} 天内的数据)...`
|
|
1683
1676
|
);
|
|
1684
1677
|
const allOrders = await this.payment.getOrderListAsync();
|
|
1685
1678
|
if (!allOrders || allOrders.length === 0) {
|
|
1686
|
-
console.log("[Checkout]
|
|
1679
|
+
console.log("[Checkout] 没有找到需要清理的订单数据");
|
|
1687
1680
|
return;
|
|
1688
1681
|
}
|
|
1689
1682
|
const thresholdDate = /* @__PURE__ */ new Date();
|
|
@@ -1718,7 +1711,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1718
1711
|
});
|
|
1719
1712
|
}
|
|
1720
1713
|
} catch (error) {
|
|
1721
|
-
console.warn(`[Checkout]
|
|
1714
|
+
console.warn(`[Checkout] 处理订单 ${order.uuid} 时出错:`, error);
|
|
1722
1715
|
continue;
|
|
1723
1716
|
}
|
|
1724
1717
|
}
|
|
@@ -1731,10 +1724,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1731
1724
|
await this.payment.deletePaymentOrderAsync(orderInfo.uuid);
|
|
1732
1725
|
deletedCount++;
|
|
1733
1726
|
console.log(
|
|
1734
|
-
`[Checkout]
|
|
1727
|
+
`[Checkout] 已删除过期订单: ${orderInfo.orderId} (${orderInfo.daysSinceCreated} 天前创建)`
|
|
1735
1728
|
);
|
|
1736
1729
|
} catch (error) {
|
|
1737
|
-
console.error(`[Checkout]
|
|
1730
|
+
console.error(`[Checkout] 删除订单 ${orderInfo.uuid} 失败:`, error);
|
|
1738
1731
|
}
|
|
1739
1732
|
}
|
|
1740
1733
|
const summary = {
|
|
@@ -1750,16 +1743,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1750
1743
|
this.logInfo("Expired orders cleanup completed", summary);
|
|
1751
1744
|
if (ordersToDelete.length > maxOrdersToDelete) {
|
|
1752
1745
|
console.log(
|
|
1753
|
-
`[Checkout]
|
|
1746
|
+
`[Checkout] 过期订单清理完成: 总计 ${allOrders.length} 个订单,发现 ${ordersToDelete.length} 个过期已同步订单,删除了 ${deletedCount} 个(限制为 ${maxOrdersToDelete} 个)`
|
|
1754
1747
|
);
|
|
1755
1748
|
} else {
|
|
1756
1749
|
console.log(
|
|
1757
|
-
`[Checkout]
|
|
1750
|
+
`[Checkout] 过期订单清理完成: 总计 ${allOrders.length} 个订单,删除了 ${deletedCount} 个过期已同步订单`
|
|
1758
1751
|
);
|
|
1759
1752
|
}
|
|
1760
1753
|
} catch (error) {
|
|
1761
1754
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1762
|
-
console.error("[Checkout]
|
|
1755
|
+
console.error("[Checkout] 清理过期订单数据失败:", error);
|
|
1763
1756
|
this.logError("Expired orders cleanup failed", { error: errorMessage });
|
|
1764
1757
|
}
|
|
1765
1758
|
}
|
|
@@ -1768,7 +1761,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1768
1761
|
*/
|
|
1769
1762
|
async calculatePaidAmountAsync() {
|
|
1770
1763
|
if (!this.store.currentOrder) {
|
|
1771
|
-
this.logWarning("[Checkout] calculatePaidAmountAsync:
|
|
1764
|
+
this.logWarning("[Checkout] calculatePaidAmountAsync: 没有当前订单");
|
|
1772
1765
|
return "0.00";
|
|
1773
1766
|
}
|
|
1774
1767
|
try {
|
|
@@ -1781,11 +1774,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1781
1774
|
const amount = new import_decimal.default(payment.amount || "0");
|
|
1782
1775
|
const roundingAmount = new import_decimal.default(payment.rounding_amount || "0");
|
|
1783
1776
|
const effectiveAmount = amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
|
|
1784
|
-
console.log(`[Checkout]
|
|
1777
|
+
console.log(`[Checkout] 计算支付项: ${payment.code}`, {
|
|
1785
1778
|
originalAmount: amount.toFixed(2),
|
|
1786
1779
|
roundingAmount: roundingAmount.toFixed(2),
|
|
1787
1780
|
effectiveAmount: effectiveAmount.toFixed(2),
|
|
1788
|
-
description: !roundingAmount.isZero() ?
|
|
1781
|
+
description: !roundingAmount.isZero() ? `抹零金额 ${roundingAmount.toFixed(2)} 元,有效支付增加 ${roundingAmount.abs().toFixed(2)} 元` : "无抹零",
|
|
1789
1782
|
// Decimal 精度验证
|
|
1790
1783
|
preciseCalculationValues: {
|
|
1791
1784
|
amount: amount.toString(),
|
|
@@ -1796,10 +1789,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1796
1789
|
return sum.add(effectiveAmount);
|
|
1797
1790
|
}, new import_decimal.default(0));
|
|
1798
1791
|
const result = paidAmount.toFixed(2);
|
|
1799
|
-
this.logInfo("calculatePaidAmountAsync:
|
|
1792
|
+
this.logInfo("calculatePaidAmountAsync: 计算结果 =", result);
|
|
1800
1793
|
return result;
|
|
1801
1794
|
} catch (error) {
|
|
1802
|
-
this.logError("calculatePaidAmountAsync
|
|
1795
|
+
this.logError("calculatePaidAmountAsync 失败:", error);
|
|
1803
1796
|
return "0.00";
|
|
1804
1797
|
}
|
|
1805
1798
|
}
|
|
@@ -1808,7 +1801,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1808
1801
|
*/
|
|
1809
1802
|
async calculateRemainingAmountAsync() {
|
|
1810
1803
|
if (!this.store.currentOrder) {
|
|
1811
|
-
this.logWarning("calculateRemainingAmountAsync:
|
|
1804
|
+
this.logWarning("calculateRemainingAmountAsync: 没有当前订单");
|
|
1812
1805
|
return "0.00";
|
|
1813
1806
|
}
|
|
1814
1807
|
let totalAmount = new import_decimal.default(this.store.currentOrder.total_amount || "0");
|
|
@@ -1822,7 +1815,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1822
1815
|
const paidAmount = new import_decimal.default(paidAmountStr);
|
|
1823
1816
|
const remainingAmount = totalAmount.sub(paidAmount);
|
|
1824
1817
|
const result = import_decimal.default.max(0, remainingAmount).toFixed(2);
|
|
1825
|
-
this.logInfo("calculateRemainingAmountAsync:
|
|
1818
|
+
this.logInfo("calculateRemainingAmountAsync: 计算=", result);
|
|
1826
1819
|
return result;
|
|
1827
1820
|
}
|
|
1828
1821
|
/**
|
|
@@ -1830,7 +1823,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1830
1823
|
*/
|
|
1831
1824
|
async calculateRemainingTotalAmountAsync() {
|
|
1832
1825
|
if (!this.store.currentOrder) {
|
|
1833
|
-
this.logWarning("calculateRemainingTotalAmountAsync:
|
|
1826
|
+
this.logWarning("calculateRemainingTotalAmountAsync: 没有当前订单");
|
|
1834
1827
|
return "0.00";
|
|
1835
1828
|
}
|
|
1836
1829
|
const totalAmount = new import_decimal.default(this.store.currentOrder.total_amount || "0");
|
|
@@ -1838,7 +1831,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1838
1831
|
const paidAmount = new import_decimal.default(paidAmountStr);
|
|
1839
1832
|
const remainingAmount = totalAmount.sub(paidAmount);
|
|
1840
1833
|
const result = import_decimal.default.max(0, remainingAmount).toFixed(2);
|
|
1841
|
-
this.logInfo("calculateRemainingTotalAmountAsync:
|
|
1834
|
+
this.logInfo("calculateRemainingTotalAmountAsync: 计算=", result);
|
|
1842
1835
|
return result;
|
|
1843
1836
|
}
|
|
1844
1837
|
/**
|
|
@@ -1851,24 +1844,24 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1851
1844
|
const currentBalanceDueAmount = this.store.balanceDueAmount;
|
|
1852
1845
|
if (remainingAmount !== currentBalanceDueAmount) {
|
|
1853
1846
|
this.store.balanceDueAmount = remainingAmount;
|
|
1854
|
-
await this.core.effects.emit(
|
|
1847
|
+
await this.core.effects.emit(`${this.name}:onBalanceDueAmountChanged`, {
|
|
1855
1848
|
oldAmount: currentBalanceDueAmount,
|
|
1856
1849
|
newAmount: remainingAmount,
|
|
1857
1850
|
timestamp: Date.now(),
|
|
1858
1851
|
totalAmount: remainingTotalAmount
|
|
1859
1852
|
});
|
|
1860
|
-
this.logInfo("balanceDueAmount
|
|
1853
|
+
this.logInfo("balanceDueAmount 已自动更新:", {
|
|
1861
1854
|
oldAmount: currentBalanceDueAmount,
|
|
1862
1855
|
newAmount: remainingAmount
|
|
1863
1856
|
});
|
|
1864
1857
|
} else {
|
|
1865
|
-
this.logInfo("balanceDueAmount
|
|
1858
|
+
this.logInfo("balanceDueAmount 无需更新,当前值已是最新:", {
|
|
1866
1859
|
balanceDueAmount: currentBalanceDueAmount,
|
|
1867
1860
|
remainingAmount
|
|
1868
1861
|
});
|
|
1869
1862
|
}
|
|
1870
1863
|
} catch (error) {
|
|
1871
|
-
this.logError("
|
|
1864
|
+
this.logError("更新 balanceDueAmount 失败:", error);
|
|
1872
1865
|
}
|
|
1873
1866
|
}
|
|
1874
1867
|
/**
|
|
@@ -1906,18 +1899,18 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1906
1899
|
const currentStateAmount = this.store.stateAmount;
|
|
1907
1900
|
if (remainingAmount !== currentStateAmount) {
|
|
1908
1901
|
this.store.stateAmount = remainingAmount;
|
|
1909
|
-
this.core.effects.emit(
|
|
1902
|
+
this.core.effects.emit(`${this.name}:onStateAmountChanged`, {
|
|
1910
1903
|
oldAmount: currentStateAmount,
|
|
1911
1904
|
newAmount: remainingAmount,
|
|
1912
1905
|
timestamp: Date.now(),
|
|
1913
1906
|
totalAmount: remainingTotalAmount
|
|
1914
1907
|
});
|
|
1915
|
-
this.logInfo("stateAmount
|
|
1908
|
+
this.logInfo("stateAmount 已自动更新为剩余金额:", {
|
|
1916
1909
|
oldAmount: currentStateAmount,
|
|
1917
1910
|
newAmount: remainingAmount
|
|
1918
1911
|
});
|
|
1919
1912
|
} else {
|
|
1920
|
-
this.logInfo("stateAmount
|
|
1913
|
+
this.logInfo("stateAmount 无需更新,当前值已是最新:", {
|
|
1921
1914
|
stateAmount: currentStateAmount,
|
|
1922
1915
|
remainingAmount
|
|
1923
1916
|
});
|
|
@@ -1926,10 +1919,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1926
1919
|
if (checkOrder) {
|
|
1927
1920
|
await this.checkOrderPaymentCompletion();
|
|
1928
1921
|
} else {
|
|
1929
|
-
this.logInfo("
|
|
1922
|
+
this.logInfo("外部传入无需 checkOrder,不执行订单支付完成检测和同步");
|
|
1930
1923
|
}
|
|
1931
1924
|
} catch (error) {
|
|
1932
|
-
this.logError("
|
|
1925
|
+
this.logError("更新 stateAmount 为剩余金额失败:", error);
|
|
1933
1926
|
}
|
|
1934
1927
|
}
|
|
1935
1928
|
/**
|
|
@@ -1947,7 +1940,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1947
1940
|
if (remainingValue.lte(0)) {
|
|
1948
1941
|
const totalAmount = this.store.currentOrder.total_amount;
|
|
1949
1942
|
const paidAmount = await this.calculatePaidAmountAsync();
|
|
1950
|
-
this.logInfo("
|
|
1943
|
+
this.logInfo("检测到订单支付完成:", {
|
|
1951
1944
|
orderUuid: this.store.currentOrder.uuid,
|
|
1952
1945
|
orderId: this.store.currentOrder.order_id,
|
|
1953
1946
|
totalAmount,
|
|
@@ -1965,13 +1958,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1965
1958
|
(item) => item.status !== "voided" && item.voucher_id
|
|
1966
1959
|
);
|
|
1967
1960
|
const shouldAutoSync = hasPaymentItems && !allPaymentsHaveVoucherId;
|
|
1968
|
-
this.logInfo("
|
|
1961
|
+
this.logInfo("自动同步订单条件检查:", {
|
|
1969
1962
|
paymentCount: currentPayments.length,
|
|
1970
1963
|
hasPaymentItems,
|
|
1971
1964
|
allHaveVoucherId: allPaymentsHaveVoucherId,
|
|
1972
1965
|
isOrderSynced: this.store.isOrderSynced,
|
|
1973
1966
|
shouldAutoSync,
|
|
1974
|
-
reason: shouldAutoSync ? "
|
|
1967
|
+
reason: shouldAutoSync ? "支付完成,需要同步最终支付状态" : "跳过同步",
|
|
1975
1968
|
paymentItems: currentPayments.map((p) => ({
|
|
1976
1969
|
uuid: p.uuid,
|
|
1977
1970
|
code: p.code,
|
|
@@ -1983,16 +1976,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1983
1976
|
}))
|
|
1984
1977
|
});
|
|
1985
1978
|
if (shouldAutoSync) {
|
|
1986
|
-
this.logInfo("
|
|
1979
|
+
this.logInfo("满足自动同步条件,开始同步订单到后端...");
|
|
1987
1980
|
await this.syncOrderToBackendWithReturn(false);
|
|
1988
1981
|
} else {
|
|
1989
1982
|
if (!hasPaymentItems) {
|
|
1990
|
-
this.logInfo("
|
|
1983
|
+
this.logInfo("没有支付项,跳过订单同步");
|
|
1991
1984
|
} else if (allPaymentsHaveVoucherId) {
|
|
1992
|
-
this.logInfo("
|
|
1985
|
+
this.logInfo("所有支付项均为代金券类型,跳过订单同步");
|
|
1993
1986
|
}
|
|
1994
1987
|
}
|
|
1995
|
-
await this.core.effects.emit(
|
|
1988
|
+
await this.core.effects.emit(`${this.name}:onOrderPaymentCompleted`, {
|
|
1996
1989
|
orderUuid: this.store.currentOrder.uuid,
|
|
1997
1990
|
orderId: this.store.currentOrder.order_id,
|
|
1998
1991
|
totalAmount,
|
|
@@ -2002,7 +1995,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2002
1995
|
});
|
|
2003
1996
|
}
|
|
2004
1997
|
} catch (error) {
|
|
2005
|
-
this.logError("
|
|
1998
|
+
this.logError("检查订单支付完成状态失败:", error);
|
|
2006
1999
|
}
|
|
2007
2000
|
}
|
|
2008
2001
|
/**
|
|
@@ -2015,12 +2008,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2015
2008
|
async syncOrderToBackendWithReturn(isManual = false, customPaymentItems) {
|
|
2016
2009
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2017
2010
|
if (!this.store.localOrderData || !this.store.currentOrder) {
|
|
2018
|
-
throw new Error("
|
|
2011
|
+
throw new Error("缺少必要的订单数据,无法同步到后端");
|
|
2019
2012
|
}
|
|
2020
2013
|
this.logInfo("syncOrderToBackendWithReturn called", { isManual });
|
|
2021
2014
|
const currentOrderId = this.store.currentOrder.order_id;
|
|
2022
2015
|
const isUpdateOperation = this.store.isOrderSynced || !(0, import_utils.isVirtualOrderId)(currentOrderId);
|
|
2023
|
-
this.logInfo(
|
|
2016
|
+
this.logInfo(`开始同步订单到后端...`, {
|
|
2024
2017
|
currentOrderId,
|
|
2025
2018
|
isVirtualId: (0, import_utils.isVirtualOrderId)(currentOrderId || ""),
|
|
2026
2019
|
orderUuid: this.store.currentOrder.uuid,
|
|
@@ -2044,15 +2037,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2044
2037
|
const manualDepositValue = new import_decimal.default(manualDepositAmount);
|
|
2045
2038
|
if (manualDepositValue.gt(0)) {
|
|
2046
2039
|
finalDepositAmount = manualDepositAmount;
|
|
2047
|
-
this.logInfo("
|
|
2040
|
+
this.logInfo("使用手动设置的定金金额", {
|
|
2048
2041
|
manualDepositAmount,
|
|
2049
|
-
reason: "
|
|
2042
|
+
reason: "用户通过setDepositAmountAsync手动设置了定金金额"
|
|
2050
2043
|
});
|
|
2051
2044
|
} else {
|
|
2052
2045
|
finalDepositAmount = "0.00";
|
|
2053
|
-
this.logInfo("
|
|
2046
|
+
this.logInfo("定金金额为0", {
|
|
2054
2047
|
manualDepositAmount,
|
|
2055
|
-
reason: "
|
|
2048
|
+
reason: "手动设置和计算值均为0"
|
|
2056
2049
|
});
|
|
2057
2050
|
}
|
|
2058
2051
|
if (this.store.currentOrder.is_deposit === 0 && processedPaymentItems.every((item) => item.order_payment_type !== "deposit")) {
|
|
@@ -2073,7 +2066,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2073
2066
|
return sum.plus(amt).sub(rounding);
|
|
2074
2067
|
}, new import_decimal.default(0)).toFixed(2);
|
|
2075
2068
|
}
|
|
2076
|
-
this.logInfo("
|
|
2069
|
+
this.logInfo("定金金额确定结果", {
|
|
2077
2070
|
depositPaymentItemsCount: processedPaymentItems.length,
|
|
2078
2071
|
depositPaymentItems: processedPaymentItems.map((item) => ({
|
|
2079
2072
|
uuid: item.uuid,
|
|
@@ -2134,14 +2127,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2134
2127
|
if (isUpdateOperation) {
|
|
2135
2128
|
if ((0, import_utils.isVirtualOrderId)(currentOrderId)) {
|
|
2136
2129
|
this.logWarning(
|
|
2137
|
-
"
|
|
2130
|
+
"尝试数据修复:暂时不包含order_id,注意:这次调用将作为创建操作处理,但后续会修复数据一致性"
|
|
2138
2131
|
);
|
|
2139
2132
|
} else {
|
|
2140
2133
|
orderParams.order_id = currentOrderId;
|
|
2141
2134
|
}
|
|
2142
2135
|
}
|
|
2143
2136
|
const startTime = Date.now();
|
|
2144
|
-
await this.core.effects.emit(
|
|
2137
|
+
await this.core.effects.emit(`${this.name}:onOrderSubmitStart`, {
|
|
2145
2138
|
orderUuid: this.store.currentOrder.uuid,
|
|
2146
2139
|
operation: isUpdateOperation ? "update" : "create",
|
|
2147
2140
|
isManual,
|
|
@@ -2159,12 +2152,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2159
2152
|
});
|
|
2160
2153
|
checkoutResponse = await this.order.createOrderByCheckout(orderParams);
|
|
2161
2154
|
submitSuccess = true;
|
|
2162
|
-
this.logInfo("
|
|
2155
|
+
this.logInfo("下单接口调用成功", checkoutResponse);
|
|
2163
2156
|
} catch (error) {
|
|
2164
2157
|
submitSuccess = false;
|
|
2165
2158
|
submitError = error instanceof Error ? error.message : String(error);
|
|
2166
|
-
this.logError("
|
|
2167
|
-
await this.core.effects.emit(
|
|
2159
|
+
this.logError("下单接口调用失败:", submitError);
|
|
2160
|
+
await this.core.effects.emit(`${this.name}:onOrderSyncFailed`, {
|
|
2168
2161
|
orderUuid: this.store.currentOrder.uuid,
|
|
2169
2162
|
operation: isUpdateOperation ? "update" : "create",
|
|
2170
2163
|
isManual,
|
|
@@ -2175,7 +2168,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2175
2168
|
});
|
|
2176
2169
|
throw error;
|
|
2177
2170
|
} finally {
|
|
2178
|
-
await this.core.effects.emit(
|
|
2171
|
+
await this.core.effects.emit(`${this.name}:onOrderSubmitEnd`, {
|
|
2179
2172
|
success: submitSuccess,
|
|
2180
2173
|
orderUuid: this.store.currentOrder.uuid,
|
|
2181
2174
|
operation: isUpdateOperation ? "update" : "create",
|
|
@@ -2189,8 +2182,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2189
2182
|
const responseStatus = checkoutResponse == null ? void 0 : checkoutResponse.status;
|
|
2190
2183
|
const isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === "success" || responseStatus === 1 && (checkoutResponse == null ? void 0 : checkoutResponse.code) === 200;
|
|
2191
2184
|
if (!isSuccessResponse) {
|
|
2192
|
-
const errorMessage = (checkoutResponse == null ? void 0 : checkoutResponse.message) || "
|
|
2193
|
-
await this.core.effects.emit(
|
|
2185
|
+
const errorMessage = (checkoutResponse == null ? void 0 : checkoutResponse.message) || "订单同步失败,后端返回非成功状态";
|
|
2186
|
+
await this.core.effects.emit(`${this.name}:onOrderSyncFailed`, {
|
|
2194
2187
|
orderUuid: this.store.currentOrder.uuid,
|
|
2195
2188
|
operation: isUpdateOperation ? "update" : "create",
|
|
2196
2189
|
isManual,
|
|
@@ -2214,10 +2207,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2214
2207
|
extractedOrderId = String(extractedOrderId);
|
|
2215
2208
|
}
|
|
2216
2209
|
if (!extractedOrderId) {
|
|
2217
|
-
this.logError("
|
|
2210
|
+
this.logError("后端返回的订单信息中未包含订单ID");
|
|
2218
2211
|
}
|
|
2219
2212
|
realOrderId = extractedOrderId;
|
|
2220
|
-
this.logInfo("
|
|
2213
|
+
this.logInfo("准备替换订单ID:", {
|
|
2221
2214
|
orderUuid: this.store.currentOrder.uuid,
|
|
2222
2215
|
oldOrderId: this.store.currentOrder.order_id,
|
|
2223
2216
|
newOrderId: realOrderId
|
|
@@ -2227,38 +2220,38 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2227
2220
|
this.store.currentOrder.uuid,
|
|
2228
2221
|
realOrderId
|
|
2229
2222
|
);
|
|
2230
|
-
this.logInfo("Payment
|
|
2223
|
+
this.logInfo("Payment模块替换订单ID结果:", {
|
|
2231
2224
|
wasSuccessful: !!updatedOrder,
|
|
2232
2225
|
returnedOrderId: updatedOrder == null ? void 0 : updatedOrder.order_id,
|
|
2233
2226
|
expectedOrderId: realOrderId
|
|
2234
2227
|
});
|
|
2235
2228
|
if (updatedOrder) {
|
|
2236
|
-
this.logInfo("Payment
|
|
2229
|
+
this.logInfo("Payment模块返回的更新后订单:", {
|
|
2237
2230
|
uuid: updatedOrder.uuid,
|
|
2238
2231
|
orderId: updatedOrder.order_id,
|
|
2239
2232
|
totalAmount: updatedOrder.total_amount
|
|
2240
2233
|
});
|
|
2241
2234
|
this.store.currentOrder = updatedOrder;
|
|
2242
2235
|
this.logInfo(
|
|
2243
|
-
"[Checkout]
|
|
2236
|
+
"[Checkout] 订单ID替换成功,当前订单ID:",
|
|
2244
2237
|
this.store.currentOrder.order_id
|
|
2245
2238
|
);
|
|
2246
2239
|
} else {
|
|
2247
2240
|
this.logError(
|
|
2248
|
-
"[Checkout] Payment
|
|
2241
|
+
"[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换"
|
|
2249
2242
|
);
|
|
2250
2243
|
const beforeManualUpdate = this.store.currentOrder.order_id;
|
|
2251
2244
|
this.store.currentOrder.order_id = realOrderId;
|
|
2252
|
-
this.logInfo("
|
|
2245
|
+
this.logInfo("手动设置订单ID:", {
|
|
2253
2246
|
beforeReplacement: beforeManualUpdate,
|
|
2254
2247
|
afterReplacement: this.store.currentOrder.order_id,
|
|
2255
|
-
|
|
2248
|
+
目标ID: realOrderId
|
|
2256
2249
|
});
|
|
2257
2250
|
}
|
|
2258
2251
|
} catch (error) {
|
|
2259
|
-
this.logError("
|
|
2252
|
+
this.logError("调用Payment模块替换订单ID时发生错误:", error);
|
|
2260
2253
|
this.store.currentOrder.order_id = realOrderId;
|
|
2261
|
-
this.logInfo("
|
|
2254
|
+
this.logInfo("错误恢复:手动设置订单ID:", realOrderId);
|
|
2262
2255
|
}
|
|
2263
2256
|
}
|
|
2264
2257
|
try {
|
|
@@ -2271,10 +2264,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2271
2264
|
);
|
|
2272
2265
|
}
|
|
2273
2266
|
} catch (e) {
|
|
2274
|
-
this.logWarning("
|
|
2267
|
+
this.logWarning("标记支付项已同步失败(不阻塞主流程)", { error: e });
|
|
2275
2268
|
}
|
|
2276
2269
|
this.store.isOrderSynced = true;
|
|
2277
|
-
await this.core.effects.emit(
|
|
2270
|
+
await this.core.effects.emit(`${this.name}:onOrderSynced`, {
|
|
2278
2271
|
orderUuid: this.store.currentOrder.uuid,
|
|
2279
2272
|
realOrderId,
|
|
2280
2273
|
virtualOrderId: this.store.currentOrder.order_id,
|
|
@@ -2315,7 +2308,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2315
2308
|
if (!orderId) {
|
|
2316
2309
|
return {
|
|
2317
2310
|
success: false,
|
|
2318
|
-
message: "
|
|
2311
|
+
message: "订单ID不能为空",
|
|
2319
2312
|
orderId
|
|
2320
2313
|
};
|
|
2321
2314
|
}
|
|
@@ -2329,7 +2322,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2329
2322
|
const response = await this.request.put(`/order/order/${orderId}/note`, {
|
|
2330
2323
|
note
|
|
2331
2324
|
});
|
|
2332
|
-
this.logInfo("
|
|
2325
|
+
this.logInfo("订单备注编辑响应:", {
|
|
2333
2326
|
orderId,
|
|
2334
2327
|
status: response.status,
|
|
2335
2328
|
message: response.message,
|
|
@@ -2341,7 +2334,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2341
2334
|
if (this.store.localOrderData) {
|
|
2342
2335
|
this.store.localOrderData.shop_note = note;
|
|
2343
2336
|
}
|
|
2344
|
-
await this.core.effects.emit(
|
|
2337
|
+
await this.core.effects.emit(`${this.name}:onOrderNoteChanged`, {
|
|
2345
2338
|
orderUuid: this.store.currentOrder.uuid,
|
|
2346
2339
|
oldNote: previousNote,
|
|
2347
2340
|
newNote: note,
|
|
@@ -2350,12 +2343,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2350
2343
|
}
|
|
2351
2344
|
return {
|
|
2352
2345
|
success: true,
|
|
2353
|
-
message: response.message || "
|
|
2346
|
+
message: response.message || "订单备注修改成功",
|
|
2354
2347
|
orderId
|
|
2355
2348
|
};
|
|
2356
2349
|
} else {
|
|
2357
|
-
const errorMessage = response.message || "
|
|
2358
|
-
this.logError(
|
|
2350
|
+
const errorMessage = response.message || "订单备注修改失败";
|
|
2351
|
+
this.logError(`订单 ${orderId} 备注修改失败:`, errorMessage);
|
|
2359
2352
|
return {
|
|
2360
2353
|
success: false,
|
|
2361
2354
|
message: errorMessage,
|
|
@@ -2363,11 +2356,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2363
2356
|
};
|
|
2364
2357
|
}
|
|
2365
2358
|
} catch (error) {
|
|
2366
|
-
this.logError("
|
|
2367
|
-
const errorMessage = error instanceof Error ? error.message : "
|
|
2359
|
+
this.logError("编辑订单备注失败:", error);
|
|
2360
|
+
const errorMessage = error instanceof Error ? error.message : "网络错误或服务器异常";
|
|
2368
2361
|
return {
|
|
2369
2362
|
success: false,
|
|
2370
|
-
message:
|
|
2363
|
+
message: `编辑订单备注失败: ${errorMessage}`,
|
|
2371
2364
|
orderId
|
|
2372
2365
|
};
|
|
2373
2366
|
}
|
|
@@ -2393,13 +2386,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2393
2386
|
if (!params.order_ids || params.order_ids.length === 0) {
|
|
2394
2387
|
return {
|
|
2395
2388
|
success: false,
|
|
2396
|
-
message: "
|
|
2389
|
+
message: "订单ID列表不能为空"
|
|
2397
2390
|
};
|
|
2398
2391
|
}
|
|
2399
2392
|
if (!params.emails || params.emails.length === 0) {
|
|
2400
2393
|
return {
|
|
2401
2394
|
success: false,
|
|
2402
|
-
message: "
|
|
2395
|
+
message: "邮箱地址列表不能为空"
|
|
2403
2396
|
};
|
|
2404
2397
|
}
|
|
2405
2398
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
@@ -2409,7 +2402,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2409
2402
|
if (invalidEmails.length > 0) {
|
|
2410
2403
|
return {
|
|
2411
2404
|
success: false,
|
|
2412
|
-
message:
|
|
2405
|
+
message: `邮箱格式无效: ${invalidEmails.join(", ")}`
|
|
2413
2406
|
};
|
|
2414
2407
|
}
|
|
2415
2408
|
const requestBody = {
|
|
@@ -2425,7 +2418,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2425
2418
|
"/order/batch-email",
|
|
2426
2419
|
requestBody
|
|
2427
2420
|
);
|
|
2428
|
-
this.logInfo("
|
|
2421
|
+
this.logInfo("支付链接邮件发送响应:", {
|
|
2429
2422
|
status: response.status,
|
|
2430
2423
|
message: response.message,
|
|
2431
2424
|
data: response.data,
|
|
@@ -2434,22 +2427,22 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2434
2427
|
if (response.status === true || response.status === 200) {
|
|
2435
2428
|
return {
|
|
2436
2429
|
success: true,
|
|
2437
|
-
message: response.message || "
|
|
2430
|
+
message: response.message || "支付链接邮件发送成功"
|
|
2438
2431
|
};
|
|
2439
2432
|
} else {
|
|
2440
|
-
const errorMessage = response.message || "
|
|
2441
|
-
console.error("[Checkout]
|
|
2433
|
+
const errorMessage = response.message || "支付链接邮件发送失败";
|
|
2434
|
+
console.error("[Checkout] 支付链接邮件发送失败:", errorMessage);
|
|
2442
2435
|
return {
|
|
2443
2436
|
success: false,
|
|
2444
2437
|
message: errorMessage
|
|
2445
2438
|
};
|
|
2446
2439
|
}
|
|
2447
2440
|
} catch (error) {
|
|
2448
|
-
this.logError("
|
|
2449
|
-
const errorMessage = error instanceof Error ? error.message : "
|
|
2441
|
+
this.logError("发送客户支付链接邮件失败:", error);
|
|
2442
|
+
const errorMessage = error instanceof Error ? error.message : "网络错误或服务器异常";
|
|
2450
2443
|
return {
|
|
2451
2444
|
success: false,
|
|
2452
|
-
message:
|
|
2445
|
+
message: `发送支付链接邮件失败: ${errorMessage}`
|
|
2453
2446
|
};
|
|
2454
2447
|
}
|
|
2455
2448
|
}
|
|
@@ -2483,7 +2476,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2483
2476
|
await ((_b = (_a = this.order) == null ? void 0 : _a.destroy) == null ? void 0 : _b.call(_a));
|
|
2484
2477
|
await ((_d = (_c = this.payment) == null ? void 0 : _c.destroy) == null ? void 0 : _d.call(_c));
|
|
2485
2478
|
this.core.unregisterModule(this);
|
|
2486
|
-
console.log("[Checkout]
|
|
2479
|
+
console.log("[Checkout] 已销毁");
|
|
2487
2480
|
}
|
|
2488
2481
|
/**
|
|
2489
2482
|
* 重置 store 状态
|
|
@@ -2496,7 +2489,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2496
2489
|
uuid: this.store.currentOrder.uuid,
|
|
2497
2490
|
orderId: this.store.currentOrder.order_id
|
|
2498
2491
|
} : null;
|
|
2499
|
-
console.log("[Checkout]
|
|
2492
|
+
console.log("[Checkout] 重置 store 状态,准备创建新订单", prevOrderInfo);
|
|
2500
2493
|
this.store.currentOrder = void 0;
|
|
2501
2494
|
this.store.localOrderData = void 0;
|
|
2502
2495
|
this.store.cartSummary = void 0;
|
|
@@ -2507,15 +2500,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2507
2500
|
this.store.lastError = void 0;
|
|
2508
2501
|
this.store.cartItems = [];
|
|
2509
2502
|
this.payment.wallet.clearAllCache();
|
|
2510
|
-
console.log("[Checkout] Store
|
|
2503
|
+
console.log("[Checkout] Store 状态重置完成");
|
|
2511
2504
|
if (prevOrderInfo) {
|
|
2512
|
-
await this.core.effects.emit(
|
|
2505
|
+
await this.core.effects.emit(`${this.name}:onOrderCleared`, {
|
|
2513
2506
|
previousOrder: prevOrderInfo,
|
|
2514
2507
|
timestamp: Date.now()
|
|
2515
2508
|
});
|
|
2516
2509
|
}
|
|
2517
2510
|
} catch (error) {
|
|
2518
|
-
console.error("[Checkout]
|
|
2511
|
+
console.error("[Checkout] 重置 store 状态失败:", error);
|
|
2519
2512
|
}
|
|
2520
2513
|
}
|
|
2521
2514
|
};
|