@pisell/pisellos 2.1.10 → 2.1.12

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.
@@ -403,13 +403,19 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
403
403
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
404
404
  while (1) switch (_context8.prev = _context8.next) {
405
405
  case 0:
406
+ this.logInfo('initWalletData called', {
407
+ params: params
408
+ });
406
409
  amountInfo = (_this$store$currentOr3 = this.store.currentOrder) === null || _this$store$currentOr3 === void 0 || (_this$store$currentOr3 = _this$store$currentOr3.order_info) === null || _this$store$currentOr3 === void 0 ? void 0 : _this$store$currentOr3.amount_breakdown;
407
410
  if (amountInfo) {
408
- _context8.next = 3;
411
+ _context8.next = 5;
409
412
  break;
410
413
  }
414
+ this.logInfo('initWalletData amountInfo not found', {
415
+ params: params
416
+ });
411
417
  return _context8.abrupt("return");
412
- case 3:
418
+ case 5:
413
419
  // 准备钱包初始化的业务数据
414
420
  walletBusinessData = _objectSpread({
415
421
  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,
@@ -419,16 +425,28 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
419
425
  },
420
426
  products: this.getProductListByOrder()
421
427
  }, params);
422
- _context8.next = 6;
428
+ this.logInfo('开始拉取:initializeWalletDataFromBusinessAsync', {
429
+ walletBusinessData: walletBusinessData
430
+ });
431
+ _context8.next = 9;
423
432
  return this.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
424
- case 6:
433
+ case 9:
434
+ this.logInfo('调用结束:initializeWalletDataFromBusinessAsync', {
435
+ walletBusinessData: walletBusinessData
436
+ });
437
+
438
+ // 因为上面是接口 这里最好检查一下还有没有 currentOrder 了,如果没有,则不触发事件
425
439
  if (this.store.currentOrder) {
426
- _context8.next = 8;
440
+ _context8.next = 12;
427
441
  break;
428
442
  }
429
443
  return _context8.abrupt("return");
430
- case 8:
431
- _context8.next = 10;
444
+ case 12:
445
+ this.logInfo('initWalletData currentOrder found', {
446
+ currentOrder: this.store.currentOrder
447
+ });
448
+ // 触发钱包数据初始化完成事件
449
+ _context8.next = 15;
432
450
  return this.core.effects.emit(CheckoutHooks.OnWalletDataInitialized, {
433
451
  orderUuid: (_this$store$currentOr4 = this.store.currentOrder) === null || _this$store$currentOr4 === void 0 ? void 0 : _this$store$currentOr4.uuid,
434
452
  customerId: walletBusinessData.customer_id,
@@ -439,7 +457,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
439
457
  },
440
458
  timestamp: Date.now()
441
459
  });
442
- case 10:
460
+ case 15:
443
461
  case "end":
444
462
  return _context8.stop();
445
463
  }
@@ -540,7 +558,6 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
540
558
  case 21:
541
559
  paymentOrder = _context9.sent;
542
560
  this.store.currentOrder = paymentOrder;
543
- this.initWalletData();
544
561
 
545
562
  // 如果设置了自动支付,直接跳转到支付步骤
546
563
  if (params.autoPayment) {
@@ -552,9 +569,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
552
569
  });
553
570
 
554
571
  // 自动设置 stateAmount 为剩余未支付金额
555
- _context9.next = 28;
572
+ _context9.next = 27;
556
573
  return this.updateStateAmountToRemaining();
557
- case 28:
574
+ case 27:
558
575
  this.logInfo('本地订单创建成功:', {
559
576
  localOrderId: localOrderId,
560
577
  uuid: paymentOrder.uuid,
@@ -563,6 +580,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
563
580
  taxAmount: amountInfo.taxAmount,
564
581
  stateAmount: this.store.stateAmount
565
582
  });
583
+ this.initWalletData();
566
584
  return _context9.abrupt("return", paymentOrder);
567
585
  case 32:
568
586
  _context9.prev = 32;
@@ -570,12 +588,13 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
570
588
  _context9.next = 36;
571
589
  return this.handleError(_context9.t0, CheckoutErrorType.OrderCreationFailed);
572
590
  case 36:
591
+ this.logError('本地订单创建失败:', _context9.t0);
573
592
  this.core.effects.emit(CheckoutHooks.OnOrderCreationFailed, {
574
593
  error: this.store.lastError,
575
594
  timestamp: Date.now()
576
595
  });
577
596
  throw _context9.t0;
578
- case 38:
597
+ case 39:
579
598
  case "end":
580
599
  return _context9.stop();
581
600
  }
@@ -1447,6 +1466,143 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1447
1466
  }
1448
1467
  return updateOrderDepositStatusAsync;
1449
1468
  }()
1469
+ /**
1470
+ * 手动设置当前订单的定金金额
1471
+ *
1472
+ * 允许手动设置订单的定金金额,通常用于用户自定义定金支付场景
1473
+ *
1474
+ * @param depositAmount 定金金额,必须是有效的数字字符串,且不能超过订单总额
1475
+ * @throws 当前没有活跃订单时抛出错误
1476
+ * @throws 定金金额格式无效或超过订单总额时抛出错误
1477
+ */
1478
+ )
1479
+ }, {
1480
+ key: "setDepositAmountAsync",
1481
+ value: (function () {
1482
+ var _setDepositAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(depositAmount) {
1483
+ var _this$store$currentOr6, _this$store$currentOr7;
1484
+ var depositValue, totalAmount, formattedDepositAmount, oldDepositAmount, updateParams;
1485
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1486
+ while (1) switch (_context19.prev = _context19.next) {
1487
+ case 0:
1488
+ this.logInfo('setDepositAmountAsync called', {
1489
+ depositAmount: depositAmount,
1490
+ hasCurrentOrder: !!this.store.currentOrder,
1491
+ currentOrderId: (_this$store$currentOr6 = this.store.currentOrder) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.order_id,
1492
+ currentTotalAmount: (_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.total_amount
1493
+ });
1494
+ _context19.prev = 1;
1495
+ // 验证定金金额格式
1496
+ depositValue = new Decimal(depositAmount);
1497
+ if (!(depositValue.isNaN() || depositValue.lt(0))) {
1498
+ _context19.next = 5;
1499
+ break;
1500
+ }
1501
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u65E0\u6548\u7684\u5B9A\u91D1\u91D1\u989D\u683C\u5F0F: ".concat(depositAmount));
1502
+ case 5:
1503
+ if (this.store.currentOrder) {
1504
+ _context19.next = 7;
1505
+ break;
1506
+ }
1507
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法设置定金金额');
1508
+ case 7:
1509
+ // 使用 Decimal.js 进行安全比较,检查定金金额是否超过订单总额
1510
+ totalAmount = new Decimal(this.store.currentOrder.total_amount || '0');
1511
+ if (!depositValue.gt(totalAmount)) {
1512
+ _context19.next = 10;
1513
+ break;
1514
+ }
1515
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u5B9A\u91D1\u91D1\u989D ".concat(depositAmount, " \u4E0D\u80FD\u8D85\u8FC7\u8BA2\u5355\u603B\u989D ").concat(totalAmount.toFixed(2)));
1516
+ case 10:
1517
+ formattedDepositAmount = depositValue.toFixed(2);
1518
+ oldDepositAmount = this.store.currentOrder.deposit_amount || '0.00'; // 如果定金金额没有变化,直接返回
1519
+ if (!(formattedDepositAmount === oldDepositAmount)) {
1520
+ _context19.next = 15;
1521
+ break;
1522
+ }
1523
+ this.logInfo('定金金额无变化,跳过更新:', {
1524
+ currentAmount: oldDepositAmount,
1525
+ newAmount: formattedDepositAmount
1526
+ });
1527
+ return _context19.abrupt("return");
1528
+ case 15:
1529
+ this.logInfo('开始设置订单定金金额:', {
1530
+ orderUuid: this.store.currentOrder.uuid,
1531
+ orderId: this.store.currentOrder.order_id,
1532
+ oldDepositAmount: oldDepositAmount,
1533
+ newDepositAmount: formattedDepositAmount,
1534
+ totalAmount: totalAmount.toFixed(2)
1535
+ });
1536
+
1537
+ // 准备更新参数
1538
+ updateParams = {
1539
+ deposit_amount: formattedDepositAmount
1540
+ }; // 如果设置的定金金额大于0,自动将订单标记为定金订单
1541
+ if (depositValue.gt(0) && this.store.currentOrder.is_deposit !== 1) {
1542
+ updateParams.is_deposit = 1;
1543
+ this.logInfo('定金金额大于0,自动设置为定金订单');
1544
+ }
1545
+ // 如果设置的定金金额为0,可以考虑将订单标记为全款订单
1546
+ else if (depositValue.eq(0) && this.store.currentOrder.is_deposit === 1) {
1547
+ updateParams.is_deposit = 0;
1548
+ this.logInfo('定金金额为0,自动设置为全款订单');
1549
+ }
1550
+
1551
+ // 调用 Payment 模块更新订单
1552
+ _context19.next = 20;
1553
+ return this.payment.updateOrderAsync(this.store.currentOrder.uuid, updateParams);
1554
+ case 20:
1555
+ // 更新本地缓存的订单对象
1556
+ this.store.currentOrder = _objectSpread(_objectSpread({}, this.store.currentOrder), updateParams);
1557
+
1558
+ // 同时更新本地订单数据(如果存在)
1559
+ if (this.store.localOrderData) {
1560
+ // 注意:本地订单数据中没有deposit_amount字段,但如果需要可以在这里添加
1561
+ if ('deposit_amount' in this.store.localOrderData) {
1562
+ this.store.localOrderData.deposit_amount = formattedDepositAmount;
1563
+ }
1564
+ // 同步更新 is_deposit 状态(如果有变化)
1565
+ if (updateParams.is_deposit !== undefined) {
1566
+ this.store.localOrderData.is_deposit = updateParams.is_deposit;
1567
+ }
1568
+ }
1569
+
1570
+ // 触发订单更新事件
1571
+ _context19.next = 24;
1572
+ return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
1573
+ order: this.store.currentOrder,
1574
+ timestamp: Date.now()
1575
+ });
1576
+ case 24:
1577
+ this.logInfo('订单定金金额设置成功:', {
1578
+ orderUuid: this.store.currentOrder.uuid,
1579
+ orderId: this.store.currentOrder.order_id,
1580
+ oldDepositAmount: oldDepositAmount,
1581
+ newDepositAmount: formattedDepositAmount,
1582
+ isDeposit: this.store.currentOrder.is_deposit,
1583
+ totalAmount: this.store.currentOrder.total_amount
1584
+ });
1585
+ _context19.next = 33;
1586
+ break;
1587
+ case 27:
1588
+ _context19.prev = 27;
1589
+ _context19.t0 = _context19["catch"](1);
1590
+ this.logError('设置订单定金金额失败:', _context19.t0);
1591
+ _context19.next = 32;
1592
+ return this.handleError(_context19.t0, CheckoutErrorType.ValidationFailed);
1593
+ case 32:
1594
+ throw _context19.t0;
1595
+ case 33:
1596
+ case "end":
1597
+ return _context19.stop();
1598
+ }
1599
+ }, _callee19, this, [[1, 27]]);
1600
+ }));
1601
+ function setDepositAmountAsync(_x18) {
1602
+ return _setDepositAmountAsync.apply(this, arguments);
1603
+ }
1604
+ return setDepositAmountAsync;
1605
+ }()
1450
1606
  /**
1451
1607
  * 手动同步订单到后端
1452
1608
  *
@@ -1456,26 +1612,26 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1456
1612
  }, {
1457
1613
  key: "manualSyncOrderAsync",
1458
1614
  value: (function () {
1459
- var _manualSyncOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1460
- var _this$store$currentOr6, _this$store$currentOr7, _this$store$currentOr8;
1461
- var orderUuid, oldOrderId, syncResult, finalOrderId, finalIsVirtual, _this$store$currentOr9, errorMessage;
1462
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1463
- while (1) switch (_context19.prev = _context19.next) {
1615
+ var _manualSyncOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1616
+ var _this$store$currentOr8, _this$store$currentOr9, _this$store$currentOr10;
1617
+ var orderUuid, oldOrderId, syncResult, finalOrderId, finalIsVirtual, _this$store$currentOr11, errorMessage;
1618
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1619
+ while (1) switch (_context20.prev = _context20.next) {
1464
1620
  case 0:
1465
1621
  this.logInfo('manualSyncOrderAsync called', {
1466
1622
  hasCurrentOrder: !!this.store.currentOrder,
1467
- currentOrderId: (_this$store$currentOr6 = this.store.currentOrder) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.order_id,
1468
- orderUuid: (_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.uuid,
1469
- totalAmount: (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.total_amount,
1623
+ currentOrderId: (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.order_id,
1624
+ orderUuid: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.uuid,
1625
+ totalAmount: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.total_amount,
1470
1626
  isOrderSynced: this.store.isOrderSynced,
1471
1627
  isVirtualOrderId: this.store.currentOrder ? isVirtualOrderId(this.store.currentOrder.order_id) : false
1472
1628
  });
1473
- _context19.prev = 1;
1629
+ _context20.prev = 1;
1474
1630
  if (this.store.currentOrder) {
1475
- _context19.next = 4;
1631
+ _context20.next = 4;
1476
1632
  break;
1477
1633
  }
1478
- return _context19.abrupt("return", {
1634
+ return _context20.abrupt("return", {
1479
1635
  success: false,
1480
1636
  message: '当前没有活跃订单,无法同步'
1481
1637
  });
@@ -1485,25 +1641,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1485
1641
  if (this.store.isOrderSynced) {
1486
1642
  this.logInfo('订单已同步过,将执行更新操作');
1487
1643
  }
1488
- _context19.t0 = this;
1489
- _context19.t1 = orderUuid;
1490
- _context19.t2 = oldOrderId;
1491
- _context19.t3 = this.store.currentOrder.total_amount;
1492
- _context19.next = 13;
1644
+ _context20.t0 = this;
1645
+ _context20.t1 = orderUuid;
1646
+ _context20.t2 = oldOrderId;
1647
+ _context20.t3 = this.store.currentOrder.total_amount;
1648
+ _context20.next = 13;
1493
1649
  return this.calculateRemainingAmountAsync();
1494
1650
  case 13:
1495
- _context19.t4 = _context19.sent;
1496
- _context19.t5 = {
1497
- orderUuid: _context19.t1,
1498
- orderId: _context19.t2,
1499
- totalAmount: _context19.t3,
1500
- remainingAmount: _context19.t4
1651
+ _context20.t4 = _context20.sent;
1652
+ _context20.t5 = {
1653
+ orderUuid: _context20.t1,
1654
+ orderId: _context20.t2,
1655
+ totalAmount: _context20.t3,
1656
+ remainingAmount: _context20.t4
1501
1657
  };
1502
- _context19.t0.logInfo.call(_context19.t0, '开始手动同步订单到后端:', _context19.t5);
1503
- _context19.next = 18;
1658
+ _context20.t0.logInfo.call(_context20.t0, '开始手动同步订单到后端:', _context20.t5);
1659
+ _context20.next = 18;
1504
1660
  return this.syncOrderToBackendWithReturn(true);
1505
1661
  case 18:
1506
- syncResult = _context19.sent;
1662
+ syncResult = _context20.sent;
1507
1663
  this.logInfo('手动同步订单完成:', {
1508
1664
  orderUuid: orderUuid,
1509
1665
  syncResult: syncResult,
@@ -1521,22 +1677,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1521
1677
  if (syncResult.orderId !== finalOrderId) {
1522
1678
  this.logError('[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!');
1523
1679
  }
1524
- return _context19.abrupt("return", syncResult);
1680
+ return _context20.abrupt("return", syncResult);
1525
1681
  case 27:
1526
- _context19.prev = 27;
1527
- _context19.t6 = _context19["catch"](1);
1528
- this.logError('手动同步订单失败:', _context19.t6);
1529
- errorMessage = _context19.t6 instanceof Error ? _context19.t6.message : '同步失败';
1530
- return _context19.abrupt("return", {
1682
+ _context20.prev = 27;
1683
+ _context20.t6 = _context20["catch"](1);
1684
+ this.logError('手动同步订单失败:', _context20.t6);
1685
+ errorMessage = _context20.t6 instanceof Error ? _context20.t6.message : '同步失败';
1686
+ return _context20.abrupt("return", {
1531
1687
  success: false,
1532
1688
  message: "\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(errorMessage),
1533
- orderUuid: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.uuid
1689
+ orderUuid: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.uuid
1534
1690
  });
1535
1691
  case 32:
1536
1692
  case "end":
1537
- return _context19.stop();
1693
+ return _context20.stop();
1538
1694
  }
1539
- }, _callee19, this, [[1, 27]]);
1695
+ }, _callee20, this, [[1, 27]]);
1540
1696
  }));
1541
1697
  function manualSyncOrderAsync() {
1542
1698
  return _manualSyncOrderAsync.apply(this, arguments);
@@ -1606,27 +1762,27 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1606
1762
  }, {
1607
1763
  key: "cancelCurrentOrderAsync",
1608
1764
  value: (function () {
1609
- var _cancelCurrentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(cancelReason) {
1610
- var _this$store$currentOr10, _this$store$currentOr11, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
1611
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1612
- while (1) switch (_context20.prev = _context20.next) {
1765
+ var _cancelCurrentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(cancelReason) {
1766
+ var _this$store$currentOr12, _this$store$currentOr13, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
1767
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1768
+ while (1) switch (_context21.prev = _context21.next) {
1613
1769
  case 0:
1614
- _context20.prev = 0;
1770
+ _context21.prev = 0;
1615
1771
  this.logInfo('开始取消当前本地订单:', {
1616
1772
  hasCurrentOrder: !!this.store.currentOrder,
1617
- orderUuid: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.uuid,
1618
- orderId: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.order_id,
1773
+ orderUuid: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.uuid,
1774
+ orderId: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.order_id,
1619
1775
  isOrderSynced: this.store.isOrderSynced,
1620
1776
  cancelReason: cancelReason
1621
1777
  });
1622
1778
 
1623
1779
  // 检查是否有当前订单
1624
1780
  if (this.store.currentOrder) {
1625
- _context20.next = 5;
1781
+ _context21.next = 5;
1626
1782
  break;
1627
1783
  }
1628
1784
  this.logInfo('没有当前订单,无需取消');
1629
- return _context20.abrupt("return", {
1785
+ return _context21.abrupt("return", {
1630
1786
  success: false,
1631
1787
  message: '没有当前订单可取消'
1632
1788
  });
@@ -1635,31 +1791,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1635
1791
  currentOrderId = this.store.currentOrder.order_id;
1636
1792
  isOrderSynced = this.store.isOrderSynced; // 检查订单是否已同步,已同步的订单不能取消
1637
1793
  if (!isOrderSynced) {
1638
- _context20.next = 11;
1794
+ _context21.next = 11;
1639
1795
  break;
1640
1796
  }
1641
1797
  this.logInfo('订单已同步到后端,不能取消:', {
1642
1798
  orderId: currentOrderId,
1643
1799
  orderUuid: currentOrderUuid
1644
1800
  });
1645
- return _context20.abrupt("return", {
1801
+ return _context21.abrupt("return", {
1646
1802
  success: false,
1647
1803
  message: '订单已同步到后端,无法取消',
1648
1804
  orderId: currentOrderId
1649
1805
  });
1650
1806
  case 11:
1651
- _context20.prev = 11;
1807
+ _context21.prev = 11;
1652
1808
  this.logInfo('删除本地订单数据');
1653
- _context20.next = 15;
1809
+ _context21.next = 15;
1654
1810
  return this.payment.deletePaymentOrderAsync(currentOrderUuid);
1655
1811
  case 15:
1656
1812
  this.logInfo('本地订单数据删除成功');
1657
- _context20.next = 21;
1813
+ _context21.next = 21;
1658
1814
  break;
1659
1815
  case 18:
1660
- _context20.prev = 18;
1661
- _context20.t0 = _context20["catch"](11);
1662
- this.logWarning('删除本地订单数据失败,但继续执行:', _context20.t0);
1816
+ _context21.prev = 18;
1817
+ _context21.t0 = _context21["catch"](11);
1818
+ this.logWarning('删除本地订单数据失败,但继续执行:', _context21.t0);
1663
1819
  case 21:
1664
1820
  // 清理订单相关状态,确保正确释放 currentOrder
1665
1821
  this.logInfo('清理订单相关状态');
@@ -1675,7 +1831,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1675
1831
  this.logInfo('订单状态清理完成,currentOrder已释放');
1676
1832
 
1677
1833
  // 触发订单取消事件
1678
- _context20.next = 32;
1834
+ _context21.next = 32;
1679
1835
  return this.core.effects.emit(CheckoutHooks.OnOrderCancelled, {
1680
1836
  orderUuid: currentOrderUuid,
1681
1837
  orderId: currentOrderId,
@@ -1690,27 +1846,27 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1690
1846
  orderId: currentOrderId,
1691
1847
  cancelReason: cancelReason
1692
1848
  });
1693
- return _context20.abrupt("return", {
1849
+ return _context21.abrupt("return", {
1694
1850
  success: true,
1695
1851
  message: '本地订单已成功取消',
1696
1852
  orderId: currentOrderId
1697
1853
  });
1698
1854
  case 36:
1699
- _context20.prev = 36;
1700
- _context20.t1 = _context20["catch"](0);
1701
- this.logError('取消本地订单失败:', _context20.t1);
1702
- errorMessage = _context20.t1 instanceof Error ? _context20.t1.message : '未知错误';
1703
- return _context20.abrupt("return", {
1855
+ _context21.prev = 36;
1856
+ _context21.t1 = _context21["catch"](0);
1857
+ this.logError('取消本地订单失败:', _context21.t1);
1858
+ errorMessage = _context21.t1 instanceof Error ? _context21.t1.message : '未知错误';
1859
+ return _context21.abrupt("return", {
1704
1860
  success: false,
1705
1861
  message: "\u53D6\u6D88\u8BA2\u5355\u5931\u8D25: ".concat(errorMessage)
1706
1862
  });
1707
1863
  case 41:
1708
1864
  case "end":
1709
- return _context20.stop();
1865
+ return _context21.stop();
1710
1866
  }
1711
- }, _callee20, this, [[0, 36], [11, 18]]);
1867
+ }, _callee21, this, [[0, 36], [11, 18]]);
1712
1868
  }));
1713
- function cancelCurrentOrderAsync(_x18) {
1869
+ function cancelCurrentOrderAsync(_x19) {
1714
1870
  return _cancelCurrentOrderAsync.apply(this, arguments);
1715
1871
  }
1716
1872
  return cancelCurrentOrderAsync;
@@ -1725,17 +1881,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1725
1881
  }, {
1726
1882
  key: "saveForLaterPaymentAsync",
1727
1883
  value: (function () {
1728
- var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1729
- var orderUuid, currentOrderId, allPaymentItems, syncResult, _this$store$currentOr12, errorMessage;
1730
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1731
- while (1) switch (_context21.prev = _context21.next) {
1884
+ var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1885
+ var orderUuid, currentOrderId, allPaymentItems, syncResult, _this$store$currentOr14, errorMessage;
1886
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1887
+ while (1) switch (_context22.prev = _context22.next) {
1732
1888
  case 0:
1733
- _context21.prev = 0;
1889
+ _context22.prev = 0;
1734
1890
  if (this.store.currentOrder) {
1735
- _context21.next = 3;
1891
+ _context22.next = 3;
1736
1892
  break;
1737
1893
  }
1738
- return _context21.abrupt("return", {
1894
+ return _context22.abrupt("return", {
1739
1895
  success: false,
1740
1896
  message: '当前没有活跃订单,无法保存'
1741
1897
  });
@@ -1749,14 +1905,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1749
1905
  });
1750
1906
 
1751
1907
  // 获取当前订单的所有支付项
1752
- _context21.next = 8;
1908
+ _context22.next = 8;
1753
1909
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
1754
1910
  case 8:
1755
- allPaymentItems = _context21.sent;
1756
- _context21.next = 11;
1911
+ allPaymentItems = _context22.sent;
1912
+ _context22.next = 11;
1757
1913
  return this.syncOrderToBackendWithReturn(true, allPaymentItems);
1758
1914
  case 11:
1759
- syncResult = _context21.sent;
1915
+ syncResult = _context22.sent;
1760
1916
  this.logInfo('保存订单完成:', {
1761
1917
  orderUuid: orderUuid,
1762
1918
  oldOrderId: currentOrderId,
@@ -1765,7 +1921,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1765
1921
  isOrderSynced: this.store.isOrderSynced,
1766
1922
  filteredPaymentsCount: allPaymentItems.length
1767
1923
  });
1768
- return _context21.abrupt("return", {
1924
+ return _context22.abrupt("return", {
1769
1925
  success: true,
1770
1926
  message: '订单保存成功,可稍后继续支付',
1771
1927
  orderId: syncResult.orderId,
@@ -1773,20 +1929,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1773
1929
  response: syncResult.response
1774
1930
  });
1775
1931
  case 16:
1776
- _context21.prev = 16;
1777
- _context21.t0 = _context21["catch"](0);
1778
- this.logError('保存订单失败:', _context21.t0);
1779
- errorMessage = _context21.t0 instanceof Error ? _context21.t0.message : '保存失败';
1780
- return _context21.abrupt("return", {
1932
+ _context22.prev = 16;
1933
+ _context22.t0 = _context22["catch"](0);
1934
+ this.logError('保存订单失败:', _context22.t0);
1935
+ errorMessage = _context22.t0 instanceof Error ? _context22.t0.message : '保存失败';
1936
+ return _context22.abrupt("return", {
1781
1937
  success: false,
1782
1938
  message: "\u8BA2\u5355\u4FDD\u5B58\u5931\u8D25: ".concat(errorMessage),
1783
- orderUuid: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.uuid
1939
+ orderUuid: (_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.uuid
1784
1940
  });
1785
1941
  case 21:
1786
1942
  case "end":
1787
- return _context21.stop();
1943
+ return _context22.stop();
1788
1944
  }
1789
- }, _callee21, this, [[0, 16]]);
1945
+ }, _callee22, this, [[0, 16]]);
1790
1946
  }));
1791
1947
  function saveForLaterPaymentAsync() {
1792
1948
  return _saveForLaterPaymentAsync.apply(this, arguments);
@@ -1802,20 +1958,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1802
1958
  }, {
1803
1959
  key: "updateOrderNoteAsync",
1804
1960
  value: (function () {
1805
- var _updateOrderNoteAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(note) {
1806
- var _this$store$currentOr13, _this$store$currentOr14, oldNote, orderInPayment;
1807
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1808
- while (1) switch (_context22.prev = _context22.next) {
1961
+ var _updateOrderNoteAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(note) {
1962
+ var _this$store$currentOr15, _this$store$currentOr16, oldNote, orderInPayment;
1963
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1964
+ while (1) switch (_context23.prev = _context23.next) {
1809
1965
  case 0:
1810
- _context22.prev = 0;
1966
+ _context23.prev = 0;
1811
1967
  if (this.store.localOrderData) {
1812
- _context22.next = 3;
1968
+ _context23.next = 3;
1813
1969
  break;
1814
1970
  }
1815
1971
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '没有本地订单数据,无法更新备注');
1816
1972
  case 3:
1817
1973
  console.log('[Checkout] 更新订单备注:', {
1818
- orderUuid: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.uuid,
1974
+ orderUuid: (_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.uuid,
1819
1975
  oldNote: this.store.localOrderData.shop_note,
1820
1976
  newNote: note
1821
1977
  });
@@ -1826,29 +1982,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1826
1982
 
1827
1983
  // 如果有当前订单,也同步到Payment模块中的订单数据
1828
1984
  if (!this.store.currentOrder) {
1829
- _context22.next = 17;
1985
+ _context23.next = 17;
1830
1986
  break;
1831
1987
  }
1832
- _context22.prev = 7;
1833
- _context22.next = 10;
1988
+ _context23.prev = 7;
1989
+ _context23.next = 10;
1834
1990
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1835
1991
  case 10:
1836
- orderInPayment = _context22.sent;
1992
+ orderInPayment = _context23.sent;
1837
1993
  if (orderInPayment && orderInPayment.note !== undefined) {
1838
1994
  // 使用Payment模块的更新方法(如果有的话)
1839
1995
  // 这里可能需要根据Payment模块的实际API来调整
1840
1996
  console.log('[Checkout] 同步备注到Payment模块的订单数据中');
1841
1997
  }
1842
- _context22.next = 17;
1998
+ _context23.next = 17;
1843
1999
  break;
1844
2000
  case 14:
1845
- _context22.prev = 14;
1846
- _context22.t0 = _context22["catch"](7);
1847
- console.warn('[Checkout] 同步备注到Payment模块失败,但本地更新成功:', _context22.t0);
2001
+ _context23.prev = 14;
2002
+ _context23.t0 = _context23["catch"](7);
2003
+ console.warn('[Checkout] 同步备注到Payment模块失败,但本地更新成功:', _context23.t0);
1848
2004
  case 17:
1849
- _context22.next = 19;
2005
+ _context23.next = 19;
1850
2006
  return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
1851
- orderUuid: (_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.uuid,
2007
+ orderUuid: (_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.uuid,
1852
2008
  oldNote: oldNote,
1853
2009
  newNote: note,
1854
2010
  timestamp: Date.now()
@@ -1858,23 +2014,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1858
2014
  oldNote: oldNote,
1859
2015
  newNote: note
1860
2016
  });
1861
- _context22.next = 28;
2017
+ _context23.next = 28;
1862
2018
  break;
1863
2019
  case 22:
1864
- _context22.prev = 22;
1865
- _context22.t1 = _context22["catch"](0);
1866
- console.error('[Checkout] 更新订单备注失败:', _context22.t1);
1867
- _context22.next = 27;
1868
- return this.handleError(_context22.t1, CheckoutErrorType.ValidationFailed);
2020
+ _context23.prev = 22;
2021
+ _context23.t1 = _context23["catch"](0);
2022
+ console.error('[Checkout] 更新订单备注失败:', _context23.t1);
2023
+ _context23.next = 27;
2024
+ return this.handleError(_context23.t1, CheckoutErrorType.ValidationFailed);
1869
2025
  case 27:
1870
- throw _context22.t1;
2026
+ throw _context23.t1;
1871
2027
  case 28:
1872
2028
  case "end":
1873
- return _context22.stop();
2029
+ return _context23.stop();
1874
2030
  }
1875
- }, _callee22, this, [[0, 22], [7, 14]]);
2031
+ }, _callee23, this, [[0, 22], [7, 14]]);
1876
2032
  }));
1877
- function updateOrderNoteAsync(_x19) {
2033
+ function updateOrderNoteAsync(_x20) {
1878
2034
  return _updateOrderNoteAsync.apply(this, arguments);
1879
2035
  }
1880
2036
  return updateOrderNoteAsync;
@@ -1886,14 +2042,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1886
2042
  }, {
1887
2043
  key: "handleError",
1888
2044
  value: (function () {
1889
- var _handleError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(error, type) {
2045
+ var _handleError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(error, type) {
1890
2046
  var checkoutError;
1891
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1892
- while (1) switch (_context23.prev = _context23.next) {
2047
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2048
+ while (1) switch (_context24.prev = _context24.next) {
1893
2049
  case 0:
1894
2050
  checkoutError = error instanceof Error && 'type' in error ? error : createCheckoutError(type, error.message, error);
1895
2051
  this.store.lastError = checkoutError;
1896
- _context23.next = 4;
2052
+ _context24.next = 4;
1897
2053
  return this.core.effects.emit(CheckoutHooks.OnError, {
1898
2054
  error: checkoutError,
1899
2055
  context: {},
@@ -1903,11 +2059,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1903
2059
  console.error('[Checkout] 错误:', checkoutError);
1904
2060
  case 5:
1905
2061
  case "end":
1906
- return _context23.stop();
2062
+ return _context24.stop();
1907
2063
  }
1908
- }, _callee23, this);
2064
+ }, _callee24, this);
1909
2065
  }));
1910
- function handleError(_x20, _x21) {
2066
+ function handleError(_x21, _x22) {
1911
2067
  return _handleError.apply(this, arguments);
1912
2068
  }
1913
2069
  return handleError;
@@ -1919,31 +2075,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1919
2075
  }, {
1920
2076
  key: "handlePaymentSuccess",
1921
2077
  value: (function () {
1922
- var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(data) {
1923
- var _this$store$currentOr15;
1924
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1925
- while (1) switch (_context24.prev = _context24.next) {
2078
+ var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(data) {
2079
+ var _this$store$currentOr17;
2080
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2081
+ while (1) switch (_context25.prev = _context25.next) {
1926
2082
  case 0:
1927
- _context24.next = 2;
2083
+ _context25.next = 2;
1928
2084
  return this.updateStateAmountToRemaining();
1929
2085
  case 2:
1930
- _context24.next = 4;
2086
+ _context25.next = 4;
1931
2087
  return this.core.effects.emit(CheckoutHooks.OnPaymentSuccess, {
1932
2088
  orderUuid: data.orderUuid,
1933
2089
  paymentMethodCode: '',
1934
- amount: ((_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.total_amount) || '0',
2090
+ amount: ((_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.total_amount) || '0',
1935
2091
  timestamp: data.timestamp
1936
2092
  });
1937
2093
  case 4:
1938
- _context24.next = 6;
2094
+ _context25.next = 6;
1939
2095
  return this.completeCheckoutAsync();
1940
2096
  case 6:
1941
2097
  case "end":
1942
- return _context24.stop();
2098
+ return _context25.stop();
1943
2099
  }
1944
- }, _callee24, this);
2100
+ }, _callee25, this);
1945
2101
  }));
1946
- function handlePaymentSuccess(_x22) {
2102
+ function handlePaymentSuccess(_x23) {
1947
2103
  return _handlePaymentSuccess.apply(this, arguments);
1948
2104
  }
1949
2105
  return handlePaymentSuccess;
@@ -1955,30 +2111,30 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1955
2111
  }, {
1956
2112
  key: "handlePaymentError",
1957
2113
  value: (function () {
1958
- var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(data) {
1959
- var _this$store$currentOr16;
2114
+ var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(data) {
2115
+ var _this$store$currentOr18;
1960
2116
  var error;
1961
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1962
- while (1) switch (_context25.prev = _context25.next) {
2117
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2118
+ while (1) switch (_context26.prev = _context26.next) {
1963
2119
  case 0:
1964
2120
  error = createCheckoutError(CheckoutErrorType.PaymentFailed, data.error || '支付同步失败');
1965
- _context25.next = 3;
2121
+ _context26.next = 3;
1966
2122
  return this.handleError(error instanceof Error ? error : new Error(String(error)), CheckoutErrorType.PaymentFailed);
1967
2123
  case 3:
1968
- _context25.next = 5;
2124
+ _context26.next = 5;
1969
2125
  return this.core.effects.emit(CheckoutHooks.OnPaymentFailed, {
1970
2126
  orderUuid: data.orderUuid,
1971
2127
  paymentMethodCode: '',
1972
- amount: ((_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.total_amount) || '0',
2128
+ amount: ((_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.total_amount) || '0',
1973
2129
  timestamp: data.timestamp
1974
2130
  });
1975
2131
  case 5:
1976
2132
  case "end":
1977
- return _context25.stop();
2133
+ return _context26.stop();
1978
2134
  }
1979
- }, _callee25, this);
2135
+ }, _callee26, this);
1980
2136
  }));
1981
- function handlePaymentError(_x23) {
2137
+ function handlePaymentError(_x24) {
1982
2138
  return _handlePaymentError.apply(this, arguments);
1983
2139
  }
1984
2140
  return handlePaymentError;
@@ -2002,43 +2158,43 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2002
2158
  }, {
2003
2159
  key: "processCashPaymentItem",
2004
2160
  value: (function () {
2005
- var _processCashPaymentItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(paymentItem) {
2161
+ var _processCashPaymentItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(paymentItem) {
2006
2162
  var cashPayment, remainingAmountStr, remainingAmount, cashAmount, changeAmount, processedPaymentItem;
2007
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2008
- while (1) switch (_context26.prev = _context26.next) {
2163
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2164
+ while (1) switch (_context27.prev = _context27.next) {
2009
2165
  case 0:
2010
2166
  // 检查是否是现金支付
2011
2167
  cashPayment = isCashPayment(paymentItem.code, paymentItem.type);
2012
2168
  if (cashPayment) {
2013
- _context26.next = 3;
2169
+ _context27.next = 3;
2014
2170
  break;
2015
2171
  }
2016
- return _context26.abrupt("return", paymentItem);
2172
+ return _context27.abrupt("return", paymentItem);
2017
2173
  case 3:
2018
- _context26.prev = 3;
2019
- _context26.next = 6;
2174
+ _context27.prev = 3;
2175
+ _context27.next = 6;
2020
2176
  return this.calculateRemainingAmountAsync();
2021
2177
  case 6:
2022
- remainingAmountStr = _context26.sent;
2178
+ remainingAmountStr = _context27.sent;
2023
2179
  remainingAmount = new Decimal(remainingAmountStr);
2024
2180
  cashAmount = new Decimal(String(paymentItem.amount)); // 如果现金金额小于等于剩余待付金额,无需找零
2025
2181
  if (!cashAmount.lte(remainingAmount)) {
2026
- _context26.next = 11;
2182
+ _context27.next = 11;
2027
2183
  break;
2028
2184
  }
2029
- return _context26.abrupt("return", paymentItem);
2185
+ return _context27.abrupt("return", paymentItem);
2030
2186
  case 11:
2031
2187
  // 使用 Decimal.js 安全计算找零金额
2032
2188
  changeAmount = cashAmount.sub(remainingAmount); // 如果还有 rounding_amount 的配置,要判断是否和 changeAmount 相等
2033
2189
  if (!(Number(paymentItem.rounding_amount) > 0)) {
2034
- _context26.next = 18;
2190
+ _context27.next = 18;
2035
2191
  break;
2036
2192
  }
2037
2193
  if (!(Number(paymentItem.rounding_amount) === changeAmount.toNumber())) {
2038
- _context26.next = 17;
2194
+ _context27.next = 17;
2039
2195
  break;
2040
2196
  }
2041
- return _context26.abrupt("return", paymentItem);
2197
+ return _context27.abrupt("return", paymentItem);
2042
2198
  case 17:
2043
2199
  // 如果不等于,则remainingAmount需要加上 rounding_amount,避免这里被改为未舍入金额
2044
2200
  remainingAmount = remainingAmount.add(new Decimal(paymentItem.rounding_amount || '0'));
@@ -2066,20 +2222,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2066
2222
  changeAmountPrecise: changeAmount.toString()
2067
2223
  }
2068
2224
  });
2069
- return _context26.abrupt("return", processedPaymentItem);
2225
+ return _context27.abrupt("return", processedPaymentItem);
2070
2226
  case 23:
2071
- _context26.prev = 23;
2072
- _context26.t0 = _context26["catch"](3);
2073
- this.logError('处理现金支付项时出错:', _context26.t0);
2227
+ _context27.prev = 23;
2228
+ _context27.t0 = _context27["catch"](3);
2229
+ this.logError('处理现金支付项时出错:', _context27.t0);
2074
2230
  // 出错时返回原始支付项,避免中断支付流程
2075
- return _context26.abrupt("return", paymentItem);
2231
+ return _context27.abrupt("return", paymentItem);
2076
2232
  case 27:
2077
2233
  case "end":
2078
- return _context26.stop();
2234
+ return _context27.stop();
2079
2235
  }
2080
- }, _callee26, this, [[3, 23]]);
2236
+ }, _callee27, this, [[3, 23]]);
2081
2237
  }));
2082
- function processCashPaymentItem(_x24) {
2238
+ function processCashPaymentItem(_x25) {
2083
2239
  return _processCashPaymentItem.apply(this, arguments);
2084
2240
  }
2085
2241
  return processCashPaymentItem;
@@ -2091,31 +2247,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2091
2247
  }, {
2092
2248
  key: "preloadPaymentMethods",
2093
2249
  value: (function () {
2094
- var _preloadPaymentMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
2250
+ var _preloadPaymentMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2095
2251
  var methods;
2096
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2097
- while (1) switch (_context27.prev = _context27.next) {
2252
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2253
+ while (1) switch (_context28.prev = _context28.next) {
2098
2254
  case 0:
2099
- _context27.prev = 0;
2255
+ _context28.prev = 0;
2100
2256
  console.log('[Checkout] 预加载支付方式...');
2101
- _context27.next = 4;
2257
+ _context28.next = 4;
2102
2258
  return this.payment.getPayMethodListAsync();
2103
2259
  case 4:
2104
- methods = _context27.sent;
2260
+ methods = _context28.sent;
2105
2261
  this.store.paymentMethods = methods;
2106
2262
  console.log("[Checkout] \u9884\u52A0\u8F7D\u5B8C\u6210\uFF0C\u5171 ".concat(methods.length, " \u79CD\u652F\u4ED8\u65B9\u5F0F"));
2107
- _context27.next = 13;
2263
+ _context28.next = 13;
2108
2264
  break;
2109
2265
  case 9:
2110
- _context27.prev = 9;
2111
- _context27.t0 = _context27["catch"](0);
2112
- console.error('[Checkout] 预加载支付方式失败:', _context27.t0);
2266
+ _context28.prev = 9;
2267
+ _context28.t0 = _context28["catch"](0);
2268
+ console.error('[Checkout] 预加载支付方式失败:', _context28.t0);
2113
2269
  this.store.paymentMethods = [];
2114
2270
  case 13:
2115
2271
  case "end":
2116
- return _context27.stop();
2272
+ return _context28.stop();
2117
2273
  }
2118
- }, _callee27, this, [[0, 9]]);
2274
+ }, _callee28, this, [[0, 9]]);
2119
2275
  }));
2120
2276
  function preloadPaymentMethods() {
2121
2277
  return _preloadPaymentMethods.apply(this, arguments);
@@ -2131,59 +2287,59 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2131
2287
  }, {
2132
2288
  key: "cleanupExpiredOrdersAsync",
2133
2289
  value: (function () {
2134
- var _cleanupExpiredOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2290
+ var _cleanupExpiredOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2135
2291
  var cleanupConfig, isCleanupEnabled, retentionDays, maxOrdersToDelete, allOrders, thresholdDate, deletedCount, ordersToDelete, _iterator, _step, order, _order$order_info, _order$order_info2, isSynced, orderCreatedAt, actualOrdersToDelete, _iterator2, _step2, orderInfo, summary, errorMessage;
2136
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2137
- while (1) switch (_context28.prev = _context28.next) {
2292
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2293
+ while (1) switch (_context29.prev = _context29.next) {
2138
2294
  case 0:
2139
- _context28.prev = 0;
2295
+ _context29.prev = 0;
2140
2296
  // 检查是否启用了清理功能
2141
2297
  cleanupConfig = this.otherParams.orderDataCleanup || {};
2142
2298
  isCleanupEnabled = cleanupConfig.enabled !== false; // 默认启用
2143
2299
  retentionDays = cleanupConfig.retentionDays || 7; // 默认保留7天
2144
2300
  maxOrdersToDelete = cleanupConfig.maxOrdersToDelete || 100; // 默认最多删除100个订单
2145
2301
  if (isCleanupEnabled) {
2146
- _context28.next = 8;
2302
+ _context29.next = 8;
2147
2303
  break;
2148
2304
  }
2149
2305
  console.log('[Checkout] 订单数据清理功能已禁用');
2150
- return _context28.abrupt("return");
2306
+ return _context29.abrupt("return");
2151
2307
  case 8:
2152
2308
  console.log("[Checkout] \u5F00\u59CB\u6E05\u7406\u8FC7\u671F\u8BA2\u5355\u6570\u636E\uFF08\u4FDD\u7559 ".concat(retentionDays, " \u5929\u5185\u7684\u6570\u636E\uFF09..."));
2153
2309
 
2154
2310
  // 获取所有订单
2155
- _context28.next = 11;
2311
+ _context29.next = 11;
2156
2312
  return this.payment.getOrderListAsync();
2157
2313
  case 11:
2158
- allOrders = _context28.sent;
2314
+ allOrders = _context29.sent;
2159
2315
  if (!(!allOrders || allOrders.length === 0)) {
2160
- _context28.next = 15;
2316
+ _context29.next = 15;
2161
2317
  break;
2162
2318
  }
2163
2319
  console.log('[Checkout] 没有找到需要清理的订单数据');
2164
- return _context28.abrupt("return");
2320
+ return _context29.abrupt("return");
2165
2321
  case 15:
2166
2322
  thresholdDate = new Date();
2167
2323
  thresholdDate.setDate(thresholdDate.getDate() - retentionDays);
2168
2324
  deletedCount = 0;
2169
2325
  ordersToDelete = [];
2170
2326
  _iterator = _createForOfIteratorHelper(allOrders);
2171
- _context28.prev = 20;
2327
+ _context29.prev = 20;
2172
2328
  _iterator.s();
2173
2329
  case 22:
2174
2330
  if ((_step = _iterator.n()).done) {
2175
- _context28.next = 41;
2331
+ _context29.next = 41;
2176
2332
  break;
2177
2333
  }
2178
2334
  order = _step.value;
2179
- _context28.prev = 24;
2335
+ _context29.prev = 24;
2180
2336
  // 检查订单是否已同步(订单ID不是虚拟ID)
2181
2337
  isSynced = order.order_id && !isVirtualOrderId(order.order_id);
2182
2338
  if (isSynced) {
2183
- _context28.next = 28;
2339
+ _context29.next = 28;
2184
2340
  break;
2185
2341
  }
2186
- return _context28.abrupt("continue", 39);
2342
+ return _context29.abrupt("continue", 39);
2187
2343
  case 28:
2188
2344
  // 检查创建时间
2189
2345
  orderCreatedAt = null; // 尝试从 order_info.created_at 获取创建时间
@@ -2197,10 +2353,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2197
2353
 
2198
2354
  // 如果无法获取创建时间,跳过此订单
2199
2355
  if (!(!orderCreatedAt || isNaN(orderCreatedAt.getTime()))) {
2200
- _context28.next = 32;
2356
+ _context29.next = 32;
2201
2357
  break;
2202
2358
  }
2203
- return _context28.abrupt("continue", 39);
2359
+ return _context29.abrupt("continue", 39);
2204
2360
  case 32:
2205
2361
  // 检查是否超过指定天数
2206
2362
  if (orderCreatedAt < thresholdDate) {
@@ -2211,27 +2367,27 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2211
2367
  daysSinceCreated: Math.floor((Date.now() - orderCreatedAt.getTime()) / (1000 * 60 * 60 * 24))
2212
2368
  });
2213
2369
  }
2214
- _context28.next = 39;
2370
+ _context29.next = 39;
2215
2371
  break;
2216
2372
  case 35:
2217
- _context28.prev = 35;
2218
- _context28.t0 = _context28["catch"](24);
2219
- console.warn("[Checkout] \u5904\u7406\u8BA2\u5355 ".concat(order.uuid, " \u65F6\u51FA\u9519:"), _context28.t0);
2220
- return _context28.abrupt("continue", 39);
2373
+ _context29.prev = 35;
2374
+ _context29.t0 = _context29["catch"](24);
2375
+ console.warn("[Checkout] \u5904\u7406\u8BA2\u5355 ".concat(order.uuid, " \u65F6\u51FA\u9519:"), _context29.t0);
2376
+ return _context29.abrupt("continue", 39);
2221
2377
  case 39:
2222
- _context28.next = 22;
2378
+ _context29.next = 22;
2223
2379
  break;
2224
2380
  case 41:
2225
- _context28.next = 46;
2381
+ _context29.next = 46;
2226
2382
  break;
2227
2383
  case 43:
2228
- _context28.prev = 43;
2229
- _context28.t1 = _context28["catch"](20);
2230
- _iterator.e(_context28.t1);
2384
+ _context29.prev = 43;
2385
+ _context29.t1 = _context29["catch"](20);
2386
+ _iterator.e(_context29.t1);
2231
2387
  case 46:
2232
- _context28.prev = 46;
2388
+ _context29.prev = 46;
2233
2389
  _iterator.f();
2234
- return _context28.finish(46);
2390
+ return _context29.finish(46);
2235
2391
  case 49:
2236
2392
  // 按创建时间排序(最老的先删除)并限制删除数量
2237
2393
  ordersToDelete.sort(function (a, b) {
@@ -2239,40 +2395,40 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2239
2395
  });
2240
2396
  actualOrdersToDelete = ordersToDelete.slice(0, maxOrdersToDelete); // 删除符合条件的订单
2241
2397
  _iterator2 = _createForOfIteratorHelper(actualOrdersToDelete);
2242
- _context28.prev = 52;
2398
+ _context29.prev = 52;
2243
2399
  _iterator2.s();
2244
2400
  case 54:
2245
2401
  if ((_step2 = _iterator2.n()).done) {
2246
- _context28.next = 68;
2402
+ _context29.next = 68;
2247
2403
  break;
2248
2404
  }
2249
2405
  orderInfo = _step2.value;
2250
- _context28.prev = 56;
2251
- _context28.next = 59;
2406
+ _context29.prev = 56;
2407
+ _context29.next = 59;
2252
2408
  return this.payment.deletePaymentOrderAsync(orderInfo.uuid);
2253
2409
  case 59:
2254
2410
  deletedCount++;
2255
2411
  console.log("[Checkout] \u5DF2\u5220\u9664\u8FC7\u671F\u8BA2\u5355: ".concat(orderInfo.orderId, " (").concat(orderInfo.daysSinceCreated, " \u5929\u524D\u521B\u5EFA)"));
2256
- _context28.next = 66;
2412
+ _context29.next = 66;
2257
2413
  break;
2258
2414
  case 63:
2259
- _context28.prev = 63;
2260
- _context28.t2 = _context28["catch"](56);
2261
- console.error("[Checkout] \u5220\u9664\u8BA2\u5355 ".concat(orderInfo.uuid, " \u5931\u8D25:"), _context28.t2);
2415
+ _context29.prev = 63;
2416
+ _context29.t2 = _context29["catch"](56);
2417
+ console.error("[Checkout] \u5220\u9664\u8BA2\u5355 ".concat(orderInfo.uuid, " \u5931\u8D25:"), _context29.t2);
2262
2418
  case 66:
2263
- _context28.next = 54;
2419
+ _context29.next = 54;
2264
2420
  break;
2265
2421
  case 68:
2266
- _context28.next = 73;
2422
+ _context29.next = 73;
2267
2423
  break;
2268
2424
  case 70:
2269
- _context28.prev = 70;
2270
- _context28.t3 = _context28["catch"](52);
2271
- _iterator2.e(_context28.t3);
2425
+ _context29.prev = 70;
2426
+ _context29.t3 = _context29["catch"](52);
2427
+ _iterator2.e(_context29.t3);
2272
2428
  case 73:
2273
- _context28.prev = 73;
2429
+ _context29.prev = 73;
2274
2430
  _iterator2.f();
2275
- return _context28.finish(73);
2431
+ return _context29.finish(73);
2276
2432
  case 76:
2277
2433
  summary = {
2278
2434
  totalOrders: allOrders.length,
@@ -2290,21 +2446,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2290
2446
  } else {
2291
2447
  console.log("[Checkout] \u8FC7\u671F\u8BA2\u5355\u6E05\u7406\u5B8C\u6210: \u603B\u8BA1 ".concat(allOrders.length, " \u4E2A\u8BA2\u5355\uFF0C\u5220\u9664\u4E86 ").concat(deletedCount, " \u4E2A\u8FC7\u671F\u5DF2\u540C\u6B65\u8BA2\u5355"));
2292
2448
  }
2293
- _context28.next = 86;
2449
+ _context29.next = 86;
2294
2450
  break;
2295
2451
  case 81:
2296
- _context28.prev = 81;
2297
- _context28.t4 = _context28["catch"](0);
2298
- errorMessage = _context28.t4 instanceof Error ? _context28.t4.message : String(_context28.t4);
2299
- console.error('[Checkout] 清理过期订单数据失败:', _context28.t4);
2452
+ _context29.prev = 81;
2453
+ _context29.t4 = _context29["catch"](0);
2454
+ errorMessage = _context29.t4 instanceof Error ? _context29.t4.message : String(_context29.t4);
2455
+ console.error('[Checkout] 清理过期订单数据失败:', _context29.t4);
2300
2456
  this.logError('Expired orders cleanup failed', {
2301
2457
  error: errorMessage
2302
2458
  });
2303
2459
  case 86:
2304
2460
  case "end":
2305
- return _context28.stop();
2461
+ return _context29.stop();
2306
2462
  }
2307
- }, _callee28, this, [[0, 81], [20, 43, 46, 49], [24, 35], [52, 70, 73, 76], [56, 63]]);
2463
+ }, _callee29, this, [[0, 81], [20, 43, 46, 49], [24, 35], [52, 70, 73, 76], [56, 63]]);
2308
2464
  }));
2309
2465
  function cleanupExpiredOrdersAsync() {
2310
2466
  return _cleanupExpiredOrdersAsync.apply(this, arguments);
@@ -2318,24 +2474,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2318
2474
  }, {
2319
2475
  key: "calculatePaidAmountAsync",
2320
2476
  value: (function () {
2321
- var _calculatePaidAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2477
+ var _calculatePaidAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2322
2478
  var payments, paidAmount, result;
2323
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2324
- while (1) switch (_context29.prev = _context29.next) {
2479
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2480
+ while (1) switch (_context30.prev = _context30.next) {
2325
2481
  case 0:
2326
2482
  if (this.store.currentOrder) {
2327
- _context29.next = 3;
2483
+ _context30.next = 3;
2328
2484
  break;
2329
2485
  }
2330
2486
  this.logWarning('[Checkout] calculatePaidAmountAsync: 没有当前订单');
2331
- return _context29.abrupt("return", '0.00');
2487
+ return _context30.abrupt("return", '0.00');
2332
2488
  case 3:
2333
- _context29.prev = 3;
2334
- _context29.next = 6;
2489
+ _context30.prev = 3;
2490
+ _context30.next = 6;
2335
2491
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
2336
2492
  );
2337
2493
  case 6:
2338
- payments = _context29.sent;
2494
+ payments = _context30.sent;
2339
2495
  // 使用 Decimal.js 进行安全的金额计算
2340
2496
  paidAmount = payments.filter(function (payment) {
2341
2497
  return payment.status !== 'voided';
@@ -2364,17 +2520,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2364
2520
  }, new Decimal(0));
2365
2521
  result = paidAmount.toFixed(2);
2366
2522
  this.logInfo('calculatePaidAmountAsync: 计算结果 =', result);
2367
- return _context29.abrupt("return", result);
2523
+ return _context30.abrupt("return", result);
2368
2524
  case 13:
2369
- _context29.prev = 13;
2370
- _context29.t0 = _context29["catch"](3);
2371
- this.logError('calculatePaidAmountAsync 失败:', _context29.t0);
2372
- return _context29.abrupt("return", '0.00');
2525
+ _context30.prev = 13;
2526
+ _context30.t0 = _context30["catch"](3);
2527
+ this.logError('calculatePaidAmountAsync 失败:', _context30.t0);
2528
+ return _context30.abrupt("return", '0.00');
2373
2529
  case 17:
2374
2530
  case "end":
2375
- return _context29.stop();
2531
+ return _context30.stop();
2376
2532
  }
2377
- }, _callee29, this, [[3, 13]]);
2533
+ }, _callee30, this, [[3, 13]]);
2378
2534
  }));
2379
2535
  function calculatePaidAmountAsync() {
2380
2536
  return _calculatePaidAmountAsync.apply(this, arguments);
@@ -2388,34 +2544,34 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2388
2544
  }, {
2389
2545
  key: "calculateRemainingAmountAsync",
2390
2546
  value: (function () {
2391
- var _calculateRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2547
+ var _calculateRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2392
2548
  var totalAmount, paidAmountStr, paidAmount, remainingAmount, result;
2393
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2394
- while (1) switch (_context30.prev = _context30.next) {
2549
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2550
+ while (1) switch (_context31.prev = _context31.next) {
2395
2551
  case 0:
2396
2552
  if (this.store.currentOrder) {
2397
- _context30.next = 3;
2553
+ _context31.next = 3;
2398
2554
  break;
2399
2555
  }
2400
2556
  this.logWarning('calculateRemainingAmountAsync: 没有当前订单');
2401
- return _context30.abrupt("return", '0.00');
2557
+ return _context31.abrupt("return", '0.00');
2402
2558
  case 3:
2403
2559
  // 使用 Decimal.js 进行安全的金额计算
2404
2560
  totalAmount = new Decimal(this.store.currentOrder.total_amount || '0');
2405
- _context30.next = 6;
2561
+ _context31.next = 6;
2406
2562
  return this.calculatePaidAmountAsync();
2407
2563
  case 6:
2408
- paidAmountStr = _context30.sent;
2564
+ paidAmountStr = _context31.sent;
2409
2565
  paidAmount = new Decimal(paidAmountStr);
2410
2566
  remainingAmount = totalAmount.sub(paidAmount); // 确保剩余金额不为负数
2411
2567
  result = Decimal.max(0, remainingAmount).toFixed(2);
2412
2568
  this.logInfo('calculateRemainingAmountAsync: 计算=', result);
2413
- return _context30.abrupt("return", result);
2569
+ return _context31.abrupt("return", result);
2414
2570
  case 12:
2415
2571
  case "end":
2416
- return _context30.stop();
2572
+ return _context31.stop();
2417
2573
  }
2418
- }, _callee30, this);
2574
+ }, _callee31, this);
2419
2575
  }));
2420
2576
  function calculateRemainingAmountAsync() {
2421
2577
  return _calculateRemainingAmountAsync.apply(this, arguments);
@@ -2429,25 +2585,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2429
2585
  }, {
2430
2586
  key: "updateBalanceDueAmount",
2431
2587
  value: (function () {
2432
- var _updateBalanceDueAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2588
+ var _updateBalanceDueAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2433
2589
  var remainingAmount, currentBalanceDueAmount;
2434
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2435
- while (1) switch (_context31.prev = _context31.next) {
2590
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2591
+ while (1) switch (_context32.prev = _context32.next) {
2436
2592
  case 0:
2437
- _context31.prev = 0;
2438
- _context31.next = 3;
2593
+ _context32.prev = 0;
2594
+ _context32.next = 3;
2439
2595
  return this.calculateRemainingAmountAsync();
2440
2596
  case 3:
2441
- remainingAmount = _context31.sent;
2597
+ remainingAmount = _context32.sent;
2442
2598
  currentBalanceDueAmount = this.store.balanceDueAmount; // 只有当剩余金额与当前 balanceDueAmount 不同时才更新
2443
2599
  if (!(remainingAmount !== currentBalanceDueAmount)) {
2444
- _context31.next = 12;
2600
+ _context32.next = 12;
2445
2601
  break;
2446
2602
  }
2447
2603
  this.store.balanceDueAmount = remainingAmount;
2448
2604
 
2449
2605
  // 发出 balanceDueAmount 变更事件
2450
- _context31.next = 9;
2606
+ _context32.next = 9;
2451
2607
  return this.core.effects.emit(CheckoutHooks.OnBalanceDueAmountChanged, {
2452
2608
  oldAmount: currentBalanceDueAmount,
2453
2609
  newAmount: remainingAmount,
@@ -2458,7 +2614,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2458
2614
  oldAmount: currentBalanceDueAmount,
2459
2615
  newAmount: remainingAmount
2460
2616
  });
2461
- _context31.next = 13;
2617
+ _context32.next = 13;
2462
2618
  break;
2463
2619
  case 12:
2464
2620
  this.logInfo('balanceDueAmount 无需更新,当前值已是最新:', {
@@ -2466,17 +2622,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2466
2622
  remainingAmount: remainingAmount
2467
2623
  });
2468
2624
  case 13:
2469
- _context31.next = 18;
2625
+ _context32.next = 18;
2470
2626
  break;
2471
2627
  case 15:
2472
- _context31.prev = 15;
2473
- _context31.t0 = _context31["catch"](0);
2474
- this.logError('更新 balanceDueAmount 失败:', _context31.t0);
2628
+ _context32.prev = 15;
2629
+ _context32.t0 = _context32["catch"](0);
2630
+ this.logError('更新 balanceDueAmount 失败:', _context32.t0);
2475
2631
  case 18:
2476
2632
  case "end":
2477
- return _context31.stop();
2633
+ return _context32.stop();
2478
2634
  }
2479
- }, _callee31, this, [[0, 15]]);
2635
+ }, _callee32, this, [[0, 15]]);
2480
2636
  }));
2481
2637
  function updateBalanceDueAmount() {
2482
2638
  return _updateBalanceDueAmount.apply(this, arguments);
@@ -2490,16 +2646,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2490
2646
  }, {
2491
2647
  key: "updateStateAmountToRemaining",
2492
2648
  value: (function () {
2493
- var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2649
+ var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2494
2650
  var remainingAmount, currentStateAmount;
2495
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2496
- while (1) switch (_context32.prev = _context32.next) {
2651
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2652
+ while (1) switch (_context33.prev = _context33.next) {
2497
2653
  case 0:
2498
- _context32.prev = 0;
2499
- _context32.next = 3;
2654
+ _context33.prev = 0;
2655
+ _context33.next = 3;
2500
2656
  return this.calculateRemainingAmountAsync();
2501
2657
  case 3:
2502
- remainingAmount = _context32.sent;
2658
+ remainingAmount = _context33.sent;
2503
2659
  currentStateAmount = this.store.stateAmount; // 只有当剩余金额与当前 stateAmount 不同时才更新
2504
2660
  if (remainingAmount !== currentStateAmount) {
2505
2661
  this.store.stateAmount = remainingAmount;
@@ -2522,23 +2678,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2522
2678
  }
2523
2679
 
2524
2680
  // 同步更新系统内部的 balanceDueAmount
2525
- _context32.next = 8;
2681
+ _context33.next = 8;
2526
2682
  return this.updateBalanceDueAmount();
2527
2683
  case 8:
2528
- _context32.next = 10;
2684
+ _context33.next = 10;
2529
2685
  return this.checkOrderPaymentCompletion();
2530
2686
  case 10:
2531
- _context32.next = 15;
2687
+ _context33.next = 15;
2532
2688
  break;
2533
2689
  case 12:
2534
- _context32.prev = 12;
2535
- _context32.t0 = _context32["catch"](0);
2536
- this.logError('更新 stateAmount 为剩余金额失败:', _context32.t0);
2690
+ _context33.prev = 12;
2691
+ _context33.t0 = _context33["catch"](0);
2692
+ this.logError('更新 stateAmount 为剩余金额失败:', _context33.t0);
2537
2693
  case 15:
2538
2694
  case "end":
2539
- return _context32.stop();
2695
+ return _context33.stop();
2540
2696
  }
2541
- }, _callee32, this, [[0, 12]]);
2697
+ }, _callee33, this, [[0, 12]]);
2542
2698
  }));
2543
2699
  function updateStateAmountToRemaining() {
2544
2700
  return _updateStateAmountToRemaining.apply(this, arguments);
@@ -2554,32 +2710,32 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2554
2710
  }, {
2555
2711
  key: "checkOrderPaymentCompletion",
2556
2712
  value: (function () {
2557
- var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2713
+ var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
2558
2714
  var remainingAmount, remainingValue, totalAmount, paidAmount, currentPayments, hasPaymentItems, allPaymentsHaveVoucherId, shouldAutoSync;
2559
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2560
- while (1) switch (_context33.prev = _context33.next) {
2715
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2716
+ while (1) switch (_context34.prev = _context34.next) {
2561
2717
  case 0:
2562
- _context33.prev = 0;
2718
+ _context34.prev = 0;
2563
2719
  if (this.store.currentOrder) {
2564
- _context33.next = 3;
2720
+ _context34.next = 3;
2565
2721
  break;
2566
2722
  }
2567
- return _context33.abrupt("return");
2723
+ return _context34.abrupt("return");
2568
2724
  case 3:
2569
- _context33.next = 5;
2725
+ _context34.next = 5;
2570
2726
  return this.calculateRemainingAmountAsync();
2571
2727
  case 5:
2572
- remainingAmount = _context33.sent;
2728
+ remainingAmount = _context34.sent;
2573
2729
  remainingValue = new Decimal(remainingAmount); // 当剩余金额小于等于0时,认为订单已完成支付
2574
2730
  if (!remainingValue.lte(0)) {
2575
- _context33.next = 29;
2731
+ _context34.next = 29;
2576
2732
  break;
2577
2733
  }
2578
2734
  totalAmount = this.store.currentOrder.total_amount;
2579
- _context33.next = 11;
2735
+ _context34.next = 11;
2580
2736
  return this.calculatePaidAmountAsync();
2581
2737
  case 11:
2582
- paidAmount = _context33.sent;
2738
+ paidAmount = _context34.sent;
2583
2739
  this.logInfo('检测到订单支付完成:', {
2584
2740
  orderUuid: this.store.currentOrder.uuid,
2585
2741
  orderId: this.store.currentOrder.order_id,
@@ -2590,11 +2746,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2590
2746
  });
2591
2747
 
2592
2748
  // 从 Payment 模块获取最新支付项,检查自动同步条件
2593
- _context33.next = 15;
2749
+ _context34.next = 15;
2594
2750
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
2595
2751
  );
2596
2752
  case 15:
2597
- currentPayments = _context33.sent;
2753
+ currentPayments = _context34.sent;
2598
2754
  // 检查自动同步条件:
2599
2755
  // 1. 待付金额为 0 ✓ (已在上面检查)
2600
2756
  // 2. 需要有支付项
@@ -2628,14 +2784,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2628
2784
  })
2629
2785
  });
2630
2786
  if (!shouldAutoSync) {
2631
- _context33.next = 26;
2787
+ _context34.next = 26;
2632
2788
  break;
2633
2789
  }
2634
2790
  this.logInfo('满足自动同步条件,开始同步订单到后端...');
2635
- _context33.next = 24;
2791
+ _context34.next = 24;
2636
2792
  return this.syncOrderToBackendWithReturn(false);
2637
2793
  case 24:
2638
- _context33.next = 27;
2794
+ _context34.next = 27;
2639
2795
  break;
2640
2796
  case 26:
2641
2797
  if (!hasPaymentItems) {
@@ -2644,7 +2800,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2644
2800
  this.logInfo('所有支付项均为代金券类型,跳过订单同步');
2645
2801
  }
2646
2802
  case 27:
2647
- _context33.next = 29;
2803
+ _context34.next = 29;
2648
2804
  return this.core.effects.emit(CheckoutHooks.OnOrderPaymentCompleted, {
2649
2805
  orderUuid: this.store.currentOrder.uuid,
2650
2806
  orderId: this.store.currentOrder.order_id,
@@ -2654,17 +2810,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2654
2810
  timestamp: Date.now()
2655
2811
  });
2656
2812
  case 29:
2657
- _context33.next = 34;
2813
+ _context34.next = 34;
2658
2814
  break;
2659
2815
  case 31:
2660
- _context33.prev = 31;
2661
- _context33.t0 = _context33["catch"](0);
2662
- this.logError('检查订单支付完成状态失败:', _context33.t0);
2816
+ _context34.prev = 31;
2817
+ _context34.t0 = _context34["catch"](0);
2818
+ this.logError('检查订单支付完成状态失败:', _context34.t0);
2663
2819
  case 34:
2664
2820
  case "end":
2665
- return _context33.stop();
2821
+ return _context34.stop();
2666
2822
  }
2667
- }, _callee33, this, [[0, 31]]);
2823
+ }, _callee34, this, [[0, 31]]);
2668
2824
  }));
2669
2825
  function checkOrderPaymentCompletion() {
2670
2826
  return _checkOrderPaymentCompletion.apply(this, arguments);
@@ -2682,11 +2838,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2682
2838
  }, {
2683
2839
  key: "syncOrderToBackendWithReturn",
2684
2840
  value: (function () {
2685
- var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
2841
+ var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
2686
2842
  var _this4 = this,
2687
- _this$store$currentOr17,
2843
+ _this$store$currentOr19,
2844
+ _this$store$currentOr20,
2688
2845
  _this$store$currentCu2,
2689
- _this$store$currentOr18,
2846
+ _this$store$currentOr21,
2690
2847
  _checkoutResponse3,
2691
2848
  _checkoutResponse4;
2692
2849
  var isManual,
@@ -2695,8 +2852,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2695
2852
  isUpdateOperation,
2696
2853
  paymentItems,
2697
2854
  processedPaymentItems,
2855
+ finalDepositAmount,
2856
+ manualDepositAmount,
2698
2857
  depositPaymentItems,
2699
2858
  calculatedDepositAmount,
2859
+ manualDepositValue,
2860
+ calculatedDepositValue,
2700
2861
  orderParams,
2701
2862
  startTime,
2702
2863
  checkoutResponse,
@@ -2714,14 +2875,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2714
2875
  _checkoutResponse7,
2715
2876
  updatedOrder,
2716
2877
  beforeManualUpdate,
2717
- _args34 = arguments;
2718
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2719
- while (1) switch (_context34.prev = _context34.next) {
2878
+ _args35 = arguments;
2879
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2880
+ while (1) switch (_context35.prev = _context35.next) {
2720
2881
  case 0:
2721
- isManual = _args34.length > 0 && _args34[0] !== undefined ? _args34[0] : false;
2722
- customPaymentItems = _args34.length > 1 ? _args34[1] : undefined;
2882
+ isManual = _args35.length > 0 && _args35[0] !== undefined ? _args35[0] : false;
2883
+ customPaymentItems = _args35.length > 1 ? _args35[1] : undefined;
2723
2884
  if (!(!this.store.localOrderData || !this.store.currentOrder)) {
2724
- _context34.next = 4;
2885
+ _context35.next = 4;
2725
2886
  break;
2726
2887
  }
2727
2888
  throw new Error('缺少必要的订单数据,无法同步到后端');
@@ -2740,17 +2901,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2740
2901
  });
2741
2902
 
2742
2903
  // 获取当前订单的支付项
2743
- _context34.t0 = customPaymentItems;
2744
- if (_context34.t0) {
2745
- _context34.next = 13;
2904
+ _context35.t0 = customPaymentItems;
2905
+ if (_context35.t0) {
2906
+ _context35.next = 13;
2746
2907
  break;
2747
2908
  }
2748
- _context34.next = 12;
2909
+ _context35.next = 12;
2749
2910
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
2750
2911
  case 12:
2751
- _context34.t0 = _context34.sent;
2912
+ _context35.t0 = _context35.sent;
2752
2913
  case 13:
2753
- paymentItems = _context34.t0;
2914
+ paymentItems = _context35.t0;
2754
2915
  // 处理支付项数据,确保包含完整的 metadata
2755
2916
  processedPaymentItems = paymentItems.map(function (item) {
2756
2917
  var _item$metadata, _item$metadata2;
@@ -2760,7 +2921,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2760
2921
  shop_wallet_pass_id: ((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.shop_wallet_pass_id) || _this4.otherParams.shop_wallet_pass_id
2761
2922
  })
2762
2923
  });
2763
- }); // 计算定金支付项的总金额(order_payment_type="deposit")
2924
+ }); // 确定最终的定金金额:优先使用手动设置的值,否则从支付项中计算
2925
+ manualDepositAmount = ((_this$store$currentOr19 = this.store.currentOrder) === null || _this$store$currentOr19 === void 0 ? void 0 : _this$store$currentOr19.deposit_amount) || '0.00'; // 计算定金支付项的总金额(order_payment_type="deposit")
2764
2926
  depositPaymentItems = processedPaymentItems.filter(function (item) {
2765
2927
  return item.order_payment_type === 'deposit' && item.status !== 'voided';
2766
2928
  });
@@ -2770,8 +2932,35 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2770
2932
  // 包含抹零计算的有效支付金额
2771
2933
  var effectiveAmount = amount.add(roundingAmount.abs());
2772
2934
  return sum.add(effectiveAmount);
2773
- }, new Decimal(0)).toFixed(2);
2774
- this.logInfo('计算定金支付项总金额', {
2935
+ }, new Decimal(0)).toFixed(2); // 优先级逻辑:手动设置的定金金额 > 从支付项计算的金额
2936
+ manualDepositValue = new Decimal(manualDepositAmount);
2937
+ calculatedDepositValue = new Decimal(calculatedDepositAmount);
2938
+ if (manualDepositValue.gt(0)) {
2939
+ // 如果手动设置了定金金额且大于0,使用手动设置的值
2940
+ finalDepositAmount = manualDepositAmount;
2941
+ this.logInfo('使用手动设置的定金金额', {
2942
+ manualDepositAmount: manualDepositAmount,
2943
+ calculatedDepositAmount: calculatedDepositAmount,
2944
+ reason: '用户通过setDepositAmountAsync手动设置了定金金额'
2945
+ });
2946
+ } else if (calculatedDepositValue.gt(0)) {
2947
+ // 如果没有手动设置但有定金类型的支付项,使用计算值
2948
+ finalDepositAmount = calculatedDepositAmount;
2949
+ this.logInfo('使用从支付项计算的定金金额', {
2950
+ manualDepositAmount: manualDepositAmount,
2951
+ calculatedDepositAmount: calculatedDepositAmount,
2952
+ reason: '未手动设置定金金额,从定金类型支付项计算得出'
2953
+ });
2954
+ } else {
2955
+ // 都为0,使用0
2956
+ finalDepositAmount = '0.00';
2957
+ this.logInfo('定金金额为0', {
2958
+ manualDepositAmount: manualDepositAmount,
2959
+ calculatedDepositAmount: calculatedDepositAmount,
2960
+ reason: '手动设置和计算值均为0'
2961
+ });
2962
+ }
2963
+ this.logInfo('定金金额确定结果', {
2775
2964
  depositPaymentItemsCount: depositPaymentItems.length,
2776
2965
  depositPaymentItems: depositPaymentItems.map(function (item) {
2777
2966
  return {
@@ -2783,8 +2972,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2783
2972
  status: item.status
2784
2973
  };
2785
2974
  }),
2975
+ manualDepositAmount: manualDepositAmount,
2786
2976
  calculatedDepositAmount: calculatedDepositAmount,
2787
- originalDepositAmount: ((_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.deposit_amount) || '0.00'
2977
+ finalDepositAmount: finalDepositAmount,
2978
+ isDeposit: ((_this$store$currentOr20 = this.store.currentOrder) === null || _this$store$currentOr20 === void 0 ? void 0 : _this$store$currentOr20.is_deposit) || 0
2788
2979
  });
2789
2980
 
2790
2981
  // 构造订单参数,直接使用 localOrderData 中已处理好的数据
@@ -2806,9 +2997,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2806
2997
  currency_code: this.otherParams.currency_code,
2807
2998
  currency_symbol: this.otherParams.currency_symbol,
2808
2999
  currency_format: this.otherParams.currency_format,
2809
- is_deposit: ((_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.is_deposit) || 0,
2810
- deposit_amount: calculatedDepositAmount,
2811
- // 使用从支付项中计算出的定金金额
3000
+ is_deposit: ((_this$store$currentOr21 = this.store.currentOrder) === null || _this$store$currentOr21 === void 0 ? void 0 : _this$store$currentOr21.is_deposit) || 0,
3001
+ deposit_amount: finalDepositAmount,
3002
+ // 使用最终确定的定金金额(手动设置优先)
2812
3003
  product_tax_fee: this.store.localOrderData.tax_fee,
2813
3004
  note: this.store.localOrderData.shop_note
2814
3005
  }); // 如果是更新操作,需要在参数中包含真实的订单ID
@@ -2823,7 +3014,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2823
3014
 
2824
3015
  // 发送下单接口请求开始事件
2825
3016
  startTime = Date.now();
2826
- _context34.next = 23;
3017
+ _context35.next = 27;
2827
3018
  return this.core.effects.emit(CheckoutHooks.OnOrderSubmitStart, {
2828
3019
  orderUuid: this.store.currentOrder.uuid,
2829
3020
  operation: isUpdateOperation ? 'update' : 'create',
@@ -2831,9 +3022,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2831
3022
  paymentItemCount: paymentItems.length,
2832
3023
  timestamp: startTime
2833
3024
  });
2834
- case 23:
3025
+ case 27:
2835
3026
  submitSuccess = false;
2836
- _context34.prev = 24;
3027
+ _context35.prev = 28;
2837
3028
  // 记录接口调用参数
2838
3029
  this.logInfo('Calling backend checkout API', _objectSpread({
2839
3030
  url: '/order/checkout',
@@ -2841,23 +3032,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2841
3032
  }, orderParams));
2842
3033
 
2843
3034
  // 调用 Order 模块的专用 createOrderByCheckout 方法
2844
- _context34.next = 28;
3035
+ _context35.next = 32;
2845
3036
  return this.order.createOrderByCheckout(orderParams);
2846
- case 28:
2847
- checkoutResponse = _context34.sent;
3037
+ case 32:
3038
+ checkoutResponse = _context35.sent;
2848
3039
  submitSuccess = true;
2849
3040
  this.logInfo('下单接口调用成功', checkoutResponse);
2850
- _context34.next = 41;
3041
+ _context35.next = 45;
2851
3042
  break;
2852
- case 33:
2853
- _context34.prev = 33;
2854
- _context34.t1 = _context34["catch"](24);
3043
+ case 37:
3044
+ _context35.prev = 37;
3045
+ _context35.t1 = _context35["catch"](28);
2855
3046
  submitSuccess = false;
2856
- submitError = _context34.t1 instanceof Error ? _context34.t1.message : String(_context34.t1);
3047
+ submitError = _context35.t1 instanceof Error ? _context35.t1.message : String(_context35.t1);
2857
3048
  this.logError('下单接口调用失败:', submitError);
2858
3049
 
2859
3050
  // 发送订单同步失败事件(网络错误或请求失败)
2860
- _context34.next = 40;
3051
+ _context35.next = 44;
2861
3052
  return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
2862
3053
  orderUuid: this.store.currentOrder.uuid,
2863
3054
  operation: isUpdateOperation ? 'update' : 'create',
@@ -2867,11 +3058,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2867
3058
  duration: Date.now() - startTime,
2868
3059
  timestamp: Date.now()
2869
3060
  });
2870
- case 40:
2871
- throw _context34.t1;
2872
- case 41:
2873
- _context34.prev = 41;
2874
- _context34.next = 44;
3061
+ case 44:
3062
+ throw _context35.t1;
3063
+ case 45:
3064
+ _context35.prev = 45;
3065
+ _context35.next = 48;
2875
3066
  return this.core.effects.emit(CheckoutHooks.OnOrderSubmitEnd, {
2876
3067
  success: submitSuccess,
2877
3068
  orderUuid: this.store.currentOrder.uuid,
@@ -2882,18 +3073,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2882
3073
  duration: Date.now() - startTime,
2883
3074
  timestamp: Date.now()
2884
3075
  });
2885
- case 44:
2886
- return _context34.finish(41);
2887
- case 45:
3076
+ case 48:
3077
+ return _context35.finish(45);
3078
+ case 49:
2888
3079
  // 检查响应状态是否为成功状态
2889
3080
  responseStatus = (_checkoutResponse3 = checkoutResponse) === null || _checkoutResponse3 === void 0 ? void 0 : _checkoutResponse3.status;
2890
3081
  isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse4 = checkoutResponse) === null || _checkoutResponse4 === void 0 ? void 0 : _checkoutResponse4.code) === 200;
2891
3082
  if (isSuccessResponse) {
2892
- _context34.next = 52;
3083
+ _context35.next = 56;
2893
3084
  break;
2894
3085
  }
2895
3086
  errorMessage = ((_checkoutResponse5 = checkoutResponse) === null || _checkoutResponse5 === void 0 ? void 0 : _checkoutResponse5.message) || '订单同步失败,后端返回非成功状态'; // 发送订单同步失败事件
2896
- _context34.next = 51;
3087
+ _context35.next = 55;
2897
3088
  return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
2898
3089
  orderUuid: this.store.currentOrder.uuid,
2899
3090
  operation: isUpdateOperation ? 'update' : 'create',
@@ -2904,18 +3095,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2904
3095
  duration: Date.now() - startTime,
2905
3096
  timestamp: Date.now()
2906
3097
  });
2907
- case 51:
3098
+ case 55:
2908
3099
  throw new Error(errorMessage);
2909
- case 52:
3100
+ case 56:
2910
3101
  if (!isUpdateOperation) {
2911
- _context34.next = 56;
3102
+ _context35.next = 60;
2912
3103
  break;
2913
3104
  }
2914
3105
  // 更新操作:使用现有的订单ID
2915
3106
  realOrderId = currentOrderId;
2916
- _context34.next = 75;
3107
+ _context35.next = 79;
2917
3108
  break;
2918
- case 56:
3109
+ case 60:
2919
3110
  // 创建操作:从响应中提取新的订单ID
2920
3111
  extractedOrderId = (_checkoutResponse6 = checkoutResponse) === null || _checkoutResponse6 === void 0 || (_checkoutResponse6 = _checkoutResponse6.data) === null || _checkoutResponse6 === void 0 ? void 0 : _checkoutResponse6.order_id; // 如果data.order_id不存在,尝试直接从根级获取
2921
3112
  if (!extractedOrderId) {
@@ -2937,11 +3128,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2937
3128
  oldOrderId: this.store.currentOrder.order_id,
2938
3129
  newOrderId: realOrderId
2939
3130
  });
2940
- _context34.prev = 62;
2941
- _context34.next = 65;
3131
+ _context35.prev = 66;
3132
+ _context35.next = 69;
2942
3133
  return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, realOrderId);
2943
- case 65:
2944
- updatedOrder = _context34.sent;
3134
+ case 69:
3135
+ updatedOrder = _context35.sent;
2945
3136
  this.logInfo('Payment模块替换订单ID结果:', {
2946
3137
  wasSuccessful: !!updatedOrder,
2947
3138
  returnedOrderId: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.order_id,
@@ -2967,22 +3158,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2967
3158
  目标ID: realOrderId
2968
3159
  });
2969
3160
  }
2970
- _context34.next = 75;
3161
+ _context35.next = 79;
2971
3162
  break;
2972
- case 70:
2973
- _context34.prev = 70;
2974
- _context34.t2 = _context34["catch"](62);
2975
- this.logError('调用Payment模块替换订单ID时发生错误:', _context34.t2);
3163
+ case 74:
3164
+ _context35.prev = 74;
3165
+ _context35.t2 = _context35["catch"](66);
3166
+ this.logError('调用Payment模块替换订单ID时发生错误:', _context35.t2);
2976
3167
 
2977
3168
  // 发生错误时也进行手动替换
2978
3169
  this.store.currentOrder.order_id = realOrderId;
2979
3170
  this.logInfo('错误恢复:手动设置订单ID:', realOrderId);
2980
- case 75:
3171
+ case 79:
2981
3172
  // 标记订单已同步
2982
3173
  this.store.isOrderSynced = true;
2983
3174
 
2984
3175
  // 触发订单同步完成事件
2985
- _context34.next = 78;
3176
+ _context35.next = 82;
2986
3177
  return this.core.effects.emit(CheckoutHooks.OnOrderSynced, {
2987
3178
  orderUuid: this.store.currentOrder.uuid,
2988
3179
  realOrderId: realOrderId,
@@ -2991,18 +3182,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2991
3182
  isManual: isManual,
2992
3183
  response: checkoutResponse
2993
3184
  });
2994
- case 78:
2995
- return _context34.abrupt("return", {
3185
+ case 82:
3186
+ return _context35.abrupt("return", {
2996
3187
  success: true,
2997
3188
  orderId: realOrderId,
2998
3189
  orderUuid: this.store.currentOrder.uuid,
2999
3190
  response: checkoutResponse
3000
3191
  });
3001
- case 79:
3192
+ case 83:
3002
3193
  case "end":
3003
- return _context34.stop();
3194
+ return _context35.stop();
3004
3195
  }
3005
- }, _callee34, this, [[24, 33, 41, 45], [62, 70]]);
3196
+ }, _callee35, this, [[28, 37, 45, 49], [66, 74]]);
3006
3197
  }));
3007
3198
  function syncOrderToBackendWithReturn() {
3008
3199
  return _syncOrderToBackendWithReturn.apply(this, arguments);
@@ -3012,15 +3203,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3012
3203
  }, {
3013
3204
  key: "setOtherParams",
3014
3205
  value: function () {
3015
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
3206
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
3016
3207
  var _ref5,
3017
3208
  _ref5$cover,
3018
3209
  cover,
3019
- _args35 = arguments;
3020
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3021
- while (1) switch (_context35.prev = _context35.next) {
3210
+ _args36 = arguments;
3211
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3212
+ while (1) switch (_context36.prev = _context36.next) {
3022
3213
  case 0:
3023
- _ref5 = _args35.length > 1 && _args35[1] !== undefined ? _args35[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
3214
+ _ref5 = _args36.length > 1 && _args36[1] !== undefined ? _args36[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
3024
3215
  if (cover) {
3025
3216
  this.otherParams = params;
3026
3217
  } else {
@@ -3028,11 +3219,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3028
3219
  }
3029
3220
  case 2:
3030
3221
  case "end":
3031
- return _context35.stop();
3222
+ return _context36.stop();
3032
3223
  }
3033
- }, _callee35, this);
3224
+ }, _callee36, this);
3034
3225
  }));
3035
- function setOtherParams(_x25) {
3226
+ function setOtherParams(_x26) {
3036
3227
  return _setOtherParams.apply(this, arguments);
3037
3228
  }
3038
3229
  return setOtherParams;
@@ -3049,22 +3240,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3049
3240
  }, {
3050
3241
  key: "editOrderNoteByOrderIdAsync",
3051
3242
  value: (function () {
3052
- var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(orderId, note) {
3243
+ var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(orderId, note) {
3053
3244
  var response, previousNote, errorMessage, _errorMessage;
3054
- return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3055
- while (1) switch (_context36.prev = _context36.next) {
3245
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3246
+ while (1) switch (_context37.prev = _context37.next) {
3056
3247
  case 0:
3057
3248
  this.logInfo('editOrderNoteByOrderIdAsync called', {
3058
3249
  orderId: orderId,
3059
3250
  note: note,
3060
3251
  noteLength: note.length
3061
3252
  });
3062
- _context36.prev = 1;
3253
+ _context37.prev = 1;
3063
3254
  if (orderId) {
3064
- _context36.next = 4;
3255
+ _context37.next = 4;
3065
3256
  break;
3066
3257
  }
3067
- return _context36.abrupt("return", {
3258
+ return _context37.abrupt("return", {
3068
3259
  success: false,
3069
3260
  message: '订单ID不能为空',
3070
3261
  orderId: orderId
@@ -3080,12 +3271,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3080
3271
  });
3081
3272
 
3082
3273
  // 调用后端API修改订单备注
3083
- _context36.next = 7;
3274
+ _context37.next = 7;
3084
3275
  return this.request.put("/order/order/".concat(orderId, "/note"), {
3085
3276
  note: note
3086
3277
  });
3087
3278
  case 7:
3088
- response = _context36.sent;
3279
+ response = _context37.sent;
3089
3280
  this.logInfo('订单备注编辑响应:', {
3090
3281
  orderId: orderId,
3091
3282
  status: response.status,
@@ -3095,11 +3286,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3095
3286
 
3096
3287
  // 检查响应状态
3097
3288
  if (!(response.status === true || response.status === 200)) {
3098
- _context36.next = 18;
3289
+ _context37.next = 18;
3099
3290
  break;
3100
3291
  }
3101
3292
  if (!(this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId)))) {
3102
- _context36.next = 15;
3293
+ _context37.next = 15;
3103
3294
  break;
3104
3295
  }
3105
3296
  // 获取修改前的备注用于事件
@@ -3109,7 +3300,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3109
3300
  }
3110
3301
 
3111
3302
  // 触发订单备注变更事件
3112
- _context36.next = 15;
3303
+ _context37.next = 15;
3113
3304
  return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
3114
3305
  orderUuid: this.store.currentOrder.uuid,
3115
3306
  oldNote: previousNote,
@@ -3117,7 +3308,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3117
3308
  timestamp: Date.now()
3118
3309
  });
3119
3310
  case 15:
3120
- return _context36.abrupt("return", {
3311
+ return _context37.abrupt("return", {
3121
3312
  success: true,
3122
3313
  message: response.message || '订单备注修改成功',
3123
3314
  orderId: orderId
@@ -3126,31 +3317,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3126
3317
  // API返回失败状态
3127
3318
  errorMessage = response.message || '订单备注修改失败';
3128
3319
  this.logError("\u8BA2\u5355 ".concat(orderId, " \u5907\u6CE8\u4FEE\u6539\u5931\u8D25:"), errorMessage);
3129
- return _context36.abrupt("return", {
3320
+ return _context37.abrupt("return", {
3130
3321
  success: false,
3131
3322
  message: errorMessage,
3132
3323
  orderId: orderId
3133
3324
  });
3134
3325
  case 21:
3135
- _context36.next = 28;
3326
+ _context37.next = 28;
3136
3327
  break;
3137
3328
  case 23:
3138
- _context36.prev = 23;
3139
- _context36.t0 = _context36["catch"](1);
3140
- this.logError('编辑订单备注失败:', _context36.t0);
3141
- _errorMessage = _context36.t0 instanceof Error ? _context36.t0.message : '网络错误或服务器异常';
3142
- return _context36.abrupt("return", {
3329
+ _context37.prev = 23;
3330
+ _context37.t0 = _context37["catch"](1);
3331
+ this.logError('编辑订单备注失败:', _context37.t0);
3332
+ _errorMessage = _context37.t0 instanceof Error ? _context37.t0.message : '网络错误或服务器异常';
3333
+ return _context37.abrupt("return", {
3143
3334
  success: false,
3144
3335
  message: "\u7F16\u8F91\u8BA2\u5355\u5907\u6CE8\u5931\u8D25: ".concat(_errorMessage),
3145
3336
  orderId: orderId
3146
3337
  });
3147
3338
  case 28:
3148
3339
  case "end":
3149
- return _context36.stop();
3340
+ return _context37.stop();
3150
3341
  }
3151
- }, _callee36, this, [[1, 23]]);
3342
+ }, _callee37, this, [[1, 23]]);
3152
3343
  }));
3153
- function editOrderNoteByOrderIdAsync(_x26, _x27) {
3344
+ function editOrderNoteByOrderIdAsync(_x27, _x28) {
3154
3345
  return _editOrderNoteByOrderIdAsync.apply(this, arguments);
3155
3346
  }
3156
3347
  return editOrderNoteByOrderIdAsync;
@@ -3167,11 +3358,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3167
3358
  }, {
3168
3359
  key: "sendCustomerPayLinkAsync",
3169
3360
  value: (function () {
3170
- var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
3361
+ var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
3171
3362
  var _params$order_ids, _params$emails;
3172
3363
  var emailRegex, invalidEmails, requestBody, response, errorMessage, _errorMessage2;
3173
- return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3174
- while (1) switch (_context37.prev = _context37.next) {
3364
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3365
+ while (1) switch (_context38.prev = _context38.next) {
3175
3366
  case 0:
3176
3367
  this.logInfo('sendCustomerPayLinkAsync called', {
3177
3368
  orderIds: params.order_ids,
@@ -3180,21 +3371,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3180
3371
  emailsCount: ((_params$emails = params.emails) === null || _params$emails === void 0 ? void 0 : _params$emails.length) || 0,
3181
3372
  notifyAction: params.notify_action || 'order_payment_reminder'
3182
3373
  });
3183
- _context37.prev = 1;
3374
+ _context38.prev = 1;
3184
3375
  if (!(!params.order_ids || params.order_ids.length === 0)) {
3185
- _context37.next = 4;
3376
+ _context38.next = 4;
3186
3377
  break;
3187
3378
  }
3188
- return _context37.abrupt("return", {
3379
+ return _context38.abrupt("return", {
3189
3380
  success: false,
3190
3381
  message: '订单ID列表不能为空'
3191
3382
  });
3192
3383
  case 4:
3193
3384
  if (!(!params.emails || params.emails.length === 0)) {
3194
- _context37.next = 6;
3385
+ _context38.next = 6;
3195
3386
  break;
3196
3387
  }
3197
- return _context37.abrupt("return", {
3388
+ return _context38.abrupt("return", {
3198
3389
  success: false,
3199
3390
  message: '邮箱地址列表不能为空'
3200
3391
  });
@@ -3205,10 +3396,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3205
3396
  return !emailRegex.test(email);
3206
3397
  });
3207
3398
  if (!(invalidEmails.length > 0)) {
3208
- _context37.next = 10;
3399
+ _context38.next = 10;
3209
3400
  break;
3210
3401
  }
3211
- return _context37.abrupt("return", {
3402
+ return _context38.abrupt("return", {
3212
3403
  success: false,
3213
3404
  message: "\u90AE\u7BB1\u683C\u5F0F\u65E0\u6548: ".concat(invalidEmails.join(', '))
3214
3405
  });
@@ -3224,10 +3415,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3224
3415
  }, requestBody));
3225
3416
 
3226
3417
  // 调用后端API发送邮件
3227
- _context37.next = 14;
3418
+ _context38.next = 14;
3228
3419
  return this.request.post('/order/batch-email', requestBody);
3229
3420
  case 14:
3230
- response = _context37.sent;
3421
+ response = _context38.sent;
3231
3422
  this.logInfo('支付链接邮件发送响应:', {
3232
3423
  status: response.status,
3233
3424
  message: response.message,
@@ -3237,10 +3428,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3237
3428
 
3238
3429
  // 检查响应状态
3239
3430
  if (!(response.status === true || response.status === 200)) {
3240
- _context37.next = 20;
3431
+ _context38.next = 20;
3241
3432
  break;
3242
3433
  }
3243
- return _context37.abrupt("return", {
3434
+ return _context38.abrupt("return", {
3244
3435
  success: true,
3245
3436
  message: response.message || '支付链接邮件发送成功'
3246
3437
  });
@@ -3248,29 +3439,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3248
3439
  // API返回失败状态
3249
3440
  errorMessage = response.message || '支付链接邮件发送失败';
3250
3441
  console.error('[Checkout] 支付链接邮件发送失败:', errorMessage);
3251
- return _context37.abrupt("return", {
3442
+ return _context38.abrupt("return", {
3252
3443
  success: false,
3253
3444
  message: errorMessage
3254
3445
  });
3255
3446
  case 23:
3256
- _context37.next = 30;
3447
+ _context38.next = 30;
3257
3448
  break;
3258
3449
  case 25:
3259
- _context37.prev = 25;
3260
- _context37.t0 = _context37["catch"](1);
3261
- this.logError('发送客户支付链接邮件失败:', _context37.t0);
3262
- _errorMessage2 = _context37.t0 instanceof Error ? _context37.t0.message : '网络错误或服务器异常';
3263
- return _context37.abrupt("return", {
3450
+ _context38.prev = 25;
3451
+ _context38.t0 = _context38["catch"](1);
3452
+ this.logError('发送客户支付链接邮件失败:', _context38.t0);
3453
+ _errorMessage2 = _context38.t0 instanceof Error ? _context38.t0.message : '网络错误或服务器异常';
3454
+ return _context38.abrupt("return", {
3264
3455
  success: false,
3265
3456
  message: "\u53D1\u9001\u652F\u4ED8\u94FE\u63A5\u90AE\u4EF6\u5931\u8D25: ".concat(_errorMessage2)
3266
3457
  });
3267
3458
  case 30:
3268
3459
  case "end":
3269
- return _context37.stop();
3460
+ return _context38.stop();
3270
3461
  }
3271
- }, _callee37, this, [[1, 25]]);
3462
+ }, _callee38, this, [[1, 25]]);
3272
3463
  }));
3273
- function sendCustomerPayLinkAsync(_x28) {
3464
+ function sendCustomerPayLinkAsync(_x29) {
3274
3465
  return _sendCustomerPayLinkAsync.apply(this, arguments);
3275
3466
  }
3276
3467
  return sendCustomerPayLinkAsync;
@@ -3285,24 +3476,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3285
3476
  }, {
3286
3477
  key: "roundAmountAsync",
3287
3478
  value: (function () {
3288
- var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(amount) {
3479
+ var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(amount) {
3289
3480
  var _this$otherParams$ord, _this$otherParams$ord2;
3290
3481
  var result;
3291
- return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3292
- while (1) switch (_context38.prev = _context38.next) {
3482
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3483
+ while (1) switch (_context39.prev = _context39.next) {
3293
3484
  case 0:
3294
- _context38.next = 2;
3485
+ _context39.next = 2;
3295
3486
  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);
3296
3487
  case 2:
3297
- result = _context38.sent;
3298
- return _context38.abrupt("return", result);
3488
+ result = _context39.sent;
3489
+ return _context39.abrupt("return", result);
3299
3490
  case 4:
3300
3491
  case "end":
3301
- return _context38.stop();
3492
+ return _context39.stop();
3302
3493
  }
3303
- }, _callee38, this);
3494
+ }, _callee39, this);
3304
3495
  }));
3305
- function roundAmountAsync(_x29) {
3496
+ function roundAmountAsync(_x30) {
3306
3497
  return _roundAmountAsync.apply(this, arguments);
3307
3498
  }
3308
3499
  return roundAmountAsync;
@@ -3310,10 +3501,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3310
3501
  }, {
3311
3502
  key: "destroy",
3312
3503
  value: function () {
3313
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
3504
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40() {
3314
3505
  var _this$order, _this$order$destroy, _this$payment, _this$payment$destroy;
3315
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3316
- while (1) switch (_context39.prev = _context39.next) {
3506
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3507
+ while (1) switch (_context40.prev = _context40.next) {
3317
3508
  case 0:
3318
3509
  // 清理钱包模块的所有缓存数据
3319
3510
  this.payment.wallet.clearAllCache();
@@ -3322,10 +3513,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3322
3513
  this.core.effects.offByModuleDestroy(this.name);
3323
3514
 
3324
3515
  // 销毁子模块
3325
- _context39.next = 4;
3516
+ _context40.next = 4;
3326
3517
  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);
3327
3518
  case 4:
3328
- _context39.next = 6;
3519
+ _context40.next = 6;
3329
3520
  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);
3330
3521
  case 6:
3331
3522
  // 取消注册模块
@@ -3333,9 +3524,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3333
3524
  console.log('[Checkout] 已销毁');
3334
3525
  case 8:
3335
3526
  case "end":
3336
- return _context39.stop();
3527
+ return _context40.stop();
3337
3528
  }
3338
- }, _callee39, this);
3529
+ }, _callee40, this);
3339
3530
  }));
3340
3531
  function destroy() {
3341
3532
  return _destroy.apply(this, arguments);
@@ -3350,12 +3541,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3350
3541
  }, {
3351
3542
  key: "resetStoreStateAsync",
3352
3543
  value: (function () {
3353
- var _resetStoreStateAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40() {
3544
+ var _resetStoreStateAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
3354
3545
  var prevOrderInfo;
3355
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3356
- while (1) switch (_context40.prev = _context40.next) {
3546
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3547
+ while (1) switch (_context41.prev = _context41.next) {
3357
3548
  case 0:
3358
- _context40.prev = 0;
3549
+ _context41.prev = 0;
3359
3550
  prevOrderInfo = this.store.currentOrder ? {
3360
3551
  uuid: this.store.currentOrder.uuid,
3361
3552
  orderId: this.store.currentOrder.order_id
@@ -3384,26 +3575,26 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3384
3575
 
3385
3576
  // 触发订单清理事件(如果之前有订单)
3386
3577
  if (!prevOrderInfo) {
3387
- _context40.next = 17;
3578
+ _context41.next = 17;
3388
3579
  break;
3389
3580
  }
3390
- _context40.next = 17;
3581
+ _context41.next = 17;
3391
3582
  return this.core.effects.emit(CheckoutHooks.OnOrderCleared, {
3392
3583
  previousOrder: prevOrderInfo,
3393
3584
  timestamp: Date.now()
3394
3585
  });
3395
3586
  case 17:
3396
- _context40.next = 22;
3587
+ _context41.next = 22;
3397
3588
  break;
3398
3589
  case 19:
3399
- _context40.prev = 19;
3400
- _context40.t0 = _context40["catch"](0);
3401
- console.error('[Checkout] 重置 store 状态失败:', _context40.t0);
3590
+ _context41.prev = 19;
3591
+ _context41.t0 = _context41["catch"](0);
3592
+ console.error('[Checkout] 重置 store 状态失败:', _context41.t0);
3402
3593
  case 22:
3403
3594
  case "end":
3404
- return _context40.stop();
3595
+ return _context41.stop();
3405
3596
  }
3406
- }, _callee40, this, [[0, 19]]);
3597
+ }, _callee41, this, [[0, 19]]);
3407
3598
  }));
3408
3599
  function resetStoreStateAsync() {
3409
3600
  return _resetStoreStateAsync.apply(this, arguments);