@pisell/pisellos 2.1.38 → 2.2.1

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.
Files changed (135) hide show
  1. package/dist/core/index.d.ts +8 -1
  2. package/dist/core/index.js +116 -42
  3. package/dist/effects/index.d.ts +1 -0
  4. package/dist/effects/index.js +29 -6
  5. package/dist/modules/Account/index.js +2 -3
  6. package/dist/modules/BaseModule.d.ts +3 -0
  7. package/dist/modules/BaseModule.js +15 -0
  8. package/dist/modules/Customer/index.js +9 -10
  9. package/dist/modules/Customer/types.d.ts +2 -2
  10. package/dist/modules/Customer/types.js +2 -2
  11. package/dist/modules/Discount/index.js +1 -1
  12. package/dist/modules/Guests/index.js +9 -9
  13. package/dist/modules/Order/index.js +1 -1
  14. package/dist/modules/Payment/index.js +63 -73
  15. package/dist/modules/Payment/walletpass.js +4 -1
  16. package/dist/modules/Product/index.d.ts +1 -1
  17. package/dist/modules/Product/types.d.ts +19 -0
  18. package/dist/modules/ProductList/index.js +5 -14
  19. package/dist/modules/Resource/index.js +1 -1
  20. package/dist/modules/Rules/index.js +2 -3
  21. package/dist/modules/Schedule/types.d.ts +2 -0
  22. package/dist/plugins/request.d.ts +1 -0
  23. package/dist/server/index.d.ts +152 -0
  24. package/dist/server/index.js +946 -0
  25. package/dist/server/modules/index.d.ts +16 -0
  26. package/dist/server/modules/index.js +21 -0
  27. package/dist/server/modules/menu/index.d.ts +63 -0
  28. package/dist/server/modules/menu/index.js +476 -0
  29. package/dist/server/modules/menu/types.d.ts +68 -0
  30. package/dist/server/modules/menu/types.js +16 -0
  31. package/dist/server/modules/products/index.d.ts +141 -0
  32. package/dist/server/modules/products/index.js +768 -0
  33. package/dist/server/modules/products/types.d.ts +94 -0
  34. package/dist/server/modules/products/types.js +43 -0
  35. package/dist/server/modules/quotation/index.d.ts +47 -0
  36. package/dist/server/modules/quotation/index.js +367 -0
  37. package/dist/server/modules/quotation/types.d.ts +50 -0
  38. package/dist/server/modules/quotation/types.js +20 -0
  39. package/dist/server/modules/schedule/index.d.ts +62 -0
  40. package/dist/server/modules/schedule/index.js +431 -0
  41. package/dist/server/modules/schedule/types.d.ts +1 -0
  42. package/dist/server/modules/schedule/types.js +2 -0
  43. package/dist/server/modules/schedule/utils.d.ts +32 -0
  44. package/dist/server/modules/schedule/utils.js +747 -0
  45. package/dist/server/types.d.ts +64 -0
  46. package/dist/server/types.js +1 -0
  47. package/dist/server/utils/index.d.ts +5 -0
  48. package/dist/server/utils/index.js +6 -0
  49. package/dist/server/utils/product.d.ts +18 -0
  50. package/dist/server/utils/product.js +339 -0
  51. package/dist/server/utils/schedule.d.ts +14 -0
  52. package/dist/server/utils/schedule.js +108 -0
  53. package/dist/server/utils/time.d.ts +18 -0
  54. package/dist/server/utils/time.js +53 -0
  55. package/dist/solution/BookingByStep/index.d.ts +1 -17
  56. package/dist/solution/BookingByStep/index.js +23 -468
  57. package/dist/solution/BookingByStep/utils/capacity.d.ts +2 -7
  58. package/dist/solution/BookingByStep/utils/capacity.js +8 -24
  59. package/dist/solution/BookingTicket/index.d.ts +12 -0
  60. package/dist/solution/BookingTicket/index.js +122 -79
  61. package/dist/solution/BookingTicket/utils/scan/index.d.ts +4 -0
  62. package/dist/solution/BookingTicket/utils/scan/index.js +25 -16
  63. package/dist/solution/BuyTickets/index.js +7 -8
  64. package/dist/solution/Checkout/index.d.ts +1 -46
  65. package/dist/solution/Checkout/index.js +530 -850
  66. package/dist/solution/ShopDiscount/index.js +9 -10
  67. package/dist/types/index.d.ts +27 -0
  68. package/lib/core/index.d.ts +8 -1
  69. package/lib/core/index.js +48 -1
  70. package/lib/effects/index.d.ts +1 -0
  71. package/lib/effects/index.js +13 -0
  72. package/lib/modules/Account/index.js +2 -3
  73. package/lib/modules/BaseModule.d.ts +3 -0
  74. package/lib/modules/BaseModule.js +9 -0
  75. package/lib/modules/Customer/index.js +9 -10
  76. package/lib/modules/Customer/types.d.ts +2 -2
  77. package/lib/modules/Customer/types.js +2 -2
  78. package/lib/modules/Discount/index.js +1 -1
  79. package/lib/modules/Guests/index.js +9 -9
  80. package/lib/modules/Order/index.js +1 -1
  81. package/lib/modules/Payment/index.js +56 -43
  82. package/lib/modules/Payment/walletpass.js +3 -1
  83. package/lib/modules/Product/index.d.ts +1 -1
  84. package/lib/modules/Product/types.d.ts +19 -0
  85. package/lib/modules/ProductList/index.js +4 -13
  86. package/lib/modules/Resource/index.js +1 -1
  87. package/lib/modules/Rules/index.js +2 -3
  88. package/lib/modules/Schedule/types.d.ts +2 -0
  89. package/lib/plugins/request.d.ts +1 -0
  90. package/lib/server/index.d.ts +152 -0
  91. package/lib/server/index.js +555 -0
  92. package/lib/server/modules/index.d.ts +16 -0
  93. package/lib/server/modules/index.js +47 -0
  94. package/lib/server/modules/menu/index.d.ts +63 -0
  95. package/lib/server/modules/menu/index.js +234 -0
  96. package/lib/server/modules/menu/types.d.ts +68 -0
  97. package/lib/server/modules/menu/types.js +33 -0
  98. package/lib/server/modules/products/index.d.ts +141 -0
  99. package/lib/server/modules/products/index.js +434 -0
  100. package/lib/server/modules/products/types.d.ts +94 -0
  101. package/lib/server/modules/products/types.js +35 -0
  102. package/lib/server/modules/quotation/index.d.ts +47 -0
  103. package/lib/server/modules/quotation/index.js +177 -0
  104. package/lib/server/modules/quotation/types.d.ts +50 -0
  105. package/lib/server/modules/quotation/types.js +33 -0
  106. package/lib/server/modules/schedule/index.d.ts +62 -0
  107. package/lib/server/modules/schedule/index.js +231 -0
  108. package/lib/server/modules/schedule/types.d.ts +1 -0
  109. package/lib/server/modules/schedule/types.js +23 -0
  110. package/lib/server/modules/schedule/utils.d.ts +32 -0
  111. package/lib/server/modules/schedule/utils.js +451 -0
  112. package/lib/server/types.d.ts +64 -0
  113. package/lib/server/types.js +17 -0
  114. package/lib/server/utils/index.d.ts +5 -0
  115. package/lib/server/utils/index.js +25 -0
  116. package/lib/server/utils/product.d.ts +18 -0
  117. package/lib/server/utils/product.js +262 -0
  118. package/lib/server/utils/schedule.d.ts +14 -0
  119. package/lib/server/utils/schedule.js +88 -0
  120. package/lib/server/utils/time.d.ts +18 -0
  121. package/lib/server/utils/time.js +70 -0
  122. package/lib/solution/BookingByStep/index.d.ts +1 -17
  123. package/lib/solution/BookingByStep/index.js +40 -312
  124. package/lib/solution/BookingByStep/utils/capacity.d.ts +2 -7
  125. package/lib/solution/BookingByStep/utils/capacity.js +8 -21
  126. package/lib/solution/BookingTicket/index.d.ts +12 -0
  127. package/lib/solution/BookingTicket/index.js +25 -6
  128. package/lib/solution/BookingTicket/utils/scan/index.d.ts +4 -0
  129. package/lib/solution/BookingTicket/utils/scan/index.js +7 -1
  130. package/lib/solution/BuyTickets/index.js +7 -8
  131. package/lib/solution/Checkout/index.d.ts +1 -46
  132. package/lib/solution/Checkout/index.js +92 -289
  133. package/lib/solution/ShopDiscount/index.js +10 -11
  134. package/lib/types/index.d.ts +27 -0
  135. package/package.json +2 -2
@@ -49,9 +49,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
49
49
  this.defaultVersion = "1.0.0";
50
50
  this.isSolution = true;
51
51
  this.otherParams = {};
52
- // LoggerManager 实例
53
- // 计算缓存(用于性能优化)
54
- this.calculationCache = {};
55
52
  }
56
53
  async initialize(core, options) {
57
54
  this.core = core;
@@ -81,7 +78,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
81
78
  await this.preloadPaymentMethods();
82
79
  await this.cleanupExpiredOrdersAsync();
83
80
  console.log("[Checkout] 初始化完成");
84
- await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutInitialized, {
81
+ await this.core.effects.emit(`${this.name}:onCheckoutInitialized`, {
85
82
  timestamp: Date.now()
86
83
  });
87
84
  this.logInfo("CheckoutModule initialized successfully");
@@ -265,7 +262,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
265
262
  this.logInfo("initWalletData currentOrder found", {
266
263
  currentOrder: this.store.currentOrder
267
264
  });
268
- await this.core.effects.emit(import_types.CheckoutHooks.OnWalletDataInitialized, {
265
+ await this.core.effects.emit(`${this.name}:onWalletDataInitialized`, {
269
266
  orderUuid: (_g = this.store.currentOrder) == null ? void 0 : _g.uuid,
270
267
  customerId: walletBusinessData.customer_id,
271
268
  walletBusinessData: {
@@ -347,7 +344,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
347
344
  totalInfoKeys: params.totalInfo ? Object.keys(params.totalInfo) : []
348
345
  });
349
346
  try {
350
- this.resetStoreState();
347
+ await this.resetStoreStateAsync();
351
348
  const validation = (0, import_utils.validateLocalOrderData)(params.orderData);
352
349
  if (!validation.valid) {
353
350
  throw (0, import_utils.createCheckoutError)(
@@ -397,20 +394,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
397
394
  }
398
395
  });
399
396
  this.store.currentOrder = paymentOrder;
400
- this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
397
+ if (params.autoPayment) {
398
+ }
399
+ this.core.effects.emit(`${this.name}:onOrderCreated`, {
401
400
  order: paymentOrder,
402
401
  timestamp: Date.now()
403
402
  });
404
- const updateAmountStartTime = Date.now();
405
403
  await this.updateStateAmountToRemaining(false);
406
- const updateAmountDuration = Date.now() - updateAmountStartTime;
407
- this.logInfo("updateStateAmountToRemaining operation completed", {
408
- operation: "updateStateAmountToRemaining",
409
- orderUuid: paymentOrder.uuid,
410
- orderId: paymentOrder.order_id,
411
- duration: `${updateAmountDuration}ms`,
412
- performance: updateAmountDuration > 200 ? "slow" : updateAmountDuration > 100 ? "medium" : "fast"
413
- });
414
404
  this.logInfo("本地订单创建成功:", {
415
405
  localOrderId,
416
406
  uuid: paymentOrder.uuid,
@@ -427,7 +417,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
427
417
  import_types.CheckoutErrorType.OrderCreationFailed
428
418
  );
429
419
  this.logError("本地订单创建失败:", error);
430
- this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreationFailed, {
420
+ this.core.effects.emit(`${this.name}:onOrderCreationFailed`, {
431
421
  error: this.store.lastError,
432
422
  timestamp: Date.now()
433
423
  });
@@ -528,7 +518,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
528
518
  totalAmount: updated.total_amount,
529
519
  expectAmount: updated.expect_amount
530
520
  });
531
- await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
521
+ await this.core.effects.emit(`${this.name}:onOrderCreated`, {
532
522
  order: updated,
533
523
  timestamp: Date.now()
534
524
  });
@@ -594,12 +584,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
594
584
  );
595
585
  }
596
586
  this.payment.wallet.clearAllCache();
597
- await this.core.effects.emit(import_types.CheckoutHooks.OnCheckoutCompleted, {
587
+ await this.core.effects.emit(`${this.name}:onCheckoutCompleted`, {
598
588
  orderId: order.id,
599
589
  timestamp: Date.now()
600
590
  });
601
591
  console.log("[Checkout] 结账流程完成:", order.id);
602
- this.resetStoreState();
592
+ await this.resetStoreStateAsync();
603
593
  return {
604
594
  success: true,
605
595
  orderId: String(order.id)
@@ -705,7 +695,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
705
695
  );
706
696
  if (updatedOrder) {
707
697
  this.store.currentOrder = updatedOrder;
708
- await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
698
+ await this.core.effects.emit(`${this.name}:onOrderCreated`, {
709
699
  order: updatedOrder,
710
700
  timestamp: Date.now()
711
701
  });
@@ -746,7 +736,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
746
736
  newAmount: formattedAmount
747
737
  });
748
738
  this.store.stateAmount = formattedAmount;
749
- await this.core.effects.emit(import_types.CheckoutHooks.OnStateAmountChanged, {
739
+ await this.core.effects.emit(`${this.name}:onStateAmountChanged`, {
750
740
  oldAmount,
751
741
  newAmount: formattedAmount,
752
742
  timestamp: Date.now()
@@ -864,7 +854,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
864
854
  paymentItemWithType
865
855
  );
866
856
  this.logInfo("支付项添加成功");
867
- this.clearCalculationCache();
868
857
  await this.updateStateAmountToRemaining();
869
858
  const remainingAmount = await this.calculateRemainingAmountAsync();
870
859
  if (Number(remainingAmount) > 0) {
@@ -898,7 +887,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
898
887
  }
899
888
  }
900
889
  }
901
- this.core.effects.emit(import_types.CheckoutHooks.OnPaymentItemAdded, {
890
+ this.core.effects.emit(`${this.name}:onPaymentItemAdded`, {
902
891
  orderUuid: this.store.currentOrder.uuid,
903
892
  paymentMethodCode: paymentItem.code,
904
893
  paymentMethodName: paymentItem.name,
@@ -955,7 +944,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
955
944
  paymentUuid
956
945
  );
957
946
  this.logInfo("Payment支付项删除完成", paymentItem);
958
- this.clearCalculationCache();
959
947
  const currentOrderId = this.store.currentOrder.order_id;
960
948
  const isCurrentOrderReal = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
961
949
  const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(
@@ -975,7 +963,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
975
963
  this.store.currentOrder = updatedOrder;
976
964
  }
977
965
  await this.updateStateAmountToRemaining(false);
978
- await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
966
+ await this.core.effects.emit(`${this.name}:onPaymentStarted`, {
979
967
  orderUuid: this.store.currentOrder.uuid,
980
968
  paymentMethodCode: paymentItem.code,
981
969
  amount: `-${paymentItem.amount}`,
@@ -1050,7 +1038,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1050
1038
  this.store.currentOrder.uuid,
1051
1039
  voucherPaymentItemsWithType
1052
1040
  );
1053
- this.clearCalculationCache();
1054
1041
  const currentOrderId = this.store.currentOrder.order_id;
1055
1042
  const isCurrentOrderReal = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
1056
1043
  const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(
@@ -1070,7 +1057,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1070
1057
  this.store.currentOrder = updatedOrder;
1071
1058
  }
1072
1059
  await this.updateStateAmountToRemaining(false);
1073
- await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentStarted, {
1060
+ await this.core.effects.emit(`${this.name}:onPaymentStarted`, {
1074
1061
  orderUuid: this.store.currentOrder.uuid,
1075
1062
  paymentMethodCode: "VOUCHER_BATCH",
1076
1063
  amount: voucherPaymentItems.reduce((sum, item) => sum + parseFloat(String(item.amount)), 0).toFixed(2),
@@ -1130,9 +1117,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1130
1117
  if (this.store.localOrderData) {
1131
1118
  this.store.localOrderData.is_deposit = newDepositValue;
1132
1119
  }
1133
- this.clearCalculationCache();
1134
1120
  this.updateStateAmountToRemaining(false);
1135
- await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
1121
+ await this.core.effects.emit(`${this.name}:onOrderCreated`, {
1136
1122
  order: this.store.currentOrder,
1137
1123
  timestamp: Date.now()
1138
1124
  });
@@ -1222,9 +1208,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1222
1208
  this.store.localOrderData.is_deposit = updateParams.is_deposit;
1223
1209
  }
1224
1210
  }
1225
- this.clearCalculationCache();
1226
1211
  this.updateStateAmountToRemaining(false);
1227
- await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
1212
+ await this.core.effects.emit(`${this.name}:onOrderCreated`, {
1228
1213
  order: this.store.currentOrder,
1229
1214
  timestamp: Date.now()
1230
1215
  });
@@ -1252,7 +1237,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1252
1237
  */
1253
1238
  async manualSyncOrderAsync() {
1254
1239
  var _a, _b, _c, _d, _e;
1255
- console.log("manualSyncOrderAsync called");
1256
1240
  this.logInfo("manualSyncOrderAsync called", {
1257
1241
  hasCurrentOrder: !!this.store.currentOrder,
1258
1242
  currentOrderId: (_a = this.store.currentOrder) == null ? void 0 : _a.order_id,
@@ -1279,9 +1263,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1279
1263
  totalAmount: this.store.currentOrder.total_amount,
1280
1264
  remainingAmount: await this.calculateRemainingAmountAsync()
1281
1265
  });
1282
- console.time("manualSyncOrderAsync");
1283
1266
  const syncResult = await this.syncOrderToBackendWithReturn(true);
1284
- console.timeEnd("manualSyncOrderAsync");
1285
1267
  this.logInfo("手动同步订单完成:", {
1286
1268
  orderUuid,
1287
1269
  syncResult,
@@ -1411,7 +1393,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1411
1393
  this.store.currentCustomer = void 0;
1412
1394
  this.payment.wallet.clearAllCache();
1413
1395
  this.logInfo("订单状态清理完成,currentOrder已释放");
1414
- await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCancelled, {
1396
+ await this.core.effects.emit(`${this.name}:onOrderCancelled`, {
1415
1397
  orderUuid: currentOrderUuid,
1416
1398
  orderId: currentOrderId,
1417
1399
  cancelReason,
@@ -1528,7 +1510,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1528
1510
  );
1529
1511
  }
1530
1512
  }
1531
- await this.core.effects.emit(import_types.CheckoutHooks.OnOrderNoteChanged, {
1513
+ await this.core.effects.emit(`${this.name}:onOrderNoteChanged`, {
1532
1514
  orderUuid: (_b = this.store.currentOrder) == null ? void 0 : _b.uuid,
1533
1515
  oldNote,
1534
1516
  newNote: note,
@@ -1553,7 +1535,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1553
1535
  async handleError(error, type) {
1554
1536
  const checkoutError = error instanceof Error && "type" in error ? error : (0, import_utils.createCheckoutError)(type, error.message, error);
1555
1537
  this.store.lastError = checkoutError;
1556
- await this.core.effects.emit(import_types.CheckoutHooks.OnError, {
1538
+ await this.core.effects.emit(`${this.name}:onError`, {
1557
1539
  error: checkoutError,
1558
1540
  context: {},
1559
1541
  timestamp: Date.now()
@@ -1566,7 +1548,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1566
1548
  async handlePaymentSuccess(data) {
1567
1549
  var _a;
1568
1550
  await this.updateStateAmountToRemaining();
1569
- await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentSuccess, {
1551
+ await this.core.effects.emit(`${this.name}:onPaymentSuccess`, {
1570
1552
  orderUuid: data.orderUuid,
1571
1553
  paymentMethodCode: "",
1572
1554
  amount: ((_a = this.store.currentOrder) == null ? void 0 : _a.total_amount) || "0",
@@ -1587,7 +1569,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1587
1569
  error instanceof Error ? error : new Error(String(error)),
1588
1570
  import_types.CheckoutErrorType.PaymentFailed
1589
1571
  );
1590
- await this.core.effects.emit(import_types.CheckoutHooks.OnPaymentFailed, {
1572
+ await this.core.effects.emit(`${this.name}:onPaymentFailed`, {
1591
1573
  orderUuid: data.orderUuid,
1592
1574
  paymentMethodCode: "",
1593
1575
  amount: ((_a = this.store.currentOrder) == null ? void 0 : _a.total_amount) || "0",
@@ -1774,58 +1756,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1774
1756
  this.logError("Expired orders cleanup failed", { error: errorMessage });
1775
1757
  }
1776
1758
  }
1777
- /**
1778
- * 清除计算缓存
1779
- */
1780
- clearCalculationCache() {
1781
- this.calculationCache = {};
1782
- }
1783
- /**
1784
- * 批量获取订单数据(用于性能优化)
1785
- * 一次性获取所有需要的数据,避免重复查询
1786
- */
1787
- async fetchOrderDataBatch() {
1788
- if (!this.store.currentOrder) {
1789
- return { paymentItems: [], currentOrder: null };
1790
- }
1791
- const orderUuid = this.store.currentOrder.uuid;
1792
- const now = Date.now();
1793
- const cacheValid = this.calculationCache.orderUuid === orderUuid && this.calculationCache.timestamp && now - this.calculationCache.timestamp < 5e3;
1794
- if (cacheValid && this.calculationCache.paymentItems && this.calculationCache.currentOrder) {
1795
- return {
1796
- paymentItems: this.calculationCache.paymentItems,
1797
- currentOrder: this.calculationCache.currentOrder
1798
- };
1799
- }
1800
- const [paymentItems, currentOrder] = await Promise.all([
1801
- this.payment.getPaymentItemsAsync(orderUuid, false),
1802
- this.payment.getPaymentOrderByUuidAsync(orderUuid)
1803
- ]);
1804
- this.calculationCache = {
1805
- paymentItems,
1806
- currentOrder,
1807
- orderUuid,
1808
- timestamp: now
1809
- };
1810
- return { paymentItems, currentOrder };
1811
- }
1812
- /**
1813
- * 从支付项数组计算已支付金额(纯计算,不查询数据库)
1814
- */
1815
- calculatePaidAmountFromItems(payments) {
1816
- const paidAmount = payments.filter((payment) => payment.status !== "voided").reduce((sum, payment) => {
1817
- const amount = new import_decimal.default(payment.amount || "0");
1818
- const roundingAmount = new import_decimal.default(payment.rounding_amount || "0");
1819
- const effectiveAmount = amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
1820
- return sum.add(effectiveAmount);
1821
- }, new import_decimal.default(0));
1822
- return paidAmount.toFixed(2);
1823
- }
1824
1759
  /**
1825
1760
  * 计算已支付金额(从 Payment 模块获取最新数据)
1826
- *
1827
- * 注意:此方法保持独立性,可以单独调用。
1828
- * 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
1829
1761
  */
1830
1762
  async calculatePaidAmountAsync() {
1831
1763
  if (!this.store.currentOrder) {
@@ -1833,18 +1765,30 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1833
1765
  return "0.00";
1834
1766
  }
1835
1767
  try {
1836
- const now = Date.now();
1837
- const cacheValid = this.calculationCache.orderUuid === this.store.currentOrder.uuid && this.calculationCache.timestamp && now - this.calculationCache.timestamp < 5e3 && this.calculationCache.paidAmount;
1838
- if (cacheValid && this.calculationCache.paidAmount) {
1839
- return this.calculationCache.paidAmount;
1840
- }
1841
1768
  const payments = await this.payment.getPaymentItemsAsync(
1842
1769
  this.store.currentOrder.uuid,
1843
1770
  false
1844
1771
  // 不包括已撤销的支付项
1845
1772
  );
1846
- const result = this.calculatePaidAmountFromItems(payments);
1847
- this.calculationCache.paidAmount = result;
1773
+ const paidAmount = payments.filter((payment) => payment.status !== "voided").reduce((sum, payment) => {
1774
+ const amount = new import_decimal.default(payment.amount || "0");
1775
+ const roundingAmount = new import_decimal.default(payment.rounding_amount || "0");
1776
+ const effectiveAmount = amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
1777
+ console.log(`[Checkout] 计算支付项: ${payment.code}`, {
1778
+ originalAmount: amount.toFixed(2),
1779
+ roundingAmount: roundingAmount.toFixed(2),
1780
+ effectiveAmount: effectiveAmount.toFixed(2),
1781
+ description: !roundingAmount.isZero() ? `抹零金额 ${roundingAmount.toFixed(2)} 元,有效支付增加 ${roundingAmount.abs().toFixed(2)} 元` : "无抹零",
1782
+ // Decimal 精度验证
1783
+ preciseCalculationValues: {
1784
+ amount: amount.toString(),
1785
+ roundingAmount: roundingAmount.toString(),
1786
+ effectiveAmount: effectiveAmount.toString()
1787
+ }
1788
+ });
1789
+ return sum.add(effectiveAmount);
1790
+ }, new import_decimal.default(0));
1791
+ const result = paidAmount.toFixed(2);
1848
1792
  this.logInfo("calculatePaidAmountAsync: 计算结果 =", result);
1849
1793
  return result;
1850
1794
  } catch (error) {
@@ -1852,64 +1796,41 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1852
1796
  return "0.00";
1853
1797
  }
1854
1798
  }
1855
- /**
1856
- * 从订单和支付项计算剩余金额(纯计算,不查询数据库)
1857
- */
1858
- calculateRemainingAmountFromData(currentOrder, paidAmount) {
1859
- let totalAmount = new import_decimal.default(currentOrder.total_amount || "0");
1860
- if (currentOrder.is_deposit && currentOrder.deposit_amount && Number(currentOrder.deposit_amount) > 0) {
1861
- totalAmount = new import_decimal.default(currentOrder.deposit_amount);
1862
- }
1863
- const paid = new import_decimal.default(paidAmount);
1864
- const remainingAmount = totalAmount.sub(paid);
1865
- return import_decimal.default.max(0, remainingAmount).toFixed(2);
1866
- }
1867
- /**
1868
- * 从订单和支付项计算剩余总金额(纯计算,排除定金)
1869
- */
1870
- calculateRemainingTotalAmountFromData(currentOrder, paidAmount) {
1871
- const totalAmount = new import_decimal.default(currentOrder.total_amount || "0");
1872
- const paid = new import_decimal.default(paidAmount);
1873
- const remainingAmount = totalAmount.sub(paid);
1874
- return import_decimal.default.max(0, remainingAmount).toFixed(2);
1875
- }
1876
1799
  /**
1877
1800
  * 计算剩余未支付金额(从 Payment 模块获取最新数据)
1878
- *
1879
- * 注意:此方法保持独立性,可以单独调用。
1880
- * 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
1881
1801
  */
1882
1802
  async calculateRemainingAmountAsync() {
1883
1803
  if (!this.store.currentOrder) {
1884
1804
  this.logWarning("calculateRemainingAmountAsync: 没有当前订单");
1885
1805
  return "0.00";
1886
1806
  }
1887
- const { currentOrder } = await this.fetchOrderDataBatch();
1888
- if (!currentOrder) {
1889
- return "0.00";
1807
+ let totalAmount = new import_decimal.default(this.store.currentOrder.total_amount || "0");
1808
+ const currentOrder = await this.payment.getPaymentOrderByUuidAsync(
1809
+ this.store.currentOrder.uuid
1810
+ );
1811
+ if ((currentOrder == null ? void 0 : currentOrder.is_deposit) && (currentOrder == null ? void 0 : currentOrder.deposit_amount) && Number(currentOrder == null ? void 0 : currentOrder.deposit_amount) > 0) {
1812
+ totalAmount = new import_decimal.default(currentOrder == null ? void 0 : currentOrder.deposit_amount);
1890
1813
  }
1891
1814
  const paidAmountStr = await this.calculatePaidAmountAsync();
1892
- const result = this.calculateRemainingAmountFromData(currentOrder, paidAmountStr);
1815
+ const paidAmount = new import_decimal.default(paidAmountStr);
1816
+ const remainingAmount = totalAmount.sub(paidAmount);
1817
+ const result = import_decimal.default.max(0, remainingAmount).toFixed(2);
1893
1818
  this.logInfo("calculateRemainingAmountAsync: 计算=", result);
1894
1819
  return result;
1895
1820
  }
1896
1821
  /**
1897
1822
  * 计算剩余未支付金额(排除定金计算,始终使用订单总金额)
1898
- *
1899
- * 注意:此方法保持独立性,可以单独调用。
1900
- * 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
1901
1823
  */
1902
1824
  async calculateRemainingTotalAmountAsync() {
1903
1825
  if (!this.store.currentOrder) {
1904
1826
  this.logWarning("calculateRemainingTotalAmountAsync: 没有当前订单");
1905
1827
  return "0.00";
1906
1828
  }
1907
- const { currentOrder } = await this.fetchOrderDataBatch();
1908
- if (!currentOrder) {
1909
- return "0.00";
1910
- }
1829
+ const totalAmount = new import_decimal.default(this.store.currentOrder.total_amount || "0");
1911
1830
  const paidAmountStr = await this.calculatePaidAmountAsync();
1912
- const result = this.calculateRemainingTotalAmountFromData(currentOrder, paidAmountStr);
1831
+ const paidAmount = new import_decimal.default(paidAmountStr);
1832
+ const remainingAmount = totalAmount.sub(paidAmount);
1833
+ const result = import_decimal.default.max(0, remainingAmount).toFixed(2);
1913
1834
  this.logInfo("calculateRemainingTotalAmountAsync: 计算=", result);
1914
1835
  return result;
1915
1836
  }
@@ -1923,7 +1844,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1923
1844
  const currentBalanceDueAmount = this.store.balanceDueAmount;
1924
1845
  if (remainingAmount !== currentBalanceDueAmount) {
1925
1846
  this.store.balanceDueAmount = remainingAmount;
1926
- await this.core.effects.emit(import_types.CheckoutHooks.OnBalanceDueAmountChanged, {
1847
+ await this.core.effects.emit(`${this.name}:onBalanceDueAmountChanged`, {
1927
1848
  oldAmount: currentBalanceDueAmount,
1928
1849
  newAmount: remainingAmount,
1929
1850
  timestamp: Date.now(),
@@ -1945,25 +1866,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1945
1866
  }
1946
1867
  /**
1947
1868
  * 更新 stateAmount 为当前剩余未支付金额
1948
- *
1949
- * 优化版本:批量获取数据,避免重复查询数据库
1950
1869
  */
1951
1870
  async updateStateAmountToRemaining(checkOrder = true) {
1871
+ var _a, _b, _c, _d;
1952
1872
  try {
1953
- if (!this.store.currentOrder) {
1954
- return;
1955
- }
1956
- console.time("updateStateAmountToRemaining");
1957
- const { paymentItems, currentOrder } = await this.fetchOrderDataBatch();
1958
- console.timeEnd("updateStateAmountToRemaining");
1959
- if (!currentOrder) {
1960
- this.logWarning("updateStateAmountToRemaining: 未找到当前订单");
1961
- return;
1962
- }
1963
- const paidAmount = this.calculatePaidAmountFromItems(paymentItems);
1964
- this.calculationCache.paidAmount = paidAmount;
1965
- let needUpdateDepositStatus = false;
1966
- if (currentOrder.is_deposit === 1) {
1873
+ if (((_a = this.store.currentOrder) == null ? void 0 : _a.is_deposit) === 1) {
1874
+ const paymentItems = await this.payment.getPaymentItemsAsync(
1875
+ (_b = this.store.currentOrder) == null ? void 0 : _b.uuid
1876
+ );
1967
1877
  const depositPaidAmount = paymentItems.filter(
1968
1878
  (item) => item.order_payment_type === "deposit" && item.status !== "voided"
1969
1879
  ).reduce((sum, item) => {
@@ -1974,70 +1884,40 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1974
1884
  const roundingAmount = new import_decimal.default(item.rounding_amount || "0");
1975
1885
  return sum.add(amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0));
1976
1886
  }, new import_decimal.default(0));
1977
- if (depositPaidAmount.gte(currentOrder.deposit_amount || "0")) {
1978
- needUpdateDepositStatus = true;
1979
- currentOrder.is_deposit = 0;
1887
+ if (depositPaidAmount.gte((_c = this.store.currentOrder) == null ? void 0 : _c.deposit_amount)) {
1888
+ this.store.currentOrder = {
1889
+ ...this.store.currentOrder,
1890
+ is_deposit: 0
1891
+ };
1892
+ await this.payment.updateOrderAsync((_d = this.store.currentOrder) == null ? void 0 : _d.uuid, {
1893
+ is_deposit: 0
1894
+ });
1980
1895
  }
1981
1896
  }
1982
- const remainingAmount = this.calculateRemainingAmountFromData(currentOrder, paidAmount);
1983
- const remainingTotalAmount = this.calculateRemainingTotalAmountFromData(currentOrder, paidAmount);
1897
+ const remainingAmount = await this.calculateRemainingAmountAsync();
1898
+ const remainingTotalAmount = await this.calculateRemainingTotalAmountAsync();
1984
1899
  const currentStateAmount = this.store.stateAmount;
1985
- const currentBalanceDueAmount = this.store.balanceDueAmount;
1986
- let hasStateChanged = false;
1987
- if (needUpdateDepositStatus) {
1988
- this.store.currentOrder = {
1989
- ...this.store.currentOrder,
1990
- is_deposit: 0
1991
- };
1992
- await this.payment.updateOrderAsync(this.store.currentOrder.uuid, {
1993
- is_deposit: 0
1994
- });
1995
- hasStateChanged = true;
1996
- }
1997
- console.time("updateStateAmountToRemaining: remainingAmount");
1998
1900
  if (remainingAmount !== currentStateAmount) {
1999
1901
  this.store.stateAmount = remainingAmount;
2000
- hasStateChanged = true;
2001
- setTimeout(() => {
2002
- this.core.effects.emit(`${this.name}:onStateAmountChanged`, {
2003
- oldAmount: currentStateAmount,
2004
- newAmount: remainingAmount,
2005
- timestamp: Date.now(),
2006
- totalAmount: remainingTotalAmount
2007
- });
2008
- }, 0);
2009
- this.logInfo("stateAmount 已自动更新为剩余金额:", {
1902
+ this.core.effects.emit(`${this.name}:onStateAmountChanged`, {
2010
1903
  oldAmount: currentStateAmount,
2011
- newAmount: remainingAmount
1904
+ newAmount: remainingAmount,
1905
+ timestamp: Date.now(),
1906
+ totalAmount: remainingTotalAmount
2012
1907
  });
2013
- }
2014
- console.timeEnd("updateStateAmountToRemaining: remainingAmount");
2015
- console.time("updateStateAmountToRemaining: updateStateAmountToRemaining");
2016
- if (remainingAmount !== currentBalanceDueAmount) {
2017
- this.store.balanceDueAmount = remainingAmount;
2018
- hasStateChanged = true;
2019
- setTimeout(() => {
2020
- this.core.effects.emit(`${this.name}:onBalanceDueAmountChanged`, {
2021
- oldAmount: currentBalanceDueAmount,
2022
- newAmount: remainingAmount,
2023
- timestamp: Date.now(),
2024
- totalAmount: remainingTotalAmount
2025
- });
2026
- }, 0);
2027
- this.logInfo("balanceDueAmount 已自动更新:", {
2028
- oldAmount: currentBalanceDueAmount,
1908
+ this.logInfo("stateAmount 已自动更新为剩余金额:", {
1909
+ oldAmount: currentStateAmount,
2029
1910
  newAmount: remainingAmount
2030
1911
  });
2031
- }
2032
- console.timeEnd("updateStateAmountToRemaining: updateStateAmountToRemaining");
2033
- if (!hasStateChanged) {
2034
- this.logInfo("状态无需更新,当前值已是最新:", {
1912
+ } else {
1913
+ this.logInfo("stateAmount 无需更新,当前值已是最新:", {
2035
1914
  stateAmount: currentStateAmount,
2036
1915
  remainingAmount
2037
1916
  });
2038
1917
  }
1918
+ await this.updateBalanceDueAmount();
2039
1919
  if (checkOrder) {
2040
- await this.checkOrderPaymentCompletionOptimized(paymentItems, remainingAmount);
1920
+ await this.checkOrderPaymentCompletion();
2041
1921
  } else {
2042
1922
  this.logInfo("外部传入无需 checkOrder,不执行订单支付完成检测和同步");
2043
1923
  }
@@ -2045,81 +1925,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2045
1925
  this.logError("更新 stateAmount 为剩余金额失败:", error);
2046
1926
  }
2047
1927
  }
2048
- /**
2049
- * 检查订单支付是否完成(优化版,复用已获取的数据)
2050
- *
2051
- * @param paymentItems 已获取的支付项数据
2052
- * @param remainingAmount 已计算的剩余金额
2053
- */
2054
- async checkOrderPaymentCompletionOptimized(paymentItems, remainingAmount) {
2055
- try {
2056
- if (!this.store.currentOrder) {
2057
- return;
2058
- }
2059
- const remainingValue = new import_decimal.default(remainingAmount);
2060
- if (remainingValue.lte(0)) {
2061
- const totalAmount = this.store.currentOrder.total_amount;
2062
- const paidAmount = this.calculationCache.paidAmount || "0.00";
2063
- this.logInfo("检测到订单支付完成:", {
2064
- orderUuid: this.store.currentOrder.uuid,
2065
- orderId: this.store.currentOrder.order_id,
2066
- totalAmount,
2067
- paidAmount,
2068
- remainingAmount,
2069
- isOrderSynced: this.store.isOrderSynced
2070
- });
2071
- const hasPaymentItems = paymentItems.length > 0;
2072
- const allPaymentsHaveVoucherId = hasPaymentItems && paymentItems.every(
2073
- (item) => item.status !== "voided" && item.voucher_id
2074
- );
2075
- const shouldAutoSync = hasPaymentItems && !allPaymentsHaveVoucherId;
2076
- this.logInfo("自动同步订单条件检查:", {
2077
- paymentCount: paymentItems.length,
2078
- hasPaymentItems,
2079
- allHaveVoucherId: allPaymentsHaveVoucherId,
2080
- isOrderSynced: this.store.isOrderSynced,
2081
- shouldAutoSync,
2082
- reason: shouldAutoSync ? "支付完成,需要同步最终支付状态" : "跳过同步",
2083
- paymentItems: paymentItems.map((p) => ({
2084
- uuid: p.uuid,
2085
- code: p.code,
2086
- amount: p.amount,
2087
- rounding_amount: p.rounding_amount,
2088
- effective_amount: (parseFloat(p.amount || "0") + Math.abs(parseFloat(Number(p.rounding_amount) > 0 ? "0" : p.rounding_amount || "0"))).toFixed(2),
2089
- voucher_id: p.voucher_id,
2090
- status: p.status
2091
- }))
2092
- });
2093
- if (shouldAutoSync) {
2094
- this.logInfo("满足自动同步条件,开始同步订单到后端...");
2095
- await this.syncOrderToBackendWithReturn(false);
2096
- } else {
2097
- if (!hasPaymentItems) {
2098
- this.logInfo("没有支付项,跳过订单同步");
2099
- } else if (allPaymentsHaveVoucherId) {
2100
- this.logInfo("所有支付项均为代金券类型,跳过订单同步");
2101
- }
2102
- }
2103
- await this.core.effects.emit(`${this.name}:onOrderPaymentCompleted`, {
2104
- orderUuid: this.store.currentOrder.uuid,
2105
- orderId: this.store.currentOrder.order_id,
2106
- totalAmount,
2107
- paidAmount,
2108
- remainingAmount,
2109
- timestamp: Date.now()
2110
- });
2111
- }
2112
- } catch (error) {
2113
- this.logError("检查订单支付完成状态失败:", error);
2114
- }
2115
- }
2116
1928
  /**
2117
1929
  * 检查订单支付是否完成
2118
1930
  *
2119
1931
  * 当剩余待付款金额 <= 0 时,触发订单支付完成事件
2120
- *
2121
- * 注意:此方法保持独立性,可以单独调用。
2122
- * 在 updateStateAmountToRemaining 中会使用优化版本。
2123
1932
  */
2124
1933
  async checkOrderPaymentCompletion() {
2125
1934
  try {
@@ -2176,7 +1985,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2176
1985
  this.logInfo("所有支付项均为代金券类型,跳过订单同步");
2177
1986
  }
2178
1987
  }
2179
- await this.core.effects.emit(import_types.CheckoutHooks.OnOrderPaymentCompleted, {
1988
+ await this.core.effects.emit(`${this.name}:onOrderPaymentCompleted`, {
2180
1989
  orderUuid: this.store.currentOrder.uuid,
2181
1990
  orderId: this.store.currentOrder.order_id,
2182
1991
  totalAmount,
@@ -2325,7 +2134,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2325
2134
  }
2326
2135
  }
2327
2136
  const startTime = Date.now();
2328
- await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSubmitStart, {
2137
+ await this.core.effects.emit(`${this.name}:onOrderSubmitStart`, {
2329
2138
  orderUuid: this.store.currentOrder.uuid,
2330
2139
  operation: isUpdateOperation ? "update" : "create",
2331
2140
  isManual,
@@ -2348,7 +2157,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2348
2157
  submitSuccess = false;
2349
2158
  submitError = error instanceof Error ? error.message : String(error);
2350
2159
  this.logError("下单接口调用失败:", submitError);
2351
- await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSyncFailed, {
2160
+ await this.core.effects.emit(`${this.name}:onOrderSyncFailed`, {
2352
2161
  orderUuid: this.store.currentOrder.uuid,
2353
2162
  operation: isUpdateOperation ? "update" : "create",
2354
2163
  isManual,
@@ -2359,7 +2168,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2359
2168
  });
2360
2169
  throw error;
2361
2170
  } finally {
2362
- await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSubmitEnd, {
2171
+ await this.core.effects.emit(`${this.name}:onOrderSubmitEnd`, {
2363
2172
  success: submitSuccess,
2364
2173
  orderUuid: this.store.currentOrder.uuid,
2365
2174
  operation: isUpdateOperation ? "update" : "create",
@@ -2374,7 +2183,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2374
2183
  const isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === "success" || responseStatus === 1 && (checkoutResponse == null ? void 0 : checkoutResponse.code) === 200;
2375
2184
  if (!isSuccessResponse) {
2376
2185
  const errorMessage = (checkoutResponse == null ? void 0 : checkoutResponse.message) || "订单同步失败,后端返回非成功状态";
2377
- await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSyncFailed, {
2186
+ await this.core.effects.emit(`${this.name}:onOrderSyncFailed`, {
2378
2187
  orderUuid: this.store.currentOrder.uuid,
2379
2188
  operation: isUpdateOperation ? "update" : "create",
2380
2189
  isManual,
@@ -2458,8 +2267,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2458
2267
  this.logWarning("标记支付项已同步失败(不阻塞主流程)", { error: e });
2459
2268
  }
2460
2269
  this.store.isOrderSynced = true;
2461
- this.clearCalculationCache();
2462
- await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSynced, {
2270
+ await this.core.effects.emit(`${this.name}:onOrderSynced`, {
2463
2271
  orderUuid: this.store.currentOrder.uuid,
2464
2272
  realOrderId,
2465
2273
  virtualOrderId: this.store.currentOrder.order_id,
@@ -2526,7 +2334,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2526
2334
  if (this.store.localOrderData) {
2527
2335
  this.store.localOrderData.shop_note = note;
2528
2336
  }
2529
- await this.core.effects.emit(import_types.CheckoutHooks.OnOrderNoteChanged, {
2337
+ await this.core.effects.emit(`${this.name}:onOrderNoteChanged`, {
2530
2338
  orderUuid: this.store.currentOrder.uuid,
2531
2339
  oldNote: previousNote,
2532
2340
  newNote: note,
@@ -2674,10 +2482,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2674
2482
  * 重置 store 状态
2675
2483
  *
2676
2484
  * 在创建新订单前调用,确保状态完全干净
2677
- *
2678
- * 🚀 性能优化:改为同步方法,事件发射不阻塞主流程
2679
2485
  */
2680
- resetStoreState() {
2486
+ async resetStoreStateAsync() {
2681
2487
  try {
2682
2488
  const prevOrderInfo = this.store.currentOrder ? {
2683
2489
  uuid: this.store.currentOrder.uuid,
@@ -2694,15 +2500,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2694
2500
  this.store.lastError = void 0;
2695
2501
  this.store.cartItems = [];
2696
2502
  this.payment.wallet.clearAllCache();
2697
- this.clearCalculationCache();
2698
2503
  console.log("[Checkout] Store 状态重置完成");
2699
2504
  if (prevOrderInfo) {
2700
- setTimeout(() => {
2701
- this.core.effects.emit(import_types.CheckoutHooks.OnOrderCleared, {
2702
- previousOrder: prevOrderInfo,
2703
- timestamp: Date.now()
2704
- });
2705
- }, 0);
2505
+ await this.core.effects.emit(`${this.name}:onOrderCleared`, {
2506
+ previousOrder: prevOrderInfo,
2507
+ timestamp: Date.now()
2508
+ });
2706
2509
  }
2707
2510
  } catch (error) {
2708
2511
  console.error("[Checkout] 重置 store 状态失败:", error);