@pisell/pisellos 0.0.228 → 0.0.230

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.
Files changed (44) hide show
  1. package/dist/modules/Discount/index.d.ts +2 -1
  2. package/dist/modules/Discount/index.js +67 -4
  3. package/dist/modules/Discount/types.d.ts +25 -0
  4. package/dist/modules/Payment/index.d.ts +59 -6
  5. package/dist/modules/Payment/index.js +823 -504
  6. package/dist/modules/Payment/types.d.ts +62 -32
  7. package/dist/modules/Payment/types.js +2 -2
  8. package/dist/modules/Payment/walletpass.d.ts +0 -0
  9. package/dist/modules/Payment/walletpass.js +0 -0
  10. package/dist/solution/BookingByStep/index.js +1 -1
  11. package/dist/solution/BookingTicket/index.d.ts +1 -1
  12. package/dist/solution/Checkout/appointmentDemo.json +1 -0
  13. package/dist/solution/Checkout/index.d.ts +181 -0
  14. package/dist/solution/Checkout/index.js +1596 -0
  15. package/dist/solution/Checkout/types.d.ts +550 -0
  16. package/dist/solution/Checkout/types.js +132 -0
  17. package/dist/solution/Checkout/utils/index.d.ts +73 -0
  18. package/dist/solution/Checkout/utils/index.js +371 -0
  19. package/dist/solution/ShopDiscount/index.d.ts +1 -1
  20. package/dist/solution/ShopDiscount/index.js +6 -6
  21. package/dist/solution/index.d.ts +1 -0
  22. package/dist/solution/index.js +2 -1
  23. package/lib/modules/Discount/index.d.ts +2 -1
  24. package/lib/modules/Discount/index.js +45 -3
  25. package/lib/modules/Discount/types.d.ts +25 -0
  26. package/lib/modules/Payment/index.d.ts +59 -6
  27. package/lib/modules/Payment/index.js +203 -64
  28. package/lib/modules/Payment/types.d.ts +62 -32
  29. package/lib/modules/Payment/walletpass.d.ts +0 -0
  30. package/lib/modules/Payment/walletpass.js +0 -0
  31. package/lib/solution/BookingByStep/index.js +1 -1
  32. package/lib/solution/BookingTicket/index.d.ts +1 -1
  33. package/lib/solution/Checkout/appointmentDemo.json +1 -0
  34. package/lib/solution/Checkout/index.d.ts +181 -0
  35. package/lib/solution/Checkout/index.js +864 -0
  36. package/lib/solution/Checkout/types.d.ts +550 -0
  37. package/lib/solution/Checkout/types.js +75 -0
  38. package/lib/solution/Checkout/utils/index.d.ts +73 -0
  39. package/lib/solution/Checkout/utils/index.js +266 -0
  40. package/lib/solution/ShopDiscount/index.d.ts +1 -1
  41. package/lib/solution/ShopDiscount/index.js +2 -2
  42. package/lib/solution/index.d.ts +1 -0
  43. package/lib/solution/index.js +3 -1
  44. package/package.json +1 -1
@@ -583,13 +583,13 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
583
583
  return getOrderListAsync;
584
584
  }()
585
585
  /**
586
- * 根据uuid获取指定订单
586
+ * 根据订单UUID获取支付订单(新方法)
587
587
  */
588
588
  )
589
589
  }, {
590
- key: "getOrderByUuidAsync",
590
+ key: "getPaymentOrderByUuidAsync",
591
591
  value: (function () {
592
- var _getOrderByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(orderUuid) {
592
+ var _getPaymentOrderByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(orderUuid) {
593
593
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
594
594
  while (1) switch (_context6.prev = _context6.next) {
595
595
  case 0:
@@ -601,7 +601,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
601
601
  case 6:
602
602
  _context6.prev = 6;
603
603
  _context6.t0 = _context6["catch"](0);
604
- console.error('[PaymentModule] 获取订单失败', _context6.t0);
604
+ console.error('[PaymentModule] 获取支付订单失败', _context6.t0);
605
605
  return _context6.abrupt("return", null);
606
606
  case 10:
607
607
  case "end":
@@ -609,26 +609,26 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
609
609
  }
610
610
  }, _callee6, this, [[0, 6]]);
611
611
  }));
612
- function getOrderByUuidAsync(_x5) {
613
- return _getOrderByUuidAsync.apply(this, arguments);
612
+ function getPaymentOrderByUuidAsync(_x5) {
613
+ return _getPaymentOrderByUuidAsync.apply(this, arguments);
614
614
  }
615
- return getOrderByUuidAsync;
615
+ return getPaymentOrderByUuidAsync;
616
616
  }()
617
617
  /**
618
- * 往交易组中添加订单
618
+ * 创建支付订单(新方法,专注支付数据)
619
619
  */
620
620
  )
621
621
  }, {
622
- key: "pushOrderAsync",
622
+ key: "createPaymentOrderAsync",
623
623
  value: (function () {
624
- var _pushOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
624
+ var _createPaymentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
625
625
  var existingOrders, existingOrder, originalOrder, newOrder;
626
626
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
627
627
  while (1) switch (_context7.prev = _context7.next) {
628
628
  case 0:
629
- this.logInfo('Starting pushOrderAsync', {
630
- orderId: params.order_info.order_id,
631
- totalAmount: params.order_info.total_amount
629
+ this.logInfo('Starting createPaymentOrderAsync', {
630
+ orderId: params.order_id,
631
+ totalAmount: params.total_amount
632
632
  });
633
633
  _context7.prev = 1;
634
634
  _context7.next = 4;
@@ -636,48 +636,46 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
636
636
  case 4:
637
637
  existingOrders = _context7.sent;
638
638
  existingOrder = existingOrders.find(function (order) {
639
- return order.id === params.order_info.order_id;
639
+ return String(order.id) === String(params.order_id);
640
640
  });
641
641
  if (!existingOrder) {
642
642
  _context7.next = 21;
643
643
  break;
644
644
  }
645
- // 如果存在相同 order_id 的订单,更新该订单的 order_info
646
- console.log("[PaymentModule] \u53D1\u73B0\u91CD\u590D\u8BA2\u5355 ID: ".concat(params.order_info.order_id, "\uFF0C\u66F4\u65B0\u73B0\u6709\u8BA2\u5355"));
645
+ // 如果存在相同 order_id 的订单,更新该订单信息
646
+ console.log("[PaymentModule] \u53D1\u73B0\u91CD\u590D\u8BA2\u5355 ID: ".concat(params.order_id, "\uFF0C\u66F4\u65B0\u73B0\u6709\u652F\u4ED8\u8BA2\u5355"));
647
647
  originalOrder = _objectSpread({}, existingOrder);
648
648
  existingOrder.order_info = params.order_info;
649
- existingOrder.total_amount = params.order_info.total_amount;
649
+ existingOrder.total_amount = params.total_amount;
650
+ existingOrder.is_deposit = params.is_deposit || 0;
651
+ existingOrder.deposit_amount = params.deposit_amount || '0.00';
650
652
 
651
653
  // 重新计算待付金额
652
654
  this.recalculateOrderAmount(existingOrder);
653
655
 
654
656
  // 更新到数据库
655
- _context7.next = 14;
656
- return this.dbManager.update('order', existingOrder);
657
- case 14:
658
657
  _context7.next = 16;
659
- return this.core.effects.emit(PaymentHooks.OnOrderUpdated, existingOrder);
658
+ return this.dbManager.update('order', existingOrder);
660
659
  case 16:
661
660
  _context7.next = 18;
662
- return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
663
- action: 'update',
664
- order: existingOrder,
665
- originalOrder: originalOrder
666
- });
661
+ return this.core.effects.emit(PaymentHooks.OnOrderUpdated, existingOrder);
667
662
  case 18:
668
663
  return _context7.abrupt("return", existingOrder);
669
664
  case 21:
670
- // 如果不存在相同 order_id 的订单,创建新订单
665
+ // 创建新的支付订单
671
666
  newOrder = {
672
667
  uuid: getUniqueId('pay_order_'),
673
- id: params.order_info.order_id,
668
+ id: params.order_id,
669
+ order_id: params.order_id,
674
670
  order_info: params.order_info,
675
671
  payment_status: PaymentStatus.Processing,
676
672
  payment: [],
677
673
  adjust_offline_payments: [],
678
- total_amount: params.order_info.total_amount,
679
- expect_amount: params.order_info.total_amount,
680
- tax_fee: '0.00'
674
+ total_amount: params.total_amount,
675
+ expect_amount: params.total_amount,
676
+ tax_fee: '0.00',
677
+ is_deposit: params.is_deposit || 0,
678
+ deposit_amount: params.deposit_amount || '0.00'
681
679
  };
682
680
  _context7.next = 24;
683
681
  return this.dbManager.add('order', newOrder);
@@ -685,86 +683,126 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
685
683
  _context7.next = 26;
686
684
  return this.core.effects.emit(PaymentHooks.OnOrderAdded, newOrder);
687
685
  case 26:
688
- _context7.next = 28;
689
- return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
690
- action: 'add',
691
- order: newOrder
692
- });
693
- case 28:
694
- this.logInfo('pushOrderAsync completed - new order created', {
686
+ this.logInfo('createPaymentOrderAsync completed - new payment order created', {
695
687
  orderUuid: newOrder.uuid,
696
688
  orderId: newOrder.id
697
689
  });
698
690
  return _context7.abrupt("return", newOrder);
699
- case 30:
700
- _context7.next = 37;
691
+ case 28:
692
+ _context7.next = 35;
701
693
  break;
702
- case 32:
703
- _context7.prev = 32;
694
+ case 30:
695
+ _context7.prev = 30;
704
696
  _context7.t0 = _context7["catch"](1);
705
- console.error('[PaymentModule] 添加订单失败', _context7.t0);
706
- this.logError('pushOrderAsync failed', _context7.t0, {
707
- orderId: params.order_info.order_id
697
+ console.error('[PaymentModule] 创建支付订单失败', _context7.t0);
698
+ this.logError('createPaymentOrderAsync failed', _context7.t0, {
699
+ orderId: params.order_id
708
700
  });
709
701
  throw _context7.t0;
710
- case 37:
702
+ case 35:
711
703
  case "end":
712
704
  return _context7.stop();
713
705
  }
714
- }, _callee7, this, [[1, 32]]);
706
+ }, _callee7, this, [[1, 30]]);
707
+ }));
708
+ function createPaymentOrderAsync(_x6) {
709
+ return _createPaymentOrderAsync.apply(this, arguments);
710
+ }
711
+ return createPaymentOrderAsync;
712
+ }()
713
+ /**
714
+ * 往交易组中添加订单(兼容性方法)
715
+ * @deprecated 使用 createPaymentOrderAsync 替代
716
+ */
717
+ )
718
+ }, {
719
+ key: "pushOrderAsync",
720
+ value: (function () {
721
+ var _pushOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
722
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
723
+ while (1) switch (_context8.prev = _context8.next) {
724
+ case 0:
725
+ console.warn('[PaymentModule] pushOrderAsync 已废弃,请使用 createPaymentOrderAsync 替代');
726
+ return _context8.abrupt("return", this.createPaymentOrderAsync(params));
727
+ case 2:
728
+ case "end":
729
+ return _context8.stop();
730
+ }
731
+ }, _callee8, this);
715
732
  }));
716
- function pushOrderAsync(_x6) {
733
+ function pushOrderAsync(_x7) {
717
734
  return _pushOrderAsync.apply(this, arguments);
718
735
  }
719
736
  return pushOrderAsync;
720
737
  }()
721
738
  /**
722
- * 删除订单
739
+ * 删除支付订单(新方法)
723
740
  */
724
741
  )
725
742
  }, {
726
- key: "deleteOrderAsync",
743
+ key: "deletePaymentOrderAsync",
727
744
  value: (function () {
728
- var _deleteOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(orderUuid) {
745
+ var _deletePaymentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(orderUuid) {
729
746
  var order;
730
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
731
- while (1) switch (_context8.prev = _context8.next) {
747
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
748
+ while (1) switch (_context9.prev = _context9.next) {
732
749
  case 0:
733
- _context8.prev = 0;
734
- _context8.next = 3;
750
+ _context9.prev = 0;
751
+ _context9.next = 3;
735
752
  return this.dbManager.get('order', orderUuid);
736
753
  case 3:
737
- order = _context8.sent;
754
+ order = _context9.sent;
738
755
  if (!order) {
739
- _context8.next = 11;
756
+ _context9.next = 10;
740
757
  break;
741
758
  }
742
- _context8.next = 7;
759
+ _context9.next = 7;
743
760
  return this.dbManager.delete('order', orderUuid);
744
761
  case 7:
745
- _context8.next = 9;
762
+ _context9.next = 9;
746
763
  return this.core.effects.emit(PaymentHooks.OnOrderDeleted, order);
747
764
  case 9:
748
- _context8.next = 11;
749
- return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
750
- action: 'delete',
751
- order: order
752
- });
753
- case 11:
754
- _context8.next = 17;
765
+ console.log('[PaymentModule] 支付订单删除成功:', orderUuid);
766
+ case 10:
767
+ _context9.next = 16;
755
768
  break;
756
- case 13:
757
- _context8.prev = 13;
758
- _context8.t0 = _context8["catch"](0);
759
- console.error('[PaymentModule] 删除订单失败', _context8.t0);
760
- throw _context8.t0;
761
- case 17:
769
+ case 12:
770
+ _context9.prev = 12;
771
+ _context9.t0 = _context9["catch"](0);
772
+ console.error('[PaymentModule] 删除支付订单失败', _context9.t0);
773
+ throw _context9.t0;
774
+ case 16:
762
775
  case "end":
763
- return _context8.stop();
776
+ return _context9.stop();
764
777
  }
765
- }, _callee8, this, [[0, 13]]);
778
+ }, _callee9, this, [[0, 12]]);
766
779
  }));
767
- function deleteOrderAsync(_x7) {
780
+ function deletePaymentOrderAsync(_x8) {
781
+ return _deletePaymentOrderAsync.apply(this, arguments);
782
+ }
783
+ return deletePaymentOrderAsync;
784
+ }()
785
+ /**
786
+ * 删除订单(兼容性方法)
787
+ * @deprecated 使用 deletePaymentOrderAsync 替代
788
+ */
789
+ )
790
+ }, {
791
+ key: "deleteOrderAsync",
792
+ value: (function () {
793
+ var _deleteOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(orderUuid) {
794
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
795
+ while (1) switch (_context10.prev = _context10.next) {
796
+ case 0:
797
+ console.warn('[PaymentModule] deleteOrderAsync 已废弃,请使用 deletePaymentOrderAsync 替代');
798
+ return _context10.abrupt("return", this.deletePaymentOrderAsync(orderUuid));
799
+ case 2:
800
+ case "end":
801
+ return _context10.stop();
802
+ }
803
+ }, _callee10, this);
804
+ }));
805
+ function deleteOrderAsync(_x9) {
768
806
  return _deleteOrderAsync.apply(this, arguments);
769
807
  }
770
808
  return deleteOrderAsync;
@@ -776,165 +814,322 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
776
814
  }, {
777
815
  key: "updateOrderAsync",
778
816
  value: (function () {
779
- var _updateOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(orderUuid, params) {
817
+ var _updateOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(orderUuid, params) {
780
818
  var order, updatedOrder;
781
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
782
- while (1) switch (_context9.prev = _context9.next) {
819
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
820
+ while (1) switch (_context11.prev = _context11.next) {
783
821
  case 0:
784
- _context9.prev = 0;
785
- _context9.next = 3;
822
+ _context11.prev = 0;
823
+ _context11.next = 3;
786
824
  return this.dbManager.get('order', orderUuid);
787
825
  case 3:
788
- order = _context9.sent;
826
+ order = _context11.sent;
789
827
  if (!order) {
790
- _context9.next = 12;
828
+ _context11.next = 12;
791
829
  break;
792
830
  }
793
831
  updatedOrder = _objectSpread(_objectSpread({}, order), params);
794
- _context9.next = 8;
832
+ _context11.next = 8;
795
833
  return this.dbManager.update('order', updatedOrder);
796
834
  case 8:
797
- _context9.next = 10;
835
+ _context11.next = 10;
798
836
  return this.core.effects.emit(PaymentHooks.OnOrderUpdated, updatedOrder);
799
837
  case 10:
800
- _context9.next = 12;
838
+ _context11.next = 12;
801
839
  return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
802
840
  action: 'update',
803
841
  order: updatedOrder,
804
842
  originalOrder: order
805
843
  });
806
844
  case 12:
807
- _context9.next = 18;
845
+ _context11.next = 18;
808
846
  break;
809
847
  case 14:
810
- _context9.prev = 14;
811
- _context9.t0 = _context9["catch"](0);
812
- console.error('[PaymentModule] 更新订单失败', _context9.t0);
813
- throw _context9.t0;
848
+ _context11.prev = 14;
849
+ _context11.t0 = _context11["catch"](0);
850
+ console.error('[PaymentModule] 更新订单失败', _context11.t0);
851
+ throw _context11.t0;
814
852
  case 18:
815
853
  case "end":
816
- return _context9.stop();
854
+ return _context11.stop();
817
855
  }
818
- }, _callee9, this, [[0, 14]]);
856
+ }, _callee11, this, [[0, 14]]);
819
857
  }));
820
- function updateOrderAsync(_x8, _x9) {
858
+ function updateOrderAsync(_x10, _x11) {
821
859
  return _updateOrderAsync.apply(this, arguments);
822
860
  }
823
861
  return updateOrderAsync;
824
862
  }()
825
863
  /**
826
- * 获取支付项
864
+ * 基于UUID替换订单ID
865
+ *
866
+ * 此方法用于将本地虚拟订单ID替换为真实的订单ID。
867
+ * 当前端模拟下单流程完成后,后端返回真实订单ID时调用此方法。
868
+ *
869
+ * @param orderUuid 订单的UUID
870
+ * @param newOrderId 新的订单ID (来自后端)
871
+ * @returns 更新后的订单对象,如果订单不存在则返回null
827
872
  */
828
873
  )
829
874
  }, {
830
- key: "getPaymentAsync",
875
+ key: "replaceOrderIdByUuidAsync",
831
876
  value: (function () {
832
- var _getPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(orderUuid) {
877
+ var _replaceOrderIdByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(orderUuid, newOrderId) {
878
+ var existingOrder, allOrders, duplicateOrder, originalOrderId, updatedOrder;
879
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
880
+ while (1) switch (_context12.prev = _context12.next) {
881
+ case 0:
882
+ this.logInfo('Starting replaceOrderIdByUuidAsync', {
883
+ orderUuid: orderUuid,
884
+ newOrderId: newOrderId
885
+ });
886
+ _context12.prev = 1;
887
+ _context12.next = 4;
888
+ return this.dbManager.get('order', orderUuid);
889
+ case 4:
890
+ existingOrder = _context12.sent;
891
+ if (existingOrder) {
892
+ _context12.next = 8;
893
+ break;
894
+ }
895
+ this.logWarning('Order not found for UUID replacement', {
896
+ orderUuid: orderUuid
897
+ });
898
+ return _context12.abrupt("return", null);
899
+ case 8:
900
+ _context12.next = 10;
901
+ return this.dbManager.getAll('order');
902
+ case 10:
903
+ allOrders = _context12.sent;
904
+ duplicateOrder = allOrders.find(function (order) {
905
+ return String(order.order_id) === String(newOrderId) && order.uuid !== orderUuid;
906
+ });
907
+ if (!duplicateOrder) {
908
+ _context12.next = 15;
909
+ break;
910
+ }
911
+ this.logWarning('New order ID already exists', {
912
+ newOrderId: newOrderId,
913
+ existingOrderUuid: duplicateOrder.uuid
914
+ });
915
+ throw new Error("\u8BA2\u5355ID ".concat(newOrderId, " \u5DF2\u5B58\u5728"));
916
+ case 15:
917
+ // 保存原始订单ID用于日志
918
+ originalOrderId = existingOrder.id; // 更新订单ID
919
+ updatedOrder = _objectSpread(_objectSpread({}, existingOrder), {}, {
920
+ id: newOrderId,
921
+ order_info: _objectSpread(_objectSpread({}, existingOrder.order_info), {}, {
922
+ order_id: newOrderId,
923
+ // 保留原始本地订单ID作为参考
924
+ original_local_order_id: originalOrderId,
925
+ updated_at: new Date().toISOString()
926
+ })
927
+ }); // 更新到数据库
928
+ _context12.next = 19;
929
+ return this.dbManager.update('order', updatedOrder);
930
+ case 19:
931
+ _context12.next = 21;
932
+ return this.core.effects.emit(PaymentHooks.OnOrderUpdated, updatedOrder);
933
+ case 21:
934
+ _context12.next = 23;
935
+ return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
936
+ action: 'order_id_replaced',
937
+ order: updatedOrder,
938
+ originalOrder: existingOrder,
939
+ metadata: {
940
+ originalOrderId: originalOrderId,
941
+ newOrderId: newOrderId
942
+ }
943
+ });
944
+ case 23:
945
+ this.logInfo('Order ID replacement completed successfully', {
946
+ orderUuid: orderUuid,
947
+ originalOrderId: originalOrderId,
948
+ newOrderId: newOrderId
949
+ });
950
+ console.log("[PaymentModule] \u8BA2\u5355ID\u66FF\u6362\u6210\u529F: ".concat(originalOrderId, " \u2192 ").concat(newOrderId));
951
+ return _context12.abrupt("return", updatedOrder);
952
+ case 28:
953
+ _context12.prev = 28;
954
+ _context12.t0 = _context12["catch"](1);
955
+ console.error('[PaymentModule] 替换订单ID失败', _context12.t0);
956
+ this.logError('replaceOrderIdByUuidAsync failed', _context12.t0, {
957
+ orderUuid: orderUuid,
958
+ newOrderId: newOrderId
959
+ });
960
+ throw _context12.t0;
961
+ case 33:
962
+ case "end":
963
+ return _context12.stop();
964
+ }
965
+ }, _callee12, this, [[1, 28]]);
966
+ }));
967
+ function replaceOrderIdByUuidAsync(_x12, _x13) {
968
+ return _replaceOrderIdByUuidAsync.apply(this, arguments);
969
+ }
970
+ return replaceOrderIdByUuidAsync;
971
+ }()
972
+ /**
973
+ * 获取支付项(新方法)
974
+ */
975
+ )
976
+ }, {
977
+ key: "getPaymentItemsAsync",
978
+ value: (function () {
979
+ var _getPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderUuid) {
833
980
  var order;
834
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
835
- while (1) switch (_context10.prev = _context10.next) {
981
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
982
+ while (1) switch (_context13.prev = _context13.next) {
836
983
  case 0:
837
984
  if (orderUuid) {
838
- _context10.next = 2;
985
+ _context13.next = 2;
839
986
  break;
840
987
  }
841
988
  throw new Error('orderUuid is required');
842
989
  case 2:
843
- _context10.next = 4;
844
- return this.getOrderByUuidAsync(orderUuid);
990
+ _context13.next = 4;
991
+ return this.getPaymentOrderByUuidAsync(orderUuid);
845
992
  case 4:
846
- order = _context10.sent;
847
- return _context10.abrupt("return", (order === null || order === void 0 ? void 0 : order.payment) || []);
993
+ order = _context13.sent;
994
+ return _context13.abrupt("return", (order === null || order === void 0 ? void 0 : order.payment) || []);
848
995
  case 6:
849
996
  case "end":
850
- return _context10.stop();
997
+ return _context13.stop();
851
998
  }
852
- }, _callee10, this);
999
+ }, _callee13, this);
1000
+ }));
1001
+ function getPaymentItemsAsync(_x14) {
1002
+ return _getPaymentItemsAsync.apply(this, arguments);
1003
+ }
1004
+ return getPaymentItemsAsync;
1005
+ }()
1006
+ /**
1007
+ * 获取支付项(兼容性方法)
1008
+ * @deprecated 使用 getPaymentItemsAsync 替代
1009
+ */
1010
+ )
1011
+ }, {
1012
+ key: "getPaymentAsync",
1013
+ value: (function () {
1014
+ var _getPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderUuid) {
1015
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1016
+ while (1) switch (_context14.prev = _context14.next) {
1017
+ case 0:
1018
+ console.warn('[PaymentModule] getPaymentAsync 已废弃,请使用 getPaymentItemsAsync 替代');
1019
+ return _context14.abrupt("return", this.getPaymentItemsAsync(orderUuid));
1020
+ case 2:
1021
+ case "end":
1022
+ return _context14.stop();
1023
+ }
1024
+ }, _callee14, this);
853
1025
  }));
854
- function getPaymentAsync(_x10) {
1026
+ function getPaymentAsync(_x15) {
855
1027
  return _getPaymentAsync.apply(this, arguments);
856
1028
  }
857
1029
  return getPaymentAsync;
858
1030
  }()
859
1031
  /**
860
- * 为某个订单设置一个支付项
1032
+ * 为某个订单添加支付项(新方法)
861
1033
  */
862
1034
  )
863
1035
  }, {
864
- key: "pushPaymentAsync",
1036
+ key: "addPaymentItemAsync",
865
1037
  value: (function () {
866
- var _pushPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(orderUuid, paymentItem) {
1038
+ var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(orderUuid, paymentItem) {
867
1039
  var order, newPaymentItem;
868
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
869
- while (1) switch (_context11.prev = _context11.next) {
1040
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1041
+ while (1) switch (_context15.prev = _context15.next) {
870
1042
  case 0:
871
- this.logInfo('Starting pushPaymentAsync', {
1043
+ this.logInfo('Starting addPaymentItemAsync', {
872
1044
  orderUuid: orderUuid,
873
1045
  paymentAmount: paymentItem.amount,
874
1046
  paymentCode: paymentItem.code
875
1047
  });
876
- _context11.prev = 1;
877
- _context11.next = 4;
878
- return this.dbManager.get('order', orderUuid);
1048
+ _context15.prev = 1;
1049
+ _context15.next = 4;
1050
+ return this.getPaymentOrderByUuidAsync(orderUuid);
879
1051
  case 4:
880
- order = _context11.sent;
1052
+ order = _context15.sent;
881
1053
  if (order) {
882
- _context11.next = 7;
1054
+ _context15.next = 7;
883
1055
  break;
884
1056
  }
885
- throw new Error('订单不存在');
1057
+ throw new Error("Order not found: ".concat(orderUuid));
886
1058
  case 7:
887
- newPaymentItem = _objectSpread(_objectSpread({}, paymentItem), {}, {
1059
+ newPaymentItem = {
1060
+ uuid: getUniqueId('payment_'),
1061
+ id: paymentItem.id || 0,
1062
+ name: paymentItem.name,
1063
+ code: paymentItem.code,
1064
+ type: paymentItem.type,
888
1065
  amount: formatAmount(paymentItem.amount),
889
- // 格式化金额为保留两位小数的字符串
890
- uuid: getUniqueId('pay_item_'),
1066
+ voucher_id: paymentItem.voucher_id || '',
1067
+ rounding_amount: '0.00',
1068
+ service_charge: {
1069
+ percentage: '0.00',
1070
+ amount: '0.00'
1071
+ },
891
1072
  isSynced: false
892
- });
1073
+ };
893
1074
  order.payment.push(newPaymentItem);
894
-
895
- // 重新计算待付金额
896
1075
  this.recalculateOrderAmount(order);
897
-
898
- // 更新到 IndexDB
899
- _context11.next = 12;
1076
+ _context15.next = 12;
900
1077
  return this.dbManager.update('order', order);
901
1078
  case 12:
902
- _context11.next = 14;
1079
+ _context15.next = 14;
903
1080
  return this.core.effects.emit(PaymentHooks.OnPaymentAdded, {
904
- order: order,
905
- paymentItem: newPaymentItem
1081
+ orderUuid: orderUuid,
1082
+ payment: newPaymentItem
906
1083
  });
907
1084
  case 14:
908
- _context11.next = 16;
909
- return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
910
- action: 'payment_add',
911
- order: order,
912
- paymentItem: newPaymentItem
913
- });
914
- case 16:
915
- this.logInfo('pushPaymentAsync completed successfully', {
1085
+ this.logInfo('addPaymentItemAsync completed successfully', {
916
1086
  orderUuid: orderUuid,
917
1087
  paymentUuid: newPaymentItem.uuid,
918
1088
  newExpectAmount: order.expect_amount
919
1089
  });
920
- _context11.next = 24;
1090
+ _context15.next = 22;
921
1091
  break;
922
- case 19:
923
- _context11.prev = 19;
924
- _context11.t0 = _context11["catch"](1);
925
- console.error('[PaymentModule] 添加支付项失败', _context11.t0);
926
- this.logError('pushPaymentAsync failed', _context11.t0, {
1092
+ case 17:
1093
+ _context15.prev = 17;
1094
+ _context15.t0 = _context15["catch"](1);
1095
+ console.error('[PaymentModule] 添加支付项失败', _context15.t0);
1096
+ this.logError('addPaymentItemAsync failed', _context15.t0, {
927
1097
  orderUuid: orderUuid,
928
1098
  paymentItem: paymentItem
929
1099
  });
930
- throw _context11.t0;
931
- case 24:
1100
+ throw _context15.t0;
1101
+ case 22:
932
1102
  case "end":
933
- return _context11.stop();
1103
+ return _context15.stop();
1104
+ }
1105
+ }, _callee15, this, [[1, 17]]);
1106
+ }));
1107
+ function addPaymentItemAsync(_x16, _x17) {
1108
+ return _addPaymentItemAsync.apply(this, arguments);
1109
+ }
1110
+ return addPaymentItemAsync;
1111
+ }()
1112
+ /**
1113
+ * 为某个订单设置一个支付项(兼容性方法)
1114
+ * @deprecated 使用 addPaymentItemAsync 替代
1115
+ */
1116
+ )
1117
+ }, {
1118
+ key: "pushPaymentAsync",
1119
+ value: (function () {
1120
+ var _pushPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(orderUuid, paymentItem) {
1121
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1122
+ while (1) switch (_context16.prev = _context16.next) {
1123
+ case 0:
1124
+ console.warn('[PaymentModule] pushPaymentAsync 已废弃,请使用 addPaymentItemAsync 替代');
1125
+ return _context16.abrupt("return", this.addPaymentItemAsync(orderUuid, paymentItem));
1126
+ case 2:
1127
+ case "end":
1128
+ return _context16.stop();
934
1129
  }
935
- }, _callee11, this, [[1, 19]]);
1130
+ }, _callee16, this);
936
1131
  }));
937
- function pushPaymentAsync(_x11, _x12) {
1132
+ function pushPaymentAsync(_x18, _x19) {
938
1133
  return _pushPaymentAsync.apply(this, arguments);
939
1134
  }
940
1135
  return pushPaymentAsync;
@@ -946,22 +1141,22 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
946
1141
  }, {
947
1142
  key: "deletePaymentAsync",
948
1143
  value: (function () {
949
- var _deletePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(orderUuid, paymentUuid) {
1144
+ var _deletePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(orderUuid, paymentUuid) {
950
1145
  var order, index, deletedPayment;
951
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
952
- while (1) switch (_context12.prev = _context12.next) {
1146
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1147
+ while (1) switch (_context17.prev = _context17.next) {
953
1148
  case 0:
954
1149
  this.logInfo('Starting deletePaymentAsync', {
955
1150
  orderUuid: orderUuid,
956
1151
  paymentUuid: paymentUuid
957
1152
  });
958
- _context12.prev = 1;
959
- _context12.next = 4;
1153
+ _context17.prev = 1;
1154
+ _context17.next = 4;
960
1155
  return this.dbManager.get('order', orderUuid);
961
1156
  case 4:
962
- order = _context12.sent;
1157
+ order = _context17.sent;
963
1158
  if (order) {
964
- _context12.next = 7;
1159
+ _context17.next = 7;
965
1160
  break;
966
1161
  }
967
1162
  throw new Error('订单不存在');
@@ -970,43 +1165,43 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
970
1165
  return payment.uuid === paymentUuid;
971
1166
  });
972
1167
  if (!(index > -1)) {
973
- _context12.next = 17;
1168
+ _context17.next = 17;
974
1169
  break;
975
1170
  }
976
1171
  deletedPayment = order.payment.splice(index, 1)[0]; // 重新计算待付金额
977
1172
  this.recalculateOrderAmount(order);
978
1173
 
979
1174
  // 更新到 IndexDB
980
- _context12.next = 13;
1175
+ _context17.next = 13;
981
1176
  return this.dbManager.update('order', order);
982
1177
  case 13:
983
- _context12.next = 15;
1178
+ _context17.next = 15;
984
1179
  return this.core.effects.emit(PaymentHooks.OnPaymentDeleted, {
985
1180
  order: order,
986
1181
  paymentItem: deletedPayment
987
1182
  });
988
1183
  case 15:
989
- _context12.next = 17;
1184
+ _context17.next = 17;
990
1185
  return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
991
1186
  action: 'payment_delete',
992
1187
  order: order,
993
1188
  paymentItem: deletedPayment
994
1189
  });
995
1190
  case 17:
996
- _context12.next = 23;
1191
+ _context17.next = 23;
997
1192
  break;
998
1193
  case 19:
999
- _context12.prev = 19;
1000
- _context12.t0 = _context12["catch"](1);
1001
- console.error('[PaymentModule] 删除支付项失败', _context12.t0);
1002
- throw _context12.t0;
1194
+ _context17.prev = 19;
1195
+ _context17.t0 = _context17["catch"](1);
1196
+ console.error('[PaymentModule] 删除支付项失败', _context17.t0);
1197
+ throw _context17.t0;
1003
1198
  case 23:
1004
1199
  case "end":
1005
- return _context12.stop();
1200
+ return _context17.stop();
1006
1201
  }
1007
- }, _callee12, this, [[1, 19]]);
1202
+ }, _callee17, this, [[1, 19]]);
1008
1203
  }));
1009
- function deletePaymentAsync(_x13, _x14) {
1204
+ function deletePaymentAsync(_x20, _x21) {
1010
1205
  return _deletePaymentAsync.apply(this, arguments);
1011
1206
  }
1012
1207
  return deletePaymentAsync;
@@ -1018,18 +1213,18 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1018
1213
  }, {
1019
1214
  key: "updatePaymentAsync",
1020
1215
  value: (function () {
1021
- var _updatePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderUuid, paymentUuid, params) {
1216
+ var _updatePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(orderUuid, paymentUuid, params) {
1022
1217
  var order, paymentItem, formattedParams;
1023
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1024
- while (1) switch (_context13.prev = _context13.next) {
1218
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1219
+ while (1) switch (_context18.prev = _context18.next) {
1025
1220
  case 0:
1026
- _context13.prev = 0;
1027
- _context13.next = 3;
1221
+ _context18.prev = 0;
1222
+ _context18.next = 3;
1028
1223
  return this.dbManager.get('order', orderUuid);
1029
1224
  case 3:
1030
- order = _context13.sent;
1225
+ order = _context18.sent;
1031
1226
  if (order) {
1032
- _context13.next = 6;
1227
+ _context18.next = 6;
1033
1228
  break;
1034
1229
  }
1035
1230
  throw new Error('订单不存在');
@@ -1038,7 +1233,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1038
1233
  return payment.uuid === paymentUuid;
1039
1234
  });
1040
1235
  if (!paymentItem) {
1041
- _context13.next = 18;
1236
+ _context18.next = 18;
1042
1237
  break;
1043
1238
  }
1044
1239
  // 如果更新参数中包含 amount,先格式化
@@ -1052,36 +1247,36 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1052
1247
  this.recalculateOrderAmount(order);
1053
1248
 
1054
1249
  // 更新到 IndexDB
1055
- _context13.next = 14;
1250
+ _context18.next = 14;
1056
1251
  return this.dbManager.update('order', order);
1057
1252
  case 14:
1058
- _context13.next = 16;
1253
+ _context18.next = 16;
1059
1254
  return this.core.effects.emit(PaymentHooks.OnPaymentUpdated, {
1060
1255
  order: order,
1061
1256
  paymentItem: paymentItem
1062
1257
  });
1063
1258
  case 16:
1064
- _context13.next = 18;
1259
+ _context18.next = 18;
1065
1260
  return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
1066
1261
  action: 'payment_update',
1067
1262
  order: order,
1068
1263
  paymentItem: paymentItem
1069
1264
  });
1070
1265
  case 18:
1071
- _context13.next = 24;
1266
+ _context18.next = 24;
1072
1267
  break;
1073
1268
  case 20:
1074
- _context13.prev = 20;
1075
- _context13.t0 = _context13["catch"](0);
1076
- console.error('[PaymentModule] 更新支付项失败', _context13.t0);
1077
- throw _context13.t0;
1269
+ _context18.prev = 20;
1270
+ _context18.t0 = _context18["catch"](0);
1271
+ console.error('[PaymentModule] 更新支付项失败', _context18.t0);
1272
+ throw _context18.t0;
1078
1273
  case 24:
1079
1274
  case "end":
1080
- return _context13.stop();
1275
+ return _context18.stop();
1081
1276
  }
1082
- }, _callee13, this, [[0, 20]]);
1277
+ }, _callee18, this, [[0, 20]]);
1083
1278
  }));
1084
- function updatePaymentAsync(_x15, _x16, _x17) {
1279
+ function updatePaymentAsync(_x22, _x23, _x24) {
1085
1280
  return _updatePaymentAsync.apply(this, arguments);
1086
1281
  }
1087
1282
  return updatePaymentAsync;
@@ -1093,76 +1288,76 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1093
1288
  }, {
1094
1289
  key: "submitPayAsync",
1095
1290
  value: (function () {
1096
- var _submitPayAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderUuid) {
1291
+ var _submitPayAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(orderUuid) {
1097
1292
  var orderToSubmit, order, _allOrders, _iterator5, _step5, _order, allOrders, allOrdersProcessed, result;
1098
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1099
- while (1) switch (_context14.prev = _context14.next) {
1293
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1294
+ while (1) switch (_context19.prev = _context19.next) {
1100
1295
  case 0:
1101
1296
  this.logInfo('Starting submitPayAsync', {
1102
1297
  orderUuid: orderUuid
1103
1298
  });
1104
- _context14.prev = 1;
1299
+ _context19.prev = 1;
1105
1300
  if (!orderUuid) {
1106
- _context14.next = 9;
1301
+ _context19.next = 9;
1107
1302
  break;
1108
1303
  }
1109
- _context14.next = 5;
1304
+ _context19.next = 5;
1110
1305
  return this.dbManager.get('order', orderUuid);
1111
1306
  case 5:
1112
- order = _context14.sent;
1307
+ order = _context19.sent;
1113
1308
  orderToSubmit = order ? [order] : [];
1114
- _context14.next = 13;
1309
+ _context19.next = 13;
1115
1310
  break;
1116
1311
  case 9:
1117
- _context14.next = 11;
1312
+ _context19.next = 11;
1118
1313
  return this.dbManager.getAll('order');
1119
1314
  case 11:
1120
- _allOrders = _context14.sent;
1315
+ _allOrders = _context19.sent;
1121
1316
  // 包括正在处理中的订单和部分支付的订单(可能添加了新的支付项)
1122
1317
  orderToSubmit = _allOrders.filter(function (order) {
1123
1318
  return order.payment_status === PaymentStatus.Processing || order.payment_status === PaymentStatus.PartiallyPaid;
1124
1319
  });
1125
1320
  case 13:
1126
1321
  _iterator5 = _createForOfIteratorHelper(orderToSubmit);
1127
- _context14.prev = 14;
1322
+ _context19.prev = 14;
1128
1323
  _iterator5.s();
1129
1324
  case 16:
1130
1325
  if ((_step5 = _iterator5.n()).done) {
1131
- _context14.next = 22;
1326
+ _context19.next = 22;
1132
1327
  break;
1133
1328
  }
1134
1329
  _order = _step5.value;
1135
- _context14.next = 20;
1330
+ _context19.next = 20;
1136
1331
  return this.submitSingleOrderPayment(_order);
1137
1332
  case 20:
1138
- _context14.next = 16;
1333
+ _context19.next = 16;
1139
1334
  break;
1140
1335
  case 22:
1141
- _context14.next = 27;
1336
+ _context19.next = 27;
1142
1337
  break;
1143
1338
  case 24:
1144
- _context14.prev = 24;
1145
- _context14.t0 = _context14["catch"](14);
1146
- _iterator5.e(_context14.t0);
1339
+ _context19.prev = 24;
1340
+ _context19.t0 = _context19["catch"](14);
1341
+ _iterator5.e(_context19.t0);
1147
1342
  case 27:
1148
- _context14.prev = 27;
1343
+ _context19.prev = 27;
1149
1344
  _iterator5.f();
1150
- return _context14.finish(27);
1345
+ return _context19.finish(27);
1151
1346
  case 30:
1152
- _context14.next = 32;
1347
+ _context19.next = 32;
1153
1348
  return this.runPaymentSyncQueue();
1154
1349
  case 32:
1155
- _context14.next = 34;
1350
+ _context19.next = 34;
1156
1351
  return this.dbManager.getAll('order');
1157
1352
  case 34:
1158
- allOrders = _context14.sent;
1353
+ allOrders = _context19.sent;
1159
1354
  allOrdersProcessed = allOrders.every(function (order) {
1160
1355
  return order.payment.every(function (payment) {
1161
1356
  return payment.isSynced === true;
1162
1357
  });
1163
1358
  });
1164
1359
  if (!allOrdersProcessed) {
1165
- _context14.next = 42;
1360
+ _context19.next = 42;
1166
1361
  break;
1167
1362
  }
1168
1363
  result = {
@@ -1172,34 +1367,34 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1172
1367
  result: result.status,
1173
1368
  processedOrdersCount: allOrders.length
1174
1369
  });
1175
- return _context14.abrupt("return", result);
1370
+ return _context19.abrupt("return", result);
1176
1371
  case 42:
1177
1372
  this.logWarning('submitPayAsync completed with unprocessed orders', {
1178
1373
  totalOrders: allOrders.length
1179
1374
  });
1180
- return _context14.abrupt("return", {
1375
+ return _context19.abrupt("return", {
1181
1376
  status: 'failed'
1182
1377
  });
1183
1378
  case 44:
1184
- _context14.next = 51;
1379
+ _context19.next = 51;
1185
1380
  break;
1186
1381
  case 46:
1187
- _context14.prev = 46;
1188
- _context14.t1 = _context14["catch"](1);
1189
- console.error('[PaymentModule] 提交支付失败', _context14.t1);
1190
- this.logError('submitPayAsync failed', _context14.t1, {
1382
+ _context19.prev = 46;
1383
+ _context19.t1 = _context19["catch"](1);
1384
+ console.error('[PaymentModule] 提交支付失败', _context19.t1);
1385
+ this.logError('submitPayAsync failed', _context19.t1, {
1191
1386
  orderUuid: orderUuid
1192
1387
  });
1193
- return _context14.abrupt("return", {
1388
+ return _context19.abrupt("return", {
1194
1389
  status: 'failed'
1195
1390
  });
1196
1391
  case 51:
1197
1392
  case "end":
1198
- return _context14.stop();
1393
+ return _context19.stop();
1199
1394
  }
1200
- }, _callee14, this, [[1, 46], [14, 24, 27, 30]]);
1395
+ }, _callee19, this, [[1, 46], [14, 24, 27, 30]]);
1201
1396
  }));
1202
- function submitPayAsync(_x18) {
1397
+ function submitPayAsync(_x25) {
1203
1398
  return _submitPayAsync.apply(this, arguments);
1204
1399
  }
1205
1400
  return submitPayAsync;
@@ -1211,12 +1406,12 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1211
1406
  }, {
1212
1407
  key: "submitSingleOrderPayment",
1213
1408
  value: (function () {
1214
- var _submitSingleOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(order) {
1409
+ var _submitSingleOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(order) {
1215
1410
  var paymentData, totalPaidAmount, orderTotalAmount;
1216
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1217
- while (1) switch (_context15.prev = _context15.next) {
1411
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1412
+ while (1) switch (_context20.prev = _context20.next) {
1218
1413
  case 0:
1219
- _context15.prev = 0;
1414
+ _context20.prev = 0;
1220
1415
  paymentData = {
1221
1416
  payments: order.payment.map(function (payment) {
1222
1417
  return {
@@ -1237,7 +1432,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1237
1432
  totalPaidAmount = paymentData.payments.reduce(function (sum, payment) {
1238
1433
  return sum.plus(payment.amount);
1239
1434
  }, new Decimal(0));
1240
- orderTotalAmount = new Decimal(order.order_info.total_amount); // 根据支付金额判断订单状态
1435
+ orderTotalAmount = new Decimal(order.total_amount); // 根据支付金额判断订单状态
1241
1436
  if (totalPaidAmount.gte(orderTotalAmount)) {
1242
1437
  // 支付金额足够,标记为已完成
1243
1438
  order.payment_status = PaymentStatus.Finished;
@@ -1253,46 +1448,46 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1253
1448
 
1254
1449
  // 更新订单状态到数据库
1255
1450
  // 注意:isSynced 保持为 false,直到网络同步成功后才设为 true
1256
- _context15.next = 8;
1451
+ _context20.next = 8;
1257
1452
  return this.dbManager.update('order', order);
1258
1453
  case 8:
1259
1454
  if (!(paymentData.payments.length === 0)) {
1260
- _context15.next = 12;
1455
+ _context20.next = 12;
1261
1456
  break;
1262
1457
  }
1263
1458
  console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u5217\u8868\u4E3A\u7A7A\uFF0C\u8DF3\u8FC7\u961F\u5217\u63A8\u9001"));
1264
1459
  this.logWarning('Empty payment queue submission', {
1265
1460
  orderUuid: order.uuid,
1266
- orderId: order.order_info.order_id
1461
+ orderId: order.order_id
1267
1462
  });
1268
- return _context15.abrupt("return");
1463
+ return _context20.abrupt("return");
1269
1464
  case 12:
1270
- _context15.next = 14;
1465
+ _context20.next = 14;
1271
1466
  return this.addToSyncQueue(order, paymentData);
1272
1467
  case 14:
1273
- _context15.next = 16;
1468
+ _context20.next = 16;
1274
1469
  return this.core.effects.emit(PaymentHooks.OnPaymentSubmitted, order);
1275
1470
  case 16:
1276
- _context15.next = 18;
1471
+ _context20.next = 18;
1277
1472
  return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
1278
1473
  action: 'submit',
1279
1474
  order: order
1280
1475
  });
1281
1476
  case 18:
1282
- _context15.next = 24;
1477
+ _context20.next = 24;
1283
1478
  break;
1284
1479
  case 20:
1285
- _context15.prev = 20;
1286
- _context15.t0 = _context15["catch"](0);
1287
- console.error("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u63D0\u4EA4\u5931\u8D25"), _context15.t0);
1288
- throw _context15.t0;
1480
+ _context20.prev = 20;
1481
+ _context20.t0 = _context20["catch"](0);
1482
+ console.error("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u63D0\u4EA4\u5931\u8D25"), _context20.t0);
1483
+ throw _context20.t0;
1289
1484
  case 24:
1290
1485
  case "end":
1291
- return _context15.stop();
1486
+ return _context20.stop();
1292
1487
  }
1293
- }, _callee15, this, [[0, 20]]);
1488
+ }, _callee20, this, [[0, 20]]);
1294
1489
  }));
1295
- function submitSingleOrderPayment(_x19) {
1490
+ function submitSingleOrderPayment(_x26) {
1296
1491
  return _submitSingleOrderPayment.apply(this, arguments);
1297
1492
  }
1298
1493
  return submitSingleOrderPayment;
@@ -1304,9 +1499,9 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1304
1499
  }, {
1305
1500
  key: "addToSyncQueue",
1306
1501
  value: (function () {
1307
- var _addToSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(order, paymentData) {
1308
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1309
- while (1) switch (_context16.prev = _context16.next) {
1502
+ var _addToSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(order, paymentData) {
1503
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1504
+ while (1) switch (_context21.prev = _context21.next) {
1310
1505
  case 0:
1311
1506
  try {
1312
1507
  console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u5DF2\u6DFB\u52A0\u5230\u540C\u6B65\u961F\u5217"));
@@ -1321,7 +1516,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1321
1516
  action: 'syncPayment',
1322
1517
  payload: {
1323
1518
  orderUuid: order.uuid,
1324
- orderId: order.order_info.order_id,
1519
+ orderId: order.order_id,
1325
1520
  paymentData: paymentData,
1326
1521
  core: this.core
1327
1522
  },
@@ -1338,11 +1533,11 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1338
1533
  }
1339
1534
  case 1:
1340
1535
  case "end":
1341
- return _context16.stop();
1536
+ return _context21.stop();
1342
1537
  }
1343
- }, _callee16, this);
1538
+ }, _callee21, this);
1344
1539
  }));
1345
- function addToSyncQueue(_x20, _x21) {
1540
+ function addToSyncQueue(_x27, _x28) {
1346
1541
  return _addToSyncQueue.apply(this, arguments);
1347
1542
  }
1348
1543
  return addToSyncQueue;
@@ -1354,29 +1549,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1354
1549
  }, {
1355
1550
  key: "getRemainingOrderAmountAsync",
1356
1551
  value: (function () {
1357
- var _getRemainingOrderAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(orderUuid) {
1552
+ var _getRemainingOrderAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(orderUuid) {
1358
1553
  var order;
1359
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1360
- while (1) switch (_context17.prev = _context17.next) {
1554
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1555
+ while (1) switch (_context22.prev = _context22.next) {
1361
1556
  case 0:
1362
- _context17.next = 2;
1363
- return this.getOrderByUuidAsync(orderUuid);
1557
+ _context22.next = 2;
1558
+ return this.getPaymentOrderByUuidAsync(orderUuid);
1364
1559
  case 2:
1365
- order = _context17.sent;
1560
+ order = _context22.sent;
1366
1561
  if (order) {
1367
- _context17.next = 5;
1562
+ _context22.next = 5;
1368
1563
  break;
1369
1564
  }
1370
1565
  throw new Error('订单不存在');
1371
1566
  case 5:
1372
- return _context17.abrupt("return", new Decimal(order.expect_amount).toNumber());
1567
+ return _context22.abrupt("return", new Decimal(order.expect_amount).toNumber());
1373
1568
  case 6:
1374
1569
  case "end":
1375
- return _context17.stop();
1570
+ return _context22.stop();
1376
1571
  }
1377
- }, _callee17, this);
1572
+ }, _callee22, this);
1378
1573
  }));
1379
- function getRemainingOrderAmountAsync(_x22) {
1574
+ function getRemainingOrderAmountAsync(_x29) {
1380
1575
  return _getRemainingOrderAmountAsync.apply(this, arguments);
1381
1576
  }
1382
1577
  return getRemainingOrderAmountAsync;
@@ -1388,65 +1583,65 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1388
1583
  }, {
1389
1584
  key: "getRemainingOrderAmountWithInputAsync",
1390
1585
  value: (function () {
1391
- var _getRemainingOrderAmountWithInputAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(inputAmount, orderUuid) {
1586
+ var _getRemainingOrderAmountWithInputAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(inputAmount, orderUuid) {
1392
1587
  var order, inputDecimal;
1393
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1394
- while (1) switch (_context18.prev = _context18.next) {
1588
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1589
+ while (1) switch (_context23.prev = _context23.next) {
1395
1590
  case 0:
1396
- _context18.next = 2;
1397
- return this.getOrderByUuidAsync(orderUuid);
1591
+ _context23.next = 2;
1592
+ return this.getPaymentOrderByUuidAsync(orderUuid);
1398
1593
  case 2:
1399
- order = _context18.sent;
1594
+ order = _context23.sent;
1400
1595
  if (order) {
1401
- _context18.next = 5;
1596
+ _context23.next = 5;
1402
1597
  break;
1403
1598
  }
1404
1599
  throw new Error('订单不存在');
1405
1600
  case 5:
1406
1601
  if (!(inputAmount === null || inputAmount === undefined)) {
1407
- _context18.next = 7;
1602
+ _context23.next = 7;
1408
1603
  break;
1409
1604
  }
1410
- return _context18.abrupt("return", new Decimal(order.expect_amount).toNumber());
1605
+ return _context23.abrupt("return", new Decimal(order.expect_amount).toNumber());
1411
1606
  case 7:
1412
1607
  if (!(typeof inputAmount === 'string')) {
1413
- _context18.next = 10;
1608
+ _context23.next = 10;
1414
1609
  break;
1415
1610
  }
1416
1611
  if (!(inputAmount.trim() === '')) {
1417
- _context18.next = 10;
1612
+ _context23.next = 10;
1418
1613
  break;
1419
1614
  }
1420
- return _context18.abrupt("return", new Decimal(order.expect_amount).toNumber());
1615
+ return _context23.abrupt("return", new Decimal(order.expect_amount).toNumber());
1421
1616
  case 10:
1422
1617
  if (!(typeof inputAmount === 'number')) {
1423
- _context18.next = 14;
1618
+ _context23.next = 14;
1424
1619
  break;
1425
1620
  }
1426
1621
  if (!(isNaN(inputAmount) || !isFinite(inputAmount))) {
1427
- _context18.next = 14;
1622
+ _context23.next = 14;
1428
1623
  break;
1429
1624
  }
1430
1625
  // 如果输入是 NaN 或无穷大,返回原始的待付金额
1431
1626
  console.warn("[PaymentModule] \u8F93\u5165\u91D1\u989D\u4E0D\u662F\u6709\u6548\u6570\u5B57: ".concat(inputAmount, "\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D"));
1432
- return _context18.abrupt("return", new Decimal(order.expect_amount).toNumber());
1627
+ return _context23.abrupt("return", new Decimal(order.expect_amount).toNumber());
1433
1628
  case 14:
1434
- _context18.prev = 14;
1629
+ _context23.prev = 14;
1435
1630
  inputDecimal = new Decimal(inputAmount);
1436
- return _context18.abrupt("return", new Decimal(order.expect_amount).minus(inputDecimal).toNumber());
1631
+ return _context23.abrupt("return", new Decimal(order.expect_amount).minus(inputDecimal).toNumber());
1437
1632
  case 19:
1438
- _context18.prev = 19;
1439
- _context18.t0 = _context18["catch"](14);
1633
+ _context23.prev = 19;
1634
+ _context23.t0 = _context23["catch"](14);
1440
1635
  // 如果输入不是有效的数字,返回原始的待付金额
1441
1636
  console.warn("[PaymentModule] \u8F93\u5165\u91D1\u989D\u683C\u5F0F\u65E0\u6548: ".concat(inputAmount, "\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D"));
1442
- return _context18.abrupt("return", new Decimal(order.expect_amount).toNumber());
1637
+ return _context23.abrupt("return", new Decimal(order.expect_amount).toNumber());
1443
1638
  case 23:
1444
1639
  case "end":
1445
- return _context18.stop();
1640
+ return _context23.stop();
1446
1641
  }
1447
- }, _callee18, this, [[14, 19]]);
1642
+ }, _callee23, this, [[14, 19]]);
1448
1643
  }));
1449
- function getRemainingOrderAmountWithInputAsync(_x23, _x24) {
1644
+ function getRemainingOrderAmountWithInputAsync(_x30, _x31) {
1450
1645
  return _getRemainingOrderAmountWithInputAsync.apply(this, arguments);
1451
1646
  }
1452
1647
  return getRemainingOrderAmountWithInputAsync;
@@ -1458,9 +1653,14 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1458
1653
  }, {
1459
1654
  key: "recalculateOrderAmount",
1460
1655
  value: function recalculateOrderAmount(order) {
1461
- var totalAmount = new Decimal(order.order_info.total_amount);
1656
+ var totalAmount = new Decimal(order.total_amount);
1462
1657
  var paidAmount = order.payment.reduce(function (sum, payment) {
1463
- return sum.plus(payment.amount);
1658
+ try {
1659
+ return sum.plus(payment.amount);
1660
+ } catch (error) {
1661
+ console.warn("[PaymentModule] \u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: ".concat(payment.amount, "\uFF0C\u8DF3\u8FC7\u8BA1\u7B97"));
1662
+ return sum;
1663
+ }
1464
1664
  }, new Decimal(0));
1465
1665
  var remainingAmount = totalAmount.minus(paidAmount);
1466
1666
  order.expect_amount = Decimal.max(0, remainingAmount).toFixed(2);
@@ -1472,29 +1672,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1472
1672
  }, {
1473
1673
  key: "getCashPaymentMethod",
1474
1674
  value: (function () {
1475
- var _getCashPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1675
+ var _getCashPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
1476
1676
  var payMethods;
1477
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1478
- while (1) switch (_context19.prev = _context19.next) {
1677
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1678
+ while (1) switch (_context24.prev = _context24.next) {
1479
1679
  case 0:
1480
- _context19.prev = 0;
1481
- _context19.next = 3;
1680
+ _context24.prev = 0;
1681
+ _context24.next = 3;
1482
1682
  return this.dbManager.getAll('pay_method');
1483
1683
  case 3:
1484
- payMethods = _context19.sent;
1485
- return _context19.abrupt("return", payMethods.find(function (method) {
1684
+ payMethods = _context24.sent;
1685
+ return _context24.abrupt("return", payMethods.find(function (method) {
1486
1686
  return method.code === PaymentMethodType.Cash;
1487
1687
  }) || null);
1488
1688
  case 7:
1489
- _context19.prev = 7;
1490
- _context19.t0 = _context19["catch"](0);
1491
- console.error('[PaymentModule] 获取现金支付方式失败', _context19.t0);
1492
- return _context19.abrupt("return", null);
1689
+ _context24.prev = 7;
1690
+ _context24.t0 = _context24["catch"](0);
1691
+ console.error('[PaymentModule] 获取现金支付方式失败', _context24.t0);
1692
+ return _context24.abrupt("return", null);
1493
1693
  case 11:
1494
1694
  case "end":
1495
- return _context19.stop();
1695
+ return _context24.stop();
1496
1696
  }
1497
- }, _callee19, this, [[0, 7]]);
1697
+ }, _callee24, this, [[0, 7]]);
1498
1698
  }));
1499
1699
  function getCashPaymentMethod() {
1500
1700
  return _getCashPaymentMethod.apply(this, arguments);
@@ -1508,29 +1708,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1508
1708
  }, {
1509
1709
  key: "getEftposPaymentMethod",
1510
1710
  value: (function () {
1511
- var _getEftposPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1711
+ var _getEftposPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1512
1712
  var payMethods;
1513
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1514
- while (1) switch (_context20.prev = _context20.next) {
1713
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1714
+ while (1) switch (_context25.prev = _context25.next) {
1515
1715
  case 0:
1516
- _context20.prev = 0;
1517
- _context20.next = 3;
1716
+ _context25.prev = 0;
1717
+ _context25.next = 3;
1518
1718
  return this.dbManager.getAll('pay_method');
1519
1719
  case 3:
1520
- payMethods = _context20.sent;
1521
- return _context20.abrupt("return", payMethods.find(function (method) {
1720
+ payMethods = _context25.sent;
1721
+ return _context25.abrupt("return", payMethods.find(function (method) {
1522
1722
  return method.code === PaymentMethodType.Eftpos;
1523
1723
  }) || null);
1524
1724
  case 7:
1525
- _context20.prev = 7;
1526
- _context20.t0 = _context20["catch"](0);
1527
- console.error('[PaymentModule] 获取Eftpos支付方式失败', _context20.t0);
1528
- return _context20.abrupt("return", null);
1725
+ _context25.prev = 7;
1726
+ _context25.t0 = _context25["catch"](0);
1727
+ console.error('[PaymentModule] 获取Eftpos支付方式失败', _context25.t0);
1728
+ return _context25.abrupt("return", null);
1529
1729
  case 11:
1530
1730
  case "end":
1531
- return _context20.stop();
1731
+ return _context25.stop();
1532
1732
  }
1533
- }, _callee20, this, [[0, 7]]);
1733
+ }, _callee25, this, [[0, 7]]);
1534
1734
  }));
1535
1735
  function getEftposPaymentMethod() {
1536
1736
  return _getEftposPaymentMethod.apply(this, arguments);
@@ -1544,29 +1744,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1544
1744
  }, {
1545
1745
  key: "getWalletPaymentMethod",
1546
1746
  value: (function () {
1547
- var _getWalletPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1747
+ var _getWalletPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
1548
1748
  var payMethods;
1549
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1550
- while (1) switch (_context21.prev = _context21.next) {
1749
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
1750
+ while (1) switch (_context26.prev = _context26.next) {
1551
1751
  case 0:
1552
- _context21.prev = 0;
1553
- _context21.next = 3;
1752
+ _context26.prev = 0;
1753
+ _context26.next = 3;
1554
1754
  return this.dbManager.getAll('pay_method');
1555
1755
  case 3:
1556
- payMethods = _context21.sent;
1557
- return _context21.abrupt("return", payMethods.find(function (method) {
1756
+ payMethods = _context26.sent;
1757
+ return _context26.abrupt("return", payMethods.find(function (method) {
1558
1758
  return method.code === PaymentMethodType.Wallet;
1559
1759
  }) || null);
1560
1760
  case 7:
1561
- _context21.prev = 7;
1562
- _context21.t0 = _context21["catch"](0);
1563
- console.error('[PaymentModule] 获取钱包支付方式失败', _context21.t0);
1564
- return _context21.abrupt("return", null);
1761
+ _context26.prev = 7;
1762
+ _context26.t0 = _context26["catch"](0);
1763
+ console.error('[PaymentModule] 获取钱包支付方式失败', _context26.t0);
1764
+ return _context26.abrupt("return", null);
1565
1765
  case 11:
1566
1766
  case "end":
1567
- return _context21.stop();
1767
+ return _context26.stop();
1568
1768
  }
1569
- }, _callee21, this, [[0, 7]]);
1769
+ }, _callee26, this, [[0, 7]]);
1570
1770
  }));
1571
1771
  function getWalletPaymentMethod() {
1572
1772
  return _getWalletPaymentMethod.apply(this, arguments);
@@ -1600,38 +1800,38 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1600
1800
  * 确保支付模块所需的数据库表已创建
1601
1801
  */
1602
1802
  function () {
1603
- var _ensurePaymentTables = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1604
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1605
- while (1) switch (_context22.prev = _context22.next) {
1803
+ var _ensurePaymentTables = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
1804
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
1805
+ while (1) switch (_context27.prev = _context27.next) {
1606
1806
  case 0:
1607
- _context22.prev = 0;
1608
- _context22.next = 3;
1807
+ _context27.prev = 0;
1808
+ _context27.next = 3;
1609
1809
  return this.dbManager.getAll('pay_method');
1610
1810
  case 3:
1611
- _context22.next = 9;
1811
+ _context27.next = 9;
1612
1812
  break;
1613
1813
  case 5:
1614
- _context22.prev = 5;
1615
- _context22.t0 = _context22["catch"](0);
1814
+ _context27.prev = 5;
1815
+ _context27.t0 = _context27["catch"](0);
1616
1816
  console.warn('[PaymentModule] pay_method 表不存在,请在数据库配置中添加以下配置:');
1617
1817
  console.warn('{ name: "pay_method", keyPath: "id" }');
1618
1818
  case 9:
1619
- _context22.prev = 9;
1620
- _context22.next = 12;
1819
+ _context27.prev = 9;
1820
+ _context27.next = 12;
1621
1821
  return this.dbManager.getAll('order');
1622
1822
  case 12:
1623
- _context22.next = 18;
1823
+ _context27.next = 18;
1624
1824
  break;
1625
1825
  case 14:
1626
- _context22.prev = 14;
1627
- _context22.t1 = _context22["catch"](9);
1826
+ _context27.prev = 14;
1827
+ _context27.t1 = _context27["catch"](9);
1628
1828
  console.warn('[PaymentModule] order 表不存在,请在数据库配置中添加以下配置:');
1629
1829
  console.warn('{ name: "order", keyPath: "uuid" }');
1630
1830
  case 18:
1631
1831
  case "end":
1632
- return _context22.stop();
1832
+ return _context27.stop();
1633
1833
  }
1634
- }, _callee22, this, [[0, 5], [9, 14]]);
1834
+ }, _callee27, this, [[0, 5], [9, 14]]);
1635
1835
  }));
1636
1836
  function ensurePaymentTables() {
1637
1837
  return _ensurePaymentTables.apply(this, arguments);
@@ -1645,29 +1845,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1645
1845
  }, {
1646
1846
  key: "getPartiallyPaidOrdersAsync",
1647
1847
  value: (function () {
1648
- var _getPartiallyPaidOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1848
+ var _getPartiallyPaidOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
1649
1849
  var allOrders;
1650
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1651
- while (1) switch (_context23.prev = _context23.next) {
1850
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
1851
+ while (1) switch (_context28.prev = _context28.next) {
1652
1852
  case 0:
1653
- _context23.prev = 0;
1654
- _context23.next = 3;
1853
+ _context28.prev = 0;
1854
+ _context28.next = 3;
1655
1855
  return this.dbManager.getAll('order');
1656
1856
  case 3:
1657
- allOrders = _context23.sent;
1658
- return _context23.abrupt("return", allOrders.filter(function (order) {
1857
+ allOrders = _context28.sent;
1858
+ return _context28.abrupt("return", allOrders.filter(function (order) {
1659
1859
  return order.payment_status === PaymentStatus.PartiallyPaid;
1660
1860
  }));
1661
1861
  case 7:
1662
- _context23.prev = 7;
1663
- _context23.t0 = _context23["catch"](0);
1664
- console.error('[PaymentModule] 获取部分支付订单失败', _context23.t0);
1665
- return _context23.abrupt("return", []);
1862
+ _context28.prev = 7;
1863
+ _context28.t0 = _context28["catch"](0);
1864
+ console.error('[PaymentModule] 获取部分支付订单失败', _context28.t0);
1865
+ return _context28.abrupt("return", []);
1666
1866
  case 11:
1667
1867
  case "end":
1668
- return _context23.stop();
1868
+ return _context28.stop();
1669
1869
  }
1670
- }, _callee23, this, [[0, 7]]);
1870
+ }, _callee28, this, [[0, 7]]);
1671
1871
  }));
1672
1872
  function getPartiallyPaidOrdersAsync() {
1673
1873
  return _getPartiallyPaidOrdersAsync.apply(this, arguments);
@@ -1681,32 +1881,32 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1681
1881
  }, {
1682
1882
  key: "getUnsyncedOrdersAsync",
1683
1883
  value: (function () {
1684
- var _getUnsyncedOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
1884
+ var _getUnsyncedOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
1685
1885
  var allOrders;
1686
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1687
- while (1) switch (_context24.prev = _context24.next) {
1886
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
1887
+ while (1) switch (_context29.prev = _context29.next) {
1688
1888
  case 0:
1689
- _context24.prev = 0;
1690
- _context24.next = 3;
1889
+ _context29.prev = 0;
1890
+ _context29.next = 3;
1691
1891
  return this.dbManager.getAll('order');
1692
1892
  case 3:
1693
- allOrders = _context24.sent;
1694
- return _context24.abrupt("return", allOrders.filter(function (order) {
1893
+ allOrders = _context29.sent;
1894
+ return _context29.abrupt("return", allOrders.filter(function (order) {
1695
1895
  // 订单已完成或部分支付,但支付项还未同步
1696
1896
  return (order.payment_status === PaymentStatus.Finished || order.payment_status === PaymentStatus.PartiallyPaid) && order.payment.some(function (payment) {
1697
1897
  return !payment.isSynced;
1698
1898
  });
1699
1899
  }));
1700
1900
  case 7:
1701
- _context24.prev = 7;
1702
- _context24.t0 = _context24["catch"](0);
1703
- console.error('[PaymentModule] 获取未同步订单失败', _context24.t0);
1704
- return _context24.abrupt("return", []);
1901
+ _context29.prev = 7;
1902
+ _context29.t0 = _context29["catch"](0);
1903
+ console.error('[PaymentModule] 获取未同步订单失败', _context29.t0);
1904
+ return _context29.abrupt("return", []);
1705
1905
  case 11:
1706
1906
  case "end":
1707
- return _context24.stop();
1907
+ return _context29.stop();
1708
1908
  }
1709
- }, _callee24, this, [[0, 7]]);
1909
+ }, _callee29, this, [[0, 7]]);
1710
1910
  }));
1711
1911
  function getUnsyncedOrdersAsync() {
1712
1912
  return _getUnsyncedOrdersAsync.apply(this, arguments);
@@ -1721,59 +1921,59 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1721
1921
  }, {
1722
1922
  key: "cleanupFinishedOrders",
1723
1923
  value: (function () {
1724
- var _cleanupFinishedOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1924
+ var _cleanupFinishedOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
1725
1925
  var allOrders, finishedAndSyncedOrders, _iterator6, _step6, order;
1726
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1727
- while (1) switch (_context25.prev = _context25.next) {
1926
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
1927
+ while (1) switch (_context30.prev = _context30.next) {
1728
1928
  case 0:
1729
- _context25.prev = 0;
1730
- _context25.next = 3;
1929
+ _context30.prev = 0;
1930
+ _context30.next = 3;
1731
1931
  return this.dbManager.getAll('order');
1732
1932
  case 3:
1733
- allOrders = _context25.sent;
1933
+ allOrders = _context30.sent;
1734
1934
  finishedAndSyncedOrders = allOrders.filter(function (order) {
1735
1935
  return order.payment_status === PaymentStatus.Finished && order.payment.every(function (payment) {
1736
1936
  return payment.isSynced;
1737
1937
  });
1738
1938
  });
1739
1939
  _iterator6 = _createForOfIteratorHelper(finishedAndSyncedOrders);
1740
- _context25.prev = 6;
1940
+ _context30.prev = 6;
1741
1941
  _iterator6.s();
1742
1942
  case 8:
1743
1943
  if ((_step6 = _iterator6.n()).done) {
1744
- _context25.next = 14;
1944
+ _context30.next = 14;
1745
1945
  break;
1746
1946
  }
1747
1947
  order = _step6.value;
1748
- _context25.next = 12;
1948
+ _context30.next = 12;
1749
1949
  return this.deleteOrderAsync(order.uuid);
1750
1950
  case 12:
1751
- _context25.next = 8;
1951
+ _context30.next = 8;
1752
1952
  break;
1753
1953
  case 14:
1754
- _context25.next = 19;
1954
+ _context30.next = 19;
1755
1955
  break;
1756
1956
  case 16:
1757
- _context25.prev = 16;
1758
- _context25.t0 = _context25["catch"](6);
1759
- _iterator6.e(_context25.t0);
1957
+ _context30.prev = 16;
1958
+ _context30.t0 = _context30["catch"](6);
1959
+ _iterator6.e(_context30.t0);
1760
1960
  case 19:
1761
- _context25.prev = 19;
1961
+ _context30.prev = 19;
1762
1962
  _iterator6.f();
1763
- return _context25.finish(19);
1963
+ return _context30.finish(19);
1764
1964
  case 22:
1765
1965
  console.log("[PaymentModule] \u6E05\u7406\u4E86 ".concat(finishedAndSyncedOrders.length, " \u4E2A\u5DF2\u5B8C\u6210\u4E14\u5DF2\u540C\u6B65\u7684\u8BA2\u5355"));
1766
- _context25.next = 28;
1966
+ _context30.next = 28;
1767
1967
  break;
1768
1968
  case 25:
1769
- _context25.prev = 25;
1770
- _context25.t1 = _context25["catch"](0);
1771
- console.error('[PaymentModule] 清理已完成订单失败', _context25.t1);
1969
+ _context30.prev = 25;
1970
+ _context30.t1 = _context30["catch"](0);
1971
+ console.error('[PaymentModule] 清理已完成订单失败', _context30.t1);
1772
1972
  case 28:
1773
1973
  case "end":
1774
- return _context25.stop();
1974
+ return _context30.stop();
1775
1975
  }
1776
- }, _callee25, this, [[0, 25], [6, 16, 19, 22]]);
1976
+ }, _callee30, this, [[0, 25], [6, 16, 19, 22]]);
1777
1977
  }));
1778
1978
  function cleanupFinishedOrders() {
1779
1979
  return _cleanupFinishedOrders.apply(this, arguments);
@@ -1798,32 +1998,32 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1798
1998
  }, {
1799
1999
  key: "recheckAndRequeueUnsyncedOrders",
1800
2000
  value: (function () {
1801
- var _recheckAndRequeueUnsyncedOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
2001
+ var _recheckAndRequeueUnsyncedOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
1802
2002
  var unsyncedOrders, requeuedCount, _iterator7, _step7, order, success;
1803
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
1804
- while (1) switch (_context26.prev = _context26.next) {
2003
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2004
+ while (1) switch (_context31.prev = _context31.next) {
1805
2005
  case 0:
1806
2006
  this.logInfo('Starting recheckAndRequeueUnsyncedOrders');
1807
- _context26.prev = 1;
2007
+ _context31.prev = 1;
1808
2008
  if (this.app.tasksManager) {
1809
- _context26.next = 6;
2009
+ _context31.next = 6;
1810
2010
  break;
1811
2011
  }
1812
2012
  console.warn('[PaymentModule] TasksManager 未初始化,无法重新排队未同步订单');
1813
2013
  this.logWarning('TasksManager not initialized, cannot requeue unsynced orders');
1814
- return _context26.abrupt("return", 0);
2014
+ return _context31.abrupt("return", 0);
1815
2015
  case 6:
1816
- _context26.next = 8;
2016
+ _context31.next = 8;
1817
2017
  return this.getUnsyncedOrdersAsync();
1818
2018
  case 8:
1819
- unsyncedOrders = _context26.sent;
2019
+ unsyncedOrders = _context31.sent;
1820
2020
  if (!(unsyncedOrders.length === 0)) {
1821
- _context26.next = 13;
2021
+ _context31.next = 13;
1822
2022
  break;
1823
2023
  }
1824
2024
  console.log('[PaymentModule] 没有发现未同步的订单');
1825
2025
  this.logInfo('No unsynced orders found');
1826
- return _context26.abrupt("return", 0);
2026
+ return _context31.abrupt("return", 0);
1827
2027
  case 13:
1828
2028
  console.log("[PaymentModule] \u53D1\u73B0 ".concat(unsyncedOrders.length, " \u4E2A\u672A\u540C\u6B65\u7684\u8BA2\u5355\uFF0C\u5F00\u59CB\u91CD\u65B0\u52A0\u5165\u4EFB\u52A1\u961F\u5217"));
1829
2029
  this.logInfo('Found unsynced orders, adding to sync queue', {
@@ -1834,53 +2034,53 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1834
2034
  });
1835
2035
  requeuedCount = 0; // 将未同步的订单重新添加到任务队列
1836
2036
  _iterator7 = _createForOfIteratorHelper(unsyncedOrders);
1837
- _context26.prev = 17;
2037
+ _context31.prev = 17;
1838
2038
  _iterator7.s();
1839
2039
  case 19:
1840
2040
  if ((_step7 = _iterator7.n()).done) {
1841
- _context26.next = 27;
2041
+ _context31.next = 27;
1842
2042
  break;
1843
2043
  }
1844
2044
  order = _step7.value;
1845
- _context26.next = 23;
2045
+ _context31.next = 23;
1846
2046
  return this.reAddOrderToSyncQueue(order);
1847
2047
  case 23:
1848
- success = _context26.sent;
2048
+ success = _context31.sent;
1849
2049
  if (success) {
1850
2050
  requeuedCount++;
1851
2051
  }
1852
2052
  case 25:
1853
- _context26.next = 19;
2053
+ _context31.next = 19;
1854
2054
  break;
1855
2055
  case 27:
1856
- _context26.next = 32;
2056
+ _context31.next = 32;
1857
2057
  break;
1858
2058
  case 29:
1859
- _context26.prev = 29;
1860
- _context26.t0 = _context26["catch"](17);
1861
- _iterator7.e(_context26.t0);
2059
+ _context31.prev = 29;
2060
+ _context31.t0 = _context31["catch"](17);
2061
+ _iterator7.e(_context31.t0);
1862
2062
  case 32:
1863
- _context26.prev = 32;
2063
+ _context31.prev = 32;
1864
2064
  _iterator7.f();
1865
- return _context26.finish(32);
2065
+ return _context31.finish(32);
1866
2066
  case 35:
1867
2067
  console.log("[PaymentModule] \u6210\u529F\u91CD\u65B0\u52A0\u5165 ".concat(requeuedCount, " \u4E2A\u8BA2\u5355\u5230\u4EFB\u52A1\u961F\u5217"));
1868
2068
  this.logInfo('Successfully requeued unsynced orders', {
1869
2069
  requeuedCount: requeuedCount,
1870
2070
  totalFound: unsyncedOrders.length
1871
2071
  });
1872
- return _context26.abrupt("return", requeuedCount);
2072
+ return _context31.abrupt("return", requeuedCount);
1873
2073
  case 40:
1874
- _context26.prev = 40;
1875
- _context26.t1 = _context26["catch"](1);
1876
- console.error('[PaymentModule] 重新排队未同步订单失败', _context26.t1);
1877
- this.logError('recheckAndRequeueUnsyncedOrders failed', _context26.t1);
1878
- return _context26.abrupt("return", 0);
2074
+ _context31.prev = 40;
2075
+ _context31.t1 = _context31["catch"](1);
2076
+ console.error('[PaymentModule] 重新排队未同步订单失败', _context31.t1);
2077
+ this.logError('recheckAndRequeueUnsyncedOrders failed', _context31.t1);
2078
+ return _context31.abrupt("return", 0);
1879
2079
  case 45:
1880
2080
  case "end":
1881
- return _context26.stop();
2081
+ return _context31.stop();
1882
2082
  }
1883
- }, _callee26, this, [[1, 40], [17, 29, 32, 35]]);
2083
+ }, _callee31, this, [[1, 40], [17, 29, 32, 35]]);
1884
2084
  }));
1885
2085
  function recheckAndRequeueUnsyncedOrders() {
1886
2086
  return _recheckAndRequeueUnsyncedOrders.apply(this, arguments);
@@ -1910,21 +2110,21 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1910
2110
  }, {
1911
2111
  key: "runPaymentSyncQueue",
1912
2112
  value: (function () {
1913
- var _runPaymentSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
2113
+ var _runPaymentSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
1914
2114
  var _this3 = this;
1915
2115
  var queue;
1916
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
1917
- while (1) switch (_context27.prev = _context27.next) {
2116
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2117
+ while (1) switch (_context32.prev = _context32.next) {
1918
2118
  case 0:
1919
2119
  this.logInfo('Starting runPaymentSyncQueue');
1920
- _context27.prev = 1;
2120
+ _context32.prev = 1;
1921
2121
  if (this.app.tasksManager) {
1922
- _context27.next = 6;
2122
+ _context32.next = 6;
1923
2123
  break;
1924
2124
  }
1925
2125
  console.warn('[PaymentModule] TasksManager 未初始化,无法执行同步队列');
1926
2126
  this.logWarning('TasksManager not initialized, cannot run sync queue');
1927
- return _context27.abrupt("return");
2127
+ return _context32.abrupt("return");
1928
2128
  case 6:
1929
2129
  // 检查队列里有没有要跑的东西,没有就不 run 了
1930
2130
  queue = this.app.tasksManager.getTaskQueue({
@@ -1932,14 +2132,14 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1932
2132
  queueId: 'payment_sync'
1933
2133
  });
1934
2134
  if (queue !== null && queue !== void 0 && queue.length) {
1935
- _context27.next = 10;
2135
+ _context32.next = 10;
1936
2136
  break;
1937
2137
  }
1938
2138
  console.log('[PaymentModule] 支付同步队列无内容,不执行');
1939
- return _context27.abrupt("return");
2139
+ return _context32.abrupt("return");
1940
2140
  case 10:
1941
2141
  console.log('[PaymentModule] 开始执行支付同步队列');
1942
- _context27.next = 13;
2142
+ _context32.next = 13;
1943
2143
  return this.app.tasksManager.run({
1944
2144
  module: 'payment',
1945
2145
  queueId: 'payment_sync',
@@ -1956,19 +2156,19 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1956
2156
  });
1957
2157
  case 13:
1958
2158
  this.logInfo('runPaymentSyncQueue completed successfully');
1959
- _context27.next = 20;
2159
+ _context32.next = 20;
1960
2160
  break;
1961
2161
  case 16:
1962
- _context27.prev = 16;
1963
- _context27.t0 = _context27["catch"](1);
1964
- console.error('[PaymentModule] 执行支付同步队列失败', _context27.t0);
1965
- this.logError('runPaymentSyncQueue failed', _context27.t0);
2162
+ _context32.prev = 16;
2163
+ _context32.t0 = _context32["catch"](1);
2164
+ console.error('[PaymentModule] 执行支付同步队列失败', _context32.t0);
2165
+ this.logError('runPaymentSyncQueue failed', _context32.t0);
1966
2166
  // 不抛出错误,避免影响主流程
1967
2167
  case 20:
1968
2168
  case "end":
1969
- return _context27.stop();
2169
+ return _context32.stop();
1970
2170
  }
1971
- }, _callee27, this, [[1, 16]]);
2171
+ }, _callee32, this, [[1, 16]]);
1972
2172
  }));
1973
2173
  function runPaymentSyncQueue() {
1974
2174
  return _runPaymentSyncQueue.apply(this, arguments);
@@ -1986,12 +2186,12 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1986
2186
  }, {
1987
2187
  key: "reAddOrderToSyncQueue",
1988
2188
  value: (function () {
1989
- var _reAddOrderToSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(order) {
2189
+ var _reAddOrderToSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(order) {
1990
2190
  var paymentData, existingQueue, taskId, taskExists;
1991
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
1992
- while (1) switch (_context28.prev = _context28.next) {
2191
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2192
+ while (1) switch (_context33.prev = _context33.next) {
1993
2193
  case 0:
1994
- _context28.prev = 0;
2194
+ _context33.prev = 0;
1995
2195
  // 构造支付数据
1996
2196
  paymentData = {
1997
2197
  payments: order.payment.map(function (payment) {
@@ -2019,52 +2219,171 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2019
2219
  return task.id === taskId;
2020
2220
  });
2021
2221
  if (!taskExists) {
2022
- _context28.next = 8;
2222
+ _context33.next = 8;
2023
2223
  break;
2024
2224
  }
2025
2225
  console.log("[PaymentModule] \u4EFB\u52A1 ".concat(taskId, " \u5DF2\u5B58\u5728\u4E8E\u961F\u5217\u4E2D\uFF0C\u8DF3\u8FC7\u91CD\u590D\u6DFB\u52A0"));
2026
- return _context28.abrupt("return", false);
2226
+ return _context33.abrupt("return", false);
2027
2227
  case 8:
2028
- _context28.next = 10;
2228
+ _context33.next = 10;
2029
2229
  return this.addToSyncQueue(order, paymentData);
2030
2230
  case 10:
2031
2231
  console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u5DF2\u91CD\u65B0\u6DFB\u52A0\u5230\u540C\u6B65\u961F\u5217"));
2032
2232
  this.logInfo('Order re-added to sync queue', {
2033
2233
  orderUuid: order.uuid,
2034
- orderId: order.order_info.order_id,
2234
+ orderId: order.order_id,
2035
2235
  paymentStatus: order.payment_status,
2036
2236
  unsyncedPayments: order.payment.filter(function (p) {
2037
2237
  return !p.isSynced;
2038
2238
  }).length
2039
2239
  });
2040
- return _context28.abrupt("return", true);
2240
+ return _context33.abrupt("return", true);
2041
2241
  case 15:
2042
- _context28.prev = 15;
2043
- _context28.t0 = _context28["catch"](0);
2044
- console.error("[PaymentModule] \u91CD\u65B0\u6DFB\u52A0\u8BA2\u5355 ".concat(order.uuid, " \u5230\u540C\u6B65\u961F\u5217\u5931\u8D25"), _context28.t0);
2045
- this.logError('Failed to re-add order to sync queue', _context28.t0, {
2242
+ _context33.prev = 15;
2243
+ _context33.t0 = _context33["catch"](0);
2244
+ console.error("[PaymentModule] \u91CD\u65B0\u6DFB\u52A0\u8BA2\u5355 ".concat(order.uuid, " \u5230\u540C\u6B65\u961F\u5217\u5931\u8D25"), _context33.t0);
2245
+ this.logError('Failed to re-add order to sync queue', _context33.t0, {
2046
2246
  orderUuid: order.uuid,
2047
- orderId: order.order_info.order_id
2247
+ orderId: order.order_id
2048
2248
  });
2049
- return _context28.abrupt("return", false);
2249
+ return _context33.abrupt("return", false);
2050
2250
  case 20:
2051
2251
  case "end":
2052
- return _context28.stop();
2252
+ return _context33.stop();
2053
2253
  }
2054
- }, _callee28, this, [[0, 15]]);
2254
+ }, _callee33, this, [[0, 15]]);
2055
2255
  }));
2056
- function reAddOrderToSyncQueue(_x25) {
2256
+ function reAddOrderToSyncQueue(_x32) {
2057
2257
  return _reAddOrderToSyncQueue.apply(this, arguments);
2058
2258
  }
2059
2259
  return reAddOrderToSyncQueue;
2260
+ }() // === 新的 API 方法实现 ===
2261
+ /**
2262
+ * 删除支付项(新方法)
2263
+ */
2264
+ )
2265
+ }, {
2266
+ key: "deletePaymentItemAsync",
2267
+ value: function () {
2268
+ var _deletePaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(orderUuid, paymentUuid) {
2269
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2270
+ while (1) switch (_context34.prev = _context34.next) {
2271
+ case 0:
2272
+ console.warn('[PaymentModule] deletePaymentItemAsync 暂时使用 deletePaymentAsync 实现');
2273
+ return _context34.abrupt("return", this.deletePaymentAsync(orderUuid, paymentUuid));
2274
+ case 2:
2275
+ case "end":
2276
+ return _context34.stop();
2277
+ }
2278
+ }, _callee34, this);
2279
+ }));
2280
+ function deletePaymentItemAsync(_x33, _x34) {
2281
+ return _deletePaymentItemAsync.apply(this, arguments);
2282
+ }
2283
+ return deletePaymentItemAsync;
2284
+ }()
2285
+ /**
2286
+ * 更新支付项(新方法)
2287
+ */
2288
+ }, {
2289
+ key: "updatePaymentItemAsync",
2290
+ value: (function () {
2291
+ var _updatePaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(orderUuid, paymentUuid, params) {
2292
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2293
+ while (1) switch (_context35.prev = _context35.next) {
2294
+ case 0:
2295
+ console.warn('[PaymentModule] updatePaymentItemAsync 暂时使用 updatePaymentAsync 实现');
2296
+ return _context35.abrupt("return", this.updatePaymentAsync(orderUuid, paymentUuid, params));
2297
+ case 2:
2298
+ case "end":
2299
+ return _context35.stop();
2300
+ }
2301
+ }, _callee35, this);
2302
+ }));
2303
+ function updatePaymentItemAsync(_x35, _x36, _x37) {
2304
+ return _updatePaymentItemAsync.apply(this, arguments);
2305
+ }
2306
+ return updatePaymentItemAsync;
2307
+ }()
2308
+ /**
2309
+ * 获取订单剩余待付金额(新方法)
2310
+ */
2311
+ )
2312
+ }, {
2313
+ key: "getRemainingAmountAsync",
2314
+ value: (function () {
2315
+ var _getRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(orderUuid) {
2316
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
2317
+ while (1) switch (_context36.prev = _context36.next) {
2318
+ case 0:
2319
+ console.warn('[PaymentModule] getRemainingAmountAsync 暂时使用 getRemainingOrderAmountAsync 实现');
2320
+ return _context36.abrupt("return", this.getRemainingOrderAmountAsync(orderUuid));
2321
+ case 2:
2322
+ case "end":
2323
+ return _context36.stop();
2324
+ }
2325
+ }, _callee36, this);
2326
+ }));
2327
+ function getRemainingAmountAsync(_x38) {
2328
+ return _getRemainingAmountAsync.apply(this, arguments);
2329
+ }
2330
+ return getRemainingAmountAsync;
2331
+ }()
2332
+ /**
2333
+ * 获取订单剩余待付金额(基于用户输入的金额)(新方法)
2334
+ */
2335
+ )
2336
+ }, {
2337
+ key: "getRemainingAmountWithInputAsync",
2338
+ value: (function () {
2339
+ var _getRemainingAmountWithInputAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(inputAmount, orderUuid) {
2340
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
2341
+ while (1) switch (_context37.prev = _context37.next) {
2342
+ case 0:
2343
+ console.warn('[PaymentModule] getRemainingAmountWithInputAsync 暂时使用 getRemainingOrderAmountWithInputAsync 实现');
2344
+ return _context37.abrupt("return", this.getRemainingOrderAmountWithInputAsync(inputAmount, orderUuid));
2345
+ case 2:
2346
+ case "end":
2347
+ return _context37.stop();
2348
+ }
2349
+ }, _callee37, this);
2350
+ }));
2351
+ function getRemainingAmountWithInputAsync(_x39, _x40) {
2352
+ return _getRemainingAmountWithInputAsync.apply(this, arguments);
2353
+ }
2354
+ return getRemainingAmountWithInputAsync;
2355
+ }()
2356
+ /**
2357
+ * 提交支付(新方法)
2358
+ */
2359
+ )
2360
+ }, {
2361
+ key: "submitPaymentAsync",
2362
+ value: (function () {
2363
+ var _submitPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(orderUuid) {
2364
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
2365
+ while (1) switch (_context38.prev = _context38.next) {
2366
+ case 0:
2367
+ console.warn('[PaymentModule] submitPaymentAsync 暂时使用 submitPayAsync 实现');
2368
+ return _context38.abrupt("return", this.submitPayAsync(orderUuid));
2369
+ case 2:
2370
+ case "end":
2371
+ return _context38.stop();
2372
+ }
2373
+ }, _callee38, this);
2374
+ }));
2375
+ function submitPaymentAsync(_x41) {
2376
+ return _submitPaymentAsync.apply(this, arguments);
2377
+ }
2378
+ return submitPaymentAsync;
2060
2379
  }())
2061
2380
  }], [{
2062
2381
  key: "syncPaymentTask",
2063
2382
  value: (function () {
2064
- var _syncPaymentTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(payload) {
2383
+ var _syncPaymentTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(payload) {
2065
2384
  var _payload$task$payload, orderUuid, orderId, paymentData, core, app, logger, request, dbManager, requestRes, order, businessError, _error$message, _error$message2, _error$message3, isNetworkError, _error$response3, _error$response, errorData, _error$response2, _order2;
2066
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2067
- while (1) switch (_context29.prev = _context29.next) {
2385
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
2386
+ while (1) switch (_context39.prev = _context39.next) {
2068
2387
  case 0:
2069
2388
  _payload$task$payload = payload.task.payload, orderUuid = _payload$task$payload.orderUuid, orderId = _payload$task$payload.orderId, paymentData = _payload$task$payload.paymentData, core = _payload$task$payload.core;
2070
2389
  console.log("[PaymentModule] \u5F00\u59CB\u540E\u53F0\u540C\u6B65\u652F\u4ED8\uFF0C\u8BA2\u5355ID: ".concat(orderId));
@@ -2087,42 +2406,42 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2087
2406
  });
2088
2407
  }
2089
2408
  if (app) {
2090
- _context29.next = 8;
2409
+ _context39.next = 8;
2091
2410
  break;
2092
2411
  }
2093
2412
  throw new Error('App 实例未找到');
2094
2413
  case 8:
2095
2414
  request = app.request;
2096
2415
  if (request) {
2097
- _context29.next = 11;
2416
+ _context39.next = 11;
2098
2417
  break;
2099
2418
  }
2100
2419
  throw new Error('Request 插件未找到');
2101
2420
  case 11:
2102
2421
  dbManager = app.dbManager;
2103
2422
  if (dbManager) {
2104
- _context29.next = 14;
2423
+ _context39.next = 14;
2105
2424
  break;
2106
2425
  }
2107
2426
  throw new Error('DBManager 未找到');
2108
2427
  case 14:
2109
- _context29.prev = 14;
2110
- _context29.next = 17;
2428
+ _context39.prev = 14;
2429
+ _context39.next = 17;
2111
2430
  return request.post("/shop/order/".concat(orderId, "/order-payment"), paymentData, {
2112
2431
  noToast: true
2113
2432
  });
2114
2433
  case 17:
2115
- requestRes = _context29.sent;
2434
+ requestRes = _context39.sent;
2116
2435
  if (!(requestRes.status === true)) {
2117
- _context29.next = 35;
2436
+ _context39.next = 35;
2118
2437
  break;
2119
2438
  }
2120
- _context29.next = 21;
2439
+ _context39.next = 21;
2121
2440
  return dbManager.get('order', orderUuid);
2122
2441
  case 21:
2123
- order = _context29.sent;
2442
+ order = _context39.sent;
2124
2443
  if (!order) {
2125
- _context29.next = 27;
2444
+ _context39.next = 27;
2126
2445
  break;
2127
2446
  }
2128
2447
  order.payment.forEach(function (payment) {
@@ -2130,13 +2449,13 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2130
2449
  // 清除之前的错误状态
2131
2450
  delete payment.syncError;
2132
2451
  });
2133
- _context29.next = 26;
2452
+ _context39.next = 26;
2134
2453
  return dbManager.update('order', order);
2135
2454
  case 26:
2136
2455
  console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u72B6\u6001\u5DF2\u66F4\u65B0"));
2137
2456
  case 27:
2138
2457
  console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u540E\u53F0\u540C\u6B65\u6210\u529F"));
2139
- _context29.next = 30;
2458
+ _context39.next = 30;
2140
2459
  return core.effects.emit('payment:onPaymentSyncSuccess', {
2141
2460
  orderUuid: orderUuid,
2142
2461
  orderId: orderId,
@@ -2156,7 +2475,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2156
2475
  }
2157
2476
  });
2158
2477
  }
2159
- return _context29.abrupt("return", {
2478
+ return _context39.abrupt("return", {
2160
2479
  status: 'success',
2161
2480
  orderUuid: orderUuid,
2162
2481
  orderId: orderId
@@ -2174,17 +2493,17 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2174
2493
  businessError.responseData = requestRes;
2175
2494
  throw businessError;
2176
2495
  case 41:
2177
- _context29.next = 80;
2496
+ _context39.next = 80;
2178
2497
  break;
2179
2498
  case 43:
2180
- _context29.prev = 43;
2181
- _context29.t0 = _context29["catch"](14);
2182
- console.error('[PaymentModule] 后台同步失败:', _context29.t0);
2499
+ _context39.prev = 43;
2500
+ _context39.t0 = _context39["catch"](14);
2501
+ console.error('[PaymentModule] 后台同步失败:', _context39.t0);
2183
2502
 
2184
2503
  // 检查是否是网络错误(没有响应码)还是业务错误(有响应码)
2185
- isNetworkError = !_context29.t0.response && !_context29.t0.status && (_context29.t0.code === 'NETWORK_ERROR' || _context29.t0.code === 'ERR_NETWORK' || _context29.t0.code === 'ECONNREFUSED' || _context29.t0.code === 'ENOTFOUND' || _context29.t0.code === 'ETIMEDOUT' || ((_error$message = _context29.t0.message) === null || _error$message === void 0 ? void 0 : _error$message.includes('网络')) || ((_error$message2 = _context29.t0.message) === null || _error$message2 === void 0 ? void 0 : _error$message2.includes('network')) || ((_error$message3 = _context29.t0.message) === null || _error$message3 === void 0 ? void 0 : _error$message3.includes('fetch')));
2504
+ isNetworkError = !_context39.t0.response && !_context39.t0.status && (_context39.t0.code === 'NETWORK_ERROR' || _context39.t0.code === 'ERR_NETWORK' || _context39.t0.code === 'ECONNREFUSED' || _context39.t0.code === 'ENOTFOUND' || _context39.t0.code === 'ETIMEDOUT' || ((_error$message = _context39.t0.message) === null || _error$message === void 0 ? void 0 : _error$message.includes('网络')) || ((_error$message2 = _context39.t0.message) === null || _error$message2 === void 0 ? void 0 : _error$message2.includes('network')) || ((_error$message3 = _context39.t0.message) === null || _error$message3 === void 0 ? void 0 : _error$message3.includes('fetch')));
2186
2505
  if (!isNetworkError) {
2187
- _context29.next = 53;
2506
+ _context39.next = 53;
2188
2507
  break;
2189
2508
  }
2190
2509
  // 网络错误:重试
@@ -2198,39 +2517,39 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2198
2517
  metadata: {
2199
2518
  orderUuid: orderUuid,
2200
2519
  orderId: orderId,
2201
- errorCode: _context29.t0.code,
2202
- errorMessage: _context29.t0.message
2520
+ errorCode: _context39.t0.code,
2521
+ errorMessage: _context39.t0.message
2203
2522
  }
2204
2523
  });
2205
2524
  }
2206
- throw _context29.t0;
2525
+ throw _context39.t0;
2207
2526
  case 53:
2208
2527
  // 业务错误(有响应码):不标记为已同步,通过 effects 通知前端,但不重试
2209
2528
  console.log("[PaymentModule] \u4E1A\u52A1\u9519\u8BEF\uFF0C\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u5931\u8D25\uFF0C\u901A\u77E5\u524D\u7AEF"));
2210
- _context29.prev = 54;
2529
+ _context39.prev = 54;
2211
2530
  if (!(core && core.effects)) {
2212
- _context29.next = 63;
2531
+ _context39.next = 63;
2213
2532
  break;
2214
2533
  }
2215
2534
  // 通过 effects 通知前端同步错误
2216
2535
  errorData = {
2217
2536
  orderUuid: orderUuid,
2218
2537
  orderId: orderId,
2219
- error: _context29.t0.message || '业务错误',
2220
- errorCode: _context29.t0.code,
2221
- statusCode: ((_error$response = _context29.t0.response) === null || _error$response === void 0 ? void 0 : _error$response.status) || _context29.t0.status,
2538
+ error: _context39.t0.message || '业务错误',
2539
+ errorCode: _context39.t0.code,
2540
+ statusCode: ((_error$response = _context39.t0.response) === null || _error$response === void 0 ? void 0 : _error$response.status) || _context39.t0.status,
2222
2541
  timestamp: Date.now()
2223
2542
  }; // 如果是业务错误,添加响应数据
2224
- if (_context29.t0.isBusinessError && _context29.t0.responseData) {
2225
- errorData.error = _context29.t0.responseData.message || _context29.t0.message || '接口返回失败';
2543
+ if (_context39.t0.isBusinessError && _context39.t0.responseData) {
2544
+ errorData.error = _context39.t0.responseData.message || _context39.t0.message || '接口返回失败';
2226
2545
  // 可以添加更多响应数据
2227
- errorData.responseData = _context29.t0.responseData;
2546
+ errorData.responseData = _context39.t0.responseData;
2228
2547
  }
2229
- _context29.next = 60;
2548
+ _context39.next = 60;
2230
2549
  return core.effects.emit('payment:onPaymentSyncError', errorData);
2231
2550
  case 60:
2232
2551
  console.log("[PaymentModule] \u5DF2\u901A\u8FC7 effects \u901A\u77E5\u524D\u7AEF\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u9519\u8BEF"));
2233
- _context29.next = 64;
2552
+ _context39.next = 64;
2234
2553
  break;
2235
2554
  case 63:
2236
2555
  console.warn("[PaymentModule] \u65E0\u6CD5\u83B7\u53D6 core \u5B9E\u4F8B\uFF0C\u65E0\u6CD5\u901A\u77E5\u524D\u7AEF\u9519\u8BEF");
@@ -2243,19 +2562,19 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2243
2562
  metadata: {
2244
2563
  orderUuid: orderUuid,
2245
2564
  orderId: orderId,
2246
- errorCode: _context29.t0.code,
2247
- errorMessage: _context29.t0.message,
2248
- statusCode: ((_error$response2 = _context29.t0.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.status) || _context29.t0.status,
2249
- isBusinessError: _context29.t0.isBusinessError
2565
+ errorCode: _context39.t0.code,
2566
+ errorMessage: _context39.t0.message,
2567
+ statusCode: ((_error$response2 = _context39.t0.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.status) || _context39.t0.status,
2568
+ isBusinessError: _context39.t0.isBusinessError
2250
2569
  }
2251
2570
  });
2252
2571
  }
2253
- _context29.next = 71;
2572
+ _context39.next = 71;
2254
2573
  break;
2255
2574
  case 67:
2256
- _context29.prev = 67;
2257
- _context29.t1 = _context29["catch"](54);
2258
- console.error("[PaymentModule] \u901A\u77E5\u524D\u7AEF\u540C\u6B65\u9519\u8BEF\u5931\u8D25:", _context29.t1);
2575
+ _context39.prev = 67;
2576
+ _context39.t1 = _context39["catch"](54);
2577
+ console.error("[PaymentModule] \u901A\u77E5\u524D\u7AEF\u540C\u6B65\u9519\u8BEF\u5931\u8D25:", _context39.t1);
2259
2578
 
2260
2579
  // 记录通知错误日志
2261
2580
  if (logger) {
@@ -2265,41 +2584,41 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
2265
2584
  metadata: {
2266
2585
  orderUuid: orderUuid,
2267
2586
  orderId: orderId,
2268
- notifyError: _context29.t1 instanceof Error ? _context29.t1.message : String(_context29.t1)
2587
+ notifyError: _context39.t1 instanceof Error ? _context39.t1.message : String(_context39.t1)
2269
2588
  }
2270
2589
  });
2271
2590
  }
2272
2591
  case 71:
2273
- _context29.next = 73;
2592
+ _context39.next = 73;
2274
2593
  return dbManager.get('order', orderUuid);
2275
2594
  case 73:
2276
- _order2 = _context29.sent;
2595
+ _order2 = _context39.sent;
2277
2596
  if (!_order2) {
2278
- _context29.next = 79;
2597
+ _context39.next = 79;
2279
2598
  break;
2280
2599
  }
2281
2600
  _order2.payment.forEach(function (payment) {
2282
2601
  payment.isSynced = true;
2283
2602
  });
2284
- _context29.next = 78;
2603
+ _context39.next = 78;
2285
2604
  return dbManager.update('order', _order2);
2286
2605
  case 78:
2287
2606
  console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u4E1A\u52A1\u9519\u8BEF\uFF0C\u5DF2\u6807\u8BB0\u4E3A\u5DF2\u540C\u6B65"));
2288
2607
  case 79:
2289
- return _context29.abrupt("return", {
2608
+ return _context39.abrupt("return", {
2290
2609
  status: 'completed_with_error',
2291
2610
  orderUuid: orderUuid,
2292
2611
  orderId: orderId,
2293
- error: _context29.t0.message || '业务错误',
2294
- statusCode: ((_error$response3 = _context29.t0.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.status) || _context29.t0.status
2612
+ error: _context39.t0.message || '业务错误',
2613
+ statusCode: ((_error$response3 = _context39.t0.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.status) || _context39.t0.status
2295
2614
  });
2296
2615
  case 80:
2297
2616
  case "end":
2298
- return _context29.stop();
2617
+ return _context39.stop();
2299
2618
  }
2300
- }, _callee29, null, [[14, 43], [54, 67]]);
2619
+ }, _callee39, null, [[14, 43], [54, 67]]);
2301
2620
  }));
2302
- function syncPaymentTask(_x26) {
2621
+ function syncPaymentTask(_x42) {
2303
2622
  return _syncPaymentTask.apply(this, arguments);
2304
2623
  }
2305
2624
  return syncPaymentTask;