@pisell/pisellos 0.0.294 → 0.0.295

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.
@@ -31,6 +31,7 @@ import { PaymentModule } from "../../modules/Payment";
31
31
  import { CheckoutHooks, CheckoutErrorType } from "./types";
32
32
  import { PaymentStatus, PaymentHooks } from "../../modules/Payment/types";
33
33
  import { validateCheckoutData, createCheckoutError, validateLocalOrderData, generateLocalOrderId, formatDateTime, extractAmountFromCartSummary, isVirtualOrderId, isCashPayment } from "./utils";
34
+ import { getProductDeposit } from "../../modules/Cart/utils";
34
35
  export * from "./types";
35
36
 
36
37
  /**
@@ -398,8 +399,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
398
399
  key: "initWalletData",
399
400
  value: function () {
400
401
  var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
401
- var _this$store$currentOr3, _this$store$currentCu, _this$store$currentOr5;
402
- var amountInfo, walletBusinessData, _this$store$currentOr4;
402
+ var _this$store$currentOr3, _this$store$currentCu, _this$store$currentOr4, _this$store$currentOr5, _this$store$currentOr7;
403
+ var amountInfo, walletBusinessData, _this$store$currentOr6;
403
404
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
404
405
  while (1) switch (_context8.prev = _context8.next) {
405
406
  case 0:
@@ -421,12 +422,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
421
422
  customer_id: (_this$store$currentCu = this.store.currentCustomer) !== null && _this$store$currentCu !== void 0 && _this$store$currentCu.customer_id ? Number(this.store.currentCustomer.customer_id) : undefined,
422
423
  amountInfo: {
423
424
  totalAmount: amountInfo.totalAmount,
424
- subTotal: amountInfo.subTotal
425
+ subTotal: amountInfo.subTotal,
426
+ depositAmount: (_this$store$currentOr4 = this.store.currentOrder) === null || _this$store$currentOr4 === void 0 ? void 0 : _this$store$currentOr4.deposit_amount,
427
+ isDeposit: (_this$store$currentOr5 = this.store.currentOrder) === null || _this$store$currentOr5 === void 0 ? void 0 : _this$store$currentOr5.is_deposit
425
428
  },
426
429
  products: this.getProductListByOrder()
427
430
  }, params); // 判断订单是否已经同步,如果是则追加payment_order_id参数
428
431
  if (this.store.isOrderSynced) {
429
- walletBusinessData.payment_order_id = (_this$store$currentOr4 = this.store.currentOrder) === null || _this$store$currentOr4 === void 0 ? void 0 : _this$store$currentOr4.order_id;
432
+ walletBusinessData.payment_order_id = (_this$store$currentOr6 = this.store.currentOrder) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.order_id;
430
433
  }
431
434
  this.logInfo('开始拉取:initializeWalletDataFromBusinessAsync', {
432
435
  walletBusinessData: walletBusinessData
@@ -451,7 +454,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
451
454
  // 触发钱包数据初始化完成事件
452
455
  _context8.next = 16;
453
456
  return this.core.effects.emit(CheckoutHooks.OnWalletDataInitialized, {
454
- orderUuid: (_this$store$currentOr5 = this.store.currentOrder) === null || _this$store$currentOr5 === void 0 ? void 0 : _this$store$currentOr5.uuid,
457
+ orderUuid: (_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.uuid,
455
458
  customerId: walletBusinessData.customer_id,
456
459
  walletBusinessData: {
457
460
  customer_id: walletBusinessData.customer_id,
@@ -471,6 +474,59 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
471
474
  }
472
475
  return initWalletData;
473
476
  }()
477
+ }, {
478
+ key: "checkIsNeedDepositAsync",
479
+ value: function checkIsNeedDepositAsync(bookings, relationProducts) {
480
+ var summaryDeposit = {
481
+ total: 0,
482
+ protocols: [],
483
+ hasDeposit: false
484
+ };
485
+ bookings === null || bookings === void 0 || bookings.forEach(function (item) {
486
+ var deposit = getProductDeposit({
487
+ cartItem: {
488
+ total: item.product.price * item.num
489
+ },
490
+ product: item.product,
491
+ bundle: item.bundle,
492
+ options: item.options,
493
+ num: item.num
494
+ });
495
+ item.deposit = deposit;
496
+ if (deposit !== null && deposit !== void 0 && deposit.total && Number(deposit.total) > 0) {
497
+ // 需要减去商品券折扣卡抵扣的金额
498
+ summaryDeposit.total = new Decimal(summaryDeposit.total).plus(deposit.total).toNumber();
499
+ item.product.discount_list.forEach(function (discount) {
500
+ summaryDeposit.total = new Decimal(summaryDeposit.total).minus(discount.amount || 0).toNumber();
501
+ });
502
+ summaryDeposit.protocols = summaryDeposit.protocols.concat(deposit.protocols);
503
+ summaryDeposit.hasDeposit = true;
504
+ }
505
+ });
506
+ relationProducts === null || relationProducts === void 0 || relationProducts.forEach(function (item) {
507
+ var deposit = getProductDeposit({
508
+ cartItem: {
509
+ total: item.price * item.num
510
+ },
511
+ product: item,
512
+ bundle: item.product_bundle,
513
+ options: item.product_option_item,
514
+ num: item.num
515
+ });
516
+ item.deposit = deposit;
517
+ if (deposit !== null && deposit !== void 0 && deposit.total && Number(deposit.total) > 0) {
518
+ // 需要减去商品券折扣卡抵扣的金额
519
+ summaryDeposit.total = new Decimal(summaryDeposit.total).plus(deposit.total).toNumber();
520
+ item.discount_list.forEach(function (discount) {
521
+ summaryDeposit.total = new Decimal(summaryDeposit.total).minus(discount.amount || 0).toNumber();
522
+ });
523
+ summaryDeposit.protocols = summaryDeposit.protocols.concat(deposit.protocols);
524
+ summaryDeposit.hasDeposit = true;
525
+ }
526
+ });
527
+ return summaryDeposit;
528
+ }
529
+
474
530
  /**
475
531
  * 创建本地订单 (前端模拟下单流程)
476
532
  *
@@ -483,7 +539,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
483
539
  value: (function () {
484
540
  var _createLocalOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
485
541
  var _params$orderData, _params$orderData2, _params$orderData3, _params$orderData4, _params$orderData5, _params$cartSummary;
486
- var _params$totalInfo, _params$totalInfo2, _params$totalInfo3, _params$totalInfo4, validation, localOrderId, amountInfo, customerInfo, paymentOrder;
542
+ var _params$totalInfo, _params$totalInfo2, _params$totalInfo3, _params$totalInfo4, validation, localOrderId, amountInfo, customerInfo, isNeedDeposit, paymentOrder;
487
543
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
488
544
  while (1) switch (_context9.prev = _context9.next) {
489
545
  case 0:
@@ -540,13 +596,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
540
596
  console.log('[Checkout] 未提供客户信息');
541
597
  }
542
598
 
543
- // 创建支付订单对象
544
- _context9.next = 21;
599
+ // 计算是否需要支付定金,如果需要默认切换到定金模式,以及记录定金总金额,并把当前默认待付金额调整为定金总金额
600
+ isNeedDeposit = this.checkIsNeedDepositAsync(params.orderData.bookings, params.orderData.relation_products); // 创建支付订单对象
601
+ _context9.next = 22;
545
602
  return this.payment.createPaymentOrderAsync({
546
603
  order_id: localOrderId,
547
604
  total_amount: amountInfo.totalAmount,
548
- is_deposit: params.orderData.is_deposit || 0,
549
- deposit_amount: amountInfo.depositAmount || '0.00',
605
+ is_deposit: isNeedDeposit.hasDeposit ? 1 : 0,
606
+ deposit_amount: isNeedDeposit.total ? isNeedDeposit.total.toString() : '0.00',
550
607
  order_info: {
551
608
  original_order_data: params.orderData,
552
609
  cart_summary: params.cartSummary,
@@ -558,7 +615,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
558
615
  amount_breakdown: amountInfo
559
616
  }
560
617
  });
561
- case 21:
618
+ case 22:
562
619
  paymentOrder = _context9.sent;
563
620
  this.store.currentOrder = paymentOrder;
564
621
 
@@ -572,9 +629,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
572
629
  });
573
630
 
574
631
  // 自动设置 stateAmount 为剩余未支付金额
575
- _context9.next = 27;
632
+ _context9.next = 28;
576
633
  return this.updateStateAmountToRemaining(false);
577
- case 27:
634
+ case 28:
578
635
  this.logInfo('本地订单创建成功:', {
579
636
  localOrderId: localOrderId,
580
637
  uuid: paymentOrder.uuid,
@@ -585,23 +642,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
585
642
  });
586
643
  this.initWalletData();
587
644
  return _context9.abrupt("return", paymentOrder);
588
- case 32:
589
- _context9.prev = 32;
645
+ case 33:
646
+ _context9.prev = 33;
590
647
  _context9.t0 = _context9["catch"](1);
591
- _context9.next = 36;
648
+ _context9.next = 37;
592
649
  return this.handleError(_context9.t0, CheckoutErrorType.OrderCreationFailed);
593
- case 36:
650
+ case 37:
594
651
  this.logError('本地订单创建失败:', _context9.t0);
595
652
  this.core.effects.emit(CheckoutHooks.OnOrderCreationFailed, {
596
653
  error: this.store.lastError,
597
654
  timestamp: Date.now()
598
655
  });
599
656
  throw _context9.t0;
600
- case 39:
657
+ case 40:
601
658
  case "end":
602
659
  return _context9.stop();
603
660
  }
604
- }, _callee9, this, [[1, 32]]);
661
+ }, _callee9, this, [[1, 33]]);
605
662
  }));
606
663
  function createLocalOrderAsync(_x11) {
607
664
  return _createLocalOrderAsync.apply(this, arguments);
@@ -849,8 +906,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
849
906
  }, {
850
907
  key: "getOrderOriginalData",
851
908
  value: function getOrderOriginalData() {
852
- var _this$store$currentOr6;
853
- return (_this$store$currentOr6 = this.store.currentOrder) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.order_info;
909
+ var _this$store$currentOr8;
910
+ return (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.order_info;
854
911
  }
855
912
 
856
913
  /**
@@ -1631,33 +1688,34 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1631
1688
  if (this.store.localOrderData) {
1632
1689
  this.store.localOrderData.is_deposit = newDepositValue;
1633
1690
  }
1691
+ this.updateStateAmountToRemaining();
1634
1692
 
1635
1693
  // 触发订单更新事件
1636
- _context19.next = 18;
1694
+ _context19.next = 19;
1637
1695
  return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
1638
1696
  order: this.store.currentOrder,
1639
1697
  timestamp: Date.now()
1640
1698
  });
1641
- case 18:
1699
+ case 19:
1642
1700
  this.logInfo('订单定金状态更新成功:', {
1643
1701
  isDeposit: newDepositValue,
1644
1702
  depositAmount: this.store.currentOrder.deposit_amount
1645
1703
  });
1646
- _context19.next = 27;
1704
+ _context19.next = 28;
1647
1705
  break;
1648
- case 21:
1649
- _context19.prev = 21;
1706
+ case 22:
1707
+ _context19.prev = 22;
1650
1708
  _context19.t0 = _context19["catch"](0);
1651
1709
  this.logError('更新订单定金状态失败:', _context19.t0);
1652
- _context19.next = 26;
1710
+ _context19.next = 27;
1653
1711
  return this.handleError(_context19.t0, CheckoutErrorType.ValidationFailed);
1654
- case 26:
1655
- throw _context19.t0;
1656
1712
  case 27:
1713
+ throw _context19.t0;
1714
+ case 28:
1657
1715
  case "end":
1658
1716
  return _context19.stop();
1659
1717
  }
1660
- }, _callee19, this, [[0, 21]]);
1718
+ }, _callee19, this, [[0, 22]]);
1661
1719
  }));
1662
1720
  function updateOrderDepositStatusAsync(_x18) {
1663
1721
  return _updateOrderDepositStatusAsync.apply(this, arguments);
@@ -1678,16 +1736,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1678
1736
  key: "setDepositAmountAsync",
1679
1737
  value: (function () {
1680
1738
  var _setDepositAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(depositAmount) {
1681
- var _this$store$currentOr7, _this$store$currentOr8;
1682
- var depositValue, totalAmount, formattedDepositAmount, oldDepositAmount, updateParams;
1739
+ var _this$store$currentOr9, _this$store$currentOr10;
1740
+ var depositValue, formattedDepositAmount, oldDepositAmount, updateParams;
1683
1741
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1684
1742
  while (1) switch (_context20.prev = _context20.next) {
1685
1743
  case 0:
1686
1744
  this.logInfo('setDepositAmountAsync called', {
1687
1745
  depositAmount: depositAmount,
1688
1746
  hasCurrentOrder: !!this.store.currentOrder,
1689
- currentOrderId: (_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.order_id,
1690
- currentTotalAmount: (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.total_amount
1747
+ currentOrderId: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.order_id,
1748
+ currentTotalAmount: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.total_amount
1691
1749
  });
1692
1750
  _context20.prev = 1;
1693
1751
  // 验证定金金额格式
@@ -1704,18 +1762,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1704
1762
  }
1705
1763
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法设置定金金额');
1706
1764
  case 7:
1707
- // 使用 Decimal.js 进行安全比较,检查定金金额是否超过订单总额
1708
- totalAmount = new Decimal(this.store.currentOrder.total_amount || '0');
1709
- if (!depositValue.gt(totalAmount)) {
1710
- _context20.next = 10;
1711
- break;
1712
- }
1713
- throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u5B9A\u91D1\u91D1\u989D ".concat(depositAmount, " \u4E0D\u80FD\u8D85\u8FC7\u8BA2\u5355\u603B\u989D ").concat(totalAmount.toFixed(2)));
1714
- case 10:
1715
1765
  formattedDepositAmount = depositValue.toFixed(2);
1716
1766
  oldDepositAmount = this.store.currentOrder.deposit_amount || '0.00'; // 如果定金金额没有变化,直接返回
1717
1767
  if (!(formattedDepositAmount === oldDepositAmount)) {
1718
- _context20.next = 15;
1768
+ _context20.next = 12;
1719
1769
  break;
1720
1770
  }
1721
1771
  this.logInfo('定金金额无变化,跳过更新:', {
@@ -1723,13 +1773,13 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1723
1773
  newAmount: formattedDepositAmount
1724
1774
  });
1725
1775
  return _context20.abrupt("return");
1726
- case 15:
1776
+ case 12:
1727
1777
  this.logInfo('开始设置订单定金金额:', {
1728
1778
  orderUuid: this.store.currentOrder.uuid,
1729
1779
  orderId: this.store.currentOrder.order_id,
1730
1780
  oldDepositAmount: oldDepositAmount,
1731
1781
  newDepositAmount: formattedDepositAmount,
1732
- totalAmount: totalAmount.toFixed(2)
1782
+ totalAmount: this.store.currentOrder.total_amount
1733
1783
  });
1734
1784
 
1735
1785
  // 准备更新参数
@@ -1747,9 +1797,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1747
1797
  }
1748
1798
 
1749
1799
  // 调用 Payment 模块更新订单
1750
- _context20.next = 20;
1800
+ _context20.next = 17;
1751
1801
  return this.payment.updateOrderAsync(this.store.currentOrder.uuid, updateParams);
1752
- case 20:
1802
+ case 17:
1753
1803
  // 更新本地缓存的订单对象
1754
1804
  this.store.currentOrder = _objectSpread(_objectSpread({}, this.store.currentOrder), updateParams);
1755
1805
 
@@ -1764,14 +1814,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1764
1814
  this.store.localOrderData.is_deposit = updateParams.is_deposit;
1765
1815
  }
1766
1816
  }
1817
+ this.updateStateAmountToRemaining(false);
1767
1818
 
1768
1819
  // 触发订单更新事件
1769
- _context20.next = 24;
1820
+ _context20.next = 22;
1770
1821
  return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
1771
1822
  order: this.store.currentOrder,
1772
1823
  timestamp: Date.now()
1773
1824
  });
1774
- case 24:
1825
+ case 22:
1775
1826
  this.logInfo('订单定金金额设置成功:', {
1776
1827
  orderUuid: this.store.currentOrder.uuid,
1777
1828
  orderId: this.store.currentOrder.order_id,
@@ -1780,21 +1831,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1780
1831
  isDeposit: this.store.currentOrder.is_deposit,
1781
1832
  totalAmount: this.store.currentOrder.total_amount
1782
1833
  });
1783
- _context20.next = 33;
1834
+ _context20.next = 31;
1784
1835
  break;
1785
- case 27:
1786
- _context20.prev = 27;
1836
+ case 25:
1837
+ _context20.prev = 25;
1787
1838
  _context20.t0 = _context20["catch"](1);
1788
1839
  this.logError('设置订单定金金额失败:', _context20.t0);
1789
- _context20.next = 32;
1840
+ _context20.next = 30;
1790
1841
  return this.handleError(_context20.t0, CheckoutErrorType.ValidationFailed);
1791
- case 32:
1842
+ case 30:
1792
1843
  throw _context20.t0;
1793
- case 33:
1844
+ case 31:
1794
1845
  case "end":
1795
1846
  return _context20.stop();
1796
1847
  }
1797
- }, _callee20, this, [[1, 27]]);
1848
+ }, _callee20, this, [[1, 25]]);
1798
1849
  }));
1799
1850
  function setDepositAmountAsync(_x19) {
1800
1851
  return _setDepositAmountAsync.apply(this, arguments);
@@ -1811,16 +1862,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1811
1862
  key: "manualSyncOrderAsync",
1812
1863
  value: (function () {
1813
1864
  var _manualSyncOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1814
- var _this$store$currentOr9, _this$store$currentOr10, _this$store$currentOr11;
1815
- var orderUuid, oldOrderId, syncResult, finalOrderId, finalIsVirtual, _this$store$currentOr12, errorMessage;
1865
+ var _this$store$currentOr11, _this$store$currentOr12, _this$store$currentOr13;
1866
+ var _this$store$currentOr14, orderUuid, oldOrderId, syncResult, finalOrderId, finalIsVirtual, newRes, _this$store$currentOr15, errorMessage;
1816
1867
  return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1817
1868
  while (1) switch (_context21.prev = _context21.next) {
1818
1869
  case 0:
1819
1870
  this.logInfo('manualSyncOrderAsync called', {
1820
1871
  hasCurrentOrder: !!this.store.currentOrder,
1821
- currentOrderId: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.order_id,
1822
- orderUuid: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.uuid,
1823
- totalAmount: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.total_amount,
1872
+ currentOrderId: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.order_id,
1873
+ orderUuid: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.uuid,
1874
+ totalAmount: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.total_amount,
1824
1875
  isOrderSynced: this.store.isOrderSynced,
1825
1876
  isVirtualOrderId: this.store.currentOrder ? isVirtualOrderId(this.store.currentOrder.order_id) : false
1826
1877
  });
@@ -1875,22 +1926,28 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1875
1926
  if (syncResult.orderId !== finalOrderId) {
1876
1927
  this.logError('[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!');
1877
1928
  }
1878
- return _context21.abrupt("return", syncResult);
1929
+ newRes = _objectSpread(_objectSpread({}, syncResult), {}, {
1930
+ is_deposit: ((_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.is_deposit) || 0
1931
+ });
1932
+ _context21.next = 27;
1933
+ return this.updateStateAmountToRemaining(false);
1879
1934
  case 27:
1880
- _context21.prev = 27;
1935
+ return _context21.abrupt("return", newRes);
1936
+ case 30:
1937
+ _context21.prev = 30;
1881
1938
  _context21.t6 = _context21["catch"](1);
1882
1939
  this.logError('手动同步订单失败:', _context21.t6);
1883
1940
  errorMessage = _context21.t6 instanceof Error ? _context21.t6.message : '同步失败';
1884
1941
  return _context21.abrupt("return", {
1885
1942
  success: false,
1886
1943
  message: "\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(errorMessage),
1887
- orderUuid: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.uuid
1944
+ orderUuid: (_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.uuid
1888
1945
  });
1889
- case 32:
1946
+ case 35:
1890
1947
  case "end":
1891
1948
  return _context21.stop();
1892
1949
  }
1893
- }, _callee21, this, [[1, 27]]);
1950
+ }, _callee21, this, [[1, 30]]);
1894
1951
  }));
1895
1952
  function manualSyncOrderAsync() {
1896
1953
  return _manualSyncOrderAsync.apply(this, arguments);
@@ -1961,15 +2018,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1961
2018
  key: "cancelCurrentOrderAsync",
1962
2019
  value: (function () {
1963
2020
  var _cancelCurrentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(cancelReason) {
1964
- var _this$store$currentOr13, _this$store$currentOr14, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
2021
+ var _this$store$currentOr16, _this$store$currentOr17, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
1965
2022
  return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1966
2023
  while (1) switch (_context22.prev = _context22.next) {
1967
2024
  case 0:
1968
2025
  _context22.prev = 0;
1969
2026
  this.logInfo('开始取消当前本地订单:', {
1970
2027
  hasCurrentOrder: !!this.store.currentOrder,
1971
- orderUuid: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.uuid,
1972
- orderId: (_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.order_id,
2028
+ orderUuid: (_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.uuid,
2029
+ orderId: (_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.order_id,
1973
2030
  isOrderSynced: this.store.isOrderSynced,
1974
2031
  cancelReason: cancelReason
1975
2032
  });
@@ -2080,7 +2137,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2080
2137
  key: "saveForLaterPaymentAsync",
2081
2138
  value: (function () {
2082
2139
  var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
2083
- var orderUuid, currentOrderId, allPaymentItems, syncResult, _this$store$currentOr15, errorMessage;
2140
+ var orderUuid, currentOrderId, allPaymentItems, syncResult, _this$store$currentOr18, errorMessage;
2084
2141
  return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2085
2142
  while (1) switch (_context23.prev = _context23.next) {
2086
2143
  case 0:
@@ -2134,7 +2191,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2134
2191
  return _context23.abrupt("return", {
2135
2192
  success: false,
2136
2193
  message: "\u8BA2\u5355\u4FDD\u5B58\u5931\u8D25: ".concat(errorMessage),
2137
- orderUuid: (_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.uuid
2194
+ orderUuid: (_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.uuid
2138
2195
  });
2139
2196
  case 21:
2140
2197
  case "end":
@@ -2157,7 +2214,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2157
2214
  key: "updateOrderNoteAsync",
2158
2215
  value: (function () {
2159
2216
  var _updateOrderNoteAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(note) {
2160
- var _this$store$currentOr16, _this$store$currentOr17, oldNote, orderInPayment;
2217
+ var _this$store$currentOr19, _this$store$currentOr20, oldNote, orderInPayment;
2161
2218
  return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2162
2219
  while (1) switch (_context24.prev = _context24.next) {
2163
2220
  case 0:
@@ -2169,7 +2226,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2169
2226
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '没有本地订单数据,无法更新备注');
2170
2227
  case 3:
2171
2228
  console.log('[Checkout] 更新订单备注:', {
2172
- orderUuid: (_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.uuid,
2229
+ orderUuid: (_this$store$currentOr19 = this.store.currentOrder) === null || _this$store$currentOr19 === void 0 ? void 0 : _this$store$currentOr19.uuid,
2173
2230
  oldNote: this.store.localOrderData.shop_note,
2174
2231
  newNote: note
2175
2232
  });
@@ -2202,7 +2259,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2202
2259
  case 17:
2203
2260
  _context24.next = 19;
2204
2261
  return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
2205
- orderUuid: (_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.uuid,
2262
+ orderUuid: (_this$store$currentOr20 = this.store.currentOrder) === null || _this$store$currentOr20 === void 0 ? void 0 : _this$store$currentOr20.uuid,
2206
2263
  oldNote: oldNote,
2207
2264
  newNote: note,
2208
2265
  timestamp: Date.now()
@@ -2274,7 +2331,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2274
2331
  key: "handlePaymentSuccess",
2275
2332
  value: (function () {
2276
2333
  var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(data) {
2277
- var _this$store$currentOr18;
2334
+ var _this$store$currentOr21;
2278
2335
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2279
2336
  while (1) switch (_context26.prev = _context26.next) {
2280
2337
  case 0:
@@ -2285,7 +2342,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2285
2342
  return this.core.effects.emit(CheckoutHooks.OnPaymentSuccess, {
2286
2343
  orderUuid: data.orderUuid,
2287
2344
  paymentMethodCode: '',
2288
- amount: ((_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.total_amount) || '0',
2345
+ amount: ((_this$store$currentOr21 = this.store.currentOrder) === null || _this$store$currentOr21 === void 0 ? void 0 : _this$store$currentOr21.total_amount) || '0',
2289
2346
  timestamp: data.timestamp
2290
2347
  });
2291
2348
  case 4:
@@ -2310,7 +2367,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2310
2367
  key: "handlePaymentError",
2311
2368
  value: (function () {
2312
2369
  var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(data) {
2313
- var _this$store$currentOr19;
2370
+ var _this$store$currentOr22;
2314
2371
  var error;
2315
2372
  return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2316
2373
  while (1) switch (_context27.prev = _context27.next) {
@@ -2323,7 +2380,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2323
2380
  return this.core.effects.emit(CheckoutHooks.OnPaymentFailed, {
2324
2381
  orderUuid: data.orderUuid,
2325
2382
  paymentMethodCode: '',
2326
- amount: ((_this$store$currentOr19 = this.store.currentOrder) === null || _this$store$currentOr19 === void 0 ? void 0 : _this$store$currentOr19.total_amount) || '0',
2383
+ amount: ((_this$store$currentOr22 = this.store.currentOrder) === null || _this$store$currentOr22 === void 0 ? void 0 : _this$store$currentOr22.total_amount) || '0',
2327
2384
  timestamp: data.timestamp
2328
2385
  });
2329
2386
  case 5:
@@ -2743,7 +2800,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2743
2800
  key: "calculateRemainingAmountAsync",
2744
2801
  value: (function () {
2745
2802
  var _calculateRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2746
- var totalAmount, paidAmountStr, paidAmount, remainingAmount, result;
2803
+ var totalAmount, currentOrder, paidAmountStr, paidAmount, remainingAmount, result;
2747
2804
  return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2748
2805
  while (1) switch (_context32.prev = _context32.next) {
2749
2806
  case 0:
@@ -2757,15 +2814,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2757
2814
  // 使用 Decimal.js 进行安全的金额计算
2758
2815
  totalAmount = new Decimal(this.store.currentOrder.total_amount || '0');
2759
2816
  _context32.next = 6;
2760
- return this.calculatePaidAmountAsync();
2817
+ return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
2761
2818
  case 6:
2819
+ currentOrder = _context32.sent;
2820
+ if (currentOrder !== null && currentOrder !== void 0 && currentOrder.is_deposit && currentOrder !== null && currentOrder !== void 0 && currentOrder.deposit_amount && Number(currentOrder === null || currentOrder === void 0 ? void 0 : currentOrder.deposit_amount) > 0) {
2821
+ totalAmount = new Decimal(currentOrder === null || currentOrder === void 0 ? void 0 : currentOrder.deposit_amount);
2822
+ }
2823
+ _context32.next = 10;
2824
+ return this.calculatePaidAmountAsync();
2825
+ case 10:
2762
2826
  paidAmountStr = _context32.sent;
2763
2827
  paidAmount = new Decimal(paidAmountStr);
2764
2828
  remainingAmount = totalAmount.sub(paidAmount); // 确保剩余金额不为负数
2765
2829
  result = Decimal.max(0, remainingAmount).toFixed(2);
2766
2830
  this.logInfo('calculateRemainingAmountAsync: 计算=', result);
2767
2831
  return _context32.abrupt("return", result);
2768
- case 12:
2832
+ case 16:
2769
2833
  case "end":
2770
2834
  return _context32.stop();
2771
2835
  }
@@ -2846,6 +2910,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2846
2910
  value: (function () {
2847
2911
  var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
2848
2912
  var checkOrder,
2913
+ _this$store$currentOr23,
2914
+ _this$store$currentOr24,
2915
+ _this$store$currentOr25,
2916
+ paymentItems,
2917
+ depositPaidAmount,
2918
+ _this$store$currentOr26,
2849
2919
  remainingAmount,
2850
2920
  currentStateAmount,
2851
2921
  _args34 = arguments;
@@ -2854,9 +2924,40 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2854
2924
  case 0:
2855
2925
  checkOrder = _args34.length > 0 && _args34[0] !== undefined ? _args34[0] : true;
2856
2926
  _context34.prev = 1;
2857
- _context34.next = 4;
2927
+ if (!(((_this$store$currentOr23 = this.store.currentOrder) === null || _this$store$currentOr23 === void 0 ? void 0 : _this$store$currentOr23.is_deposit) === 1)) {
2928
+ _context34.next = 11;
2929
+ break;
2930
+ }
2931
+ _context34.next = 5;
2932
+ return this.payment.getPaymentItemsAsync((_this$store$currentOr24 = this.store.currentOrder) === null || _this$store$currentOr24 === void 0 ? void 0 : _this$store$currentOr24.uuid);
2933
+ case 5:
2934
+ paymentItems = _context34.sent;
2935
+ depositPaidAmount = paymentItems.filter(function (item) {
2936
+ return item.order_payment_type === 'deposit' && item.status !== 'voided';
2937
+ }).reduce(function (sum, item) {
2938
+ // 如果是 wallet,并且还没同步到后端,则不计入这一部分金额
2939
+ if (item.voucher_id && !item.isSynced) {
2940
+ return sum;
2941
+ }
2942
+ var amount = new Decimal(item.amount || '0');
2943
+ var roundingAmount = new Decimal(item.rounding_amount || '0');
2944
+ return sum.add(amount.add(roundingAmount.abs()));
2945
+ }, new Decimal(0));
2946
+ if (!depositPaidAmount.gte((_this$store$currentOr25 = this.store.currentOrder) === null || _this$store$currentOr25 === void 0 ? void 0 : _this$store$currentOr25.deposit_amount)) {
2947
+ _context34.next = 11;
2948
+ break;
2949
+ }
2950
+ this.store.currentOrder = _objectSpread(_objectSpread({}, this.store.currentOrder), {}, {
2951
+ is_deposit: 0
2952
+ });
2953
+ _context34.next = 11;
2954
+ return this.payment.updateOrderAsync((_this$store$currentOr26 = this.store.currentOrder) === null || _this$store$currentOr26 === void 0 ? void 0 : _this$store$currentOr26.uuid, {
2955
+ is_deposit: 0
2956
+ });
2957
+ case 11:
2958
+ _context34.next = 13;
2858
2959
  return this.calculateRemainingAmountAsync();
2859
- case 4:
2960
+ case 13:
2860
2961
  remainingAmount = _context34.sent;
2861
2962
  currentStateAmount = this.store.stateAmount; // 只有当剩余金额与当前 stateAmount 不同时才更新
2862
2963
  if (remainingAmount !== currentStateAmount) {
@@ -2878,34 +2979,33 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2878
2979
  remainingAmount: remainingAmount
2879
2980
  });
2880
2981
  }
2881
-
2882
2982
  // 同步更新系统内部的 balanceDueAmount
2883
- _context34.next = 9;
2983
+ _context34.next = 18;
2884
2984
  return this.updateBalanceDueAmount();
2885
- case 9:
2985
+ case 18:
2886
2986
  if (!checkOrder) {
2887
- _context34.next = 14;
2987
+ _context34.next = 23;
2888
2988
  break;
2889
2989
  }
2890
- _context34.next = 12;
2990
+ _context34.next = 21;
2891
2991
  return this.checkOrderPaymentCompletion();
2892
- case 12:
2893
- _context34.next = 15;
2992
+ case 21:
2993
+ _context34.next = 24;
2894
2994
  break;
2895
- case 14:
2995
+ case 23:
2896
2996
  this.logInfo('外部传入无需 checkOrder,不执行订单支付完成检测和同步');
2897
- case 15:
2898
- _context34.next = 20;
2997
+ case 24:
2998
+ _context34.next = 29;
2899
2999
  break;
2900
- case 17:
2901
- _context34.prev = 17;
3000
+ case 26:
3001
+ _context34.prev = 26;
2902
3002
  _context34.t0 = _context34["catch"](1);
2903
3003
  this.logError('更新 stateAmount 为剩余金额失败:', _context34.t0);
2904
- case 20:
3004
+ case 29:
2905
3005
  case "end":
2906
3006
  return _context34.stop();
2907
3007
  }
2908
- }, _callee34, this, [[1, 17]]);
3008
+ }, _callee34, this, [[1, 26]]);
2909
3009
  }));
2910
3010
  function updateStateAmountToRemaining() {
2911
3011
  return _updateStateAmountToRemaining.apply(this, arguments);
@@ -3051,10 +3151,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3051
3151
  value: (function () {
3052
3152
  var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
3053
3153
  var _this4 = this,
3054
- _this$store$currentOr20,
3055
- _this$store$currentOr21,
3154
+ _this$store$currentOr27,
3155
+ _this$store$currentOr28,
3056
3156
  _this$store$currentCu2,
3057
- _this$store$currentOr22,
3157
+ _this$store$currentOr29,
3158
+ _this$store$localOrde,
3159
+ _this$store$localOrde2,
3058
3160
  _checkoutResponse3,
3059
3161
  _checkoutResponse4;
3060
3162
  var isManual,
@@ -3065,10 +3167,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3065
3167
  processedPaymentItems,
3066
3168
  finalDepositAmount,
3067
3169
  manualDepositAmount,
3068
- depositPaymentItems,
3069
- calculatedDepositAmount,
3070
3170
  manualDepositValue,
3071
- calculatedDepositValue,
3072
3171
  orderParams,
3073
3172
  startTime,
3074
3173
  checkoutResponse,
@@ -3137,47 +3236,26 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3137
3236
  })
3138
3237
  });
3139
3238
  }); // 确定最终的定金金额:优先使用手动设置的值,否则从支付项中计算
3140
- manualDepositAmount = ((_this$store$currentOr20 = this.store.currentOrder) === null || _this$store$currentOr20 === void 0 ? void 0 : _this$store$currentOr20.deposit_amount) || '0.00'; // 计算定金支付项的总金额(order_payment_type="deposit")
3141
- depositPaymentItems = processedPaymentItems.filter(function (item) {
3142
- return item.order_payment_type === 'deposit' && item.status !== 'voided';
3143
- });
3144
- calculatedDepositAmount = depositPaymentItems.reduce(function (sum, item) {
3145
- var amount = new Decimal(item.amount || '0');
3146
- var roundingAmount = new Decimal(item.rounding_amount || '0');
3147
- // 包含抹零计算的有效支付金额
3148
- var effectiveAmount = amount.add(roundingAmount.abs());
3149
- return sum.add(effectiveAmount);
3150
- }, new Decimal(0)).toFixed(2); // 优先级逻辑:手动设置的定金金额 > 从支付项计算的金额
3239
+ manualDepositAmount = ((_this$store$currentOr27 = this.store.currentOrder) === null || _this$store$currentOr27 === void 0 ? void 0 : _this$store$currentOr27.deposit_amount) || '0.00'; // 优先级逻辑:手动设置的定金金额 > 从支付项计算的金额
3151
3240
  manualDepositValue = new Decimal(manualDepositAmount);
3152
- calculatedDepositValue = new Decimal(calculatedDepositAmount);
3153
3241
  if (manualDepositValue.gt(0)) {
3154
3242
  // 如果手动设置了定金金额且大于0,使用手动设置的值
3155
3243
  finalDepositAmount = manualDepositAmount;
3156
3244
  this.logInfo('使用手动设置的定金金额', {
3157
3245
  manualDepositAmount: manualDepositAmount,
3158
- calculatedDepositAmount: calculatedDepositAmount,
3159
3246
  reason: '用户通过setDepositAmountAsync手动设置了定金金额'
3160
3247
  });
3161
- } else if (calculatedDepositValue.gt(0)) {
3162
- // 如果没有手动设置但有定金类型的支付项,使用计算值
3163
- finalDepositAmount = calculatedDepositAmount;
3164
- this.logInfo('使用从支付项计算的定金金额', {
3165
- manualDepositAmount: manualDepositAmount,
3166
- calculatedDepositAmount: calculatedDepositAmount,
3167
- reason: '未手动设置定金金额,从定金类型支付项计算得出'
3168
- });
3169
3248
  } else {
3170
3249
  // 都为0,使用0
3171
3250
  finalDepositAmount = '0.00';
3172
3251
  this.logInfo('定金金额为0', {
3173
3252
  manualDepositAmount: manualDepositAmount,
3174
- calculatedDepositAmount: calculatedDepositAmount,
3175
3253
  reason: '手动设置和计算值均为0'
3176
3254
  });
3177
3255
  }
3178
3256
  this.logInfo('定金金额确定结果', {
3179
- depositPaymentItemsCount: depositPaymentItems.length,
3180
- depositPaymentItems: depositPaymentItems.map(function (item) {
3257
+ depositPaymentItemsCount: processedPaymentItems.length,
3258
+ depositPaymentItems: processedPaymentItems.map(function (item) {
3181
3259
  return {
3182
3260
  uuid: item.uuid,
3183
3261
  code: item.code,
@@ -3188,9 +3266,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3188
3266
  };
3189
3267
  }),
3190
3268
  manualDepositAmount: manualDepositAmount,
3191
- calculatedDepositAmount: calculatedDepositAmount,
3192
3269
  finalDepositAmount: finalDepositAmount,
3193
- isDeposit: ((_this$store$currentOr21 = this.store.currentOrder) === null || _this$store$currentOr21 === void 0 ? void 0 : _this$store$currentOr21.is_deposit) || 0
3270
+ isDeposit: ((_this$store$currentOr28 = this.store.currentOrder) === null || _this$store$currentOr28 === void 0 ? void 0 : _this$store$currentOr28.is_deposit) || 0
3194
3271
  });
3195
3272
 
3196
3273
  // 构造订单参数,直接使用 localOrderData 中已处理好的数据
@@ -3212,11 +3289,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3212
3289
  currency_code: this.otherParams.currency_code,
3213
3290
  currency_symbol: this.otherParams.currency_symbol,
3214
3291
  currency_format: this.otherParams.currency_format,
3215
- is_deposit: ((_this$store$currentOr22 = this.store.currentOrder) === null || _this$store$currentOr22 === void 0 ? void 0 : _this$store$currentOr22.is_deposit) || 0,
3292
+ is_deposit: ((_this$store$currentOr29 = this.store.currentOrder) !== null && _this$store$currentOr29 !== void 0 && _this$store$currentOr29.is_deposit || Number(finalDepositAmount) > 0 ? 1 : 0) || 0,
3216
3293
  deposit_amount: finalDepositAmount,
3217
3294
  // 使用最终确定的定金金额(手动设置优先)
3218
3295
  product_tax_fee: this.store.localOrderData.tax_fee,
3219
- note: this.store.localOrderData.shop_note
3296
+ note: this.store.localOrderData.shop_note,
3297
+ bookings: (_this$store$localOrde = this.store.localOrderData.bookings) === null || _this$store$localOrde === void 0 ? void 0 : _this$store$localOrde.map(function (item) {
3298
+ return _objectSpread(_objectSpread({}, item), {}, {
3299
+ product: _objectSpread(_objectSpread({}, item.product), {}, {
3300
+ custom_deposit_data: undefined
3301
+ }),
3302
+ deposit: undefined
3303
+ });
3304
+ }),
3305
+ relation_products: (_this$store$localOrde2 = this.store.localOrderData.relation_products) === null || _this$store$localOrde2 === void 0 ? void 0 : _this$store$localOrde2.map(function (item) {
3306
+ return _objectSpread(_objectSpread({}, item), {}, {
3307
+ custom_deposit_data: undefined,
3308
+ deposit: undefined
3309
+ });
3310
+ })
3220
3311
  }); // 如果是更新操作,需要在参数中包含真实的订单ID
3221
3312
  if (isUpdateOperation) {
3222
3313
  // 如果当前订单ID是虚拟ID,但订单已同步过,可能存在数据不一致的问题
@@ -3229,7 +3320,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3229
3320
 
3230
3321
  // 发送下单接口请求开始事件
3231
3322
  startTime = Date.now();
3232
- _context36.next = 27;
3323
+ _context36.next = 24;
3233
3324
  return this.core.effects.emit(CheckoutHooks.OnOrderSubmitStart, {
3234
3325
  orderUuid: this.store.currentOrder.uuid,
3235
3326
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3237,9 +3328,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3237
3328
  paymentItemCount: paymentItems.length,
3238
3329
  timestamp: startTime
3239
3330
  });
3240
- case 27:
3331
+ case 24:
3241
3332
  submitSuccess = false;
3242
- _context36.prev = 28;
3333
+ _context36.prev = 25;
3243
3334
  // 记录接口调用参数
3244
3335
  this.logInfo('Calling backend checkout API', _objectSpread({
3245
3336
  url: '/order/checkout',
@@ -3247,23 +3338,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3247
3338
  }, orderParams));
3248
3339
 
3249
3340
  // 调用 Order 模块的专用 createOrderByCheckout 方法
3250
- _context36.next = 32;
3341
+ _context36.next = 29;
3251
3342
  return this.order.createOrderByCheckout(orderParams);
3252
- case 32:
3343
+ case 29:
3253
3344
  checkoutResponse = _context36.sent;
3254
3345
  submitSuccess = true;
3255
3346
  this.logInfo('下单接口调用成功', checkoutResponse);
3256
- _context36.next = 45;
3347
+ _context36.next = 42;
3257
3348
  break;
3258
- case 37:
3259
- _context36.prev = 37;
3260
- _context36.t1 = _context36["catch"](28);
3349
+ case 34:
3350
+ _context36.prev = 34;
3351
+ _context36.t1 = _context36["catch"](25);
3261
3352
  submitSuccess = false;
3262
3353
  submitError = _context36.t1 instanceof Error ? _context36.t1.message : String(_context36.t1);
3263
3354
  this.logError('下单接口调用失败:', submitError);
3264
3355
 
3265
3356
  // 发送订单同步失败事件(网络错误或请求失败)
3266
- _context36.next = 44;
3357
+ _context36.next = 41;
3267
3358
  return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
3268
3359
  orderUuid: this.store.currentOrder.uuid,
3269
3360
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3273,11 +3364,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3273
3364
  duration: Date.now() - startTime,
3274
3365
  timestamp: Date.now()
3275
3366
  });
3276
- case 44:
3367
+ case 41:
3277
3368
  throw _context36.t1;
3278
- case 45:
3279
- _context36.prev = 45;
3280
- _context36.next = 48;
3369
+ case 42:
3370
+ _context36.prev = 42;
3371
+ _context36.next = 45;
3281
3372
  return this.core.effects.emit(CheckoutHooks.OnOrderSubmitEnd, {
3282
3373
  success: submitSuccess,
3283
3374
  orderUuid: this.store.currentOrder.uuid,
@@ -3288,18 +3379,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3288
3379
  duration: Date.now() - startTime,
3289
3380
  timestamp: Date.now()
3290
3381
  });
3291
- case 48:
3292
- return _context36.finish(45);
3293
- case 49:
3382
+ case 45:
3383
+ return _context36.finish(42);
3384
+ case 46:
3294
3385
  // 检查响应状态是否为成功状态
3295
3386
  responseStatus = (_checkoutResponse3 = checkoutResponse) === null || _checkoutResponse3 === void 0 ? void 0 : _checkoutResponse3.status;
3296
3387
  isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse4 = checkoutResponse) === null || _checkoutResponse4 === void 0 ? void 0 : _checkoutResponse4.code) === 200;
3297
3388
  if (isSuccessResponse) {
3298
- _context36.next = 56;
3389
+ _context36.next = 53;
3299
3390
  break;
3300
3391
  }
3301
3392
  errorMessage = ((_checkoutResponse5 = checkoutResponse) === null || _checkoutResponse5 === void 0 ? void 0 : _checkoutResponse5.message) || '订单同步失败,后端返回非成功状态'; // 发送订单同步失败事件
3302
- _context36.next = 55;
3393
+ _context36.next = 52;
3303
3394
  return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
3304
3395
  orderUuid: this.store.currentOrder.uuid,
3305
3396
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3310,18 +3401,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3310
3401
  duration: Date.now() - startTime,
3311
3402
  timestamp: Date.now()
3312
3403
  });
3313
- case 55:
3404
+ case 52:
3314
3405
  throw new Error(errorMessage);
3315
- case 56:
3406
+ case 53:
3316
3407
  if (!isUpdateOperation) {
3317
- _context36.next = 60;
3408
+ _context36.next = 57;
3318
3409
  break;
3319
3410
  }
3320
3411
  // 更新操作:使用现有的订单ID
3321
3412
  realOrderId = currentOrderId;
3322
- _context36.next = 79;
3413
+ _context36.next = 76;
3323
3414
  break;
3324
- case 60:
3415
+ case 57:
3325
3416
  // 创建操作:从响应中提取新的订单ID
3326
3417
  extractedOrderId = (_checkoutResponse6 = checkoutResponse) === null || _checkoutResponse6 === void 0 || (_checkoutResponse6 = _checkoutResponse6.data) === null || _checkoutResponse6 === void 0 ? void 0 : _checkoutResponse6.order_id; // 如果data.order_id不存在,尝试直接从根级获取
3327
3418
  if (!extractedOrderId) {
@@ -3343,10 +3434,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3343
3434
  oldOrderId: this.store.currentOrder.order_id,
3344
3435
  newOrderId: realOrderId
3345
3436
  });
3346
- _context36.prev = 66;
3347
- _context36.next = 69;
3437
+ _context36.prev = 63;
3438
+ _context36.next = 66;
3348
3439
  return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, realOrderId);
3349
- case 69:
3440
+ case 66:
3350
3441
  updatedOrder = _context36.sent;
3351
3442
  this.logInfo('Payment模块替换订单ID结果:', {
3352
3443
  wasSuccessful: !!updatedOrder,
@@ -3373,66 +3464,66 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3373
3464
  目标ID: realOrderId
3374
3465
  });
3375
3466
  }
3376
- _context36.next = 79;
3467
+ _context36.next = 76;
3377
3468
  break;
3378
- case 74:
3379
- _context36.prev = 74;
3380
- _context36.t2 = _context36["catch"](66);
3469
+ case 71:
3470
+ _context36.prev = 71;
3471
+ _context36.t2 = _context36["catch"](63);
3381
3472
  this.logError('调用Payment模块替换订单ID时发生错误:', _context36.t2);
3382
3473
 
3383
3474
  // 发生错误时也进行手动替换
3384
3475
  this.store.currentOrder.order_id = realOrderId;
3385
3476
  this.logInfo('错误恢复:手动设置订单ID:', realOrderId);
3386
- case 79:
3387
- _context36.prev = 79;
3477
+ case 76:
3478
+ _context36.prev = 76;
3388
3479
  syncedPaymentUuids = processedPaymentItems.filter(function (item) {
3389
3480
  return item.status !== 'voided';
3390
3481
  }).map(function (item) {
3391
3482
  return item.uuid;
3392
3483
  }).filter(Boolean);
3393
3484
  _iterator3 = _createForOfIteratorHelper(syncedPaymentUuids);
3394
- _context36.prev = 82;
3485
+ _context36.prev = 79;
3395
3486
  _iterator3.s();
3396
- case 84:
3487
+ case 81:
3397
3488
  if ((_step3 = _iterator3.n()).done) {
3398
- _context36.next = 90;
3489
+ _context36.next = 87;
3399
3490
  break;
3400
3491
  }
3401
3492
  paymentUuid = _step3.value;
3402
- _context36.next = 88;
3493
+ _context36.next = 85;
3403
3494
  return this.payment.updatePaymentAsync(this.store.currentOrder.uuid, paymentUuid, {
3404
3495
  isSynced: true,
3405
3496
  syncError: undefined
3406
3497
  });
3407
- case 88:
3408
- _context36.next = 84;
3498
+ case 85:
3499
+ _context36.next = 81;
3409
3500
  break;
3410
- case 90:
3411
- _context36.next = 95;
3501
+ case 87:
3502
+ _context36.next = 92;
3412
3503
  break;
3504
+ case 89:
3505
+ _context36.prev = 89;
3506
+ _context36.t3 = _context36["catch"](79);
3507
+ _iterator3.e(_context36.t3);
3413
3508
  case 92:
3414
3509
  _context36.prev = 92;
3415
- _context36.t3 = _context36["catch"](82);
3416
- _iterator3.e(_context36.t3);
3417
- case 95:
3418
- _context36.prev = 95;
3419
3510
  _iterator3.f();
3420
- return _context36.finish(95);
3421
- case 98:
3422
- _context36.next = 103;
3511
+ return _context36.finish(92);
3512
+ case 95:
3513
+ _context36.next = 100;
3423
3514
  break;
3424
- case 100:
3425
- _context36.prev = 100;
3426
- _context36.t4 = _context36["catch"](79);
3515
+ case 97:
3516
+ _context36.prev = 97;
3517
+ _context36.t4 = _context36["catch"](76);
3427
3518
  this.logWarning('标记支付项已同步失败(不阻塞主流程)', {
3428
3519
  error: _context36.t4
3429
3520
  });
3430
- case 103:
3521
+ case 100:
3431
3522
  // 标记订单已同步
3432
3523
  this.store.isOrderSynced = true;
3433
3524
 
3434
3525
  // 触发订单同步完成事件
3435
- _context36.next = 106;
3526
+ _context36.next = 103;
3436
3527
  return this.core.effects.emit(CheckoutHooks.OnOrderSynced, {
3437
3528
  orderUuid: this.store.currentOrder.uuid,
3438
3529
  realOrderId: realOrderId,
@@ -3441,18 +3532,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3441
3532
  isManual: isManual,
3442
3533
  response: checkoutResponse
3443
3534
  });
3444
- case 106:
3535
+ case 103:
3445
3536
  return _context36.abrupt("return", {
3446
3537
  success: true,
3447
3538
  orderId: realOrderId,
3448
3539
  orderUuid: this.store.currentOrder.uuid,
3449
3540
  response: checkoutResponse
3450
3541
  });
3451
- case 107:
3542
+ case 104:
3452
3543
  case "end":
3453
3544
  return _context36.stop();
3454
3545
  }
3455
- }, _callee36, this, [[28, 37, 45, 49], [66, 74], [79, 100], [82, 92, 95, 98]]);
3546
+ }, _callee36, this, [[25, 34, 42, 46], [63, 71], [76, 97], [79, 89, 92, 95]]);
3456
3547
  }));
3457
3548
  function syncOrderToBackendWithReturn() {
3458
3549
  return _syncOrderToBackendWithReturn.apply(this, arguments);