@pisell/pisellos 0.0.479 → 0.0.481

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 (147) hide show
  1. package/dist/core/index.d.ts +3 -2
  2. package/dist/core/index.js +7 -0
  3. package/dist/effects/index.d.ts +2 -2
  4. package/dist/effects/index.js +34 -81
  5. package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
  6. package/dist/model/strategy/adapter/walletPass/type.d.ts +9 -2
  7. package/dist/model/strategy/adapter/walletPass/utils.d.ts +6 -6
  8. package/dist/model/strategy/adapter/walletPass/utils.js +111 -72
  9. package/dist/modules/Customer/index.js +1 -1
  10. package/dist/modules/Discount/index.d.ts +6 -2
  11. package/dist/modules/Discount/index.js +14 -8
  12. package/dist/modules/Order/index.d.ts +1 -1
  13. package/dist/modules/Order/index.js +18 -13
  14. package/dist/modules/Payment/index.d.ts +4 -0
  15. package/dist/modules/Payment/index.js +774 -649
  16. package/dist/modules/Payment/walletpass.js +44 -17
  17. package/dist/modules/Product/index.d.ts +1 -1
  18. package/dist/modules/Product/types.d.ts +2 -0
  19. package/dist/modules/ProductList/index.d.ts +3 -0
  20. package/dist/modules/ProductList/index.js +9 -7
  21. package/dist/modules/Rules/index.d.ts +2 -2
  22. package/dist/modules/Rules/index.js +37 -31
  23. package/dist/modules/Rules/types.d.ts +2 -2
  24. package/dist/modules/Schedule/index.d.ts +9 -0
  25. package/dist/modules/Schedule/index.js +15 -2
  26. package/dist/plugins/app-types/app/app.d.ts +1 -0
  27. package/dist/plugins/request.d.ts +2 -0
  28. package/dist/server/index.d.ts +107 -2
  29. package/dist/server/index.js +1507 -279
  30. package/dist/server/modules/index.d.ts +6 -0
  31. package/dist/server/modules/index.js +7 -0
  32. package/dist/server/modules/menu/index.d.ts +19 -0
  33. package/dist/server/modules/menu/index.js +221 -71
  34. package/dist/server/modules/order/index.d.ts +87 -0
  35. package/dist/server/modules/order/index.js +916 -0
  36. package/dist/server/modules/order/types.d.ts +530 -0
  37. package/dist/server/modules/order/types.js +141 -0
  38. package/dist/server/modules/order/utils/filterBookings.d.ts +6 -0
  39. package/dist/server/modules/order/utils/filterBookings.js +350 -0
  40. package/dist/server/modules/order/utils/filterOrders.d.ts +15 -0
  41. package/dist/server/modules/order/utils/filterOrders.js +226 -0
  42. package/dist/server/modules/products/index.d.ts +117 -5
  43. package/dist/server/modules/products/index.js +1450 -240
  44. package/dist/server/modules/products/types.d.ts +25 -1
  45. package/dist/server/modules/products/types.js +3 -0
  46. package/dist/server/modules/resource/index.d.ts +86 -0
  47. package/dist/server/modules/resource/index.js +1128 -0
  48. package/dist/server/modules/resource/types.d.ts +121 -0
  49. package/dist/server/modules/resource/types.js +47 -0
  50. package/dist/server/modules/schedule/index.d.ts +19 -0
  51. package/dist/server/modules/schedule/index.js +229 -68
  52. package/dist/server/utils/product.d.ts +5 -0
  53. package/dist/server/utils/product.js +71 -31
  54. package/dist/solution/BookingTicket/index.d.ts +10 -2
  55. package/dist/solution/BookingTicket/index.js +41 -28
  56. package/dist/solution/BookingTicket/utils/scan/index.js +1 -1
  57. package/dist/solution/Checkout/index.d.ts +1 -0
  58. package/dist/solution/Checkout/index.js +286 -188
  59. package/dist/solution/Checkout/utils/index.d.ts +2 -1
  60. package/dist/solution/Checkout/utils/index.js +6 -4
  61. package/dist/solution/RegisterAndLogin/config.js +340 -1
  62. package/dist/solution/Sales/index.d.ts +96 -0
  63. package/dist/solution/Sales/index.js +566 -0
  64. package/dist/solution/Sales/types.d.ts +67 -0
  65. package/dist/solution/Sales/types.js +26 -0
  66. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  67. package/dist/solution/ShopDiscount/index.js +35 -22
  68. package/dist/solution/ShopDiscount/types.d.ts +6 -0
  69. package/dist/solution/ShopDiscount/utils.d.ts +9 -0
  70. package/dist/solution/ShopDiscount/utils.js +21 -27
  71. package/dist/solution/index.d.ts +2 -1
  72. package/dist/solution/index.js +2 -1
  73. package/dist/types/index.d.ts +5 -0
  74. package/lib/core/index.d.ts +3 -2
  75. package/lib/core/index.js +4 -0
  76. package/lib/effects/index.d.ts +2 -2
  77. package/lib/effects/index.js +22 -31
  78. package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
  79. package/lib/model/strategy/adapter/walletPass/type.d.ts +9 -2
  80. package/lib/model/strategy/adapter/walletPass/utils.d.ts +6 -6
  81. package/lib/model/strategy/adapter/walletPass/utils.js +115 -48
  82. package/lib/modules/Customer/index.js +1 -1
  83. package/lib/modules/Discount/index.d.ts +6 -2
  84. package/lib/modules/Discount/index.js +3 -1
  85. package/lib/modules/Order/index.d.ts +1 -1
  86. package/lib/modules/Order/index.js +20 -18
  87. package/lib/modules/Payment/index.d.ts +4 -0
  88. package/lib/modules/Payment/index.js +134 -66
  89. package/lib/modules/Payment/walletpass.js +23 -4
  90. package/lib/modules/Product/index.d.ts +1 -1
  91. package/lib/modules/Product/types.d.ts +2 -0
  92. package/lib/modules/ProductList/index.d.ts +3 -0
  93. package/lib/modules/ProductList/index.js +2 -2
  94. package/lib/modules/Rules/index.d.ts +2 -2
  95. package/lib/modules/Rules/index.js +69 -73
  96. package/lib/modules/Rules/types.d.ts +2 -2
  97. package/lib/modules/Schedule/index.d.ts +9 -0
  98. package/lib/modules/Schedule/index.js +11 -0
  99. package/lib/plugins/app-types/app/app.d.ts +1 -0
  100. package/lib/plugins/request.d.ts +2 -0
  101. package/lib/server/index.d.ts +107 -2
  102. package/lib/server/index.js +773 -51
  103. package/lib/server/modules/index.d.ts +6 -0
  104. package/lib/server/modules/index.js +16 -2
  105. package/lib/server/modules/menu/index.d.ts +19 -0
  106. package/lib/server/modules/menu/index.js +121 -2
  107. package/lib/server/modules/order/index.d.ts +87 -0
  108. package/lib/server/modules/order/index.js +543 -0
  109. package/lib/server/modules/order/types.d.ts +530 -0
  110. package/lib/server/modules/order/types.js +34 -0
  111. package/lib/server/modules/order/utils/filterBookings.d.ts +6 -0
  112. package/lib/server/modules/order/utils/filterBookings.js +320 -0
  113. package/lib/server/modules/order/utils/filterOrders.d.ts +15 -0
  114. package/lib/server/modules/order/utils/filterOrders.js +197 -0
  115. package/lib/server/modules/products/index.d.ts +117 -5
  116. package/lib/server/modules/products/index.js +799 -62
  117. package/lib/server/modules/products/types.d.ts +25 -1
  118. package/lib/server/modules/products/types.js +1 -0
  119. package/lib/server/modules/resource/index.d.ts +86 -0
  120. package/lib/server/modules/resource/index.js +557 -0
  121. package/lib/server/modules/resource/types.d.ts +121 -0
  122. package/lib/server/modules/resource/types.js +35 -0
  123. package/lib/server/modules/schedule/index.d.ts +19 -0
  124. package/lib/server/modules/schedule/index.js +141 -12
  125. package/lib/server/utils/product.d.ts +5 -0
  126. package/lib/server/utils/product.js +56 -27
  127. package/lib/solution/BookingTicket/index.d.ts +10 -2
  128. package/lib/solution/BookingTicket/index.js +10 -2
  129. package/lib/solution/BookingTicket/utils/scan/index.js +0 -1
  130. package/lib/solution/Checkout/index.d.ts +1 -0
  131. package/lib/solution/Checkout/index.js +399 -331
  132. package/lib/solution/Checkout/utils/index.d.ts +2 -1
  133. package/lib/solution/Checkout/utils/index.js +6 -4
  134. package/lib/solution/RegisterAndLogin/config.js +266 -1
  135. package/lib/solution/Sales/index.d.ts +96 -0
  136. package/lib/solution/Sales/index.js +416 -0
  137. package/lib/solution/Sales/types.d.ts +67 -0
  138. package/lib/solution/Sales/types.js +35 -0
  139. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  140. package/lib/solution/ShopDiscount/index.js +14 -6
  141. package/lib/solution/ShopDiscount/types.d.ts +6 -0
  142. package/lib/solution/ShopDiscount/utils.d.ts +9 -0
  143. package/lib/solution/ShopDiscount/utils.js +6 -10
  144. package/lib/solution/index.d.ts +2 -1
  145. package/lib/solution/index.js +4 -2
  146. package/lib/types/index.d.ts +5 -0
  147. package/package.json +1 -1
@@ -61,6 +61,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
61
61
  // LoggerManager 实例
62
62
  // 计算缓存(用于性能优化)
63
63
  _defineProperty(_assertThisInitialized(_this), "calculationCache", {});
64
+ // 同步订单到后端锁(按订单维度),防止短时间内重复触发导致同一订单多次同步
65
+ _defineProperty(_assertThisInitialized(_this), "syncOrderToBackendInFlightByOrderKey", new Map());
64
66
  // 直接挂载的模块
65
67
  _defineProperty(_assertThisInitialized(_this), "order", void 0);
66
68
  _defineProperty(_assertThisInitialized(_this), "payment", void 0);
@@ -464,24 +466,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
464
466
  key: "initWalletData",
465
467
  value: function () {
466
468
  var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
467
- var _this$store$currentOr3, _this$store$currentCu, _this$store$currentOr4, _this$store$currentOr5, _this$store$currentOr6, _this$store$currentOr8;
468
- var amountInfo, walletBusinessData, _this$store$currentOr7;
469
+ var _this$store$currentOr3, _this$store$currentCu, _this$store$currentOr4, _this$store$currentOr5, _this$store$currentOr6, _this$store$currentOr8, amountInfo, walletBusinessData, _this$store$currentOr7;
469
470
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
470
471
  while (1) switch (_context8.prev = _context8.next) {
471
472
  case 0:
472
473
  this.logInfo('initWalletData called', {
473
474
  params: params
474
475
  });
476
+ _context8.prev = 1;
475
477
  amountInfo = (_this$store$currentOr3 = this.store.currentOrder) === null || _this$store$currentOr3 === void 0 || (_this$store$currentOr3 = _this$store$currentOr3.order_info) === null || _this$store$currentOr3 === void 0 ? void 0 : _this$store$currentOr3.amount_breakdown;
476
478
  if (amountInfo) {
477
- _context8.next = 5;
479
+ _context8.next = 6;
478
480
  break;
479
481
  }
480
482
  this.logInfo('initWalletData amountInfo not found', {
481
483
  params: params
482
484
  });
483
485
  return _context8.abrupt("return");
484
- case 5:
486
+ case 6:
485
487
  // 准备钱包初始化的业务数据
486
488
  walletBusinessData = _objectSpread({
487
489
  customer_id: (_this$store$currentCu = this.store.currentCustomer) !== null && _this$store$currentCu !== void 0 && _this$store$currentCu.customer_id ? Number(this.store.currentCustomer.customer_id) : undefined,
@@ -501,25 +503,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
501
503
  this.logInfo('开始拉取:initializeWalletDataFromBusinessAsync', {
502
504
  walletBusinessData: walletBusinessData
503
505
  });
504
- _context8.next = 10;
506
+ _context8.next = 11;
505
507
  return this.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
506
- case 10:
508
+ case 11:
507
509
  this.logInfo('调用结束:initializeWalletDataFromBusinessAsync', {
508
510
  walletBusinessData: walletBusinessData
509
511
  });
510
512
 
511
513
  // 因为上面是接口 这里最好检查一下还有没有 currentOrder 了,如果没有,则不触发事件
512
514
  if (this.store.currentOrder) {
513
- _context8.next = 13;
515
+ _context8.next = 14;
514
516
  break;
515
517
  }
516
518
  return _context8.abrupt("return");
517
- case 13:
519
+ case 14:
518
520
  this.logInfo('initWalletData currentOrder found', {
519
521
  currentOrder: this.store.currentOrder
520
522
  });
521
523
  // 触发钱包数据初始化完成事件
522
- _context8.next = 16;
524
+ _context8.next = 17;
523
525
  return this.core.effects.emit("".concat(this.name, ":onWalletDataInitialized"), {
524
526
  orderUuid: (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.uuid,
525
527
  customerId: walletBusinessData.customer_id,
@@ -530,11 +532,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
530
532
  },
531
533
  timestamp: Date.now()
532
534
  });
533
- case 16:
535
+ case 17:
536
+ _context8.next = 23;
537
+ break;
538
+ case 19:
539
+ _context8.prev = 19;
540
+ _context8.t0 = _context8["catch"](1);
541
+ this.logError('initWalletData error', {
542
+ error: _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0)
543
+ });
544
+ throw _context8.t0;
545
+ case 23:
534
546
  case "end":
535
547
  return _context8.stop();
536
548
  }
537
- }, _callee8, this);
549
+ }, _callee8, this, [[1, 19]]);
538
550
  }));
539
551
  function initWalletData(_x10) {
540
552
  return _initWalletData.apply(this, arguments);
@@ -753,11 +765,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
753
765
  key: "updateLocalOrderAsync",
754
766
  value: (function () {
755
767
  var _updateLocalOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
756
- var _params$orderData6, _params$orderData7, _params$cartSummary2, _params$totalInfo5, _params$totalInfo6, _params$totalInfo7, _params$totalInfo8;
768
+ var _params$orderData6, _params$orderData7, _params$cartSummary2, _params$totalInfo5, _params$totalInfo6, _params$totalInfo7, _params$totalInfo8, _this$store$currentOr9, _this$store$currentOr10;
757
769
  var validation, amountInfo, customerInfo, allOrders, existingOrder, _updated$payment2, _existingOrder$paymen, _updated$payment, currentTime, formattedExistPayments, _isNeedDeposit, _updated, syncedPayments, _syncedAmount, _totalAmount, _remainingExpectAmount, _depositDiffAmount, totalAmount, activePayments, paidAmount, remaining, _isNeedDeposit2, updated, syncedAmount, remainingExpectAmount, depositDiffAmount, isNeedDeposit, created, _syncedPayments, _syncedAmount2;
758
770
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
759
771
  while (1) switch (_context10.prev = _context10.next) {
760
772
  case 0:
773
+ this.payment.wallet.clearAllCache();
761
774
  this.logInfo('updateLocalOrderAsync called', {
762
775
  orderId: params.orderId,
763
776
  orderDataType: (_params$orderData6 = params.orderData) === null || _params$orderData6 === void 0 ? void 0 : _params$orderData6.type,
@@ -769,11 +782,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
769
782
  // 基础校验
770
783
  validation = validateLocalOrderData(params.orderData);
771
784
  if (validation.valid) {
772
- _context10.next = 4;
785
+ _context10.next = 5;
773
786
  break;
774
787
  }
775
788
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u8BA2\u5355\u6570\u636E\u9A8C\u8BC1\u5931\u8D25: ".concat(validation.errors.join(', ')));
776
- case 4:
789
+ case 5:
777
790
  // 计算金额
778
791
  amountInfo = extractAmountFromCartSummary(params.cartSummary); // 规范化补充字段
779
792
  params.orderData.created_at = formatDateTime(new Date());
@@ -799,19 +812,19 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
799
812
  }
800
813
 
801
814
  // 保留原有支付项:通过 orderId 找到现有订单(按 id 或 order_id 匹配)
802
- _context10.next = 17;
815
+ _context10.next = 18;
803
816
  return this.payment.getOrderListAsync();
804
- case 17:
817
+ case 18:
805
818
  allOrders = _context10.sent;
806
819
  existingOrder = allOrders.find(function (o) {
807
820
  return String(o.id) === String(params.orderId) || String(o.order_id) === String(params.orderId);
808
821
  });
809
822
  if (!existingOrder) {
810
- _context10.next = 71;
823
+ _context10.next = 72;
811
824
  break;
812
825
  }
813
826
  if (!(params.existPayment && params.existPayment.length > 0)) {
814
- _context10.next = 47;
827
+ _context10.next = 48;
815
828
  break;
816
829
  }
817
830
  this.logInfo('检测到云端支付项,将替换本地订单的支付项列表', {
@@ -835,7 +848,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
835
848
  });
836
849
  }); // 计算是否需要支付定金
837
850
  _isNeedDeposit = this.checkIsNeedDepositAsync(params.orderData.bookings, params.orderData.relation_products); // 更新订单,替换支付项列表
838
- _context10.next = 28;
851
+ _context10.next = 29;
839
852
  return this.payment.updateOrderAsync(existingOrder.uuid, {
840
853
  total_amount: amountInfo.totalAmount,
841
854
  is_deposit: _isNeedDeposit.hasDeposit ? 1 : 0,
@@ -853,21 +866,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
853
866
  amount_breakdown: amountInfo
854
867
  }
855
868
  });
856
- case 28:
857
- _context10.next = 30;
869
+ case 29:
870
+ _context10.next = 31;
858
871
  return this.payment.getPaymentOrderByUuidAsync(existingOrder.uuid);
859
- case 30:
872
+ case 31:
860
873
  _updated = _context10.sent;
861
874
  if (_updated) {
862
- _context10.next = 33;
875
+ _context10.next = 34;
863
876
  break;
864
877
  }
865
878
  throw createCheckoutError(CheckoutErrorType.UnknownError, '订单更新失败');
866
- case 33:
879
+ case 34:
867
880
  this.store.currentOrder = _updated;
868
- _context10.next = 36;
881
+ _context10.next = 37;
869
882
  return this.updateStateAmountToRemaining(false);
870
- case 36:
883
+ case 37:
871
884
  this.logInfo('本地订单更新成功(已替换云端支付项):', {
872
885
  orderId: params.orderId,
873
886
  uuid: _updated.uuid,
@@ -878,12 +891,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
878
891
  });
879
892
 
880
893
  // 事件通知
881
- _context10.next = 39;
894
+ _context10.next = 40;
882
895
  return this.core.effects.emit("".concat(this.name, ":onOrderCreated"), {
883
896
  order: _updated,
884
897
  timestamp: Date.now()
885
898
  });
886
- case 39:
899
+ case 40:
887
900
  // 计算已同步的支付金额
888
901
  syncedPayments = _updated.payment.filter(function (p) {
889
902
  return p.isSynced && p.status !== 'voided';
@@ -903,11 +916,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
903
916
  order_wait_pay_amount: Number(_depositDiffAmount) > 0 ? Number(_depositDiffAmount) : Number(_remainingExpectAmount)
904
917
  });
905
918
  return _context10.abrupt("return", _updated);
906
- case 47:
919
+ case 48:
907
920
  // 原有逻辑:保留现有支付项
908
921
  totalAmount = new Decimal(amountInfo.totalAmount || '0');
909
922
  activePayments = (existingOrder.payment || []).filter(function (p) {
910
- return p.status !== 'voided';
923
+ return p.status !== 'voided' && (!p.voucher_id || p.voucher_id && p.isSynced);
911
924
  });
912
925
  paidAmount = activePayments.reduce(function (sum, p) {
913
926
  var amt = new Decimal(p.amount || '0');
@@ -916,7 +929,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
916
929
  }, new Decimal(0));
917
930
  remaining = Decimal.max(0, totalAmount.minus(paidAmount)).toFixed(2); // 计算是否需要支付定金,如果需要默认切换到定金模式,以及记录定金总金额,并把当前默认待付金额调整为定金总金额
918
931
  _isNeedDeposit2 = this.checkIsNeedDepositAsync(params.orderData.bookings, params.orderData.relation_products); // 更新到支付模块(使用 uuid,不修改 payment 列表)
919
- _context10.next = 54;
932
+ _context10.next = 55;
920
933
  return this.payment.updateOrderAsync(existingOrder.uuid, {
921
934
  total_amount: amountInfo.totalAmount,
922
935
  is_deposit: _isNeedDeposit2.hasDeposit ? 1 : 0,
@@ -933,21 +946,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
933
946
  amount_breakdown: amountInfo
934
947
  }
935
948
  });
936
- case 54:
937
- _context10.next = 56;
949
+ case 55:
950
+ _context10.next = 57;
938
951
  return this.payment.getPaymentOrderByUuidAsync(existingOrder.uuid);
939
- case 56:
952
+ case 57:
940
953
  updated = _context10.sent;
941
954
  if (updated) {
942
- _context10.next = 59;
955
+ _context10.next = 60;
943
956
  break;
944
957
  }
945
958
  throw createCheckoutError(CheckoutErrorType.UnknownError, '订单更新失败');
946
- case 59:
959
+ case 60:
947
960
  this.store.currentOrder = updated;
948
- _context10.next = 62;
961
+ _context10.next = 63;
949
962
  return this.updateStateAmountToRemaining(false);
950
- case 62:
963
+ case 63:
951
964
  this.logInfo('本地订单更新成功(保留支付项):', {
952
965
  orderId: params.orderId,
953
966
  uuid: updated.uuid,
@@ -957,12 +970,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
957
970
  });
958
971
 
959
972
  // 事件通知(复用创建事件,便于上层监听刷新)
960
- _context10.next = 65;
973
+ _context10.next = 66;
961
974
  return this.core.effects.emit("".concat(this.name, ":onOrderCreated"), {
962
975
  order: updated,
963
976
  timestamp: Date.now()
964
977
  });
965
- case 65:
978
+ case 66:
966
979
  // 需要减去已经同步给后端的支付过的钱
967
980
  syncedAmount = activePayments.reduce(function (sum, p) {
968
981
  var amt = new Decimal(p.amount || '0');
@@ -978,10 +991,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
978
991
  order_wait_pay_amount: Number(depositDiffAmount) > 0 ? Number(depositDiffAmount) : Number(remainingExpectAmount)
979
992
  });
980
993
  return _context10.abrupt("return", updated);
981
- case 71:
994
+ case 72:
982
995
  // 计算是否需要支付定金,如果需要默认切换到定金模式,以及记录定金总金额,并把当前默认待付金额调整为定金总金额
983
996
  isNeedDeposit = this.checkIsNeedDepositAsync(params.orderData.bookings, params.orderData.relation_products); // 没找到现有订单时,回退为创建逻辑(用于异常兜底)
984
- _context10.next = 74;
997
+ _context10.next = 75;
985
998
  return this.payment.createPaymentOrderAsync({
986
999
  order_id: String(params.orderId),
987
1000
  total_amount: amountInfo.totalAmount,
@@ -1000,12 +1013,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1000
1013
  amount_breakdown: amountInfo
1001
1014
  }
1002
1015
  });
1003
- case 74:
1016
+ case 75:
1004
1017
  created = _context10.sent;
1005
1018
  this.store.currentOrder = created;
1006
1019
 
1007
1020
  // 🔧 新增: 如果有云端支付项,需要计算正确的待付金额
1008
- if (params.existPayment && params.existPayment.length > 0) {
1021
+ if (params.existPayment && params.existPayment.length > 0 || (_this$store$currentOr9 = this.store.currentOrder) !== null && _this$store$currentOr9 !== void 0 && _this$store$currentOr9.order_id && !isVirtualOrderId((_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.order_id)) {
1009
1022
  // 标记订单已同步(因为订单和支付项都来自云端)
1010
1023
  this.store.isOrderSynced = true;
1011
1024
 
@@ -1036,7 +1049,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1036
1049
  this.initWalletData();
1037
1050
  }
1038
1051
  return _context10.abrupt("return", created);
1039
- case 78:
1052
+ case 79:
1040
1053
  case "end":
1041
1054
  return _context10.stop();
1042
1055
  }
@@ -1119,8 +1132,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1119
1132
  }, {
1120
1133
  key: "getOrderOriginalData",
1121
1134
  value: function getOrderOriginalData() {
1122
- var _this$store$currentOr9;
1123
- return (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.order_info;
1135
+ var _this$store$currentOr11;
1136
+ return (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.order_info;
1124
1137
  }
1125
1138
 
1126
1139
  /**
@@ -1504,7 +1517,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1504
1517
  value: (function () {
1505
1518
  var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(paymentItem, orderUuid) {
1506
1519
  var _paymentItem$type, _paymentItem$code;
1507
- var isEftposPayment, shouldRepairFromIndexDb, _this$store$currentOr10, orderPaymentType, processedPaymentItem, metadata, paymentItemWithType, remainingAmount, _paymentItem$type2, _paymentItem$code2, _isEftposPayment, _isCashPayment, isCustomePayment, syncResult;
1520
+ var isEftposPayment, shouldRepairFromIndexDb, _this$store$currentOr12, orderPaymentType, processedPaymentItem, metadata, paymentItemWithType, remainingAmount, _paymentItem$type2, _paymentItem$code2, _isEftposPayment, isCash, isCustomePayment, syncResult;
1508
1521
  return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1509
1522
  while (1) switch (_context16.prev = _context16.next) {
1510
1523
  case 0:
@@ -1520,7 +1533,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1520
1533
  }
1521
1534
  this.logError('EFTPOS push payment repair triggered', {
1522
1535
  orderUuid: orderUuid,
1523
- currentOrderUuid: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.uuid,
1536
+ currentOrderUuid: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.uuid,
1524
1537
  paymentCode: paymentItem.code,
1525
1538
  paymentType: paymentItem.type
1526
1539
  });
@@ -1588,7 +1601,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1588
1601
  this.logInfo('订单金额还有待付的,同步 EFTPOS 支付');
1589
1602
  // 检查是否是 EFTPOS 支付,如果是则立即同步订单
1590
1603
  _isEftposPayment = ((_paymentItem$type2 = paymentItem.type) === null || _paymentItem$type2 === void 0 ? void 0 : _paymentItem$type2.toLowerCase()) === 'eftpos' || ((_paymentItem$code2 = paymentItem.code) === null || _paymentItem$code2 === void 0 ? void 0 : _paymentItem$code2.toUpperCase().includes('EFTPOS'));
1591
- _isCashPayment = paymentItem.code === 'CASHMANUAL';
1604
+ isCash = isCashPayment(paymentItem);
1592
1605
  isCustomePayment = paymentItem.type === 'custom';
1593
1606
  this.logInfo('EFTPOS 支付检查:', {
1594
1607
  paymentCode: paymentItem.code,
@@ -1596,7 +1609,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1596
1609
  isEftposPayment: _isEftposPayment,
1597
1610
  currentOrderSynced: this.store.isOrderSynced
1598
1611
  });
1599
- if (!(_isEftposPayment || _isCashPayment || isCustomePayment)) {
1612
+ if (!(_isEftposPayment || isCash || isCustomePayment)) {
1600
1613
  _context16.next = 52;
1601
1614
  break;
1602
1615
  }
@@ -1780,32 +1793,54 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1780
1793
  value: (function () {
1781
1794
  var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(voucherPaymentItems) {
1782
1795
  var _this4 = this;
1783
- var paymentItems, allPaymentItemsSynced, remainingAmount, remainingValue, isOrderSynced, orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder;
1796
+ var paymentItems, savedVoucherPaymentItems, allPaymentItemsSynced, remainingAmount, remainingValue, isOrderSynced, orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder;
1784
1797
  return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1785
1798
  while (1) switch (_context18.prev = _context18.next) {
1786
1799
  case 0:
1787
1800
  _context18.prev = 0;
1801
+ this.logInfo('updateVoucherPaymentItemsAsync called:', {
1802
+ voucherPaymentItems: voucherPaymentItems
1803
+ });
1804
+ // 检查是否有当前订单
1788
1805
  if (this.store.currentOrder) {
1789
- _context18.next = 3;
1806
+ _context18.next = 4;
1790
1807
  break;
1791
1808
  }
1792
1809
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '当前没有活跃订单,无法更新代金券支付项');
1793
- case 3:
1794
- _context18.next = 5;
1810
+ case 4:
1811
+ _context18.next = 6;
1795
1812
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
1796
- case 5:
1813
+ case 6:
1797
1814
  paymentItems = _context18.sent;
1815
+ if (!(!voucherPaymentItems || (voucherPaymentItems === null || voucherPaymentItems === void 0 ? void 0 : voucherPaymentItems.length) === 0)) {
1816
+ _context18.next = 13;
1817
+ break;
1818
+ }
1819
+ savedVoucherPaymentItems = (paymentItems === null || paymentItems === void 0 ? void 0 : paymentItems.filter(function (item) {
1820
+ return item.voucher_id && !item.isSynced;
1821
+ })) || [];
1822
+ this.logInfo('未传入 voucher 且本地订单无 voucher 记录,阻断updateVoucherPaymentItemsAsync', {
1823
+ voucherPaymentItems: voucherPaymentItems,
1824
+ savedVoucherPaymentItems: savedVoucherPaymentItems
1825
+ });
1826
+ if (!((savedVoucherPaymentItems === null || savedVoucherPaymentItems === void 0 ? void 0 : savedVoucherPaymentItems.length) === 0)) {
1827
+ _context18.next = 13;
1828
+ break;
1829
+ }
1830
+ this.updateStateAmountToRemaining(false);
1831
+ return _context18.abrupt("return");
1832
+ case 13:
1798
1833
  allPaymentItemsSynced = paymentItems.every(function (item) {
1799
1834
  return item.isSynced;
1800
1835
  });
1801
- _context18.next = 9;
1836
+ _context18.next = 16;
1802
1837
  return this.calculateRemainingAmountAsync();
1803
- case 9:
1838
+ case 16:
1804
1839
  remainingAmount = _context18.sent;
1805
1840
  remainingValue = new Decimal(remainingAmount);
1806
1841
  isOrderSynced = this.store.isOrderSynced;
1807
1842
  if (!(remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0 && allPaymentItemsSynced)) {
1808
- _context18.next = 15;
1843
+ _context18.next = 22;
1809
1844
  break;
1810
1845
  }
1811
1846
  this.logInfo('订单已同步且支付完成,跳过清空代金券操作避免重复同步:', {
@@ -1817,7 +1852,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1817
1852
  reason: 'Order synced and payment completed, skip clear vouchers to avoid duplicate sync'
1818
1853
  });
1819
1854
  return _context18.abrupt("return");
1820
- case 15:
1855
+ case 22:
1821
1856
  this.logInfo('开始批量更新代金券支付项:', {
1822
1857
  voucherPaymentItems: voucherPaymentItems
1823
1858
  });
@@ -1839,18 +1874,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1839
1874
  metadata: metadata
1840
1875
  });
1841
1876
  }); // 调用 Payment 模块的批量更新方法
1842
- _context18.next = 20;
1877
+ _context18.next = 27;
1843
1878
  return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItemsWithType);
1844
- case 20:
1879
+ case 27:
1845
1880
  // 🚀 清除计算缓存,确保获取最新数据
1846
1881
  this.clearCalculationCache();
1847
1882
 
1848
1883
  // 重新从Payment模块获取最新的订单数据,确保支付项同步
1849
1884
  currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1850
1885
  isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
1851
- _context18.next = 25;
1886
+ _context18.next = 32;
1852
1887
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1853
- case 25:
1888
+ case 32:
1854
1889
  updatedOrder = _context18.sent;
1855
1890
  if (updatedOrder) {
1856
1891
  // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
@@ -1865,10 +1900,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1865
1900
  }
1866
1901
 
1867
1902
  // 更新 stateAmount 为剩余未支付金额
1868
- _context18.next = 29;
1903
+ _context18.next = 36;
1869
1904
  return this.updateStateAmountToRemaining(false);
1870
- case 29:
1871
- _context18.next = 31;
1905
+ case 36:
1906
+ _context18.next = 38;
1872
1907
  return this.core.effects.emit("".concat(this.name, ":onPaymentStarted"), {
1873
1908
  orderUuid: this.store.currentOrder.uuid,
1874
1909
  paymentMethodCode: 'VOUCHER_BATCH',
@@ -1877,23 +1912,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1877
1912
  }, 0).toFixed(2),
1878
1913
  timestamp: Date.now()
1879
1914
  });
1880
- case 31:
1915
+ case 38:
1881
1916
  this.logInfo('代金券支付项批量更新成功');
1882
- _context18.next = 40;
1917
+ _context18.next = 47;
1883
1918
  break;
1884
- case 34:
1885
- _context18.prev = 34;
1919
+ case 41:
1920
+ _context18.prev = 41;
1886
1921
  _context18.t0 = _context18["catch"](0);
1887
- this.logError('[Checkout] 批量更新代金券支付项失败:', _context18.t0);
1888
- _context18.next = 39;
1922
+ this.logInfo('[Checkout] 批量更新代金券支付项失败:', {
1923
+ error: _context18.t0
1924
+ });
1925
+ _context18.next = 46;
1889
1926
  return this.handleError(_context18.t0, CheckoutErrorType.PaymentFailed);
1890
- case 39:
1927
+ case 46:
1891
1928
  throw _context18.t0;
1892
- case 40:
1929
+ case 47:
1893
1930
  case "end":
1894
1931
  return _context18.stop();
1895
1932
  }
1896
- }, _callee18, this, [[0, 34]]);
1933
+ }, _callee18, this, [[0, 41]]);
1897
1934
  }));
1898
1935
  function updateVoucherPaymentItemsAsync(_x18) {
1899
1936
  return _updateVoucherPaymentItemsAsync.apply(this, arguments);
@@ -2018,7 +2055,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2018
2055
  key: "setDepositAmountAsync",
2019
2056
  value: (function () {
2020
2057
  var _setDepositAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(depositAmount) {
2021
- var _this$store$currentOr11, _this$store$currentOr12;
2058
+ var _this$store$currentOr13, _this$store$currentOr14;
2022
2059
  var depositValue, formattedDepositAmount, oldDepositAmount, updateParams;
2023
2060
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2024
2061
  while (1) switch (_context20.prev = _context20.next) {
@@ -2026,8 +2063,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2026
2063
  this.logInfo('setDepositAmountAsync called', {
2027
2064
  depositAmount: depositAmount,
2028
2065
  hasCurrentOrder: !!this.store.currentOrder,
2029
- currentOrderId: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.order_id,
2030
- currentTotalAmount: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.total_amount
2066
+ currentOrderId: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.order_id,
2067
+ currentTotalAmount: (_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.total_amount
2031
2068
  });
2032
2069
  _context20.prev = 1;
2033
2070
  // 验证定金金额格式
@@ -2147,17 +2184,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2147
2184
  key: "manualSyncOrderAsync",
2148
2185
  value: (function () {
2149
2186
  var _manualSyncOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
2150
- var _this$store$currentOr13, _this$store$currentOr14, _this$store$currentOr15;
2151
- var _this$store$currentOr16, orderUuid, oldOrderId, syncResult, finalOrderId, finalIsVirtual, newRes, _this$store$currentOr17, errorMessage;
2187
+ var _this$store$currentOr15, _this$store$currentOr16, _this$store$currentOr17;
2188
+ var _this$store$currentOr18, orderUuid, oldOrderId, syncResult, finalOrderId, finalIsVirtual, newRes, _this$store$currentOr19, errorMessage;
2152
2189
  return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2153
2190
  while (1) switch (_context21.prev = _context21.next) {
2154
2191
  case 0:
2155
2192
  console.log('manualSyncOrderAsync called');
2156
2193
  this.logInfo('manualSyncOrderAsync called', {
2157
2194
  hasCurrentOrder: !!this.store.currentOrder,
2158
- currentOrderId: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.order_id,
2159
- orderUuid: (_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.uuid,
2160
- totalAmount: (_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.total_amount,
2195
+ currentOrderId: (_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.order_id,
2196
+ orderUuid: (_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.uuid,
2197
+ totalAmount: (_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.total_amount,
2161
2198
  isOrderSynced: this.store.isOrderSynced,
2162
2199
  isVirtualOrderId: this.store.currentOrder ? isVirtualOrderId(this.store.currentOrder.order_id) : false
2163
2200
  });
@@ -2217,7 +2254,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2217
2254
  this.logError('[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!');
2218
2255
  }
2219
2256
  newRes = _objectSpread(_objectSpread({}, syncResult), {}, {
2220
- is_deposit: ((_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.is_deposit) || 0
2257
+ is_deposit: ((_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.is_deposit) || 0
2221
2258
  });
2222
2259
  _context21.next = 30;
2223
2260
  return this.updateStateAmountToRemaining(false);
@@ -2231,7 +2268,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2231
2268
  return _context21.abrupt("return", {
2232
2269
  success: false,
2233
2270
  message: "\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(errorMessage),
2234
- orderUuid: (_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.uuid
2271
+ orderUuid: (_this$store$currentOr19 = this.store.currentOrder) === null || _this$store$currentOr19 === void 0 ? void 0 : _this$store$currentOr19.uuid
2235
2272
  });
2236
2273
  case 38:
2237
2274
  case "end":
@@ -2308,15 +2345,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2308
2345
  key: "cancelCurrentOrderAsync",
2309
2346
  value: (function () {
2310
2347
  var _cancelCurrentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(cancelReason) {
2311
- var _this$store$currentOr18, _this$store$currentOr19, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
2348
+ var _this$store$currentOr20, _this$store$currentOr21, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
2312
2349
  return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2313
2350
  while (1) switch (_context22.prev = _context22.next) {
2314
2351
  case 0:
2315
2352
  _context22.prev = 0;
2316
2353
  this.logInfo('开始取消当前本地订单:', {
2317
2354
  hasCurrentOrder: !!this.store.currentOrder,
2318
- orderUuid: (_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.uuid,
2319
- orderId: (_this$store$currentOr19 = this.store.currentOrder) === null || _this$store$currentOr19 === void 0 ? void 0 : _this$store$currentOr19.order_id,
2355
+ orderUuid: (_this$store$currentOr20 = this.store.currentOrder) === null || _this$store$currentOr20 === void 0 ? void 0 : _this$store$currentOr20.uuid,
2356
+ orderId: (_this$store$currentOr21 = this.store.currentOrder) === null || _this$store$currentOr21 === void 0 ? void 0 : _this$store$currentOr21.order_id,
2320
2357
  isOrderSynced: this.store.isOrderSynced,
2321
2358
  cancelReason: cancelReason
2322
2359
  });
@@ -2429,7 +2466,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2429
2466
  key: "saveForLaterPaymentAsync",
2430
2467
  value: (function () {
2431
2468
  var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
2432
- var orderUuid, currentOrderId, allPaymentItems, orderPaymentStatus, syncResult, _this$store$currentOr20, errorMessage;
2469
+ var orderUuid, currentOrderId, allPaymentItems, orderPaymentStatus, syncResult, _this$store$currentOr22, errorMessage;
2433
2470
  return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2434
2471
  while (1) switch (_context23.prev = _context23.next) {
2435
2472
  case 0:
@@ -2488,7 +2525,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2488
2525
  return _context23.abrupt("return", {
2489
2526
  success: false,
2490
2527
  message: "\u8BA2\u5355\u4FDD\u5B58\u5931\u8D25: ".concat(errorMessage),
2491
- orderUuid: (_this$store$currentOr20 = this.store.currentOrder) === null || _this$store$currentOr20 === void 0 ? void 0 : _this$store$currentOr20.uuid
2528
+ orderUuid: (_this$store$currentOr22 = this.store.currentOrder) === null || _this$store$currentOr22 === void 0 ? void 0 : _this$store$currentOr22.uuid
2492
2529
  });
2493
2530
  case 22:
2494
2531
  case "end":
@@ -2511,7 +2548,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2511
2548
  key: "updateOrderNoteAsync",
2512
2549
  value: (function () {
2513
2550
  var _updateOrderNoteAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(note) {
2514
- var _this$store$currentOr21, _this$store$currentOr22, oldNote, orderInPayment;
2551
+ var _this$store$currentOr23, _this$store$currentOr24, oldNote, orderInPayment;
2515
2552
  return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2516
2553
  while (1) switch (_context24.prev = _context24.next) {
2517
2554
  case 0:
@@ -2523,7 +2560,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2523
2560
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '没有本地订单数据,无法更新备注');
2524
2561
  case 3:
2525
2562
  console.log('[Checkout] 更新订单备注:', {
2526
- orderUuid: (_this$store$currentOr21 = this.store.currentOrder) === null || _this$store$currentOr21 === void 0 ? void 0 : _this$store$currentOr21.uuid,
2563
+ orderUuid: (_this$store$currentOr23 = this.store.currentOrder) === null || _this$store$currentOr23 === void 0 ? void 0 : _this$store$currentOr23.uuid,
2527
2564
  oldNote: this.store.localOrderData.shop_note,
2528
2565
  newNote: note
2529
2566
  });
@@ -2556,7 +2593,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2556
2593
  case 17:
2557
2594
  _context24.next = 19;
2558
2595
  return this.core.effects.emit("".concat(this.name, ":onOrderNoteChanged"), {
2559
- orderUuid: (_this$store$currentOr22 = this.store.currentOrder) === null || _this$store$currentOr22 === void 0 ? void 0 : _this$store$currentOr22.uuid,
2596
+ orderUuid: (_this$store$currentOr24 = this.store.currentOrder) === null || _this$store$currentOr24 === void 0 ? void 0 : _this$store$currentOr24.uuid,
2560
2597
  oldNote: oldNote,
2561
2598
  newNote: note,
2562
2599
  timestamp: Date.now()
@@ -2628,7 +2665,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2628
2665
  key: "handlePaymentSuccess",
2629
2666
  value: (function () {
2630
2667
  var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(data) {
2631
- var _this$store$currentOr23;
2668
+ var _this$store$currentOr25;
2632
2669
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2633
2670
  while (1) switch (_context26.prev = _context26.next) {
2634
2671
  case 0:
@@ -2639,7 +2676,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2639
2676
  return this.core.effects.emit("".concat(this.name, ":onPaymentSuccess"), {
2640
2677
  orderUuid: data.orderUuid,
2641
2678
  paymentMethodCode: '',
2642
- amount: ((_this$store$currentOr23 = this.store.currentOrder) === null || _this$store$currentOr23 === void 0 ? void 0 : _this$store$currentOr23.total_amount) || '0',
2679
+ amount: ((_this$store$currentOr25 = this.store.currentOrder) === null || _this$store$currentOr25 === void 0 ? void 0 : _this$store$currentOr25.total_amount) || '0',
2643
2680
  timestamp: data.timestamp
2644
2681
  });
2645
2682
  case 4:
@@ -2664,7 +2701,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2664
2701
  key: "handlePaymentError",
2665
2702
  value: (function () {
2666
2703
  var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(data) {
2667
- var _this$store$currentOr24;
2704
+ var _this$store$currentOr26;
2668
2705
  var error;
2669
2706
  return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2670
2707
  while (1) switch (_context27.prev = _context27.next) {
@@ -2677,7 +2714,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2677
2714
  return this.core.effects.emit("".concat(this.name, ":onPaymentFailed"), {
2678
2715
  orderUuid: data.orderUuid,
2679
2716
  paymentMethodCode: '',
2680
- amount: ((_this$store$currentOr24 = this.store.currentOrder) === null || _this$store$currentOr24 === void 0 ? void 0 : _this$store$currentOr24.total_amount) || '0',
2717
+ amount: ((_this$store$currentOr26 = this.store.currentOrder) === null || _this$store$currentOr26 === void 0 ? void 0 : _this$store$currentOr26.total_amount) || '0',
2681
2718
  timestamp: data.timestamp
2682
2719
  });
2683
2720
  case 5:
@@ -2716,7 +2753,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2716
2753
  while (1) switch (_context28.prev = _context28.next) {
2717
2754
  case 0:
2718
2755
  // 检查是否是现金支付
2719
- cashPayment = isCashPayment(paymentItem.code, paymentItem.type);
2756
+ cashPayment = isCashPayment(paymentItem);
2720
2757
  if (cashPayment) {
2721
2758
  _context28.next = 3;
2722
2759
  break;
@@ -3103,13 +3140,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3103
3140
  return payment.status !== 'voided';
3104
3141
  }) // 只计算未撤销的支付项
3105
3142
  .reduce(function (sum, payment) {
3106
- var amount = new Decimal(payment.amount || '0');
3107
- var roundingAmount = new Decimal(payment.rounding_amount || '0');
3108
-
3109
- // 使用 Decimal.js 计算实际支付有效金额:
3110
- // rounding_amount 为负数时,表示抹掉的金额,应该按绝对值加到实际支付中
3111
- // 例如:amount=15, rounding_amount=-0.2,实际相当于支付了15.2(抹掉了0.2元的零头)
3112
- var effectiveAmount = amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
3143
+ // const amount = new Decimal(payment.amount || '0');
3144
+ // 计算有效支付金额:支付金额 + 抹零金额的绝对值
3145
+ // 当 rounding_amount 为负数时,表示抹掉的金额,按绝对值计算有效支付
3146
+ // 例如:amount=15, rounding_amount=-0.2,有效支付=15.2(抹掉0.2元零头)
3147
+ // 例2:amount=15,rounding_amount=0.2,有效支付 14.8
3148
+ var paymentAmount = new Decimal(payment.amount || 0);
3149
+ var roundingAmount = new Decimal(payment.rounding_amount || 0);
3150
+ var effectiveAmount = paymentAmount.minus(roundingAmount);
3113
3151
  return sum.add(effectiveAmount);
3114
3152
  }, new Decimal(0));
3115
3153
  return paidAmount.toFixed(2);
@@ -4166,18 +4204,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4166
4204
  key: "syncOrderToBackendWithReturn",
4167
4205
  value: (function () {
4168
4206
  var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
4169
- var _this7 = this,
4170
- _this$store$currentOr25,
4171
- _this$store$currentOr26,
4172
- _this$store$currentCu2,
4207
+ var _this7 = this;
4208
+ var isManual,
4209
+ customPaymentItems,
4210
+ paymentStatus,
4211
+ orderLockKey,
4212
+ existingInFlight,
4213
+ resolveInFlight,
4214
+ rejectInFlight,
4215
+ inFlightPromise,
4173
4216
  _this$store$currentOr27,
4217
+ _this$store$currentOr28,
4218
+ _this$store$currentCu2,
4219
+ _this$otherParams2,
4220
+ _this$store$currentOr29,
4174
4221
  _this$store$localOrde,
4175
4222
  _this$store$localOrde2,
4176
4223
  _checkoutResponse12,
4177
- _checkoutResponse13;
4178
- var isManual,
4179
- customPaymentItems,
4180
- paymentStatus,
4224
+ _checkoutResponse13,
4181
4225
  currentOrderId,
4182
4226
  isUpdateOperation,
4183
4227
  paymentItems,
@@ -4210,6 +4254,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4210
4254
  _iterator4,
4211
4255
  _step4,
4212
4256
  paymentUuid,
4257
+ result,
4258
+ currentInFlight,
4213
4259
  _args41 = arguments;
4214
4260
  return _regeneratorRuntime().wrap(function _callee41$(_context41) {
4215
4261
  while (1) switch (_context41.prev = _context41.next) {
@@ -4223,6 +4269,36 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4223
4269
  }
4224
4270
  throw new Error('缺少必要的订单数据,无法同步到后端');
4225
4271
  case 5:
4272
+ orderLockKey = this.store.currentOrder.uuid || this.store.currentOrder.order_id;
4273
+ if (orderLockKey) {
4274
+ _context41.next = 8;
4275
+ break;
4276
+ }
4277
+ throw new Error('缺少订单标识,无法同步到后端');
4278
+ case 8:
4279
+ existingInFlight = this.syncOrderToBackendInFlightByOrderKey.get(orderLockKey);
4280
+ if (!existingInFlight) {
4281
+ _context41.next = 14;
4282
+ break;
4283
+ }
4284
+ this.logInfo('syncOrderToBackendWithReturn 触发锁:当前订单正在同步中,将等待当前同步结束', {
4285
+ orderLockKey: orderLockKey,
4286
+ orderUuid: this.store.currentOrder.uuid,
4287
+ orderId: this.store.currentOrder.order_id,
4288
+ isManual: isManual,
4289
+ hasCustomPaymentItems: !!customPaymentItems
4290
+ });
4291
+ _context41.next = 13;
4292
+ return existingInFlight;
4293
+ case 13:
4294
+ return _context41.abrupt("return", _context41.sent);
4295
+ case 14:
4296
+ inFlightPromise = new Promise(function (resolve, reject) {
4297
+ resolveInFlight = resolve;
4298
+ rejectInFlight = reject;
4299
+ });
4300
+ this.syncOrderToBackendInFlightByOrderKey.set(orderLockKey, inFlightPromise);
4301
+ _context41.prev = 16;
4226
4302
  this.logInfo('syncOrderToBackendWithReturn called', {
4227
4303
  isManual: isManual
4228
4304
  });
@@ -4239,14 +4315,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4239
4315
  // 获取当前订单的支付项
4240
4316
  _context41.t0 = customPaymentItems;
4241
4317
  if (_context41.t0) {
4242
- _context41.next = 14;
4318
+ _context41.next = 26;
4243
4319
  break;
4244
4320
  }
4245
- _context41.next = 13;
4321
+ _context41.next = 25;
4246
4322
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
4247
- case 13:
4323
+ case 25:
4248
4324
  _context41.t0 = _context41.sent;
4249
- case 14:
4325
+ case 26:
4250
4326
  paymentItems = _context41.t0;
4251
4327
  // 处理支付项数据,确保包含完整的 metadata
4252
4328
  processedPaymentItems = paymentItems.map(function (item) {
@@ -4258,7 +4334,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4258
4334
  })
4259
4335
  });
4260
4336
  }); // 确定最终的定金金额:优先使用手动设置的值,否则从支付项中计算
4261
- manualDepositAmount = ((_this$store$currentOr25 = this.store.currentOrder) === null || _this$store$currentOr25 === void 0 ? void 0 : _this$store$currentOr25.deposit_amount) || '0.00'; // 优先级逻辑:手动设置的定金金额 > 从支付项计算的金额
4337
+ manualDepositAmount = ((_this$store$currentOr27 = this.store.currentOrder) === null || _this$store$currentOr27 === void 0 ? void 0 : _this$store$currentOr27.deposit_amount) || '0.00'; // 优先级逻辑:手动设置的定金金额 > 从支付项计算的金额
4262
4338
  manualDepositValue = new Decimal(manualDepositAmount);
4263
4339
  if (manualDepositValue.gt(0)) {
4264
4340
  // 如果手动设置了定金金额且大于0,使用手动设置的值
@@ -4318,7 +4394,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4318
4394
  }),
4319
4395
  manualDepositAmount: manualDepositAmount,
4320
4396
  finalDepositAmount: finalDepositAmount,
4321
- isDeposit: ((_this$store$currentOr26 = this.store.currentOrder) === null || _this$store$currentOr26 === void 0 ? void 0 : _this$store$currentOr26.is_deposit) || 0
4397
+ isDeposit: ((_this$store$currentOr28 = this.store.currentOrder) === null || _this$store$currentOr28 === void 0 ? void 0 : _this$store$currentOr28.is_deposit) || 0
4322
4398
  });
4323
4399
 
4324
4400
  // 计算订单状态,优先读取外面传递的,如果没有则根据订单支付数据来
@@ -4365,7 +4441,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4365
4441
  currency_code: this.otherParams.currency_code,
4366
4442
  currency_symbol: this.otherParams.currency_symbol,
4367
4443
  currency_format: this.otherParams.currency_format,
4368
- is_deposit: ((_this$store$currentOr27 = this.store.currentOrder) !== null && _this$store$currentOr27 !== void 0 && _this$store$currentOr27.is_deposit || Number(finalDepositAmount) > 0 ? 1 : 0) || 0,
4444
+ business_code: ((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.business_code) || undefined,
4445
+ 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,
4369
4446
  deposit_amount: finalDepositAmount,
4370
4447
  // 使用最终确定的定金金额(手动设置优先)
4371
4448
  product_tax_fee: this.store.localOrderData.tax_fee,
@@ -4396,7 +4473,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4396
4473
 
4397
4474
  // 发送下单接口请求开始事件
4398
4475
  startTime = Date.now();
4399
- _context41.next = 30;
4476
+ _context41.next = 42;
4400
4477
  return this.core.effects.emit("".concat(this.name, ":onOrderSubmitStart"), {
4401
4478
  orderUuid: this.store.currentOrder.uuid,
4402
4479
  operation: isUpdateOperation ? 'update' : 'create',
@@ -4404,9 +4481,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4404
4481
  paymentItemCount: paymentItems.length,
4405
4482
  timestamp: startTime
4406
4483
  });
4407
- case 30:
4484
+ case 42:
4408
4485
  submitSuccess = false;
4409
- _context41.prev = 31;
4486
+ _context41.prev = 43;
4410
4487
  // 记录接口调用参数
4411
4488
  this.logInfo('Calling backend checkout API', _objectSpread({
4412
4489
  url: '/order/checkout',
@@ -4414,24 +4491,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4414
4491
  }, orderParams));
4415
4492
 
4416
4493
  // 调用 Order 模块的专用 createOrderByCheckout 方法
4417
- _context41.next = 35;
4494
+ _context41.next = 47;
4418
4495
  return this.order.createOrderByCheckout(orderParams);
4419
- case 35:
4496
+ case 47:
4420
4497
  checkoutResponse = _context41.sent;
4421
4498
  submitSuccess = true;
4422
4499
  this.store.currentOrder.payment_status = checkoutResponse.data.payment_status;
4423
4500
  this.logInfo('下单接口调用成功', checkoutResponse);
4424
- _context41.next = 49;
4501
+ _context41.next = 61;
4425
4502
  break;
4426
- case 41:
4427
- _context41.prev = 41;
4428
- _context41.t1 = _context41["catch"](31);
4503
+ case 53:
4504
+ _context41.prev = 53;
4505
+ _context41.t1 = _context41["catch"](43);
4429
4506
  submitSuccess = false;
4430
4507
  submitError = _context41.t1 instanceof Error ? _context41.t1.message : String(_context41.t1);
4431
4508
  this.logError('下单接口调用失败:', submitError);
4432
4509
 
4433
4510
  // 发送订单同步失败事件(网络错误或请求失败)
4434
- _context41.next = 48;
4511
+ _context41.next = 60;
4435
4512
  return this.core.effects.emit("".concat(this.name, ":onOrderSyncFailed"), {
4436
4513
  orderUuid: this.store.currentOrder.uuid,
4437
4514
  operation: isUpdateOperation ? 'update' : 'create',
@@ -4441,11 +4518,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4441
4518
  duration: Date.now() - startTime,
4442
4519
  timestamp: Date.now()
4443
4520
  });
4444
- case 48:
4521
+ case 60:
4445
4522
  throw _context41.t1;
4446
- case 49:
4447
- _context41.prev = 49;
4448
- _context41.next = 52;
4523
+ case 61:
4524
+ _context41.prev = 61;
4525
+ _context41.next = 64;
4449
4526
  return this.core.effects.emit("".concat(this.name, ":onOrderSubmitEnd"), {
4450
4527
  success: submitSuccess,
4451
4528
  orderUuid: this.store.currentOrder.uuid,
@@ -4456,18 +4533,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4456
4533
  duration: Date.now() - startTime,
4457
4534
  timestamp: Date.now()
4458
4535
  });
4459
- case 52:
4460
- return _context41.finish(49);
4461
- case 53:
4536
+ case 64:
4537
+ return _context41.finish(61);
4538
+ case 65:
4462
4539
  // 检查响应状态是否为成功状态
4463
4540
  responseStatus = (_checkoutResponse12 = checkoutResponse) === null || _checkoutResponse12 === void 0 ? void 0 : _checkoutResponse12.status;
4464
4541
  isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse13 = checkoutResponse) === null || _checkoutResponse13 === void 0 ? void 0 : _checkoutResponse13.code) === 200;
4465
4542
  if (isSuccessResponse) {
4466
- _context41.next = 60;
4543
+ _context41.next = 72;
4467
4544
  break;
4468
4545
  }
4469
4546
  errorMessage = ((_checkoutResponse14 = checkoutResponse) === null || _checkoutResponse14 === void 0 ? void 0 : _checkoutResponse14.message) || '订单同步失败,后端返回非成功状态'; // 发送订单同步失败事件
4470
- _context41.next = 59;
4547
+ _context41.next = 71;
4471
4548
  return this.core.effects.emit("".concat(this.name, ":onOrderSyncFailed"), {
4472
4549
  orderUuid: this.store.currentOrder.uuid,
4473
4550
  operation: isUpdateOperation ? 'update' : 'create',
@@ -4478,18 +4555,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4478
4555
  duration: Date.now() - startTime,
4479
4556
  timestamp: Date.now()
4480
4557
  });
4481
- case 59:
4558
+ case 71:
4482
4559
  throw new Error(errorMessage);
4483
- case 60:
4560
+ case 72:
4484
4561
  if (!isUpdateOperation) {
4485
- _context41.next = 64;
4562
+ _context41.next = 76;
4486
4563
  break;
4487
4564
  }
4488
4565
  // 更新操作:使用现有的订单ID
4489
4566
  realOrderId = currentOrderId;
4490
- _context41.next = 97;
4567
+ _context41.next = 109;
4491
4568
  break;
4492
- case 64:
4569
+ case 76:
4493
4570
  // 创建操作:从响应中提取新的订单ID
4494
4571
  extractedOrderId = (_checkoutResponse15 = checkoutResponse) === null || _checkoutResponse15 === void 0 || (_checkoutResponse15 = _checkoutResponse15.data) === null || _checkoutResponse15 === void 0 ? void 0 : _checkoutResponse15.order_id; // 如果data.order_id不存在,尝试直接从根级获取
4495
4572
  if (!extractedOrderId) {
@@ -4511,12 +4588,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4511
4588
  oldOrderId: this.store.currentOrder.order_id,
4512
4589
  newOrderId: realOrderId
4513
4590
  });
4514
- _context41.prev = 70;
4591
+ _context41.prev = 82;
4515
4592
  latestPaymentStatus = this.store.currentOrder.payment_status;
4516
4593
  previousOrder = this.store.currentOrder;
4517
- _context41.next = 75;
4594
+ _context41.next = 87;
4518
4595
  return this.payment.replaceOrderIdByUuidAsync(previousOrder.uuid, realOrderId);
4519
- case 75:
4596
+ case 87:
4520
4597
  updatedOrder = _context41.sent;
4521
4598
  this.logInfo('Payment模块替换订单ID结果:', {
4522
4599
  wasSuccessful: !!updatedOrder,
@@ -4524,7 +4601,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4524
4601
  expectedOrderId: realOrderId
4525
4602
  });
4526
4603
  if (!updatedOrder) {
4527
- _context41.next = 86;
4604
+ _context41.next = 98;
4528
4605
  break;
4529
4606
  }
4530
4607
  this.logInfo('Payment模块返回的更新后订单:', {
@@ -4540,18 +4617,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4540
4617
 
4541
4618
  // 同步更新 Payment 模块 DB,避免后续读取 DB 时又拿回旧状态
4542
4619
  if (!latestPaymentStatus) {
4543
- _context41.next = 83;
4620
+ _context41.next = 95;
4544
4621
  break;
4545
4622
  }
4546
- _context41.next = 83;
4623
+ _context41.next = 95;
4547
4624
  return this.payment.updateOrderAsync(previousOrder.uuid, {
4548
4625
  payment_status: latestPaymentStatus
4549
4626
  });
4550
- case 83:
4627
+ case 95:
4551
4628
  this.logInfo('[Checkout] 订单ID替换成功,当前订单ID:', this.store.currentOrder.order_id);
4552
- _context41.next = 90;
4629
+ _context41.next = 102;
4553
4630
  break;
4554
- case 86:
4631
+ case 98:
4555
4632
  this.logError('[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换');
4556
4633
 
4557
4634
  // 如果替换失败,手动更新订单ID
@@ -4562,62 +4639,62 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4562
4639
  afterReplacement: this.store.currentOrder.order_id,
4563
4640
  目标ID: realOrderId
4564
4641
  });
4565
- case 90:
4566
- _context41.next = 97;
4642
+ case 102:
4643
+ _context41.next = 109;
4567
4644
  break;
4568
- case 92:
4569
- _context41.prev = 92;
4570
- _context41.t2 = _context41["catch"](70);
4645
+ case 104:
4646
+ _context41.prev = 104;
4647
+ _context41.t2 = _context41["catch"](82);
4571
4648
  this.logError('调用Payment模块替换订单ID时发生错误:', _context41.t2);
4572
4649
 
4573
4650
  // 发生错误时也进行手动替换
4574
4651
  this.store.currentOrder.order_id = realOrderId;
4575
4652
  this.logInfo('错误恢复:手动设置订单ID:', realOrderId);
4576
- case 97:
4577
- _context41.prev = 97;
4653
+ case 109:
4654
+ _context41.prev = 109;
4578
4655
  syncedPaymentUuids = processedPaymentItems.filter(function (item) {
4579
4656
  return item.status !== 'voided';
4580
4657
  }).map(function (item) {
4581
4658
  return item.uuid;
4582
4659
  }).filter(Boolean);
4583
4660
  _iterator4 = _createForOfIteratorHelper(syncedPaymentUuids);
4584
- _context41.prev = 100;
4661
+ _context41.prev = 112;
4585
4662
  _iterator4.s();
4586
- case 102:
4663
+ case 114:
4587
4664
  if ((_step4 = _iterator4.n()).done) {
4588
- _context41.next = 108;
4665
+ _context41.next = 120;
4589
4666
  break;
4590
4667
  }
4591
4668
  paymentUuid = _step4.value;
4592
- _context41.next = 106;
4669
+ _context41.next = 118;
4593
4670
  return this.payment.updatePaymentAsync(this.store.currentOrder.uuid, paymentUuid, {
4594
4671
  isSynced: true,
4595
4672
  syncError: undefined
4596
4673
  });
4597
- case 106:
4598
- _context41.next = 102;
4674
+ case 118:
4675
+ _context41.next = 114;
4599
4676
  break;
4600
- case 108:
4601
- _context41.next = 113;
4677
+ case 120:
4678
+ _context41.next = 125;
4602
4679
  break;
4603
- case 110:
4604
- _context41.prev = 110;
4605
- _context41.t3 = _context41["catch"](100);
4680
+ case 122:
4681
+ _context41.prev = 122;
4682
+ _context41.t3 = _context41["catch"](112);
4606
4683
  _iterator4.e(_context41.t3);
4607
- case 113:
4608
- _context41.prev = 113;
4684
+ case 125:
4685
+ _context41.prev = 125;
4609
4686
  _iterator4.f();
4610
- return _context41.finish(113);
4611
- case 116:
4612
- _context41.next = 121;
4687
+ return _context41.finish(125);
4688
+ case 128:
4689
+ _context41.next = 133;
4613
4690
  break;
4614
- case 118:
4615
- _context41.prev = 118;
4616
- _context41.t4 = _context41["catch"](97);
4691
+ case 130:
4692
+ _context41.prev = 130;
4693
+ _context41.t4 = _context41["catch"](109);
4617
4694
  this.logWarning('标记支付项已同步失败(不阻塞主流程)', {
4618
4695
  error: _context41.t4
4619
4696
  });
4620
- case 121:
4697
+ case 133:
4621
4698
  // 标记订单已同步
4622
4699
  this.store.isOrderSynced = true;
4623
4700
 
@@ -4625,7 +4702,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4625
4702
  this.clearCalculationCache();
4626
4703
 
4627
4704
  // 触发订单同步完成事件
4628
- _context41.next = 125;
4705
+ _context41.next = 137;
4629
4706
  return this.core.effects.emit("".concat(this.name, ":onOrderSynced"), {
4630
4707
  orderUuid: this.store.currentOrder.uuid,
4631
4708
  realOrderId: realOrderId,
@@ -4634,18 +4711,33 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4634
4711
  isManual: isManual,
4635
4712
  response: checkoutResponse
4636
4713
  });
4637
- case 125:
4638
- return _context41.abrupt("return", {
4714
+ case 137:
4715
+ // 返回同步结果
4716
+ result = {
4639
4717
  success: true,
4640
4718
  orderId: realOrderId,
4641
4719
  orderUuid: this.store.currentOrder.uuid,
4642
4720
  response: checkoutResponse
4643
- });
4644
- case 126:
4721
+ };
4722
+ resolveInFlight(result);
4723
+ return _context41.abrupt("return", result);
4724
+ case 142:
4725
+ _context41.prev = 142;
4726
+ _context41.t5 = _context41["catch"](16);
4727
+ rejectInFlight(_context41.t5);
4728
+ throw _context41.t5;
4729
+ case 146:
4730
+ _context41.prev = 146;
4731
+ currentInFlight = this.syncOrderToBackendInFlightByOrderKey.get(orderLockKey);
4732
+ if (currentInFlight === inFlightPromise) {
4733
+ this.syncOrderToBackendInFlightByOrderKey.delete(orderLockKey);
4734
+ }
4735
+ return _context41.finish(146);
4736
+ case 150:
4645
4737
  case "end":
4646
4738
  return _context41.stop();
4647
4739
  }
4648
- }, _callee41, this, [[31, 41, 49, 53], [70, 92], [97, 118], [100, 110, 113, 116]]);
4740
+ }, _callee41, this, [[16, 142, 146, 150], [43, 53, 61, 65], [82, 104], [109, 130], [112, 122, 125, 128]]);
4649
4741
  }));
4650
4742
  function syncOrderToBackendWithReturn() {
4651
4743
  return _syncOrderToBackendWithReturn.apply(this, arguments);
@@ -4664,12 +4756,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4664
4756
  while (1) switch (_context42.prev = _context42.next) {
4665
4757
  case 0:
4666
4758
  _ref5 = _args42.length > 1 && _args42[1] !== undefined ? _args42[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
4759
+ this.logInfo('setOtherParams called', {
4760
+ metadata: {
4761
+ params: params,
4762
+ cover: cover
4763
+ }
4764
+ });
4667
4765
  if (cover) {
4668
4766
  this.otherParams = params;
4669
4767
  } else {
4670
4768
  this.otherParams = _objectSpread(_objectSpread({}, this.otherParams), params);
4671
4769
  }
4672
- case 2:
4770
+ case 3:
4673
4771
  case "end":
4674
4772
  return _context42.stop();
4675
4773
  }