@pisell/pisellos 0.0.233 → 0.0.235

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 (37) hide show
  1. package/dist/modules/Order/index.d.ts +1 -1
  2. package/dist/modules/Order/index.js +1 -1
  3. package/dist/modules/Payment/index.d.ts +3 -3
  4. package/dist/modules/Payment/index.js +74 -10
  5. package/dist/modules/Payment/types.d.ts +24 -3
  6. package/dist/modules/Payment/types.js +9 -1
  7. package/dist/modules/Payment/utils.js +1 -1
  8. package/dist/modules/Payment/walletpass.d.ts +5 -2
  9. package/dist/modules/Payment/walletpass.js +63 -11
  10. package/dist/solution/BookingByStep/utils/timeslots.js +88 -38
  11. package/dist/solution/BookingTicket/index.d.ts +8 -0
  12. package/dist/solution/BookingTicket/index.js +27 -3
  13. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +6 -0
  14. package/dist/solution/BookingTicket/utils/scan/handleScan.js +43 -28
  15. package/dist/solution/Checkout/index.d.ts +50 -7
  16. package/dist/solution/Checkout/index.js +890 -474
  17. package/dist/solution/Checkout/types.d.ts +69 -3
  18. package/dist/solution/Checkout/types.js +5 -0
  19. package/lib/modules/Order/index.d.ts +1 -1
  20. package/lib/modules/Order/index.js +1 -1
  21. package/lib/modules/Payment/index.d.ts +3 -3
  22. package/lib/modules/Payment/index.js +30 -5
  23. package/lib/modules/Payment/types.d.ts +24 -3
  24. package/lib/modules/Payment/types.js +1 -1
  25. package/lib/modules/Payment/utils.js +1 -1
  26. package/lib/modules/Payment/walletpass.d.ts +5 -2
  27. package/lib/modules/Payment/walletpass.js +30 -2
  28. package/lib/solution/BookingByStep/utils/timeslots.js +38 -3
  29. package/lib/solution/BookingTicket/index.d.ts +8 -0
  30. package/lib/solution/BookingTicket/index.js +23 -2
  31. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +6 -0
  32. package/lib/solution/BookingTicket/utils/scan/handleScan.js +21 -14
  33. package/lib/solution/Checkout/index.d.ts +50 -7
  34. package/lib/solution/Checkout/index.js +267 -92
  35. package/lib/solution/Checkout/types.d.ts +69 -3
  36. package/lib/solution/Checkout/types.js +1 -0
  37. package/package.json +1 -1
@@ -935,8 +935,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
935
935
  while (1) switch (_context13.prev = _context13.next) {
936
936
  case 0:
937
937
  totalAmount = ((_this$store$currentOr3 = this.store.currentOrder) === null || _this$store$currentOr3 === void 0 ? void 0 : _this$store$currentOr3.total_amount) || '0.00';
938
- paidAmount = this.calculatePaidAmount();
939
- remainingAmount = this.calculateRemainingAmount();
938
+ _context13.next = 3;
939
+ return this.calculatePaidAmountAsync();
940
+ case 3:
941
+ paidAmount = _context13.sent;
942
+ _context13.next = 6;
943
+ return this.calculateRemainingAmountAsync();
944
+ case 6:
945
+ remainingAmount = _context13.sent;
940
946
  return _context13.abrupt("return", {
941
947
  order: this.store.currentOrder,
942
948
  totalAmount: totalAmount,
@@ -945,7 +951,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
945
951
  paymentStatus: ((_this$store$currentOr4 = this.store.currentOrder) === null || _this$store$currentOr4 === void 0 ? void 0 : _this$store$currentOr4.payment_status) || PaymentStatus.Processing,
946
952
  availablePaymentMethods: this.store.paymentMethods
947
953
  });
948
- case 4:
954
+ case 8:
949
955
  case "end":
950
956
  return _context13.stop();
951
957
  }
@@ -1551,7 +1557,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1551
1557
  key: "addPaymentItemAsync",
1552
1558
  value: (function () {
1553
1559
  var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(paymentItem) {
1554
- var currentOrderId, isCurrentOrderReal, updatedOrder, needsOrderSync;
1560
+ var currentOrderId, isCurrentOrderReal;
1555
1561
  return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1556
1562
  while (1) switch (_context23.prev = _context23.next) {
1557
1563
  case 0:
@@ -1586,82 +1592,82 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1586
1592
  当前订单ID: currentOrderId,
1587
1593
  是否为真实ID: isCurrentOrderReal
1588
1594
  });
1589
- _context23.next = 12;
1590
- return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1591
- case 12:
1592
- updatedOrder = _context23.sent;
1593
- if (updatedOrder) {
1594
- // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
1595
- if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
1596
- console.warn('[Checkout] 检测到订单ID回退,保护真实订单ID:', {
1597
- 当前真实ID: currentOrderId,
1598
- 获取到的虚拟ID: updatedOrder.order_id
1599
- });
1600
- updatedOrder.order_id = currentOrderId; // 恢复真实的订单ID
1601
- }
1602
- this.store.currentOrder = updatedOrder;
1603
- console.log('[Checkout] 订单数据已同步:', {
1604
- 支付项数量: updatedOrder.payment.length,
1605
- 最终订单ID: updatedOrder.order_id,
1606
- 是否为虚拟ID: this.isVirtualOrderId(updatedOrder.order_id)
1607
- });
1608
- }
1609
1595
 
1610
- // 检查是否需要同步订单到后端
1611
- needsOrderSync = this.shouldSyncOrderForPayment(paymentItem.code, paymentItem.type);
1612
- console.log('[Checkout] 支付项同步检查:', {
1613
- paymentCode: paymentItem.code,
1614
- paymentType: paymentItem.type,
1615
- paymentAmount: paymentItem.amount,
1616
- expectedCashCode: PaymentMethodType.Cash,
1617
- needsOrderSync: needsOrderSync,
1618
- isOrderSynced: this.store.isOrderSynced
1619
- });
1620
- if (!needsOrderSync) {
1621
- _context23.next = 21;
1622
- break;
1623
- }
1624
- console.log('[Checkout] 检测到非现金/自定义支付,开始同步订单到后端...', {
1625
- 同步前订单ID: this.store.currentOrder.order_id,
1626
- 是否为虚拟ID: this.isVirtualOrderId(this.store.currentOrder.order_id),
1627
- 订单同步状态: this.store.isOrderSynced,
1628
- 订单UUID: this.store.currentOrder.uuid
1629
- });
1630
- _context23.next = 20;
1631
- return this.syncOrderToBackend();
1632
- case 20:
1633
- console.log('[Checkout] addPaymentItemAsync 中的同步完成:', {
1634
- 同步后订单ID: this.store.currentOrder.order_id,
1635
- 是否为虚拟ID: this.isVirtualOrderId(this.store.currentOrder.order_id),
1636
- 订单同步状态: this.store.isOrderSynced
1637
- });
1638
- case 21:
1639
- _context23.next = 23;
1596
+ // const updatedOrder = await this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1597
+ // if (updatedOrder) {
1598
+ // // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
1599
+ // if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
1600
+ // console.warn('[Checkout] 检测到订单ID回退,保护真实订单ID:', {
1601
+ // 当前真实ID: currentOrderId,
1602
+ // 获取到的虚拟ID: updatedOrder.order_id
1603
+ // });
1604
+ // updatedOrder.order_id = currentOrderId; // 恢复真实的订单ID
1605
+ // }
1606
+
1607
+ // this.store.currentOrder = updatedOrder;
1608
+ // console.log('[Checkout] 订单数据已同步:', {
1609
+ // 支付项数量: updatedOrder.payment.length,
1610
+ // 最终订单ID: updatedOrder.order_id,
1611
+ // 是否为虚拟ID: this.isVirtualOrderId(updatedOrder.order_id)
1612
+ // });
1613
+ // }
1614
+
1615
+ // // 检查是否需要同步订单到后端
1616
+ // const needsOrderSync = this.shouldSyncOrderForPayment(paymentItem.code, paymentItem.type);
1617
+
1618
+ // console.log('[Checkout] 支付项同步检查:', {
1619
+ // paymentCode: paymentItem.code,
1620
+ // paymentType: paymentItem.type,
1621
+ // paymentAmount: paymentItem.amount,
1622
+ // expectedCashCode: PaymentMethodType.Cash,
1623
+ // needsOrderSync,
1624
+ // isOrderSynced: this.store.isOrderSynced
1625
+ // });
1626
+
1627
+ // if (needsOrderSync) {
1628
+ // console.log('[Checkout] 检测到非现金/自定义支付,开始同步订单到后端...', {
1629
+ // 同步前订单ID: this.store.currentOrder.order_id,
1630
+ // 是否为虚拟ID: this.isVirtualOrderId(this.store.currentOrder.order_id),
1631
+ // 订单同步状态: this.store.isOrderSynced,
1632
+ // 订单UUID: this.store.currentOrder.uuid
1633
+ // });
1634
+
1635
+ // await this.syncOrderToBackend();
1636
+
1637
+ // console.log('[Checkout] addPaymentItemAsync 中的同步完成:', {
1638
+ // 同步后订单ID: this.store.currentOrder.order_id,
1639
+ // 是否为虚拟ID: this.isVirtualOrderId(this.store.currentOrder.order_id),
1640
+ // 订单同步状态: this.store.isOrderSynced
1641
+ // });
1642
+ // }
1643
+
1644
+ // 支付项添加后,更新 stateAmount 为剩余未支付金额
1645
+ _context23.next = 12;
1640
1646
  return this.updateStateAmountToRemaining();
1641
- case 23:
1642
- _context23.next = 25;
1647
+ case 12:
1648
+ _context23.next = 14;
1643
1649
  return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1644
1650
  orderUuid: this.store.currentOrder.uuid,
1645
1651
  paymentMethodCode: paymentItem.code,
1646
1652
  amount: String(paymentItem.amount),
1647
1653
  timestamp: Date.now()
1648
1654
  });
1649
- case 25:
1650
- _context23.next = 33;
1655
+ case 14:
1656
+ _context23.next = 22;
1651
1657
  break;
1652
- case 27:
1653
- _context23.prev = 27;
1658
+ case 16:
1659
+ _context23.prev = 16;
1654
1660
  _context23.t0 = _context23["catch"](0);
1655
1661
  console.error('[Checkout] 添加支付项失败:', _context23.t0);
1656
- _context23.next = 32;
1662
+ _context23.next = 21;
1657
1663
  return this.handleError(_context23.t0, CheckoutErrorType.PaymentFailed);
1658
- case 32:
1664
+ case 21:
1659
1665
  throw _context23.t0;
1660
- case 33:
1666
+ case 22:
1661
1667
  case "end":
1662
1668
  return _context23.stop();
1663
1669
  }
1664
- }, _callee23, this, [[0, 27]]);
1670
+ }, _callee23, this, [[0, 16]]);
1665
1671
  }));
1666
1672
  function addPaymentItemAsync(_x14) {
1667
1673
  return _addPaymentItemAsync.apply(this, arguments);
@@ -1682,7 +1688,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1682
1688
  key: "deletePaymentItemAsync",
1683
1689
  value: (function () {
1684
1690
  var _deletePaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(paymentUuid) {
1685
- var paymentItem, currentOrderId, isCurrentOrderReal, updatedOrder;
1691
+ var currentPayments, paymentItem, currentOrderId, isCurrentOrderReal, updatedOrder;
1686
1692
  return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1687
1693
  while (1) switch (_context24.prev = _context24.next) {
1688
1694
  case 0:
@@ -1698,16 +1704,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1698
1704
  paymentUuid: paymentUuid
1699
1705
  });
1700
1706
 
1701
- // 验证支付项是否存在
1702
- paymentItem = this.store.currentOrder.payment.find(function (p) {
1707
+ // 从 Payment 模块验证支付项是否存在
1708
+ _context24.next = 6;
1709
+ return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, true // 包括已撤销的支付项,因为我们需要验证是否存在
1710
+ );
1711
+ case 6:
1712
+ currentPayments = _context24.sent;
1713
+ paymentItem = currentPayments.find(function (p) {
1703
1714
  return p.uuid === paymentUuid;
1704
1715
  });
1705
1716
  if (paymentItem) {
1706
- _context24.next = 7;
1717
+ _context24.next = 10;
1707
1718
  break;
1708
1719
  }
1709
1720
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u652F\u4ED8\u9879\u4E0D\u5B58\u5728: ".concat(paymentUuid));
1710
- case 7:
1721
+ case 10:
1711
1722
  console.log('[Checkout] 找到要删除的支付项:', {
1712
1723
  uuid: paymentItem.uuid,
1713
1724
  code: paymentItem.code,
@@ -1716,17 +1727,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1716
1727
  });
1717
1728
 
1718
1729
  // 调用 Payment 模块删除支付项
1719
- _context24.next = 10;
1730
+ _context24.next = 13;
1720
1731
  return this.payment.deletePaymentAsync(this.store.currentOrder.uuid, paymentUuid);
1721
- case 10:
1732
+ case 13:
1722
1733
  console.log('[Checkout] Payment模块删除完成');
1723
1734
 
1724
1735
  // 重新从Payment模块获取最新的订单数据,确保支付项同步
1725
1736
  currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1726
1737
  isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
1727
- _context24.next = 15;
1738
+ _context24.next = 18;
1728
1739
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1729
- case 15:
1740
+ case 18:
1730
1741
  updatedOrder = _context24.sent;
1731
1742
  if (updatedOrder) {
1732
1743
  // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
@@ -1742,10 +1753,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1742
1753
  }
1743
1754
 
1744
1755
  // 更新 stateAmount 为剩余未支付金额
1745
- _context24.next = 19;
1756
+ _context24.next = 22;
1746
1757
  return this.updateStateAmountToRemaining();
1747
- case 19:
1748
- _context24.next = 21;
1758
+ case 22:
1759
+ _context24.next = 24;
1749
1760
  return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1750
1761
  orderUuid: this.store.currentOrder.uuid,
1751
1762
  paymentMethodCode: paymentItem.code,
@@ -1753,23 +1764,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1753
1764
  // 负数表示删除
1754
1765
  timestamp: Date.now()
1755
1766
  });
1756
- case 21:
1767
+ case 24:
1757
1768
  console.log('[Checkout] 支付项删除成功');
1758
- _context24.next = 30;
1769
+ _context24.next = 33;
1759
1770
  break;
1760
- case 24:
1761
- _context24.prev = 24;
1771
+ case 27:
1772
+ _context24.prev = 27;
1762
1773
  _context24.t0 = _context24["catch"](0);
1763
1774
  console.error('[Checkout] 删除支付项失败:', _context24.t0);
1764
- _context24.next = 29;
1775
+ _context24.next = 32;
1765
1776
  return this.handleError(_context24.t0, CheckoutErrorType.PaymentFailed);
1766
- case 29:
1777
+ case 32:
1767
1778
  throw _context24.t0;
1768
- case 30:
1779
+ case 33:
1769
1780
  case "end":
1770
1781
  return _context24.stop();
1771
1782
  }
1772
- }, _callee24, this, [[0, 24]]);
1783
+ }, _callee24, this, [[0, 27]]);
1773
1784
  }));
1774
1785
  function deletePaymentItemAsync(_x15) {
1775
1786
  return _deletePaymentItemAsync.apply(this, arguments);
@@ -2089,65 +2100,98 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2089
2100
  }
2090
2101
 
2091
2102
  /**
2092
- * 检查订单是否需要手动同步
2103
+ * 检查订单是否需要手动同步(异步版本)
2093
2104
  *
2094
2105
  * 返回订单是否为纯代金券支付且待付金额<=0但未同步的状态
2106
+ * 从 Payment 模块获取最新的支付项数据
2095
2107
  */
2096
2108
  }, {
2097
- key: "needsManualSync",
2098
- value: function needsManualSync() {
2099
- try {
2100
- var _this$store$currentOr6;
2101
- // 检查基础条件
2102
- if (!this.store.currentOrder || this.store.isOrderSynced) {
2103
- return false;
2104
- }
2105
-
2106
- // 检查是否支付完成(剩余金额<=0)
2107
- var remainingAmount = this.calculateRemainingAmount();
2108
- var remainingValue = parseFloat(remainingAmount);
2109
- if (remainingValue > 0) {
2110
- return false;
2111
- }
2112
-
2113
- // 检查是否所有支付项都带有 voucher_id
2114
- var allPaymentsHaveVoucherId = this.store.currentOrder.payment && this.store.currentOrder.payment.length > 0 && this.store.currentOrder.payment.every(function (item) {
2115
- return item.status !== 'voided' && item.voucher_id;
2116
- });
2117
- console.log('[Checkout] needsManualSync 检查结果:', {
2118
- orderUuid: this.store.currentOrder.uuid,
2119
- isOrderSynced: this.store.isOrderSynced,
2120
- remainingAmount: remainingAmount,
2121
- hasPayments: ((_this$store$currentOr6 = this.store.currentOrder.payment) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.length) > 0,
2122
- allPaymentsHaveVoucherId: allPaymentsHaveVoucherId,
2123
- needsManualSync: allPaymentsHaveVoucherId
2124
- });
2125
- return allPaymentsHaveVoucherId;
2126
- } catch (error) {
2127
- console.error('[Checkout] needsManualSync 检查失败:', error);
2128
- return false;
2109
+ key: "needsManualSyncAsync",
2110
+ value: (function () {
2111
+ var _needsManualSyncAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2112
+ var remainingAmount, remainingValue, currentPayments, allPaymentsHaveVoucherId;
2113
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2114
+ while (1) switch (_context28.prev = _context28.next) {
2115
+ case 0:
2116
+ _context28.prev = 0;
2117
+ if (!(!this.store.currentOrder || this.store.isOrderSynced)) {
2118
+ _context28.next = 3;
2119
+ break;
2120
+ }
2121
+ return _context28.abrupt("return", false);
2122
+ case 3:
2123
+ _context28.next = 5;
2124
+ return this.calculateRemainingAmountAsync();
2125
+ case 5:
2126
+ remainingAmount = _context28.sent;
2127
+ remainingValue = parseFloat(remainingAmount);
2128
+ if (!(remainingValue > 0)) {
2129
+ _context28.next = 9;
2130
+ break;
2131
+ }
2132
+ return _context28.abrupt("return", false);
2133
+ case 9:
2134
+ _context28.next = 11;
2135
+ return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
2136
+ );
2137
+ case 11:
2138
+ currentPayments = _context28.sent;
2139
+ allPaymentsHaveVoucherId = currentPayments.length > 0 && currentPayments.every(function (item) {
2140
+ return item.status !== 'voided' && item.voucher_id;
2141
+ });
2142
+ console.log('[Checkout] needsManualSyncAsync 检查结果:', {
2143
+ orderUuid: this.store.currentOrder.uuid,
2144
+ isOrderSynced: this.store.isOrderSynced,
2145
+ remainingAmount: remainingAmount,
2146
+ hasPayments: currentPayments.length > 0,
2147
+ allPaymentsHaveVoucherId: allPaymentsHaveVoucherId,
2148
+ needsManualSync: allPaymentsHaveVoucherId,
2149
+ paymentItems: currentPayments.map(function (p) {
2150
+ return {
2151
+ code: p.code,
2152
+ amount: p.amount,
2153
+ status: p.status,
2154
+ hasVoucherId: !!p.voucher_id
2155
+ };
2156
+ })
2157
+ });
2158
+ return _context28.abrupt("return", allPaymentsHaveVoucherId);
2159
+ case 17:
2160
+ _context28.prev = 17;
2161
+ _context28.t0 = _context28["catch"](0);
2162
+ console.error('[Checkout] needsManualSyncAsync 检查失败:', _context28.t0);
2163
+ return _context28.abrupt("return", false);
2164
+ case 21:
2165
+ case "end":
2166
+ return _context28.stop();
2167
+ }
2168
+ }, _callee28, this, [[0, 17]]);
2169
+ }));
2170
+ function needsManualSyncAsync() {
2171
+ return _needsManualSyncAsync.apply(this, arguments);
2129
2172
  }
2130
- }
2131
-
2173
+ return needsManualSyncAsync;
2174
+ }()
2132
2175
  /**
2133
2176
  * 手动同步订单到后端
2134
2177
  *
2135
2178
  * 用于强制同步订单到后端,特别适用于纯代金券支付完成的订单
2136
2179
  */
2180
+ )
2137
2181
  }, {
2138
2182
  key: "manualSyncOrderAsync",
2139
2183
  value: (function () {
2140
- var _manualSyncOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2141
- var orderUuid, oldOrderId, realOrderId, finalOrderId, finalIsVirtual, _this$store$currentOr7, errorMessage;
2142
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2143
- while (1) switch (_context28.prev = _context28.next) {
2184
+ var _manualSyncOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2185
+ var orderUuid, oldOrderId, realOrderId, finalOrderId, finalIsVirtual, _this$store$currentOr6, errorMessage;
2186
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2187
+ while (1) switch (_context29.prev = _context29.next) {
2144
2188
  case 0:
2145
- _context28.prev = 0;
2189
+ _context29.prev = 0;
2146
2190
  if (this.store.currentOrder) {
2147
- _context28.next = 3;
2191
+ _context29.next = 3;
2148
2192
  break;
2149
2193
  }
2150
- return _context28.abrupt("return", {
2194
+ return _context29.abrupt("return", {
2151
2195
  success: false,
2152
2196
  message: '当前没有活跃订单,无法同步'
2153
2197
  });
@@ -2157,18 +2201,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2157
2201
  if (this.store.isOrderSynced) {
2158
2202
  console.log('[Checkout] 订单已同步过,将执行更新操作');
2159
2203
  }
2160
- console.log('[Checkout] 开始手动同步订单到后端:', {
2161
- orderUuid: orderUuid,
2162
- orderId: oldOrderId,
2163
- totalAmount: this.store.currentOrder.total_amount,
2164
- remainingAmount: this.calculateRemainingAmount()
2165
- });
2166
-
2167
- // 强制同步订单到后端,并获取真实订单ID
2168
- _context28.next = 9;
2204
+ _context29.t0 = console;
2205
+ _context29.t1 = orderUuid;
2206
+ _context29.t2 = oldOrderId;
2207
+ _context29.t3 = this.store.currentOrder.total_amount;
2208
+ _context29.next = 12;
2209
+ return this.calculateRemainingAmountAsync();
2210
+ case 12:
2211
+ _context29.t4 = _context29.sent;
2212
+ _context29.t5 = {
2213
+ orderUuid: _context29.t1,
2214
+ orderId: _context29.t2,
2215
+ totalAmount: _context29.t3,
2216
+ remainingAmount: _context29.t4
2217
+ };
2218
+ _context29.t0.log.call(_context29.t0, '[Checkout] 开始手动同步订单到后端:', _context29.t5);
2219
+ _context29.next = 17;
2169
2220
  return this.syncOrderToBackendWithReturn(true);
2170
- case 9:
2171
- realOrderId = _context28.sent;
2221
+ case 17:
2222
+ realOrderId = _context29.sent;
2172
2223
  console.log('[Checkout] 手动同步订单完成:', {
2173
2224
  orderUuid: orderUuid,
2174
2225
  oldOrderId: oldOrderId,
@@ -2192,28 +2243,28 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2192
2243
  if (realOrderId !== finalOrderId) {
2193
2244
  console.error('[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!');
2194
2245
  }
2195
- return _context28.abrupt("return", {
2246
+ return _context29.abrupt("return", {
2196
2247
  success: true,
2197
2248
  message: '订单同步成功',
2198
2249
  orderId: realOrderId,
2199
2250
  // 直接返回从后端获取的真实订单ID
2200
2251
  orderUuid: orderUuid
2201
2252
  });
2202
- case 19:
2203
- _context28.prev = 19;
2204
- _context28.t0 = _context28["catch"](0);
2205
- console.error('[Checkout] 手动同步订单失败:', _context28.t0);
2206
- errorMessage = _context28.t0 instanceof Error ? _context28.t0.message : '同步失败';
2207
- return _context28.abrupt("return", {
2253
+ case 27:
2254
+ _context29.prev = 27;
2255
+ _context29.t6 = _context29["catch"](0);
2256
+ console.error('[Checkout] 手动同步订单失败:', _context29.t6);
2257
+ errorMessage = _context29.t6 instanceof Error ? _context29.t6.message : '同步失败';
2258
+ return _context29.abrupt("return", {
2208
2259
  success: false,
2209
2260
  message: "\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(errorMessage),
2210
- orderUuid: (_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.uuid
2261
+ orderUuid: (_this$store$currentOr6 = this.store.currentOrder) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.uuid
2211
2262
  });
2212
- case 24:
2263
+ case 32:
2213
2264
  case "end":
2214
- return _context28.stop();
2265
+ return _context29.stop();
2215
2266
  }
2216
- }, _callee28, this, [[0, 19]]);
2267
+ }, _callee29, this, [[0, 27]]);
2217
2268
  }));
2218
2269
  function manualSyncOrderAsync() {
2219
2270
  return _manualSyncOrderAsync.apply(this, arguments);
@@ -2250,26 +2301,171 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2250
2301
  return this.store.currentOrder.order_id;
2251
2302
  }
2252
2303
 
2304
+ /**
2305
+ * 获取当前订单是否已同步到后端
2306
+ *
2307
+ * @returns 当前订单是否已同步状态,如果没有订单则返回false
2308
+ */
2309
+ }, {
2310
+ key: "isCurrentOrderSynced",
2311
+ value: function isCurrentOrderSynced() {
2312
+ // 如果没有当前订单,返回false
2313
+ if (!this.store.currentOrder) {
2314
+ console.log('[Checkout] 没有当前订单,同步状态为false');
2315
+ return false;
2316
+ }
2317
+ var syncStatus = this.store.isOrderSynced;
2318
+ console.log('[Checkout] 当前订单同步状态:', {
2319
+ orderUuid: this.store.currentOrder.uuid,
2320
+ orderId: this.store.currentOrder.order_id,
2321
+ isOrderSynced: syncStatus
2322
+ });
2323
+ return syncStatus;
2324
+ }
2325
+
2326
+ /**
2327
+ * 取消当前本地订单
2328
+ *
2329
+ * 只能取消未同步到后端的本地订单,如果订单已同步则不能取消
2330
+ *
2331
+ * @param cancelReason 取消原因(可选)
2332
+ * @returns 取消结果
2333
+ */
2334
+ }, {
2335
+ key: "cancelCurrentOrderAsync",
2336
+ value: (function () {
2337
+ var _cancelCurrentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(cancelReason) {
2338
+ var _this$store$currentOr7, _this$store$currentOr8, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
2339
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2340
+ while (1) switch (_context30.prev = _context30.next) {
2341
+ case 0:
2342
+ _context30.prev = 0;
2343
+ console.log('[Checkout] 开始取消当前本地订单:', {
2344
+ hasCurrentOrder: !!this.store.currentOrder,
2345
+ orderUuid: (_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.uuid,
2346
+ orderId: (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.order_id,
2347
+ isOrderSynced: this.store.isOrderSynced,
2348
+ cancelReason: cancelReason
2349
+ });
2350
+
2351
+ // 检查是否有当前订单
2352
+ if (this.store.currentOrder) {
2353
+ _context30.next = 5;
2354
+ break;
2355
+ }
2356
+ console.log('[Checkout] 没有当前订单,无需取消');
2357
+ return _context30.abrupt("return", {
2358
+ success: false,
2359
+ message: '没有当前订单可取消'
2360
+ });
2361
+ case 5:
2362
+ currentOrderUuid = this.store.currentOrder.uuid;
2363
+ currentOrderId = this.store.currentOrder.order_id;
2364
+ isOrderSynced = this.store.isOrderSynced; // 检查订单是否已同步,已同步的订单不能取消
2365
+ if (!isOrderSynced) {
2366
+ _context30.next = 11;
2367
+ break;
2368
+ }
2369
+ console.log('[Checkout] 订单已同步到后端,不能取消:', {
2370
+ orderId: currentOrderId,
2371
+ orderUuid: currentOrderUuid
2372
+ });
2373
+ return _context30.abrupt("return", {
2374
+ success: false,
2375
+ message: '订单已同步到后端,无法取消',
2376
+ orderId: currentOrderId
2377
+ });
2378
+ case 11:
2379
+ console.log('[Checkout] 订单尚未同步,可以取消');
2380
+
2381
+ // 删除本地订单数据
2382
+ _context30.prev = 12;
2383
+ console.log('[Checkout] 删除本地订单数据');
2384
+ _context30.next = 16;
2385
+ return this.payment.deletePaymentOrderAsync(currentOrderUuid);
2386
+ case 16:
2387
+ console.log('[Checkout] 本地订单数据删除成功');
2388
+ _context30.next = 22;
2389
+ break;
2390
+ case 19:
2391
+ _context30.prev = 19;
2392
+ _context30.t0 = _context30["catch"](12);
2393
+ console.warn('[Checkout] 删除本地订单数据失败,但继续执行:', _context30.t0);
2394
+ case 22:
2395
+ // 清理订单相关状态,确保正确释放 currentOrder
2396
+ console.log('[Checkout] 清理订单相关状态');
2397
+ this.store.currentOrder = undefined; // 释放 currentOrder
2398
+ this.store.localOrderData = undefined;
2399
+ this.store.stateAmount = '0.00';
2400
+ this.store.isOrderSynced = false;
2401
+ this.store.currentCustomer = undefined;
2402
+
2403
+ // 清理钱包缓存
2404
+ this.payment.wallet.clearAllCache();
2405
+ console.log('[Checkout] 订单状态清理完成,currentOrder已释放');
2406
+
2407
+ // 触发订单取消事件
2408
+ _context30.next = 32;
2409
+ return this.core.effects.emit(CheckoutHooks.OnOrderCancelled, {
2410
+ orderUuid: currentOrderUuid,
2411
+ orderId: currentOrderId,
2412
+ cancelReason: cancelReason,
2413
+ wasSynced: false,
2414
+ // 只有未同步订单可以被取消
2415
+ timestamp: Date.now()
2416
+ });
2417
+ case 32:
2418
+ console.log('[Checkout] 本地订单取消完成:', {
2419
+ orderUuid: currentOrderUuid,
2420
+ orderId: currentOrderId,
2421
+ cancelReason: cancelReason
2422
+ });
2423
+ return _context30.abrupt("return", {
2424
+ success: true,
2425
+ message: '本地订单已成功取消',
2426
+ orderId: currentOrderId
2427
+ });
2428
+ case 36:
2429
+ _context30.prev = 36;
2430
+ _context30.t1 = _context30["catch"](0);
2431
+ console.error('[Checkout] 取消本地订单失败:', _context30.t1);
2432
+ errorMessage = _context30.t1 instanceof Error ? _context30.t1.message : '未知错误';
2433
+ return _context30.abrupt("return", {
2434
+ success: false,
2435
+ message: "\u53D6\u6D88\u8BA2\u5355\u5931\u8D25: ".concat(errorMessage)
2436
+ });
2437
+ case 41:
2438
+ case "end":
2439
+ return _context30.stop();
2440
+ }
2441
+ }, _callee30, this, [[0, 36], [12, 19]]);
2442
+ }));
2443
+ function cancelCurrentOrderAsync(_x19) {
2444
+ return _cancelCurrentOrderAsync.apply(this, arguments);
2445
+ }
2446
+ return cancelCurrentOrderAsync;
2447
+ }()
2253
2448
  /**
2254
2449
  * 保存订单并稍后支付
2255
2450
  *
2256
2451
  * 将当前订单保存到后端,但排除代金券类支付项(voucher_id),
2257
2452
  * 适用于用户想要保存订单但稍后完成支付的场景
2258
2453
  */
2454
+ )
2259
2455
  }, {
2260
2456
  key: "saveForLaterPaymentAsync",
2261
2457
  value: (function () {
2262
- var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2263
- var orderUuid, currentOrderId, allPaymentItems, filteredPaymentItems, voucherItems, realOrderId, finalOrderId, _this$store$currentOr8, errorMessage;
2264
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2265
- while (1) switch (_context29.prev = _context29.next) {
2458
+ var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2459
+ var orderUuid, currentOrderId, allPaymentItems, filteredPaymentItems, voucherItems, realOrderId, finalOrderId, _this$store$currentOr9, errorMessage;
2460
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2461
+ while (1) switch (_context31.prev = _context31.next) {
2266
2462
  case 0:
2267
- _context29.prev = 0;
2463
+ _context31.prev = 0;
2268
2464
  if (this.store.currentOrder) {
2269
- _context29.next = 3;
2465
+ _context31.next = 3;
2270
2466
  break;
2271
2467
  }
2272
- return _context29.abrupt("return", {
2468
+ return _context31.abrupt("return", {
2273
2469
  success: false,
2274
2470
  message: '当前没有活跃订单,无法保存'
2275
2471
  });
@@ -2283,10 +2479,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2283
2479
  });
2284
2480
 
2285
2481
  // 获取当前订单的所有支付项
2286
- _context29.next = 8;
2482
+ _context31.next = 8;
2287
2483
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
2288
2484
  case 8:
2289
- allPaymentItems = _context29.sent;
2485
+ allPaymentItems = _context31.sent;
2290
2486
  // 过滤掉带有 voucher_id 的支付项(代金券类支付项)
2291
2487
  filteredPaymentItems = allPaymentItems.filter(function (payment) {
2292
2488
  return !payment.voucher_id || payment.voucher_id.trim() === '';
@@ -2316,10 +2512,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2316
2512
  });
2317
2513
 
2318
2514
  // 调用同步方法,传入过滤后的支付项
2319
- _context29.next = 14;
2515
+ _context31.next = 14;
2320
2516
  return this.syncOrderToBackendWithReturn(false, filteredPaymentItems);
2321
2517
  case 14:
2322
- realOrderId = _context29.sent;
2518
+ realOrderId = _context31.sent;
2323
2519
  console.log('[Checkout] 保存订单完成:', {
2324
2520
  orderUuid: orderUuid,
2325
2521
  oldOrderId: currentOrderId,
@@ -2336,27 +2532,27 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2336
2532
  是否一致: realOrderId === finalOrderId,
2337
2533
  同步状态: this.store.isOrderSynced
2338
2534
  });
2339
- return _context29.abrupt("return", {
2535
+ return _context31.abrupt("return", {
2340
2536
  success: true,
2341
2537
  message: '订单保存成功,可稍后继续支付',
2342
2538
  orderId: realOrderId,
2343
2539
  orderUuid: orderUuid
2344
2540
  });
2345
2541
  case 21:
2346
- _context29.prev = 21;
2347
- _context29.t0 = _context29["catch"](0);
2348
- console.error('[Checkout] 保存订单失败:', _context29.t0);
2349
- errorMessage = _context29.t0 instanceof Error ? _context29.t0.message : '保存失败';
2350
- return _context29.abrupt("return", {
2542
+ _context31.prev = 21;
2543
+ _context31.t0 = _context31["catch"](0);
2544
+ console.error('[Checkout] 保存订单失败:', _context31.t0);
2545
+ errorMessage = _context31.t0 instanceof Error ? _context31.t0.message : '保存失败';
2546
+ return _context31.abrupt("return", {
2351
2547
  success: false,
2352
2548
  message: "\u8BA2\u5355\u4FDD\u5B58\u5931\u8D25: ".concat(errorMessage),
2353
- orderUuid: (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.uuid
2549
+ orderUuid: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.uuid
2354
2550
  });
2355
2551
  case 26:
2356
2552
  case "end":
2357
- return _context29.stop();
2553
+ return _context31.stop();
2358
2554
  }
2359
- }, _callee29, this, [[0, 21]]);
2555
+ }, _callee31, this, [[0, 21]]);
2360
2556
  }));
2361
2557
  function saveForLaterPaymentAsync() {
2362
2558
  return _saveForLaterPaymentAsync.apply(this, arguments);
@@ -2400,15 +2596,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2400
2596
  }, {
2401
2597
  key: "updateShopDiscountAsync",
2402
2598
  value: (function () {
2403
- var _updateShopDiscountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(discountAmount) {
2404
- var _this$store$currentOr9, _this$store$currentOr10, oldDiscount, shopDiscountItem, updatedAmountInfo;
2405
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2406
- while (1) switch (_context30.prev = _context30.next) {
2599
+ var _updateShopDiscountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(discountAmount) {
2600
+ var _this$store$currentOr10, _this$store$currentOr11, oldDiscount, shopDiscountItem, updatedAmountInfo;
2601
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2602
+ while (1) switch (_context32.prev = _context32.next) {
2407
2603
  case 0:
2408
- _context30.prev = 0;
2604
+ _context32.prev = 0;
2409
2605
  oldDiscount = this.getShopDiscount();
2410
2606
  console.log('[Checkout] 更新商店折扣:', {
2411
- orderUuid: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.uuid,
2607
+ orderUuid: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.uuid,
2412
2608
  oldDiscount: oldDiscount,
2413
2609
  newDiscount: discountAmount
2414
2610
  });
@@ -2453,12 +2649,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2453
2649
  }
2454
2650
 
2455
2651
  // 4. 更新 stateAmount 为剩余未支付金额
2456
- _context30.next = 8;
2652
+ _context32.next = 8;
2457
2653
  return this.updateStateAmountToRemaining();
2458
2654
  case 8:
2459
- _context30.next = 10;
2655
+ _context32.next = 10;
2460
2656
  return this.core.effects.emit(CheckoutHooks.OnShopDiscountChanged, {
2461
- orderUuid: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.uuid,
2657
+ orderUuid: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.uuid,
2462
2658
  oldDiscount: oldDiscount,
2463
2659
  newDiscount: discountAmount,
2464
2660
  timestamp: Date.now()
@@ -2468,23 +2664,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2468
2664
  oldDiscount: oldDiscount,
2469
2665
  newDiscount: discountAmount
2470
2666
  });
2471
- _context30.next = 19;
2667
+ _context32.next = 19;
2472
2668
  break;
2473
2669
  case 13:
2474
- _context30.prev = 13;
2475
- _context30.t0 = _context30["catch"](0);
2476
- console.error('[Checkout] 更新商店折扣失败:', _context30.t0);
2477
- _context30.next = 18;
2478
- return this.handleError(_context30.t0, CheckoutErrorType.ValidationFailed);
2670
+ _context32.prev = 13;
2671
+ _context32.t0 = _context32["catch"](0);
2672
+ console.error('[Checkout] 更新商店折扣失败:', _context32.t0);
2673
+ _context32.next = 18;
2674
+ return this.handleError(_context32.t0, CheckoutErrorType.ValidationFailed);
2479
2675
  case 18:
2480
- throw _context30.t0;
2676
+ throw _context32.t0;
2481
2677
  case 19:
2482
2678
  case "end":
2483
- return _context30.stop();
2679
+ return _context32.stop();
2484
2680
  }
2485
- }, _callee30, this, [[0, 13]]);
2681
+ }, _callee32, this, [[0, 13]]);
2486
2682
  }));
2487
- function updateShopDiscountAsync(_x19) {
2683
+ function updateShopDiscountAsync(_x20) {
2488
2684
  return _updateShopDiscountAsync.apply(this, arguments);
2489
2685
  }
2490
2686
  return updateShopDiscountAsync;
@@ -2498,20 +2694,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2498
2694
  }, {
2499
2695
  key: "updateOrderNoteAsync",
2500
2696
  value: (function () {
2501
- var _updateOrderNoteAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(note) {
2502
- var _this$store$currentOr11, _this$store$currentOr12, oldNote, orderInPayment;
2503
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2504
- while (1) switch (_context31.prev = _context31.next) {
2697
+ var _updateOrderNoteAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(note) {
2698
+ var _this$store$currentOr12, _this$store$currentOr13, oldNote, orderInPayment;
2699
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2700
+ while (1) switch (_context33.prev = _context33.next) {
2505
2701
  case 0:
2506
- _context31.prev = 0;
2702
+ _context33.prev = 0;
2507
2703
  if (this.store.localOrderData) {
2508
- _context31.next = 3;
2704
+ _context33.next = 3;
2509
2705
  break;
2510
2706
  }
2511
2707
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '没有本地订单数据,无法更新备注');
2512
2708
  case 3:
2513
2709
  console.log('[Checkout] 更新订单备注:', {
2514
- orderUuid: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.uuid,
2710
+ orderUuid: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.uuid,
2515
2711
  oldNote: this.store.localOrderData.shop_note,
2516
2712
  newNote: note
2517
2713
  });
@@ -2522,29 +2718,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2522
2718
 
2523
2719
  // 如果有当前订单,也同步到Payment模块中的订单数据
2524
2720
  if (!this.store.currentOrder) {
2525
- _context31.next = 17;
2721
+ _context33.next = 17;
2526
2722
  break;
2527
2723
  }
2528
- _context31.prev = 7;
2529
- _context31.next = 10;
2724
+ _context33.prev = 7;
2725
+ _context33.next = 10;
2530
2726
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
2531
2727
  case 10:
2532
- orderInPayment = _context31.sent;
2728
+ orderInPayment = _context33.sent;
2533
2729
  if (orderInPayment && orderInPayment.note !== undefined) {
2534
2730
  // 使用Payment模块的更新方法(如果有的话)
2535
2731
  // 这里可能需要根据Payment模块的实际API来调整
2536
2732
  console.log('[Checkout] 同步备注到Payment模块的订单数据中');
2537
2733
  }
2538
- _context31.next = 17;
2734
+ _context33.next = 17;
2539
2735
  break;
2540
2736
  case 14:
2541
- _context31.prev = 14;
2542
- _context31.t0 = _context31["catch"](7);
2543
- console.warn('[Checkout] 同步备注到Payment模块失败,但本地更新成功:', _context31.t0);
2737
+ _context33.prev = 14;
2738
+ _context33.t0 = _context33["catch"](7);
2739
+ console.warn('[Checkout] 同步备注到Payment模块失败,但本地更新成功:', _context33.t0);
2544
2740
  case 17:
2545
- _context31.next = 19;
2741
+ _context33.next = 19;
2546
2742
  return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
2547
- orderUuid: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.uuid,
2743
+ orderUuid: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.uuid,
2548
2744
  oldNote: oldNote,
2549
2745
  newNote: note,
2550
2746
  timestamp: Date.now()
@@ -2554,23 +2750,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2554
2750
  oldNote: oldNote,
2555
2751
  newNote: note
2556
2752
  });
2557
- _context31.next = 28;
2753
+ _context33.next = 28;
2558
2754
  break;
2559
2755
  case 22:
2560
- _context31.prev = 22;
2561
- _context31.t1 = _context31["catch"](0);
2562
- console.error('[Checkout] 更新订单备注失败:', _context31.t1);
2563
- _context31.next = 27;
2564
- return this.handleError(_context31.t1, CheckoutErrorType.ValidationFailed);
2756
+ _context33.prev = 22;
2757
+ _context33.t1 = _context33["catch"](0);
2758
+ console.error('[Checkout] 更新订单备注失败:', _context33.t1);
2759
+ _context33.next = 27;
2760
+ return this.handleError(_context33.t1, CheckoutErrorType.ValidationFailed);
2565
2761
  case 27:
2566
- throw _context31.t1;
2762
+ throw _context33.t1;
2567
2763
  case 28:
2568
2764
  case "end":
2569
- return _context31.stop();
2765
+ return _context33.stop();
2570
2766
  }
2571
- }, _callee31, this, [[0, 22], [7, 14]]);
2767
+ }, _callee33, this, [[0, 22], [7, 14]]);
2572
2768
  }));
2573
- function updateOrderNoteAsync(_x20) {
2769
+ function updateOrderNoteAsync(_x21) {
2574
2770
  return _updateOrderNoteAsync.apply(this, arguments);
2575
2771
  }
2576
2772
  return updateOrderNoteAsync;
@@ -2582,14 +2778,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2582
2778
  }, {
2583
2779
  key: "setStatus",
2584
2780
  value: (function () {
2585
- var _setStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(status) {
2781
+ var _setStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(status) {
2586
2782
  var oldStatus;
2587
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2588
- while (1) switch (_context32.prev = _context32.next) {
2783
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2784
+ while (1) switch (_context34.prev = _context34.next) {
2589
2785
  case 0:
2590
2786
  oldStatus = this.store.status;
2591
2787
  this.store.status = status;
2592
- _context32.next = 4;
2788
+ _context34.next = 4;
2593
2789
  return this.core.effects.emit(CheckoutHooks.OnStatusChanged, {
2594
2790
  oldStatus: oldStatus,
2595
2791
  newStatus: status,
@@ -2597,11 +2793,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2597
2793
  });
2598
2794
  case 4:
2599
2795
  case "end":
2600
- return _context32.stop();
2796
+ return _context34.stop();
2601
2797
  }
2602
- }, _callee32, this);
2798
+ }, _callee34, this);
2603
2799
  }));
2604
- function setStatus(_x21) {
2800
+ function setStatus(_x22) {
2605
2801
  return _setStatus.apply(this, arguments);
2606
2802
  }
2607
2803
  return setStatus;
@@ -2613,14 +2809,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2613
2809
  }, {
2614
2810
  key: "setStep",
2615
2811
  value: (function () {
2616
- var _setStep = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(step) {
2812
+ var _setStep = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(step) {
2617
2813
  var oldStep;
2618
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2619
- while (1) switch (_context33.prev = _context33.next) {
2814
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2815
+ while (1) switch (_context35.prev = _context35.next) {
2620
2816
  case 0:
2621
2817
  oldStep = this.store.step;
2622
2818
  this.store.step = step;
2623
- _context33.next = 4;
2819
+ _context35.next = 4;
2624
2820
  return this.core.effects.emit(CheckoutHooks.OnStepChanged, {
2625
2821
  oldStep: oldStep,
2626
2822
  newStep: step,
@@ -2628,11 +2824,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2628
2824
  });
2629
2825
  case 4:
2630
2826
  case "end":
2631
- return _context33.stop();
2827
+ return _context35.stop();
2632
2828
  }
2633
- }, _callee33, this);
2829
+ }, _callee35, this);
2634
2830
  }));
2635
- function setStep(_x22) {
2831
+ function setStep(_x23) {
2636
2832
  return _setStep.apply(this, arguments);
2637
2833
  }
2638
2834
  return setStep;
@@ -2644,17 +2840,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2644
2840
  }, {
2645
2841
  key: "handleError",
2646
2842
  value: (function () {
2647
- var _handleError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(error, type) {
2843
+ var _handleError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(error, type) {
2648
2844
  var checkoutError;
2649
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2650
- while (1) switch (_context34.prev = _context34.next) {
2845
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
2846
+ while (1) switch (_context36.prev = _context36.next) {
2651
2847
  case 0:
2652
2848
  checkoutError = error instanceof Error && 'type' in error ? error : createCheckoutError(type, error.message, error);
2653
2849
  this.store.lastError = checkoutError;
2654
- _context34.next = 4;
2850
+ _context36.next = 4;
2655
2851
  return this.setStatus(CheckoutStatus.Error);
2656
2852
  case 4:
2657
- _context34.next = 6;
2853
+ _context36.next = 6;
2658
2854
  return this.core.effects.emit(CheckoutHooks.OnError, {
2659
2855
  error: checkoutError,
2660
2856
  context: {
@@ -2667,11 +2863,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2667
2863
  console.error('[Checkout] 错误:', checkoutError);
2668
2864
  case 7:
2669
2865
  case "end":
2670
- return _context34.stop();
2866
+ return _context36.stop();
2671
2867
  }
2672
- }, _callee34, this);
2868
+ }, _callee36, this);
2673
2869
  }));
2674
- function handleError(_x23, _x24) {
2870
+ function handleError(_x24, _x25) {
2675
2871
  return _handleError.apply(this, arguments);
2676
2872
  }
2677
2873
  return handleError;
@@ -2683,34 +2879,34 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2683
2879
  }, {
2684
2880
  key: "handlePaymentSuccess",
2685
2881
  value: (function () {
2686
- var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(data) {
2687
- var _this$store$currentOr13;
2688
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2689
- while (1) switch (_context35.prev = _context35.next) {
2882
+ var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(data) {
2883
+ var _this$store$currentOr14;
2884
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
2885
+ while (1) switch (_context37.prev = _context37.next) {
2690
2886
  case 0:
2691
- _context35.next = 2;
2887
+ _context37.next = 2;
2692
2888
  return this.setStatus(CheckoutStatus.PaymentCompleted);
2693
2889
  case 2:
2694
- _context35.next = 4;
2890
+ _context37.next = 4;
2695
2891
  return this.updateStateAmountToRemaining();
2696
2892
  case 4:
2697
- _context35.next = 6;
2893
+ _context37.next = 6;
2698
2894
  return this.core.effects.emit(CheckoutHooks.OnPaymentSuccess, {
2699
2895
  orderUuid: data.orderUuid,
2700
2896
  paymentMethodCode: '',
2701
- amount: ((_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.total_amount) || '0',
2897
+ amount: ((_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.total_amount) || '0',
2702
2898
  timestamp: data.timestamp
2703
2899
  });
2704
2900
  case 6:
2705
- _context35.next = 8;
2901
+ _context37.next = 8;
2706
2902
  return this.completeCheckoutAsync();
2707
2903
  case 8:
2708
2904
  case "end":
2709
- return _context35.stop();
2905
+ return _context37.stop();
2710
2906
  }
2711
- }, _callee35, this);
2907
+ }, _callee37, this);
2712
2908
  }));
2713
- function handlePaymentSuccess(_x25) {
2909
+ function handlePaymentSuccess(_x26) {
2714
2910
  return _handlePaymentSuccess.apply(this, arguments);
2715
2911
  }
2716
2912
  return handlePaymentSuccess;
@@ -2722,30 +2918,30 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2722
2918
  }, {
2723
2919
  key: "handlePaymentError",
2724
2920
  value: (function () {
2725
- var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(data) {
2726
- var _this$store$currentOr14;
2921
+ var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(data) {
2922
+ var _this$store$currentOr15;
2727
2923
  var error;
2728
- return _regeneratorRuntime().wrap(function _callee36$(_context36) {
2729
- while (1) switch (_context36.prev = _context36.next) {
2924
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
2925
+ while (1) switch (_context38.prev = _context38.next) {
2730
2926
  case 0:
2731
2927
  error = createCheckoutError(CheckoutErrorType.PaymentFailed, data.error || '支付同步失败');
2732
- _context36.next = 3;
2928
+ _context38.next = 3;
2733
2929
  return this.handleError(error instanceof Error ? error : new Error(String(error)), CheckoutErrorType.PaymentFailed);
2734
2930
  case 3:
2735
- _context36.next = 5;
2931
+ _context38.next = 5;
2736
2932
  return this.core.effects.emit(CheckoutHooks.OnPaymentFailed, {
2737
2933
  orderUuid: data.orderUuid,
2738
2934
  paymentMethodCode: '',
2739
- amount: ((_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.total_amount) || '0',
2935
+ amount: ((_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.total_amount) || '0',
2740
2936
  timestamp: data.timestamp
2741
2937
  });
2742
2938
  case 5:
2743
2939
  case "end":
2744
- return _context36.stop();
2940
+ return _context38.stop();
2745
2941
  }
2746
- }, _callee36, this);
2942
+ }, _callee38, this);
2747
2943
  }));
2748
- function handlePaymentError(_x26) {
2944
+ function handlePaymentError(_x27) {
2749
2945
  return _handlePaymentError.apply(this, arguments);
2750
2946
  }
2751
2947
  return handlePaymentError;
@@ -2757,18 +2953,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2757
2953
  }, {
2758
2954
  key: "validateCheckoutParams",
2759
2955
  value: (function () {
2760
- var _validateCheckoutParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
2761
- return _regeneratorRuntime().wrap(function _callee37$(_context37) {
2762
- while (1) switch (_context37.prev = _context37.next) {
2956
+ var _validateCheckoutParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
2957
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
2958
+ while (1) switch (_context39.prev = _context39.next) {
2763
2959
  case 0:
2764
- return _context37.abrupt("return", validateCheckoutData(params));
2960
+ return _context39.abrupt("return", validateCheckoutData(params));
2765
2961
  case 1:
2766
2962
  case "end":
2767
- return _context37.stop();
2963
+ return _context39.stop();
2768
2964
  }
2769
- }, _callee37);
2965
+ }, _callee39);
2770
2966
  }));
2771
- function validateCheckoutParams(_x27) {
2967
+ function validateCheckoutParams(_x28) {
2772
2968
  return _validateCheckoutParams.apply(this, arguments);
2773
2969
  }
2774
2970
  return validateCheckoutParams;
@@ -2780,10 +2976,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2780
2976
  }, {
2781
2977
  key: "validateLocalOrderData",
2782
2978
  value: (function () {
2783
- var _validateLocalOrderData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(orderData) {
2979
+ var _validateLocalOrderData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(orderData) {
2784
2980
  var errors;
2785
- return _regeneratorRuntime().wrap(function _callee38$(_context38) {
2786
- while (1) switch (_context38.prev = _context38.next) {
2981
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
2982
+ while (1) switch (_context40.prev = _context40.next) {
2787
2983
  case 0:
2788
2984
  errors = []; // 验证基本字段
2789
2985
  if (!orderData.type) {
@@ -2810,17 +3006,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2810
3006
  }
2811
3007
  });
2812
3008
  }
2813
- return _context38.abrupt("return", {
3009
+ return _context40.abrupt("return", {
2814
3010
  valid: errors.length === 0,
2815
3011
  errors: errors
2816
3012
  });
2817
3013
  case 6:
2818
3014
  case "end":
2819
- return _context38.stop();
3015
+ return _context40.stop();
2820
3016
  }
2821
- }, _callee38);
3017
+ }, _callee40);
2822
3018
  }));
2823
- function validateLocalOrderData(_x28) {
3019
+ function validateLocalOrderData(_x29) {
2824
3020
  return _validateLocalOrderData.apply(this, arguments);
2825
3021
  }
2826
3022
  return validateLocalOrderData;
@@ -2918,31 +3114,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2918
3114
  }, {
2919
3115
  key: "preloadPaymentMethods",
2920
3116
  value: (function () {
2921
- var _preloadPaymentMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
3117
+ var _preloadPaymentMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
2922
3118
  var methods;
2923
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
2924
- while (1) switch (_context39.prev = _context39.next) {
3119
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3120
+ while (1) switch (_context41.prev = _context41.next) {
2925
3121
  case 0:
2926
- _context39.prev = 0;
3122
+ _context41.prev = 0;
2927
3123
  console.log('[Checkout] 预加载支付方式...');
2928
- _context39.next = 4;
3124
+ _context41.next = 4;
2929
3125
  return this.payment.getPayMethodListAsync();
2930
3126
  case 4:
2931
- methods = _context39.sent;
3127
+ methods = _context41.sent;
2932
3128
  this.store.paymentMethods = methods;
2933
3129
  console.log("[Checkout] \u9884\u52A0\u8F7D\u5B8C\u6210\uFF0C\u5171 ".concat(methods.length, " \u79CD\u652F\u4ED8\u65B9\u5F0F"));
2934
- _context39.next = 13;
3130
+ _context41.next = 13;
2935
3131
  break;
2936
3132
  case 9:
2937
- _context39.prev = 9;
2938
- _context39.t0 = _context39["catch"](0);
2939
- console.error('[Checkout] 预加载支付方式失败:', _context39.t0);
3133
+ _context41.prev = 9;
3134
+ _context41.t0 = _context41["catch"](0);
3135
+ console.error('[Checkout] 预加载支付方式失败:', _context41.t0);
2940
3136
  this.store.paymentMethods = [];
2941
3137
  case 13:
2942
3138
  case "end":
2943
- return _context39.stop();
3139
+ return _context41.stop();
2944
3140
  }
2945
- }, _callee39, this, [[0, 9]]);
3141
+ }, _callee41, this, [[0, 9]]);
2946
3142
  }));
2947
3143
  function preloadPaymentMethods() {
2948
3144
  return _preloadPaymentMethods.apply(this, arguments);
@@ -2965,126 +3161,180 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2965
3161
  }
2966
3162
 
2967
3163
  /**
2968
- * 计算已支付金额
3164
+ * 计算已支付金额(从 Payment 模块获取最新数据)
2969
3165
  */
2970
3166
  }, {
2971
- key: "calculatePaidAmount",
2972
- value: function calculatePaidAmount() {
2973
- if (!this.store.currentOrder) {
2974
- console.log('[Checkout] calculatePaidAmount: 没有当前订单');
2975
- return '0.00';
3167
+ key: "calculatePaidAmountAsync",
3168
+ value: (function () {
3169
+ var _calculatePaidAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42() {
3170
+ var payments, paidAmount, result;
3171
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3172
+ while (1) switch (_context42.prev = _context42.next) {
3173
+ case 0:
3174
+ if (this.store.currentOrder) {
3175
+ _context42.next = 3;
3176
+ break;
3177
+ }
3178
+ console.log('[Checkout] calculatePaidAmountAsync: 没有当前订单');
3179
+ return _context42.abrupt("return", '0.00');
3180
+ case 3:
3181
+ _context42.prev = 3;
3182
+ _context42.next = 6;
3183
+ return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
3184
+ );
3185
+ case 6:
3186
+ payments = _context42.sent;
3187
+ console.log('[Checkout] calculatePaidAmountAsync: 支付项详情:', {
3188
+ paymentCount: payments.length,
3189
+ payments: payments.map(function (p) {
3190
+ return {
3191
+ uuid: p.uuid,
3192
+ amount: p.amount,
3193
+ code: p.code,
3194
+ status: p.status
3195
+ };
3196
+ })
3197
+ });
3198
+ paidAmount = payments.filter(function (payment) {
3199
+ return payment.status !== 'voided';
3200
+ }) // 只计算未撤销的支付项
3201
+ .reduce(function (sum, payment) {
3202
+ var amount = parseFloat(payment.amount || '0');
3203
+ console.log("[Checkout] \u8BA1\u7B97\u652F\u4ED8\u9879: ".concat(payment.code, " = ").concat(amount));
3204
+ return sum + amount;
3205
+ }, 0);
3206
+ result = paidAmount.toFixed(2);
3207
+ console.log('[Checkout] calculatePaidAmountAsync: 计算结果 =', result);
3208
+ return _context42.abrupt("return", result);
3209
+ case 14:
3210
+ _context42.prev = 14;
3211
+ _context42.t0 = _context42["catch"](3);
3212
+ console.error('[Checkout] calculatePaidAmountAsync 失败:', _context42.t0);
3213
+ return _context42.abrupt("return", '0.00');
3214
+ case 18:
3215
+ case "end":
3216
+ return _context42.stop();
3217
+ }
3218
+ }, _callee42, this, [[3, 14]]);
3219
+ }));
3220
+ function calculatePaidAmountAsync() {
3221
+ return _calculatePaidAmountAsync.apply(this, arguments);
2976
3222
  }
2977
- var payments = this.store.currentOrder.payment || [];
2978
- console.log('[Checkout] calculatePaidAmount: 支付项详情:', {
2979
- paymentCount: payments.length,
2980
- payments: payments.map(function (p) {
2981
- return {
2982
- uuid: p.uuid,
2983
- amount: p.amount,
2984
- code: p.code,
2985
- status: p.status
2986
- };
2987
- })
2988
- });
2989
- var paidAmount = payments.filter(function (payment) {
2990
- return payment.status !== 'voided';
2991
- }) // 只计算未撤销的支付项
2992
- .reduce(function (sum, payment) {
2993
- var amount = parseFloat(payment.amount || '0');
2994
- console.log("[Checkout] \u8BA1\u7B97\u652F\u4ED8\u9879: ".concat(payment.code, " = ").concat(amount));
2995
- return sum + amount;
2996
- }, 0);
2997
- var result = paidAmount.toFixed(2);
2998
- console.log('[Checkout] calculatePaidAmount: 计算结果 =', result);
2999
- return result;
3000
- }
3001
-
3223
+ return calculatePaidAmountAsync;
3224
+ }()
3002
3225
  /**
3003
- * 计算剩余未支付金额
3226
+ * 计算剩余未支付金额(从 Payment 模块获取最新数据)
3004
3227
  */
3228
+ )
3005
3229
  }, {
3006
- key: "calculateRemainingAmount",
3007
- value: function calculateRemainingAmount() {
3008
- if (!this.store.currentOrder) {
3009
- console.log('[Checkout] calculateRemainingAmount: 没有当前订单');
3010
- return '0.00';
3230
+ key: "calculateRemainingAmountAsync",
3231
+ value: (function () {
3232
+ var _calculateRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43() {
3233
+ var totalAmount, paidAmount, remainingAmount, result;
3234
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3235
+ while (1) switch (_context43.prev = _context43.next) {
3236
+ case 0:
3237
+ if (this.store.currentOrder) {
3238
+ _context43.next = 3;
3239
+ break;
3240
+ }
3241
+ console.log('[Checkout] calculateRemainingAmountAsync: 没有当前订单');
3242
+ return _context43.abrupt("return", '0.00');
3243
+ case 3:
3244
+ totalAmount = parseFloat(this.store.currentOrder.total_amount || '0');
3245
+ _context43.t0 = parseFloat;
3246
+ _context43.next = 7;
3247
+ return this.calculatePaidAmountAsync();
3248
+ case 7:
3249
+ _context43.t1 = _context43.sent;
3250
+ paidAmount = (0, _context43.t0)(_context43.t1);
3251
+ remainingAmount = totalAmount - paidAmount;
3252
+ result = Math.max(0, remainingAmount).toFixed(2);
3253
+ console.log('[Checkout] calculateRemainingAmountAsync: 计算详情:', {
3254
+ orderUuid: this.store.currentOrder.uuid,
3255
+ totalAmount: totalAmount.toFixed(2),
3256
+ paidAmount: paidAmount.toFixed(2),
3257
+ calculatedRemaining: remainingAmount.toFixed(2),
3258
+ finalResult: result
3259
+ });
3260
+ return _context43.abrupt("return", result);
3261
+ case 13:
3262
+ case "end":
3263
+ return _context43.stop();
3264
+ }
3265
+ }, _callee43, this);
3266
+ }));
3267
+ function calculateRemainingAmountAsync() {
3268
+ return _calculateRemainingAmountAsync.apply(this, arguments);
3011
3269
  }
3012
- var totalAmount = parseFloat(this.store.currentOrder.total_amount || '0');
3013
- var paidAmount = parseFloat(this.calculatePaidAmount());
3014
- var remainingAmount = totalAmount - paidAmount;
3015
- var result = Math.max(0, remainingAmount).toFixed(2);
3016
- console.log('[Checkout] calculateRemainingAmount: 计算详情:', {
3017
- orderUuid: this.store.currentOrder.uuid,
3018
- totalAmount: totalAmount.toFixed(2),
3019
- paidAmount: paidAmount.toFixed(2),
3020
- calculatedRemaining: remainingAmount.toFixed(2),
3021
- finalResult: result
3022
- });
3023
- return result;
3024
- }
3025
-
3270
+ return calculateRemainingAmountAsync;
3271
+ }()
3026
3272
  /**
3027
3273
  * 更新 stateAmount 为当前剩余未支付金额
3028
3274
  */
3275
+ )
3029
3276
  }, {
3030
3277
  key: "updateStateAmountToRemaining",
3031
3278
  value: (function () {
3032
- var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40() {
3033
- var _this$store$currentOr15, remainingAmount, currentStateAmount;
3034
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3035
- while (1) switch (_context40.prev = _context40.next) {
3279
+ var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44() {
3280
+ var _this$store$currentOr16, remainingAmount, currentStateAmount;
3281
+ return _regeneratorRuntime().wrap(function _callee44$(_context44) {
3282
+ while (1) switch (_context44.prev = _context44.next) {
3036
3283
  case 0:
3037
- _context40.prev = 0;
3038
- remainingAmount = this.calculateRemainingAmount();
3284
+ _context44.prev = 0;
3285
+ _context44.next = 3;
3286
+ return this.calculateRemainingAmountAsync();
3287
+ case 3:
3288
+ remainingAmount = _context44.sent;
3039
3289
  currentStateAmount = this.store.stateAmount;
3040
3290
  console.log('[Checkout] updateStateAmountToRemaining: 状态检查:', {
3041
3291
  calculatedRemainingAmount: remainingAmount,
3042
3292
  currentStateAmount: currentStateAmount,
3043
3293
  needsUpdate: remainingAmount !== currentStateAmount,
3044
- orderUuid: (_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.uuid
3294
+ orderUuid: (_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.uuid
3045
3295
  });
3046
3296
 
3047
3297
  // 只有当剩余金额与当前 stateAmount 不同时才更新
3048
3298
  if (!(remainingAmount !== currentStateAmount)) {
3049
- _context40.next = 11;
3299
+ _context44.next = 13;
3050
3300
  break;
3051
3301
  }
3052
3302
  this.store.stateAmount = remainingAmount;
3053
3303
 
3054
3304
  // 发出 stateAmount 变更事件
3055
- _context40.next = 8;
3305
+ _context44.next = 10;
3056
3306
  return this.core.effects.emit(CheckoutHooks.OnStateAmountChanged, {
3057
3307
  oldAmount: currentStateAmount,
3058
3308
  newAmount: remainingAmount,
3059
3309
  timestamp: Date.now()
3060
3310
  });
3061
- case 8:
3311
+ case 10:
3062
3312
  console.log('[Checkout] stateAmount 已自动更新为剩余金额:', {
3063
3313
  oldAmount: currentStateAmount,
3064
3314
  newAmount: remainingAmount
3065
3315
  });
3066
- _context40.next = 12;
3316
+ _context44.next = 14;
3067
3317
  break;
3068
- case 11:
3318
+ case 13:
3069
3319
  console.log('[Checkout] stateAmount 无需更新,当前值已是最新:', {
3070
3320
  stateAmount: currentStateAmount,
3071
3321
  remainingAmount: remainingAmount
3072
3322
  });
3073
- case 12:
3074
- _context40.next = 14;
3075
- return this.checkOrderPaymentCompletion();
3076
3323
  case 14:
3077
- _context40.next = 19;
3078
- break;
3324
+ _context44.next = 16;
3325
+ return this.checkOrderPaymentCompletion();
3079
3326
  case 16:
3080
- _context40.prev = 16;
3081
- _context40.t0 = _context40["catch"](0);
3082
- console.error('[Checkout] 更新 stateAmount 为剩余金额失败:', _context40.t0);
3083
- case 19:
3327
+ _context44.next = 21;
3328
+ break;
3329
+ case 18:
3330
+ _context44.prev = 18;
3331
+ _context44.t0 = _context44["catch"](0);
3332
+ console.error('[Checkout] 更新 stateAmount 为剩余金额失败:', _context44.t0);
3333
+ case 21:
3084
3334
  case "end":
3085
- return _context40.stop();
3335
+ return _context44.stop();
3086
3336
  }
3087
- }, _callee40, this, [[0, 16]]);
3337
+ }, _callee44, this, [[0, 18]]);
3088
3338
  }));
3089
3339
  function updateStateAmountToRemaining() {
3090
3340
  return _updateStateAmountToRemaining.apply(this, arguments);
@@ -3100,26 +3350,32 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3100
3350
  }, {
3101
3351
  key: "checkOrderPaymentCompletion",
3102
3352
  value: (function () {
3103
- var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
3104
- var remainingAmount, remainingValue, _this$store$currentOr16, _this$store$currentOr17, totalAmount, paidAmount, allPaymentsHaveVoucherId;
3105
- return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3106
- while (1) switch (_context41.prev = _context41.next) {
3353
+ var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45() {
3354
+ var remainingAmount, remainingValue, totalAmount, paidAmount, currentPayments, allPaymentsHaveVoucherId;
3355
+ return _regeneratorRuntime().wrap(function _callee45$(_context45) {
3356
+ while (1) switch (_context45.prev = _context45.next) {
3107
3357
  case 0:
3108
- _context41.prev = 0;
3358
+ _context45.prev = 0;
3109
3359
  if (this.store.currentOrder) {
3110
- _context41.next = 3;
3360
+ _context45.next = 3;
3111
3361
  break;
3112
3362
  }
3113
- return _context41.abrupt("return");
3363
+ return _context45.abrupt("return");
3114
3364
  case 3:
3115
- remainingAmount = this.calculateRemainingAmount();
3365
+ _context45.next = 5;
3366
+ return this.calculateRemainingAmountAsync();
3367
+ case 5:
3368
+ remainingAmount = _context45.sent;
3116
3369
  remainingValue = parseFloat(remainingAmount); // 当剩余金额小于等于0时,认为订单已完成支付
3117
3370
  if (!(remainingValue <= 0)) {
3118
- _context41.next = 21;
3371
+ _context45.next = 27;
3119
3372
  break;
3120
3373
  }
3121
3374
  totalAmount = this.store.currentOrder.total_amount;
3122
- paidAmount = this.calculatePaidAmount();
3375
+ _context45.next = 11;
3376
+ return this.calculatePaidAmountAsync();
3377
+ case 11:
3378
+ paidAmount = _context45.sent;
3123
3379
  console.log('[Checkout] 检测到订单支付完成:', {
3124
3380
  orderUuid: this.store.currentOrder.uuid,
3125
3381
  orderId: this.store.currentOrder.order_id,
@@ -3129,14 +3385,19 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3129
3385
  isOrderSynced: this.store.isOrderSynced
3130
3386
  });
3131
3387
 
3132
- // 检查是否所有支付项都带有 voucher_id
3133
- allPaymentsHaveVoucherId = this.store.currentOrder.payment && this.store.currentOrder.payment.length > 0 && this.store.currentOrder.payment.every(function (item) {
3388
+ // Payment 模块获取最新支付项,检查是否所有支付项都带有 voucher_id
3389
+ _context45.next = 15;
3390
+ return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
3391
+ );
3392
+ case 15:
3393
+ currentPayments = _context45.sent;
3394
+ allPaymentsHaveVoucherId = currentPayments.length > 0 && currentPayments.every(function (item) {
3134
3395
  return item.status !== 'voided' && item.voucher_id;
3135
3396
  });
3136
3397
  console.log('[Checkout] 支付项voucher_id检查:', {
3137
- paymentCount: ((_this$store$currentOr16 = this.store.currentOrder.payment) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.length) || 0,
3398
+ paymentCount: currentPayments.length,
3138
3399
  allHaveVoucherId: allPaymentsHaveVoucherId,
3139
- paymentItems: (_this$store$currentOr17 = this.store.currentOrder.payment) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.map(function (p) {
3400
+ paymentItems: currentPayments.map(function (p) {
3140
3401
  return {
3141
3402
  uuid: p.uuid,
3142
3403
  code: p.code,
@@ -3147,24 +3408,28 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3147
3408
  })
3148
3409
  });
3149
3410
 
3150
- // 如果支付完成但订单未同步,需要判断是否同步
3151
- if (this.store.isOrderSynced) {
3152
- _context41.next = 19;
3153
- break;
3154
- }
3411
+ // // 如果支付完成但订单未同步,需要判断是否同步
3412
+ // if (!this.store.isOrderSynced) {
3413
+ // if (allPaymentsHaveVoucherId) {
3414
+ // console.log('[Checkout] 所有支付项均为代金券类型,跳过订单同步');
3415
+ // } else {
3416
+ // console.log('[Checkout] 支付完成但订单未同步,开始同步订单到后端...');
3417
+ // await this.syncOrderToBackend();
3418
+ // }
3419
+ // }
3155
3420
  if (!allPaymentsHaveVoucherId) {
3156
- _context41.next = 16;
3421
+ _context45.next = 22;
3157
3422
  break;
3158
3423
  }
3159
3424
  console.log('[Checkout] 所有支付项均为代金券类型,跳过订单同步');
3160
- _context41.next = 19;
3425
+ _context45.next = 25;
3161
3426
  break;
3162
- case 16:
3427
+ case 22:
3163
3428
  console.log('[Checkout] 支付完成但订单未同步,开始同步订单到后端...');
3164
- _context41.next = 19;
3429
+ _context45.next = 25;
3165
3430
  return this.syncOrderToBackend();
3166
- case 19:
3167
- _context41.next = 21;
3431
+ case 25:
3432
+ _context45.next = 27;
3168
3433
  return this.core.effects.emit(CheckoutHooks.OnOrderPaymentCompleted, {
3169
3434
  orderUuid: this.store.currentOrder.uuid,
3170
3435
  orderId: this.store.currentOrder.order_id,
@@ -3173,18 +3438,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3173
3438
  remainingAmount: remainingAmount,
3174
3439
  timestamp: Date.now()
3175
3440
  });
3176
- case 21:
3177
- _context41.next = 26;
3441
+ case 27:
3442
+ _context45.next = 32;
3178
3443
  break;
3179
- case 23:
3180
- _context41.prev = 23;
3181
- _context41.t0 = _context41["catch"](0);
3182
- console.error('[Checkout] 检查订单支付完成状态失败:', _context41.t0);
3183
- case 26:
3444
+ case 29:
3445
+ _context45.prev = 29;
3446
+ _context45.t0 = _context45["catch"](0);
3447
+ console.error('[Checkout] 检查订单支付完成状态失败:', _context45.t0);
3448
+ case 32:
3184
3449
  case "end":
3185
- return _context41.stop();
3450
+ return _context45.stop();
3186
3451
  }
3187
- }, _callee41, this, [[0, 23]]);
3452
+ }, _callee45, this, [[0, 29]]);
3188
3453
  }));
3189
3454
  function checkOrderPaymentCompletion() {
3190
3455
  return _checkOrderPaymentCompletion.apply(this, arguments);
@@ -3256,8 +3521,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3256
3521
  }, {
3257
3522
  key: "syncOrderToBackendWithReturn",
3258
3523
  value: (function () {
3259
- var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42() {
3260
- var _this$store$currentCu2, _this$store$currentOr18, _this$store$currentOr19;
3524
+ var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46() {
3525
+ var _this$store$currentCu2, _this$store$currentOr17, _this$store$currentOr18;
3261
3526
  var isManual,
3262
3527
  customPaymentItems,
3263
3528
  syncType,
@@ -3276,14 +3541,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3276
3541
  beforeManualUpdate,
3277
3542
  finalOrderId,
3278
3543
  finalIsVirtual,
3279
- _args42 = arguments;
3280
- return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3281
- while (1) switch (_context42.prev = _context42.next) {
3544
+ _args46 = arguments;
3545
+ return _regeneratorRuntime().wrap(function _callee46$(_context46) {
3546
+ while (1) switch (_context46.prev = _context46.next) {
3282
3547
  case 0:
3283
- isManual = _args42.length > 0 && _args42[0] !== undefined ? _args42[0] : false;
3284
- customPaymentItems = _args42.length > 1 ? _args42[1] : undefined;
3548
+ isManual = _args46.length > 0 && _args46[0] !== undefined ? _args46[0] : false;
3549
+ customPaymentItems = _args46.length > 1 ? _args46[1] : undefined;
3285
3550
  if (!(!this.store.localOrderData || !this.store.currentOrder)) {
3286
- _context42.next = 4;
3551
+ _context46.next = 4;
3287
3552
  break;
3288
3553
  }
3289
3554
  throw new Error('缺少必要的订单数据,无法同步到后端');
@@ -3324,17 +3589,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3324
3589
  });
3325
3590
 
3326
3591
  // 获取当前订单的支付项
3327
- _context42.t0 = customPaymentItems;
3328
- if (_context42.t0) {
3329
- _context42.next = 18;
3592
+ _context46.t0 = customPaymentItems;
3593
+ if (_context46.t0) {
3594
+ _context46.next = 18;
3330
3595
  break;
3331
3596
  }
3332
- _context42.next = 17;
3597
+ _context46.next = 17;
3333
3598
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
3334
3599
  case 17:
3335
- _context42.t0 = _context42.sent;
3600
+ _context46.t0 = _context46.sent;
3336
3601
  case 18:
3337
- paymentItems = _context42.t0;
3602
+ paymentItems = _context46.t0;
3338
3603
  console.log('[Checkout] 获取到支付项:', {
3339
3604
  count: paymentItems.length,
3340
3605
  isCustomFiltered: !!customPaymentItems,
@@ -3375,8 +3640,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3375
3640
  currency_code: this.otherParams.currency_code,
3376
3641
  currency_symbol: this.otherParams.currency_symbol,
3377
3642
  currency_format: this.otherParams.currency_format,
3378
- is_deposit: ((_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.is_deposit) || 0,
3379
- deposit_amount: ((_this$store$currentOr19 = this.store.currentOrder) === null || _this$store$currentOr19 === void 0 ? void 0 : _this$store$currentOr19.deposit_amount) || '0.00',
3643
+ is_deposit: ((_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.is_deposit) || 0,
3644
+ deposit_amount: ((_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.deposit_amount) || '0.00',
3380
3645
  // surcharge_fee: this.otherParams.surcharge_fee,
3381
3646
  // surcharges: ,
3382
3647
  note: this.store.localOrderData.shop_note
@@ -3406,10 +3671,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3406
3671
  }
3407
3672
 
3408
3673
  // 调用 Order 模块的专用 createOrderByCheckout 方法
3409
- _context42.next = 24;
3674
+ _context46.next = 24;
3410
3675
  return this.order.createOrderByCheckout(orderParams);
3411
3676
  case 24:
3412
- checkoutResponse = _context42.sent;
3677
+ checkoutResponse = _context46.sent;
3413
3678
  console.log('[Checkout] 后端返回的响应数据:', {
3414
3679
  status: checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.status,
3415
3680
  code: checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.code,
@@ -3417,13 +3682,13 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3417
3682
  data: checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.data
3418
3683
  });
3419
3684
  if (!isUpdateOperation) {
3420
- _context42.next = 31;
3685
+ _context46.next = 31;
3421
3686
  break;
3422
3687
  }
3423
3688
  // 更新操作:使用现有的订单ID
3424
3689
  realOrderId = currentOrderId;
3425
3690
  console.log("[Checkout] \u8BA2\u5355\u66F4\u65B0\u6210\u529F\uFF0C\u8BA2\u5355ID: ".concat(realOrderId));
3426
- _context42.next = 52;
3691
+ _context46.next = 52;
3427
3692
  break;
3428
3693
  case 31:
3429
3694
  // 创建操作:从响应中提取新的订单ID
@@ -3437,7 +3702,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3437
3702
  extractedOrderId = String(extractedOrderId);
3438
3703
  }
3439
3704
  if (extractedOrderId) {
3440
- _context42.next = 36;
3705
+ _context46.next = 36;
3441
3706
  break;
3442
3707
  }
3443
3708
  throw new Error('后端返回的订单信息中未包含订单ID');
@@ -3451,11 +3716,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3451
3716
  oldOrderId: this.store.currentOrder.order_id,
3452
3717
  newOrderId: realOrderId
3453
3718
  });
3454
- _context42.prev = 39;
3455
- _context42.next = 42;
3719
+ _context46.prev = 39;
3720
+ _context46.next = 42;
3456
3721
  return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, realOrderId);
3457
3722
  case 42:
3458
- updatedOrder = _context42.sent;
3723
+ updatedOrder = _context46.sent;
3459
3724
  console.log('[Checkout] Payment模块替换订单ID结果:', {
3460
3725
  wasSuccessful: !!updatedOrder,
3461
3726
  returnedOrderId: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.order_id,
@@ -3481,12 +3746,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3481
3746
  目标ID: realOrderId
3482
3747
  });
3483
3748
  }
3484
- _context42.next = 52;
3749
+ _context46.next = 52;
3485
3750
  break;
3486
3751
  case 47:
3487
- _context42.prev = 47;
3488
- _context42.t1 = _context42["catch"](39);
3489
- console.error('[Checkout] 调用Payment模块替换订单ID时发生错误:', _context42.t1);
3752
+ _context46.prev = 47;
3753
+ _context46.t1 = _context46["catch"](39);
3754
+ console.error('[Checkout] 调用Payment模块替换订单ID时发生错误:', _context46.t1);
3490
3755
 
3491
3756
  // 发生错误时也进行手动替换
3492
3757
  this.store.currentOrder.order_id = realOrderId;
@@ -3496,7 +3761,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3496
3761
  this.store.isOrderSynced = true;
3497
3762
 
3498
3763
  // 触发订单同步完成事件
3499
- _context42.next = 55;
3764
+ _context46.next = 55;
3500
3765
  return this.core.effects.emit(CheckoutHooks.OnOrderSynced, {
3501
3766
  orderUuid: this.store.currentOrder.uuid,
3502
3767
  realOrderId: realOrderId,
@@ -3522,12 +3787,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3522
3787
  }
3523
3788
 
3524
3789
  // 返回真实订单ID
3525
- return _context42.abrupt("return", realOrderId);
3790
+ return _context46.abrupt("return", realOrderId);
3526
3791
  case 60:
3527
3792
  case "end":
3528
- return _context42.stop();
3793
+ return _context46.stop();
3529
3794
  }
3530
- }, _callee42, this, [[39, 47]]);
3795
+ }, _callee46, this, [[39, 47]]);
3531
3796
  }));
3532
3797
  function syncOrderToBackendWithReturn() {
3533
3798
  return _syncOrderToBackendWithReturn.apply(this, arguments);
@@ -3537,27 +3802,27 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3537
3802
  }, {
3538
3803
  key: "syncOrderToBackend",
3539
3804
  value: function () {
3540
- var _syncOrderToBackend = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43() {
3541
- return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3542
- while (1) switch (_context43.prev = _context43.next) {
3805
+ var _syncOrderToBackend = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47() {
3806
+ return _regeneratorRuntime().wrap(function _callee47$(_context47) {
3807
+ while (1) switch (_context47.prev = _context47.next) {
3543
3808
  case 0:
3544
- _context43.prev = 0;
3545
- _context43.next = 3;
3809
+ _context47.prev = 0;
3810
+ _context47.next = 3;
3546
3811
  return this.syncOrderToBackendWithReturn(false);
3547
3812
  case 3:
3548
- _context43.next = 10;
3813
+ _context47.next = 10;
3549
3814
  break;
3550
3815
  case 5:
3551
- _context43.prev = 5;
3552
- _context43.t0 = _context43["catch"](0);
3553
- console.error('[Checkout] 同步订单到后端失败:', _context43.t0);
3554
- _context43.next = 10;
3555
- return this.handleError(new Error("\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context43.t0 instanceof Error ? _context43.t0.message : String(_context43.t0))), CheckoutErrorType.OrderCreationFailed);
3816
+ _context47.prev = 5;
3817
+ _context47.t0 = _context47["catch"](0);
3818
+ console.error('[Checkout] 同步订单到后端失败:', _context47.t0);
3819
+ _context47.next = 10;
3820
+ return this.handleError(new Error("\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context47.t0 instanceof Error ? _context47.t0.message : String(_context47.t0))), CheckoutErrorType.OrderCreationFailed);
3556
3821
  case 10:
3557
3822
  case "end":
3558
- return _context43.stop();
3823
+ return _context47.stop();
3559
3824
  }
3560
- }, _callee43, this, [[0, 5]]);
3825
+ }, _callee47, this, [[0, 5]]);
3561
3826
  }));
3562
3827
  function syncOrderToBackend() {
3563
3828
  return _syncOrderToBackend.apply(this, arguments);
@@ -3597,15 +3862,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3597
3862
  }, {
3598
3863
  key: "setOtherParams",
3599
3864
  value: function () {
3600
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(params) {
3865
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee48(params) {
3601
3866
  var _ref3,
3602
3867
  _ref3$cover,
3603
3868
  cover,
3604
- _args44 = arguments;
3605
- return _regeneratorRuntime().wrap(function _callee44$(_context44) {
3606
- while (1) switch (_context44.prev = _context44.next) {
3869
+ _args48 = arguments;
3870
+ return _regeneratorRuntime().wrap(function _callee48$(_context48) {
3871
+ while (1) switch (_context48.prev = _context48.next) {
3607
3872
  case 0:
3608
- _ref3 = _args44.length > 1 && _args44[1] !== undefined ? _args44[1] : {}, _ref3$cover = _ref3.cover, cover = _ref3$cover === void 0 ? false : _ref3$cover;
3873
+ _ref3 = _args48.length > 1 && _args48[1] !== undefined ? _args48[1] : {}, _ref3$cover = _ref3.cover, cover = _ref3$cover === void 0 ? false : _ref3$cover;
3609
3874
  if (cover) {
3610
3875
  this.otherParams = params;
3611
3876
  } else {
@@ -3613,11 +3878,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3613
3878
  }
3614
3879
  case 2:
3615
3880
  case "end":
3616
- return _context44.stop();
3881
+ return _context48.stop();
3617
3882
  }
3618
- }, _callee44, this);
3883
+ }, _callee48, this);
3619
3884
  }));
3620
- function setOtherParams(_x29) {
3885
+ function setOtherParams(_x30) {
3621
3886
  return _setOtherParams.apply(this, arguments);
3622
3887
  }
3623
3888
  return setOtherParams;
@@ -3634,12 +3899,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3634
3899
  }, {
3635
3900
  key: "editOrderNoteByOrderIdAsync",
3636
3901
  value: (function () {
3637
- var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(orderId, note) {
3902
+ var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee49(orderId, note) {
3638
3903
  var response, previousNote, errorMessage, _errorMessage;
3639
- return _regeneratorRuntime().wrap(function _callee45$(_context45) {
3640
- while (1) switch (_context45.prev = _context45.next) {
3904
+ return _regeneratorRuntime().wrap(function _callee49$(_context49) {
3905
+ while (1) switch (_context49.prev = _context49.next) {
3641
3906
  case 0:
3642
- _context45.prev = 0;
3907
+ _context49.prev = 0;
3643
3908
  console.log('[Checkout] 开始编辑订单备注:', {
3644
3909
  orderId: orderId,
3645
3910
  note: note,
@@ -3648,21 +3913,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3648
3913
 
3649
3914
  // 参数验证
3650
3915
  if (orderId) {
3651
- _context45.next = 4;
3916
+ _context49.next = 4;
3652
3917
  break;
3653
3918
  }
3654
- return _context45.abrupt("return", {
3919
+ return _context49.abrupt("return", {
3655
3920
  success: false,
3656
3921
  message: '订单ID不能为空',
3657
3922
  orderId: orderId
3658
3923
  });
3659
3924
  case 4:
3660
- _context45.next = 6;
3925
+ _context49.next = 6;
3661
3926
  return this.request.put("/shop/order/order/".concat(orderId, "/note"), {
3662
3927
  note: note
3663
3928
  });
3664
3929
  case 6:
3665
- response = _context45.sent;
3930
+ response = _context49.sent;
3666
3931
  console.log('[Checkout] 订单备注编辑响应:', {
3667
3932
  orderId: orderId,
3668
3933
  status: response.status,
@@ -3672,14 +3937,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3672
3937
 
3673
3938
  // 检查响应状态
3674
3939
  if (!(response.status === true || response.status === 200)) {
3675
- _context45.next = 19;
3940
+ _context49.next = 19;
3676
3941
  break;
3677
3942
  }
3678
3943
  console.log("[Checkout] \u8BA2\u5355 ".concat(orderId, " \u5907\u6CE8\u4FEE\u6539\u6210\u529F"));
3679
3944
 
3680
3945
  // 如果当前订单就是被修改的订单,同时更新本地状态
3681
3946
  if (!(this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId)))) {
3682
- _context45.next = 16;
3947
+ _context49.next = 16;
3683
3948
  break;
3684
3949
  }
3685
3950
  console.log('[Checkout] 更新本地订单备注状态');
@@ -3691,7 +3956,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3691
3956
  }
3692
3957
 
3693
3958
  // 触发订单备注变更事件
3694
- _context45.next = 16;
3959
+ _context49.next = 16;
3695
3960
  return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
3696
3961
  orderUuid: this.store.currentOrder.uuid,
3697
3962
  oldNote: previousNote,
@@ -3699,7 +3964,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3699
3964
  timestamp: Date.now()
3700
3965
  });
3701
3966
  case 16:
3702
- return _context45.abrupt("return", {
3967
+ return _context49.abrupt("return", {
3703
3968
  success: true,
3704
3969
  message: response.message || '订单备注修改成功',
3705
3970
  orderId: orderId
@@ -3708,42 +3973,193 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3708
3973
  // API返回失败状态
3709
3974
  errorMessage = response.message || '订单备注修改失败';
3710
3975
  console.error("[Checkout] \u8BA2\u5355 ".concat(orderId, " \u5907\u6CE8\u4FEE\u6539\u5931\u8D25:"), errorMessage);
3711
- return _context45.abrupt("return", {
3976
+ return _context49.abrupt("return", {
3712
3977
  success: false,
3713
3978
  message: errorMessage,
3714
3979
  orderId: orderId
3715
3980
  });
3716
3981
  case 22:
3717
- _context45.next = 29;
3982
+ _context49.next = 29;
3718
3983
  break;
3719
3984
  case 24:
3720
- _context45.prev = 24;
3721
- _context45.t0 = _context45["catch"](0);
3722
- console.error('[Checkout] 编辑订单备注失败:', _context45.t0);
3723
- _errorMessage = _context45.t0 instanceof Error ? _context45.t0.message : '网络错误或服务器异常';
3724
- return _context45.abrupt("return", {
3985
+ _context49.prev = 24;
3986
+ _context49.t0 = _context49["catch"](0);
3987
+ console.error('[Checkout] 编辑订单备注失败:', _context49.t0);
3988
+ _errorMessage = _context49.t0 instanceof Error ? _context49.t0.message : '网络错误或服务器异常';
3989
+ return _context49.abrupt("return", {
3725
3990
  success: false,
3726
3991
  message: "\u7F16\u8F91\u8BA2\u5355\u5907\u6CE8\u5931\u8D25: ".concat(_errorMessage),
3727
3992
  orderId: orderId
3728
3993
  });
3729
3994
  case 29:
3730
3995
  case "end":
3731
- return _context45.stop();
3996
+ return _context49.stop();
3732
3997
  }
3733
- }, _callee45, this, [[0, 24]]);
3998
+ }, _callee49, this, [[0, 24]]);
3734
3999
  }));
3735
- function editOrderNoteByOrderIdAsync(_x30, _x31) {
4000
+ function editOrderNoteByOrderIdAsync(_x31, _x32) {
3736
4001
  return _editOrderNoteByOrderIdAsync.apply(this, arguments);
3737
4002
  }
3738
4003
  return editOrderNoteByOrderIdAsync;
4004
+ }()
4005
+ /**
4006
+ * 发送客户支付链接邮件
4007
+ *
4008
+ * 向指定邮箱发送订单支付提醒邮件
4009
+ *
4010
+ * @param params 发送参数
4011
+ * @returns 发送结果
4012
+ */
4013
+ )
4014
+ }, {
4015
+ key: "sendCustomerPayLinkAsync",
4016
+ value: (function () {
4017
+ var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee50(params) {
4018
+ var emailRegex, invalidEmails, requestBody, response, errorMessage, _errorMessage2;
4019
+ return _regeneratorRuntime().wrap(function _callee50$(_context50) {
4020
+ while (1) switch (_context50.prev = _context50.next) {
4021
+ case 0:
4022
+ _context50.prev = 0;
4023
+ console.log('[Checkout] 开始发送客户支付链接邮件:', {
4024
+ orderIds: params.order_ids,
4025
+ emails: params.emails,
4026
+ notifyAction: params.notify_action || 'order_payment_reminder'
4027
+ });
4028
+
4029
+ // 参数验证
4030
+ if (!(!params.order_ids || params.order_ids.length === 0)) {
4031
+ _context50.next = 4;
4032
+ break;
4033
+ }
4034
+ return _context50.abrupt("return", {
4035
+ success: false,
4036
+ message: '订单ID列表不能为空'
4037
+ });
4038
+ case 4:
4039
+ if (!(!params.emails || params.emails.length === 0)) {
4040
+ _context50.next = 6;
4041
+ break;
4042
+ }
4043
+ return _context50.abrupt("return", {
4044
+ success: false,
4045
+ message: '邮箱地址列表不能为空'
4046
+ });
4047
+ case 6:
4048
+ // 验证邮箱格式
4049
+ emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
4050
+ invalidEmails = params.emails.filter(function (email) {
4051
+ return !emailRegex.test(email);
4052
+ });
4053
+ if (!(invalidEmails.length > 0)) {
4054
+ _context50.next = 10;
4055
+ break;
4056
+ }
4057
+ return _context50.abrupt("return", {
4058
+ success: false,
4059
+ message: "\u90AE\u7BB1\u683C\u5F0F\u65E0\u6548: ".concat(invalidEmails.join(', '))
4060
+ });
4061
+ case 10:
4062
+ // 构建请求参数
4063
+ requestBody = {
4064
+ order_ids: params.order_ids,
4065
+ notify_action: params.notify_action || 'order_payment_reminder',
4066
+ emails: params.emails
4067
+ };
4068
+ console.log('[Checkout] 发送支付链接邮件请求参数:', requestBody);
4069
+
4070
+ // 调用后端API发送邮件
4071
+ _context50.next = 14;
4072
+ return this.request.post('/order/batch-email', requestBody);
4073
+ case 14:
4074
+ response = _context50.sent;
4075
+ console.log('[Checkout] 支付链接邮件发送响应:', {
4076
+ status: response.status,
4077
+ message: response.message,
4078
+ data: response.data,
4079
+ response: response
4080
+ });
4081
+
4082
+ // 检查响应状态
4083
+ if (!(response.status === true || response.status === 200)) {
4084
+ _context50.next = 21;
4085
+ break;
4086
+ }
4087
+ console.log('[Checkout] 支付链接邮件发送成功');
4088
+ return _context50.abrupt("return", {
4089
+ success: true,
4090
+ message: response.message || '支付链接邮件发送成功'
4091
+ });
4092
+ case 21:
4093
+ // API返回失败状态
4094
+ errorMessage = response.message || '支付链接邮件发送失败';
4095
+ console.error('[Checkout] 支付链接邮件发送失败:', errorMessage);
4096
+ return _context50.abrupt("return", {
4097
+ success: false,
4098
+ message: errorMessage
4099
+ });
4100
+ case 24:
4101
+ _context50.next = 31;
4102
+ break;
4103
+ case 26:
4104
+ _context50.prev = 26;
4105
+ _context50.t0 = _context50["catch"](0);
4106
+ console.error('[Checkout] 发送客户支付链接邮件失败:', _context50.t0);
4107
+ _errorMessage2 = _context50.t0 instanceof Error ? _context50.t0.message : '网络错误或服务器异常';
4108
+ return _context50.abrupt("return", {
4109
+ success: false,
4110
+ message: "\u53D1\u9001\u652F\u4ED8\u94FE\u63A5\u90AE\u4EF6\u5931\u8D25: ".concat(_errorMessage2)
4111
+ });
4112
+ case 31:
4113
+ case "end":
4114
+ return _context50.stop();
4115
+ }
4116
+ }, _callee50, this, [[0, 26]]);
4117
+ }));
4118
+ function sendCustomerPayLinkAsync(_x33) {
4119
+ return _sendCustomerPayLinkAsync.apply(this, arguments);
4120
+ }
4121
+ return sendCustomerPayLinkAsync;
4122
+ }()
4123
+ /**
4124
+ * 金额舍入
4125
+ *
4126
+ * @param amount 原始金额
4127
+ * @returns 舍入结果详情,包含原始金额、舍入后金额和舍入差额
4128
+ */
4129
+ )
4130
+ }, {
4131
+ key: "roundAmountAsync",
4132
+ value: (function () {
4133
+ var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee51(amount) {
4134
+ var _this$otherParams$ord, _this$otherParams$ord2;
4135
+ var result;
4136
+ return _regeneratorRuntime().wrap(function _callee51$(_context51) {
4137
+ while (1) switch (_context51.prev = _context51.next) {
4138
+ case 0:
4139
+ _context51.next = 2;
4140
+ 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);
4141
+ case 2:
4142
+ result = _context51.sent;
4143
+ console.log("[Checkout] \u91D1\u989D\u820D\u5165\u5B8C\u6210 - \u539F\u59CB: ".concat(result.originalAmount, ", \u820D\u5165\u540E: ").concat(result.roundedAmount, ", \u5DEE\u989D: ").concat(result.roundingDifference));
4144
+ return _context51.abrupt("return", result);
4145
+ case 5:
4146
+ case "end":
4147
+ return _context51.stop();
4148
+ }
4149
+ }, _callee51, this);
4150
+ }));
4151
+ function roundAmountAsync(_x34) {
4152
+ return _roundAmountAsync.apply(this, arguments);
4153
+ }
4154
+ return roundAmountAsync;
3739
4155
  }())
3740
4156
  }, {
3741
4157
  key: "destroy",
3742
4158
  value: function () {
3743
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46() {
4159
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee52() {
3744
4160
  var _this$order, _this$order$destroy, _this$payment, _this$payment$destroy;
3745
- return _regeneratorRuntime().wrap(function _callee46$(_context46) {
3746
- while (1) switch (_context46.prev = _context46.next) {
4161
+ return _regeneratorRuntime().wrap(function _callee52$(_context52) {
4162
+ while (1) switch (_context52.prev = _context52.next) {
3747
4163
  case 0:
3748
4164
  // 清理钱包模块的所有缓存数据
3749
4165
  this.payment.wallet.clearAllCache();
@@ -3752,10 +4168,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3752
4168
  this.core.effects.offByModuleDestroy(this.name);
3753
4169
 
3754
4170
  // 销毁子模块
3755
- _context46.next = 4;
4171
+ _context52.next = 4;
3756
4172
  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);
3757
4173
  case 4:
3758
- _context46.next = 6;
4174
+ _context52.next = 6;
3759
4175
  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);
3760
4176
  case 6:
3761
4177
  // 取消注册模块
@@ -3763,9 +4179,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3763
4179
  console.log('[Checkout] 已销毁');
3764
4180
  case 8:
3765
4181
  case "end":
3766
- return _context46.stop();
4182
+ return _context52.stop();
3767
4183
  }
3768
- }, _callee46, this);
4184
+ }, _callee52, this);
3769
4185
  }));
3770
4186
  function destroy() {
3771
4187
  return _destroy.apply(this, arguments);