@pisell/pisellos 2.1.25 → 2.1.26

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