@pisell/pisellos 2.1.28 → 2.1.30

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