@pisell/pisellos 2.1.36 → 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 (133) 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/types.d.ts +19 -0
  17. package/dist/modules/ProductList/index.js +5 -14
  18. package/dist/modules/Resource/index.js +1 -1
  19. package/dist/modules/Rules/index.js +2 -3
  20. package/dist/modules/Schedule/types.d.ts +2 -0
  21. package/dist/plugins/request.d.ts +1 -0
  22. package/dist/server/index.d.ts +152 -0
  23. package/dist/server/index.js +946 -0
  24. package/dist/server/modules/index.d.ts +16 -0
  25. package/dist/server/modules/index.js +21 -0
  26. package/dist/server/modules/menu/index.d.ts +63 -0
  27. package/dist/server/modules/menu/index.js +476 -0
  28. package/dist/server/modules/menu/types.d.ts +68 -0
  29. package/dist/server/modules/menu/types.js +16 -0
  30. package/dist/server/modules/products/index.d.ts +141 -0
  31. package/dist/server/modules/products/index.js +768 -0
  32. package/dist/server/modules/products/types.d.ts +94 -0
  33. package/dist/server/modules/products/types.js +43 -0
  34. package/dist/server/modules/quotation/index.d.ts +47 -0
  35. package/dist/server/modules/quotation/index.js +367 -0
  36. package/dist/server/modules/quotation/types.d.ts +50 -0
  37. package/dist/server/modules/quotation/types.js +20 -0
  38. package/dist/server/modules/schedule/index.d.ts +62 -0
  39. package/dist/server/modules/schedule/index.js +431 -0
  40. package/dist/server/modules/schedule/types.d.ts +1 -0
  41. package/dist/server/modules/schedule/types.js +2 -0
  42. package/dist/server/modules/schedule/utils.d.ts +32 -0
  43. package/dist/server/modules/schedule/utils.js +747 -0
  44. package/dist/server/types.d.ts +64 -0
  45. package/dist/server/types.js +1 -0
  46. package/dist/server/utils/index.d.ts +5 -0
  47. package/dist/server/utils/index.js +6 -0
  48. package/dist/server/utils/product.d.ts +18 -0
  49. package/dist/server/utils/product.js +339 -0
  50. package/dist/server/utils/schedule.d.ts +14 -0
  51. package/dist/server/utils/schedule.js +108 -0
  52. package/dist/server/utils/time.d.ts +18 -0
  53. package/dist/server/utils/time.js +53 -0
  54. package/dist/solution/BookingByStep/index.d.ts +0 -16
  55. package/dist/solution/BookingByStep/index.js +57 -508
  56. package/dist/solution/BookingByStep/utils/capacity.d.ts +2 -7
  57. package/dist/solution/BookingByStep/utils/capacity.js +8 -24
  58. package/dist/solution/BookingTicket/index.d.ts +12 -0
  59. package/dist/solution/BookingTicket/index.js +122 -79
  60. package/dist/solution/BookingTicket/utils/scan/index.d.ts +4 -0
  61. package/dist/solution/BookingTicket/utils/scan/index.js +25 -16
  62. package/dist/solution/BuyTickets/index.js +7 -8
  63. package/dist/solution/Checkout/index.d.ts +1 -46
  64. package/dist/solution/Checkout/index.js +530 -850
  65. package/dist/solution/ShopDiscount/index.js +9 -10
  66. package/dist/types/index.d.ts +27 -0
  67. package/lib/core/index.d.ts +8 -1
  68. package/lib/core/index.js +48 -1
  69. package/lib/effects/index.d.ts +1 -0
  70. package/lib/effects/index.js +13 -0
  71. package/lib/modules/Account/index.js +2 -3
  72. package/lib/modules/BaseModule.d.ts +3 -0
  73. package/lib/modules/BaseModule.js +9 -0
  74. package/lib/modules/Customer/index.js +9 -10
  75. package/lib/modules/Customer/types.d.ts +2 -2
  76. package/lib/modules/Customer/types.js +2 -2
  77. package/lib/modules/Discount/index.js +1 -1
  78. package/lib/modules/Guests/index.js +9 -9
  79. package/lib/modules/Order/index.js +1 -1
  80. package/lib/modules/Payment/index.js +56 -43
  81. package/lib/modules/Payment/walletpass.js +3 -1
  82. package/lib/modules/Product/types.d.ts +19 -0
  83. package/lib/modules/ProductList/index.js +4 -13
  84. package/lib/modules/Resource/index.js +1 -1
  85. package/lib/modules/Rules/index.js +2 -3
  86. package/lib/modules/Schedule/types.d.ts +2 -0
  87. package/lib/plugins/request.d.ts +1 -0
  88. package/lib/server/index.d.ts +152 -0
  89. package/lib/server/index.js +555 -0
  90. package/lib/server/modules/index.d.ts +16 -0
  91. package/lib/server/modules/index.js +47 -0
  92. package/lib/server/modules/menu/index.d.ts +63 -0
  93. package/lib/server/modules/menu/index.js +234 -0
  94. package/lib/server/modules/menu/types.d.ts +68 -0
  95. package/lib/server/modules/menu/types.js +33 -0
  96. package/lib/server/modules/products/index.d.ts +141 -0
  97. package/lib/server/modules/products/index.js +434 -0
  98. package/lib/server/modules/products/types.d.ts +94 -0
  99. package/lib/server/modules/products/types.js +35 -0
  100. package/lib/server/modules/quotation/index.d.ts +47 -0
  101. package/lib/server/modules/quotation/index.js +177 -0
  102. package/lib/server/modules/quotation/types.d.ts +50 -0
  103. package/lib/server/modules/quotation/types.js +33 -0
  104. package/lib/server/modules/schedule/index.d.ts +62 -0
  105. package/lib/server/modules/schedule/index.js +231 -0
  106. package/lib/server/modules/schedule/types.d.ts +1 -0
  107. package/lib/server/modules/schedule/types.js +23 -0
  108. package/lib/server/modules/schedule/utils.d.ts +32 -0
  109. package/lib/server/modules/schedule/utils.js +451 -0
  110. package/lib/server/types.d.ts +64 -0
  111. package/lib/server/types.js +17 -0
  112. package/lib/server/utils/index.d.ts +5 -0
  113. package/lib/server/utils/index.js +25 -0
  114. package/lib/server/utils/product.d.ts +18 -0
  115. package/lib/server/utils/product.js +262 -0
  116. package/lib/server/utils/schedule.d.ts +14 -0
  117. package/lib/server/utils/schedule.js +88 -0
  118. package/lib/server/utils/time.d.ts +18 -0
  119. package/lib/server/utils/time.js +70 -0
  120. package/lib/solution/BookingByStep/index.d.ts +0 -16
  121. package/lib/solution/BookingByStep/index.js +44 -316
  122. package/lib/solution/BookingByStep/utils/capacity.d.ts +2 -7
  123. package/lib/solution/BookingByStep/utils/capacity.js +8 -21
  124. package/lib/solution/BookingTicket/index.d.ts +12 -0
  125. package/lib/solution/BookingTicket/index.js +25 -6
  126. package/lib/solution/BookingTicket/utils/scan/index.d.ts +4 -0
  127. package/lib/solution/BookingTicket/utils/scan/index.js +7 -1
  128. package/lib/solution/BuyTickets/index.js +7 -8
  129. package/lib/solution/Checkout/index.d.ts +1 -46
  130. package/lib/solution/Checkout/index.js +92 -289
  131. package/lib/solution/ShopDiscount/index.js +10 -11
  132. package/lib/types/index.d.ts +27 -0
  133. package/package.json +2 -2
@@ -1,8 +1,4 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
5
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
2
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
7
3
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
4
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -32,7 +28,7 @@ import { BaseModule } from "../../modules/BaseModule";
32
28
  import Decimal from 'decimal.js';
33
29
  import { OrderModule } from "../../modules/Order";
34
30
  import { PaymentModule } from "../../modules/Payment";
35
- import { CheckoutHooks, CheckoutErrorType } from "./types";
31
+ import { CheckoutErrorType } from "./types";
36
32
  import { PaymentStatus, PaymentHooks } from "../../modules/Payment/types";
37
33
  import { validateCheckoutData, createCheckoutError, validateLocalOrderData, generateLocalOrderId, formatDateTime, extractAmountFromCartSummary, isVirtualOrderId, isCashPayment } from "./utils";
38
34
  import { getProductDeposit } from "../../modules/Cart/utils";
@@ -59,8 +55,6 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
59
55
  _defineProperty(_assertThisInitialized(_this), "otherParams", {});
60
56
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
61
57
  // LoggerManager 实例
62
- // 计算缓存(用于性能优化)
63
- _defineProperty(_assertThisInitialized(_this), "calculationCache", {});
64
58
  // 直接挂载的模块
65
59
  _defineProperty(_assertThisInitialized(_this), "order", void 0);
66
60
  _defineProperty(_assertThisInitialized(_this), "payment", void 0);
@@ -123,7 +117,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
123
117
  case 19:
124
118
  console.log('[Checkout] 初始化完成');
125
119
  _context.next = 22;
126
- return this.core.effects.emit(CheckoutHooks.OnCheckoutInitialized, {
120
+ return this.core.effects.emit("".concat(this.name, ":onCheckoutInitialized"), {
127
121
  timestamp: Date.now()
128
122
  });
129
123
  case 22:
@@ -459,7 +453,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
459
453
  });
460
454
  // 触发钱包数据初始化完成事件
461
455
  _context8.next = 16;
462
- return this.core.effects.emit(CheckoutHooks.OnWalletDataInitialized, {
456
+ return this.core.effects.emit("".concat(this.name, ":onWalletDataInitialized"), {
463
457
  orderUuid: (_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.uuid,
464
458
  customerId: walletBusinessData.customer_id,
465
459
  walletBusinessData: {
@@ -545,7 +539,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
545
539
  value: (function () {
546
540
  var _createLocalOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
547
541
  var _params$orderData, _params$orderData2, _params$orderData3, _params$orderData4, _params$orderData5, _params$cartSummary;
548
- var _params$totalInfo, _params$totalInfo2, _params$totalInfo3, _params$totalInfo4, validation, localOrderId, amountInfo, customerInfo, isNeedDeposit, paymentOrder, updateAmountStartTime, updateAmountDuration;
542
+ var _params$totalInfo, _params$totalInfo2, _params$totalInfo3, _params$totalInfo4, validation, localOrderId, amountInfo, customerInfo, isNeedDeposit, paymentOrder;
549
543
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
550
544
  while (1) switch (_context9.prev = _context9.next) {
551
545
  case 0:
@@ -560,16 +554,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
560
554
  totalInfoKeys: params.totalInfo ? Object.keys(params.totalInfo) : []
561
555
  });
562
556
  _context9.prev = 1;
563
- // 🔧 修改:在创建新订单前,直接重置 store 状态(同步执行)
564
- this.resetStoreState();
557
+ _context9.next = 4;
558
+ return this.resetStoreStateAsync();
559
+ case 4:
565
560
  // 验证订单数据
566
561
  validation = validateLocalOrderData(params.orderData);
567
562
  if (validation.valid) {
568
- _context9.next = 6;
563
+ _context9.next = 7;
569
564
  break;
570
565
  }
571
566
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u8BA2\u5355\u6570\u636E\u9A8C\u8BC1\u5931\u8D25: ".concat(validation.errors.join(', ')));
572
- case 6:
567
+ case 7:
573
568
  // 生成本地虚拟订单ID (后续可以被真实订单ID替换)
574
569
  localOrderId = generateLocalOrderId(); // 从购物车小计数据中提取金额信息
575
570
  amountInfo = extractAmountFromCartSummary(params.cartSummary); // TODO: 外面传的是 pos ,但是现在 后端只有 shop 和 kiosk
@@ -603,7 +598,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
603
598
 
604
599
  // 计算是否需要支付定金,如果需要默认切换到定金模式,以及记录定金总金额,并把当前默认待付金额调整为定金总金额
605
600
  isNeedDeposit = this.checkIsNeedDepositAsync(params.orderData.bookings, params.orderData.relation_products); // 创建支付订单对象
606
- _context9.next = 21;
601
+ _context9.next = 22;
607
602
  return this.payment.createPaymentOrderAsync({
608
603
  order_id: localOrderId,
609
604
  total_amount: amountInfo.totalAmount,
@@ -620,34 +615,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
620
615
  amount_breakdown: amountInfo
621
616
  }
622
617
  });
623
- case 21:
618
+ case 22:
624
619
  paymentOrder = _context9.sent;
625
620
  this.store.currentOrder = paymentOrder;
626
621
 
627
- // // 如果设置了自动支付,直接跳转到支付步骤
628
- // if (params.autoPayment) {
629
- // // 自动支付模式标记
630
- // }
631
-
632
- this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
622
+ // 如果设置了自动支付,直接跳转到支付步骤
623
+ if (params.autoPayment) {
624
+ // 自动支付模式标记
625
+ }
626
+ this.core.effects.emit("".concat(this.name, ":onOrderCreated"), {
633
627
  order: paymentOrder,
634
628
  timestamp: Date.now()
635
629
  });
636
630
 
637
631
  // 自动设置 stateAmount 为剩余未支付金额
638
- // 🚀 性能监控:记录 updateStateAmountToRemaining 操作耗时
639
- updateAmountStartTime = Date.now();
640
- _context9.next = 27;
632
+ _context9.next = 28;
641
633
  return this.updateStateAmountToRemaining(false);
642
- case 27:
643
- updateAmountDuration = Date.now() - updateAmountStartTime;
644
- this.logInfo('updateStateAmountToRemaining operation completed', {
645
- operation: 'updateStateAmountToRemaining',
646
- orderUuid: paymentOrder.uuid,
647
- orderId: paymentOrder.order_id,
648
- duration: "".concat(updateAmountDuration, "ms"),
649
- performance: updateAmountDuration > 200 ? 'slow' : updateAmountDuration > 100 ? 'medium' : 'fast'
650
- });
634
+ case 28:
651
635
  this.logInfo('本地订单创建成功:', {
652
636
  localOrderId: localOrderId,
653
637
  uuid: paymentOrder.uuid,
@@ -658,23 +642,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
658
642
  });
659
643
  this.initWalletData();
660
644
  return _context9.abrupt("return", paymentOrder);
661
- case 34:
662
- _context9.prev = 34;
645
+ case 33:
646
+ _context9.prev = 33;
663
647
  _context9.t0 = _context9["catch"](1);
664
- _context9.next = 38;
648
+ _context9.next = 37;
665
649
  return this.handleError(_context9.t0, CheckoutErrorType.OrderCreationFailed);
666
- case 38:
650
+ case 37:
667
651
  this.logError('本地订单创建失败:', _context9.t0);
668
- this.core.effects.emit(CheckoutHooks.OnOrderCreationFailed, {
652
+ this.core.effects.emit("".concat(this.name, ":onOrderCreationFailed"), {
669
653
  error: this.store.lastError,
670
654
  timestamp: Date.now()
671
655
  });
672
656
  throw _context9.t0;
673
- case 41:
657
+ case 40:
674
658
  case "end":
675
659
  return _context9.stop();
676
660
  }
677
- }, _callee9, this, [[1, 34]]);
661
+ }, _callee9, this, [[1, 33]]);
678
662
  }));
679
663
  function createLocalOrderAsync(_x11) {
680
664
  return _createLocalOrderAsync.apply(this, arguments);
@@ -803,7 +787,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
803
787
 
804
788
  // 事件通知(复用创建事件,便于上层监听刷新)
805
789
  _context10.next = 38;
806
- return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
790
+ return this.core.effects.emit("".concat(this.name, ":onOrderCreated"), {
807
791
  order: updated,
808
792
  timestamp: Date.now()
809
793
  });
@@ -891,33 +875,35 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
891
875
  // 清理钱包模块的所有缓存数据
892
876
  this.payment.wallet.clearAllCache();
893
877
  _context11.next = 11;
894
- return this.core.effects.emit(CheckoutHooks.OnCheckoutCompleted, {
878
+ return this.core.effects.emit("".concat(this.name, ":onCheckoutCompleted"), {
895
879
  orderId: order.id,
896
880
  timestamp: Date.now()
897
881
  });
898
882
  case 11:
899
883
  console.log('[Checkout] 结账流程完成:', order.id);
900
884
 
901
- // 🔧 新增:自动重置 store 状态(同步执行)
902
- this.resetStoreState();
885
+ // 🔧 新增:自动重置 store 状态
886
+ _context11.next = 14;
887
+ return this.resetStoreStateAsync();
888
+ case 14:
903
889
  return _context11.abrupt("return", {
904
890
  success: true,
905
891
  orderId: String(order.id)
906
892
  });
907
- case 16:
908
- _context11.prev = 16;
893
+ case 17:
894
+ _context11.prev = 17;
909
895
  _context11.t0 = _context11["catch"](0);
910
- _context11.next = 20;
896
+ _context11.next = 21;
911
897
  return this.handleError(_context11.t0, CheckoutErrorType.UnknownError);
912
- case 20:
898
+ case 21:
913
899
  return _context11.abrupt("return", {
914
900
  success: false
915
901
  });
916
- case 21:
902
+ case 22:
917
903
  case "end":
918
904
  return _context11.stop();
919
905
  }
920
- }, _callee11, this, [[0, 16]]);
906
+ }, _callee11, this, [[0, 17]]);
921
907
  }));
922
908
  function completeCheckoutAsync() {
923
909
  return _completeCheckoutAsync.apply(this, arguments);
@@ -1078,7 +1064,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1078
1064
 
1079
1065
  // 触发订单更新事件
1080
1066
  _context13.next = 11;
1081
- return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
1067
+ return this.core.effects.emit("".concat(this.name, ":onOrderCreated"), {
1082
1068
  order: updatedOrder,
1083
1069
  timestamp: Date.now()
1084
1070
  });
@@ -1158,7 +1144,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1158
1144
 
1159
1145
  // 触发金额变更事件
1160
1146
  _context14.next = 12;
1161
- return this.core.effects.emit(CheckoutHooks.OnStateAmountChanged, {
1147
+ return this.core.effects.emit("".concat(this.name, ":onStateAmountChanged"), {
1162
1148
  oldAmount: oldAmount,
1163
1149
  newAmount: formattedAmount,
1164
1150
  timestamp: Date.now()
@@ -1333,19 +1319,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1333
1319
  case 12:
1334
1320
  this.logInfo('支付项添加成功');
1335
1321
 
1336
- // 🚀 清除计算缓存,确保获取最新数据
1337
- this.clearCalculationCache();
1338
-
1339
1322
  // 支付项添加后,更新 stateAmount 为剩余未支付金额
1340
- _context16.next = 16;
1323
+ _context16.next = 15;
1341
1324
  return this.updateStateAmountToRemaining();
1342
- case 16:
1343
- _context16.next = 18;
1325
+ case 15:
1326
+ _context16.next = 17;
1344
1327
  return this.calculateRemainingAmountAsync();
1345
- case 18:
1328
+ case 17:
1346
1329
  remainingAmount = _context16.sent;
1347
1330
  if (!(Number(remainingAmount) > 0)) {
1348
- _context16.next = 39;
1331
+ _context16.next = 38;
1349
1332
  break;
1350
1333
  }
1351
1334
  this.logInfo('订单金额还有待付的,同步 EFTPOS 支付');
@@ -1360,53 +1343,53 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1360
1343
  currentOrderSynced: this.store.isOrderSynced
1361
1344
  });
1362
1345
  if (!(isEftposPayment || _isCashPayment || isCustomePayment)) {
1363
- _context16.next = 39;
1346
+ _context16.next = 38;
1364
1347
  break;
1365
1348
  }
1366
1349
  this.logInfo('检测到 EFTPOS 支付,立即同步订单到后端...');
1367
- _context16.prev = 27;
1368
- _context16.next = 30;
1350
+ _context16.prev = 26;
1351
+ _context16.next = 29;
1369
1352
  return this.syncOrderToBackendWithReturn(true);
1370
- case 30:
1353
+ case 29:
1371
1354
  syncResult = _context16.sent;
1372
1355
  this.logInfo('EFTPOS 支付后订单同步完成 (已标记为手动同步):', {
1373
1356
  orderId: syncResult.orderId,
1374
1357
  isOrderSynced: this.store.isOrderSynced,
1375
1358
  backendResponse: syncResult.response
1376
1359
  });
1377
- _context16.next = 39;
1360
+ _context16.next = 38;
1378
1361
  break;
1379
- case 34:
1380
- _context16.prev = 34;
1381
- _context16.t0 = _context16["catch"](27);
1362
+ case 33:
1363
+ _context16.prev = 33;
1364
+ _context16.t0 = _context16["catch"](26);
1382
1365
  this.logError('EFTPOS 支付后订单同步失败:', _context16.t0);
1383
1366
  // 不抛出错误,避免影响支付流程,但记录错误
1384
- _context16.next = 39;
1367
+ _context16.next = 38;
1385
1368
  return this.handleError(new Error("EFTPOS \u652F\u4ED8\u540E\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0))), CheckoutErrorType.OrderCreationFailed);
1386
- case 39:
1369
+ case 38:
1387
1370
  // 触发支付项添加事件(可以复用支付开始事件)
1388
- this.core.effects.emit(CheckoutHooks.OnPaymentItemAdded, {
1371
+ this.core.effects.emit("".concat(this.name, ":onPaymentItemAdded"), {
1389
1372
  orderUuid: this.store.currentOrder.uuid,
1390
1373
  paymentMethodCode: paymentItem.code,
1391
1374
  paymentMethodName: paymentItem.name,
1392
1375
  amount: String(paymentItem.amount),
1393
1376
  timestamp: Date.now()
1394
1377
  });
1395
- _context16.next = 48;
1378
+ _context16.next = 47;
1396
1379
  break;
1397
- case 42:
1398
- _context16.prev = 42;
1380
+ case 41:
1381
+ _context16.prev = 41;
1399
1382
  _context16.t1 = _context16["catch"](1);
1400
1383
  this.logError('添加支付项失败:', _context16.t1);
1401
- _context16.next = 47;
1384
+ _context16.next = 46;
1402
1385
  return this.handleError(_context16.t1, CheckoutErrorType.PaymentFailed);
1403
- case 47:
1386
+ case 46:
1404
1387
  throw _context16.t1;
1405
- case 48:
1388
+ case 47:
1406
1389
  case "end":
1407
1390
  return _context16.stop();
1408
1391
  }
1409
- }, _callee16, this, [[1, 42], [27, 34]]);
1392
+ }, _callee16, this, [[1, 41], [26, 33]]);
1410
1393
  }));
1411
1394
  function addPaymentItemAsync(_x15) {
1412
1395
  return _addPaymentItemAsync.apply(this, arguments);
@@ -1471,15 +1454,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1471
1454
  case 13:
1472
1455
  this.logInfo('Payment支付项删除完成', paymentItem);
1473
1456
 
1474
- // 🚀 清除计算缓存,确保获取最新数据
1475
- this.clearCalculationCache();
1476
-
1477
1457
  // 重新从Payment模块获取最新的订单数据,确保支付项同步
1478
1458
  currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1479
1459
  isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
1480
- _context17.next = 19;
1460
+ _context17.next = 18;
1481
1461
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1482
- case 19:
1462
+ case 18:
1483
1463
  updatedOrder = _context17.sent;
1484
1464
  if (updatedOrder) {
1485
1465
  // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
@@ -1494,33 +1474,33 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1494
1474
  }
1495
1475
 
1496
1476
  // 更新 stateAmount 为剩余未支付金额
1497
- _context17.next = 23;
1477
+ _context17.next = 22;
1498
1478
  return this.updateStateAmountToRemaining(false);
1499
- case 23:
1500
- _context17.next = 25;
1501
- return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1479
+ case 22:
1480
+ _context17.next = 24;
1481
+ return this.core.effects.emit("".concat(this.name, ":onPaymentStarted"), {
1502
1482
  orderUuid: this.store.currentOrder.uuid,
1503
1483
  paymentMethodCode: paymentItem.code,
1504
1484
  amount: "-".concat(paymentItem.amount),
1505
1485
  // 负数表示删除
1506
1486
  timestamp: Date.now()
1507
1487
  });
1508
- case 25:
1509
- _context17.next = 33;
1488
+ case 24:
1489
+ _context17.next = 32;
1510
1490
  break;
1511
- case 27:
1512
- _context17.prev = 27;
1491
+ case 26:
1492
+ _context17.prev = 26;
1513
1493
  _context17.t0 = _context17["catch"](0);
1514
1494
  this.logError('删除支付项失败:', _context17.t0);
1515
- _context17.next = 32;
1495
+ _context17.next = 31;
1516
1496
  return this.handleError(_context17.t0, CheckoutErrorType.PaymentFailed);
1517
- case 32:
1497
+ case 31:
1518
1498
  throw _context17.t0;
1519
- case 33:
1499
+ case 32:
1520
1500
  case "end":
1521
1501
  return _context17.stop();
1522
1502
  }
1523
- }, _callee17, this, [[0, 27]]);
1503
+ }, _callee17, this, [[0, 26]]);
1524
1504
  }));
1525
1505
  function deletePaymentItemAsync(_x16) {
1526
1506
  return _deletePaymentItemAsync.apply(this, arguments);
@@ -1605,15 +1585,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1605
1585
  _context18.next = 20;
1606
1586
  return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItemsWithType);
1607
1587
  case 20:
1608
- // 🚀 清除计算缓存,确保获取最新数据
1609
- this.clearCalculationCache();
1610
-
1611
1588
  // 重新从Payment模块获取最新的订单数据,确保支付项同步
1612
1589
  currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1613
1590
  isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
1614
- _context18.next = 25;
1591
+ _context18.next = 24;
1615
1592
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1616
- case 25:
1593
+ case 24:
1617
1594
  updatedOrder = _context18.sent;
1618
1595
  if (updatedOrder) {
1619
1596
  // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
@@ -1628,11 +1605,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1628
1605
  }
1629
1606
 
1630
1607
  // 更新 stateAmount 为剩余未支付金额
1631
- _context18.next = 29;
1608
+ _context18.next = 28;
1632
1609
  return this.updateStateAmountToRemaining(false);
1633
- case 29:
1634
- _context18.next = 31;
1635
- return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1610
+ case 28:
1611
+ _context18.next = 30;
1612
+ return this.core.effects.emit("".concat(this.name, ":onPaymentStarted"), {
1636
1613
  orderUuid: this.store.currentOrder.uuid,
1637
1614
  paymentMethodCode: 'VOUCHER_BATCH',
1638
1615
  amount: voucherPaymentItems.reduce(function (sum, item) {
@@ -1640,23 +1617,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1640
1617
  }, 0).toFixed(2),
1641
1618
  timestamp: Date.now()
1642
1619
  });
1643
- case 31:
1620
+ case 30:
1644
1621
  this.logInfo('代金券支付项批量更新成功');
1645
- _context18.next = 40;
1622
+ _context18.next = 39;
1646
1623
  break;
1647
- case 34:
1648
- _context18.prev = 34;
1624
+ case 33:
1625
+ _context18.prev = 33;
1649
1626
  _context18.t0 = _context18["catch"](0);
1650
1627
  this.logError('[Checkout] 批量更新代金券支付项失败:', _context18.t0);
1651
- _context18.next = 39;
1628
+ _context18.next = 38;
1652
1629
  return this.handleError(_context18.t0, CheckoutErrorType.PaymentFailed);
1653
- case 39:
1630
+ case 38:
1654
1631
  throw _context18.t0;
1655
- case 40:
1632
+ case 39:
1656
1633
  case "end":
1657
1634
  return _context18.stop();
1658
1635
  }
1659
- }, _callee18, this, [[0, 34]]);
1636
+ }, _callee18, this, [[0, 33]]);
1660
1637
  }));
1661
1638
  function updateVoucherPaymentItemsAsync(_x17) {
1662
1639
  return _updateVoucherPaymentItemsAsync.apply(this, arguments);
@@ -1730,37 +1707,34 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1730
1707
  if (this.store.localOrderData) {
1731
1708
  this.store.localOrderData.is_deposit = newDepositValue;
1732
1709
  }
1733
-
1734
- // 🚀 清除计算缓存,确保获取最新数据
1735
- this.clearCalculationCache();
1736
1710
  this.updateStateAmountToRemaining(false);
1737
1711
 
1738
1712
  // 触发订单更新事件
1739
- _context19.next = 21;
1740
- return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
1713
+ _context19.next = 20;
1714
+ return this.core.effects.emit("".concat(this.name, ":onOrderCreated"), {
1741
1715
  order: this.store.currentOrder,
1742
1716
  timestamp: Date.now()
1743
1717
  });
1744
- case 21:
1718
+ case 20:
1745
1719
  this.logInfo('订单定金状态更新成功:', {
1746
1720
  isDeposit: newDepositValue,
1747
1721
  depositAmount: this.store.currentOrder.deposit_amount
1748
1722
  });
1749
- _context19.next = 30;
1723
+ _context19.next = 29;
1750
1724
  break;
1751
- case 24:
1752
- _context19.prev = 24;
1725
+ case 23:
1726
+ _context19.prev = 23;
1753
1727
  _context19.t0 = _context19["catch"](0);
1754
1728
  this.logError('更新订单定金状态失败:', _context19.t0);
1755
- _context19.next = 29;
1729
+ _context19.next = 28;
1756
1730
  return this.handleError(_context19.t0, CheckoutErrorType.ValidationFailed);
1757
- case 29:
1731
+ case 28:
1758
1732
  throw _context19.t0;
1759
- case 30:
1733
+ case 29:
1760
1734
  case "end":
1761
1735
  return _context19.stop();
1762
1736
  }
1763
- }, _callee19, this, [[0, 24]]);
1737
+ }, _callee19, this, [[0, 23]]);
1764
1738
  }));
1765
1739
  function updateOrderDepositStatusAsync(_x18) {
1766
1740
  return _updateOrderDepositStatusAsync.apply(this, arguments);
@@ -1859,18 +1833,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1859
1833
  this.store.localOrderData.is_deposit = updateParams.is_deposit;
1860
1834
  }
1861
1835
  }
1862
-
1863
- // 🚀 清除计算缓存,确保获取最新数据
1864
- this.clearCalculationCache();
1865
1836
  this.updateStateAmountToRemaining(false);
1866
1837
 
1867
1838
  // 触发订单更新事件
1868
- _context20.next = 23;
1869
- return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
1839
+ _context20.next = 22;
1840
+ return this.core.effects.emit("".concat(this.name, ":onOrderCreated"), {
1870
1841
  order: this.store.currentOrder,
1871
1842
  timestamp: Date.now()
1872
1843
  });
1873
- case 23:
1844
+ case 22:
1874
1845
  this.logInfo('订单定金金额设置成功:', {
1875
1846
  orderUuid: this.store.currentOrder.uuid,
1876
1847
  orderId: this.store.currentOrder.order_id,
@@ -1879,21 +1850,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1879
1850
  isDeposit: this.store.currentOrder.is_deposit,
1880
1851
  totalAmount: this.store.currentOrder.total_amount
1881
1852
  });
1882
- _context20.next = 32;
1853
+ _context20.next = 31;
1883
1854
  break;
1884
- case 26:
1885
- _context20.prev = 26;
1855
+ case 25:
1856
+ _context20.prev = 25;
1886
1857
  _context20.t0 = _context20["catch"](1);
1887
1858
  this.logError('设置订单定金金额失败:', _context20.t0);
1888
- _context20.next = 31;
1859
+ _context20.next = 30;
1889
1860
  return this.handleError(_context20.t0, CheckoutErrorType.ValidationFailed);
1890
- case 31:
1861
+ case 30:
1891
1862
  throw _context20.t0;
1892
- case 32:
1863
+ case 31:
1893
1864
  case "end":
1894
1865
  return _context20.stop();
1895
1866
  }
1896
- }, _callee20, this, [[1, 26]]);
1867
+ }, _callee20, this, [[1, 25]]);
1897
1868
  }));
1898
1869
  function setDepositAmountAsync(_x19) {
1899
1870
  return _setDepositAmountAsync.apply(this, arguments);
@@ -1915,7 +1886,6 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1915
1886
  return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1916
1887
  while (1) switch (_context21.prev = _context21.next) {
1917
1888
  case 0:
1918
- console.log('manualSyncOrderAsync called');
1919
1889
  this.logInfo('manualSyncOrderAsync called', {
1920
1890
  hasCurrentOrder: !!this.store.currentOrder,
1921
1891
  currentOrderId: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.order_id,
@@ -1924,16 +1894,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1924
1894
  isOrderSynced: this.store.isOrderSynced,
1925
1895
  isVirtualOrderId: this.store.currentOrder ? isVirtualOrderId(this.store.currentOrder.order_id) : false
1926
1896
  });
1927
- _context21.prev = 2;
1897
+ _context21.prev = 1;
1928
1898
  if (this.store.currentOrder) {
1929
- _context21.next = 5;
1899
+ _context21.next = 4;
1930
1900
  break;
1931
1901
  }
1932
1902
  return _context21.abrupt("return", {
1933
1903
  success: false,
1934
1904
  message: '当前没有活跃订单,无法同步'
1935
1905
  });
1936
- case 5:
1906
+ case 4:
1937
1907
  orderUuid = this.store.currentOrder.uuid;
1938
1908
  oldOrderId = this.store.currentOrder.order_id; // 检查订单是否已经同步
1939
1909
  if (this.store.isOrderSynced) {
@@ -1943,9 +1913,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1943
1913
  _context21.t1 = orderUuid;
1944
1914
  _context21.t2 = oldOrderId;
1945
1915
  _context21.t3 = this.store.currentOrder.total_amount;
1946
- _context21.next = 14;
1916
+ _context21.next = 13;
1947
1917
  return this.calculateRemainingAmountAsync();
1948
- case 14:
1918
+ case 13:
1949
1919
  _context21.t4 = _context21.sent;
1950
1920
  _context21.t5 = {
1951
1921
  orderUuid: _context21.t1,
@@ -1954,14 +1924,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1954
1924
  remainingAmount: _context21.t4
1955
1925
  };
1956
1926
  _context21.t0.logInfo.call(_context21.t0, '开始手动同步订单到后端:', _context21.t5);
1957
- console.time('manualSyncOrderAsync');
1958
-
1959
- // 强制同步订单到后端,并获取完整响应数据
1960
- _context21.next = 20;
1927
+ _context21.next = 18;
1961
1928
  return this.syncOrderToBackendWithReturn(true);
1962
- case 20:
1929
+ case 18:
1963
1930
  syncResult = _context21.sent;
1964
- console.timeEnd('manualSyncOrderAsync');
1965
1931
  this.logInfo('手动同步订单完成:', {
1966
1932
  orderUuid: orderUuid,
1967
1933
  syncResult: syncResult,
@@ -1982,13 +1948,13 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1982
1948
  newRes = _objectSpread(_objectSpread({}, syncResult), {}, {
1983
1949
  is_deposit: ((_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.is_deposit) || 0
1984
1950
  });
1985
- _context21.next = 30;
1951
+ _context21.next = 27;
1986
1952
  return this.updateStateAmountToRemaining(false);
1987
- case 30:
1953
+ case 27:
1988
1954
  return _context21.abrupt("return", newRes);
1989
- case 33:
1990
- _context21.prev = 33;
1991
- _context21.t6 = _context21["catch"](2);
1955
+ case 30:
1956
+ _context21.prev = 30;
1957
+ _context21.t6 = _context21["catch"](1);
1992
1958
  this.logError('手动同步订单失败:', _context21.t6);
1993
1959
  errorMessage = _context21.t6 instanceof Error ? _context21.t6.message : '同步失败';
1994
1960
  return _context21.abrupt("return", {
@@ -1996,11 +1962,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1996
1962
  message: "\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(errorMessage),
1997
1963
  orderUuid: (_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.uuid
1998
1964
  });
1999
- case 38:
1965
+ case 35:
2000
1966
  case "end":
2001
1967
  return _context21.stop();
2002
1968
  }
2003
- }, _callee21, this, [[2, 33]]);
1969
+ }, _callee21, this, [[1, 30]]);
2004
1970
  }));
2005
1971
  function manualSyncOrderAsync() {
2006
1972
  return _manualSyncOrderAsync.apply(this, arguments);
@@ -2140,7 +2106,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2140
2106
 
2141
2107
  // 触发订单取消事件
2142
2108
  _context22.next = 32;
2143
- return this.core.effects.emit(CheckoutHooks.OnOrderCancelled, {
2109
+ return this.core.effects.emit("".concat(this.name, ":onOrderCancelled"), {
2144
2110
  orderUuid: currentOrderUuid,
2145
2111
  orderId: currentOrderId,
2146
2112
  cancelReason: cancelReason,
@@ -2311,7 +2277,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2311
2277
  console.warn('[Checkout] 同步备注到Payment模块失败,但本地更新成功:', _context24.t0);
2312
2278
  case 17:
2313
2279
  _context24.next = 19;
2314
- return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
2280
+ return this.core.effects.emit("".concat(this.name, ":onOrderNoteChanged"), {
2315
2281
  orderUuid: (_this$store$currentOr20 = this.store.currentOrder) === null || _this$store$currentOr20 === void 0 ? void 0 : _this$store$currentOr20.uuid,
2316
2282
  oldNote: oldNote,
2317
2283
  newNote: note,
@@ -2358,7 +2324,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2358
2324
  checkoutError = error instanceof Error && 'type' in error ? error : createCheckoutError(type, error.message, error);
2359
2325
  this.store.lastError = checkoutError;
2360
2326
  _context25.next = 4;
2361
- return this.core.effects.emit(CheckoutHooks.OnError, {
2327
+ return this.core.effects.emit("".concat(this.name, ":onError"), {
2362
2328
  error: checkoutError,
2363
2329
  context: {},
2364
2330
  timestamp: Date.now()
@@ -2392,7 +2358,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2392
2358
  return this.updateStateAmountToRemaining();
2393
2359
  case 2:
2394
2360
  _context26.next = 4;
2395
- return this.core.effects.emit(CheckoutHooks.OnPaymentSuccess, {
2361
+ return this.core.effects.emit("".concat(this.name, ":onPaymentSuccess"), {
2396
2362
  orderUuid: data.orderUuid,
2397
2363
  paymentMethodCode: '',
2398
2364
  amount: ((_this$store$currentOr21 = this.store.currentOrder) === null || _this$store$currentOr21 === void 0 ? void 0 : _this$store$currentOr21.total_amount) || '0',
@@ -2430,7 +2396,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2430
2396
  return this.handleError(error instanceof Error ? error : new Error(String(error)), CheckoutErrorType.PaymentFailed);
2431
2397
  case 3:
2432
2398
  _context27.next = 5;
2433
- return this.core.effects.emit(CheckoutHooks.OnPaymentFailed, {
2399
+ return this.core.effects.emit("".concat(this.name, ":onPaymentFailed"), {
2434
2400
  orderUuid: data.orderUuid,
2435
2401
  paymentMethodCode: '',
2436
2402
  amount: ((_this$store$currentOr22 = this.store.currentOrder) === null || _this$store$currentOr22 === void 0 ? void 0 : _this$store$currentOr22.total_amount) || '0',
@@ -2776,237 +2742,117 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2776
2742
  return cleanupExpiredOrdersAsync;
2777
2743
  }()
2778
2744
  /**
2779
- * 清除计算缓存
2745
+ * 计算已支付金额(从 Payment 模块获取最新数据)
2780
2746
  */
2781
2747
  )
2782
2748
  }, {
2783
- key: "clearCalculationCache",
2784
- value: function clearCalculationCache() {
2785
- this.calculationCache = {};
2786
- }
2787
-
2788
- /**
2789
- * 批量获取订单数据(用于性能优化)
2790
- * 一次性获取所有需要的数据,避免重复查询
2791
- */
2792
- }, {
2793
- key: "fetchOrderDataBatch",
2749
+ key: "calculatePaidAmountAsync",
2794
2750
  value: (function () {
2795
- var _fetchOrderDataBatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2796
- var orderUuid, now, cacheValid, _yield$Promise$all, _yield$Promise$all2, paymentItems, currentOrder;
2751
+ var _calculatePaidAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2752
+ var payments, paidAmount, result;
2797
2753
  return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2798
2754
  while (1) switch (_context31.prev = _context31.next) {
2799
2755
  case 0:
2800
2756
  if (this.store.currentOrder) {
2801
- _context31.next = 2;
2802
- break;
2803
- }
2804
- return _context31.abrupt("return", {
2805
- paymentItems: [],
2806
- currentOrder: null
2807
- });
2808
- case 2:
2809
- orderUuid = this.store.currentOrder.uuid; // 检查缓存是否有效(5秒内的缓存认为有效)
2810
- now = Date.now();
2811
- cacheValid = this.calculationCache.orderUuid === orderUuid && this.calculationCache.timestamp && now - this.calculationCache.timestamp < 5000;
2812
- if (!(cacheValid && this.calculationCache.paymentItems && this.calculationCache.currentOrder)) {
2813
- _context31.next = 7;
2814
- break;
2815
- }
2816
- return _context31.abrupt("return", {
2817
- paymentItems: this.calculationCache.paymentItems,
2818
- currentOrder: this.calculationCache.currentOrder
2819
- });
2820
- case 7:
2821
- _context31.next = 9;
2822
- return Promise.all([this.payment.getPaymentItemsAsync(orderUuid, false), this.payment.getPaymentOrderByUuidAsync(orderUuid)]);
2823
- case 9:
2824
- _yield$Promise$all = _context31.sent;
2825
- _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
2826
- paymentItems = _yield$Promise$all2[0];
2827
- currentOrder = _yield$Promise$all2[1];
2828
- // 更新缓存
2829
- this.calculationCache = {
2830
- paymentItems: paymentItems,
2831
- currentOrder: currentOrder,
2832
- orderUuid: orderUuid,
2833
- timestamp: now
2834
- };
2835
- return _context31.abrupt("return", {
2836
- paymentItems: paymentItems,
2837
- currentOrder: currentOrder
2838
- });
2839
- case 15:
2840
- case "end":
2841
- return _context31.stop();
2842
- }
2843
- }, _callee31, this);
2844
- }));
2845
- function fetchOrderDataBatch() {
2846
- return _fetchOrderDataBatch.apply(this, arguments);
2847
- }
2848
- return fetchOrderDataBatch;
2849
- }()
2850
- /**
2851
- * 从支付项数组计算已支付金额(纯计算,不查询数据库)
2852
- */
2853
- )
2854
- }, {
2855
- key: "calculatePaidAmountFromItems",
2856
- value: function calculatePaidAmountFromItems(payments) {
2857
- // 使用 Decimal.js 进行安全的金额计算
2858
- var paidAmount = payments.filter(function (payment) {
2859
- return payment.status !== 'voided';
2860
- }) // 只计算未撤销的支付项
2861
- .reduce(function (sum, payment) {
2862
- var amount = new Decimal(payment.amount || '0');
2863
- var roundingAmount = new Decimal(payment.rounding_amount || '0');
2864
-
2865
- // 使用 Decimal.js 计算实际支付有效金额:
2866
- // 当 rounding_amount 为负数时,表示抹掉的金额,应该按绝对值加到实际支付中
2867
- // 例如:amount=15, rounding_amount=-0.2,实际相当于支付了15.2(抹掉了0.2元的零头)
2868
- var effectiveAmount = amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
2869
- return sum.add(effectiveAmount);
2870
- }, new Decimal(0));
2871
- return paidAmount.toFixed(2);
2872
- }
2873
-
2874
- /**
2875
- * 计算已支付金额(从 Payment 模块获取最新数据)
2876
- *
2877
- * 注意:此方法保持独立性,可以单独调用。
2878
- * 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
2879
- */
2880
- }, {
2881
- key: "calculatePaidAmountAsync",
2882
- value: (function () {
2883
- var _calculatePaidAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2884
- var now, cacheValid, payments, result;
2885
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2886
- while (1) switch (_context32.prev = _context32.next) {
2887
- case 0:
2888
- if (this.store.currentOrder) {
2889
- _context32.next = 3;
2757
+ _context31.next = 3;
2890
2758
  break;
2891
2759
  }
2892
2760
  this.logWarning('[Checkout] calculatePaidAmountAsync: 没有当前订单');
2893
- return _context32.abrupt("return", '0.00');
2761
+ return _context31.abrupt("return", '0.00');
2894
2762
  case 3:
2895
- _context32.prev = 3;
2896
- // 检查是否有缓存的已支付金额
2897
- now = Date.now();
2898
- cacheValid = this.calculationCache.orderUuid === this.store.currentOrder.uuid && this.calculationCache.timestamp && now - this.calculationCache.timestamp < 5000 && this.calculationCache.paidAmount;
2899
- if (!(cacheValid && this.calculationCache.paidAmount)) {
2900
- _context32.next = 8;
2901
- break;
2902
- }
2903
- return _context32.abrupt("return", this.calculationCache.paidAmount);
2904
- case 8:
2905
- _context32.next = 10;
2763
+ _context31.prev = 3;
2764
+ _context31.next = 6;
2906
2765
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
2907
2766
  );
2908
- case 10:
2909
- payments = _context32.sent;
2910
- result = this.calculatePaidAmountFromItems(payments); // 更新缓存
2911
- this.calculationCache.paidAmount = result;
2767
+ case 6:
2768
+ payments = _context31.sent;
2769
+ // 使用 Decimal.js 进行安全的金额计算
2770
+ paidAmount = payments.filter(function (payment) {
2771
+ return payment.status !== 'voided';
2772
+ }) // 只计算未撤销的支付项
2773
+ .reduce(function (sum, payment) {
2774
+ var amount = new Decimal(payment.amount || '0');
2775
+ var roundingAmount = new Decimal(payment.rounding_amount || '0');
2776
+
2777
+ // 使用 Decimal.js 计算实际支付有效金额:
2778
+ // 当 rounding_amount 为负数时,表示抹掉的金额,应该按绝对值加到实际支付中
2779
+ // 例如:amount=15, rounding_amount=-0.2,实际相当于支付了15.2(抹掉了0.2元的零头)
2780
+ var effectiveAmount = amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
2781
+ console.log("[Checkout] \u8BA1\u7B97\u652F\u4ED8\u9879: ".concat(payment.code), {
2782
+ originalAmount: amount.toFixed(2),
2783
+ roundingAmount: roundingAmount.toFixed(2),
2784
+ effectiveAmount: effectiveAmount.toFixed(2),
2785
+ description: !roundingAmount.isZero() ? "\u62B9\u96F6\u91D1\u989D ".concat(roundingAmount.toFixed(2), " \u5143\uFF0C\u6709\u6548\u652F\u4ED8\u589E\u52A0 ").concat(roundingAmount.abs().toFixed(2), " \u5143") : '无抹零',
2786
+ // Decimal 精度验证
2787
+ preciseCalculationValues: {
2788
+ amount: amount.toString(),
2789
+ roundingAmount: roundingAmount.toString(),
2790
+ effectiveAmount: effectiveAmount.toString()
2791
+ }
2792
+ });
2793
+ return sum.add(effectiveAmount);
2794
+ }, new Decimal(0));
2795
+ result = paidAmount.toFixed(2);
2912
2796
  this.logInfo('calculatePaidAmountAsync: 计算结果 =', result);
2913
- return _context32.abrupt("return", result);
2797
+ return _context31.abrupt("return", result);
2798
+ case 13:
2799
+ _context31.prev = 13;
2800
+ _context31.t0 = _context31["catch"](3);
2801
+ this.logError('calculatePaidAmountAsync 失败:', _context31.t0);
2802
+ return _context31.abrupt("return", '0.00');
2914
2803
  case 17:
2915
- _context32.prev = 17;
2916
- _context32.t0 = _context32["catch"](3);
2917
- this.logError('calculatePaidAmountAsync 失败:', _context32.t0);
2918
- return _context32.abrupt("return", '0.00');
2919
- case 21:
2920
2804
  case "end":
2921
- return _context32.stop();
2805
+ return _context31.stop();
2922
2806
  }
2923
- }, _callee32, this, [[3, 17]]);
2807
+ }, _callee31, this, [[3, 13]]);
2924
2808
  }));
2925
2809
  function calculatePaidAmountAsync() {
2926
2810
  return _calculatePaidAmountAsync.apply(this, arguments);
2927
2811
  }
2928
2812
  return calculatePaidAmountAsync;
2929
2813
  }()
2930
- /**
2931
- * 从订单和支付项计算剩余金额(纯计算,不查询数据库)
2932
- */
2933
- )
2934
- }, {
2935
- key: "calculateRemainingAmountFromData",
2936
- value: function calculateRemainingAmountFromData(currentOrder, paidAmount) {
2937
- // 使用 Decimal.js 进行安全的金额计算
2938
- var totalAmount = new Decimal(currentOrder.total_amount || '0');
2939
-
2940
- // 如果是定金订单,使用定金金额
2941
- if (currentOrder.is_deposit && currentOrder.deposit_amount && Number(currentOrder.deposit_amount) > 0) {
2942
- totalAmount = new Decimal(currentOrder.deposit_amount);
2943
- }
2944
- var paid = new Decimal(paidAmount);
2945
- var remainingAmount = totalAmount.sub(paid);
2946
-
2947
- // 确保剩余金额不为负数
2948
- return Decimal.max(0, remainingAmount).toFixed(2);
2949
- }
2950
-
2951
- /**
2952
- * 从订单和支付项计算剩余总金额(纯计算,排除定金)
2953
- */
2954
- }, {
2955
- key: "calculateRemainingTotalAmountFromData",
2956
- value: function calculateRemainingTotalAmountFromData(currentOrder, paidAmount) {
2957
- // 始终使用订单总金额,不进行定金相关的计算
2958
- var totalAmount = new Decimal(currentOrder.total_amount || '0');
2959
- var paid = new Decimal(paidAmount);
2960
- var remainingAmount = totalAmount.sub(paid);
2961
-
2962
- // 确保剩余金额不为负数
2963
- return Decimal.max(0, remainingAmount).toFixed(2);
2964
- }
2965
-
2966
2814
  /**
2967
2815
  * 计算剩余未支付金额(从 Payment 模块获取最新数据)
2968
- *
2969
- * 注意:此方法保持独立性,可以单独调用。
2970
- * 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
2971
2816
  */
2817
+ )
2972
2818
  }, {
2973
2819
  key: "calculateRemainingAmountAsync",
2974
2820
  value: (function () {
2975
- var _calculateRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2976
- var _yield$this$fetchOrde, currentOrder, paidAmountStr, result;
2977
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2978
- while (1) switch (_context33.prev = _context33.next) {
2821
+ var _calculateRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2822
+ var totalAmount, currentOrder, paidAmountStr, paidAmount, remainingAmount, result;
2823
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2824
+ while (1) switch (_context32.prev = _context32.next) {
2979
2825
  case 0:
2980
2826
  if (this.store.currentOrder) {
2981
- _context33.next = 3;
2827
+ _context32.next = 3;
2982
2828
  break;
2983
2829
  }
2984
2830
  this.logWarning('calculateRemainingAmountAsync: 没有当前订单');
2985
- return _context33.abrupt("return", '0.00');
2831
+ return _context32.abrupt("return", '0.00');
2986
2832
  case 3:
2987
- _context33.next = 5;
2988
- return this.fetchOrderDataBatch();
2989
- case 5:
2990
- _yield$this$fetchOrde = _context33.sent;
2991
- currentOrder = _yield$this$fetchOrde.currentOrder;
2992
- if (currentOrder) {
2993
- _context33.next = 9;
2994
- break;
2833
+ // 使用 Decimal.js 进行安全的金额计算
2834
+ totalAmount = new Decimal(this.store.currentOrder.total_amount || '0');
2835
+ _context32.next = 6;
2836
+ return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
2837
+ case 6:
2838
+ currentOrder = _context32.sent;
2839
+ if (currentOrder !== null && currentOrder !== void 0 && currentOrder.is_deposit && currentOrder !== null && currentOrder !== void 0 && currentOrder.deposit_amount && Number(currentOrder === null || currentOrder === void 0 ? void 0 : currentOrder.deposit_amount) > 0) {
2840
+ totalAmount = new Decimal(currentOrder === null || currentOrder === void 0 ? void 0 : currentOrder.deposit_amount);
2995
2841
  }
2996
- return _context33.abrupt("return", '0.00');
2997
- case 9:
2998
- _context33.next = 11;
2842
+ _context32.next = 10;
2999
2843
  return this.calculatePaidAmountAsync();
3000
- case 11:
3001
- paidAmountStr = _context33.sent;
3002
- result = this.calculateRemainingAmountFromData(currentOrder, paidAmountStr);
2844
+ case 10:
2845
+ paidAmountStr = _context32.sent;
2846
+ paidAmount = new Decimal(paidAmountStr);
2847
+ remainingAmount = totalAmount.sub(paidAmount); // 确保剩余金额不为负数
2848
+ result = Decimal.max(0, remainingAmount).toFixed(2);
3003
2849
  this.logInfo('calculateRemainingAmountAsync: 计算=', result);
3004
- return _context33.abrupt("return", result);
3005
- case 15:
2850
+ return _context32.abrupt("return", result);
2851
+ case 16:
3006
2852
  case "end":
3007
- return _context33.stop();
2853
+ return _context32.stop();
3008
2854
  }
3009
- }, _callee33, this);
2855
+ }, _callee32, this);
3010
2856
  }));
3011
2857
  function calculateRemainingAmountAsync() {
3012
2858
  return _calculateRemainingAmountAsync.apply(this, arguments);
@@ -3015,49 +2861,40 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3015
2861
  }()
3016
2862
  /**
3017
2863
  * 计算剩余未支付金额(排除定金计算,始终使用订单总金额)
3018
- *
3019
- * 注意:此方法保持独立性,可以单独调用。
3020
- * 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
3021
2864
  */
3022
2865
  )
3023
2866
  }, {
3024
2867
  key: "calculateRemainingTotalAmountAsync",
3025
2868
  value: (function () {
3026
- var _calculateRemainingTotalAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
3027
- var _yield$this$fetchOrde2, currentOrder, paidAmountStr, result;
3028
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
3029
- while (1) switch (_context34.prev = _context34.next) {
2869
+ var _calculateRemainingTotalAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2870
+ var totalAmount, paidAmountStr, paidAmount, remainingAmount, result;
2871
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2872
+ while (1) switch (_context33.prev = _context33.next) {
3030
2873
  case 0:
3031
2874
  if (this.store.currentOrder) {
3032
- _context34.next = 3;
2875
+ _context33.next = 3;
3033
2876
  break;
3034
2877
  }
3035
2878
  this.logWarning('calculateRemainingTotalAmountAsync: 没有当前订单');
3036
- return _context34.abrupt("return", '0.00');
2879
+ return _context33.abrupt("return", '0.00');
3037
2880
  case 3:
3038
- _context34.next = 5;
3039
- return this.fetchOrderDataBatch();
3040
- case 5:
3041
- _yield$this$fetchOrde2 = _context34.sent;
3042
- currentOrder = _yield$this$fetchOrde2.currentOrder;
3043
- if (currentOrder) {
3044
- _context34.next = 9;
3045
- break;
3046
- }
3047
- return _context34.abrupt("return", '0.00');
3048
- case 9:
3049
- _context34.next = 11;
2881
+ // 使用 Decimal.js 进行安全的金额计算
2882
+ // 始终使用订单总金额,不进行定金相关的计算
2883
+ totalAmount = new Decimal(this.store.currentOrder.total_amount || '0');
2884
+ _context33.next = 6;
3050
2885
  return this.calculatePaidAmountAsync();
3051
- case 11:
3052
- paidAmountStr = _context34.sent;
3053
- result = this.calculateRemainingTotalAmountFromData(currentOrder, paidAmountStr);
2886
+ case 6:
2887
+ paidAmountStr = _context33.sent;
2888
+ paidAmount = new Decimal(paidAmountStr);
2889
+ remainingAmount = totalAmount.sub(paidAmount); // 确保剩余金额不为负数
2890
+ result = Decimal.max(0, remainingAmount).toFixed(2);
3054
2891
  this.logInfo('calculateRemainingTotalAmountAsync: 计算=', result);
3055
- return _context34.abrupt("return", result);
3056
- case 15:
2892
+ return _context33.abrupt("return", result);
2893
+ case 12:
3057
2894
  case "end":
3058
- return _context34.stop();
2895
+ return _context33.stop();
3059
2896
  }
3060
- }, _callee34, this);
2897
+ }, _callee33, this);
3061
2898
  }));
3062
2899
  function calculateRemainingTotalAmountAsync() {
3063
2900
  return _calculateRemainingTotalAmountAsync.apply(this, arguments);
@@ -3071,30 +2908,30 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3071
2908
  }, {
3072
2909
  key: "updateBalanceDueAmount",
3073
2910
  value: (function () {
3074
- var _updateBalanceDueAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
2911
+ var _updateBalanceDueAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
3075
2912
  var remainingAmount, remainingTotalAmount, currentBalanceDueAmount;
3076
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3077
- while (1) switch (_context35.prev = _context35.next) {
2913
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2914
+ while (1) switch (_context34.prev = _context34.next) {
3078
2915
  case 0:
3079
- _context35.prev = 0;
3080
- _context35.next = 3;
2916
+ _context34.prev = 0;
2917
+ _context34.next = 3;
3081
2918
  return this.calculateRemainingAmountAsync();
3082
2919
  case 3:
3083
- remainingAmount = _context35.sent;
3084
- _context35.next = 6;
2920
+ remainingAmount = _context34.sent;
2921
+ _context34.next = 6;
3085
2922
  return this.calculateRemainingTotalAmountAsync();
3086
2923
  case 6:
3087
- remainingTotalAmount = _context35.sent;
2924
+ remainingTotalAmount = _context34.sent;
3088
2925
  currentBalanceDueAmount = this.store.balanceDueAmount; // 只有当剩余金额与当前 balanceDueAmount 不同时才更新
3089
2926
  if (!(remainingAmount !== currentBalanceDueAmount)) {
3090
- _context35.next = 15;
2927
+ _context34.next = 15;
3091
2928
  break;
3092
2929
  }
3093
2930
  this.store.balanceDueAmount = remainingAmount;
3094
2931
 
3095
2932
  // 发出 balanceDueAmount 变更事件
3096
- _context35.next = 12;
3097
- return this.core.effects.emit(CheckoutHooks.OnBalanceDueAmountChanged, {
2933
+ _context34.next = 12;
2934
+ return this.core.effects.emit("".concat(this.name, ":onBalanceDueAmountChanged"), {
3098
2935
  oldAmount: currentBalanceDueAmount,
3099
2936
  newAmount: remainingAmount,
3100
2937
  timestamp: Date.now(),
@@ -3105,7 +2942,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3105
2942
  oldAmount: currentBalanceDueAmount,
3106
2943
  newAmount: remainingAmount
3107
2944
  });
3108
- _context35.next = 16;
2945
+ _context34.next = 16;
3109
2946
  break;
3110
2947
  case 15:
3111
2948
  this.logInfo('balanceDueAmount 无需更新,当前值已是最新:', {
@@ -3113,17 +2950,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3113
2950
  remainingAmount: remainingAmount
3114
2951
  });
3115
2952
  case 16:
3116
- _context35.next = 21;
2953
+ _context34.next = 21;
3117
2954
  break;
3118
2955
  case 18:
3119
- _context35.prev = 18;
3120
- _context35.t0 = _context35["catch"](0);
3121
- this.logError('更新 balanceDueAmount 失败:', _context35.t0);
2956
+ _context34.prev = 18;
2957
+ _context34.t0 = _context34["catch"](0);
2958
+ this.logError('更新 balanceDueAmount 失败:', _context34.t0);
3122
2959
  case 21:
3123
2960
  case "end":
3124
- return _context35.stop();
2961
+ return _context34.stop();
3125
2962
  }
3126
- }, _callee35, this, [[0, 18]]);
2963
+ }, _callee34, this, [[0, 18]]);
3127
2964
  }));
3128
2965
  function updateBalanceDueAmount() {
3129
2966
  return _updateBalanceDueAmount.apply(this, arguments);
@@ -3132,323 +2969,156 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3132
2969
  }()
3133
2970
  /**
3134
2971
  * 更新 stateAmount 为当前剩余未支付金额
3135
- *
3136
- * 优化版本:批量获取数据,避免重复查询数据库
3137
2972
  */
3138
2973
  )
3139
2974
  }, {
3140
2975
  key: "updateStateAmountToRemaining",
3141
2976
  value: (function () {
3142
- var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
3143
- var _this4 = this;
2977
+ var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
3144
2978
  var checkOrder,
3145
- _yield$this$fetchOrde3,
2979
+ _this$store$currentOr23,
2980
+ _this$store$currentOr24,
2981
+ _this$store$currentOr25,
3146
2982
  paymentItems,
3147
- _currentOrder3,
3148
- paidAmount,
3149
- needUpdateDepositStatus,
3150
2983
  depositPaidAmount,
2984
+ _this$store$currentOr26,
3151
2985
  remainingAmount,
3152
2986
  remainingTotalAmount,
3153
2987
  currentStateAmount,
3154
- currentBalanceDueAmount,
3155
- hasStateChanged,
3156
- _args36 = arguments;
3157
- return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3158
- while (1) switch (_context36.prev = _context36.next) {
2988
+ _args35 = arguments;
2989
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2990
+ while (1) switch (_context35.prev = _context35.next) {
3159
2991
  case 0:
3160
- checkOrder = _args36.length > 0 && _args36[0] !== undefined ? _args36[0] : true;
3161
- _context36.prev = 1;
3162
- if (this.store.currentOrder) {
3163
- _context36.next = 4;
2992
+ checkOrder = _args35.length > 0 && _args35[0] !== undefined ? _args35[0] : true;
2993
+ _context35.prev = 1;
2994
+ if (!(((_this$store$currentOr23 = this.store.currentOrder) === null || _this$store$currentOr23 === void 0 ? void 0 : _this$store$currentOr23.is_deposit) === 1)) {
2995
+ _context35.next = 11;
3164
2996
  break;
3165
2997
  }
3166
- return _context36.abrupt("return");
3167
- case 4:
3168
- console.time('updateStateAmountToRemaining');
3169
- // 🚀 性能优化:一次性批量获取所有需要的数据
3170
- _context36.next = 7;
3171
- return this.fetchOrderDataBatch();
3172
- case 7:
3173
- _yield$this$fetchOrde3 = _context36.sent;
3174
- paymentItems = _yield$this$fetchOrde3.paymentItems;
3175
- _currentOrder3 = _yield$this$fetchOrde3.currentOrder;
3176
- console.timeEnd('updateStateAmountToRemaining');
3177
- if (_currentOrder3) {
3178
- _context36.next = 14;
3179
- break;
3180
- }
3181
- this.logWarning('updateStateAmountToRemaining: 未找到当前订单');
3182
- return _context36.abrupt("return");
3183
- case 14:
3184
- // 🚀 性能优化:一次性计算所有金额(纯计算,不查询数据库)
3185
- paidAmount = this.calculatePaidAmountFromItems(paymentItems); // 缓存已支付金额,供其他方法使用
3186
- this.calculationCache.paidAmount = paidAmount;
3187
-
3188
- // 检查定金支付状态,可能需要切换支付模式
3189
- needUpdateDepositStatus = false;
3190
- if (_currentOrder3.is_deposit === 1) {
3191
- depositPaidAmount = paymentItems.filter(function (item) {
3192
- return item.order_payment_type === 'deposit' && item.status !== 'voided';
3193
- }).reduce(function (sum, item) {
3194
- // 如果是 wallet,并且还没同步到后端,则不计入这一部分金额
3195
- if (item.voucher_id && !item.isSynced) {
3196
- return sum;
3197
- }
3198
- var amount = new Decimal(item.amount || '0');
3199
- var roundingAmount = new Decimal(item.rounding_amount || '0');
3200
- return sum.add(amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0));
3201
- }, new Decimal(0));
3202
- if (depositPaidAmount.gte(_currentOrder3.deposit_amount || '0')) {
3203
- needUpdateDepositStatus = true;
3204
- // 更新缓存中的订单状态
3205
- _currentOrder3.is_deposit = 0;
2998
+ _context35.next = 5;
2999
+ return this.payment.getPaymentItemsAsync((_this$store$currentOr24 = this.store.currentOrder) === null || _this$store$currentOr24 === void 0 ? void 0 : _this$store$currentOr24.uuid);
3000
+ case 5:
3001
+ paymentItems = _context35.sent;
3002
+ depositPaidAmount = paymentItems.filter(function (item) {
3003
+ return item.order_payment_type === 'deposit' && item.status !== 'voided';
3004
+ }).reduce(function (sum, item) {
3005
+ // 如果是 wallet,并且还没同步到后端,则不计入这一部分金额
3006
+ if (item.voucher_id && !item.isSynced) {
3007
+ return sum;
3206
3008
  }
3207
- }
3208
-
3209
- // 计算剩余金额(使用缓存的数据)
3210
- remainingAmount = this.calculateRemainingAmountFromData(_currentOrder3, paidAmount);
3211
- remainingTotalAmount = this.calculateRemainingTotalAmountFromData(_currentOrder3, paidAmount);
3212
- currentStateAmount = this.store.stateAmount;
3213
- currentBalanceDueAmount = this.store.balanceDueAmount; // 批量更新状态,减少操作次数
3214
- hasStateChanged = false; // 如果需要更新定金状态
3215
- if (!needUpdateDepositStatus) {
3216
- _context36.next = 28;
3009
+ var amount = new Decimal(item.amount || '0');
3010
+ var roundingAmount = new Decimal(item.rounding_amount || '0');
3011
+ return sum.add(amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0));
3012
+ }, new Decimal(0));
3013
+ if (!depositPaidAmount.gte((_this$store$currentOr25 = this.store.currentOrder) === null || _this$store$currentOr25 === void 0 ? void 0 : _this$store$currentOr25.deposit_amount)) {
3014
+ _context35.next = 11;
3217
3015
  break;
3218
3016
  }
3219
3017
  this.store.currentOrder = _objectSpread(_objectSpread({}, this.store.currentOrder), {}, {
3220
3018
  is_deposit: 0
3221
3019
  });
3222
- _context36.next = 27;
3223
- return this.payment.updateOrderAsync(this.store.currentOrder.uuid, {
3020
+ _context35.next = 11;
3021
+ return this.payment.updateOrderAsync((_this$store$currentOr26 = this.store.currentOrder) === null || _this$store$currentOr26 === void 0 ? void 0 : _this$store$currentOr26.uuid, {
3224
3022
  is_deposit: 0
3225
3023
  });
3226
- case 27:
3227
- hasStateChanged = true;
3228
- case 28:
3229
- console.time('updateStateAmountToRemaining: remainingAmount');
3230
- // 更新 stateAmount
3024
+ case 11:
3025
+ _context35.next = 13;
3026
+ return this.calculateRemainingAmountAsync();
3027
+ case 13:
3028
+ remainingAmount = _context35.sent;
3029
+ _context35.next = 16;
3030
+ return this.calculateRemainingTotalAmountAsync();
3031
+ case 16:
3032
+ remainingTotalAmount = _context35.sent;
3033
+ currentStateAmount = this.store.stateAmount; // 只有当剩余金额与当前 stateAmount 不同时才更新
3231
3034
  if (remainingAmount !== currentStateAmount) {
3232
3035
  this.store.stateAmount = remainingAmount;
3233
- hasStateChanged = true;
3234
- setTimeout(function () {
3235
- // 发出 stateAmount 变更事件
3236
- _this4.core.effects.emit("".concat(_this4.name, ":onStateAmountChanged"), {
3237
- oldAmount: currentStateAmount,
3238
- newAmount: remainingAmount,
3239
- timestamp: Date.now(),
3240
- totalAmount: remainingTotalAmount
3241
- });
3242
- }, 0);
3243
- this.logInfo('stateAmount 已自动更新为剩余金额:', {
3036
+
3037
+ // 发出 stateAmount 变更事件
3038
+ this.core.effects.emit("".concat(this.name, ":onStateAmountChanged"), {
3244
3039
  oldAmount: currentStateAmount,
3245
- newAmount: remainingAmount
3040
+ newAmount: remainingAmount,
3041
+ timestamp: Date.now(),
3042
+ totalAmount: remainingTotalAmount
3246
3043
  });
3247
- }
3248
- console.timeEnd('updateStateAmountToRemaining: remainingAmount');
3249
- console.time('updateStateAmountToRemaining: updateStateAmountToRemaining');
3250
- // 更新 balanceDueAmount
3251
- if (remainingAmount !== currentBalanceDueAmount) {
3252
- this.store.balanceDueAmount = remainingAmount;
3253
- hasStateChanged = true;
3254
-
3255
- // 发出 balanceDueAmount 变更事件
3256
- setTimeout(function () {
3257
- _this4.core.effects.emit("".concat(_this4.name, ":onBalanceDueAmountChanged"), {
3258
- oldAmount: currentBalanceDueAmount,
3259
- newAmount: remainingAmount,
3260
- timestamp: Date.now(),
3261
- totalAmount: remainingTotalAmount
3262
- });
3263
- }, 0);
3264
- this.logInfo('balanceDueAmount 已自动更新:', {
3265
- oldAmount: currentBalanceDueAmount,
3044
+ this.logInfo('stateAmount 已自动更新为剩余金额:', {
3045
+ oldAmount: currentStateAmount,
3266
3046
  newAmount: remainingAmount
3267
3047
  });
3268
- }
3269
- console.timeEnd('updateStateAmountToRemaining: updateStateAmountToRemaining');
3270
- if (!hasStateChanged) {
3271
- this.logInfo('状态无需更新,当前值已是最新:', {
3048
+ } else {
3049
+ this.logInfo('stateAmount 无需更新,当前值已是最新:', {
3272
3050
  stateAmount: currentStateAmount,
3273
3051
  remainingAmount: remainingAmount
3274
3052
  });
3275
3053
  }
3276
-
3277
- // 检查订单支付完成(复用已获取的数据)
3054
+ // 同步更新系统内部的 balanceDueAmount
3055
+ _context35.next = 21;
3056
+ return this.updateBalanceDueAmount();
3057
+ case 21:
3278
3058
  if (!checkOrder) {
3279
- _context36.next = 40;
3059
+ _context35.next = 26;
3280
3060
  break;
3281
3061
  }
3282
- _context36.next = 38;
3283
- return this.checkOrderPaymentCompletionOptimized(paymentItems, remainingAmount);
3284
- case 38:
3285
- _context36.next = 41;
3062
+ _context35.next = 24;
3063
+ return this.checkOrderPaymentCompletion();
3064
+ case 24:
3065
+ _context35.next = 27;
3286
3066
  break;
3287
- case 40:
3067
+ case 26:
3288
3068
  this.logInfo('外部传入无需 checkOrder,不执行订单支付完成检测和同步');
3289
- case 41:
3290
- _context36.next = 46;
3069
+ case 27:
3070
+ _context35.next = 32;
3291
3071
  break;
3292
- case 43:
3293
- _context36.prev = 43;
3294
- _context36.t0 = _context36["catch"](1);
3295
- this.logError('更新 stateAmount 为剩余金额失败:', _context36.t0);
3296
- case 46:
3072
+ case 29:
3073
+ _context35.prev = 29;
3074
+ _context35.t0 = _context35["catch"](1);
3075
+ this.logError('更新 stateAmount 为剩余金额失败:', _context35.t0);
3076
+ case 32:
3297
3077
  case "end":
3298
- return _context36.stop();
3078
+ return _context35.stop();
3299
3079
  }
3300
- }, _callee36, this, [[1, 43]]);
3080
+ }, _callee35, this, [[1, 29]]);
3301
3081
  }));
3302
3082
  function updateStateAmountToRemaining() {
3303
3083
  return _updateStateAmountToRemaining.apply(this, arguments);
3304
3084
  }
3305
3085
  return updateStateAmountToRemaining;
3306
3086
  }()
3307
- /**
3308
- * 检查订单支付是否完成(优化版,复用已获取的数据)
3309
- *
3310
- * @param paymentItems 已获取的支付项数据
3311
- * @param remainingAmount 已计算的剩余金额
3312
- */
3313
- )
3314
- }, {
3315
- key: "checkOrderPaymentCompletionOptimized",
3316
- value: (function () {
3317
- var _checkOrderPaymentCompletionOptimized = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(paymentItems, remainingAmount) {
3318
- var remainingValue, totalAmount, paidAmount, hasPaymentItems, allPaymentsHaveVoucherId, shouldAutoSync;
3319
- return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3320
- while (1) switch (_context37.prev = _context37.next) {
3321
- case 0:
3322
- _context37.prev = 0;
3323
- if (this.store.currentOrder) {
3324
- _context37.next = 3;
3325
- break;
3326
- }
3327
- return _context37.abrupt("return");
3328
- case 3:
3329
- remainingValue = new Decimal(remainingAmount); // 当剩余金额小于等于0时,认为订单已完成支付
3330
- if (!remainingValue.lte(0)) {
3331
- _context37.next = 21;
3332
- break;
3333
- }
3334
- totalAmount = this.store.currentOrder.total_amount;
3335
- paidAmount = this.calculationCache.paidAmount || '0.00';
3336
- this.logInfo('检测到订单支付完成:', {
3337
- orderUuid: this.store.currentOrder.uuid,
3338
- orderId: this.store.currentOrder.order_id,
3339
- totalAmount: totalAmount,
3340
- paidAmount: paidAmount,
3341
- remainingAmount: remainingAmount,
3342
- isOrderSynced: this.store.isOrderSynced
3343
- });
3344
-
3345
- // 检查自动同步条件(复用已获取的支付项数据)
3346
- hasPaymentItems = paymentItems.length > 0;
3347
- allPaymentsHaveVoucherId = hasPaymentItems && paymentItems.every(function (item) {
3348
- return item.status !== 'voided' && item.voucher_id;
3349
- });
3350
- shouldAutoSync = hasPaymentItems && !allPaymentsHaveVoucherId;
3351
- this.logInfo('自动同步订单条件检查:', {
3352
- paymentCount: paymentItems.length,
3353
- hasPaymentItems: hasPaymentItems,
3354
- allHaveVoucherId: allPaymentsHaveVoucherId,
3355
- isOrderSynced: this.store.isOrderSynced,
3356
- shouldAutoSync: shouldAutoSync,
3357
- reason: shouldAutoSync ? '支付完成,需要同步最终支付状态' : '跳过同步',
3358
- paymentItems: paymentItems.map(function (p) {
3359
- return {
3360
- uuid: p.uuid,
3361
- code: p.code,
3362
- amount: p.amount,
3363
- rounding_amount: p.rounding_amount,
3364
- effective_amount: (parseFloat(p.amount || '0') + Math.abs(parseFloat(Number(p.rounding_amount) > 0 ? '0' : p.rounding_amount || '0'))).toFixed(2),
3365
- voucher_id: p.voucher_id,
3366
- status: p.status
3367
- };
3368
- })
3369
- });
3370
- if (!shouldAutoSync) {
3371
- _context37.next = 18;
3372
- break;
3373
- }
3374
- this.logInfo('满足自动同步条件,开始同步订单到后端...');
3375
- _context37.next = 16;
3376
- return this.syncOrderToBackendWithReturn(false);
3377
- case 16:
3378
- _context37.next = 19;
3379
- break;
3380
- case 18:
3381
- if (!hasPaymentItems) {
3382
- this.logInfo('没有支付项,跳过订单同步');
3383
- } else if (allPaymentsHaveVoucherId) {
3384
- this.logInfo('所有支付项均为代金券类型,跳过订单同步');
3385
- }
3386
- case 19:
3387
- _context37.next = 21;
3388
- return this.core.effects.emit("".concat(this.name, ":onOrderPaymentCompleted"), {
3389
- orderUuid: this.store.currentOrder.uuid,
3390
- orderId: this.store.currentOrder.order_id,
3391
- totalAmount: totalAmount,
3392
- paidAmount: paidAmount,
3393
- remainingAmount: remainingAmount,
3394
- timestamp: Date.now()
3395
- });
3396
- case 21:
3397
- _context37.next = 26;
3398
- break;
3399
- case 23:
3400
- _context37.prev = 23;
3401
- _context37.t0 = _context37["catch"](0);
3402
- this.logError('检查订单支付完成状态失败:', _context37.t0);
3403
- case 26:
3404
- case "end":
3405
- return _context37.stop();
3406
- }
3407
- }, _callee37, this, [[0, 23]]);
3408
- }));
3409
- function checkOrderPaymentCompletionOptimized(_x27, _x28) {
3410
- return _checkOrderPaymentCompletionOptimized.apply(this, arguments);
3411
- }
3412
- return checkOrderPaymentCompletionOptimized;
3413
- }()
3414
3087
  /**
3415
3088
  * 检查订单支付是否完成
3416
3089
  *
3417
3090
  * 当剩余待付款金额 <= 0 时,触发订单支付完成事件
3418
- *
3419
- * 注意:此方法保持独立性,可以单独调用。
3420
- * 在 updateStateAmountToRemaining 中会使用优化版本。
3421
3091
  */
3422
3092
  )
3423
3093
  }, {
3424
3094
  key: "checkOrderPaymentCompletion",
3425
3095
  value: (function () {
3426
- var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38() {
3096
+ var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
3427
3097
  var remainingAmount, remainingValue, totalAmount, paidAmount, currentPayments, hasPaymentItems, allPaymentsHaveVoucherId, shouldAutoSync;
3428
- return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3429
- while (1) switch (_context38.prev = _context38.next) {
3098
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3099
+ while (1) switch (_context36.prev = _context36.next) {
3430
3100
  case 0:
3431
- _context38.prev = 0;
3101
+ _context36.prev = 0;
3432
3102
  if (this.store.currentOrder) {
3433
- _context38.next = 3;
3103
+ _context36.next = 3;
3434
3104
  break;
3435
3105
  }
3436
- return _context38.abrupt("return");
3106
+ return _context36.abrupt("return");
3437
3107
  case 3:
3438
- _context38.next = 5;
3108
+ _context36.next = 5;
3439
3109
  return this.calculateRemainingAmountAsync();
3440
3110
  case 5:
3441
- remainingAmount = _context38.sent;
3111
+ remainingAmount = _context36.sent;
3442
3112
  remainingValue = new Decimal(remainingAmount); // 当剩余金额小于等于0时,认为订单已完成支付
3443
3113
  if (!remainingValue.lte(0)) {
3444
- _context38.next = 29;
3114
+ _context36.next = 29;
3445
3115
  break;
3446
3116
  }
3447
3117
  totalAmount = this.store.currentOrder.total_amount;
3448
- _context38.next = 11;
3118
+ _context36.next = 11;
3449
3119
  return this.calculatePaidAmountAsync();
3450
3120
  case 11:
3451
- paidAmount = _context38.sent;
3121
+ paidAmount = _context36.sent;
3452
3122
  this.logInfo('检测到订单支付完成:', {
3453
3123
  orderUuid: this.store.currentOrder.uuid,
3454
3124
  orderId: this.store.currentOrder.order_id,
@@ -3459,11 +3129,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3459
3129
  });
3460
3130
 
3461
3131
  // 从 Payment 模块获取最新支付项,检查自动同步条件
3462
- _context38.next = 15;
3132
+ _context36.next = 15;
3463
3133
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
3464
3134
  );
3465
3135
  case 15:
3466
- currentPayments = _context38.sent;
3136
+ currentPayments = _context36.sent;
3467
3137
  // 检查自动同步条件:
3468
3138
  // 1. 待付金额为 0 ✓ (已在上面检查)
3469
3139
  // 2. 需要有支付项
@@ -3497,14 +3167,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3497
3167
  })
3498
3168
  });
3499
3169
  if (!shouldAutoSync) {
3500
- _context38.next = 26;
3170
+ _context36.next = 26;
3501
3171
  break;
3502
3172
  }
3503
3173
  this.logInfo('满足自动同步条件,开始同步订单到后端...');
3504
- _context38.next = 24;
3174
+ _context36.next = 24;
3505
3175
  return this.syncOrderToBackendWithReturn(false);
3506
3176
  case 24:
3507
- _context38.next = 27;
3177
+ _context36.next = 27;
3508
3178
  break;
3509
3179
  case 26:
3510
3180
  if (!hasPaymentItems) {
@@ -3513,8 +3183,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3513
3183
  this.logInfo('所有支付项均为代金券类型,跳过订单同步');
3514
3184
  }
3515
3185
  case 27:
3516
- _context38.next = 29;
3517
- return this.core.effects.emit(CheckoutHooks.OnOrderPaymentCompleted, {
3186
+ _context36.next = 29;
3187
+ return this.core.effects.emit("".concat(this.name, ":onOrderPaymentCompleted"), {
3518
3188
  orderUuid: this.store.currentOrder.uuid,
3519
3189
  orderId: this.store.currentOrder.order_id,
3520
3190
  totalAmount: totalAmount,
@@ -3523,17 +3193,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3523
3193
  timestamp: Date.now()
3524
3194
  });
3525
3195
  case 29:
3526
- _context38.next = 34;
3196
+ _context36.next = 34;
3527
3197
  break;
3528
3198
  case 31:
3529
- _context38.prev = 31;
3530
- _context38.t0 = _context38["catch"](0);
3531
- this.logError('检查订单支付完成状态失败:', _context38.t0);
3199
+ _context36.prev = 31;
3200
+ _context36.t0 = _context36["catch"](0);
3201
+ this.logError('检查订单支付完成状态失败:', _context36.t0);
3532
3202
  case 34:
3533
3203
  case "end":
3534
- return _context38.stop();
3204
+ return _context36.stop();
3535
3205
  }
3536
- }, _callee38, this, [[0, 31]]);
3206
+ }, _callee36, this, [[0, 31]]);
3537
3207
  }));
3538
3208
  function checkOrderPaymentCompletion() {
3539
3209
  return _checkOrderPaymentCompletion.apply(this, arguments);
@@ -3551,12 +3221,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3551
3221
  }, {
3552
3222
  key: "syncOrderToBackendWithReturn",
3553
3223
  value: (function () {
3554
- var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
3555
- var _this5 = this,
3556
- _this$store$currentOr23,
3557
- _this$store$currentOr24,
3224
+ var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37() {
3225
+ var _this4 = this,
3226
+ _this$store$currentOr27,
3227
+ _this$store$currentOr28,
3558
3228
  _this$store$currentCu2,
3559
- _this$store$currentOr25,
3229
+ _this$store$currentOr29,
3560
3230
  _this$store$localOrde,
3561
3231
  _this$store$localOrde2,
3562
3232
  _checkoutResponse3,
@@ -3591,14 +3261,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3591
3261
  _iterator3,
3592
3262
  _step3,
3593
3263
  paymentUuid,
3594
- _args39 = arguments;
3595
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3596
- while (1) switch (_context39.prev = _context39.next) {
3264
+ _args37 = arguments;
3265
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3266
+ while (1) switch (_context37.prev = _context37.next) {
3597
3267
  case 0:
3598
- isManual = _args39.length > 0 && _args39[0] !== undefined ? _args39[0] : false;
3599
- customPaymentItems = _args39.length > 1 ? _args39[1] : undefined;
3268
+ isManual = _args37.length > 0 && _args37[0] !== undefined ? _args37[0] : false;
3269
+ customPaymentItems = _args37.length > 1 ? _args37[1] : undefined;
3600
3270
  if (!(!this.store.localOrderData || !this.store.currentOrder)) {
3601
- _context39.next = 4;
3271
+ _context37.next = 4;
3602
3272
  break;
3603
3273
  }
3604
3274
  throw new Error('缺少必要的订单数据,无法同步到后端');
@@ -3617,28 +3287,28 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3617
3287
  });
3618
3288
 
3619
3289
  // 获取当前订单的支付项
3620
- _context39.t0 = customPaymentItems;
3621
- if (_context39.t0) {
3622
- _context39.next = 13;
3290
+ _context37.t0 = customPaymentItems;
3291
+ if (_context37.t0) {
3292
+ _context37.next = 13;
3623
3293
  break;
3624
3294
  }
3625
- _context39.next = 12;
3295
+ _context37.next = 12;
3626
3296
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
3627
3297
  case 12:
3628
- _context39.t0 = _context39.sent;
3298
+ _context37.t0 = _context37.sent;
3629
3299
  case 13:
3630
- paymentItems = _context39.t0;
3300
+ paymentItems = _context37.t0;
3631
3301
  // 处理支付项数据,确保包含完整的 metadata
3632
3302
  processedPaymentItems = paymentItems.map(function (item) {
3633
3303
  var _item$metadata, _item$metadata2;
3634
3304
  return _objectSpread(_objectSpread({}, item), {}, {
3635
3305
  metadata: _objectSpread(_objectSpread({}, item.metadata), {}, {
3636
- rounding_rule: ((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.rounding_rule) || _this5.otherParams.order_rounding_setting,
3637
- shop_wallet_pass_id: ((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.shop_wallet_pass_id) || _this5.otherParams.shop_wallet_pass_id
3306
+ rounding_rule: ((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.rounding_rule) || _this4.otherParams.order_rounding_setting,
3307
+ shop_wallet_pass_id: ((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.shop_wallet_pass_id) || _this4.otherParams.shop_wallet_pass_id
3638
3308
  })
3639
3309
  });
3640
3310
  }); // 确定最终的定金金额:优先使用手动设置的值,否则从支付项中计算
3641
- manualDepositAmount = ((_this$store$currentOr23 = this.store.currentOrder) === null || _this$store$currentOr23 === void 0 ? void 0 : _this$store$currentOr23.deposit_amount) || '0.00'; // 优先级逻辑:手动设置的定金金额 > 从支付项计算的金额
3311
+ manualDepositAmount = ((_this$store$currentOr27 = this.store.currentOrder) === null || _this$store$currentOr27 === void 0 ? void 0 : _this$store$currentOr27.deposit_amount) || '0.00'; // 优先级逻辑:手动设置的定金金额 > 从支付项计算的金额
3642
3312
  manualDepositValue = new Decimal(manualDepositAmount);
3643
3313
  if (manualDepositValue.gt(0)) {
3644
3314
  // 如果手动设置了定金金额且大于0,使用手动设置的值
@@ -3698,7 +3368,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3698
3368
  }),
3699
3369
  manualDepositAmount: manualDepositAmount,
3700
3370
  finalDepositAmount: finalDepositAmount,
3701
- isDeposit: ((_this$store$currentOr24 = this.store.currentOrder) === null || _this$store$currentOr24 === void 0 ? void 0 : _this$store$currentOr24.is_deposit) || 0
3371
+ isDeposit: ((_this$store$currentOr28 = this.store.currentOrder) === null || _this$store$currentOr28 === void 0 ? void 0 : _this$store$currentOr28.is_deposit) || 0
3702
3372
  });
3703
3373
 
3704
3374
  // 构造订单参数,直接使用 localOrderData 中已处理好的数据
@@ -3720,7 +3390,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3720
3390
  currency_code: this.otherParams.currency_code,
3721
3391
  currency_symbol: this.otherParams.currency_symbol,
3722
3392
  currency_format: this.otherParams.currency_format,
3723
- is_deposit: ((_this$store$currentOr25 = this.store.currentOrder) !== null && _this$store$currentOr25 !== void 0 && _this$store$currentOr25.is_deposit || Number(finalDepositAmount) > 0 ? 1 : 0) || 0,
3393
+ is_deposit: ((_this$store$currentOr29 = this.store.currentOrder) !== null && _this$store$currentOr29 !== void 0 && _this$store$currentOr29.is_deposit || Number(finalDepositAmount) > 0 ? 1 : 0) || 0,
3724
3394
  deposit_amount: finalDepositAmount,
3725
3395
  // 使用最终确定的定金金额(手动设置优先)
3726
3396
  product_tax_fee: this.store.localOrderData.tax_fee,
@@ -3751,8 +3421,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3751
3421
 
3752
3422
  // 发送下单接口请求开始事件
3753
3423
  startTime = Date.now();
3754
- _context39.next = 27;
3755
- return this.core.effects.emit(CheckoutHooks.OnOrderSubmitStart, {
3424
+ _context37.next = 27;
3425
+ return this.core.effects.emit("".concat(this.name, ":onOrderSubmitStart"), {
3756
3426
  orderUuid: this.store.currentOrder.uuid,
3757
3427
  operation: isUpdateOperation ? 'update' : 'create',
3758
3428
  isManual: isManual,
@@ -3761,7 +3431,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3761
3431
  });
3762
3432
  case 27:
3763
3433
  submitSuccess = false;
3764
- _context39.prev = 28;
3434
+ _context37.prev = 28;
3765
3435
  // 记录接口调用参数
3766
3436
  this.logInfo('Calling backend checkout API', _objectSpread({
3767
3437
  url: '/order/checkout',
@@ -3769,24 +3439,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3769
3439
  }, orderParams));
3770
3440
 
3771
3441
  // 调用 Order 模块的专用 createOrderByCheckout 方法
3772
- _context39.next = 32;
3442
+ _context37.next = 32;
3773
3443
  return this.order.createOrderByCheckout(orderParams);
3774
3444
  case 32:
3775
- checkoutResponse = _context39.sent;
3445
+ checkoutResponse = _context37.sent;
3776
3446
  submitSuccess = true;
3777
3447
  this.logInfo('下单接口调用成功', checkoutResponse);
3778
- _context39.next = 45;
3448
+ _context37.next = 45;
3779
3449
  break;
3780
3450
  case 37:
3781
- _context39.prev = 37;
3782
- _context39.t1 = _context39["catch"](28);
3451
+ _context37.prev = 37;
3452
+ _context37.t1 = _context37["catch"](28);
3783
3453
  submitSuccess = false;
3784
- submitError = _context39.t1 instanceof Error ? _context39.t1.message : String(_context39.t1);
3454
+ submitError = _context37.t1 instanceof Error ? _context37.t1.message : String(_context37.t1);
3785
3455
  this.logError('下单接口调用失败:', submitError);
3786
3456
 
3787
3457
  // 发送订单同步失败事件(网络错误或请求失败)
3788
- _context39.next = 44;
3789
- return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
3458
+ _context37.next = 44;
3459
+ return this.core.effects.emit("".concat(this.name, ":onOrderSyncFailed"), {
3790
3460
  orderUuid: this.store.currentOrder.uuid,
3791
3461
  operation: isUpdateOperation ? 'update' : 'create',
3792
3462
  isManual: isManual,
@@ -3796,11 +3466,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3796
3466
  timestamp: Date.now()
3797
3467
  });
3798
3468
  case 44:
3799
- throw _context39.t1;
3469
+ throw _context37.t1;
3800
3470
  case 45:
3801
- _context39.prev = 45;
3802
- _context39.next = 48;
3803
- return this.core.effects.emit(CheckoutHooks.OnOrderSubmitEnd, {
3471
+ _context37.prev = 45;
3472
+ _context37.next = 48;
3473
+ return this.core.effects.emit("".concat(this.name, ":onOrderSubmitEnd"), {
3804
3474
  success: submitSuccess,
3805
3475
  orderUuid: this.store.currentOrder.uuid,
3806
3476
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3811,18 +3481,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3811
3481
  timestamp: Date.now()
3812
3482
  });
3813
3483
  case 48:
3814
- return _context39.finish(45);
3484
+ return _context37.finish(45);
3815
3485
  case 49:
3816
3486
  // 检查响应状态是否为成功状态
3817
3487
  responseStatus = (_checkoutResponse3 = checkoutResponse) === null || _checkoutResponse3 === void 0 ? void 0 : _checkoutResponse3.status;
3818
3488
  isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse4 = checkoutResponse) === null || _checkoutResponse4 === void 0 ? void 0 : _checkoutResponse4.code) === 200;
3819
3489
  if (isSuccessResponse) {
3820
- _context39.next = 56;
3490
+ _context37.next = 56;
3821
3491
  break;
3822
3492
  }
3823
3493
  errorMessage = ((_checkoutResponse5 = checkoutResponse) === null || _checkoutResponse5 === void 0 ? void 0 : _checkoutResponse5.message) || '订单同步失败,后端返回非成功状态'; // 发送订单同步失败事件
3824
- _context39.next = 55;
3825
- return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
3494
+ _context37.next = 55;
3495
+ return this.core.effects.emit("".concat(this.name, ":onOrderSyncFailed"), {
3826
3496
  orderUuid: this.store.currentOrder.uuid,
3827
3497
  operation: isUpdateOperation ? 'update' : 'create',
3828
3498
  isManual: isManual,
@@ -3836,12 +3506,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3836
3506
  throw new Error(errorMessage);
3837
3507
  case 56:
3838
3508
  if (!isUpdateOperation) {
3839
- _context39.next = 60;
3509
+ _context37.next = 60;
3840
3510
  break;
3841
3511
  }
3842
3512
  // 更新操作:使用现有的订单ID
3843
3513
  realOrderId = currentOrderId;
3844
- _context39.next = 79;
3514
+ _context37.next = 79;
3845
3515
  break;
3846
3516
  case 60:
3847
3517
  // 创建操作:从响应中提取新的订单ID
@@ -3865,11 +3535,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3865
3535
  oldOrderId: this.store.currentOrder.order_id,
3866
3536
  newOrderId: realOrderId
3867
3537
  });
3868
- _context39.prev = 66;
3869
- _context39.next = 69;
3538
+ _context37.prev = 66;
3539
+ _context37.next = 69;
3870
3540
  return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, realOrderId);
3871
3541
  case 69:
3872
- updatedOrder = _context39.sent;
3542
+ updatedOrder = _context37.sent;
3873
3543
  this.logInfo('Payment模块替换订单ID结果:', {
3874
3544
  wasSuccessful: !!updatedOrder,
3875
3545
  returnedOrderId: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.order_id,
@@ -3895,70 +3565,67 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3895
3565
  目标ID: realOrderId
3896
3566
  });
3897
3567
  }
3898
- _context39.next = 79;
3568
+ _context37.next = 79;
3899
3569
  break;
3900
3570
  case 74:
3901
- _context39.prev = 74;
3902
- _context39.t2 = _context39["catch"](66);
3903
- this.logError('调用Payment模块替换订单ID时发生错误:', _context39.t2);
3571
+ _context37.prev = 74;
3572
+ _context37.t2 = _context37["catch"](66);
3573
+ this.logError('调用Payment模块替换订单ID时发生错误:', _context37.t2);
3904
3574
 
3905
3575
  // 发生错误时也进行手动替换
3906
3576
  this.store.currentOrder.order_id = realOrderId;
3907
3577
  this.logInfo('错误恢复:手动设置订单ID:', realOrderId);
3908
3578
  case 79:
3909
- _context39.prev = 79;
3579
+ _context37.prev = 79;
3910
3580
  syncedPaymentUuids = processedPaymentItems.filter(function (item) {
3911
3581
  return item.status !== 'voided';
3912
3582
  }).map(function (item) {
3913
3583
  return item.uuid;
3914
3584
  }).filter(Boolean);
3915
3585
  _iterator3 = _createForOfIteratorHelper(syncedPaymentUuids);
3916
- _context39.prev = 82;
3586
+ _context37.prev = 82;
3917
3587
  _iterator3.s();
3918
3588
  case 84:
3919
3589
  if ((_step3 = _iterator3.n()).done) {
3920
- _context39.next = 90;
3590
+ _context37.next = 90;
3921
3591
  break;
3922
3592
  }
3923
3593
  paymentUuid = _step3.value;
3924
- _context39.next = 88;
3594
+ _context37.next = 88;
3925
3595
  return this.payment.updatePaymentAsync(this.store.currentOrder.uuid, paymentUuid, {
3926
3596
  isSynced: true,
3927
3597
  syncError: undefined
3928
3598
  });
3929
3599
  case 88:
3930
- _context39.next = 84;
3600
+ _context37.next = 84;
3931
3601
  break;
3932
3602
  case 90:
3933
- _context39.next = 95;
3603
+ _context37.next = 95;
3934
3604
  break;
3935
3605
  case 92:
3936
- _context39.prev = 92;
3937
- _context39.t3 = _context39["catch"](82);
3938
- _iterator3.e(_context39.t3);
3606
+ _context37.prev = 92;
3607
+ _context37.t3 = _context37["catch"](82);
3608
+ _iterator3.e(_context37.t3);
3939
3609
  case 95:
3940
- _context39.prev = 95;
3610
+ _context37.prev = 95;
3941
3611
  _iterator3.f();
3942
- return _context39.finish(95);
3612
+ return _context37.finish(95);
3943
3613
  case 98:
3944
- _context39.next = 103;
3614
+ _context37.next = 103;
3945
3615
  break;
3946
3616
  case 100:
3947
- _context39.prev = 100;
3948
- _context39.t4 = _context39["catch"](79);
3617
+ _context37.prev = 100;
3618
+ _context37.t4 = _context37["catch"](79);
3949
3619
  this.logWarning('标记支付项已同步失败(不阻塞主流程)', {
3950
- error: _context39.t4
3620
+ error: _context37.t4
3951
3621
  });
3952
3622
  case 103:
3953
3623
  // 标记订单已同步
3954
3624
  this.store.isOrderSynced = true;
3955
3625
 
3956
- // 🚀 清除计算缓存,订单已同步,数据可能已变更
3957
- this.clearCalculationCache();
3958
-
3959
3626
  // 触发订单同步完成事件
3960
- _context39.next = 107;
3961
- return this.core.effects.emit(CheckoutHooks.OnOrderSynced, {
3627
+ _context37.next = 106;
3628
+ return this.core.effects.emit("".concat(this.name, ":onOrderSynced"), {
3962
3629
  orderUuid: this.store.currentOrder.uuid,
3963
3630
  realOrderId: realOrderId,
3964
3631
  virtualOrderId: this.store.currentOrder.order_id,
@@ -3966,18 +3633,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3966
3633
  isManual: isManual,
3967
3634
  response: checkoutResponse
3968
3635
  });
3969
- case 107:
3970
- return _context39.abrupt("return", {
3636
+ case 106:
3637
+ return _context37.abrupt("return", {
3971
3638
  success: true,
3972
3639
  orderId: realOrderId,
3973
3640
  orderUuid: this.store.currentOrder.uuid,
3974
3641
  response: checkoutResponse
3975
3642
  });
3976
- case 108:
3643
+ case 107:
3977
3644
  case "end":
3978
- return _context39.stop();
3645
+ return _context37.stop();
3979
3646
  }
3980
- }, _callee39, this, [[28, 37, 45, 49], [66, 74], [79, 100], [82, 92, 95, 98]]);
3647
+ }, _callee37, this, [[28, 37, 45, 49], [66, 74], [79, 100], [82, 92, 95, 98]]);
3981
3648
  }));
3982
3649
  function syncOrderToBackendWithReturn() {
3983
3650
  return _syncOrderToBackendWithReturn.apply(this, arguments);
@@ -3987,15 +3654,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3987
3654
  }, {
3988
3655
  key: "setOtherParams",
3989
3656
  value: function () {
3990
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
3657
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
3991
3658
  var _ref5,
3992
3659
  _ref5$cover,
3993
3660
  cover,
3994
- _args40 = arguments;
3995
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3996
- while (1) switch (_context40.prev = _context40.next) {
3661
+ _args38 = arguments;
3662
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3663
+ while (1) switch (_context38.prev = _context38.next) {
3997
3664
  case 0:
3998
- _ref5 = _args40.length > 1 && _args40[1] !== undefined ? _args40[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
3665
+ _ref5 = _args38.length > 1 && _args38[1] !== undefined ? _args38[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
3999
3666
  if (cover) {
4000
3667
  this.otherParams = params;
4001
3668
  } else {
@@ -4003,11 +3670,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4003
3670
  }
4004
3671
  case 2:
4005
3672
  case "end":
4006
- return _context40.stop();
3673
+ return _context38.stop();
4007
3674
  }
4008
- }, _callee40, this);
3675
+ }, _callee38, this);
4009
3676
  }));
4010
- function setOtherParams(_x29) {
3677
+ function setOtherParams(_x27) {
4011
3678
  return _setOtherParams.apply(this, arguments);
4012
3679
  }
4013
3680
  return setOtherParams;
@@ -4024,22 +3691,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4024
3691
  }, {
4025
3692
  key: "editOrderNoteByOrderIdAsync",
4026
3693
  value: (function () {
4027
- var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(orderId, note) {
3694
+ var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(orderId, note) {
4028
3695
  var response, previousNote, errorMessage, _errorMessage;
4029
- return _regeneratorRuntime().wrap(function _callee41$(_context41) {
4030
- while (1) switch (_context41.prev = _context41.next) {
3696
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3697
+ while (1) switch (_context39.prev = _context39.next) {
4031
3698
  case 0:
4032
3699
  this.logInfo('editOrderNoteByOrderIdAsync called', {
4033
3700
  orderId: orderId,
4034
3701
  note: note,
4035
3702
  noteLength: note.length
4036
3703
  });
4037
- _context41.prev = 1;
3704
+ _context39.prev = 1;
4038
3705
  if (orderId) {
4039
- _context41.next = 4;
3706
+ _context39.next = 4;
4040
3707
  break;
4041
3708
  }
4042
- return _context41.abrupt("return", {
3709
+ return _context39.abrupt("return", {
4043
3710
  success: false,
4044
3711
  message: '订单ID不能为空',
4045
3712
  orderId: orderId
@@ -4055,12 +3722,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4055
3722
  });
4056
3723
 
4057
3724
  // 调用后端API修改订单备注
4058
- _context41.next = 7;
3725
+ _context39.next = 7;
4059
3726
  return this.request.put("/order/order/".concat(orderId, "/note"), {
4060
3727
  note: note
4061
3728
  });
4062
3729
  case 7:
4063
- response = _context41.sent;
3730
+ response = _context39.sent;
4064
3731
  this.logInfo('订单备注编辑响应:', {
4065
3732
  orderId: orderId,
4066
3733
  status: response.status,
@@ -4070,11 +3737,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4070
3737
 
4071
3738
  // 检查响应状态
4072
3739
  if (!(response.status === true || response.status === 200)) {
4073
- _context41.next = 18;
3740
+ _context39.next = 18;
4074
3741
  break;
4075
3742
  }
4076
3743
  if (!(this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId)))) {
4077
- _context41.next = 15;
3744
+ _context39.next = 15;
4078
3745
  break;
4079
3746
  }
4080
3747
  // 获取修改前的备注用于事件
@@ -4084,15 +3751,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4084
3751
  }
4085
3752
 
4086
3753
  // 触发订单备注变更事件
4087
- _context41.next = 15;
4088
- return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
3754
+ _context39.next = 15;
3755
+ return this.core.effects.emit("".concat(this.name, ":onOrderNoteChanged"), {
4089
3756
  orderUuid: this.store.currentOrder.uuid,
4090
3757
  oldNote: previousNote,
4091
3758
  newNote: note,
4092
3759
  timestamp: Date.now()
4093
3760
  });
4094
3761
  case 15:
4095
- return _context41.abrupt("return", {
3762
+ return _context39.abrupt("return", {
4096
3763
  success: true,
4097
3764
  message: response.message || '订单备注修改成功',
4098
3765
  orderId: orderId
@@ -4101,31 +3768,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4101
3768
  // API返回失败状态
4102
3769
  errorMessage = response.message || '订单备注修改失败';
4103
3770
  this.logError("\u8BA2\u5355 ".concat(orderId, " \u5907\u6CE8\u4FEE\u6539\u5931\u8D25:"), errorMessage);
4104
- return _context41.abrupt("return", {
3771
+ return _context39.abrupt("return", {
4105
3772
  success: false,
4106
3773
  message: errorMessage,
4107
3774
  orderId: orderId
4108
3775
  });
4109
3776
  case 21:
4110
- _context41.next = 28;
3777
+ _context39.next = 28;
4111
3778
  break;
4112
3779
  case 23:
4113
- _context41.prev = 23;
4114
- _context41.t0 = _context41["catch"](1);
4115
- this.logError('编辑订单备注失败:', _context41.t0);
4116
- _errorMessage = _context41.t0 instanceof Error ? _context41.t0.message : '网络错误或服务器异常';
4117
- return _context41.abrupt("return", {
3780
+ _context39.prev = 23;
3781
+ _context39.t0 = _context39["catch"](1);
3782
+ this.logError('编辑订单备注失败:', _context39.t0);
3783
+ _errorMessage = _context39.t0 instanceof Error ? _context39.t0.message : '网络错误或服务器异常';
3784
+ return _context39.abrupt("return", {
4118
3785
  success: false,
4119
3786
  message: "\u7F16\u8F91\u8BA2\u5355\u5907\u6CE8\u5931\u8D25: ".concat(_errorMessage),
4120
3787
  orderId: orderId
4121
3788
  });
4122
3789
  case 28:
4123
3790
  case "end":
4124
- return _context41.stop();
3791
+ return _context39.stop();
4125
3792
  }
4126
- }, _callee41, this, [[1, 23]]);
3793
+ }, _callee39, this, [[1, 23]]);
4127
3794
  }));
4128
- function editOrderNoteByOrderIdAsync(_x30, _x31) {
3795
+ function editOrderNoteByOrderIdAsync(_x28, _x29) {
4129
3796
  return _editOrderNoteByOrderIdAsync.apply(this, arguments);
4130
3797
  }
4131
3798
  return editOrderNoteByOrderIdAsync;
@@ -4142,11 +3809,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4142
3809
  }, {
4143
3810
  key: "sendCustomerPayLinkAsync",
4144
3811
  value: (function () {
4145
- var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
3812
+ var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
4146
3813
  var _params$order_ids, _params$emails;
4147
3814
  var emailRegex, invalidEmails, requestBody, response, errorMessage, _errorMessage2;
4148
- return _regeneratorRuntime().wrap(function _callee42$(_context42) {
4149
- while (1) switch (_context42.prev = _context42.next) {
3815
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3816
+ while (1) switch (_context40.prev = _context40.next) {
4150
3817
  case 0:
4151
3818
  this.logInfo('sendCustomerPayLinkAsync called', {
4152
3819
  orderIds: params.order_ids,
@@ -4155,21 +3822,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4155
3822
  emailsCount: ((_params$emails = params.emails) === null || _params$emails === void 0 ? void 0 : _params$emails.length) || 0,
4156
3823
  notifyAction: params.notify_action || 'order_payment_reminder'
4157
3824
  });
4158
- _context42.prev = 1;
3825
+ _context40.prev = 1;
4159
3826
  if (!(!params.order_ids || params.order_ids.length === 0)) {
4160
- _context42.next = 4;
3827
+ _context40.next = 4;
4161
3828
  break;
4162
3829
  }
4163
- return _context42.abrupt("return", {
3830
+ return _context40.abrupt("return", {
4164
3831
  success: false,
4165
3832
  message: '订单ID列表不能为空'
4166
3833
  });
4167
3834
  case 4:
4168
3835
  if (!(!params.emails || params.emails.length === 0)) {
4169
- _context42.next = 6;
3836
+ _context40.next = 6;
4170
3837
  break;
4171
3838
  }
4172
- return _context42.abrupt("return", {
3839
+ return _context40.abrupt("return", {
4173
3840
  success: false,
4174
3841
  message: '邮箱地址列表不能为空'
4175
3842
  });
@@ -4180,10 +3847,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4180
3847
  return !emailRegex.test(email);
4181
3848
  });
4182
3849
  if (!(invalidEmails.length > 0)) {
4183
- _context42.next = 10;
3850
+ _context40.next = 10;
4184
3851
  break;
4185
3852
  }
4186
- return _context42.abrupt("return", {
3853
+ return _context40.abrupt("return", {
4187
3854
  success: false,
4188
3855
  message: "\u90AE\u7BB1\u683C\u5F0F\u65E0\u6548: ".concat(invalidEmails.join(', '))
4189
3856
  });
@@ -4199,10 +3866,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4199
3866
  }, requestBody));
4200
3867
 
4201
3868
  // 调用后端API发送邮件
4202
- _context42.next = 14;
3869
+ _context40.next = 14;
4203
3870
  return this.request.post('/order/batch-email', requestBody);
4204
3871
  case 14:
4205
- response = _context42.sent;
3872
+ response = _context40.sent;
4206
3873
  this.logInfo('支付链接邮件发送响应:', {
4207
3874
  status: response.status,
4208
3875
  message: response.message,
@@ -4212,10 +3879,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4212
3879
 
4213
3880
  // 检查响应状态
4214
3881
  if (!(response.status === true || response.status === 200)) {
4215
- _context42.next = 20;
3882
+ _context40.next = 20;
4216
3883
  break;
4217
3884
  }
4218
- return _context42.abrupt("return", {
3885
+ return _context40.abrupt("return", {
4219
3886
  success: true,
4220
3887
  message: response.message || '支付链接邮件发送成功'
4221
3888
  });
@@ -4223,29 +3890,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4223
3890
  // API返回失败状态
4224
3891
  errorMessage = response.message || '支付链接邮件发送失败';
4225
3892
  console.error('[Checkout] 支付链接邮件发送失败:', errorMessage);
4226
- return _context42.abrupt("return", {
3893
+ return _context40.abrupt("return", {
4227
3894
  success: false,
4228
3895
  message: errorMessage
4229
3896
  });
4230
3897
  case 23:
4231
- _context42.next = 30;
3898
+ _context40.next = 30;
4232
3899
  break;
4233
3900
  case 25:
4234
- _context42.prev = 25;
4235
- _context42.t0 = _context42["catch"](1);
4236
- this.logError('发送客户支付链接邮件失败:', _context42.t0);
4237
- _errorMessage2 = _context42.t0 instanceof Error ? _context42.t0.message : '网络错误或服务器异常';
4238
- return _context42.abrupt("return", {
3901
+ _context40.prev = 25;
3902
+ _context40.t0 = _context40["catch"](1);
3903
+ this.logError('发送客户支付链接邮件失败:', _context40.t0);
3904
+ _errorMessage2 = _context40.t0 instanceof Error ? _context40.t0.message : '网络错误或服务器异常';
3905
+ return _context40.abrupt("return", {
4239
3906
  success: false,
4240
3907
  message: "\u53D1\u9001\u652F\u4ED8\u94FE\u63A5\u90AE\u4EF6\u5931\u8D25: ".concat(_errorMessage2)
4241
3908
  });
4242
3909
  case 30:
4243
3910
  case "end":
4244
- return _context42.stop();
3911
+ return _context40.stop();
4245
3912
  }
4246
- }, _callee42, this, [[1, 25]]);
3913
+ }, _callee40, this, [[1, 25]]);
4247
3914
  }));
4248
- function sendCustomerPayLinkAsync(_x32) {
3915
+ function sendCustomerPayLinkAsync(_x30) {
4249
3916
  return _sendCustomerPayLinkAsync.apply(this, arguments);
4250
3917
  }
4251
3918
  return sendCustomerPayLinkAsync;
@@ -4260,38 +3927,38 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4260
3927
  }, {
4261
3928
  key: "roundAmountAsync",
4262
3929
  value: (function () {
4263
- var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(amount) {
3930
+ var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(amount) {
4264
3931
  var _cashManualPayment$me, _this$otherParams$ord, _this$otherParams$ord2;
4265
3932
  var cashManualPayment, result;
4266
- return _regeneratorRuntime().wrap(function _callee43$(_context43) {
4267
- while (1) switch (_context43.prev = _context43.next) {
3933
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3934
+ while (1) switch (_context41.prev = _context41.next) {
4268
3935
  case 0:
4269
3936
  // 检查 CASHMANUAL 的支付项是否开启了舍入,如果没开直接返回 amount
4270
3937
  cashManualPayment = this.store.paymentMethods.find(function (p) {
4271
3938
  return p.code === 'CASHMANUAL';
4272
3939
  });
4273
3940
  if (cashManualPayment !== null && cashManualPayment !== void 0 && (_cashManualPayment$me = cashManualPayment.metadata) !== null && _cashManualPayment$me !== void 0 && _cashManualPayment$me.order_rounding_switch) {
4274
- _context43.next = 3;
3941
+ _context41.next = 3;
4275
3942
  break;
4276
3943
  }
4277
- return _context43.abrupt("return", {
3944
+ return _context41.abrupt("return", {
4278
3945
  originalAmount: amount.toString(),
4279
3946
  roundedAmount: amount.toString(),
4280
3947
  roundingDifference: '0.00'
4281
3948
  });
4282
3949
  case 3:
4283
- _context43.next = 5;
3950
+ _context41.next = 5;
4284
3951
  return this.payment.roundAmountAsync(amount, (_this$otherParams$ord = this.otherParams.order_rounding_setting) === null || _this$otherParams$ord === void 0 ? void 0 : _this$otherParams$ord.interval, (_this$otherParams$ord2 = this.otherParams.order_rounding_setting) === null || _this$otherParams$ord2 === void 0 ? void 0 : _this$otherParams$ord2.type);
4285
3952
  case 5:
4286
- result = _context43.sent;
4287
- return _context43.abrupt("return", result);
3953
+ result = _context41.sent;
3954
+ return _context41.abrupt("return", result);
4288
3955
  case 7:
4289
3956
  case "end":
4290
- return _context43.stop();
3957
+ return _context41.stop();
4291
3958
  }
4292
- }, _callee43, this);
3959
+ }, _callee41, this);
4293
3960
  }));
4294
- function roundAmountAsync(_x33) {
3961
+ function roundAmountAsync(_x31) {
4295
3962
  return _roundAmountAsync.apply(this, arguments);
4296
3963
  }
4297
3964
  return roundAmountAsync;
@@ -4299,10 +3966,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4299
3966
  }, {
4300
3967
  key: "destroy",
4301
3968
  value: function () {
4302
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44() {
3969
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42() {
4303
3970
  var _this$order, _this$order$destroy, _this$payment, _this$payment$destroy;
4304
- return _regeneratorRuntime().wrap(function _callee44$(_context44) {
4305
- while (1) switch (_context44.prev = _context44.next) {
3971
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3972
+ while (1) switch (_context42.prev = _context42.next) {
4306
3973
  case 0:
4307
3974
  // 清理钱包模块的所有缓存数据
4308
3975
  this.payment.wallet.clearAllCache();
@@ -4311,10 +3978,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4311
3978
  this.core.effects.offByModuleDestroy(this.name);
4312
3979
 
4313
3980
  // 销毁子模块
4314
- _context44.next = 4;
3981
+ _context42.next = 4;
4315
3982
  return (_this$order = this.order) === null || _this$order === void 0 || (_this$order$destroy = _this$order.destroy) === null || _this$order$destroy === void 0 ? void 0 : _this$order$destroy.call(_this$order);
4316
3983
  case 4:
4317
- _context44.next = 6;
3984
+ _context42.next = 6;
4318
3985
  return (_this$payment = this.payment) === null || _this$payment === void 0 || (_this$payment$destroy = _this$payment.destroy) === null || _this$payment$destroy === void 0 ? void 0 : _this$payment$destroy.call(_this$payment);
4319
3986
  case 6:
4320
3987
  // 取消注册模块
@@ -4322,9 +3989,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4322
3989
  console.log('[Checkout] 已销毁');
4323
3990
  case 8:
4324
3991
  case "end":
4325
- return _context44.stop();
3992
+ return _context42.stop();
4326
3993
  }
4327
- }, _callee44, this);
3994
+ }, _callee42, this);
4328
3995
  }));
4329
3996
  function destroy() {
4330
3997
  return _destroy.apply(this, arguments);
@@ -4335,57 +4002,70 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4335
4002
  * 重置 store 状态
4336
4003
  *
4337
4004
  * 在创建新订单前调用,确保状态完全干净
4338
- *
4339
- * 🚀 性能优化:改为同步方法,事件发射不阻塞主流程
4340
4005
  */
4341
4006
  }, {
4342
- key: "resetStoreState",
4343
- value: function resetStoreState() {
4344
- var _this6 = this;
4345
- try {
4346
- var prevOrderInfo = this.store.currentOrder ? {
4347
- uuid: this.store.currentOrder.uuid,
4348
- orderId: this.store.currentOrder.order_id
4349
- } : null;
4350
- console.log('[Checkout] 重置 store 状态,准备创建新订单', prevOrderInfo);
4351
-
4352
- // 重置订单相关的 store 状态(保留 paymentMethods,因为支付方式数据变更不频繁)
4353
- this.store.currentOrder = undefined;
4354
- this.store.localOrderData = undefined;
4355
- this.store.cartSummary = undefined;
4356
- this.store.stateAmount = '0.00';
4357
- this.store.balanceDueAmount = '0.00';
4358
- this.store.isOrderSynced = false;
4359
- this.store.currentCustomer = undefined;
4360
- this.store.lastError = undefined;
4361
-
4362
- // 清空购物车项目
4363
- this.store.cartItems = [];
4007
+ key: "resetStoreStateAsync",
4008
+ value: (function () {
4009
+ var _resetStoreStateAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43() {
4010
+ var prevOrderInfo;
4011
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
4012
+ while (1) switch (_context43.prev = _context43.next) {
4013
+ case 0:
4014
+ _context43.prev = 0;
4015
+ prevOrderInfo = this.store.currentOrder ? {
4016
+ uuid: this.store.currentOrder.uuid,
4017
+ orderId: this.store.currentOrder.order_id
4018
+ } : null;
4019
+ console.log('[Checkout] 重置 store 状态,准备创建新订单', prevOrderInfo);
4020
+
4021
+ // 重置订单相关的 store 状态(保留 paymentMethods,因为支付方式数据变更不频繁)
4022
+ this.store.currentOrder = undefined;
4023
+ this.store.localOrderData = undefined;
4024
+ this.store.cartSummary = undefined;
4025
+ this.store.stateAmount = '0.00';
4026
+ this.store.balanceDueAmount = '0.00';
4027
+ this.store.isOrderSynced = false;
4028
+ this.store.currentCustomer = undefined;
4029
+ this.store.lastError = undefined;
4364
4030
 
4365
- // 清理钱包缓存(同步操作)
4366
- this.payment.wallet.clearAllCache();
4031
+ // 清空购物车项目
4032
+ this.store.cartItems = [];
4367
4033
 
4368
- // 🚀 清除计算缓存
4369
- this.clearCalculationCache();
4034
+ // 清理钱包缓存
4035
+ this.payment.wallet.clearAllCache();
4370
4036
 
4371
- // 注意:故意保留 this.store.paymentMethods,因为支付方式数据不易变更,保留在内存中提高性能
4037
+ // 注意:故意保留 this.store.paymentMethods,因为支付方式数据不易变更,保留在内存中提高性能
4372
4038
 
4373
- console.log('[Checkout] Store 状态重置完成');
4039
+ console.log('[Checkout] Store 状态重置完成');
4374
4040
 
4375
- // 🚀 性能优化:异步触发订单清理事件(不阻塞主流程)
4376
- // 使用 setTimeout 确保事件处理不会阻塞状态重置
4377
- if (prevOrderInfo) {
4378
- setTimeout(function () {
4379
- _this6.core.effects.emit(CheckoutHooks.OnOrderCleared, {
4380
- previousOrder: prevOrderInfo,
4381
- timestamp: Date.now()
4382
- });
4383
- }, 0);
4384
- }
4385
- } catch (error) {
4386
- console.error('[Checkout] 重置 store 状态失败:', error);
4041
+ // 触发订单清理事件(如果之前有订单)
4042
+ if (!prevOrderInfo) {
4043
+ _context43.next = 17;
4044
+ break;
4045
+ }
4046
+ _context43.next = 17;
4047
+ return this.core.effects.emit("".concat(this.name, ":onOrderCleared"), {
4048
+ previousOrder: prevOrderInfo,
4049
+ timestamp: Date.now()
4050
+ });
4051
+ case 17:
4052
+ _context43.next = 22;
4053
+ break;
4054
+ case 19:
4055
+ _context43.prev = 19;
4056
+ _context43.t0 = _context43["catch"](0);
4057
+ console.error('[Checkout] 重置 store 状态失败:', _context43.t0);
4058
+ case 22:
4059
+ case "end":
4060
+ return _context43.stop();
4061
+ }
4062
+ }, _callee43, this, [[0, 19]]);
4063
+ }));
4064
+ function resetStoreStateAsync() {
4065
+ return _resetStoreStateAsync.apply(this, arguments);
4387
4066
  }
4388
- }
4067
+ return resetStoreStateAsync;
4068
+ }())
4389
4069
  }]);
4390
4070
  return CheckoutImpl;
4391
4071
  }(BaseModule);