@pisell/pisellos 2.1.24 → 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;
844
- return this.updateStateAmountToRemaining();
1077
+ _context13.next = 15;
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,56 +1339,55 @@ 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
- _context15.next = 40;
1133
- return this.core.effects.emit(CheckoutHooks.OnPaymentItemAdded, {
1366
+ // 触发支付项添加事件(可以复用支付开始事件)
1367
+ this.core.effects.emit(CheckoutHooks.OnPaymentItemAdded, {
1134
1368
  orderUuid: this.store.currentOrder.uuid,
1135
1369
  paymentMethodCode: paymentItem.code,
1136
1370
  paymentMethodName: paymentItem.name,
1137
1371
  amount: String(paymentItem.amount),
1138
1372
  timestamp: Date.now()
1139
1373
  });
1140
- case 40:
1141
- _context15.next = 48;
1374
+ _context16.next = 47;
1142
1375
  break;
1143
- case 42:
1144
- _context15.prev = 42;
1145
- _context15.t1 = _context15["catch"](1);
1146
- this.logError('添加支付项失败:', _context15.t1);
1147
- _context15.next = 47;
1148
- return this.handleError(_context15.t1, CheckoutErrorType.PaymentFailed);
1376
+ case 41:
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);
1382
+ case 46:
1383
+ throw _context16.t1;
1149
1384
  case 47:
1150
- throw _context15.t1;
1151
- case 48:
1152
1385
  case "end":
1153
- return _context15.stop();
1386
+ return _context16.stop();
1154
1387
  }
1155
- }, _callee15, this, [[1, 42], [26, 33]]);
1388
+ }, _callee16, this, [[1, 41], [26, 33]]);
1156
1389
  }));
1157
- function addPaymentItemAsync(_x14) {
1390
+ function addPaymentItemAsync(_x15) {
1158
1391
  return _addPaymentItemAsync.apply(this, arguments);
1159
1392
  }
1160
1393
  return addPaymentItemAsync;
@@ -1172,14 +1405,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1172
1405
  }, {
1173
1406
  key: "deletePaymentItemAsync",
1174
1407
  value: (function () {
1175
- var _deletePaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(paymentUuid) {
1408
+ var _deletePaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(paymentUuid) {
1176
1409
  var currentPayments, paymentItem, currentOrderId, isCurrentOrderReal, updatedOrder;
1177
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1178
- while (1) switch (_context16.prev = _context16.next) {
1410
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1411
+ while (1) switch (_context17.prev = _context17.next) {
1179
1412
  case 0:
1180
- _context16.prev = 0;
1413
+ _context17.prev = 0;
1181
1414
  if (this.store.currentOrder) {
1182
- _context16.next = 3;
1415
+ _context17.next = 3;
1183
1416
  break;
1184
1417
  }
1185
1418
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '当前没有活跃订单,无法删除支付项');
@@ -1190,16 +1423,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1190
1423
  });
1191
1424
 
1192
1425
  // 从 Payment 模块验证支付项是否存在
1193
- _context16.next = 6;
1426
+ _context17.next = 6;
1194
1427
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, true // 包括已撤销的支付项,因为我们需要验证是否存在
1195
1428
  );
1196
1429
  case 6:
1197
- currentPayments = _context16.sent;
1430
+ currentPayments = _context17.sent;
1198
1431
  paymentItem = currentPayments.find(function (p) {
1199
1432
  return p.uuid === paymentUuid;
1200
1433
  });
1201
1434
  if (paymentItem) {
1202
- _context16.next = 10;
1435
+ _context17.next = 10;
1203
1436
  break;
1204
1437
  }
1205
1438
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u652F\u4ED8\u9879\u4E0D\u5B58\u5728: ".concat(paymentUuid));
@@ -1212,7 +1445,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1212
1445
  });
1213
1446
 
1214
1447
  // 调用 Payment 模块删除支付项
1215
- _context16.next = 13;
1448
+ _context17.next = 13;
1216
1449
  return this.payment.deletePaymentAsync(this.store.currentOrder.uuid, paymentUuid);
1217
1450
  case 13:
1218
1451
  this.logInfo('Payment支付项删除完成', paymentItem);
@@ -1220,10 +1453,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1220
1453
  // 重新从Payment模块获取最新的订单数据,确保支付项同步
1221
1454
  currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1222
1455
  isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
1223
- _context16.next = 18;
1456
+ _context17.next = 18;
1224
1457
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1225
1458
  case 18:
1226
- updatedOrder = _context16.sent;
1459
+ updatedOrder = _context17.sent;
1227
1460
  if (updatedOrder) {
1228
1461
  // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
1229
1462
  if (isCurrentOrderReal && isVirtualOrderId(updatedOrder.order_id)) {
@@ -1237,10 +1470,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1237
1470
  }
1238
1471
 
1239
1472
  // 更新 stateAmount 为剩余未支付金额
1240
- _context16.next = 22;
1241
- return this.updateStateAmountToRemaining();
1473
+ _context17.next = 22;
1474
+ return this.updateStateAmountToRemaining(false);
1242
1475
  case 22:
1243
- _context16.next = 24;
1476
+ _context17.next = 24;
1244
1477
  return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1245
1478
  orderUuid: this.store.currentOrder.uuid,
1246
1479
  paymentMethodCode: paymentItem.code,
@@ -1249,23 +1482,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1249
1482
  timestamp: Date.now()
1250
1483
  });
1251
1484
  case 24:
1252
- _context16.next = 32;
1485
+ _context17.next = 32;
1253
1486
  break;
1254
1487
  case 26:
1255
- _context16.prev = 26;
1256
- _context16.t0 = _context16["catch"](0);
1257
- this.logError('删除支付项失败:', _context16.t0);
1258
- _context16.next = 31;
1259
- 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);
1260
1493
  case 31:
1261
- throw _context16.t0;
1494
+ throw _context17.t0;
1262
1495
  case 32:
1263
1496
  case "end":
1264
- return _context16.stop();
1497
+ return _context17.stop();
1265
1498
  }
1266
- }, _callee16, this, [[0, 26]]);
1499
+ }, _callee17, this, [[0, 26]]);
1267
1500
  }));
1268
- function deletePaymentItemAsync(_x15) {
1501
+ function deletePaymentItemAsync(_x16) {
1269
1502
  return _deletePaymentItemAsync.apply(this, arguments);
1270
1503
  }
1271
1504
  return deletePaymentItemAsync;
@@ -1284,27 +1517,34 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1284
1517
  }, {
1285
1518
  key: "updateVoucherPaymentItemsAsync",
1286
1519
  value: (function () {
1287
- var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(voucherPaymentItems) {
1520
+ var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(voucherPaymentItems) {
1288
1521
  var _this3 = this;
1289
- var remainingAmount, remainingValue, isOrderSynced, orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder;
1290
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1291
- 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) {
1292
1525
  case 0:
1293
- _context17.prev = 0;
1526
+ _context18.prev = 0;
1294
1527
  if (this.store.currentOrder) {
1295
- _context17.next = 3;
1528
+ _context18.next = 3;
1296
1529
  break;
1297
1530
  }
1298
1531
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '当前没有活跃订单,无法更新代金券支付项');
1299
1532
  case 3:
1300
- _context17.next = 5;
1301
- return this.calculateRemainingAmountAsync();
1533
+ _context18.next = 5;
1534
+ return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
1302
1535
  case 5:
1303
- 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;
1304
1544
  remainingValue = new Decimal(remainingAmount);
1305
1545
  isOrderSynced = this.store.isOrderSynced;
1306
- if (!(remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0)) {
1307
- _context17.next = 11;
1546
+ if (!(remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0 && allPaymentItemsSynced)) {
1547
+ _context18.next = 15;
1308
1548
  break;
1309
1549
  }
1310
1550
  this.logInfo('订单已同步且支付完成,跳过清空代金券操作避免重复同步:', {
@@ -1315,8 +1555,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1315
1555
  voucherPaymentItemsCount: voucherPaymentItems.length,
1316
1556
  reason: 'Order synced and payment completed, skip clear vouchers to avoid duplicate sync'
1317
1557
  });
1318
- return _context17.abrupt("return");
1319
- case 11:
1558
+ return _context18.abrupt("return");
1559
+ case 15:
1320
1560
  this.logInfo('开始批量更新代金券支付项:', {
1321
1561
  voucherPaymentItems: voucherPaymentItems
1322
1562
  });
@@ -1338,16 +1578,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1338
1578
  metadata: metadata
1339
1579
  });
1340
1580
  }); // 调用 Payment 模块的批量更新方法
1341
- _context17.next = 16;
1581
+ _context18.next = 20;
1342
1582
  return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItemsWithType);
1343
- case 16:
1583
+ case 20:
1344
1584
  // 重新从Payment模块获取最新的订单数据,确保支付项同步
1345
1585
  currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1346
1586
  isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
1347
- _context17.next = 20;
1587
+ _context18.next = 24;
1348
1588
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1349
- case 20:
1350
- updatedOrder = _context17.sent;
1589
+ case 24:
1590
+ updatedOrder = _context18.sent;
1351
1591
  if (updatedOrder) {
1352
1592
  // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
1353
1593
  if (isCurrentOrderReal && isVirtualOrderId(updatedOrder.order_id)) {
@@ -1361,10 +1601,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1361
1601
  }
1362
1602
 
1363
1603
  // 更新 stateAmount 为剩余未支付金额
1364
- _context17.next = 24;
1365
- return this.updateStateAmountToRemaining();
1366
- case 24:
1367
- _context17.next = 26;
1604
+ _context18.next = 28;
1605
+ return this.updateStateAmountToRemaining(false);
1606
+ case 28:
1607
+ _context18.next = 30;
1368
1608
  return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1369
1609
  orderUuid: this.store.currentOrder.uuid,
1370
1610
  paymentMethodCode: 'VOUCHER_BATCH',
@@ -1373,25 +1613,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1373
1613
  }, 0).toFixed(2),
1374
1614
  timestamp: Date.now()
1375
1615
  });
1376
- case 26:
1616
+ case 30:
1377
1617
  this.logInfo('代金券支付项批量更新成功');
1378
- _context17.next = 35;
1618
+ _context18.next = 39;
1379
1619
  break;
1380
- case 29:
1381
- _context17.prev = 29;
1382
- _context17.t0 = _context17["catch"](0);
1383
- this.logError('[Checkout] 批量更新代金券支付项失败:', _context17.t0);
1384
- _context17.next = 34;
1385
- return this.handleError(_context17.t0, CheckoutErrorType.PaymentFailed);
1386
- case 34:
1387
- throw _context17.t0;
1388
- 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:
1389
1629
  case "end":
1390
- return _context17.stop();
1630
+ return _context18.stop();
1391
1631
  }
1392
- }, _callee17, this, [[0, 29]]);
1632
+ }, _callee18, this, [[0, 33]]);
1393
1633
  }));
1394
- function updateVoucherPaymentItemsAsync(_x16) {
1634
+ function updateVoucherPaymentItemsAsync(_x17) {
1395
1635
  return _updateVoucherPaymentItemsAsync.apply(this, arguments);
1396
1636
  }
1397
1637
  return updateVoucherPaymentItemsAsync;
@@ -1408,20 +1648,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1408
1648
  }, {
1409
1649
  key: "updateOrderDepositStatusAsync",
1410
1650
  value: (function () {
1411
- var _updateOrderDepositStatusAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(isDeposit) {
1412
- var newDepositValue, oldDepositValue, updateParams;
1413
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1414
- 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) {
1415
1655
  case 0:
1416
- _context18.prev = 0;
1656
+ _context19.prev = 0;
1417
1657
  if (!(isDeposit !== 0 && isDeposit !== 1)) {
1418
- _context18.next = 3;
1658
+ _context19.next = 3;
1419
1659
  break;
1420
1660
  }
1421
1661
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, 'isDeposit 参数只能是 0(全款订单)或 1(定金订单)');
1422
1662
  case 3:
1423
1663
  if (this.store.currentOrder) {
1424
- _context18.next = 5;
1664
+ _context19.next = 5;
1425
1665
  break;
1426
1666
  }
1427
1667
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法修改定金状态');
@@ -1429,25 +1669,33 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1429
1669
  newDepositValue = isDeposit;
1430
1670
  oldDepositValue = this.store.currentOrder.is_deposit; // 如果状态没有变化,直接返回
1431
1671
  if (!(oldDepositValue === newDepositValue)) {
1432
- _context18.next = 10;
1672
+ _context19.next = 10;
1433
1673
  break;
1434
1674
  }
1435
1675
  console.log('[Checkout] 定金状态无变化,跳过更新');
1436
- return _context18.abrupt("return");
1676
+ return _context19.abrupt("return");
1437
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
+
1438
1683
  // 准备更新参数
1439
1684
  updateParams = {
1440
- is_deposit: newDepositValue
1685
+ is_deposit: newDepositValue,
1686
+ deposit_amount: deposit_amount
1441
1687
  }; // 如果从定金改为全款,可以清空定金金额
1442
- if (isDeposit === 0 && this.store.currentOrder.deposit_amount !== '0.00') {
1443
- updateParams.deposit_amount = '0.00';
1444
- this.logInfo('订单从定金改为全款,清空定金金额');
1445
- }
1446
-
1688
+ // if (
1689
+ // isDeposit === 0 &&
1690
+ // this.store.currentOrder.deposit_amount !== '0.00'
1691
+ // ) {
1692
+ // updateParams.deposit_amount = '0.00';
1693
+ // this.logInfo('订单从定金改为全款,清空定金金额');
1694
+ // }
1447
1695
  // 调用 Payment 模块更新订单
1448
- _context18.next = 14;
1696
+ _context19.next = 15;
1449
1697
  return this.payment.updateOrderAsync(this.store.currentOrder.uuid, updateParams);
1450
- case 14:
1698
+ case 15:
1451
1699
  // 更新本地缓存的订单对象
1452
1700
  this.store.currentOrder = _objectSpread(_objectSpread({}, this.store.currentOrder), updateParams);
1453
1701
 
@@ -1455,35 +1703,36 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1455
1703
  if (this.store.localOrderData) {
1456
1704
  this.store.localOrderData.is_deposit = newDepositValue;
1457
1705
  }
1706
+ this.updateStateAmountToRemaining(false);
1458
1707
 
1459
1708
  // 触发订单更新事件
1460
- _context18.next = 18;
1709
+ _context19.next = 20;
1461
1710
  return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
1462
1711
  order: this.store.currentOrder,
1463
1712
  timestamp: Date.now()
1464
1713
  });
1465
- case 18:
1714
+ case 20:
1466
1715
  this.logInfo('订单定金状态更新成功:', {
1467
1716
  isDeposit: newDepositValue,
1468
1717
  depositAmount: this.store.currentOrder.deposit_amount
1469
1718
  });
1470
- _context18.next = 27;
1719
+ _context19.next = 29;
1471
1720
  break;
1472
- case 21:
1473
- _context18.prev = 21;
1474
- _context18.t0 = _context18["catch"](0);
1475
- this.logError('更新订单定金状态失败:', _context18.t0);
1476
- _context18.next = 26;
1477
- return this.handleError(_context18.t0, CheckoutErrorType.ValidationFailed);
1478
- case 26:
1479
- throw _context18.t0;
1480
- 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:
1481
1730
  case "end":
1482
- return _context18.stop();
1731
+ return _context19.stop();
1483
1732
  }
1484
- }, _callee18, this, [[0, 21]]);
1733
+ }, _callee19, this, [[0, 23]]);
1485
1734
  }));
1486
- function updateOrderDepositStatusAsync(_x17) {
1735
+ function updateOrderDepositStatusAsync(_x18) {
1487
1736
  return _updateOrderDepositStatusAsync.apply(this, arguments);
1488
1737
  }
1489
1738
  return updateOrderDepositStatusAsync;
@@ -1501,59 +1750,51 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1501
1750
  }, {
1502
1751
  key: "setDepositAmountAsync",
1503
1752
  value: (function () {
1504
- var _setDepositAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(depositAmount) {
1505
- var _this$store$currentOr6, _this$store$currentOr7;
1506
- var depositValue, totalAmount, formattedDepositAmount, oldDepositAmount, updateParams;
1507
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1508
- 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) {
1509
1758
  case 0:
1510
1759
  this.logInfo('setDepositAmountAsync called', {
1511
1760
  depositAmount: depositAmount,
1512
1761
  hasCurrentOrder: !!this.store.currentOrder,
1513
- currentOrderId: (_this$store$currentOr6 = this.store.currentOrder) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.order_id,
1514
- 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
1515
1764
  });
1516
- _context19.prev = 1;
1765
+ _context20.prev = 1;
1517
1766
  // 验证定金金额格式
1518
1767
  depositValue = new Decimal(depositAmount);
1519
1768
  if (!(depositValue.isNaN() || depositValue.lt(0))) {
1520
- _context19.next = 5;
1769
+ _context20.next = 5;
1521
1770
  break;
1522
1771
  }
1523
1772
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u65E0\u6548\u7684\u5B9A\u91D1\u91D1\u989D\u683C\u5F0F: ".concat(depositAmount));
1524
1773
  case 5:
1525
1774
  if (this.store.currentOrder) {
1526
- _context19.next = 7;
1775
+ _context20.next = 7;
1527
1776
  break;
1528
1777
  }
1529
1778
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法设置定金金额');
1530
1779
  case 7:
1531
- // 使用 Decimal.js 进行安全比较,检查定金金额是否超过订单总额
1532
- totalAmount = new Decimal(this.store.currentOrder.total_amount || '0');
1533
- if (!depositValue.gt(totalAmount)) {
1534
- _context19.next = 10;
1535
- break;
1536
- }
1537
- throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u5B9A\u91D1\u91D1\u989D ".concat(depositAmount, " \u4E0D\u80FD\u8D85\u8FC7\u8BA2\u5355\u603B\u989D ").concat(totalAmount.toFixed(2)));
1538
- case 10:
1539
1780
  formattedDepositAmount = depositValue.toFixed(2);
1540
1781
  oldDepositAmount = this.store.currentOrder.deposit_amount || '0.00'; // 如果定金金额没有变化,直接返回
1541
1782
  if (!(formattedDepositAmount === oldDepositAmount)) {
1542
- _context19.next = 15;
1783
+ _context20.next = 12;
1543
1784
  break;
1544
1785
  }
1545
1786
  this.logInfo('定金金额无变化,跳过更新:', {
1546
1787
  currentAmount: oldDepositAmount,
1547
1788
  newAmount: formattedDepositAmount
1548
1789
  });
1549
- return _context19.abrupt("return");
1550
- case 15:
1790
+ return _context20.abrupt("return");
1791
+ case 12:
1551
1792
  this.logInfo('开始设置订单定金金额:', {
1552
1793
  orderUuid: this.store.currentOrder.uuid,
1553
1794
  orderId: this.store.currentOrder.order_id,
1554
1795
  oldDepositAmount: oldDepositAmount,
1555
1796
  newDepositAmount: formattedDepositAmount,
1556
- totalAmount: totalAmount.toFixed(2)
1797
+ totalAmount: this.store.currentOrder.total_amount
1557
1798
  });
1558
1799
 
1559
1800
  // 准备更新参数
@@ -1571,9 +1812,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1571
1812
  }
1572
1813
 
1573
1814
  // 调用 Payment 模块更新订单
1574
- _context19.next = 20;
1815
+ _context20.next = 17;
1575
1816
  return this.payment.updateOrderAsync(this.store.currentOrder.uuid, updateParams);
1576
- case 20:
1817
+ case 17:
1577
1818
  // 更新本地缓存的订单对象
1578
1819
  this.store.currentOrder = _objectSpread(_objectSpread({}, this.store.currentOrder), updateParams);
1579
1820
 
@@ -1588,14 +1829,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1588
1829
  this.store.localOrderData.is_deposit = updateParams.is_deposit;
1589
1830
  }
1590
1831
  }
1832
+ this.updateStateAmountToRemaining(false);
1591
1833
 
1592
1834
  // 触发订单更新事件
1593
- _context19.next = 24;
1835
+ _context20.next = 22;
1594
1836
  return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
1595
1837
  order: this.store.currentOrder,
1596
1838
  timestamp: Date.now()
1597
1839
  });
1598
- case 24:
1840
+ case 22:
1599
1841
  this.logInfo('订单定金金额设置成功:', {
1600
1842
  orderUuid: this.store.currentOrder.uuid,
1601
1843
  orderId: this.store.currentOrder.order_id,
@@ -1604,23 +1846,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1604
1846
  isDeposit: this.store.currentOrder.is_deposit,
1605
1847
  totalAmount: this.store.currentOrder.total_amount
1606
1848
  });
1607
- _context19.next = 33;
1849
+ _context20.next = 31;
1608
1850
  break;
1609
- case 27:
1610
- _context19.prev = 27;
1611
- _context19.t0 = _context19["catch"](1);
1612
- this.logError('设置订单定金金额失败:', _context19.t0);
1613
- _context19.next = 32;
1614
- return this.handleError(_context19.t0, CheckoutErrorType.ValidationFailed);
1615
- case 32:
1616
- throw _context19.t0;
1617
- 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:
1618
1860
  case "end":
1619
- return _context19.stop();
1861
+ return _context20.stop();
1620
1862
  }
1621
- }, _callee19, this, [[1, 27]]);
1863
+ }, _callee20, this, [[1, 25]]);
1622
1864
  }));
1623
- function setDepositAmountAsync(_x18) {
1865
+ function setDepositAmountAsync(_x19) {
1624
1866
  return _setDepositAmountAsync.apply(this, arguments);
1625
1867
  }
1626
1868
  return setDepositAmountAsync;
@@ -1634,26 +1876,26 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1634
1876
  }, {
1635
1877
  key: "manualSyncOrderAsync",
1636
1878
  value: (function () {
1637
- var _manualSyncOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1638
- var _this$store$currentOr8, _this$store$currentOr9, _this$store$currentOr10;
1639
- var orderUuid, oldOrderId, syncResult, finalOrderId, finalIsVirtual, _this$store$currentOr11, errorMessage;
1640
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1641
- 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) {
1642
1884
  case 0:
1643
1885
  this.logInfo('manualSyncOrderAsync called', {
1644
1886
  hasCurrentOrder: !!this.store.currentOrder,
1645
- currentOrderId: (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.order_id,
1646
- orderUuid: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.uuid,
1647
- 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,
1648
1890
  isOrderSynced: this.store.isOrderSynced,
1649
1891
  isVirtualOrderId: this.store.currentOrder ? isVirtualOrderId(this.store.currentOrder.order_id) : false
1650
1892
  });
1651
- _context20.prev = 1;
1893
+ _context21.prev = 1;
1652
1894
  if (this.store.currentOrder) {
1653
- _context20.next = 4;
1895
+ _context21.next = 4;
1654
1896
  break;
1655
1897
  }
1656
- return _context20.abrupt("return", {
1898
+ return _context21.abrupt("return", {
1657
1899
  success: false,
1658
1900
  message: '当前没有活跃订单,无法同步'
1659
1901
  });
@@ -1663,25 +1905,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1663
1905
  if (this.store.isOrderSynced) {
1664
1906
  this.logInfo('订单已同步过,将执行更新操作');
1665
1907
  }
1666
- _context20.t0 = this;
1667
- _context20.t1 = orderUuid;
1668
- _context20.t2 = oldOrderId;
1669
- _context20.t3 = this.store.currentOrder.total_amount;
1670
- _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;
1671
1913
  return this.calculateRemainingAmountAsync();
1672
1914
  case 13:
1673
- _context20.t4 = _context20.sent;
1674
- _context20.t5 = {
1675
- orderUuid: _context20.t1,
1676
- orderId: _context20.t2,
1677
- totalAmount: _context20.t3,
1678
- 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
1679
1921
  };
1680
- _context20.t0.logInfo.call(_context20.t0, '开始手动同步订单到后端:', _context20.t5);
1681
- _context20.next = 18;
1922
+ _context21.t0.logInfo.call(_context21.t0, '开始手动同步订单到后端:', _context21.t5);
1923
+ _context21.next = 18;
1682
1924
  return this.syncOrderToBackendWithReturn(true);
1683
1925
  case 18:
1684
- syncResult = _context20.sent;
1926
+ syncResult = _context21.sent;
1685
1927
  this.logInfo('手动同步订单完成:', {
1686
1928
  orderUuid: orderUuid,
1687
1929
  syncResult: syncResult,
@@ -1699,22 +1941,28 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1699
1941
  if (syncResult.orderId !== finalOrderId) {
1700
1942
  this.logError('[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!');
1701
1943
  }
1702
- 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);
1703
1949
  case 27:
1704
- _context20.prev = 27;
1705
- _context20.t6 = _context20["catch"](1);
1706
- this.logError('手动同步订单失败:', _context20.t6);
1707
- errorMessage = _context20.t6 instanceof Error ? _context20.t6.message : '同步失败';
1708
- 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", {
1709
1957
  success: false,
1710
1958
  message: "\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(errorMessage),
1711
- 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
1712
1960
  });
1713
- case 32:
1961
+ case 35:
1714
1962
  case "end":
1715
- return _context20.stop();
1963
+ return _context21.stop();
1716
1964
  }
1717
- }, _callee20, this, [[1, 27]]);
1965
+ }, _callee21, this, [[1, 30]]);
1718
1966
  }));
1719
1967
  function manualSyncOrderAsync() {
1720
1968
  return _manualSyncOrderAsync.apply(this, arguments);
@@ -1784,27 +2032,27 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1784
2032
  }, {
1785
2033
  key: "cancelCurrentOrderAsync",
1786
2034
  value: (function () {
1787
- var _cancelCurrentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(cancelReason) {
1788
- var _this$store$currentOr12, _this$store$currentOr13, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
1789
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1790
- 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) {
1791
2039
  case 0:
1792
- _context21.prev = 0;
2040
+ _context22.prev = 0;
1793
2041
  this.logInfo('开始取消当前本地订单:', {
1794
2042
  hasCurrentOrder: !!this.store.currentOrder,
1795
- orderUuid: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.uuid,
1796
- 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,
1797
2045
  isOrderSynced: this.store.isOrderSynced,
1798
2046
  cancelReason: cancelReason
1799
2047
  });
1800
2048
 
1801
2049
  // 检查是否有当前订单
1802
2050
  if (this.store.currentOrder) {
1803
- _context21.next = 5;
2051
+ _context22.next = 5;
1804
2052
  break;
1805
2053
  }
1806
2054
  this.logInfo('没有当前订单,无需取消');
1807
- return _context21.abrupt("return", {
2055
+ return _context22.abrupt("return", {
1808
2056
  success: false,
1809
2057
  message: '没有当前订单可取消'
1810
2058
  });
@@ -1813,31 +2061,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1813
2061
  currentOrderId = this.store.currentOrder.order_id;
1814
2062
  isOrderSynced = this.store.isOrderSynced; // 检查订单是否已同步,已同步的订单不能取消
1815
2063
  if (!isOrderSynced) {
1816
- _context21.next = 11;
2064
+ _context22.next = 11;
1817
2065
  break;
1818
2066
  }
1819
2067
  this.logInfo('订单已同步到后端,不能取消:', {
1820
2068
  orderId: currentOrderId,
1821
2069
  orderUuid: currentOrderUuid
1822
2070
  });
1823
- return _context21.abrupt("return", {
2071
+ return _context22.abrupt("return", {
1824
2072
  success: false,
1825
2073
  message: '订单已同步到后端,无法取消',
1826
2074
  orderId: currentOrderId
1827
2075
  });
1828
2076
  case 11:
1829
- _context21.prev = 11;
2077
+ _context22.prev = 11;
1830
2078
  this.logInfo('删除本地订单数据');
1831
- _context21.next = 15;
2079
+ _context22.next = 15;
1832
2080
  return this.payment.deletePaymentOrderAsync(currentOrderUuid);
1833
2081
  case 15:
1834
2082
  this.logInfo('本地订单数据删除成功');
1835
- _context21.next = 21;
2083
+ _context22.next = 21;
1836
2084
  break;
1837
2085
  case 18:
1838
- _context21.prev = 18;
1839
- _context21.t0 = _context21["catch"](11);
1840
- this.logWarning('删除本地订单数据失败,但继续执行:', _context21.t0);
2086
+ _context22.prev = 18;
2087
+ _context22.t0 = _context22["catch"](11);
2088
+ this.logWarning('删除本地订单数据失败,但继续执行:', _context22.t0);
1841
2089
  case 21:
1842
2090
  // 清理订单相关状态,确保正确释放 currentOrder
1843
2091
  this.logInfo('清理订单相关状态');
@@ -1853,7 +2101,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1853
2101
  this.logInfo('订单状态清理完成,currentOrder已释放');
1854
2102
 
1855
2103
  // 触发订单取消事件
1856
- _context21.next = 32;
2104
+ _context22.next = 32;
1857
2105
  return this.core.effects.emit(CheckoutHooks.OnOrderCancelled, {
1858
2106
  orderUuid: currentOrderUuid,
1859
2107
  orderId: currentOrderId,
@@ -1868,27 +2116,27 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1868
2116
  orderId: currentOrderId,
1869
2117
  cancelReason: cancelReason
1870
2118
  });
1871
- return _context21.abrupt("return", {
2119
+ return _context22.abrupt("return", {
1872
2120
  success: true,
1873
2121
  message: '本地订单已成功取消',
1874
2122
  orderId: currentOrderId
1875
2123
  });
1876
2124
  case 36:
1877
- _context21.prev = 36;
1878
- _context21.t1 = _context21["catch"](0);
1879
- this.logError('取消本地订单失败:', _context21.t1);
1880
- errorMessage = _context21.t1 instanceof Error ? _context21.t1.message : '未知错误';
1881
- 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", {
1882
2130
  success: false,
1883
2131
  message: "\u53D6\u6D88\u8BA2\u5355\u5931\u8D25: ".concat(errorMessage)
1884
2132
  });
1885
2133
  case 41:
1886
2134
  case "end":
1887
- return _context21.stop();
2135
+ return _context22.stop();
1888
2136
  }
1889
- }, _callee21, this, [[0, 36], [11, 18]]);
2137
+ }, _callee22, this, [[0, 36], [11, 18]]);
1890
2138
  }));
1891
- function cancelCurrentOrderAsync(_x19) {
2139
+ function cancelCurrentOrderAsync(_x20) {
1892
2140
  return _cancelCurrentOrderAsync.apply(this, arguments);
1893
2141
  }
1894
2142
  return cancelCurrentOrderAsync;
@@ -1903,17 +2151,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1903
2151
  }, {
1904
2152
  key: "saveForLaterPaymentAsync",
1905
2153
  value: (function () {
1906
- var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1907
- var orderUuid, currentOrderId, allPaymentItems, syncResult, _this$store$currentOr14, errorMessage;
1908
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1909
- 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) {
1910
2158
  case 0:
1911
- _context22.prev = 0;
2159
+ _context23.prev = 0;
1912
2160
  if (this.store.currentOrder) {
1913
- _context22.next = 3;
2161
+ _context23.next = 3;
1914
2162
  break;
1915
2163
  }
1916
- return _context22.abrupt("return", {
2164
+ return _context23.abrupt("return", {
1917
2165
  success: false,
1918
2166
  message: '当前没有活跃订单,无法保存'
1919
2167
  });
@@ -1927,14 +2175,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1927
2175
  });
1928
2176
 
1929
2177
  // 获取当前订单的所有支付项
1930
- _context22.next = 8;
2178
+ _context23.next = 8;
1931
2179
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
1932
2180
  case 8:
1933
- allPaymentItems = _context22.sent;
1934
- _context22.next = 11;
2181
+ allPaymentItems = _context23.sent;
2182
+ _context23.next = 11;
1935
2183
  return this.syncOrderToBackendWithReturn(true, allPaymentItems);
1936
2184
  case 11:
1937
- syncResult = _context22.sent;
2185
+ syncResult = _context23.sent;
1938
2186
  this.logInfo('保存订单完成:', {
1939
2187
  orderUuid: orderUuid,
1940
2188
  oldOrderId: currentOrderId,
@@ -1943,7 +2191,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1943
2191
  isOrderSynced: this.store.isOrderSynced,
1944
2192
  filteredPaymentsCount: allPaymentItems.length
1945
2193
  });
1946
- return _context22.abrupt("return", {
2194
+ return _context23.abrupt("return", {
1947
2195
  success: true,
1948
2196
  message: '订单保存成功,可稍后继续支付',
1949
2197
  orderId: syncResult.orderId,
@@ -1951,20 +2199,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1951
2199
  response: syncResult.response
1952
2200
  });
1953
2201
  case 16:
1954
- _context22.prev = 16;
1955
- _context22.t0 = _context22["catch"](0);
1956
- this.logError('保存订单失败:', _context22.t0);
1957
- errorMessage = _context22.t0 instanceof Error ? _context22.t0.message : '保存失败';
1958
- 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", {
1959
2207
  success: false,
1960
2208
  message: "\u8BA2\u5355\u4FDD\u5B58\u5931\u8D25: ".concat(errorMessage),
1961
- 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
1962
2210
  });
1963
2211
  case 21:
1964
2212
  case "end":
1965
- return _context22.stop();
2213
+ return _context23.stop();
1966
2214
  }
1967
- }, _callee22, this, [[0, 16]]);
2215
+ }, _callee23, this, [[0, 16]]);
1968
2216
  }));
1969
2217
  function saveForLaterPaymentAsync() {
1970
2218
  return _saveForLaterPaymentAsync.apply(this, arguments);
@@ -1980,20 +2228,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1980
2228
  }, {
1981
2229
  key: "updateOrderNoteAsync",
1982
2230
  value: (function () {
1983
- var _updateOrderNoteAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(note) {
1984
- var _this$store$currentOr15, _this$store$currentOr16, oldNote, orderInPayment;
1985
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1986
- 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) {
1987
2235
  case 0:
1988
- _context23.prev = 0;
2236
+ _context24.prev = 0;
1989
2237
  if (this.store.localOrderData) {
1990
- _context23.next = 3;
2238
+ _context24.next = 3;
1991
2239
  break;
1992
2240
  }
1993
2241
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '没有本地订单数据,无法更新备注');
1994
2242
  case 3:
1995
2243
  console.log('[Checkout] 更新订单备注:', {
1996
- 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,
1997
2245
  oldNote: this.store.localOrderData.shop_note,
1998
2246
  newNote: note
1999
2247
  });
@@ -2004,29 +2252,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2004
2252
 
2005
2253
  // 如果有当前订单,也同步到Payment模块中的订单数据
2006
2254
  if (!this.store.currentOrder) {
2007
- _context23.next = 17;
2255
+ _context24.next = 17;
2008
2256
  break;
2009
2257
  }
2010
- _context23.prev = 7;
2011
- _context23.next = 10;
2258
+ _context24.prev = 7;
2259
+ _context24.next = 10;
2012
2260
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
2013
2261
  case 10:
2014
- orderInPayment = _context23.sent;
2262
+ orderInPayment = _context24.sent;
2015
2263
  if (orderInPayment && orderInPayment.note !== undefined) {
2016
2264
  // 使用Payment模块的更新方法(如果有的话)
2017
2265
  // 这里可能需要根据Payment模块的实际API来调整
2018
2266
  console.log('[Checkout] 同步备注到Payment模块的订单数据中');
2019
2267
  }
2020
- _context23.next = 17;
2268
+ _context24.next = 17;
2021
2269
  break;
2022
2270
  case 14:
2023
- _context23.prev = 14;
2024
- _context23.t0 = _context23["catch"](7);
2025
- console.warn('[Checkout] 同步备注到Payment模块失败,但本地更新成功:', _context23.t0);
2271
+ _context24.prev = 14;
2272
+ _context24.t0 = _context24["catch"](7);
2273
+ console.warn('[Checkout] 同步备注到Payment模块失败,但本地更新成功:', _context24.t0);
2026
2274
  case 17:
2027
- _context23.next = 19;
2275
+ _context24.next = 19;
2028
2276
  return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
2029
- 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,
2030
2278
  oldNote: oldNote,
2031
2279
  newNote: note,
2032
2280
  timestamp: Date.now()
@@ -2036,23 +2284,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2036
2284
  oldNote: oldNote,
2037
2285
  newNote: note
2038
2286
  });
2039
- _context23.next = 28;
2287
+ _context24.next = 28;
2040
2288
  break;
2041
2289
  case 22:
2042
- _context23.prev = 22;
2043
- _context23.t1 = _context23["catch"](0);
2044
- console.error('[Checkout] 更新订单备注失败:', _context23.t1);
2045
- _context23.next = 27;
2046
- 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);
2047
2295
  case 27:
2048
- throw _context23.t1;
2296
+ throw _context24.t1;
2049
2297
  case 28:
2050
2298
  case "end":
2051
- return _context23.stop();
2299
+ return _context24.stop();
2052
2300
  }
2053
- }, _callee23, this, [[0, 22], [7, 14]]);
2301
+ }, _callee24, this, [[0, 22], [7, 14]]);
2054
2302
  }));
2055
- function updateOrderNoteAsync(_x20) {
2303
+ function updateOrderNoteAsync(_x21) {
2056
2304
  return _updateOrderNoteAsync.apply(this, arguments);
2057
2305
  }
2058
2306
  return updateOrderNoteAsync;
@@ -2064,14 +2312,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2064
2312
  }, {
2065
2313
  key: "handleError",
2066
2314
  value: (function () {
2067
- var _handleError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(error, type) {
2315
+ var _handleError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(error, type) {
2068
2316
  var checkoutError;
2069
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2070
- while (1) switch (_context24.prev = _context24.next) {
2317
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2318
+ while (1) switch (_context25.prev = _context25.next) {
2071
2319
  case 0:
2072
2320
  checkoutError = error instanceof Error && 'type' in error ? error : createCheckoutError(type, error.message, error);
2073
2321
  this.store.lastError = checkoutError;
2074
- _context24.next = 4;
2322
+ _context25.next = 4;
2075
2323
  return this.core.effects.emit(CheckoutHooks.OnError, {
2076
2324
  error: checkoutError,
2077
2325
  context: {},
@@ -2081,11 +2329,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2081
2329
  console.error('[Checkout] 错误:', checkoutError);
2082
2330
  case 5:
2083
2331
  case "end":
2084
- return _context24.stop();
2332
+ return _context25.stop();
2085
2333
  }
2086
- }, _callee24, this);
2334
+ }, _callee25, this);
2087
2335
  }));
2088
- function handleError(_x21, _x22) {
2336
+ function handleError(_x22, _x23) {
2089
2337
  return _handleError.apply(this, arguments);
2090
2338
  }
2091
2339
  return handleError;
@@ -2097,31 +2345,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2097
2345
  }, {
2098
2346
  key: "handlePaymentSuccess",
2099
2347
  value: (function () {
2100
- var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(data) {
2101
- var _this$store$currentOr17;
2102
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2103
- 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) {
2104
2352
  case 0:
2105
- _context25.next = 2;
2353
+ _context26.next = 2;
2106
2354
  return this.updateStateAmountToRemaining();
2107
2355
  case 2:
2108
- _context25.next = 4;
2356
+ _context26.next = 4;
2109
2357
  return this.core.effects.emit(CheckoutHooks.OnPaymentSuccess, {
2110
2358
  orderUuid: data.orderUuid,
2111
2359
  paymentMethodCode: '',
2112
- 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',
2113
2361
  timestamp: data.timestamp
2114
2362
  });
2115
2363
  case 4:
2116
- _context25.next = 6;
2364
+ _context26.next = 6;
2117
2365
  return this.completeCheckoutAsync();
2118
2366
  case 6:
2119
2367
  case "end":
2120
- return _context25.stop();
2368
+ return _context26.stop();
2121
2369
  }
2122
- }, _callee25, this);
2370
+ }, _callee26, this);
2123
2371
  }));
2124
- function handlePaymentSuccess(_x23) {
2372
+ function handlePaymentSuccess(_x24) {
2125
2373
  return _handlePaymentSuccess.apply(this, arguments);
2126
2374
  }
2127
2375
  return handlePaymentSuccess;
@@ -2133,30 +2381,30 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2133
2381
  }, {
2134
2382
  key: "handlePaymentError",
2135
2383
  value: (function () {
2136
- var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(data) {
2137
- var _this$store$currentOr18;
2384
+ var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(data) {
2385
+ var _this$store$currentOr22;
2138
2386
  var error;
2139
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2140
- while (1) switch (_context26.prev = _context26.next) {
2387
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2388
+ while (1) switch (_context27.prev = _context27.next) {
2141
2389
  case 0:
2142
2390
  error = createCheckoutError(CheckoutErrorType.PaymentFailed, data.error || '支付同步失败');
2143
- _context26.next = 3;
2391
+ _context27.next = 3;
2144
2392
  return this.handleError(error instanceof Error ? error : new Error(String(error)), CheckoutErrorType.PaymentFailed);
2145
2393
  case 3:
2146
- _context26.next = 5;
2394
+ _context27.next = 5;
2147
2395
  return this.core.effects.emit(CheckoutHooks.OnPaymentFailed, {
2148
2396
  orderUuid: data.orderUuid,
2149
2397
  paymentMethodCode: '',
2150
- 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',
2151
2399
  timestamp: data.timestamp
2152
2400
  });
2153
2401
  case 5:
2154
2402
  case "end":
2155
- return _context26.stop();
2403
+ return _context27.stop();
2156
2404
  }
2157
- }, _callee26, this);
2405
+ }, _callee27, this);
2158
2406
  }));
2159
- function handlePaymentError(_x24) {
2407
+ function handlePaymentError(_x25) {
2160
2408
  return _handlePaymentError.apply(this, arguments);
2161
2409
  }
2162
2410
  return handlePaymentError;
@@ -2180,43 +2428,43 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2180
2428
  }, {
2181
2429
  key: "processCashPaymentItem",
2182
2430
  value: (function () {
2183
- var _processCashPaymentItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(paymentItem) {
2431
+ var _processCashPaymentItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(paymentItem) {
2184
2432
  var cashPayment, remainingAmountStr, remainingAmount, cashAmount, changeAmount, processedPaymentItem;
2185
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2186
- while (1) switch (_context27.prev = _context27.next) {
2433
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2434
+ while (1) switch (_context28.prev = _context28.next) {
2187
2435
  case 0:
2188
2436
  // 检查是否是现金支付
2189
2437
  cashPayment = isCashPayment(paymentItem.code, paymentItem.type);
2190
2438
  if (cashPayment) {
2191
- _context27.next = 3;
2439
+ _context28.next = 3;
2192
2440
  break;
2193
2441
  }
2194
- return _context27.abrupt("return", paymentItem);
2442
+ return _context28.abrupt("return", paymentItem);
2195
2443
  case 3:
2196
- _context27.prev = 3;
2197
- _context27.next = 6;
2444
+ _context28.prev = 3;
2445
+ _context28.next = 6;
2198
2446
  return this.calculateRemainingAmountAsync();
2199
2447
  case 6:
2200
- remainingAmountStr = _context27.sent;
2448
+ remainingAmountStr = _context28.sent;
2201
2449
  remainingAmount = new Decimal(remainingAmountStr);
2202
2450
  cashAmount = new Decimal(String(paymentItem.amount)); // 如果现金金额小于等于剩余待付金额,无需找零
2203
2451
  if (!cashAmount.lte(remainingAmount)) {
2204
- _context27.next = 11;
2452
+ _context28.next = 11;
2205
2453
  break;
2206
2454
  }
2207
- return _context27.abrupt("return", paymentItem);
2455
+ return _context28.abrupt("return", paymentItem);
2208
2456
  case 11:
2209
2457
  // 使用 Decimal.js 安全计算找零金额
2210
2458
  changeAmount = cashAmount.sub(remainingAmount); // 如果还有 rounding_amount 的配置,要判断是否和 changeAmount 相等
2211
2459
  if (!(Number(paymentItem.rounding_amount) > 0)) {
2212
- _context27.next = 18;
2460
+ _context28.next = 18;
2213
2461
  break;
2214
2462
  }
2215
2463
  if (!(Number(paymentItem.rounding_amount) === changeAmount.toNumber())) {
2216
- _context27.next = 17;
2464
+ _context28.next = 17;
2217
2465
  break;
2218
2466
  }
2219
- return _context27.abrupt("return", paymentItem);
2467
+ return _context28.abrupt("return", paymentItem);
2220
2468
  case 17:
2221
2469
  // 如果不等于,则remainingAmount需要加上 rounding_amount,避免这里被改为未舍入金额
2222
2470
  remainingAmount = remainingAmount.add(new Decimal(paymentItem.rounding_amount || '0'));
@@ -2244,20 +2492,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2244
2492
  changeAmountPrecise: changeAmount.toString()
2245
2493
  }
2246
2494
  });
2247
- return _context27.abrupt("return", processedPaymentItem);
2495
+ return _context28.abrupt("return", processedPaymentItem);
2248
2496
  case 23:
2249
- _context27.prev = 23;
2250
- _context27.t0 = _context27["catch"](3);
2251
- this.logError('处理现金支付项时出错:', _context27.t0);
2497
+ _context28.prev = 23;
2498
+ _context28.t0 = _context28["catch"](3);
2499
+ this.logError('处理现金支付项时出错:', _context28.t0);
2252
2500
  // 出错时返回原始支付项,避免中断支付流程
2253
- return _context27.abrupt("return", paymentItem);
2501
+ return _context28.abrupt("return", paymentItem);
2254
2502
  case 27:
2255
2503
  case "end":
2256
- return _context27.stop();
2504
+ return _context28.stop();
2257
2505
  }
2258
- }, _callee27, this, [[3, 23]]);
2506
+ }, _callee28, this, [[3, 23]]);
2259
2507
  }));
2260
- function processCashPaymentItem(_x25) {
2508
+ function processCashPaymentItem(_x26) {
2261
2509
  return _processCashPaymentItem.apply(this, arguments);
2262
2510
  }
2263
2511
  return processCashPaymentItem;
@@ -2269,31 +2517,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2269
2517
  }, {
2270
2518
  key: "preloadPaymentMethods",
2271
2519
  value: (function () {
2272
- var _preloadPaymentMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2520
+ var _preloadPaymentMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2273
2521
  var methods;
2274
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2275
- while (1) switch (_context28.prev = _context28.next) {
2522
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2523
+ while (1) switch (_context29.prev = _context29.next) {
2276
2524
  case 0:
2277
- _context28.prev = 0;
2525
+ _context29.prev = 0;
2278
2526
  console.log('[Checkout] 预加载支付方式...');
2279
- _context28.next = 4;
2527
+ _context29.next = 4;
2280
2528
  return this.payment.getPayMethodListAsync();
2281
2529
  case 4:
2282
- methods = _context28.sent;
2530
+ methods = _context29.sent;
2283
2531
  this.store.paymentMethods = methods;
2284
2532
  console.log("[Checkout] \u9884\u52A0\u8F7D\u5B8C\u6210\uFF0C\u5171 ".concat(methods.length, " \u79CD\u652F\u4ED8\u65B9\u5F0F"));
2285
- _context28.next = 13;
2533
+ _context29.next = 13;
2286
2534
  break;
2287
2535
  case 9:
2288
- _context28.prev = 9;
2289
- _context28.t0 = _context28["catch"](0);
2290
- console.error('[Checkout] 预加载支付方式失败:', _context28.t0);
2536
+ _context29.prev = 9;
2537
+ _context29.t0 = _context29["catch"](0);
2538
+ console.error('[Checkout] 预加载支付方式失败:', _context29.t0);
2291
2539
  this.store.paymentMethods = [];
2292
2540
  case 13:
2293
2541
  case "end":
2294
- return _context28.stop();
2542
+ return _context29.stop();
2295
2543
  }
2296
- }, _callee28, this, [[0, 9]]);
2544
+ }, _callee29, this, [[0, 9]]);
2297
2545
  }));
2298
2546
  function preloadPaymentMethods() {
2299
2547
  return _preloadPaymentMethods.apply(this, arguments);
@@ -2309,59 +2557,59 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2309
2557
  }, {
2310
2558
  key: "cleanupExpiredOrdersAsync",
2311
2559
  value: (function () {
2312
- var _cleanupExpiredOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2560
+ var _cleanupExpiredOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2313
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;
2314
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2315
- while (1) switch (_context29.prev = _context29.next) {
2562
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2563
+ while (1) switch (_context30.prev = _context30.next) {
2316
2564
  case 0:
2317
- _context29.prev = 0;
2565
+ _context30.prev = 0;
2318
2566
  // 检查是否启用了清理功能
2319
2567
  cleanupConfig = this.otherParams.orderDataCleanup || {};
2320
2568
  isCleanupEnabled = cleanupConfig.enabled !== false; // 默认启用
2321
2569
  retentionDays = cleanupConfig.retentionDays || 7; // 默认保留7天
2322
2570
  maxOrdersToDelete = cleanupConfig.maxOrdersToDelete || 100; // 默认最多删除100个订单
2323
2571
  if (isCleanupEnabled) {
2324
- _context29.next = 8;
2572
+ _context30.next = 8;
2325
2573
  break;
2326
2574
  }
2327
2575
  console.log('[Checkout] 订单数据清理功能已禁用');
2328
- return _context29.abrupt("return");
2576
+ return _context30.abrupt("return");
2329
2577
  case 8:
2330
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..."));
2331
2579
 
2332
2580
  // 获取所有订单
2333
- _context29.next = 11;
2581
+ _context30.next = 11;
2334
2582
  return this.payment.getOrderListAsync();
2335
2583
  case 11:
2336
- allOrders = _context29.sent;
2584
+ allOrders = _context30.sent;
2337
2585
  if (!(!allOrders || allOrders.length === 0)) {
2338
- _context29.next = 15;
2586
+ _context30.next = 15;
2339
2587
  break;
2340
2588
  }
2341
2589
  console.log('[Checkout] 没有找到需要清理的订单数据');
2342
- return _context29.abrupt("return");
2590
+ return _context30.abrupt("return");
2343
2591
  case 15:
2344
2592
  thresholdDate = new Date();
2345
2593
  thresholdDate.setDate(thresholdDate.getDate() - retentionDays);
2346
2594
  deletedCount = 0;
2347
2595
  ordersToDelete = [];
2348
2596
  _iterator = _createForOfIteratorHelper(allOrders);
2349
- _context29.prev = 20;
2597
+ _context30.prev = 20;
2350
2598
  _iterator.s();
2351
2599
  case 22:
2352
2600
  if ((_step = _iterator.n()).done) {
2353
- _context29.next = 41;
2601
+ _context30.next = 41;
2354
2602
  break;
2355
2603
  }
2356
2604
  order = _step.value;
2357
- _context29.prev = 24;
2605
+ _context30.prev = 24;
2358
2606
  // 检查订单是否已同步(订单ID不是虚拟ID)
2359
2607
  isSynced = order.order_id && !isVirtualOrderId(order.order_id);
2360
2608
  if (isSynced) {
2361
- _context29.next = 28;
2609
+ _context30.next = 28;
2362
2610
  break;
2363
2611
  }
2364
- return _context29.abrupt("continue", 39);
2612
+ return _context30.abrupt("continue", 39);
2365
2613
  case 28:
2366
2614
  // 检查创建时间
2367
2615
  orderCreatedAt = null; // 尝试从 order_info.created_at 获取创建时间
@@ -2375,10 +2623,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2375
2623
 
2376
2624
  // 如果无法获取创建时间,跳过此订单
2377
2625
  if (!(!orderCreatedAt || isNaN(orderCreatedAt.getTime()))) {
2378
- _context29.next = 32;
2626
+ _context30.next = 32;
2379
2627
  break;
2380
2628
  }
2381
- return _context29.abrupt("continue", 39);
2629
+ return _context30.abrupt("continue", 39);
2382
2630
  case 32:
2383
2631
  // 检查是否超过指定天数
2384
2632
  if (orderCreatedAt < thresholdDate) {
@@ -2389,27 +2637,27 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2389
2637
  daysSinceCreated: Math.floor((Date.now() - orderCreatedAt.getTime()) / (1000 * 60 * 60 * 24))
2390
2638
  });
2391
2639
  }
2392
- _context29.next = 39;
2640
+ _context30.next = 39;
2393
2641
  break;
2394
2642
  case 35:
2395
- _context29.prev = 35;
2396
- _context29.t0 = _context29["catch"](24);
2397
- console.warn("[Checkout] \u5904\u7406\u8BA2\u5355 ".concat(order.uuid, " \u65F6\u51FA\u9519:"), _context29.t0);
2398
- 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);
2399
2647
  case 39:
2400
- _context29.next = 22;
2648
+ _context30.next = 22;
2401
2649
  break;
2402
2650
  case 41:
2403
- _context29.next = 46;
2651
+ _context30.next = 46;
2404
2652
  break;
2405
2653
  case 43:
2406
- _context29.prev = 43;
2407
- _context29.t1 = _context29["catch"](20);
2408
- _iterator.e(_context29.t1);
2654
+ _context30.prev = 43;
2655
+ _context30.t1 = _context30["catch"](20);
2656
+ _iterator.e(_context30.t1);
2409
2657
  case 46:
2410
- _context29.prev = 46;
2658
+ _context30.prev = 46;
2411
2659
  _iterator.f();
2412
- return _context29.finish(46);
2660
+ return _context30.finish(46);
2413
2661
  case 49:
2414
2662
  // 按创建时间排序(最老的先删除)并限制删除数量
2415
2663
  ordersToDelete.sort(function (a, b) {
@@ -2417,40 +2665,40 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2417
2665
  });
2418
2666
  actualOrdersToDelete = ordersToDelete.slice(0, maxOrdersToDelete); // 删除符合条件的订单
2419
2667
  _iterator2 = _createForOfIteratorHelper(actualOrdersToDelete);
2420
- _context29.prev = 52;
2668
+ _context30.prev = 52;
2421
2669
  _iterator2.s();
2422
2670
  case 54:
2423
2671
  if ((_step2 = _iterator2.n()).done) {
2424
- _context29.next = 68;
2672
+ _context30.next = 68;
2425
2673
  break;
2426
2674
  }
2427
2675
  orderInfo = _step2.value;
2428
- _context29.prev = 56;
2429
- _context29.next = 59;
2676
+ _context30.prev = 56;
2677
+ _context30.next = 59;
2430
2678
  return this.payment.deletePaymentOrderAsync(orderInfo.uuid);
2431
2679
  case 59:
2432
2680
  deletedCount++;
2433
2681
  console.log("[Checkout] \u5DF2\u5220\u9664\u8FC7\u671F\u8BA2\u5355: ".concat(orderInfo.orderId, " (").concat(orderInfo.daysSinceCreated, " \u5929\u524D\u521B\u5EFA)"));
2434
- _context29.next = 66;
2682
+ _context30.next = 66;
2435
2683
  break;
2436
2684
  case 63:
2437
- _context29.prev = 63;
2438
- _context29.t2 = _context29["catch"](56);
2439
- 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);
2440
2688
  case 66:
2441
- _context29.next = 54;
2689
+ _context30.next = 54;
2442
2690
  break;
2443
2691
  case 68:
2444
- _context29.next = 73;
2692
+ _context30.next = 73;
2445
2693
  break;
2446
2694
  case 70:
2447
- _context29.prev = 70;
2448
- _context29.t3 = _context29["catch"](52);
2449
- _iterator2.e(_context29.t3);
2695
+ _context30.prev = 70;
2696
+ _context30.t3 = _context30["catch"](52);
2697
+ _iterator2.e(_context30.t3);
2450
2698
  case 73:
2451
- _context29.prev = 73;
2699
+ _context30.prev = 73;
2452
2700
  _iterator2.f();
2453
- return _context29.finish(73);
2701
+ return _context30.finish(73);
2454
2702
  case 76:
2455
2703
  summary = {
2456
2704
  totalOrders: allOrders.length,
@@ -2468,21 +2716,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2468
2716
  } else {
2469
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"));
2470
2718
  }
2471
- _context29.next = 86;
2719
+ _context30.next = 86;
2472
2720
  break;
2473
2721
  case 81:
2474
- _context29.prev = 81;
2475
- _context29.t4 = _context29["catch"](0);
2476
- errorMessage = _context29.t4 instanceof Error ? _context29.t4.message : String(_context29.t4);
2477
- 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);
2478
2726
  this.logError('Expired orders cleanup failed', {
2479
2727
  error: errorMessage
2480
2728
  });
2481
2729
  case 86:
2482
2730
  case "end":
2483
- return _context29.stop();
2731
+ return _context30.stop();
2484
2732
  }
2485
- }, _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]]);
2486
2734
  }));
2487
2735
  function cleanupExpiredOrdersAsync() {
2488
2736
  return _cleanupExpiredOrdersAsync.apply(this, arguments);
@@ -2496,24 +2744,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2496
2744
  }, {
2497
2745
  key: "calculatePaidAmountAsync",
2498
2746
  value: (function () {
2499
- var _calculatePaidAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2747
+ var _calculatePaidAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2500
2748
  var payments, paidAmount, result;
2501
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2502
- while (1) switch (_context30.prev = _context30.next) {
2749
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2750
+ while (1) switch (_context31.prev = _context31.next) {
2503
2751
  case 0:
2504
2752
  if (this.store.currentOrder) {
2505
- _context30.next = 3;
2753
+ _context31.next = 3;
2506
2754
  break;
2507
2755
  }
2508
2756
  this.logWarning('[Checkout] calculatePaidAmountAsync: 没有当前订单');
2509
- return _context30.abrupt("return", '0.00');
2757
+ return _context31.abrupt("return", '0.00');
2510
2758
  case 3:
2511
- _context30.prev = 3;
2512
- _context30.next = 6;
2759
+ _context31.prev = 3;
2760
+ _context31.next = 6;
2513
2761
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
2514
2762
  );
2515
2763
  case 6:
2516
- payments = _context30.sent;
2764
+ payments = _context31.sent;
2517
2765
  // 使用 Decimal.js 进行安全的金额计算
2518
2766
  paidAmount = payments.filter(function (payment) {
2519
2767
  return payment.status !== 'voided';
@@ -2542,17 +2790,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2542
2790
  }, new Decimal(0));
2543
2791
  result = paidAmount.toFixed(2);
2544
2792
  this.logInfo('calculatePaidAmountAsync: 计算结果 =', result);
2545
- return _context30.abrupt("return", result);
2793
+ return _context31.abrupt("return", result);
2546
2794
  case 13:
2547
- _context30.prev = 13;
2548
- _context30.t0 = _context30["catch"](3);
2549
- this.logError('calculatePaidAmountAsync 失败:', _context30.t0);
2550
- 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');
2551
2799
  case 17:
2552
2800
  case "end":
2553
- return _context30.stop();
2801
+ return _context31.stop();
2554
2802
  }
2555
- }, _callee30, this, [[3, 13]]);
2803
+ }, _callee31, this, [[3, 13]]);
2556
2804
  }));
2557
2805
  function calculatePaidAmountAsync() {
2558
2806
  return _calculatePaidAmountAsync.apply(this, arguments);
@@ -2566,34 +2814,41 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2566
2814
  }, {
2567
2815
  key: "calculateRemainingAmountAsync",
2568
2816
  value: (function () {
2569
- var _calculateRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2570
- var totalAmount, paidAmountStr, paidAmount, remainingAmount, result;
2571
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2572
- 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) {
2573
2821
  case 0:
2574
2822
  if (this.store.currentOrder) {
2575
- _context31.next = 3;
2823
+ _context32.next = 3;
2576
2824
  break;
2577
2825
  }
2578
2826
  this.logWarning('calculateRemainingAmountAsync: 没有当前订单');
2579
- return _context31.abrupt("return", '0.00');
2827
+ return _context32.abrupt("return", '0.00');
2580
2828
  case 3:
2581
2829
  // 使用 Decimal.js 进行安全的金额计算
2582
2830
  totalAmount = new Decimal(this.store.currentOrder.total_amount || '0');
2583
- _context31.next = 6;
2584
- return this.calculatePaidAmountAsync();
2831
+ _context32.next = 6;
2832
+ return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
2585
2833
  case 6:
2586
- 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;
2587
2842
  paidAmount = new Decimal(paidAmountStr);
2588
2843
  remainingAmount = totalAmount.sub(paidAmount); // 确保剩余金额不为负数
2589
2844
  result = Decimal.max(0, remainingAmount).toFixed(2);
2590
2845
  this.logInfo('calculateRemainingAmountAsync: 计算=', result);
2591
- return _context31.abrupt("return", result);
2592
- case 12:
2846
+ return _context32.abrupt("return", result);
2847
+ case 16:
2593
2848
  case "end":
2594
- return _context31.stop();
2849
+ return _context32.stop();
2595
2850
  }
2596
- }, _callee31, this);
2851
+ }, _callee32, this);
2597
2852
  }));
2598
2853
  function calculateRemainingAmountAsync() {
2599
2854
  return _calculateRemainingAmountAsync.apply(this, arguments);
@@ -2607,25 +2862,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2607
2862
  }, {
2608
2863
  key: "updateBalanceDueAmount",
2609
2864
  value: (function () {
2610
- var _updateBalanceDueAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2865
+ var _updateBalanceDueAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2611
2866
  var remainingAmount, currentBalanceDueAmount;
2612
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2613
- while (1) switch (_context32.prev = _context32.next) {
2867
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2868
+ while (1) switch (_context33.prev = _context33.next) {
2614
2869
  case 0:
2615
- _context32.prev = 0;
2616
- _context32.next = 3;
2870
+ _context33.prev = 0;
2871
+ _context33.next = 3;
2617
2872
  return this.calculateRemainingAmountAsync();
2618
2873
  case 3:
2619
- remainingAmount = _context32.sent;
2874
+ remainingAmount = _context33.sent;
2620
2875
  currentBalanceDueAmount = this.store.balanceDueAmount; // 只有当剩余金额与当前 balanceDueAmount 不同时才更新
2621
2876
  if (!(remainingAmount !== currentBalanceDueAmount)) {
2622
- _context32.next = 12;
2877
+ _context33.next = 12;
2623
2878
  break;
2624
2879
  }
2625
2880
  this.store.balanceDueAmount = remainingAmount;
2626
2881
 
2627
2882
  // 发出 balanceDueAmount 变更事件
2628
- _context32.next = 9;
2883
+ _context33.next = 9;
2629
2884
  return this.core.effects.emit(CheckoutHooks.OnBalanceDueAmountChanged, {
2630
2885
  oldAmount: currentBalanceDueAmount,
2631
2886
  newAmount: remainingAmount,
@@ -2636,7 +2891,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2636
2891
  oldAmount: currentBalanceDueAmount,
2637
2892
  newAmount: remainingAmount
2638
2893
  });
2639
- _context32.next = 13;
2894
+ _context33.next = 13;
2640
2895
  break;
2641
2896
  case 12:
2642
2897
  this.logInfo('balanceDueAmount 无需更新,当前值已是最新:', {
@@ -2644,17 +2899,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2644
2899
  remainingAmount: remainingAmount
2645
2900
  });
2646
2901
  case 13:
2647
- _context32.next = 18;
2902
+ _context33.next = 18;
2648
2903
  break;
2649
2904
  case 15:
2650
- _context32.prev = 15;
2651
- _context32.t0 = _context32["catch"](0);
2652
- this.logError('更新 balanceDueAmount 失败:', _context32.t0);
2905
+ _context33.prev = 15;
2906
+ _context33.t0 = _context33["catch"](0);
2907
+ this.logError('更新 balanceDueAmount 失败:', _context33.t0);
2653
2908
  case 18:
2654
2909
  case "end":
2655
- return _context32.stop();
2910
+ return _context33.stop();
2656
2911
  }
2657
- }, _callee32, this, [[0, 15]]);
2912
+ }, _callee33, this, [[0, 15]]);
2658
2913
  }));
2659
2914
  function updateBalanceDueAmount() {
2660
2915
  return _updateBalanceDueAmount.apply(this, arguments);
@@ -2668,16 +2923,57 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2668
2923
  }, {
2669
2924
  key: "updateStateAmountToRemaining",
2670
2925
  value: (function () {
2671
- var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2672
- var remainingAmount, currentStateAmount;
2673
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2674
- while (1) switch (_context33.prev = _context33.next) {
2926
+ var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
2927
+ var checkOrder,
2928
+ _this$store$currentOr23,
2929
+ _this$store$currentOr24,
2930
+ _this$store$currentOr25,
2931
+ paymentItems,
2932
+ depositPaidAmount,
2933
+ _this$store$currentOr26,
2934
+ remainingAmount,
2935
+ currentStateAmount,
2936
+ _args34 = arguments;
2937
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2938
+ while (1) switch (_context34.prev = _context34.next) {
2675
2939
  case 0:
2676
- _context33.prev = 0;
2677
- _context33.next = 3;
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;
2678
2974
  return this.calculateRemainingAmountAsync();
2679
- case 3:
2680
- remainingAmount = _context33.sent;
2975
+ case 13:
2976
+ remainingAmount = _context34.sent;
2681
2977
  currentStateAmount = this.store.stateAmount; // 只有当剩余金额与当前 stateAmount 不同时才更新
2682
2978
  if (remainingAmount !== currentStateAmount) {
2683
2979
  this.store.stateAmount = remainingAmount;
@@ -2698,25 +2994,33 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2698
2994
  remainingAmount: remainingAmount
2699
2995
  });
2700
2996
  }
2701
-
2702
2997
  // 同步更新系统内部的 balanceDueAmount
2703
- _context33.next = 8;
2998
+ _context34.next = 18;
2704
2999
  return this.updateBalanceDueAmount();
2705
- case 8:
2706
- _context33.next = 10;
3000
+ case 18:
3001
+ if (!checkOrder) {
3002
+ _context34.next = 23;
3003
+ break;
3004
+ }
3005
+ _context34.next = 21;
2707
3006
  return this.checkOrderPaymentCompletion();
2708
- case 10:
2709
- _context33.next = 15;
3007
+ case 21:
3008
+ _context34.next = 24;
2710
3009
  break;
2711
- case 12:
2712
- _context33.prev = 12;
2713
- _context33.t0 = _context33["catch"](0);
2714
- this.logError('更新 stateAmount 为剩余金额失败:', _context33.t0);
2715
- case 15:
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:
2716
3020
  case "end":
2717
- return _context33.stop();
3021
+ return _context34.stop();
2718
3022
  }
2719
- }, _callee33, this, [[0, 12]]);
3023
+ }, _callee34, this, [[1, 26]]);
2720
3024
  }));
2721
3025
  function updateStateAmountToRemaining() {
2722
3026
  return _updateStateAmountToRemaining.apply(this, arguments);
@@ -2732,32 +3036,32 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2732
3036
  }, {
2733
3037
  key: "checkOrderPaymentCompletion",
2734
3038
  value: (function () {
2735
- var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
3039
+ var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
2736
3040
  var remainingAmount, remainingValue, totalAmount, paidAmount, currentPayments, hasPaymentItems, allPaymentsHaveVoucherId, shouldAutoSync;
2737
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2738
- while (1) switch (_context34.prev = _context34.next) {
3041
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3042
+ while (1) switch (_context35.prev = _context35.next) {
2739
3043
  case 0:
2740
- _context34.prev = 0;
3044
+ _context35.prev = 0;
2741
3045
  if (this.store.currentOrder) {
2742
- _context34.next = 3;
3046
+ _context35.next = 3;
2743
3047
  break;
2744
3048
  }
2745
- return _context34.abrupt("return");
3049
+ return _context35.abrupt("return");
2746
3050
  case 3:
2747
- _context34.next = 5;
3051
+ _context35.next = 5;
2748
3052
  return this.calculateRemainingAmountAsync();
2749
3053
  case 5:
2750
- remainingAmount = _context34.sent;
3054
+ remainingAmount = _context35.sent;
2751
3055
  remainingValue = new Decimal(remainingAmount); // 当剩余金额小于等于0时,认为订单已完成支付
2752
3056
  if (!remainingValue.lte(0)) {
2753
- _context34.next = 29;
3057
+ _context35.next = 29;
2754
3058
  break;
2755
3059
  }
2756
3060
  totalAmount = this.store.currentOrder.total_amount;
2757
- _context34.next = 11;
3061
+ _context35.next = 11;
2758
3062
  return this.calculatePaidAmountAsync();
2759
3063
  case 11:
2760
- paidAmount = _context34.sent;
3064
+ paidAmount = _context35.sent;
2761
3065
  this.logInfo('检测到订单支付完成:', {
2762
3066
  orderUuid: this.store.currentOrder.uuid,
2763
3067
  orderId: this.store.currentOrder.order_id,
@@ -2768,11 +3072,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2768
3072
  });
2769
3073
 
2770
3074
  // 从 Payment 模块获取最新支付项,检查自动同步条件
2771
- _context34.next = 15;
3075
+ _context35.next = 15;
2772
3076
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
2773
3077
  );
2774
3078
  case 15:
2775
- currentPayments = _context34.sent;
3079
+ currentPayments = _context35.sent;
2776
3080
  // 检查自动同步条件:
2777
3081
  // 1. 待付金额为 0 ✓ (已在上面检查)
2778
3082
  // 2. 需要有支付项
@@ -2806,14 +3110,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2806
3110
  })
2807
3111
  });
2808
3112
  if (!shouldAutoSync) {
2809
- _context34.next = 26;
3113
+ _context35.next = 26;
2810
3114
  break;
2811
3115
  }
2812
3116
  this.logInfo('满足自动同步条件,开始同步订单到后端...');
2813
- _context34.next = 24;
3117
+ _context35.next = 24;
2814
3118
  return this.syncOrderToBackendWithReturn(false);
2815
3119
  case 24:
2816
- _context34.next = 27;
3120
+ _context35.next = 27;
2817
3121
  break;
2818
3122
  case 26:
2819
3123
  if (!hasPaymentItems) {
@@ -2822,7 +3126,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2822
3126
  this.logInfo('所有支付项均为代金券类型,跳过订单同步');
2823
3127
  }
2824
3128
  case 27:
2825
- _context34.next = 29;
3129
+ _context35.next = 29;
2826
3130
  return this.core.effects.emit(CheckoutHooks.OnOrderPaymentCompleted, {
2827
3131
  orderUuid: this.store.currentOrder.uuid,
2828
3132
  orderId: this.store.currentOrder.order_id,
@@ -2832,17 +3136,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2832
3136
  timestamp: Date.now()
2833
3137
  });
2834
3138
  case 29:
2835
- _context34.next = 34;
3139
+ _context35.next = 34;
2836
3140
  break;
2837
3141
  case 31:
2838
- _context34.prev = 31;
2839
- _context34.t0 = _context34["catch"](0);
2840
- this.logError('检查订单支付完成状态失败:', _context34.t0);
3142
+ _context35.prev = 31;
3143
+ _context35.t0 = _context35["catch"](0);
3144
+ this.logError('检查订单支付完成状态失败:', _context35.t0);
2841
3145
  case 34:
2842
3146
  case "end":
2843
- return _context34.stop();
3147
+ return _context35.stop();
2844
3148
  }
2845
- }, _callee34, this, [[0, 31]]);
3149
+ }, _callee35, this, [[0, 31]]);
2846
3150
  }));
2847
3151
  function checkOrderPaymentCompletion() {
2848
3152
  return _checkOrderPaymentCompletion.apply(this, arguments);
@@ -2860,12 +3164,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2860
3164
  }, {
2861
3165
  key: "syncOrderToBackendWithReturn",
2862
3166
  value: (function () {
2863
- var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
3167
+ var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
2864
3168
  var _this4 = this,
2865
- _this$store$currentOr19,
2866
- _this$store$currentOr20,
3169
+ _this$store$currentOr27,
3170
+ _this$store$currentOr28,
2867
3171
  _this$store$currentCu2,
2868
- _this$store$currentOr21,
3172
+ _this$store$currentOr29,
3173
+ _this$store$localOrde,
3174
+ _this$store$localOrde2,
2869
3175
  _checkoutResponse3,
2870
3176
  _checkoutResponse4;
2871
3177
  var isManual,
@@ -2876,10 +3182,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2876
3182
  processedPaymentItems,
2877
3183
  finalDepositAmount,
2878
3184
  manualDepositAmount,
2879
- depositPaymentItems,
2880
- calculatedDepositAmount,
2881
3185
  manualDepositValue,
2882
- calculatedDepositValue,
2883
3186
  orderParams,
2884
3187
  startTime,
2885
3188
  checkoutResponse,
@@ -2897,14 +3200,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2897
3200
  _checkoutResponse7,
2898
3201
  updatedOrder,
2899
3202
  beforeManualUpdate,
2900
- _args35 = arguments;
2901
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2902
- 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) {
2903
3210
  case 0:
2904
- isManual = _args35.length > 0 && _args35[0] !== undefined ? _args35[0] : false;
2905
- 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;
2906
3213
  if (!(!this.store.localOrderData || !this.store.currentOrder)) {
2907
- _context35.next = 4;
3214
+ _context36.next = 4;
2908
3215
  break;
2909
3216
  }
2910
3217
  throw new Error('缺少必要的订单数据,无法同步到后端');
@@ -2923,17 +3230,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2923
3230
  });
2924
3231
 
2925
3232
  // 获取当前订单的支付项
2926
- _context35.t0 = customPaymentItems;
2927
- if (_context35.t0) {
2928
- _context35.next = 13;
3233
+ _context36.t0 = customPaymentItems;
3234
+ if (_context36.t0) {
3235
+ _context36.next = 13;
2929
3236
  break;
2930
3237
  }
2931
- _context35.next = 12;
3238
+ _context36.next = 12;
2932
3239
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
2933
3240
  case 12:
2934
- _context35.t0 = _context35.sent;
3241
+ _context36.t0 = _context36.sent;
2935
3242
  case 13:
2936
- paymentItems = _context35.t0;
3243
+ paymentItems = _context36.t0;
2937
3244
  // 处理支付项数据,确保包含完整的 metadata
2938
3245
  processedPaymentItems = paymentItems.map(function (item) {
2939
3246
  var _item$metadata, _item$metadata2;
@@ -2944,47 +3251,26 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2944
3251
  })
2945
3252
  });
2946
3253
  }); // 确定最终的定金金额:优先使用手动设置的值,否则从支付项中计算
2947
- 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")
2948
- depositPaymentItems = processedPaymentItems.filter(function (item) {
2949
- return item.order_payment_type === 'deposit' && item.status !== 'voided';
2950
- });
2951
- calculatedDepositAmount = depositPaymentItems.reduce(function (sum, item) {
2952
- var amount = new Decimal(item.amount || '0');
2953
- var roundingAmount = new Decimal(item.rounding_amount || '0');
2954
- // 包含抹零计算的有效支付金额
2955
- var effectiveAmount = amount.add(roundingAmount.abs());
2956
- return sum.add(effectiveAmount);
2957
- }, 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'; // 优先级逻辑:手动设置的定金金额 > 从支付项计算的金额
2958
3255
  manualDepositValue = new Decimal(manualDepositAmount);
2959
- calculatedDepositValue = new Decimal(calculatedDepositAmount);
2960
3256
  if (manualDepositValue.gt(0)) {
2961
3257
  // 如果手动设置了定金金额且大于0,使用手动设置的值
2962
3258
  finalDepositAmount = manualDepositAmount;
2963
3259
  this.logInfo('使用手动设置的定金金额', {
2964
3260
  manualDepositAmount: manualDepositAmount,
2965
- calculatedDepositAmount: calculatedDepositAmount,
2966
3261
  reason: '用户通过setDepositAmountAsync手动设置了定金金额'
2967
3262
  });
2968
- } else if (calculatedDepositValue.gt(0)) {
2969
- // 如果没有手动设置但有定金类型的支付项,使用计算值
2970
- finalDepositAmount = calculatedDepositAmount;
2971
- this.logInfo('使用从支付项计算的定金金额', {
2972
- manualDepositAmount: manualDepositAmount,
2973
- calculatedDepositAmount: calculatedDepositAmount,
2974
- reason: '未手动设置定金金额,从定金类型支付项计算得出'
2975
- });
2976
3263
  } else {
2977
3264
  // 都为0,使用0
2978
3265
  finalDepositAmount = '0.00';
2979
3266
  this.logInfo('定金金额为0', {
2980
3267
  manualDepositAmount: manualDepositAmount,
2981
- calculatedDepositAmount: calculatedDepositAmount,
2982
3268
  reason: '手动设置和计算值均为0'
2983
3269
  });
2984
3270
  }
2985
3271
  this.logInfo('定金金额确定结果', {
2986
- depositPaymentItemsCount: depositPaymentItems.length,
2987
- depositPaymentItems: depositPaymentItems.map(function (item) {
3272
+ depositPaymentItemsCount: processedPaymentItems.length,
3273
+ depositPaymentItems: processedPaymentItems.map(function (item) {
2988
3274
  return {
2989
3275
  uuid: item.uuid,
2990
3276
  code: item.code,
@@ -2995,9 +3281,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2995
3281
  };
2996
3282
  }),
2997
3283
  manualDepositAmount: manualDepositAmount,
2998
- calculatedDepositAmount: calculatedDepositAmount,
2999
3284
  finalDepositAmount: finalDepositAmount,
3000
- 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
3001
3286
  });
3002
3287
 
3003
3288
  // 构造订单参数,直接使用 localOrderData 中已处理好的数据
@@ -3019,11 +3304,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3019
3304
  currency_code: this.otherParams.currency_code,
3020
3305
  currency_symbol: this.otherParams.currency_symbol,
3021
3306
  currency_format: this.otherParams.currency_format,
3022
- 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,
3023
3308
  deposit_amount: finalDepositAmount,
3024
3309
  // 使用最终确定的定金金额(手动设置优先)
3025
3310
  product_tax_fee: this.store.localOrderData.tax_fee,
3026
- 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
+ })
3027
3326
  }); // 如果是更新操作,需要在参数中包含真实的订单ID
3028
3327
  if (isUpdateOperation) {
3029
3328
  // 如果当前订单ID是虚拟ID,但订单已同步过,可能存在数据不一致的问题
@@ -3036,7 +3335,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3036
3335
 
3037
3336
  // 发送下单接口请求开始事件
3038
3337
  startTime = Date.now();
3039
- _context35.next = 27;
3338
+ _context36.next = 24;
3040
3339
  return this.core.effects.emit(CheckoutHooks.OnOrderSubmitStart, {
3041
3340
  orderUuid: this.store.currentOrder.uuid,
3042
3341
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3044,9 +3343,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3044
3343
  paymentItemCount: paymentItems.length,
3045
3344
  timestamp: startTime
3046
3345
  });
3047
- case 27:
3346
+ case 24:
3048
3347
  submitSuccess = false;
3049
- _context35.prev = 28;
3348
+ _context36.prev = 25;
3050
3349
  // 记录接口调用参数
3051
3350
  this.logInfo('Calling backend checkout API', _objectSpread({
3052
3351
  url: '/order/checkout',
@@ -3054,23 +3353,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3054
3353
  }, orderParams));
3055
3354
 
3056
3355
  // 调用 Order 模块的专用 createOrderByCheckout 方法
3057
- _context35.next = 32;
3356
+ _context36.next = 29;
3058
3357
  return this.order.createOrderByCheckout(orderParams);
3059
- case 32:
3060
- checkoutResponse = _context35.sent;
3358
+ case 29:
3359
+ checkoutResponse = _context36.sent;
3061
3360
  submitSuccess = true;
3062
3361
  this.logInfo('下单接口调用成功', checkoutResponse);
3063
- _context35.next = 45;
3362
+ _context36.next = 42;
3064
3363
  break;
3065
- case 37:
3066
- _context35.prev = 37;
3067
- _context35.t1 = _context35["catch"](28);
3364
+ case 34:
3365
+ _context36.prev = 34;
3366
+ _context36.t1 = _context36["catch"](25);
3068
3367
  submitSuccess = false;
3069
- submitError = _context35.t1 instanceof Error ? _context35.t1.message : String(_context35.t1);
3368
+ submitError = _context36.t1 instanceof Error ? _context36.t1.message : String(_context36.t1);
3070
3369
  this.logError('下单接口调用失败:', submitError);
3071
3370
 
3072
3371
  // 发送订单同步失败事件(网络错误或请求失败)
3073
- _context35.next = 44;
3372
+ _context36.next = 41;
3074
3373
  return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
3075
3374
  orderUuid: this.store.currentOrder.uuid,
3076
3375
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3080,11 +3379,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3080
3379
  duration: Date.now() - startTime,
3081
3380
  timestamp: Date.now()
3082
3381
  });
3083
- case 44:
3084
- throw _context35.t1;
3085
- case 45:
3086
- _context35.prev = 45;
3087
- _context35.next = 48;
3382
+ case 41:
3383
+ throw _context36.t1;
3384
+ case 42:
3385
+ _context36.prev = 42;
3386
+ _context36.next = 45;
3088
3387
  return this.core.effects.emit(CheckoutHooks.OnOrderSubmitEnd, {
3089
3388
  success: submitSuccess,
3090
3389
  orderUuid: this.store.currentOrder.uuid,
@@ -3095,18 +3394,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3095
3394
  duration: Date.now() - startTime,
3096
3395
  timestamp: Date.now()
3097
3396
  });
3098
- case 48:
3099
- return _context35.finish(45);
3100
- case 49:
3397
+ case 45:
3398
+ return _context36.finish(42);
3399
+ case 46:
3101
3400
  // 检查响应状态是否为成功状态
3102
3401
  responseStatus = (_checkoutResponse3 = checkoutResponse) === null || _checkoutResponse3 === void 0 ? void 0 : _checkoutResponse3.status;
3103
3402
  isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse4 = checkoutResponse) === null || _checkoutResponse4 === void 0 ? void 0 : _checkoutResponse4.code) === 200;
3104
3403
  if (isSuccessResponse) {
3105
- _context35.next = 56;
3404
+ _context36.next = 53;
3106
3405
  break;
3107
3406
  }
3108
3407
  errorMessage = ((_checkoutResponse5 = checkoutResponse) === null || _checkoutResponse5 === void 0 ? void 0 : _checkoutResponse5.message) || '订单同步失败,后端返回非成功状态'; // 发送订单同步失败事件
3109
- _context35.next = 55;
3408
+ _context36.next = 52;
3110
3409
  return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
3111
3410
  orderUuid: this.store.currentOrder.uuid,
3112
3411
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3117,18 +3416,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3117
3416
  duration: Date.now() - startTime,
3118
3417
  timestamp: Date.now()
3119
3418
  });
3120
- case 55:
3419
+ case 52:
3121
3420
  throw new Error(errorMessage);
3122
- case 56:
3421
+ case 53:
3123
3422
  if (!isUpdateOperation) {
3124
- _context35.next = 60;
3423
+ _context36.next = 57;
3125
3424
  break;
3126
3425
  }
3127
3426
  // 更新操作:使用现有的订单ID
3128
3427
  realOrderId = currentOrderId;
3129
- _context35.next = 79;
3428
+ _context36.next = 76;
3130
3429
  break;
3131
- case 60:
3430
+ case 57:
3132
3431
  // 创建操作:从响应中提取新的订单ID
3133
3432
  extractedOrderId = (_checkoutResponse6 = checkoutResponse) === null || _checkoutResponse6 === void 0 || (_checkoutResponse6 = _checkoutResponse6.data) === null || _checkoutResponse6 === void 0 ? void 0 : _checkoutResponse6.order_id; // 如果data.order_id不存在,尝试直接从根级获取
3134
3433
  if (!extractedOrderId) {
@@ -3150,11 +3449,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3150
3449
  oldOrderId: this.store.currentOrder.order_id,
3151
3450
  newOrderId: realOrderId
3152
3451
  });
3153
- _context35.prev = 66;
3154
- _context35.next = 69;
3452
+ _context36.prev = 63;
3453
+ _context36.next = 66;
3155
3454
  return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, realOrderId);
3156
- case 69:
3157
- updatedOrder = _context35.sent;
3455
+ case 66:
3456
+ updatedOrder = _context36.sent;
3158
3457
  this.logInfo('Payment模块替换订单ID结果:', {
3159
3458
  wasSuccessful: !!updatedOrder,
3160
3459
  returnedOrderId: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.order_id,
@@ -3180,22 +3479,66 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3180
3479
  目标ID: realOrderId
3181
3480
  });
3182
3481
  }
3183
- _context35.next = 79;
3482
+ _context36.next = 76;
3184
3483
  break;
3185
- case 74:
3186
- _context35.prev = 74;
3187
- _context35.t2 = _context35["catch"](66);
3188
- 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);
3189
3488
 
3190
3489
  // 发生错误时也进行手动替换
3191
3490
  this.store.currentOrder.order_id = realOrderId;
3192
3491
  this.logInfo('错误恢复:手动设置订单ID:', realOrderId);
3193
- 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:
3194
3537
  // 标记订单已同步
3195
3538
  this.store.isOrderSynced = true;
3196
3539
 
3197
3540
  // 触发订单同步完成事件
3198
- _context35.next = 82;
3541
+ _context36.next = 103;
3199
3542
  return this.core.effects.emit(CheckoutHooks.OnOrderSynced, {
3200
3543
  orderUuid: this.store.currentOrder.uuid,
3201
3544
  realOrderId: realOrderId,
@@ -3204,18 +3547,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3204
3547
  isManual: isManual,
3205
3548
  response: checkoutResponse
3206
3549
  });
3207
- case 82:
3208
- return _context35.abrupt("return", {
3550
+ case 103:
3551
+ return _context36.abrupt("return", {
3209
3552
  success: true,
3210
3553
  orderId: realOrderId,
3211
3554
  orderUuid: this.store.currentOrder.uuid,
3212
3555
  response: checkoutResponse
3213
3556
  });
3214
- case 83:
3557
+ case 104:
3215
3558
  case "end":
3216
- return _context35.stop();
3559
+ return _context36.stop();
3217
3560
  }
3218
- }, _callee35, this, [[28, 37, 45, 49], [66, 74]]);
3561
+ }, _callee36, this, [[25, 34, 42, 46], [63, 71], [76, 97], [79, 89, 92, 95]]);
3219
3562
  }));
3220
3563
  function syncOrderToBackendWithReturn() {
3221
3564
  return _syncOrderToBackendWithReturn.apply(this, arguments);
@@ -3225,15 +3568,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3225
3568
  }, {
3226
3569
  key: "setOtherParams",
3227
3570
  value: function () {
3228
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
3571
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
3229
3572
  var _ref5,
3230
3573
  _ref5$cover,
3231
3574
  cover,
3232
- _args36 = arguments;
3233
- return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3234
- 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) {
3235
3578
  case 0:
3236
- _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;
3237
3580
  if (cover) {
3238
3581
  this.otherParams = params;
3239
3582
  } else {
@@ -3241,11 +3584,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3241
3584
  }
3242
3585
  case 2:
3243
3586
  case "end":
3244
- return _context36.stop();
3587
+ return _context37.stop();
3245
3588
  }
3246
- }, _callee36, this);
3589
+ }, _callee37, this);
3247
3590
  }));
3248
- function setOtherParams(_x26) {
3591
+ function setOtherParams(_x27) {
3249
3592
  return _setOtherParams.apply(this, arguments);
3250
3593
  }
3251
3594
  return setOtherParams;
@@ -3262,22 +3605,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3262
3605
  }, {
3263
3606
  key: "editOrderNoteByOrderIdAsync",
3264
3607
  value: (function () {
3265
- var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(orderId, note) {
3608
+ var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(orderId, note) {
3266
3609
  var response, previousNote, errorMessage, _errorMessage;
3267
- return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3268
- while (1) switch (_context37.prev = _context37.next) {
3610
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3611
+ while (1) switch (_context38.prev = _context38.next) {
3269
3612
  case 0:
3270
3613
  this.logInfo('editOrderNoteByOrderIdAsync called', {
3271
3614
  orderId: orderId,
3272
3615
  note: note,
3273
3616
  noteLength: note.length
3274
3617
  });
3275
- _context37.prev = 1;
3618
+ _context38.prev = 1;
3276
3619
  if (orderId) {
3277
- _context37.next = 4;
3620
+ _context38.next = 4;
3278
3621
  break;
3279
3622
  }
3280
- return _context37.abrupt("return", {
3623
+ return _context38.abrupt("return", {
3281
3624
  success: false,
3282
3625
  message: '订单ID不能为空',
3283
3626
  orderId: orderId
@@ -3293,12 +3636,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3293
3636
  });
3294
3637
 
3295
3638
  // 调用后端API修改订单备注
3296
- _context37.next = 7;
3639
+ _context38.next = 7;
3297
3640
  return this.request.put("/order/order/".concat(orderId, "/note"), {
3298
3641
  note: note
3299
3642
  });
3300
3643
  case 7:
3301
- response = _context37.sent;
3644
+ response = _context38.sent;
3302
3645
  this.logInfo('订单备注编辑响应:', {
3303
3646
  orderId: orderId,
3304
3647
  status: response.status,
@@ -3308,11 +3651,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3308
3651
 
3309
3652
  // 检查响应状态
3310
3653
  if (!(response.status === true || response.status === 200)) {
3311
- _context37.next = 18;
3654
+ _context38.next = 18;
3312
3655
  break;
3313
3656
  }
3314
3657
  if (!(this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId)))) {
3315
- _context37.next = 15;
3658
+ _context38.next = 15;
3316
3659
  break;
3317
3660
  }
3318
3661
  // 获取修改前的备注用于事件
@@ -3322,7 +3665,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3322
3665
  }
3323
3666
 
3324
3667
  // 触发订单备注变更事件
3325
- _context37.next = 15;
3668
+ _context38.next = 15;
3326
3669
  return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
3327
3670
  orderUuid: this.store.currentOrder.uuid,
3328
3671
  oldNote: previousNote,
@@ -3330,7 +3673,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3330
3673
  timestamp: Date.now()
3331
3674
  });
3332
3675
  case 15:
3333
- return _context37.abrupt("return", {
3676
+ return _context38.abrupt("return", {
3334
3677
  success: true,
3335
3678
  message: response.message || '订单备注修改成功',
3336
3679
  orderId: orderId
@@ -3339,31 +3682,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3339
3682
  // API返回失败状态
3340
3683
  errorMessage = response.message || '订单备注修改失败';
3341
3684
  this.logError("\u8BA2\u5355 ".concat(orderId, " \u5907\u6CE8\u4FEE\u6539\u5931\u8D25:"), errorMessage);
3342
- return _context37.abrupt("return", {
3685
+ return _context38.abrupt("return", {
3343
3686
  success: false,
3344
3687
  message: errorMessage,
3345
3688
  orderId: orderId
3346
3689
  });
3347
3690
  case 21:
3348
- _context37.next = 28;
3691
+ _context38.next = 28;
3349
3692
  break;
3350
3693
  case 23:
3351
- _context37.prev = 23;
3352
- _context37.t0 = _context37["catch"](1);
3353
- this.logError('编辑订单备注失败:', _context37.t0);
3354
- _errorMessage = _context37.t0 instanceof Error ? _context37.t0.message : '网络错误或服务器异常';
3355
- 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", {
3356
3699
  success: false,
3357
3700
  message: "\u7F16\u8F91\u8BA2\u5355\u5907\u6CE8\u5931\u8D25: ".concat(_errorMessage),
3358
3701
  orderId: orderId
3359
3702
  });
3360
3703
  case 28:
3361
3704
  case "end":
3362
- return _context37.stop();
3705
+ return _context38.stop();
3363
3706
  }
3364
- }, _callee37, this, [[1, 23]]);
3707
+ }, _callee38, this, [[1, 23]]);
3365
3708
  }));
3366
- function editOrderNoteByOrderIdAsync(_x27, _x28) {
3709
+ function editOrderNoteByOrderIdAsync(_x28, _x29) {
3367
3710
  return _editOrderNoteByOrderIdAsync.apply(this, arguments);
3368
3711
  }
3369
3712
  return editOrderNoteByOrderIdAsync;
@@ -3380,11 +3723,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3380
3723
  }, {
3381
3724
  key: "sendCustomerPayLinkAsync",
3382
3725
  value: (function () {
3383
- var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
3726
+ var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
3384
3727
  var _params$order_ids, _params$emails;
3385
3728
  var emailRegex, invalidEmails, requestBody, response, errorMessage, _errorMessage2;
3386
- return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3387
- while (1) switch (_context38.prev = _context38.next) {
3729
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3730
+ while (1) switch (_context39.prev = _context39.next) {
3388
3731
  case 0:
3389
3732
  this.logInfo('sendCustomerPayLinkAsync called', {
3390
3733
  orderIds: params.order_ids,
@@ -3393,21 +3736,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3393
3736
  emailsCount: ((_params$emails = params.emails) === null || _params$emails === void 0 ? void 0 : _params$emails.length) || 0,
3394
3737
  notifyAction: params.notify_action || 'order_payment_reminder'
3395
3738
  });
3396
- _context38.prev = 1;
3739
+ _context39.prev = 1;
3397
3740
  if (!(!params.order_ids || params.order_ids.length === 0)) {
3398
- _context38.next = 4;
3741
+ _context39.next = 4;
3399
3742
  break;
3400
3743
  }
3401
- return _context38.abrupt("return", {
3744
+ return _context39.abrupt("return", {
3402
3745
  success: false,
3403
3746
  message: '订单ID列表不能为空'
3404
3747
  });
3405
3748
  case 4:
3406
3749
  if (!(!params.emails || params.emails.length === 0)) {
3407
- _context38.next = 6;
3750
+ _context39.next = 6;
3408
3751
  break;
3409
3752
  }
3410
- return _context38.abrupt("return", {
3753
+ return _context39.abrupt("return", {
3411
3754
  success: false,
3412
3755
  message: '邮箱地址列表不能为空'
3413
3756
  });
@@ -3418,10 +3761,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3418
3761
  return !emailRegex.test(email);
3419
3762
  });
3420
3763
  if (!(invalidEmails.length > 0)) {
3421
- _context38.next = 10;
3764
+ _context39.next = 10;
3422
3765
  break;
3423
3766
  }
3424
- return _context38.abrupt("return", {
3767
+ return _context39.abrupt("return", {
3425
3768
  success: false,
3426
3769
  message: "\u90AE\u7BB1\u683C\u5F0F\u65E0\u6548: ".concat(invalidEmails.join(', '))
3427
3770
  });
@@ -3437,10 +3780,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3437
3780
  }, requestBody));
3438
3781
 
3439
3782
  // 调用后端API发送邮件
3440
- _context38.next = 14;
3783
+ _context39.next = 14;
3441
3784
  return this.request.post('/order/batch-email', requestBody);
3442
3785
  case 14:
3443
- response = _context38.sent;
3786
+ response = _context39.sent;
3444
3787
  this.logInfo('支付链接邮件发送响应:', {
3445
3788
  status: response.status,
3446
3789
  message: response.message,
@@ -3450,10 +3793,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3450
3793
 
3451
3794
  // 检查响应状态
3452
3795
  if (!(response.status === true || response.status === 200)) {
3453
- _context38.next = 20;
3796
+ _context39.next = 20;
3454
3797
  break;
3455
3798
  }
3456
- return _context38.abrupt("return", {
3799
+ return _context39.abrupt("return", {
3457
3800
  success: true,
3458
3801
  message: response.message || '支付链接邮件发送成功'
3459
3802
  });
@@ -3461,29 +3804,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3461
3804
  // API返回失败状态
3462
3805
  errorMessage = response.message || '支付链接邮件发送失败';
3463
3806
  console.error('[Checkout] 支付链接邮件发送失败:', errorMessage);
3464
- return _context38.abrupt("return", {
3807
+ return _context39.abrupt("return", {
3465
3808
  success: false,
3466
3809
  message: errorMessage
3467
3810
  });
3468
3811
  case 23:
3469
- _context38.next = 30;
3812
+ _context39.next = 30;
3470
3813
  break;
3471
3814
  case 25:
3472
- _context38.prev = 25;
3473
- _context38.t0 = _context38["catch"](1);
3474
- this.logError('发送客户支付链接邮件失败:', _context38.t0);
3475
- _errorMessage2 = _context38.t0 instanceof Error ? _context38.t0.message : '网络错误或服务器异常';
3476
- 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", {
3477
3820
  success: false,
3478
3821
  message: "\u53D1\u9001\u652F\u4ED8\u94FE\u63A5\u90AE\u4EF6\u5931\u8D25: ".concat(_errorMessage2)
3479
3822
  });
3480
3823
  case 30:
3481
3824
  case "end":
3482
- return _context38.stop();
3825
+ return _context39.stop();
3483
3826
  }
3484
- }, _callee38, this, [[1, 25]]);
3827
+ }, _callee39, this, [[1, 25]]);
3485
3828
  }));
3486
- function sendCustomerPayLinkAsync(_x29) {
3829
+ function sendCustomerPayLinkAsync(_x30) {
3487
3830
  return _sendCustomerPayLinkAsync.apply(this, arguments);
3488
3831
  }
3489
3832
  return sendCustomerPayLinkAsync;
@@ -3498,24 +3841,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3498
3841
  }, {
3499
3842
  key: "roundAmountAsync",
3500
3843
  value: (function () {
3501
- var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(amount) {
3844
+ var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(amount) {
3502
3845
  var _this$otherParams$ord, _this$otherParams$ord2;
3503
3846
  var result;
3504
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3505
- while (1) switch (_context39.prev = _context39.next) {
3847
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3848
+ while (1) switch (_context40.prev = _context40.next) {
3506
3849
  case 0:
3507
- _context39.next = 2;
3850
+ _context40.next = 2;
3508
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);
3509
3852
  case 2:
3510
- result = _context39.sent;
3511
- return _context39.abrupt("return", result);
3853
+ result = _context40.sent;
3854
+ return _context40.abrupt("return", result);
3512
3855
  case 4:
3513
3856
  case "end":
3514
- return _context39.stop();
3857
+ return _context40.stop();
3515
3858
  }
3516
- }, _callee39, this);
3859
+ }, _callee40, this);
3517
3860
  }));
3518
- function roundAmountAsync(_x30) {
3861
+ function roundAmountAsync(_x31) {
3519
3862
  return _roundAmountAsync.apply(this, arguments);
3520
3863
  }
3521
3864
  return roundAmountAsync;
@@ -3523,10 +3866,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3523
3866
  }, {
3524
3867
  key: "destroy",
3525
3868
  value: function () {
3526
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40() {
3869
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
3527
3870
  var _this$order, _this$order$destroy, _this$payment, _this$payment$destroy;
3528
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3529
- while (1) switch (_context40.prev = _context40.next) {
3871
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3872
+ while (1) switch (_context41.prev = _context41.next) {
3530
3873
  case 0:
3531
3874
  // 清理钱包模块的所有缓存数据
3532
3875
  this.payment.wallet.clearAllCache();
@@ -3535,10 +3878,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3535
3878
  this.core.effects.offByModuleDestroy(this.name);
3536
3879
 
3537
3880
  // 销毁子模块
3538
- _context40.next = 4;
3881
+ _context41.next = 4;
3539
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);
3540
3883
  case 4:
3541
- _context40.next = 6;
3884
+ _context41.next = 6;
3542
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);
3543
3886
  case 6:
3544
3887
  // 取消注册模块
@@ -3546,9 +3889,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3546
3889
  console.log('[Checkout] 已销毁');
3547
3890
  case 8:
3548
3891
  case "end":
3549
- return _context40.stop();
3892
+ return _context41.stop();
3550
3893
  }
3551
- }, _callee40, this);
3894
+ }, _callee41, this);
3552
3895
  }));
3553
3896
  function destroy() {
3554
3897
  return _destroy.apply(this, arguments);
@@ -3563,12 +3906,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3563
3906
  }, {
3564
3907
  key: "resetStoreStateAsync",
3565
3908
  value: (function () {
3566
- var _resetStoreStateAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
3909
+ var _resetStoreStateAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42() {
3567
3910
  var prevOrderInfo;
3568
- return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3569
- while (1) switch (_context41.prev = _context41.next) {
3911
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3912
+ while (1) switch (_context42.prev = _context42.next) {
3570
3913
  case 0:
3571
- _context41.prev = 0;
3914
+ _context42.prev = 0;
3572
3915
  prevOrderInfo = this.store.currentOrder ? {
3573
3916
  uuid: this.store.currentOrder.uuid,
3574
3917
  orderId: this.store.currentOrder.order_id
@@ -3597,26 +3940,26 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3597
3940
 
3598
3941
  // 触发订单清理事件(如果之前有订单)
3599
3942
  if (!prevOrderInfo) {
3600
- _context41.next = 17;
3943
+ _context42.next = 17;
3601
3944
  break;
3602
3945
  }
3603
- _context41.next = 17;
3946
+ _context42.next = 17;
3604
3947
  return this.core.effects.emit(CheckoutHooks.OnOrderCleared, {
3605
3948
  previousOrder: prevOrderInfo,
3606
3949
  timestamp: Date.now()
3607
3950
  });
3608
3951
  case 17:
3609
- _context41.next = 22;
3952
+ _context42.next = 22;
3610
3953
  break;
3611
3954
  case 19:
3612
- _context41.prev = 19;
3613
- _context41.t0 = _context41["catch"](0);
3614
- console.error('[Checkout] 重置 store 状态失败:', _context41.t0);
3955
+ _context42.prev = 19;
3956
+ _context42.t0 = _context42["catch"](0);
3957
+ console.error('[Checkout] 重置 store 状态失败:', _context42.t0);
3615
3958
  case 22:
3616
3959
  case "end":
3617
- return _context41.stop();
3960
+ return _context42.stop();
3618
3961
  }
3619
- }, _callee41, this, [[0, 19]]);
3962
+ }, _callee42, this, [[0, 19]]);
3620
3963
  }));
3621
3964
  function resetStoreStateAsync() {
3622
3965
  return _resetStoreStateAsync.apply(this, arguments);