@pisell/pisellos 0.0.285 → 0.0.287

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.
@@ -398,8 +398,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
398
398
  key: "initWalletData",
399
399
  value: function () {
400
400
  var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
401
- var _this$store$currentOr3, _this$store$currentCu, _this$store$currentOr4;
402
- var amountInfo, walletBusinessData;
401
+ var _this$store$currentOr3, _this$store$currentCu, _this$store$currentOr5;
402
+ var amountInfo, walletBusinessData, _this$store$currentOr4;
403
403
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
404
404
  while (1) switch (_context8.prev = _context8.next) {
405
405
  case 0:
@@ -424,31 +424,34 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
424
424
  subTotal: amountInfo.subTotal
425
425
  },
426
426
  products: this.getProductListByOrder()
427
- }, params);
427
+ }, params); // 判断订单是否已经同步,如果是则追加payment_order_id参数
428
+ if (this.store.isOrderSynced) {
429
+ walletBusinessData.payment_order_id = (_this$store$currentOr4 = this.store.currentOrder) === null || _this$store$currentOr4 === void 0 ? void 0 : _this$store$currentOr4.order_id;
430
+ }
428
431
  this.logInfo('开始拉取:initializeWalletDataFromBusinessAsync', {
429
432
  walletBusinessData: walletBusinessData
430
433
  });
431
- _context8.next = 9;
434
+ _context8.next = 10;
432
435
  return this.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
433
- case 9:
436
+ case 10:
434
437
  this.logInfo('调用结束:initializeWalletDataFromBusinessAsync', {
435
438
  walletBusinessData: walletBusinessData
436
439
  });
437
440
 
438
441
  // 因为上面是接口 这里最好检查一下还有没有 currentOrder 了,如果没有,则不触发事件
439
442
  if (this.store.currentOrder) {
440
- _context8.next = 12;
443
+ _context8.next = 13;
441
444
  break;
442
445
  }
443
446
  return _context8.abrupt("return");
444
- case 12:
447
+ case 13:
445
448
  this.logInfo('initWalletData currentOrder found', {
446
449
  currentOrder: this.store.currentOrder
447
450
  });
448
451
  // 触发钱包数据初始化完成事件
449
- _context8.next = 15;
452
+ _context8.next = 16;
450
453
  return this.core.effects.emit(CheckoutHooks.OnWalletDataInitialized, {
451
- orderUuid: (_this$store$currentOr4 = this.store.currentOrder) === null || _this$store$currentOr4 === void 0 ? void 0 : _this$store$currentOr4.uuid,
454
+ orderUuid: (_this$store$currentOr5 = this.store.currentOrder) === null || _this$store$currentOr5 === void 0 ? void 0 : _this$store$currentOr5.uuid,
452
455
  customerId: walletBusinessData.customer_id,
453
456
  walletBusinessData: {
454
457
  customer_id: walletBusinessData.customer_id,
@@ -457,7 +460,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
457
460
  },
458
461
  timestamp: Date.now()
459
462
  });
460
- case 15:
463
+ case 16:
461
464
  case "end":
462
465
  return _context8.stop();
463
466
  }
@@ -605,6 +608,173 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
605
608
  }
606
609
  return createLocalOrderAsync;
607
610
  }()
611
+ /**
612
+ * 更新本地订单(已同步后端的订单)并设置为当前订单
613
+ *
614
+ * 通过传入真实的 orderId,对已缓存的订单数据进行更新,
615
+ * 会覆盖 order_info 与金额等字段,并重新计算待付金额,最后设置为 currentOrder。
616
+ */
617
+ )
618
+ }, {
619
+ key: "updateLocalOrderAsync",
620
+ value: (function () {
621
+ var _updateLocalOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
622
+ var _params$orderData6, _params$orderData7, _params$cartSummary2, _params$totalInfo5, _params$totalInfo6, _params$totalInfo7, _params$totalInfo8;
623
+ var validation, amountInfo, customerInfo, allOrders, existingOrder, _updated$payment, totalAmount, activePayments, paidAmount, remaining, updated, created;
624
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
625
+ while (1) switch (_context10.prev = _context10.next) {
626
+ case 0:
627
+ this.logInfo('updateLocalOrderAsync called', {
628
+ orderId: params.orderId,
629
+ orderDataType: (_params$orderData6 = params.orderData) === null || _params$orderData6 === void 0 ? void 0 : _params$orderData6.type,
630
+ bookingsCount: ((_params$orderData7 = params.orderData) === null || _params$orderData7 === void 0 || (_params$orderData7 = _params$orderData7.bookings) === null || _params$orderData7 === void 0 ? void 0 : _params$orderData7.length) || 0,
631
+ cartSummaryCount: ((_params$cartSummary2 = params.cartSummary) === null || _params$cartSummary2 === void 0 ? void 0 : _params$cartSummary2.length) || 0,
632
+ totalInfoKeys: params.totalInfo ? Object.keys(params.totalInfo) : []
633
+ });
634
+
635
+ // 基础校验
636
+ validation = validateLocalOrderData(params.orderData);
637
+ if (validation.valid) {
638
+ _context10.next = 4;
639
+ break;
640
+ }
641
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u8BA2\u5355\u6570\u636E\u9A8C\u8BC1\u5931\u8D25: ".concat(validation.errors.join(', ')));
642
+ case 4:
643
+ // 计算金额
644
+ amountInfo = extractAmountFromCartSummary(params.cartSummary); // 规范化补充字段
645
+ params.orderData.created_at = formatDateTime(new Date());
646
+ params.orderData.platform = 'pos';
647
+ params.orderData.surcharge_fee = (_params$totalInfo5 = params.totalInfo) === null || _params$totalInfo5 === void 0 || (_params$totalInfo5 = _params$totalInfo5.total) === null || _params$totalInfo5 === void 0 ? void 0 : _params$totalInfo5.otherAmount;
648
+ params.orderData.surcharges = (_params$totalInfo6 = params.totalInfo) === null || _params$totalInfo6 === void 0 || (_params$totalInfo6 = _params$totalInfo6.total) === null || _params$totalInfo6 === void 0 ? void 0 : _params$totalInfo6.surcharge;
649
+ params.orderData.shop_discount = (_params$totalInfo7 = params.totalInfo) === null || _params$totalInfo7 === void 0 || (_params$totalInfo7 = _params$totalInfo7.total) === null || _params$totalInfo7 === void 0 ? void 0 : _params$totalInfo7.shopDiscount;
650
+ params.orderData.tax_fee = (_params$totalInfo8 = params.totalInfo) === null || _params$totalInfo8 === void 0 || (_params$totalInfo8 = _params$totalInfo8.total) === null || _params$totalInfo8 === void 0 ? void 0 : _params$totalInfo8.tax;
651
+
652
+ // 持久化原始数据
653
+ this.store.localOrderData = params.orderData;
654
+ this.store.cartSummary = params.cartSummary;
655
+
656
+ // 同步客户信息
657
+ customerInfo = {
658
+ customer_id: params.orderData.customer_id,
659
+ customer_name: params.orderData.customer_name
660
+ };
661
+ if (customerInfo.customer_id || customerInfo.customer_name) {
662
+ this.store.currentCustomer = customerInfo;
663
+ } else {
664
+ this.store.currentCustomer = undefined;
665
+ }
666
+
667
+ // 保留原有支付项:通过 orderId 找到现有订单(按 id 或 order_id 匹配)
668
+ _context10.next = 17;
669
+ return this.payment.getOrderListAsync();
670
+ case 17:
671
+ allOrders = _context10.sent;
672
+ existingOrder = allOrders.find(function (o) {
673
+ return String(o.id) === String(params.orderId) || String(o.order_id) === String(params.orderId);
674
+ });
675
+ if (!existingOrder) {
676
+ _context10.next = 39;
677
+ break;
678
+ }
679
+ // 基于现有支付项计算新的 expect_amount
680
+ totalAmount = new Decimal(amountInfo.totalAmount || '0');
681
+ activePayments = (existingOrder.payment || []).filter(function (p) {
682
+ return p.status !== 'voided';
683
+ });
684
+ paidAmount = activePayments.reduce(function (sum, p) {
685
+ var amt = new Decimal(p.amount || '0');
686
+ var rounding = new Decimal(p.rounding_amount || '0').abs();
687
+ return sum.plus(amt).plus(rounding);
688
+ }, new Decimal(0));
689
+ remaining = Decimal.max(0, totalAmount.minus(paidAmount)).toFixed(2); // 更新到支付模块(使用 uuid,不修改 payment 列表)
690
+ _context10.next = 26;
691
+ return this.payment.updateOrderAsync(existingOrder.uuid, {
692
+ total_amount: amountInfo.totalAmount,
693
+ is_deposit: params.orderData.is_deposit || 0,
694
+ deposit_amount: amountInfo.depositAmount || '0.00',
695
+ expect_amount: remaining,
696
+ order_info: {
697
+ original_order_data: params.orderData,
698
+ cart_summary: params.cartSummary,
699
+ created_at: new Date().toISOString(),
700
+ platform: params.orderData.platform,
701
+ type: params.orderData.type,
702
+ schedule_date: params.orderData.schedule_date,
703
+ shop_note: params.orderData.shop_note,
704
+ amount_breakdown: amountInfo
705
+ }
706
+ });
707
+ case 26:
708
+ _context10.next = 28;
709
+ return this.payment.getPaymentOrderByUuidAsync(existingOrder.uuid);
710
+ case 28:
711
+ updated = _context10.sent;
712
+ if (updated) {
713
+ _context10.next = 31;
714
+ break;
715
+ }
716
+ throw createCheckoutError(CheckoutErrorType.UnknownError, '订单更新失败');
717
+ case 31:
718
+ this.store.currentOrder = updated;
719
+ _context10.next = 34;
720
+ return this.updateStateAmountToRemaining();
721
+ case 34:
722
+ this.logInfo('本地订单更新成功(保留支付项):', {
723
+ orderId: params.orderId,
724
+ uuid: updated.uuid,
725
+ payments: ((_updated$payment = updated.payment) === null || _updated$payment === void 0 ? void 0 : _updated$payment.length) || 0,
726
+ totalAmount: updated.total_amount,
727
+ expectAmount: updated.expect_amount
728
+ });
729
+
730
+ // 事件通知(复用创建事件,便于上层监听刷新)
731
+ _context10.next = 37;
732
+ return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
733
+ order: updated,
734
+ timestamp: Date.now()
735
+ });
736
+ case 37:
737
+ this.initWalletData({
738
+ order_wait_pay_amount: Number(updated.expect_amount)
739
+ });
740
+ return _context10.abrupt("return", updated);
741
+ case 39:
742
+ _context10.next = 41;
743
+ return this.payment.createPaymentOrderAsync({
744
+ order_id: String(params.orderId),
745
+ total_amount: amountInfo.totalAmount,
746
+ is_deposit: params.orderData.is_deposit || 0,
747
+ deposit_amount: amountInfo.depositAmount || '0.00',
748
+ order_info: {
749
+ original_order_data: params.orderData,
750
+ cart_summary: params.cartSummary,
751
+ created_at: new Date().toISOString(),
752
+ platform: params.orderData.platform,
753
+ type: params.orderData.type,
754
+ schedule_date: params.orderData.schedule_date,
755
+ shop_note: params.orderData.shop_note,
756
+ amount_breakdown: amountInfo
757
+ }
758
+ });
759
+ case 41:
760
+ created = _context10.sent;
761
+ this.store.currentOrder = created;
762
+ _context10.next = 45;
763
+ return this.updateStateAmountToRemaining();
764
+ case 45:
765
+ this.initWalletData();
766
+ return _context10.abrupt("return", created);
767
+ case 47:
768
+ case "end":
769
+ return _context10.stop();
770
+ }
771
+ }, _callee10, this);
772
+ }));
773
+ function updateLocalOrderAsync(_x12) {
774
+ return _updateLocalOrderAsync.apply(this, arguments);
775
+ }
776
+ return updateLocalOrderAsync;
777
+ }()
608
778
  /**
609
779
  * 完成结账
610
780
  */
@@ -612,31 +782,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
612
782
  }, {
613
783
  key: "completeCheckoutAsync",
614
784
  value: (function () {
615
- var _completeCheckoutAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
785
+ var _completeCheckoutAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
616
786
  var order;
617
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
618
- while (1) switch (_context10.prev = _context10.next) {
787
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
788
+ while (1) switch (_context11.prev = _context11.next) {
619
789
  case 0:
620
- _context10.prev = 0;
790
+ _context11.prev = 0;
621
791
  if (this.store.currentOrder) {
622
- _context10.next = 3;
792
+ _context11.next = 3;
623
793
  break;
624
794
  }
625
795
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单');
626
796
  case 3:
627
- _context10.next = 5;
797
+ _context11.next = 5;
628
798
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
629
799
  case 5:
630
- order = _context10.sent;
800
+ order = _context11.sent;
631
801
  if (!(!order || order.payment_status !== PaymentStatus.Finished)) {
632
- _context10.next = 8;
802
+ _context11.next = 8;
633
803
  break;
634
804
  }
635
805
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '订单支付未完成,无法完成结账');
636
806
  case 8:
637
807
  // 清理钱包模块的所有缓存数据
638
808
  this.payment.wallet.clearAllCache();
639
- _context10.next = 11;
809
+ _context11.next = 11;
640
810
  return this.core.effects.emit(CheckoutHooks.OnCheckoutCompleted, {
641
811
  orderId: order.id,
642
812
  timestamp: Date.now()
@@ -645,27 +815,27 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
645
815
  console.log('[Checkout] 结账流程完成:', order.id);
646
816
 
647
817
  // 🔧 新增:自动重置 store 状态
648
- _context10.next = 14;
818
+ _context11.next = 14;
649
819
  return this.resetStoreStateAsync();
650
820
  case 14:
651
- return _context10.abrupt("return", {
821
+ return _context11.abrupt("return", {
652
822
  success: true,
653
823
  orderId: String(order.id)
654
824
  });
655
825
  case 17:
656
- _context10.prev = 17;
657
- _context10.t0 = _context10["catch"](0);
658
- _context10.next = 21;
659
- return this.handleError(_context10.t0, CheckoutErrorType.UnknownError);
826
+ _context11.prev = 17;
827
+ _context11.t0 = _context11["catch"](0);
828
+ _context11.next = 21;
829
+ return this.handleError(_context11.t0, CheckoutErrorType.UnknownError);
660
830
  case 21:
661
- return _context10.abrupt("return", {
831
+ return _context11.abrupt("return", {
662
832
  success: false
663
833
  });
664
834
  case 22:
665
835
  case "end":
666
- return _context10.stop();
836
+ return _context11.stop();
667
837
  }
668
- }, _callee10, this, [[0, 17]]);
838
+ }, _callee11, this, [[0, 17]]);
669
839
  }));
670
840
  function completeCheckoutAsync() {
671
841
  return _completeCheckoutAsync.apply(this, arguments);
@@ -679,8 +849,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
679
849
  }, {
680
850
  key: "getOrderOriginalData",
681
851
  value: function getOrderOriginalData() {
682
- var _this$store$currentOr5;
683
- return (_this$store$currentOr5 = this.store.currentOrder) === null || _this$store$currentOr5 === void 0 ? void 0 : _this$store$currentOr5.order_info;
852
+ var _this$store$currentOr6;
853
+ return (_this$store$currentOr6 = this.store.currentOrder) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.order_info;
684
854
  }
685
855
 
686
856
  /**
@@ -735,35 +905,35 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
735
905
  }, {
736
906
  key: "getCurrentOrderPaymentItemsAsync",
737
907
  value: (function () {
738
- var _getCurrentOrderPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
908
+ var _getCurrentOrderPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
739
909
  var _currentOrder2, paymentItems;
740
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
741
- while (1) switch (_context11.prev = _context11.next) {
910
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
911
+ while (1) switch (_context12.prev = _context12.next) {
742
912
  case 0:
743
- _context11.prev = 0;
913
+ _context12.prev = 0;
744
914
  _currentOrder2 = this.store.currentOrder;
745
915
  if (_currentOrder2) {
746
- _context11.next = 5;
916
+ _context12.next = 5;
747
917
  break;
748
918
  }
749
919
  console.log('[Checkout] 当前没有活跃订单,无法获取支付项');
750
- return _context11.abrupt("return", []);
920
+ return _context12.abrupt("return", []);
751
921
  case 5:
752
- _context11.next = 7;
922
+ _context12.next = 7;
753
923
  return this.payment.getPaymentItemsAsync(_currentOrder2.uuid);
754
924
  case 7:
755
- paymentItems = _context11.sent;
756
- return _context11.abrupt("return", paymentItems);
925
+ paymentItems = _context12.sent;
926
+ return _context12.abrupt("return", paymentItems);
757
927
  case 11:
758
- _context11.prev = 11;
759
- _context11.t0 = _context11["catch"](0);
760
- console.error('[Checkout] 获取当前订单支付项失败:', _context11.t0);
761
- return _context11.abrupt("return", []);
928
+ _context12.prev = 11;
929
+ _context12.t0 = _context12["catch"](0);
930
+ console.error('[Checkout] 获取当前订单支付项失败:', _context12.t0);
931
+ return _context12.abrupt("return", []);
762
932
  case 15:
763
933
  case "end":
764
- return _context11.stop();
934
+ return _context12.stop();
765
935
  }
766
- }, _callee11, this, [[0, 11]]);
936
+ }, _callee12, this, [[0, 11]]);
767
937
  }));
768
938
  function getCurrentOrderPaymentItemsAsync() {
769
939
  return _getCurrentOrderPaymentItemsAsync.apply(this, arguments);
@@ -800,32 +970,32 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
800
970
  }, {
801
971
  key: "replaceLocalOrderIdAsync",
802
972
  value: (function () {
803
- var _replaceLocalOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(newOrderId) {
973
+ var _replaceLocalOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(newOrderId) {
804
974
  var updatedOrder;
805
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
806
- while (1) switch (_context12.prev = _context12.next) {
975
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
976
+ while (1) switch (_context13.prev = _context13.next) {
807
977
  case 0:
808
- _context12.prev = 0;
978
+ _context13.prev = 0;
809
979
  if (this.store.currentOrder) {
810
- _context12.next = 4;
980
+ _context13.next = 4;
811
981
  break;
812
982
  }
813
983
  console.warn('[Checkout] 没有当前订单,无法替换订单ID');
814
- return _context12.abrupt("return", null);
984
+ return _context13.abrupt("return", null);
815
985
  case 4:
816
- _context12.next = 6;
986
+ _context13.next = 6;
817
987
  return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, newOrderId);
818
988
  case 6:
819
- updatedOrder = _context12.sent;
989
+ updatedOrder = _context13.sent;
820
990
  if (!updatedOrder) {
821
- _context12.next = 15;
991
+ _context13.next = 15;
822
992
  break;
823
993
  }
824
994
  // 更新当前订单引用
825
995
  this.store.currentOrder = updatedOrder;
826
996
 
827
997
  // 触发订单更新事件
828
- _context12.next = 11;
998
+ _context13.next = 11;
829
999
  return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
830
1000
  order: updatedOrder,
831
1001
  timestamp: Date.now()
@@ -840,25 +1010,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
840
1010
  this.store.isOrderSynced = true;
841
1011
 
842
1012
  // 订单ID替换后更新 stateAmount
843
- _context12.next = 15;
1013
+ _context13.next = 15;
844
1014
  return this.updateStateAmountToRemaining();
845
1015
  case 15:
846
- return _context12.abrupt("return", updatedOrder);
1016
+ return _context13.abrupt("return", updatedOrder);
847
1017
  case 18:
848
- _context12.prev = 18;
849
- _context12.t0 = _context12["catch"](0);
850
- console.error('[Checkout] 替换订单ID失败:', _context12.t0);
851
- _context12.next = 23;
852
- return this.handleError(_context12.t0, CheckoutErrorType.UnknownError);
1018
+ _context13.prev = 18;
1019
+ _context13.t0 = _context13["catch"](0);
1020
+ console.error('[Checkout] 替换订单ID失败:', _context13.t0);
1021
+ _context13.next = 23;
1022
+ return this.handleError(_context13.t0, CheckoutErrorType.UnknownError);
853
1023
  case 23:
854
- return _context12.abrupt("return", null);
1024
+ return _context13.abrupt("return", null);
855
1025
  case 24:
856
1026
  case "end":
857
- return _context12.stop();
1027
+ return _context13.stop();
858
1028
  }
859
- }, _callee12, this, [[0, 18]]);
1029
+ }, _callee13, this, [[0, 18]]);
860
1030
  }));
861
- function replaceLocalOrderIdAsync(_x12) {
1031
+ function replaceLocalOrderIdAsync(_x13) {
862
1032
  return _replaceLocalOrderIdAsync.apply(this, arguments);
863
1033
  }
864
1034
  return replaceLocalOrderIdAsync;
@@ -874,16 +1044,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
874
1044
  }, {
875
1045
  key: "setStateAmountAsync",
876
1046
  value: (function () {
877
- var _setStateAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(amount) {
1047
+ var _setStateAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(amount) {
878
1048
  var numAmount, oldAmount, formattedAmount, errorMessage;
879
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
880
- while (1) switch (_context13.prev = _context13.next) {
1049
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1050
+ while (1) switch (_context14.prev = _context14.next) {
881
1051
  case 0:
882
- _context13.prev = 0;
1052
+ _context14.prev = 0;
883
1053
  // 验证金额格式
884
1054
  numAmount = parseFloat(amount);
885
1055
  if (!(isNaN(numAmount) || numAmount < 0)) {
886
- _context13.next = 4;
1056
+ _context14.next = 4;
887
1057
  break;
888
1058
  }
889
1059
  throw new Error("\u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: ".concat(amount));
@@ -891,10 +1061,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
891
1061
  oldAmount = this.store.stateAmount;
892
1062
  formattedAmount = numAmount.toFixed(2); // 如果金额没有变化,直接返回
893
1063
  if (!(oldAmount === formattedAmount)) {
894
- _context13.next = 8;
1064
+ _context14.next = 8;
895
1065
  break;
896
1066
  }
897
- return _context13.abrupt("return");
1067
+ return _context14.abrupt("return");
898
1068
  case 8:
899
1069
  this.logInfo('[Checkout] 设置自定义支付金额:', {
900
1070
  oldAmount: oldAmount,
@@ -905,31 +1075,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
905
1075
  this.store.stateAmount = formattedAmount;
906
1076
 
907
1077
  // 触发金额变更事件
908
- _context13.next = 12;
1078
+ _context14.next = 12;
909
1079
  return this.core.effects.emit(CheckoutHooks.OnStateAmountChanged, {
910
1080
  oldAmount: oldAmount,
911
1081
  newAmount: formattedAmount,
912
1082
  timestamp: Date.now()
913
1083
  });
914
1084
  case 12:
915
- _context13.next = 21;
1085
+ _context14.next = 21;
916
1086
  break;
917
1087
  case 14:
918
- _context13.prev = 14;
919
- _context13.t0 = _context13["catch"](0);
920
- errorMessage = _context13.t0 instanceof Error ? _context13.t0.message : '设置支付金额失败';
1088
+ _context14.prev = 14;
1089
+ _context14.t0 = _context14["catch"](0);
1090
+ errorMessage = _context14.t0 instanceof Error ? _context14.t0.message : '设置支付金额失败';
921
1091
  console.error('[Checkout] 设置自定义支付金额失败:', errorMessage);
922
- _context13.next = 20;
1092
+ _context14.next = 20;
923
1093
  return this.handleError(new Error(errorMessage), CheckoutErrorType.ValidationFailed);
924
1094
  case 20:
925
- throw _context13.t0;
1095
+ throw _context14.t0;
926
1096
  case 21:
927
1097
  case "end":
928
- return _context13.stop();
1098
+ return _context14.stop();
929
1099
  }
930
- }, _callee13, this, [[0, 14]]);
1100
+ }, _callee14, this, [[0, 14]]);
931
1101
  }));
932
- function setStateAmountAsync(_x13) {
1102
+ function setStateAmountAsync(_x14) {
933
1103
  return _setStateAmountAsync.apply(this, arguments);
934
1104
  }
935
1105
  return setStateAmountAsync;
@@ -997,39 +1167,39 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
997
1167
  }, {
998
1168
  key: "getPaymentMethodsAsync",
999
1169
  value: (function () {
1000
- var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1170
+ var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1001
1171
  var methods;
1002
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1003
- while (1) switch (_context14.prev = _context14.next) {
1172
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1173
+ while (1) switch (_context15.prev = _context15.next) {
1004
1174
  case 0:
1005
1175
  if (!(this.store.paymentMethods && this.store.paymentMethods.length > 0)) {
1006
- _context14.next = 3;
1176
+ _context15.next = 3;
1007
1177
  break;
1008
1178
  }
1009
1179
  this.logInfo("\u4F7F\u7528\u7F13\u5B58\u7684\u652F\u4ED8\u65B9\u5F0F\u6570\u636E\uFF0C\u5171 ".concat(this.store.paymentMethods.length, " \u79CD"));
1010
- return _context14.abrupt("return", this.store.paymentMethods);
1180
+ return _context15.abrupt("return", this.store.paymentMethods);
1011
1181
  case 3:
1012
1182
  // 如果缓存为空,调用 Payment 模块获取
1013
1183
  this.logInfo('store 中无缓存,从 Payment 模块获取支付方式...');
1014
- _context14.prev = 4;
1015
- _context14.next = 7;
1184
+ _context15.prev = 4;
1185
+ _context15.next = 7;
1016
1186
  return this.payment.getPayMethodListAsync();
1017
1187
  case 7:
1018
- methods = _context14.sent;
1188
+ methods = _context15.sent;
1019
1189
  // 更新缓存
1020
1190
  this.store.paymentMethods = methods;
1021
1191
  this.logInfo("\u4ECE Payment \u6A21\u5757\u83B7\u53D6\u5230 ".concat(methods.length, " \u79CD\u652F\u4ED8\u65B9\u5F0F\uFF0C\u5DF2\u66F4\u65B0\u7F13\u5B58"));
1022
- return _context14.abrupt("return", methods);
1192
+ return _context15.abrupt("return", methods);
1023
1193
  case 13:
1024
- _context14.prev = 13;
1025
- _context14.t0 = _context14["catch"](4);
1026
- this.logError('获取支付方式失败:', _context14.t0);
1027
- return _context14.abrupt("return", []);
1194
+ _context15.prev = 13;
1195
+ _context15.t0 = _context15["catch"](4);
1196
+ this.logError('获取支付方式失败:', _context15.t0);
1197
+ return _context15.abrupt("return", []);
1028
1198
  case 17:
1029
1199
  case "end":
1030
- return _context14.stop();
1200
+ return _context15.stop();
1031
1201
  }
1032
- }, _callee14, this, [[4, 13]]);
1202
+ }, _callee15, this, [[4, 13]]);
1033
1203
  }));
1034
1204
  function getPaymentMethodsAsync() {
1035
1205
  return _getPaymentMethodsAsync.apply(this, arguments);
@@ -1048,25 +1218,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1048
1218
  }, {
1049
1219
  key: "addPaymentItemAsync",
1050
1220
  value: (function () {
1051
- var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(paymentItem) {
1221
+ var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(paymentItem) {
1052
1222
  var orderPaymentType, processedPaymentItem, metadata, paymentItemWithType, remainingAmount, _paymentItem$type, _paymentItem$code, isEftposPayment, _isCashPayment, isCustomePayment, syncResult;
1053
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1054
- while (1) switch (_context15.prev = _context15.next) {
1223
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1224
+ while (1) switch (_context16.prev = _context16.next) {
1055
1225
  case 0:
1056
1226
  this.logInfo('addPaymentItemAsync called', paymentItem);
1057
- _context15.prev = 1;
1227
+ _context16.prev = 1;
1058
1228
  if (this.store.currentOrder) {
1059
- _context15.next = 4;
1229
+ _context16.next = 4;
1060
1230
  break;
1061
1231
  }
1062
1232
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法添加支付项');
1063
1233
  case 4:
1064
1234
  // 根据当前订单的定金状态设置订单支付类型
1065
1235
  orderPaymentType = this.store.currentOrder.is_deposit === 1 ? 'deposit' : 'normal'; // 处理现金支付的找零逻辑
1066
- _context15.next = 7;
1236
+ _context16.next = 7;
1067
1237
  return this.processCashPaymentItem(paymentItem);
1068
1238
  case 7:
1069
- processedPaymentItem = _context15.sent;
1239
+ processedPaymentItem = _context16.sent;
1070
1240
  // 从 otherParams 获取 metadata 字段
1071
1241
  metadata = _objectSpread(_objectSpread({}, processedPaymentItem.metadata), {}, {
1072
1242
  rounding_rule: this.otherParams.order_rounding_setting,
@@ -1076,21 +1246,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1076
1246
  order_payment_type: orderPaymentType,
1077
1247
  metadata: metadata
1078
1248
  }); // 添加支付项到订单
1079
- _context15.next = 12;
1249
+ _context16.next = 12;
1080
1250
  return this.payment.addPaymentItemAsync(this.store.currentOrder.uuid, paymentItemWithType);
1081
1251
  case 12:
1082
1252
  this.logInfo('支付项添加成功');
1083
1253
 
1084
1254
  // 支付项添加后,更新 stateAmount 为剩余未支付金额
1085
- _context15.next = 15;
1255
+ _context16.next = 15;
1086
1256
  return this.updateStateAmountToRemaining();
1087
1257
  case 15:
1088
- _context15.next = 17;
1258
+ _context16.next = 17;
1089
1259
  return this.calculateRemainingAmountAsync();
1090
1260
  case 17:
1091
- remainingAmount = _context15.sent;
1261
+ remainingAmount = _context16.sent;
1092
1262
  if (!(Number(remainingAmount) > 0)) {
1093
- _context15.next = 38;
1263
+ _context16.next = 38;
1094
1264
  break;
1095
1265
  }
1096
1266
  this.logInfo('订单金额还有待付的,同步 EFTPOS 支付');
@@ -1105,29 +1275,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1105
1275
  currentOrderSynced: this.store.isOrderSynced
1106
1276
  });
1107
1277
  if (!(isEftposPayment || _isCashPayment || isCustomePayment)) {
1108
- _context15.next = 38;
1278
+ _context16.next = 38;
1109
1279
  break;
1110
1280
  }
1111
1281
  this.logInfo('检测到 EFTPOS 支付,立即同步订单到后端...');
1112
- _context15.prev = 26;
1113
- _context15.next = 29;
1282
+ _context16.prev = 26;
1283
+ _context16.next = 29;
1114
1284
  return this.syncOrderToBackendWithReturn(true);
1115
1285
  case 29:
1116
- syncResult = _context15.sent;
1286
+ syncResult = _context16.sent;
1117
1287
  this.logInfo('EFTPOS 支付后订单同步完成 (已标记为手动同步):', {
1118
1288
  orderId: syncResult.orderId,
1119
1289
  isOrderSynced: this.store.isOrderSynced,
1120
1290
  backendResponse: syncResult.response
1121
1291
  });
1122
- _context15.next = 38;
1292
+ _context16.next = 38;
1123
1293
  break;
1124
1294
  case 33:
1125
- _context15.prev = 33;
1126
- _context15.t0 = _context15["catch"](26);
1127
- this.logError('EFTPOS 支付后订单同步失败:', _context15.t0);
1295
+ _context16.prev = 33;
1296
+ _context16.t0 = _context16["catch"](26);
1297
+ this.logError('EFTPOS 支付后订单同步失败:', _context16.t0);
1128
1298
  // 不抛出错误,避免影响支付流程,但记录错误
1129
- _context15.next = 38;
1130
- return this.handleError(new Error("EFTPOS \u652F\u4ED8\u540E\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0))), CheckoutErrorType.OrderCreationFailed);
1299
+ _context16.next = 38;
1300
+ 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);
1131
1301
  case 38:
1132
1302
  // 触发支付项添加事件(可以复用支付开始事件)
1133
1303
  this.core.effects.emit(CheckoutHooks.OnPaymentItemAdded, {
@@ -1137,23 +1307,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1137
1307
  amount: String(paymentItem.amount),
1138
1308
  timestamp: Date.now()
1139
1309
  });
1140
- _context15.next = 47;
1310
+ _context16.next = 47;
1141
1311
  break;
1142
1312
  case 41:
1143
- _context15.prev = 41;
1144
- _context15.t1 = _context15["catch"](1);
1145
- this.logError('添加支付项失败:', _context15.t1);
1146
- _context15.next = 46;
1147
- return this.handleError(_context15.t1, CheckoutErrorType.PaymentFailed);
1313
+ _context16.prev = 41;
1314
+ _context16.t1 = _context16["catch"](1);
1315
+ this.logError('添加支付项失败:', _context16.t1);
1316
+ _context16.next = 46;
1317
+ return this.handleError(_context16.t1, CheckoutErrorType.PaymentFailed);
1148
1318
  case 46:
1149
- throw _context15.t1;
1319
+ throw _context16.t1;
1150
1320
  case 47:
1151
1321
  case "end":
1152
- return _context15.stop();
1322
+ return _context16.stop();
1153
1323
  }
1154
- }, _callee15, this, [[1, 41], [26, 33]]);
1324
+ }, _callee16, this, [[1, 41], [26, 33]]);
1155
1325
  }));
1156
- function addPaymentItemAsync(_x14) {
1326
+ function addPaymentItemAsync(_x15) {
1157
1327
  return _addPaymentItemAsync.apply(this, arguments);
1158
1328
  }
1159
1329
  return addPaymentItemAsync;
@@ -1171,14 +1341,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1171
1341
  }, {
1172
1342
  key: "deletePaymentItemAsync",
1173
1343
  value: (function () {
1174
- var _deletePaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(paymentUuid) {
1344
+ var _deletePaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(paymentUuid) {
1175
1345
  var currentPayments, paymentItem, currentOrderId, isCurrentOrderReal, updatedOrder;
1176
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1177
- while (1) switch (_context16.prev = _context16.next) {
1346
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1347
+ while (1) switch (_context17.prev = _context17.next) {
1178
1348
  case 0:
1179
- _context16.prev = 0;
1349
+ _context17.prev = 0;
1180
1350
  if (this.store.currentOrder) {
1181
- _context16.next = 3;
1351
+ _context17.next = 3;
1182
1352
  break;
1183
1353
  }
1184
1354
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '当前没有活跃订单,无法删除支付项');
@@ -1189,16 +1359,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1189
1359
  });
1190
1360
 
1191
1361
  // 从 Payment 模块验证支付项是否存在
1192
- _context16.next = 6;
1362
+ _context17.next = 6;
1193
1363
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, true // 包括已撤销的支付项,因为我们需要验证是否存在
1194
1364
  );
1195
1365
  case 6:
1196
- currentPayments = _context16.sent;
1366
+ currentPayments = _context17.sent;
1197
1367
  paymentItem = currentPayments.find(function (p) {
1198
1368
  return p.uuid === paymentUuid;
1199
1369
  });
1200
1370
  if (paymentItem) {
1201
- _context16.next = 10;
1371
+ _context17.next = 10;
1202
1372
  break;
1203
1373
  }
1204
1374
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u652F\u4ED8\u9879\u4E0D\u5B58\u5728: ".concat(paymentUuid));
@@ -1211,7 +1381,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1211
1381
  });
1212
1382
 
1213
1383
  // 调用 Payment 模块删除支付项
1214
- _context16.next = 13;
1384
+ _context17.next = 13;
1215
1385
  return this.payment.deletePaymentAsync(this.store.currentOrder.uuid, paymentUuid);
1216
1386
  case 13:
1217
1387
  this.logInfo('Payment支付项删除完成', paymentItem);
@@ -1219,10 +1389,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1219
1389
  // 重新从Payment模块获取最新的订单数据,确保支付项同步
1220
1390
  currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1221
1391
  isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
1222
- _context16.next = 18;
1392
+ _context17.next = 18;
1223
1393
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1224
1394
  case 18:
1225
- updatedOrder = _context16.sent;
1395
+ updatedOrder = _context17.sent;
1226
1396
  if (updatedOrder) {
1227
1397
  // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
1228
1398
  if (isCurrentOrderReal && isVirtualOrderId(updatedOrder.order_id)) {
@@ -1236,10 +1406,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1236
1406
  }
1237
1407
 
1238
1408
  // 更新 stateAmount 为剩余未支付金额
1239
- _context16.next = 22;
1409
+ _context17.next = 22;
1240
1410
  return this.updateStateAmountToRemaining();
1241
1411
  case 22:
1242
- _context16.next = 24;
1412
+ _context17.next = 24;
1243
1413
  return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1244
1414
  orderUuid: this.store.currentOrder.uuid,
1245
1415
  paymentMethodCode: paymentItem.code,
@@ -1248,23 +1418,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1248
1418
  timestamp: Date.now()
1249
1419
  });
1250
1420
  case 24:
1251
- _context16.next = 32;
1421
+ _context17.next = 32;
1252
1422
  break;
1253
1423
  case 26:
1254
- _context16.prev = 26;
1255
- _context16.t0 = _context16["catch"](0);
1256
- this.logError('删除支付项失败:', _context16.t0);
1257
- _context16.next = 31;
1258
- return this.handleError(_context16.t0, CheckoutErrorType.PaymentFailed);
1424
+ _context17.prev = 26;
1425
+ _context17.t0 = _context17["catch"](0);
1426
+ this.logError('删除支付项失败:', _context17.t0);
1427
+ _context17.next = 31;
1428
+ return this.handleError(_context17.t0, CheckoutErrorType.PaymentFailed);
1259
1429
  case 31:
1260
- throw _context16.t0;
1430
+ throw _context17.t0;
1261
1431
  case 32:
1262
1432
  case "end":
1263
- return _context16.stop();
1433
+ return _context17.stop();
1264
1434
  }
1265
- }, _callee16, this, [[0, 26]]);
1435
+ }, _callee17, this, [[0, 26]]);
1266
1436
  }));
1267
- function deletePaymentItemAsync(_x15) {
1437
+ function deletePaymentItemAsync(_x16) {
1268
1438
  return _deletePaymentItemAsync.apply(this, arguments);
1269
1439
  }
1270
1440
  return deletePaymentItemAsync;
@@ -1283,27 +1453,27 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1283
1453
  }, {
1284
1454
  key: "updateVoucherPaymentItemsAsync",
1285
1455
  value: (function () {
1286
- var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(voucherPaymentItems) {
1456
+ var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(voucherPaymentItems) {
1287
1457
  var _this3 = this;
1288
1458
  var remainingAmount, remainingValue, isOrderSynced, orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder;
1289
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1290
- while (1) switch (_context17.prev = _context17.next) {
1459
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1460
+ while (1) switch (_context18.prev = _context18.next) {
1291
1461
  case 0:
1292
- _context17.prev = 0;
1462
+ _context18.prev = 0;
1293
1463
  if (this.store.currentOrder) {
1294
- _context17.next = 3;
1464
+ _context18.next = 3;
1295
1465
  break;
1296
1466
  }
1297
1467
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '当前没有活跃订单,无法更新代金券支付项');
1298
1468
  case 3:
1299
- _context17.next = 5;
1469
+ _context18.next = 5;
1300
1470
  return this.calculateRemainingAmountAsync();
1301
1471
  case 5:
1302
- remainingAmount = _context17.sent;
1472
+ remainingAmount = _context18.sent;
1303
1473
  remainingValue = new Decimal(remainingAmount);
1304
1474
  isOrderSynced = this.store.isOrderSynced;
1305
1475
  if (!(remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0)) {
1306
- _context17.next = 11;
1476
+ _context18.next = 11;
1307
1477
  break;
1308
1478
  }
1309
1479
  this.logInfo('订单已同步且支付完成,跳过清空代金券操作避免重复同步:', {
@@ -1314,7 +1484,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1314
1484
  voucherPaymentItemsCount: voucherPaymentItems.length,
1315
1485
  reason: 'Order synced and payment completed, skip clear vouchers to avoid duplicate sync'
1316
1486
  });
1317
- return _context17.abrupt("return");
1487
+ return _context18.abrupt("return");
1318
1488
  case 11:
1319
1489
  this.logInfo('开始批量更新代金券支付项:', {
1320
1490
  voucherPaymentItems: voucherPaymentItems
@@ -1337,16 +1507,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1337
1507
  metadata: metadata
1338
1508
  });
1339
1509
  }); // 调用 Payment 模块的批量更新方法
1340
- _context17.next = 16;
1510
+ _context18.next = 16;
1341
1511
  return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItemsWithType);
1342
1512
  case 16:
1343
1513
  // 重新从Payment模块获取最新的订单数据,确保支付项同步
1344
1514
  currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1345
1515
  isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
1346
- _context17.next = 20;
1516
+ _context18.next = 20;
1347
1517
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1348
1518
  case 20:
1349
- updatedOrder = _context17.sent;
1519
+ updatedOrder = _context18.sent;
1350
1520
  if (updatedOrder) {
1351
1521
  // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
1352
1522
  if (isCurrentOrderReal && isVirtualOrderId(updatedOrder.order_id)) {
@@ -1360,10 +1530,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1360
1530
  }
1361
1531
 
1362
1532
  // 更新 stateAmount 为剩余未支付金额
1363
- _context17.next = 24;
1533
+ _context18.next = 24;
1364
1534
  return this.updateStateAmountToRemaining();
1365
1535
  case 24:
1366
- _context17.next = 26;
1536
+ _context18.next = 26;
1367
1537
  return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1368
1538
  orderUuid: this.store.currentOrder.uuid,
1369
1539
  paymentMethodCode: 'VOUCHER_BATCH',
@@ -1374,23 +1544,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1374
1544
  });
1375
1545
  case 26:
1376
1546
  this.logInfo('代金券支付项批量更新成功');
1377
- _context17.next = 35;
1547
+ _context18.next = 35;
1378
1548
  break;
1379
1549
  case 29:
1380
- _context17.prev = 29;
1381
- _context17.t0 = _context17["catch"](0);
1382
- this.logError('[Checkout] 批量更新代金券支付项失败:', _context17.t0);
1383
- _context17.next = 34;
1384
- return this.handleError(_context17.t0, CheckoutErrorType.PaymentFailed);
1550
+ _context18.prev = 29;
1551
+ _context18.t0 = _context18["catch"](0);
1552
+ this.logError('[Checkout] 批量更新代金券支付项失败:', _context18.t0);
1553
+ _context18.next = 34;
1554
+ return this.handleError(_context18.t0, CheckoutErrorType.PaymentFailed);
1385
1555
  case 34:
1386
- throw _context17.t0;
1556
+ throw _context18.t0;
1387
1557
  case 35:
1388
1558
  case "end":
1389
- return _context17.stop();
1559
+ return _context18.stop();
1390
1560
  }
1391
- }, _callee17, this, [[0, 29]]);
1561
+ }, _callee18, this, [[0, 29]]);
1392
1562
  }));
1393
- function updateVoucherPaymentItemsAsync(_x16) {
1563
+ function updateVoucherPaymentItemsAsync(_x17) {
1394
1564
  return _updateVoucherPaymentItemsAsync.apply(this, arguments);
1395
1565
  }
1396
1566
  return updateVoucherPaymentItemsAsync;
@@ -1407,20 +1577,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1407
1577
  }, {
1408
1578
  key: "updateOrderDepositStatusAsync",
1409
1579
  value: (function () {
1410
- var _updateOrderDepositStatusAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(isDeposit) {
1580
+ var _updateOrderDepositStatusAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(isDeposit) {
1411
1581
  var newDepositValue, oldDepositValue, updateParams;
1412
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1413
- while (1) switch (_context18.prev = _context18.next) {
1582
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1583
+ while (1) switch (_context19.prev = _context19.next) {
1414
1584
  case 0:
1415
- _context18.prev = 0;
1585
+ _context19.prev = 0;
1416
1586
  if (!(isDeposit !== 0 && isDeposit !== 1)) {
1417
- _context18.next = 3;
1587
+ _context19.next = 3;
1418
1588
  break;
1419
1589
  }
1420
1590
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, 'isDeposit 参数只能是 0(全款订单)或 1(定金订单)');
1421
1591
  case 3:
1422
1592
  if (this.store.currentOrder) {
1423
- _context18.next = 5;
1593
+ _context19.next = 5;
1424
1594
  break;
1425
1595
  }
1426
1596
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法修改定金状态');
@@ -1428,11 +1598,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1428
1598
  newDepositValue = isDeposit;
1429
1599
  oldDepositValue = this.store.currentOrder.is_deposit; // 如果状态没有变化,直接返回
1430
1600
  if (!(oldDepositValue === newDepositValue)) {
1431
- _context18.next = 10;
1601
+ _context19.next = 10;
1432
1602
  break;
1433
1603
  }
1434
1604
  console.log('[Checkout] 定金状态无变化,跳过更新');
1435
- return _context18.abrupt("return");
1605
+ return _context19.abrupt("return");
1436
1606
  case 10:
1437
1607
  // 准备更新参数
1438
1608
  updateParams = {
@@ -1444,7 +1614,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1444
1614
  }
1445
1615
 
1446
1616
  // 调用 Payment 模块更新订单
1447
- _context18.next = 14;
1617
+ _context19.next = 14;
1448
1618
  return this.payment.updateOrderAsync(this.store.currentOrder.uuid, updateParams);
1449
1619
  case 14:
1450
1620
  // 更新本地缓存的订单对象
@@ -1456,7 +1626,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1456
1626
  }
1457
1627
 
1458
1628
  // 触发订单更新事件
1459
- _context18.next = 18;
1629
+ _context19.next = 18;
1460
1630
  return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
1461
1631
  order: this.store.currentOrder,
1462
1632
  timestamp: Date.now()
@@ -1466,23 +1636,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1466
1636
  isDeposit: newDepositValue,
1467
1637
  depositAmount: this.store.currentOrder.deposit_amount
1468
1638
  });
1469
- _context18.next = 27;
1639
+ _context19.next = 27;
1470
1640
  break;
1471
1641
  case 21:
1472
- _context18.prev = 21;
1473
- _context18.t0 = _context18["catch"](0);
1474
- this.logError('更新订单定金状态失败:', _context18.t0);
1475
- _context18.next = 26;
1476
- return this.handleError(_context18.t0, CheckoutErrorType.ValidationFailed);
1642
+ _context19.prev = 21;
1643
+ _context19.t0 = _context19["catch"](0);
1644
+ this.logError('更新订单定金状态失败:', _context19.t0);
1645
+ _context19.next = 26;
1646
+ return this.handleError(_context19.t0, CheckoutErrorType.ValidationFailed);
1477
1647
  case 26:
1478
- throw _context18.t0;
1648
+ throw _context19.t0;
1479
1649
  case 27:
1480
1650
  case "end":
1481
- return _context18.stop();
1651
+ return _context19.stop();
1482
1652
  }
1483
- }, _callee18, this, [[0, 21]]);
1653
+ }, _callee19, this, [[0, 21]]);
1484
1654
  }));
1485
- function updateOrderDepositStatusAsync(_x17) {
1655
+ function updateOrderDepositStatusAsync(_x18) {
1486
1656
  return _updateOrderDepositStatusAsync.apply(this, arguments);
1487
1657
  }
1488
1658
  return updateOrderDepositStatusAsync;
@@ -1500,29 +1670,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1500
1670
  }, {
1501
1671
  key: "setDepositAmountAsync",
1502
1672
  value: (function () {
1503
- var _setDepositAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(depositAmount) {
1504
- var _this$store$currentOr6, _this$store$currentOr7;
1673
+ var _setDepositAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(depositAmount) {
1674
+ var _this$store$currentOr7, _this$store$currentOr8;
1505
1675
  var depositValue, totalAmount, formattedDepositAmount, oldDepositAmount, updateParams;
1506
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1507
- while (1) switch (_context19.prev = _context19.next) {
1676
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1677
+ while (1) switch (_context20.prev = _context20.next) {
1508
1678
  case 0:
1509
1679
  this.logInfo('setDepositAmountAsync called', {
1510
1680
  depositAmount: depositAmount,
1511
1681
  hasCurrentOrder: !!this.store.currentOrder,
1512
- currentOrderId: (_this$store$currentOr6 = this.store.currentOrder) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.order_id,
1513
- currentTotalAmount: (_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.total_amount
1682
+ currentOrderId: (_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.order_id,
1683
+ currentTotalAmount: (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.total_amount
1514
1684
  });
1515
- _context19.prev = 1;
1685
+ _context20.prev = 1;
1516
1686
  // 验证定金金额格式
1517
1687
  depositValue = new Decimal(depositAmount);
1518
1688
  if (!(depositValue.isNaN() || depositValue.lt(0))) {
1519
- _context19.next = 5;
1689
+ _context20.next = 5;
1520
1690
  break;
1521
1691
  }
1522
1692
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u65E0\u6548\u7684\u5B9A\u91D1\u91D1\u989D\u683C\u5F0F: ".concat(depositAmount));
1523
1693
  case 5:
1524
1694
  if (this.store.currentOrder) {
1525
- _context19.next = 7;
1695
+ _context20.next = 7;
1526
1696
  break;
1527
1697
  }
1528
1698
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法设置定金金额');
@@ -1530,7 +1700,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1530
1700
  // 使用 Decimal.js 进行安全比较,检查定金金额是否超过订单总额
1531
1701
  totalAmount = new Decimal(this.store.currentOrder.total_amount || '0');
1532
1702
  if (!depositValue.gt(totalAmount)) {
1533
- _context19.next = 10;
1703
+ _context20.next = 10;
1534
1704
  break;
1535
1705
  }
1536
1706
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u5B9A\u91D1\u91D1\u989D ".concat(depositAmount, " \u4E0D\u80FD\u8D85\u8FC7\u8BA2\u5355\u603B\u989D ").concat(totalAmount.toFixed(2)));
@@ -1538,14 +1708,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1538
1708
  formattedDepositAmount = depositValue.toFixed(2);
1539
1709
  oldDepositAmount = this.store.currentOrder.deposit_amount || '0.00'; // 如果定金金额没有变化,直接返回
1540
1710
  if (!(formattedDepositAmount === oldDepositAmount)) {
1541
- _context19.next = 15;
1711
+ _context20.next = 15;
1542
1712
  break;
1543
1713
  }
1544
1714
  this.logInfo('定金金额无变化,跳过更新:', {
1545
1715
  currentAmount: oldDepositAmount,
1546
1716
  newAmount: formattedDepositAmount
1547
1717
  });
1548
- return _context19.abrupt("return");
1718
+ return _context20.abrupt("return");
1549
1719
  case 15:
1550
1720
  this.logInfo('开始设置订单定金金额:', {
1551
1721
  orderUuid: this.store.currentOrder.uuid,
@@ -1570,7 +1740,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1570
1740
  }
1571
1741
 
1572
1742
  // 调用 Payment 模块更新订单
1573
- _context19.next = 20;
1743
+ _context20.next = 20;
1574
1744
  return this.payment.updateOrderAsync(this.store.currentOrder.uuid, updateParams);
1575
1745
  case 20:
1576
1746
  // 更新本地缓存的订单对象
@@ -1589,7 +1759,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1589
1759
  }
1590
1760
 
1591
1761
  // 触发订单更新事件
1592
- _context19.next = 24;
1762
+ _context20.next = 24;
1593
1763
  return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
1594
1764
  order: this.store.currentOrder,
1595
1765
  timestamp: Date.now()
@@ -1603,23 +1773,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1603
1773
  isDeposit: this.store.currentOrder.is_deposit,
1604
1774
  totalAmount: this.store.currentOrder.total_amount
1605
1775
  });
1606
- _context19.next = 33;
1776
+ _context20.next = 33;
1607
1777
  break;
1608
1778
  case 27:
1609
- _context19.prev = 27;
1610
- _context19.t0 = _context19["catch"](1);
1611
- this.logError('设置订单定金金额失败:', _context19.t0);
1612
- _context19.next = 32;
1613
- return this.handleError(_context19.t0, CheckoutErrorType.ValidationFailed);
1779
+ _context20.prev = 27;
1780
+ _context20.t0 = _context20["catch"](1);
1781
+ this.logError('设置订单定金金额失败:', _context20.t0);
1782
+ _context20.next = 32;
1783
+ return this.handleError(_context20.t0, CheckoutErrorType.ValidationFailed);
1614
1784
  case 32:
1615
- throw _context19.t0;
1785
+ throw _context20.t0;
1616
1786
  case 33:
1617
1787
  case "end":
1618
- return _context19.stop();
1788
+ return _context20.stop();
1619
1789
  }
1620
- }, _callee19, this, [[1, 27]]);
1790
+ }, _callee20, this, [[1, 27]]);
1621
1791
  }));
1622
- function setDepositAmountAsync(_x18) {
1792
+ function setDepositAmountAsync(_x19) {
1623
1793
  return _setDepositAmountAsync.apply(this, arguments);
1624
1794
  }
1625
1795
  return setDepositAmountAsync;
@@ -1633,26 +1803,26 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1633
1803
  }, {
1634
1804
  key: "manualSyncOrderAsync",
1635
1805
  value: (function () {
1636
- var _manualSyncOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1637
- var _this$store$currentOr8, _this$store$currentOr9, _this$store$currentOr10;
1638
- var orderUuid, oldOrderId, syncResult, finalOrderId, finalIsVirtual, _this$store$currentOr11, errorMessage;
1639
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1640
- while (1) switch (_context20.prev = _context20.next) {
1806
+ var _manualSyncOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1807
+ var _this$store$currentOr9, _this$store$currentOr10, _this$store$currentOr11;
1808
+ var orderUuid, oldOrderId, syncResult, finalOrderId, finalIsVirtual, _this$store$currentOr12, errorMessage;
1809
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1810
+ while (1) switch (_context21.prev = _context21.next) {
1641
1811
  case 0:
1642
1812
  this.logInfo('manualSyncOrderAsync called', {
1643
1813
  hasCurrentOrder: !!this.store.currentOrder,
1644
- currentOrderId: (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.order_id,
1645
- orderUuid: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.uuid,
1646
- totalAmount: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.total_amount,
1814
+ currentOrderId: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.order_id,
1815
+ orderUuid: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.uuid,
1816
+ totalAmount: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.total_amount,
1647
1817
  isOrderSynced: this.store.isOrderSynced,
1648
1818
  isVirtualOrderId: this.store.currentOrder ? isVirtualOrderId(this.store.currentOrder.order_id) : false
1649
1819
  });
1650
- _context20.prev = 1;
1820
+ _context21.prev = 1;
1651
1821
  if (this.store.currentOrder) {
1652
- _context20.next = 4;
1822
+ _context21.next = 4;
1653
1823
  break;
1654
1824
  }
1655
- return _context20.abrupt("return", {
1825
+ return _context21.abrupt("return", {
1656
1826
  success: false,
1657
1827
  message: '当前没有活跃订单,无法同步'
1658
1828
  });
@@ -1662,25 +1832,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1662
1832
  if (this.store.isOrderSynced) {
1663
1833
  this.logInfo('订单已同步过,将执行更新操作');
1664
1834
  }
1665
- _context20.t0 = this;
1666
- _context20.t1 = orderUuid;
1667
- _context20.t2 = oldOrderId;
1668
- _context20.t3 = this.store.currentOrder.total_amount;
1669
- _context20.next = 13;
1835
+ _context21.t0 = this;
1836
+ _context21.t1 = orderUuid;
1837
+ _context21.t2 = oldOrderId;
1838
+ _context21.t3 = this.store.currentOrder.total_amount;
1839
+ _context21.next = 13;
1670
1840
  return this.calculateRemainingAmountAsync();
1671
1841
  case 13:
1672
- _context20.t4 = _context20.sent;
1673
- _context20.t5 = {
1674
- orderUuid: _context20.t1,
1675
- orderId: _context20.t2,
1676
- totalAmount: _context20.t3,
1677
- remainingAmount: _context20.t4
1842
+ _context21.t4 = _context21.sent;
1843
+ _context21.t5 = {
1844
+ orderUuid: _context21.t1,
1845
+ orderId: _context21.t2,
1846
+ totalAmount: _context21.t3,
1847
+ remainingAmount: _context21.t4
1678
1848
  };
1679
- _context20.t0.logInfo.call(_context20.t0, '开始手动同步订单到后端:', _context20.t5);
1680
- _context20.next = 18;
1849
+ _context21.t0.logInfo.call(_context21.t0, '开始手动同步订单到后端:', _context21.t5);
1850
+ _context21.next = 18;
1681
1851
  return this.syncOrderToBackendWithReturn(true);
1682
1852
  case 18:
1683
- syncResult = _context20.sent;
1853
+ syncResult = _context21.sent;
1684
1854
  this.logInfo('手动同步订单完成:', {
1685
1855
  orderUuid: orderUuid,
1686
1856
  syncResult: syncResult,
@@ -1698,22 +1868,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1698
1868
  if (syncResult.orderId !== finalOrderId) {
1699
1869
  this.logError('[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!');
1700
1870
  }
1701
- return _context20.abrupt("return", syncResult);
1871
+ return _context21.abrupt("return", syncResult);
1702
1872
  case 27:
1703
- _context20.prev = 27;
1704
- _context20.t6 = _context20["catch"](1);
1705
- this.logError('手动同步订单失败:', _context20.t6);
1706
- errorMessage = _context20.t6 instanceof Error ? _context20.t6.message : '同步失败';
1707
- return _context20.abrupt("return", {
1873
+ _context21.prev = 27;
1874
+ _context21.t6 = _context21["catch"](1);
1875
+ this.logError('手动同步订单失败:', _context21.t6);
1876
+ errorMessage = _context21.t6 instanceof Error ? _context21.t6.message : '同步失败';
1877
+ return _context21.abrupt("return", {
1708
1878
  success: false,
1709
1879
  message: "\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(errorMessage),
1710
- orderUuid: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.uuid
1880
+ orderUuid: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.uuid
1711
1881
  });
1712
1882
  case 32:
1713
1883
  case "end":
1714
- return _context20.stop();
1884
+ return _context21.stop();
1715
1885
  }
1716
- }, _callee20, this, [[1, 27]]);
1886
+ }, _callee21, this, [[1, 27]]);
1717
1887
  }));
1718
1888
  function manualSyncOrderAsync() {
1719
1889
  return _manualSyncOrderAsync.apply(this, arguments);
@@ -1783,27 +1953,27 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1783
1953
  }, {
1784
1954
  key: "cancelCurrentOrderAsync",
1785
1955
  value: (function () {
1786
- var _cancelCurrentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(cancelReason) {
1787
- var _this$store$currentOr12, _this$store$currentOr13, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
1788
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1789
- while (1) switch (_context21.prev = _context21.next) {
1956
+ var _cancelCurrentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(cancelReason) {
1957
+ var _this$store$currentOr13, _this$store$currentOr14, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
1958
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1959
+ while (1) switch (_context22.prev = _context22.next) {
1790
1960
  case 0:
1791
- _context21.prev = 0;
1961
+ _context22.prev = 0;
1792
1962
  this.logInfo('开始取消当前本地订单:', {
1793
1963
  hasCurrentOrder: !!this.store.currentOrder,
1794
- orderUuid: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.uuid,
1795
- orderId: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.order_id,
1964
+ orderUuid: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.uuid,
1965
+ orderId: (_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.order_id,
1796
1966
  isOrderSynced: this.store.isOrderSynced,
1797
1967
  cancelReason: cancelReason
1798
1968
  });
1799
1969
 
1800
1970
  // 检查是否有当前订单
1801
1971
  if (this.store.currentOrder) {
1802
- _context21.next = 5;
1972
+ _context22.next = 5;
1803
1973
  break;
1804
1974
  }
1805
1975
  this.logInfo('没有当前订单,无需取消');
1806
- return _context21.abrupt("return", {
1976
+ return _context22.abrupt("return", {
1807
1977
  success: false,
1808
1978
  message: '没有当前订单可取消'
1809
1979
  });
@@ -1812,31 +1982,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1812
1982
  currentOrderId = this.store.currentOrder.order_id;
1813
1983
  isOrderSynced = this.store.isOrderSynced; // 检查订单是否已同步,已同步的订单不能取消
1814
1984
  if (!isOrderSynced) {
1815
- _context21.next = 11;
1985
+ _context22.next = 11;
1816
1986
  break;
1817
1987
  }
1818
1988
  this.logInfo('订单已同步到后端,不能取消:', {
1819
1989
  orderId: currentOrderId,
1820
1990
  orderUuid: currentOrderUuid
1821
1991
  });
1822
- return _context21.abrupt("return", {
1992
+ return _context22.abrupt("return", {
1823
1993
  success: false,
1824
1994
  message: '订单已同步到后端,无法取消',
1825
1995
  orderId: currentOrderId
1826
1996
  });
1827
1997
  case 11:
1828
- _context21.prev = 11;
1998
+ _context22.prev = 11;
1829
1999
  this.logInfo('删除本地订单数据');
1830
- _context21.next = 15;
2000
+ _context22.next = 15;
1831
2001
  return this.payment.deletePaymentOrderAsync(currentOrderUuid);
1832
2002
  case 15:
1833
2003
  this.logInfo('本地订单数据删除成功');
1834
- _context21.next = 21;
2004
+ _context22.next = 21;
1835
2005
  break;
1836
2006
  case 18:
1837
- _context21.prev = 18;
1838
- _context21.t0 = _context21["catch"](11);
1839
- this.logWarning('删除本地订单数据失败,但继续执行:', _context21.t0);
2007
+ _context22.prev = 18;
2008
+ _context22.t0 = _context22["catch"](11);
2009
+ this.logWarning('删除本地订单数据失败,但继续执行:', _context22.t0);
1840
2010
  case 21:
1841
2011
  // 清理订单相关状态,确保正确释放 currentOrder
1842
2012
  this.logInfo('清理订单相关状态');
@@ -1852,7 +2022,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1852
2022
  this.logInfo('订单状态清理完成,currentOrder已释放');
1853
2023
 
1854
2024
  // 触发订单取消事件
1855
- _context21.next = 32;
2025
+ _context22.next = 32;
1856
2026
  return this.core.effects.emit(CheckoutHooks.OnOrderCancelled, {
1857
2027
  orderUuid: currentOrderUuid,
1858
2028
  orderId: currentOrderId,
@@ -1867,27 +2037,27 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1867
2037
  orderId: currentOrderId,
1868
2038
  cancelReason: cancelReason
1869
2039
  });
1870
- return _context21.abrupt("return", {
2040
+ return _context22.abrupt("return", {
1871
2041
  success: true,
1872
2042
  message: '本地订单已成功取消',
1873
2043
  orderId: currentOrderId
1874
2044
  });
1875
2045
  case 36:
1876
- _context21.prev = 36;
1877
- _context21.t1 = _context21["catch"](0);
1878
- this.logError('取消本地订单失败:', _context21.t1);
1879
- errorMessage = _context21.t1 instanceof Error ? _context21.t1.message : '未知错误';
1880
- return _context21.abrupt("return", {
2046
+ _context22.prev = 36;
2047
+ _context22.t1 = _context22["catch"](0);
2048
+ this.logError('取消本地订单失败:', _context22.t1);
2049
+ errorMessage = _context22.t1 instanceof Error ? _context22.t1.message : '未知错误';
2050
+ return _context22.abrupt("return", {
1881
2051
  success: false,
1882
2052
  message: "\u53D6\u6D88\u8BA2\u5355\u5931\u8D25: ".concat(errorMessage)
1883
2053
  });
1884
2054
  case 41:
1885
2055
  case "end":
1886
- return _context21.stop();
2056
+ return _context22.stop();
1887
2057
  }
1888
- }, _callee21, this, [[0, 36], [11, 18]]);
2058
+ }, _callee22, this, [[0, 36], [11, 18]]);
1889
2059
  }));
1890
- function cancelCurrentOrderAsync(_x19) {
2060
+ function cancelCurrentOrderAsync(_x20) {
1891
2061
  return _cancelCurrentOrderAsync.apply(this, arguments);
1892
2062
  }
1893
2063
  return cancelCurrentOrderAsync;
@@ -1902,17 +2072,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1902
2072
  }, {
1903
2073
  key: "saveForLaterPaymentAsync",
1904
2074
  value: (function () {
1905
- var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1906
- var orderUuid, currentOrderId, allPaymentItems, syncResult, _this$store$currentOr14, errorMessage;
1907
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1908
- while (1) switch (_context22.prev = _context22.next) {
2075
+ var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
2076
+ var orderUuid, currentOrderId, allPaymentItems, syncResult, _this$store$currentOr15, errorMessage;
2077
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2078
+ while (1) switch (_context23.prev = _context23.next) {
1909
2079
  case 0:
1910
- _context22.prev = 0;
2080
+ _context23.prev = 0;
1911
2081
  if (this.store.currentOrder) {
1912
- _context22.next = 3;
2082
+ _context23.next = 3;
1913
2083
  break;
1914
2084
  }
1915
- return _context22.abrupt("return", {
2085
+ return _context23.abrupt("return", {
1916
2086
  success: false,
1917
2087
  message: '当前没有活跃订单,无法保存'
1918
2088
  });
@@ -1926,14 +2096,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1926
2096
  });
1927
2097
 
1928
2098
  // 获取当前订单的所有支付项
1929
- _context22.next = 8;
2099
+ _context23.next = 8;
1930
2100
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
1931
2101
  case 8:
1932
- allPaymentItems = _context22.sent;
1933
- _context22.next = 11;
2102
+ allPaymentItems = _context23.sent;
2103
+ _context23.next = 11;
1934
2104
  return this.syncOrderToBackendWithReturn(true, allPaymentItems);
1935
2105
  case 11:
1936
- syncResult = _context22.sent;
2106
+ syncResult = _context23.sent;
1937
2107
  this.logInfo('保存订单完成:', {
1938
2108
  orderUuid: orderUuid,
1939
2109
  oldOrderId: currentOrderId,
@@ -1942,7 +2112,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1942
2112
  isOrderSynced: this.store.isOrderSynced,
1943
2113
  filteredPaymentsCount: allPaymentItems.length
1944
2114
  });
1945
- return _context22.abrupt("return", {
2115
+ return _context23.abrupt("return", {
1946
2116
  success: true,
1947
2117
  message: '订单保存成功,可稍后继续支付',
1948
2118
  orderId: syncResult.orderId,
@@ -1950,20 +2120,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1950
2120
  response: syncResult.response
1951
2121
  });
1952
2122
  case 16:
1953
- _context22.prev = 16;
1954
- _context22.t0 = _context22["catch"](0);
1955
- this.logError('保存订单失败:', _context22.t0);
1956
- errorMessage = _context22.t0 instanceof Error ? _context22.t0.message : '保存失败';
1957
- return _context22.abrupt("return", {
2123
+ _context23.prev = 16;
2124
+ _context23.t0 = _context23["catch"](0);
2125
+ this.logError('保存订单失败:', _context23.t0);
2126
+ errorMessage = _context23.t0 instanceof Error ? _context23.t0.message : '保存失败';
2127
+ return _context23.abrupt("return", {
1958
2128
  success: false,
1959
2129
  message: "\u8BA2\u5355\u4FDD\u5B58\u5931\u8D25: ".concat(errorMessage),
1960
- orderUuid: (_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.uuid
2130
+ orderUuid: (_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.uuid
1961
2131
  });
1962
2132
  case 21:
1963
2133
  case "end":
1964
- return _context22.stop();
2134
+ return _context23.stop();
1965
2135
  }
1966
- }, _callee22, this, [[0, 16]]);
2136
+ }, _callee23, this, [[0, 16]]);
1967
2137
  }));
1968
2138
  function saveForLaterPaymentAsync() {
1969
2139
  return _saveForLaterPaymentAsync.apply(this, arguments);
@@ -1979,20 +2149,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1979
2149
  }, {
1980
2150
  key: "updateOrderNoteAsync",
1981
2151
  value: (function () {
1982
- var _updateOrderNoteAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(note) {
1983
- var _this$store$currentOr15, _this$store$currentOr16, oldNote, orderInPayment;
1984
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1985
- while (1) switch (_context23.prev = _context23.next) {
2152
+ var _updateOrderNoteAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(note) {
2153
+ var _this$store$currentOr16, _this$store$currentOr17, oldNote, orderInPayment;
2154
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2155
+ while (1) switch (_context24.prev = _context24.next) {
1986
2156
  case 0:
1987
- _context23.prev = 0;
2157
+ _context24.prev = 0;
1988
2158
  if (this.store.localOrderData) {
1989
- _context23.next = 3;
2159
+ _context24.next = 3;
1990
2160
  break;
1991
2161
  }
1992
2162
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '没有本地订单数据,无法更新备注');
1993
2163
  case 3:
1994
2164
  console.log('[Checkout] 更新订单备注:', {
1995
- orderUuid: (_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.uuid,
2165
+ orderUuid: (_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.uuid,
1996
2166
  oldNote: this.store.localOrderData.shop_note,
1997
2167
  newNote: note
1998
2168
  });
@@ -2003,29 +2173,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2003
2173
 
2004
2174
  // 如果有当前订单,也同步到Payment模块中的订单数据
2005
2175
  if (!this.store.currentOrder) {
2006
- _context23.next = 17;
2176
+ _context24.next = 17;
2007
2177
  break;
2008
2178
  }
2009
- _context23.prev = 7;
2010
- _context23.next = 10;
2179
+ _context24.prev = 7;
2180
+ _context24.next = 10;
2011
2181
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
2012
2182
  case 10:
2013
- orderInPayment = _context23.sent;
2183
+ orderInPayment = _context24.sent;
2014
2184
  if (orderInPayment && orderInPayment.note !== undefined) {
2015
2185
  // 使用Payment模块的更新方法(如果有的话)
2016
2186
  // 这里可能需要根据Payment模块的实际API来调整
2017
2187
  console.log('[Checkout] 同步备注到Payment模块的订单数据中');
2018
2188
  }
2019
- _context23.next = 17;
2189
+ _context24.next = 17;
2020
2190
  break;
2021
2191
  case 14:
2022
- _context23.prev = 14;
2023
- _context23.t0 = _context23["catch"](7);
2024
- console.warn('[Checkout] 同步备注到Payment模块失败,但本地更新成功:', _context23.t0);
2192
+ _context24.prev = 14;
2193
+ _context24.t0 = _context24["catch"](7);
2194
+ console.warn('[Checkout] 同步备注到Payment模块失败,但本地更新成功:', _context24.t0);
2025
2195
  case 17:
2026
- _context23.next = 19;
2196
+ _context24.next = 19;
2027
2197
  return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
2028
- orderUuid: (_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.uuid,
2198
+ orderUuid: (_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.uuid,
2029
2199
  oldNote: oldNote,
2030
2200
  newNote: note,
2031
2201
  timestamp: Date.now()
@@ -2035,23 +2205,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2035
2205
  oldNote: oldNote,
2036
2206
  newNote: note
2037
2207
  });
2038
- _context23.next = 28;
2208
+ _context24.next = 28;
2039
2209
  break;
2040
2210
  case 22:
2041
- _context23.prev = 22;
2042
- _context23.t1 = _context23["catch"](0);
2043
- console.error('[Checkout] 更新订单备注失败:', _context23.t1);
2044
- _context23.next = 27;
2045
- return this.handleError(_context23.t1, CheckoutErrorType.ValidationFailed);
2211
+ _context24.prev = 22;
2212
+ _context24.t1 = _context24["catch"](0);
2213
+ console.error('[Checkout] 更新订单备注失败:', _context24.t1);
2214
+ _context24.next = 27;
2215
+ return this.handleError(_context24.t1, CheckoutErrorType.ValidationFailed);
2046
2216
  case 27:
2047
- throw _context23.t1;
2217
+ throw _context24.t1;
2048
2218
  case 28:
2049
2219
  case "end":
2050
- return _context23.stop();
2220
+ return _context24.stop();
2051
2221
  }
2052
- }, _callee23, this, [[0, 22], [7, 14]]);
2222
+ }, _callee24, this, [[0, 22], [7, 14]]);
2053
2223
  }));
2054
- function updateOrderNoteAsync(_x20) {
2224
+ function updateOrderNoteAsync(_x21) {
2055
2225
  return _updateOrderNoteAsync.apply(this, arguments);
2056
2226
  }
2057
2227
  return updateOrderNoteAsync;
@@ -2063,14 +2233,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2063
2233
  }, {
2064
2234
  key: "handleError",
2065
2235
  value: (function () {
2066
- var _handleError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(error, type) {
2236
+ var _handleError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(error, type) {
2067
2237
  var checkoutError;
2068
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2069
- while (1) switch (_context24.prev = _context24.next) {
2238
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2239
+ while (1) switch (_context25.prev = _context25.next) {
2070
2240
  case 0:
2071
2241
  checkoutError = error instanceof Error && 'type' in error ? error : createCheckoutError(type, error.message, error);
2072
2242
  this.store.lastError = checkoutError;
2073
- _context24.next = 4;
2243
+ _context25.next = 4;
2074
2244
  return this.core.effects.emit(CheckoutHooks.OnError, {
2075
2245
  error: checkoutError,
2076
2246
  context: {},
@@ -2080,11 +2250,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2080
2250
  console.error('[Checkout] 错误:', checkoutError);
2081
2251
  case 5:
2082
2252
  case "end":
2083
- return _context24.stop();
2253
+ return _context25.stop();
2084
2254
  }
2085
- }, _callee24, this);
2255
+ }, _callee25, this);
2086
2256
  }));
2087
- function handleError(_x21, _x22) {
2257
+ function handleError(_x22, _x23) {
2088
2258
  return _handleError.apply(this, arguments);
2089
2259
  }
2090
2260
  return handleError;
@@ -2096,31 +2266,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2096
2266
  }, {
2097
2267
  key: "handlePaymentSuccess",
2098
2268
  value: (function () {
2099
- var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(data) {
2100
- var _this$store$currentOr17;
2101
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2102
- while (1) switch (_context25.prev = _context25.next) {
2269
+ var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(data) {
2270
+ var _this$store$currentOr18;
2271
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2272
+ while (1) switch (_context26.prev = _context26.next) {
2103
2273
  case 0:
2104
- _context25.next = 2;
2274
+ _context26.next = 2;
2105
2275
  return this.updateStateAmountToRemaining();
2106
2276
  case 2:
2107
- _context25.next = 4;
2277
+ _context26.next = 4;
2108
2278
  return this.core.effects.emit(CheckoutHooks.OnPaymentSuccess, {
2109
2279
  orderUuid: data.orderUuid,
2110
2280
  paymentMethodCode: '',
2111
- amount: ((_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.total_amount) || '0',
2281
+ amount: ((_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.total_amount) || '0',
2112
2282
  timestamp: data.timestamp
2113
2283
  });
2114
2284
  case 4:
2115
- _context25.next = 6;
2285
+ _context26.next = 6;
2116
2286
  return this.completeCheckoutAsync();
2117
2287
  case 6:
2118
2288
  case "end":
2119
- return _context25.stop();
2289
+ return _context26.stop();
2120
2290
  }
2121
- }, _callee25, this);
2291
+ }, _callee26, this);
2122
2292
  }));
2123
- function handlePaymentSuccess(_x23) {
2293
+ function handlePaymentSuccess(_x24) {
2124
2294
  return _handlePaymentSuccess.apply(this, arguments);
2125
2295
  }
2126
2296
  return handlePaymentSuccess;
@@ -2132,30 +2302,30 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2132
2302
  }, {
2133
2303
  key: "handlePaymentError",
2134
2304
  value: (function () {
2135
- var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(data) {
2136
- var _this$store$currentOr18;
2305
+ var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(data) {
2306
+ var _this$store$currentOr19;
2137
2307
  var error;
2138
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2139
- while (1) switch (_context26.prev = _context26.next) {
2308
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2309
+ while (1) switch (_context27.prev = _context27.next) {
2140
2310
  case 0:
2141
2311
  error = createCheckoutError(CheckoutErrorType.PaymentFailed, data.error || '支付同步失败');
2142
- _context26.next = 3;
2312
+ _context27.next = 3;
2143
2313
  return this.handleError(error instanceof Error ? error : new Error(String(error)), CheckoutErrorType.PaymentFailed);
2144
2314
  case 3:
2145
- _context26.next = 5;
2315
+ _context27.next = 5;
2146
2316
  return this.core.effects.emit(CheckoutHooks.OnPaymentFailed, {
2147
2317
  orderUuid: data.orderUuid,
2148
2318
  paymentMethodCode: '',
2149
- amount: ((_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.total_amount) || '0',
2319
+ amount: ((_this$store$currentOr19 = this.store.currentOrder) === null || _this$store$currentOr19 === void 0 ? void 0 : _this$store$currentOr19.total_amount) || '0',
2150
2320
  timestamp: data.timestamp
2151
2321
  });
2152
2322
  case 5:
2153
2323
  case "end":
2154
- return _context26.stop();
2324
+ return _context27.stop();
2155
2325
  }
2156
- }, _callee26, this);
2326
+ }, _callee27, this);
2157
2327
  }));
2158
- function handlePaymentError(_x24) {
2328
+ function handlePaymentError(_x25) {
2159
2329
  return _handlePaymentError.apply(this, arguments);
2160
2330
  }
2161
2331
  return handlePaymentError;
@@ -2179,43 +2349,43 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2179
2349
  }, {
2180
2350
  key: "processCashPaymentItem",
2181
2351
  value: (function () {
2182
- var _processCashPaymentItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(paymentItem) {
2352
+ var _processCashPaymentItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(paymentItem) {
2183
2353
  var cashPayment, remainingAmountStr, remainingAmount, cashAmount, changeAmount, processedPaymentItem;
2184
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2185
- while (1) switch (_context27.prev = _context27.next) {
2354
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2355
+ while (1) switch (_context28.prev = _context28.next) {
2186
2356
  case 0:
2187
2357
  // 检查是否是现金支付
2188
2358
  cashPayment = isCashPayment(paymentItem.code, paymentItem.type);
2189
2359
  if (cashPayment) {
2190
- _context27.next = 3;
2360
+ _context28.next = 3;
2191
2361
  break;
2192
2362
  }
2193
- return _context27.abrupt("return", paymentItem);
2363
+ return _context28.abrupt("return", paymentItem);
2194
2364
  case 3:
2195
- _context27.prev = 3;
2196
- _context27.next = 6;
2365
+ _context28.prev = 3;
2366
+ _context28.next = 6;
2197
2367
  return this.calculateRemainingAmountAsync();
2198
2368
  case 6:
2199
- remainingAmountStr = _context27.sent;
2369
+ remainingAmountStr = _context28.sent;
2200
2370
  remainingAmount = new Decimal(remainingAmountStr);
2201
2371
  cashAmount = new Decimal(String(paymentItem.amount)); // 如果现金金额小于等于剩余待付金额,无需找零
2202
2372
  if (!cashAmount.lte(remainingAmount)) {
2203
- _context27.next = 11;
2373
+ _context28.next = 11;
2204
2374
  break;
2205
2375
  }
2206
- return _context27.abrupt("return", paymentItem);
2376
+ return _context28.abrupt("return", paymentItem);
2207
2377
  case 11:
2208
2378
  // 使用 Decimal.js 安全计算找零金额
2209
2379
  changeAmount = cashAmount.sub(remainingAmount); // 如果还有 rounding_amount 的配置,要判断是否和 changeAmount 相等
2210
2380
  if (!(Number(paymentItem.rounding_amount) > 0)) {
2211
- _context27.next = 18;
2381
+ _context28.next = 18;
2212
2382
  break;
2213
2383
  }
2214
2384
  if (!(Number(paymentItem.rounding_amount) === changeAmount.toNumber())) {
2215
- _context27.next = 17;
2385
+ _context28.next = 17;
2216
2386
  break;
2217
2387
  }
2218
- return _context27.abrupt("return", paymentItem);
2388
+ return _context28.abrupt("return", paymentItem);
2219
2389
  case 17:
2220
2390
  // 如果不等于,则remainingAmount需要加上 rounding_amount,避免这里被改为未舍入金额
2221
2391
  remainingAmount = remainingAmount.add(new Decimal(paymentItem.rounding_amount || '0'));
@@ -2243,20 +2413,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2243
2413
  changeAmountPrecise: changeAmount.toString()
2244
2414
  }
2245
2415
  });
2246
- return _context27.abrupt("return", processedPaymentItem);
2416
+ return _context28.abrupt("return", processedPaymentItem);
2247
2417
  case 23:
2248
- _context27.prev = 23;
2249
- _context27.t0 = _context27["catch"](3);
2250
- this.logError('处理现金支付项时出错:', _context27.t0);
2418
+ _context28.prev = 23;
2419
+ _context28.t0 = _context28["catch"](3);
2420
+ this.logError('处理现金支付项时出错:', _context28.t0);
2251
2421
  // 出错时返回原始支付项,避免中断支付流程
2252
- return _context27.abrupt("return", paymentItem);
2422
+ return _context28.abrupt("return", paymentItem);
2253
2423
  case 27:
2254
2424
  case "end":
2255
- return _context27.stop();
2425
+ return _context28.stop();
2256
2426
  }
2257
- }, _callee27, this, [[3, 23]]);
2427
+ }, _callee28, this, [[3, 23]]);
2258
2428
  }));
2259
- function processCashPaymentItem(_x25) {
2429
+ function processCashPaymentItem(_x26) {
2260
2430
  return _processCashPaymentItem.apply(this, arguments);
2261
2431
  }
2262
2432
  return processCashPaymentItem;
@@ -2268,31 +2438,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2268
2438
  }, {
2269
2439
  key: "preloadPaymentMethods",
2270
2440
  value: (function () {
2271
- var _preloadPaymentMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2441
+ var _preloadPaymentMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2272
2442
  var methods;
2273
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2274
- while (1) switch (_context28.prev = _context28.next) {
2443
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2444
+ while (1) switch (_context29.prev = _context29.next) {
2275
2445
  case 0:
2276
- _context28.prev = 0;
2446
+ _context29.prev = 0;
2277
2447
  console.log('[Checkout] 预加载支付方式...');
2278
- _context28.next = 4;
2448
+ _context29.next = 4;
2279
2449
  return this.payment.getPayMethodListAsync();
2280
2450
  case 4:
2281
- methods = _context28.sent;
2451
+ methods = _context29.sent;
2282
2452
  this.store.paymentMethods = methods;
2283
2453
  console.log("[Checkout] \u9884\u52A0\u8F7D\u5B8C\u6210\uFF0C\u5171 ".concat(methods.length, " \u79CD\u652F\u4ED8\u65B9\u5F0F"));
2284
- _context28.next = 13;
2454
+ _context29.next = 13;
2285
2455
  break;
2286
2456
  case 9:
2287
- _context28.prev = 9;
2288
- _context28.t0 = _context28["catch"](0);
2289
- console.error('[Checkout] 预加载支付方式失败:', _context28.t0);
2457
+ _context29.prev = 9;
2458
+ _context29.t0 = _context29["catch"](0);
2459
+ console.error('[Checkout] 预加载支付方式失败:', _context29.t0);
2290
2460
  this.store.paymentMethods = [];
2291
2461
  case 13:
2292
2462
  case "end":
2293
- return _context28.stop();
2463
+ return _context29.stop();
2294
2464
  }
2295
- }, _callee28, this, [[0, 9]]);
2465
+ }, _callee29, this, [[0, 9]]);
2296
2466
  }));
2297
2467
  function preloadPaymentMethods() {
2298
2468
  return _preloadPaymentMethods.apply(this, arguments);
@@ -2308,59 +2478,59 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2308
2478
  }, {
2309
2479
  key: "cleanupExpiredOrdersAsync",
2310
2480
  value: (function () {
2311
- var _cleanupExpiredOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2481
+ var _cleanupExpiredOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2312
2482
  var cleanupConfig, isCleanupEnabled, retentionDays, maxOrdersToDelete, allOrders, thresholdDate, deletedCount, ordersToDelete, _iterator, _step, order, _order$order_info, _order$order_info2, isSynced, orderCreatedAt, actualOrdersToDelete, _iterator2, _step2, orderInfo, summary, errorMessage;
2313
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2314
- while (1) switch (_context29.prev = _context29.next) {
2483
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2484
+ while (1) switch (_context30.prev = _context30.next) {
2315
2485
  case 0:
2316
- _context29.prev = 0;
2486
+ _context30.prev = 0;
2317
2487
  // 检查是否启用了清理功能
2318
2488
  cleanupConfig = this.otherParams.orderDataCleanup || {};
2319
2489
  isCleanupEnabled = cleanupConfig.enabled !== false; // 默认启用
2320
2490
  retentionDays = cleanupConfig.retentionDays || 7; // 默认保留7天
2321
2491
  maxOrdersToDelete = cleanupConfig.maxOrdersToDelete || 100; // 默认最多删除100个订单
2322
2492
  if (isCleanupEnabled) {
2323
- _context29.next = 8;
2493
+ _context30.next = 8;
2324
2494
  break;
2325
2495
  }
2326
2496
  console.log('[Checkout] 订单数据清理功能已禁用');
2327
- return _context29.abrupt("return");
2497
+ return _context30.abrupt("return");
2328
2498
  case 8:
2329
2499
  console.log("[Checkout] \u5F00\u59CB\u6E05\u7406\u8FC7\u671F\u8BA2\u5355\u6570\u636E\uFF08\u4FDD\u7559 ".concat(retentionDays, " \u5929\u5185\u7684\u6570\u636E\uFF09..."));
2330
2500
 
2331
2501
  // 获取所有订单
2332
- _context29.next = 11;
2502
+ _context30.next = 11;
2333
2503
  return this.payment.getOrderListAsync();
2334
2504
  case 11:
2335
- allOrders = _context29.sent;
2505
+ allOrders = _context30.sent;
2336
2506
  if (!(!allOrders || allOrders.length === 0)) {
2337
- _context29.next = 15;
2507
+ _context30.next = 15;
2338
2508
  break;
2339
2509
  }
2340
2510
  console.log('[Checkout] 没有找到需要清理的订单数据');
2341
- return _context29.abrupt("return");
2511
+ return _context30.abrupt("return");
2342
2512
  case 15:
2343
2513
  thresholdDate = new Date();
2344
2514
  thresholdDate.setDate(thresholdDate.getDate() - retentionDays);
2345
2515
  deletedCount = 0;
2346
2516
  ordersToDelete = [];
2347
2517
  _iterator = _createForOfIteratorHelper(allOrders);
2348
- _context29.prev = 20;
2518
+ _context30.prev = 20;
2349
2519
  _iterator.s();
2350
2520
  case 22:
2351
2521
  if ((_step = _iterator.n()).done) {
2352
- _context29.next = 41;
2522
+ _context30.next = 41;
2353
2523
  break;
2354
2524
  }
2355
2525
  order = _step.value;
2356
- _context29.prev = 24;
2526
+ _context30.prev = 24;
2357
2527
  // 检查订单是否已同步(订单ID不是虚拟ID)
2358
2528
  isSynced = order.order_id && !isVirtualOrderId(order.order_id);
2359
2529
  if (isSynced) {
2360
- _context29.next = 28;
2530
+ _context30.next = 28;
2361
2531
  break;
2362
2532
  }
2363
- return _context29.abrupt("continue", 39);
2533
+ return _context30.abrupt("continue", 39);
2364
2534
  case 28:
2365
2535
  // 检查创建时间
2366
2536
  orderCreatedAt = null; // 尝试从 order_info.created_at 获取创建时间
@@ -2374,10 +2544,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2374
2544
 
2375
2545
  // 如果无法获取创建时间,跳过此订单
2376
2546
  if (!(!orderCreatedAt || isNaN(orderCreatedAt.getTime()))) {
2377
- _context29.next = 32;
2547
+ _context30.next = 32;
2378
2548
  break;
2379
2549
  }
2380
- return _context29.abrupt("continue", 39);
2550
+ return _context30.abrupt("continue", 39);
2381
2551
  case 32:
2382
2552
  // 检查是否超过指定天数
2383
2553
  if (orderCreatedAt < thresholdDate) {
@@ -2388,27 +2558,27 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2388
2558
  daysSinceCreated: Math.floor((Date.now() - orderCreatedAt.getTime()) / (1000 * 60 * 60 * 24))
2389
2559
  });
2390
2560
  }
2391
- _context29.next = 39;
2561
+ _context30.next = 39;
2392
2562
  break;
2393
2563
  case 35:
2394
- _context29.prev = 35;
2395
- _context29.t0 = _context29["catch"](24);
2396
- console.warn("[Checkout] \u5904\u7406\u8BA2\u5355 ".concat(order.uuid, " \u65F6\u51FA\u9519:"), _context29.t0);
2397
- return _context29.abrupt("continue", 39);
2564
+ _context30.prev = 35;
2565
+ _context30.t0 = _context30["catch"](24);
2566
+ console.warn("[Checkout] \u5904\u7406\u8BA2\u5355 ".concat(order.uuid, " \u65F6\u51FA\u9519:"), _context30.t0);
2567
+ return _context30.abrupt("continue", 39);
2398
2568
  case 39:
2399
- _context29.next = 22;
2569
+ _context30.next = 22;
2400
2570
  break;
2401
2571
  case 41:
2402
- _context29.next = 46;
2572
+ _context30.next = 46;
2403
2573
  break;
2404
2574
  case 43:
2405
- _context29.prev = 43;
2406
- _context29.t1 = _context29["catch"](20);
2407
- _iterator.e(_context29.t1);
2575
+ _context30.prev = 43;
2576
+ _context30.t1 = _context30["catch"](20);
2577
+ _iterator.e(_context30.t1);
2408
2578
  case 46:
2409
- _context29.prev = 46;
2579
+ _context30.prev = 46;
2410
2580
  _iterator.f();
2411
- return _context29.finish(46);
2581
+ return _context30.finish(46);
2412
2582
  case 49:
2413
2583
  // 按创建时间排序(最老的先删除)并限制删除数量
2414
2584
  ordersToDelete.sort(function (a, b) {
@@ -2416,40 +2586,40 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2416
2586
  });
2417
2587
  actualOrdersToDelete = ordersToDelete.slice(0, maxOrdersToDelete); // 删除符合条件的订单
2418
2588
  _iterator2 = _createForOfIteratorHelper(actualOrdersToDelete);
2419
- _context29.prev = 52;
2589
+ _context30.prev = 52;
2420
2590
  _iterator2.s();
2421
2591
  case 54:
2422
2592
  if ((_step2 = _iterator2.n()).done) {
2423
- _context29.next = 68;
2593
+ _context30.next = 68;
2424
2594
  break;
2425
2595
  }
2426
2596
  orderInfo = _step2.value;
2427
- _context29.prev = 56;
2428
- _context29.next = 59;
2597
+ _context30.prev = 56;
2598
+ _context30.next = 59;
2429
2599
  return this.payment.deletePaymentOrderAsync(orderInfo.uuid);
2430
2600
  case 59:
2431
2601
  deletedCount++;
2432
2602
  console.log("[Checkout] \u5DF2\u5220\u9664\u8FC7\u671F\u8BA2\u5355: ".concat(orderInfo.orderId, " (").concat(orderInfo.daysSinceCreated, " \u5929\u524D\u521B\u5EFA)"));
2433
- _context29.next = 66;
2603
+ _context30.next = 66;
2434
2604
  break;
2435
2605
  case 63:
2436
- _context29.prev = 63;
2437
- _context29.t2 = _context29["catch"](56);
2438
- console.error("[Checkout] \u5220\u9664\u8BA2\u5355 ".concat(orderInfo.uuid, " \u5931\u8D25:"), _context29.t2);
2606
+ _context30.prev = 63;
2607
+ _context30.t2 = _context30["catch"](56);
2608
+ console.error("[Checkout] \u5220\u9664\u8BA2\u5355 ".concat(orderInfo.uuid, " \u5931\u8D25:"), _context30.t2);
2439
2609
  case 66:
2440
- _context29.next = 54;
2610
+ _context30.next = 54;
2441
2611
  break;
2442
2612
  case 68:
2443
- _context29.next = 73;
2613
+ _context30.next = 73;
2444
2614
  break;
2445
2615
  case 70:
2446
- _context29.prev = 70;
2447
- _context29.t3 = _context29["catch"](52);
2448
- _iterator2.e(_context29.t3);
2616
+ _context30.prev = 70;
2617
+ _context30.t3 = _context30["catch"](52);
2618
+ _iterator2.e(_context30.t3);
2449
2619
  case 73:
2450
- _context29.prev = 73;
2620
+ _context30.prev = 73;
2451
2621
  _iterator2.f();
2452
- return _context29.finish(73);
2622
+ return _context30.finish(73);
2453
2623
  case 76:
2454
2624
  summary = {
2455
2625
  totalOrders: allOrders.length,
@@ -2467,21 +2637,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2467
2637
  } else {
2468
2638
  console.log("[Checkout] \u8FC7\u671F\u8BA2\u5355\u6E05\u7406\u5B8C\u6210: \u603B\u8BA1 ".concat(allOrders.length, " \u4E2A\u8BA2\u5355\uFF0C\u5220\u9664\u4E86 ").concat(deletedCount, " \u4E2A\u8FC7\u671F\u5DF2\u540C\u6B65\u8BA2\u5355"));
2469
2639
  }
2470
- _context29.next = 86;
2640
+ _context30.next = 86;
2471
2641
  break;
2472
2642
  case 81:
2473
- _context29.prev = 81;
2474
- _context29.t4 = _context29["catch"](0);
2475
- errorMessage = _context29.t4 instanceof Error ? _context29.t4.message : String(_context29.t4);
2476
- console.error('[Checkout] 清理过期订单数据失败:', _context29.t4);
2643
+ _context30.prev = 81;
2644
+ _context30.t4 = _context30["catch"](0);
2645
+ errorMessage = _context30.t4 instanceof Error ? _context30.t4.message : String(_context30.t4);
2646
+ console.error('[Checkout] 清理过期订单数据失败:', _context30.t4);
2477
2647
  this.logError('Expired orders cleanup failed', {
2478
2648
  error: errorMessage
2479
2649
  });
2480
2650
  case 86:
2481
2651
  case "end":
2482
- return _context29.stop();
2652
+ return _context30.stop();
2483
2653
  }
2484
- }, _callee29, this, [[0, 81], [20, 43, 46, 49], [24, 35], [52, 70, 73, 76], [56, 63]]);
2654
+ }, _callee30, this, [[0, 81], [20, 43, 46, 49], [24, 35], [52, 70, 73, 76], [56, 63]]);
2485
2655
  }));
2486
2656
  function cleanupExpiredOrdersAsync() {
2487
2657
  return _cleanupExpiredOrdersAsync.apply(this, arguments);
@@ -2495,24 +2665,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2495
2665
  }, {
2496
2666
  key: "calculatePaidAmountAsync",
2497
2667
  value: (function () {
2498
- var _calculatePaidAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2668
+ var _calculatePaidAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2499
2669
  var payments, paidAmount, result;
2500
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2501
- while (1) switch (_context30.prev = _context30.next) {
2670
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2671
+ while (1) switch (_context31.prev = _context31.next) {
2502
2672
  case 0:
2503
2673
  if (this.store.currentOrder) {
2504
- _context30.next = 3;
2674
+ _context31.next = 3;
2505
2675
  break;
2506
2676
  }
2507
2677
  this.logWarning('[Checkout] calculatePaidAmountAsync: 没有当前订单');
2508
- return _context30.abrupt("return", '0.00');
2678
+ return _context31.abrupt("return", '0.00');
2509
2679
  case 3:
2510
- _context30.prev = 3;
2511
- _context30.next = 6;
2680
+ _context31.prev = 3;
2681
+ _context31.next = 6;
2512
2682
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
2513
2683
  );
2514
2684
  case 6:
2515
- payments = _context30.sent;
2685
+ payments = _context31.sent;
2516
2686
  // 使用 Decimal.js 进行安全的金额计算
2517
2687
  paidAmount = payments.filter(function (payment) {
2518
2688
  return payment.status !== 'voided';
@@ -2541,17 +2711,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2541
2711
  }, new Decimal(0));
2542
2712
  result = paidAmount.toFixed(2);
2543
2713
  this.logInfo('calculatePaidAmountAsync: 计算结果 =', result);
2544
- return _context30.abrupt("return", result);
2714
+ return _context31.abrupt("return", result);
2545
2715
  case 13:
2546
- _context30.prev = 13;
2547
- _context30.t0 = _context30["catch"](3);
2548
- this.logError('calculatePaidAmountAsync 失败:', _context30.t0);
2549
- return _context30.abrupt("return", '0.00');
2716
+ _context31.prev = 13;
2717
+ _context31.t0 = _context31["catch"](3);
2718
+ this.logError('calculatePaidAmountAsync 失败:', _context31.t0);
2719
+ return _context31.abrupt("return", '0.00');
2550
2720
  case 17:
2551
2721
  case "end":
2552
- return _context30.stop();
2722
+ return _context31.stop();
2553
2723
  }
2554
- }, _callee30, this, [[3, 13]]);
2724
+ }, _callee31, this, [[3, 13]]);
2555
2725
  }));
2556
2726
  function calculatePaidAmountAsync() {
2557
2727
  return _calculatePaidAmountAsync.apply(this, arguments);
@@ -2565,34 +2735,34 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2565
2735
  }, {
2566
2736
  key: "calculateRemainingAmountAsync",
2567
2737
  value: (function () {
2568
- var _calculateRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2738
+ var _calculateRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2569
2739
  var totalAmount, paidAmountStr, paidAmount, remainingAmount, result;
2570
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2571
- while (1) switch (_context31.prev = _context31.next) {
2740
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2741
+ while (1) switch (_context32.prev = _context32.next) {
2572
2742
  case 0:
2573
2743
  if (this.store.currentOrder) {
2574
- _context31.next = 3;
2744
+ _context32.next = 3;
2575
2745
  break;
2576
2746
  }
2577
2747
  this.logWarning('calculateRemainingAmountAsync: 没有当前订单');
2578
- return _context31.abrupt("return", '0.00');
2748
+ return _context32.abrupt("return", '0.00');
2579
2749
  case 3:
2580
2750
  // 使用 Decimal.js 进行安全的金额计算
2581
2751
  totalAmount = new Decimal(this.store.currentOrder.total_amount || '0');
2582
- _context31.next = 6;
2752
+ _context32.next = 6;
2583
2753
  return this.calculatePaidAmountAsync();
2584
2754
  case 6:
2585
- paidAmountStr = _context31.sent;
2755
+ paidAmountStr = _context32.sent;
2586
2756
  paidAmount = new Decimal(paidAmountStr);
2587
2757
  remainingAmount = totalAmount.sub(paidAmount); // 确保剩余金额不为负数
2588
2758
  result = Decimal.max(0, remainingAmount).toFixed(2);
2589
2759
  this.logInfo('calculateRemainingAmountAsync: 计算=', result);
2590
- return _context31.abrupt("return", result);
2760
+ return _context32.abrupt("return", result);
2591
2761
  case 12:
2592
2762
  case "end":
2593
- return _context31.stop();
2763
+ return _context32.stop();
2594
2764
  }
2595
- }, _callee31, this);
2765
+ }, _callee32, this);
2596
2766
  }));
2597
2767
  function calculateRemainingAmountAsync() {
2598
2768
  return _calculateRemainingAmountAsync.apply(this, arguments);
@@ -2606,25 +2776,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2606
2776
  }, {
2607
2777
  key: "updateBalanceDueAmount",
2608
2778
  value: (function () {
2609
- var _updateBalanceDueAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2779
+ var _updateBalanceDueAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2610
2780
  var remainingAmount, currentBalanceDueAmount;
2611
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2612
- while (1) switch (_context32.prev = _context32.next) {
2781
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2782
+ while (1) switch (_context33.prev = _context33.next) {
2613
2783
  case 0:
2614
- _context32.prev = 0;
2615
- _context32.next = 3;
2784
+ _context33.prev = 0;
2785
+ _context33.next = 3;
2616
2786
  return this.calculateRemainingAmountAsync();
2617
2787
  case 3:
2618
- remainingAmount = _context32.sent;
2788
+ remainingAmount = _context33.sent;
2619
2789
  currentBalanceDueAmount = this.store.balanceDueAmount; // 只有当剩余金额与当前 balanceDueAmount 不同时才更新
2620
2790
  if (!(remainingAmount !== currentBalanceDueAmount)) {
2621
- _context32.next = 12;
2791
+ _context33.next = 12;
2622
2792
  break;
2623
2793
  }
2624
2794
  this.store.balanceDueAmount = remainingAmount;
2625
2795
 
2626
2796
  // 发出 balanceDueAmount 变更事件
2627
- _context32.next = 9;
2797
+ _context33.next = 9;
2628
2798
  return this.core.effects.emit(CheckoutHooks.OnBalanceDueAmountChanged, {
2629
2799
  oldAmount: currentBalanceDueAmount,
2630
2800
  newAmount: remainingAmount,
@@ -2635,7 +2805,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2635
2805
  oldAmount: currentBalanceDueAmount,
2636
2806
  newAmount: remainingAmount
2637
2807
  });
2638
- _context32.next = 13;
2808
+ _context33.next = 13;
2639
2809
  break;
2640
2810
  case 12:
2641
2811
  this.logInfo('balanceDueAmount 无需更新,当前值已是最新:', {
@@ -2643,17 +2813,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2643
2813
  remainingAmount: remainingAmount
2644
2814
  });
2645
2815
  case 13:
2646
- _context32.next = 18;
2816
+ _context33.next = 18;
2647
2817
  break;
2648
2818
  case 15:
2649
- _context32.prev = 15;
2650
- _context32.t0 = _context32["catch"](0);
2651
- this.logError('更新 balanceDueAmount 失败:', _context32.t0);
2819
+ _context33.prev = 15;
2820
+ _context33.t0 = _context33["catch"](0);
2821
+ this.logError('更新 balanceDueAmount 失败:', _context33.t0);
2652
2822
  case 18:
2653
2823
  case "end":
2654
- return _context32.stop();
2824
+ return _context33.stop();
2655
2825
  }
2656
- }, _callee32, this, [[0, 15]]);
2826
+ }, _callee33, this, [[0, 15]]);
2657
2827
  }));
2658
2828
  function updateBalanceDueAmount() {
2659
2829
  return _updateBalanceDueAmount.apply(this, arguments);
@@ -2667,16 +2837,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2667
2837
  }, {
2668
2838
  key: "updateStateAmountToRemaining",
2669
2839
  value: (function () {
2670
- var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2840
+ var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
2671
2841
  var remainingAmount, currentStateAmount;
2672
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2673
- while (1) switch (_context33.prev = _context33.next) {
2842
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2843
+ while (1) switch (_context34.prev = _context34.next) {
2674
2844
  case 0:
2675
- _context33.prev = 0;
2676
- _context33.next = 3;
2845
+ _context34.prev = 0;
2846
+ _context34.next = 3;
2677
2847
  return this.calculateRemainingAmountAsync();
2678
2848
  case 3:
2679
- remainingAmount = _context33.sent;
2849
+ remainingAmount = _context34.sent;
2680
2850
  currentStateAmount = this.store.stateAmount; // 只有当剩余金额与当前 stateAmount 不同时才更新
2681
2851
  if (remainingAmount !== currentStateAmount) {
2682
2852
  this.store.stateAmount = remainingAmount;
@@ -2699,23 +2869,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2699
2869
  }
2700
2870
 
2701
2871
  // 同步更新系统内部的 balanceDueAmount
2702
- _context33.next = 8;
2872
+ _context34.next = 8;
2703
2873
  return this.updateBalanceDueAmount();
2704
2874
  case 8:
2705
- _context33.next = 10;
2875
+ _context34.next = 10;
2706
2876
  return this.checkOrderPaymentCompletion();
2707
2877
  case 10:
2708
- _context33.next = 15;
2878
+ _context34.next = 15;
2709
2879
  break;
2710
2880
  case 12:
2711
- _context33.prev = 12;
2712
- _context33.t0 = _context33["catch"](0);
2713
- this.logError('更新 stateAmount 为剩余金额失败:', _context33.t0);
2881
+ _context34.prev = 12;
2882
+ _context34.t0 = _context34["catch"](0);
2883
+ this.logError('更新 stateAmount 为剩余金额失败:', _context34.t0);
2714
2884
  case 15:
2715
2885
  case "end":
2716
- return _context33.stop();
2886
+ return _context34.stop();
2717
2887
  }
2718
- }, _callee33, this, [[0, 12]]);
2888
+ }, _callee34, this, [[0, 12]]);
2719
2889
  }));
2720
2890
  function updateStateAmountToRemaining() {
2721
2891
  return _updateStateAmountToRemaining.apply(this, arguments);
@@ -2731,32 +2901,32 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2731
2901
  }, {
2732
2902
  key: "checkOrderPaymentCompletion",
2733
2903
  value: (function () {
2734
- var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
2904
+ var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
2735
2905
  var remainingAmount, remainingValue, totalAmount, paidAmount, currentPayments, hasPaymentItems, allPaymentsHaveVoucherId, shouldAutoSync;
2736
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2737
- while (1) switch (_context34.prev = _context34.next) {
2906
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2907
+ while (1) switch (_context35.prev = _context35.next) {
2738
2908
  case 0:
2739
- _context34.prev = 0;
2909
+ _context35.prev = 0;
2740
2910
  if (this.store.currentOrder) {
2741
- _context34.next = 3;
2911
+ _context35.next = 3;
2742
2912
  break;
2743
2913
  }
2744
- return _context34.abrupt("return");
2914
+ return _context35.abrupt("return");
2745
2915
  case 3:
2746
- _context34.next = 5;
2916
+ _context35.next = 5;
2747
2917
  return this.calculateRemainingAmountAsync();
2748
2918
  case 5:
2749
- remainingAmount = _context34.sent;
2919
+ remainingAmount = _context35.sent;
2750
2920
  remainingValue = new Decimal(remainingAmount); // 当剩余金额小于等于0时,认为订单已完成支付
2751
2921
  if (!remainingValue.lte(0)) {
2752
- _context34.next = 29;
2922
+ _context35.next = 29;
2753
2923
  break;
2754
2924
  }
2755
2925
  totalAmount = this.store.currentOrder.total_amount;
2756
- _context34.next = 11;
2926
+ _context35.next = 11;
2757
2927
  return this.calculatePaidAmountAsync();
2758
2928
  case 11:
2759
- paidAmount = _context34.sent;
2929
+ paidAmount = _context35.sent;
2760
2930
  this.logInfo('检测到订单支付完成:', {
2761
2931
  orderUuid: this.store.currentOrder.uuid,
2762
2932
  orderId: this.store.currentOrder.order_id,
@@ -2767,11 +2937,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2767
2937
  });
2768
2938
 
2769
2939
  // 从 Payment 模块获取最新支付项,检查自动同步条件
2770
- _context34.next = 15;
2940
+ _context35.next = 15;
2771
2941
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
2772
2942
  );
2773
2943
  case 15:
2774
- currentPayments = _context34.sent;
2944
+ currentPayments = _context35.sent;
2775
2945
  // 检查自动同步条件:
2776
2946
  // 1. 待付金额为 0 ✓ (已在上面检查)
2777
2947
  // 2. 需要有支付项
@@ -2805,14 +2975,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2805
2975
  })
2806
2976
  });
2807
2977
  if (!shouldAutoSync) {
2808
- _context34.next = 26;
2978
+ _context35.next = 26;
2809
2979
  break;
2810
2980
  }
2811
2981
  this.logInfo('满足自动同步条件,开始同步订单到后端...');
2812
- _context34.next = 24;
2982
+ _context35.next = 24;
2813
2983
  return this.syncOrderToBackendWithReturn(false);
2814
2984
  case 24:
2815
- _context34.next = 27;
2985
+ _context35.next = 27;
2816
2986
  break;
2817
2987
  case 26:
2818
2988
  if (!hasPaymentItems) {
@@ -2821,7 +2991,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2821
2991
  this.logInfo('所有支付项均为代金券类型,跳过订单同步');
2822
2992
  }
2823
2993
  case 27:
2824
- _context34.next = 29;
2994
+ _context35.next = 29;
2825
2995
  return this.core.effects.emit(CheckoutHooks.OnOrderPaymentCompleted, {
2826
2996
  orderUuid: this.store.currentOrder.uuid,
2827
2997
  orderId: this.store.currentOrder.order_id,
@@ -2831,17 +3001,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2831
3001
  timestamp: Date.now()
2832
3002
  });
2833
3003
  case 29:
2834
- _context34.next = 34;
3004
+ _context35.next = 34;
2835
3005
  break;
2836
3006
  case 31:
2837
- _context34.prev = 31;
2838
- _context34.t0 = _context34["catch"](0);
2839
- this.logError('检查订单支付完成状态失败:', _context34.t0);
3007
+ _context35.prev = 31;
3008
+ _context35.t0 = _context35["catch"](0);
3009
+ this.logError('检查订单支付完成状态失败:', _context35.t0);
2840
3010
  case 34:
2841
3011
  case "end":
2842
- return _context34.stop();
3012
+ return _context35.stop();
2843
3013
  }
2844
- }, _callee34, this, [[0, 31]]);
3014
+ }, _callee35, this, [[0, 31]]);
2845
3015
  }));
2846
3016
  function checkOrderPaymentCompletion() {
2847
3017
  return _checkOrderPaymentCompletion.apply(this, arguments);
@@ -2859,12 +3029,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2859
3029
  }, {
2860
3030
  key: "syncOrderToBackendWithReturn",
2861
3031
  value: (function () {
2862
- var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
3032
+ var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
2863
3033
  var _this4 = this,
2864
- _this$store$currentOr19,
2865
3034
  _this$store$currentOr20,
2866
- _this$store$currentCu2,
2867
3035
  _this$store$currentOr21,
3036
+ _this$store$currentCu2,
3037
+ _this$store$currentOr22,
2868
3038
  _checkoutResponse3,
2869
3039
  _checkoutResponse4;
2870
3040
  var isManual,
@@ -2896,14 +3066,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2896
3066
  _checkoutResponse7,
2897
3067
  updatedOrder,
2898
3068
  beforeManualUpdate,
2899
- _args35 = arguments;
2900
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2901
- while (1) switch (_context35.prev = _context35.next) {
3069
+ syncedPaymentUuids,
3070
+ _iterator3,
3071
+ _step3,
3072
+ paymentUuid,
3073
+ _args36 = arguments;
3074
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3075
+ while (1) switch (_context36.prev = _context36.next) {
2902
3076
  case 0:
2903
- isManual = _args35.length > 0 && _args35[0] !== undefined ? _args35[0] : false;
2904
- customPaymentItems = _args35.length > 1 ? _args35[1] : undefined;
3077
+ isManual = _args36.length > 0 && _args36[0] !== undefined ? _args36[0] : false;
3078
+ customPaymentItems = _args36.length > 1 ? _args36[1] : undefined;
2905
3079
  if (!(!this.store.localOrderData || !this.store.currentOrder)) {
2906
- _context35.next = 4;
3080
+ _context36.next = 4;
2907
3081
  break;
2908
3082
  }
2909
3083
  throw new Error('缺少必要的订单数据,无法同步到后端');
@@ -2922,17 +3096,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2922
3096
  });
2923
3097
 
2924
3098
  // 获取当前订单的支付项
2925
- _context35.t0 = customPaymentItems;
2926
- if (_context35.t0) {
2927
- _context35.next = 13;
3099
+ _context36.t0 = customPaymentItems;
3100
+ if (_context36.t0) {
3101
+ _context36.next = 13;
2928
3102
  break;
2929
3103
  }
2930
- _context35.next = 12;
3104
+ _context36.next = 12;
2931
3105
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
2932
3106
  case 12:
2933
- _context35.t0 = _context35.sent;
3107
+ _context36.t0 = _context36.sent;
2934
3108
  case 13:
2935
- paymentItems = _context35.t0;
3109
+ paymentItems = _context36.t0;
2936
3110
  // 处理支付项数据,确保包含完整的 metadata
2937
3111
  processedPaymentItems = paymentItems.map(function (item) {
2938
3112
  var _item$metadata, _item$metadata2;
@@ -2943,7 +3117,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2943
3117
  })
2944
3118
  });
2945
3119
  }); // 确定最终的定金金额:优先使用手动设置的值,否则从支付项中计算
2946
- manualDepositAmount = ((_this$store$currentOr19 = this.store.currentOrder) === null || _this$store$currentOr19 === void 0 ? void 0 : _this$store$currentOr19.deposit_amount) || '0.00'; // 计算定金支付项的总金额(order_payment_type="deposit")
3120
+ manualDepositAmount = ((_this$store$currentOr20 = this.store.currentOrder) === null || _this$store$currentOr20 === void 0 ? void 0 : _this$store$currentOr20.deposit_amount) || '0.00'; // 计算定金支付项的总金额(order_payment_type="deposit")
2947
3121
  depositPaymentItems = processedPaymentItems.filter(function (item) {
2948
3122
  return item.order_payment_type === 'deposit' && item.status !== 'voided';
2949
3123
  });
@@ -2996,7 +3170,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2996
3170
  manualDepositAmount: manualDepositAmount,
2997
3171
  calculatedDepositAmount: calculatedDepositAmount,
2998
3172
  finalDepositAmount: finalDepositAmount,
2999
- isDeposit: ((_this$store$currentOr20 = this.store.currentOrder) === null || _this$store$currentOr20 === void 0 ? void 0 : _this$store$currentOr20.is_deposit) || 0
3173
+ isDeposit: ((_this$store$currentOr21 = this.store.currentOrder) === null || _this$store$currentOr21 === void 0 ? void 0 : _this$store$currentOr21.is_deposit) || 0
3000
3174
  });
3001
3175
 
3002
3176
  // 构造订单参数,直接使用 localOrderData 中已处理好的数据
@@ -3018,7 +3192,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3018
3192
  currency_code: this.otherParams.currency_code,
3019
3193
  currency_symbol: this.otherParams.currency_symbol,
3020
3194
  currency_format: this.otherParams.currency_format,
3021
- is_deposit: ((_this$store$currentOr21 = this.store.currentOrder) === null || _this$store$currentOr21 === void 0 ? void 0 : _this$store$currentOr21.is_deposit) || 0,
3195
+ is_deposit: ((_this$store$currentOr22 = this.store.currentOrder) === null || _this$store$currentOr22 === void 0 ? void 0 : _this$store$currentOr22.is_deposit) || 0,
3022
3196
  deposit_amount: finalDepositAmount,
3023
3197
  // 使用最终确定的定金金额(手动设置优先)
3024
3198
  product_tax_fee: this.store.localOrderData.tax_fee,
@@ -3035,7 +3209,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3035
3209
 
3036
3210
  // 发送下单接口请求开始事件
3037
3211
  startTime = Date.now();
3038
- _context35.next = 27;
3212
+ _context36.next = 27;
3039
3213
  return this.core.effects.emit(CheckoutHooks.OnOrderSubmitStart, {
3040
3214
  orderUuid: this.store.currentOrder.uuid,
3041
3215
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3045,7 +3219,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3045
3219
  });
3046
3220
  case 27:
3047
3221
  submitSuccess = false;
3048
- _context35.prev = 28;
3222
+ _context36.prev = 28;
3049
3223
  // 记录接口调用参数
3050
3224
  this.logInfo('Calling backend checkout API', _objectSpread({
3051
3225
  url: '/order/checkout',
@@ -3053,23 +3227,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3053
3227
  }, orderParams));
3054
3228
 
3055
3229
  // 调用 Order 模块的专用 createOrderByCheckout 方法
3056
- _context35.next = 32;
3230
+ _context36.next = 32;
3057
3231
  return this.order.createOrderByCheckout(orderParams);
3058
3232
  case 32:
3059
- checkoutResponse = _context35.sent;
3233
+ checkoutResponse = _context36.sent;
3060
3234
  submitSuccess = true;
3061
3235
  this.logInfo('下单接口调用成功', checkoutResponse);
3062
- _context35.next = 45;
3236
+ _context36.next = 45;
3063
3237
  break;
3064
3238
  case 37:
3065
- _context35.prev = 37;
3066
- _context35.t1 = _context35["catch"](28);
3239
+ _context36.prev = 37;
3240
+ _context36.t1 = _context36["catch"](28);
3067
3241
  submitSuccess = false;
3068
- submitError = _context35.t1 instanceof Error ? _context35.t1.message : String(_context35.t1);
3242
+ submitError = _context36.t1 instanceof Error ? _context36.t1.message : String(_context36.t1);
3069
3243
  this.logError('下单接口调用失败:', submitError);
3070
3244
 
3071
3245
  // 发送订单同步失败事件(网络错误或请求失败)
3072
- _context35.next = 44;
3246
+ _context36.next = 44;
3073
3247
  return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
3074
3248
  orderUuid: this.store.currentOrder.uuid,
3075
3249
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3080,10 +3254,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3080
3254
  timestamp: Date.now()
3081
3255
  });
3082
3256
  case 44:
3083
- throw _context35.t1;
3257
+ throw _context36.t1;
3084
3258
  case 45:
3085
- _context35.prev = 45;
3086
- _context35.next = 48;
3259
+ _context36.prev = 45;
3260
+ _context36.next = 48;
3087
3261
  return this.core.effects.emit(CheckoutHooks.OnOrderSubmitEnd, {
3088
3262
  success: submitSuccess,
3089
3263
  orderUuid: this.store.currentOrder.uuid,
@@ -3095,17 +3269,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3095
3269
  timestamp: Date.now()
3096
3270
  });
3097
3271
  case 48:
3098
- return _context35.finish(45);
3272
+ return _context36.finish(45);
3099
3273
  case 49:
3100
3274
  // 检查响应状态是否为成功状态
3101
3275
  responseStatus = (_checkoutResponse3 = checkoutResponse) === null || _checkoutResponse3 === void 0 ? void 0 : _checkoutResponse3.status;
3102
3276
  isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse4 = checkoutResponse) === null || _checkoutResponse4 === void 0 ? void 0 : _checkoutResponse4.code) === 200;
3103
3277
  if (isSuccessResponse) {
3104
- _context35.next = 56;
3278
+ _context36.next = 56;
3105
3279
  break;
3106
3280
  }
3107
3281
  errorMessage = ((_checkoutResponse5 = checkoutResponse) === null || _checkoutResponse5 === void 0 ? void 0 : _checkoutResponse5.message) || '订单同步失败,后端返回非成功状态'; // 发送订单同步失败事件
3108
- _context35.next = 55;
3282
+ _context36.next = 55;
3109
3283
  return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
3110
3284
  orderUuid: this.store.currentOrder.uuid,
3111
3285
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3120,12 +3294,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3120
3294
  throw new Error(errorMessage);
3121
3295
  case 56:
3122
3296
  if (!isUpdateOperation) {
3123
- _context35.next = 60;
3297
+ _context36.next = 60;
3124
3298
  break;
3125
3299
  }
3126
3300
  // 更新操作:使用现有的订单ID
3127
3301
  realOrderId = currentOrderId;
3128
- _context35.next = 79;
3302
+ _context36.next = 79;
3129
3303
  break;
3130
3304
  case 60:
3131
3305
  // 创建操作:从响应中提取新的订单ID
@@ -3149,11 +3323,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3149
3323
  oldOrderId: this.store.currentOrder.order_id,
3150
3324
  newOrderId: realOrderId
3151
3325
  });
3152
- _context35.prev = 66;
3153
- _context35.next = 69;
3326
+ _context36.prev = 66;
3327
+ _context36.next = 69;
3154
3328
  return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, realOrderId);
3155
3329
  case 69:
3156
- updatedOrder = _context35.sent;
3330
+ updatedOrder = _context36.sent;
3157
3331
  this.logInfo('Payment模块替换订单ID结果:', {
3158
3332
  wasSuccessful: !!updatedOrder,
3159
3333
  returnedOrderId: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.order_id,
@@ -3179,22 +3353,66 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3179
3353
  目标ID: realOrderId
3180
3354
  });
3181
3355
  }
3182
- _context35.next = 79;
3356
+ _context36.next = 79;
3183
3357
  break;
3184
3358
  case 74:
3185
- _context35.prev = 74;
3186
- _context35.t2 = _context35["catch"](66);
3187
- this.logError('调用Payment模块替换订单ID时发生错误:', _context35.t2);
3359
+ _context36.prev = 74;
3360
+ _context36.t2 = _context36["catch"](66);
3361
+ this.logError('调用Payment模块替换订单ID时发生错误:', _context36.t2);
3188
3362
 
3189
3363
  // 发生错误时也进行手动替换
3190
3364
  this.store.currentOrder.order_id = realOrderId;
3191
3365
  this.logInfo('错误恢复:手动设置订单ID:', realOrderId);
3192
3366
  case 79:
3367
+ _context36.prev = 79;
3368
+ syncedPaymentUuids = processedPaymentItems.filter(function (item) {
3369
+ return item.status !== 'voided';
3370
+ }).map(function (item) {
3371
+ return item.uuid;
3372
+ }).filter(Boolean);
3373
+ _iterator3 = _createForOfIteratorHelper(syncedPaymentUuids);
3374
+ _context36.prev = 82;
3375
+ _iterator3.s();
3376
+ case 84:
3377
+ if ((_step3 = _iterator3.n()).done) {
3378
+ _context36.next = 90;
3379
+ break;
3380
+ }
3381
+ paymentUuid = _step3.value;
3382
+ _context36.next = 88;
3383
+ return this.payment.updatePaymentAsync(this.store.currentOrder.uuid, paymentUuid, {
3384
+ isSynced: true,
3385
+ syncError: undefined
3386
+ });
3387
+ case 88:
3388
+ _context36.next = 84;
3389
+ break;
3390
+ case 90:
3391
+ _context36.next = 95;
3392
+ break;
3393
+ case 92:
3394
+ _context36.prev = 92;
3395
+ _context36.t3 = _context36["catch"](82);
3396
+ _iterator3.e(_context36.t3);
3397
+ case 95:
3398
+ _context36.prev = 95;
3399
+ _iterator3.f();
3400
+ return _context36.finish(95);
3401
+ case 98:
3402
+ _context36.next = 103;
3403
+ break;
3404
+ case 100:
3405
+ _context36.prev = 100;
3406
+ _context36.t4 = _context36["catch"](79);
3407
+ this.logWarning('标记支付项已同步失败(不阻塞主流程)', {
3408
+ error: _context36.t4
3409
+ });
3410
+ case 103:
3193
3411
  // 标记订单已同步
3194
3412
  this.store.isOrderSynced = true;
3195
3413
 
3196
3414
  // 触发订单同步完成事件
3197
- _context35.next = 82;
3415
+ _context36.next = 106;
3198
3416
  return this.core.effects.emit(CheckoutHooks.OnOrderSynced, {
3199
3417
  orderUuid: this.store.currentOrder.uuid,
3200
3418
  realOrderId: realOrderId,
@@ -3203,18 +3421,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3203
3421
  isManual: isManual,
3204
3422
  response: checkoutResponse
3205
3423
  });
3206
- case 82:
3207
- return _context35.abrupt("return", {
3424
+ case 106:
3425
+ return _context36.abrupt("return", {
3208
3426
  success: true,
3209
3427
  orderId: realOrderId,
3210
3428
  orderUuid: this.store.currentOrder.uuid,
3211
3429
  response: checkoutResponse
3212
3430
  });
3213
- case 83:
3431
+ case 107:
3214
3432
  case "end":
3215
- return _context35.stop();
3433
+ return _context36.stop();
3216
3434
  }
3217
- }, _callee35, this, [[28, 37, 45, 49], [66, 74]]);
3435
+ }, _callee36, this, [[28, 37, 45, 49], [66, 74], [79, 100], [82, 92, 95, 98]]);
3218
3436
  }));
3219
3437
  function syncOrderToBackendWithReturn() {
3220
3438
  return _syncOrderToBackendWithReturn.apply(this, arguments);
@@ -3224,15 +3442,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3224
3442
  }, {
3225
3443
  key: "setOtherParams",
3226
3444
  value: function () {
3227
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
3445
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
3228
3446
  var _ref5,
3229
3447
  _ref5$cover,
3230
3448
  cover,
3231
- _args36 = arguments;
3232
- return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3233
- while (1) switch (_context36.prev = _context36.next) {
3449
+ _args37 = arguments;
3450
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3451
+ while (1) switch (_context37.prev = _context37.next) {
3234
3452
  case 0:
3235
- _ref5 = _args36.length > 1 && _args36[1] !== undefined ? _args36[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
3453
+ _ref5 = _args37.length > 1 && _args37[1] !== undefined ? _args37[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
3236
3454
  if (cover) {
3237
3455
  this.otherParams = params;
3238
3456
  } else {
@@ -3240,11 +3458,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3240
3458
  }
3241
3459
  case 2:
3242
3460
  case "end":
3243
- return _context36.stop();
3461
+ return _context37.stop();
3244
3462
  }
3245
- }, _callee36, this);
3463
+ }, _callee37, this);
3246
3464
  }));
3247
- function setOtherParams(_x26) {
3465
+ function setOtherParams(_x27) {
3248
3466
  return _setOtherParams.apply(this, arguments);
3249
3467
  }
3250
3468
  return setOtherParams;
@@ -3261,22 +3479,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3261
3479
  }, {
3262
3480
  key: "editOrderNoteByOrderIdAsync",
3263
3481
  value: (function () {
3264
- var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(orderId, note) {
3482
+ var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(orderId, note) {
3265
3483
  var response, previousNote, errorMessage, _errorMessage;
3266
- return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3267
- while (1) switch (_context37.prev = _context37.next) {
3484
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3485
+ while (1) switch (_context38.prev = _context38.next) {
3268
3486
  case 0:
3269
3487
  this.logInfo('editOrderNoteByOrderIdAsync called', {
3270
3488
  orderId: orderId,
3271
3489
  note: note,
3272
3490
  noteLength: note.length
3273
3491
  });
3274
- _context37.prev = 1;
3492
+ _context38.prev = 1;
3275
3493
  if (orderId) {
3276
- _context37.next = 4;
3494
+ _context38.next = 4;
3277
3495
  break;
3278
3496
  }
3279
- return _context37.abrupt("return", {
3497
+ return _context38.abrupt("return", {
3280
3498
  success: false,
3281
3499
  message: '订单ID不能为空',
3282
3500
  orderId: orderId
@@ -3292,12 +3510,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3292
3510
  });
3293
3511
 
3294
3512
  // 调用后端API修改订单备注
3295
- _context37.next = 7;
3513
+ _context38.next = 7;
3296
3514
  return this.request.put("/order/order/".concat(orderId, "/note"), {
3297
3515
  note: note
3298
3516
  });
3299
3517
  case 7:
3300
- response = _context37.sent;
3518
+ response = _context38.sent;
3301
3519
  this.logInfo('订单备注编辑响应:', {
3302
3520
  orderId: orderId,
3303
3521
  status: response.status,
@@ -3307,11 +3525,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3307
3525
 
3308
3526
  // 检查响应状态
3309
3527
  if (!(response.status === true || response.status === 200)) {
3310
- _context37.next = 18;
3528
+ _context38.next = 18;
3311
3529
  break;
3312
3530
  }
3313
3531
  if (!(this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId)))) {
3314
- _context37.next = 15;
3532
+ _context38.next = 15;
3315
3533
  break;
3316
3534
  }
3317
3535
  // 获取修改前的备注用于事件
@@ -3321,7 +3539,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3321
3539
  }
3322
3540
 
3323
3541
  // 触发订单备注变更事件
3324
- _context37.next = 15;
3542
+ _context38.next = 15;
3325
3543
  return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
3326
3544
  orderUuid: this.store.currentOrder.uuid,
3327
3545
  oldNote: previousNote,
@@ -3329,7 +3547,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3329
3547
  timestamp: Date.now()
3330
3548
  });
3331
3549
  case 15:
3332
- return _context37.abrupt("return", {
3550
+ return _context38.abrupt("return", {
3333
3551
  success: true,
3334
3552
  message: response.message || '订单备注修改成功',
3335
3553
  orderId: orderId
@@ -3338,31 +3556,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3338
3556
  // API返回失败状态
3339
3557
  errorMessage = response.message || '订单备注修改失败';
3340
3558
  this.logError("\u8BA2\u5355 ".concat(orderId, " \u5907\u6CE8\u4FEE\u6539\u5931\u8D25:"), errorMessage);
3341
- return _context37.abrupt("return", {
3559
+ return _context38.abrupt("return", {
3342
3560
  success: false,
3343
3561
  message: errorMessage,
3344
3562
  orderId: orderId
3345
3563
  });
3346
3564
  case 21:
3347
- _context37.next = 28;
3565
+ _context38.next = 28;
3348
3566
  break;
3349
3567
  case 23:
3350
- _context37.prev = 23;
3351
- _context37.t0 = _context37["catch"](1);
3352
- this.logError('编辑订单备注失败:', _context37.t0);
3353
- _errorMessage = _context37.t0 instanceof Error ? _context37.t0.message : '网络错误或服务器异常';
3354
- return _context37.abrupt("return", {
3568
+ _context38.prev = 23;
3569
+ _context38.t0 = _context38["catch"](1);
3570
+ this.logError('编辑订单备注失败:', _context38.t0);
3571
+ _errorMessage = _context38.t0 instanceof Error ? _context38.t0.message : '网络错误或服务器异常';
3572
+ return _context38.abrupt("return", {
3355
3573
  success: false,
3356
3574
  message: "\u7F16\u8F91\u8BA2\u5355\u5907\u6CE8\u5931\u8D25: ".concat(_errorMessage),
3357
3575
  orderId: orderId
3358
3576
  });
3359
3577
  case 28:
3360
3578
  case "end":
3361
- return _context37.stop();
3579
+ return _context38.stop();
3362
3580
  }
3363
- }, _callee37, this, [[1, 23]]);
3581
+ }, _callee38, this, [[1, 23]]);
3364
3582
  }));
3365
- function editOrderNoteByOrderIdAsync(_x27, _x28) {
3583
+ function editOrderNoteByOrderIdAsync(_x28, _x29) {
3366
3584
  return _editOrderNoteByOrderIdAsync.apply(this, arguments);
3367
3585
  }
3368
3586
  return editOrderNoteByOrderIdAsync;
@@ -3379,11 +3597,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3379
3597
  }, {
3380
3598
  key: "sendCustomerPayLinkAsync",
3381
3599
  value: (function () {
3382
- var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
3600
+ var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
3383
3601
  var _params$order_ids, _params$emails;
3384
3602
  var emailRegex, invalidEmails, requestBody, response, errorMessage, _errorMessage2;
3385
- return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3386
- while (1) switch (_context38.prev = _context38.next) {
3603
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3604
+ while (1) switch (_context39.prev = _context39.next) {
3387
3605
  case 0:
3388
3606
  this.logInfo('sendCustomerPayLinkAsync called', {
3389
3607
  orderIds: params.order_ids,
@@ -3392,21 +3610,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3392
3610
  emailsCount: ((_params$emails = params.emails) === null || _params$emails === void 0 ? void 0 : _params$emails.length) || 0,
3393
3611
  notifyAction: params.notify_action || 'order_payment_reminder'
3394
3612
  });
3395
- _context38.prev = 1;
3613
+ _context39.prev = 1;
3396
3614
  if (!(!params.order_ids || params.order_ids.length === 0)) {
3397
- _context38.next = 4;
3615
+ _context39.next = 4;
3398
3616
  break;
3399
3617
  }
3400
- return _context38.abrupt("return", {
3618
+ return _context39.abrupt("return", {
3401
3619
  success: false,
3402
3620
  message: '订单ID列表不能为空'
3403
3621
  });
3404
3622
  case 4:
3405
3623
  if (!(!params.emails || params.emails.length === 0)) {
3406
- _context38.next = 6;
3624
+ _context39.next = 6;
3407
3625
  break;
3408
3626
  }
3409
- return _context38.abrupt("return", {
3627
+ return _context39.abrupt("return", {
3410
3628
  success: false,
3411
3629
  message: '邮箱地址列表不能为空'
3412
3630
  });
@@ -3417,10 +3635,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3417
3635
  return !emailRegex.test(email);
3418
3636
  });
3419
3637
  if (!(invalidEmails.length > 0)) {
3420
- _context38.next = 10;
3638
+ _context39.next = 10;
3421
3639
  break;
3422
3640
  }
3423
- return _context38.abrupt("return", {
3641
+ return _context39.abrupt("return", {
3424
3642
  success: false,
3425
3643
  message: "\u90AE\u7BB1\u683C\u5F0F\u65E0\u6548: ".concat(invalidEmails.join(', '))
3426
3644
  });
@@ -3436,10 +3654,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3436
3654
  }, requestBody));
3437
3655
 
3438
3656
  // 调用后端API发送邮件
3439
- _context38.next = 14;
3657
+ _context39.next = 14;
3440
3658
  return this.request.post('/order/batch-email', requestBody);
3441
3659
  case 14:
3442
- response = _context38.sent;
3660
+ response = _context39.sent;
3443
3661
  this.logInfo('支付链接邮件发送响应:', {
3444
3662
  status: response.status,
3445
3663
  message: response.message,
@@ -3449,10 +3667,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3449
3667
 
3450
3668
  // 检查响应状态
3451
3669
  if (!(response.status === true || response.status === 200)) {
3452
- _context38.next = 20;
3670
+ _context39.next = 20;
3453
3671
  break;
3454
3672
  }
3455
- return _context38.abrupt("return", {
3673
+ return _context39.abrupt("return", {
3456
3674
  success: true,
3457
3675
  message: response.message || '支付链接邮件发送成功'
3458
3676
  });
@@ -3460,29 +3678,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3460
3678
  // API返回失败状态
3461
3679
  errorMessage = response.message || '支付链接邮件发送失败';
3462
3680
  console.error('[Checkout] 支付链接邮件发送失败:', errorMessage);
3463
- return _context38.abrupt("return", {
3681
+ return _context39.abrupt("return", {
3464
3682
  success: false,
3465
3683
  message: errorMessage
3466
3684
  });
3467
3685
  case 23:
3468
- _context38.next = 30;
3686
+ _context39.next = 30;
3469
3687
  break;
3470
3688
  case 25:
3471
- _context38.prev = 25;
3472
- _context38.t0 = _context38["catch"](1);
3473
- this.logError('发送客户支付链接邮件失败:', _context38.t0);
3474
- _errorMessage2 = _context38.t0 instanceof Error ? _context38.t0.message : '网络错误或服务器异常';
3475
- return _context38.abrupt("return", {
3689
+ _context39.prev = 25;
3690
+ _context39.t0 = _context39["catch"](1);
3691
+ this.logError('发送客户支付链接邮件失败:', _context39.t0);
3692
+ _errorMessage2 = _context39.t0 instanceof Error ? _context39.t0.message : '网络错误或服务器异常';
3693
+ return _context39.abrupt("return", {
3476
3694
  success: false,
3477
3695
  message: "\u53D1\u9001\u652F\u4ED8\u94FE\u63A5\u90AE\u4EF6\u5931\u8D25: ".concat(_errorMessage2)
3478
3696
  });
3479
3697
  case 30:
3480
3698
  case "end":
3481
- return _context38.stop();
3699
+ return _context39.stop();
3482
3700
  }
3483
- }, _callee38, this, [[1, 25]]);
3701
+ }, _callee39, this, [[1, 25]]);
3484
3702
  }));
3485
- function sendCustomerPayLinkAsync(_x29) {
3703
+ function sendCustomerPayLinkAsync(_x30) {
3486
3704
  return _sendCustomerPayLinkAsync.apply(this, arguments);
3487
3705
  }
3488
3706
  return sendCustomerPayLinkAsync;
@@ -3497,24 +3715,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3497
3715
  }, {
3498
3716
  key: "roundAmountAsync",
3499
3717
  value: (function () {
3500
- var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(amount) {
3718
+ var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(amount) {
3501
3719
  var _this$otherParams$ord, _this$otherParams$ord2;
3502
3720
  var result;
3503
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3504
- while (1) switch (_context39.prev = _context39.next) {
3721
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3722
+ while (1) switch (_context40.prev = _context40.next) {
3505
3723
  case 0:
3506
- _context39.next = 2;
3724
+ _context40.next = 2;
3507
3725
  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);
3508
3726
  case 2:
3509
- result = _context39.sent;
3510
- return _context39.abrupt("return", result);
3727
+ result = _context40.sent;
3728
+ return _context40.abrupt("return", result);
3511
3729
  case 4:
3512
3730
  case "end":
3513
- return _context39.stop();
3731
+ return _context40.stop();
3514
3732
  }
3515
- }, _callee39, this);
3733
+ }, _callee40, this);
3516
3734
  }));
3517
- function roundAmountAsync(_x30) {
3735
+ function roundAmountAsync(_x31) {
3518
3736
  return _roundAmountAsync.apply(this, arguments);
3519
3737
  }
3520
3738
  return roundAmountAsync;
@@ -3522,10 +3740,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3522
3740
  }, {
3523
3741
  key: "destroy",
3524
3742
  value: function () {
3525
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40() {
3743
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
3526
3744
  var _this$order, _this$order$destroy, _this$payment, _this$payment$destroy;
3527
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3528
- while (1) switch (_context40.prev = _context40.next) {
3745
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3746
+ while (1) switch (_context41.prev = _context41.next) {
3529
3747
  case 0:
3530
3748
  // 清理钱包模块的所有缓存数据
3531
3749
  this.payment.wallet.clearAllCache();
@@ -3534,10 +3752,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3534
3752
  this.core.effects.offByModuleDestroy(this.name);
3535
3753
 
3536
3754
  // 销毁子模块
3537
- _context40.next = 4;
3755
+ _context41.next = 4;
3538
3756
  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);
3539
3757
  case 4:
3540
- _context40.next = 6;
3758
+ _context41.next = 6;
3541
3759
  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);
3542
3760
  case 6:
3543
3761
  // 取消注册模块
@@ -3545,9 +3763,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3545
3763
  console.log('[Checkout] 已销毁');
3546
3764
  case 8:
3547
3765
  case "end":
3548
- return _context40.stop();
3766
+ return _context41.stop();
3549
3767
  }
3550
- }, _callee40, this);
3768
+ }, _callee41, this);
3551
3769
  }));
3552
3770
  function destroy() {
3553
3771
  return _destroy.apply(this, arguments);
@@ -3562,12 +3780,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3562
3780
  }, {
3563
3781
  key: "resetStoreStateAsync",
3564
3782
  value: (function () {
3565
- var _resetStoreStateAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
3783
+ var _resetStoreStateAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42() {
3566
3784
  var prevOrderInfo;
3567
- return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3568
- while (1) switch (_context41.prev = _context41.next) {
3785
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3786
+ while (1) switch (_context42.prev = _context42.next) {
3569
3787
  case 0:
3570
- _context41.prev = 0;
3788
+ _context42.prev = 0;
3571
3789
  prevOrderInfo = this.store.currentOrder ? {
3572
3790
  uuid: this.store.currentOrder.uuid,
3573
3791
  orderId: this.store.currentOrder.order_id
@@ -3596,26 +3814,26 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3596
3814
 
3597
3815
  // 触发订单清理事件(如果之前有订单)
3598
3816
  if (!prevOrderInfo) {
3599
- _context41.next = 17;
3817
+ _context42.next = 17;
3600
3818
  break;
3601
3819
  }
3602
- _context41.next = 17;
3820
+ _context42.next = 17;
3603
3821
  return this.core.effects.emit(CheckoutHooks.OnOrderCleared, {
3604
3822
  previousOrder: prevOrderInfo,
3605
3823
  timestamp: Date.now()
3606
3824
  });
3607
3825
  case 17:
3608
- _context41.next = 22;
3826
+ _context42.next = 22;
3609
3827
  break;
3610
3828
  case 19:
3611
- _context41.prev = 19;
3612
- _context41.t0 = _context41["catch"](0);
3613
- console.error('[Checkout] 重置 store 状态失败:', _context41.t0);
3829
+ _context42.prev = 19;
3830
+ _context42.t0 = _context42["catch"](0);
3831
+ console.error('[Checkout] 重置 store 状态失败:', _context42.t0);
3614
3832
  case 22:
3615
3833
  case "end":
3616
- return _context41.stop();
3834
+ return _context42.stop();
3617
3835
  }
3618
- }, _callee41, this, [[0, 19]]);
3836
+ }, _callee42, this, [[0, 19]]);
3619
3837
  }));
3620
3838
  function resetStoreStateAsync() {
3621
3839
  return _resetStoreStateAsync.apply(this, arguments);