@pisell/pisellos 0.0.229 → 0.0.231

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 (65) hide show
  1. package/dist/modules/Order/index.d.ts +13 -2
  2. package/dist/modules/Order/index.js +84 -1
  3. package/dist/modules/Order/types.d.ts +43 -0
  4. package/dist/modules/Order/types.js +8 -0
  5. package/dist/modules/Payment/cash.d.ts +8 -0
  6. package/dist/modules/Payment/cash.js +20 -1
  7. package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  8. package/dist/modules/Payment/cashRecommendationAlgorithm.js +423 -0
  9. package/dist/modules/Payment/eftpos.js +1 -1
  10. package/dist/modules/Payment/index.d.ts +57 -94
  11. package/dist/modules/Payment/index.js +810 -1109
  12. package/dist/modules/Payment/mx51.d.ts +0 -0
  13. package/dist/modules/Payment/mx51.js +0 -0
  14. package/dist/modules/Payment/types.d.ts +358 -50
  15. package/dist/modules/Payment/types.js +103 -4
  16. package/dist/modules/Payment/utils.d.ts +17 -0
  17. package/dist/modules/Payment/utils.js +62 -0
  18. package/dist/modules/Payment/walletpass.d.ts +96 -0
  19. package/dist/modules/Payment/walletpass.js +492 -0
  20. package/dist/modules/Schedule/index.d.ts +9 -0
  21. package/dist/modules/Schedule/index.js +60 -0
  22. package/dist/solution/BookingTicket/index.d.ts +1 -1
  23. package/dist/solution/Checkout/appointmentDemo.json +1 -0
  24. package/dist/solution/Checkout/index.d.ts +415 -0
  25. package/dist/solution/Checkout/index.js +3622 -0
  26. package/dist/solution/Checkout/types.d.ts +737 -0
  27. package/dist/solution/Checkout/types.js +137 -0
  28. package/dist/solution/Checkout/utils/index.d.ts +73 -0
  29. package/dist/{modules/Payment/wallet.js → solution/Checkout/utils/index.js} +363 -70
  30. package/dist/solution/index.d.ts +1 -0
  31. package/dist/solution/index.js +2 -1
  32. package/lib/modules/Order/index.d.ts +13 -2
  33. package/lib/modules/Order/index.js +58 -1
  34. package/lib/modules/Order/types.d.ts +43 -0
  35. package/lib/modules/Payment/cash.d.ts +8 -0
  36. package/lib/modules/Payment/cash.js +14 -1
  37. package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  38. package/lib/modules/Payment/cashRecommendationAlgorithm.js +342 -0
  39. package/lib/modules/Payment/eftpos.js +1 -1
  40. package/lib/modules/Payment/index.d.ts +57 -94
  41. package/lib/modules/Payment/index.js +363 -525
  42. package/lib/modules/Payment/mx51.d.ts +0 -0
  43. package/lib/modules/Payment/mx51.js +0 -0
  44. package/lib/modules/Payment/types.d.ts +358 -50
  45. package/lib/modules/Payment/types.js +37 -2
  46. package/lib/modules/Payment/utils.d.ts +17 -0
  47. package/lib/modules/Payment/utils.js +67 -0
  48. package/lib/modules/Payment/walletpass.d.ts +96 -0
  49. package/lib/modules/Payment/walletpass.js +304 -0
  50. package/lib/modules/Schedule/index.d.ts +9 -0
  51. package/lib/modules/Schedule/index.js +36 -0
  52. package/lib/solution/BookingTicket/index.d.ts +1 -1
  53. package/lib/solution/Checkout/appointmentDemo.json +1 -0
  54. package/lib/solution/Checkout/index.d.ts +415 -0
  55. package/lib/solution/Checkout/index.js +2107 -0
  56. package/lib/solution/Checkout/types.d.ts +737 -0
  57. package/lib/solution/Checkout/types.js +80 -0
  58. package/lib/solution/Checkout/utils/index.d.ts +73 -0
  59. package/lib/solution/Checkout/utils/index.js +266 -0
  60. package/lib/solution/index.d.ts +1 -0
  61. package/lib/solution/index.js +3 -1
  62. package/package.json +1 -1
  63. package/dist/modules/Payment/wallet.d.ts +0 -11
  64. package/lib/modules/Payment/wallet.d.ts +0 -11
  65. package/lib/modules/Payment/wallet.js +0 -51
@@ -21,11 +21,11 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
21
21
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
22
22
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
23
  import { BaseModule } from "../BaseModule";
24
- import { PaymentStatus, PaymentHooks, PaymentMethodType } from "./types";
24
+ import { PaymentStatus, PaymentHooks, PaymentMethodType, RoundingRule } from "./types";
25
25
  import { getUniqueId } from "../Cart/utils";
26
26
  import { CashPaymentImpl } from "./cash";
27
27
  import { EftposPaymentImpl } from "./eftpos";
28
- import { WalletPaymentImpl } from "./wallet";
28
+ import { WalletPassPaymentImpl } from "./walletpass";
29
29
  import { Decimal } from 'decimal.js';
30
30
  export * from "./types";
31
31
  export { generateRequestUniqueId };
@@ -65,28 +65,7 @@ function generateRequestUniqueId() {
65
65
  /**
66
66
  * 支付模块实现
67
67
  *
68
- * 支付流程说明:
69
- * 1. 用户操作 → 调用支付API (pushPaymentAsync, submitPayAsync等)
70
- * 2. 数据处理 → 更新本地IndexDB中的订单和支付项数据
71
- * 3. 立即完成 → 本地订单状态立即更新为PaymentStatus.Finished(isSynced保持false)
72
- * 4. 后台同步 → 网络请求推送到TasksManager异步同步到服务器
73
- * 5. 同步成功 → 网络请求成功后,isSynced设为true
74
- * 6. 自动重试 → TasksManager自动重试失败的网络请求,直到isSynced为true
75
- *
76
- * 数据状态说明:
77
- * - PaymentStatus.Processing: 订单正在进行支付操作
78
- * - PaymentStatus.PartiallyPaid + isSynced=false: 部分支付完成,等待服务器同步
79
- * - PaymentStatus.PartiallyPaid + isSynced=true: 部分支付且已同步到服务器
80
- * - PaymentStatus.Finished + isSynced=false: 本地支付完成,等待服务器同步
81
- * - PaymentStatus.Finished + isSynced=true: 支付完成且已同步到服务器
82
- *
83
- * 这种设计的优势:
84
- * - 即时反馈:支付操作后立即显示完成状态,用户体验更佳
85
- * - 离线支持:即使网络断开也能正常操作,数据保存在本地
86
- * - 同步追踪:通过isSynced清楚知道哪些数据还未同步到服务器
87
- * - 自动重试:TasksManager会自动重试失败的网络请求
88
- * - 异步处理:不阻塞用户界面,网络同步在后台进行
89
- * - 数据一致性:通过事件系统确保数据状态同步
68
+ * 负责处理支付相关的数据管理和本地存储
90
69
  */
91
70
  export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
92
71
  _inherits(PaymentModule, _BaseModule);
@@ -112,7 +91,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
112
91
  _defineProperty(_assertThisInitialized(_this), "wallet", void 0);
113
92
  _this.cash = new CashPaymentImpl(_assertThisInitialized(_this));
114
93
  _this.eftpos = new EftposPaymentImpl(_assertThisInitialized(_this));
115
- _this.wallet = new WalletPaymentImpl(_assertThisInitialized(_this));
94
+ _this.wallet = new WalletPassPaymentImpl(_assertThisInitialized(_this));
116
95
  return _this;
117
96
  }
118
97
  _createClass(PaymentModule, [{
@@ -149,12 +128,10 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
149
128
  _context.next = 13;
150
129
  return this.ensurePaymentTables();
151
130
  case 13:
152
- // 注册任务处理函数
153
- this.registerTaskHandlers();
154
131
  this.registerNetworkHandlers();
155
132
  console.log('[PaymentModule] 初始化完成');
156
133
  this.logInfo('PaymentModule initialized successfully');
157
- case 17:
134
+ case 16:
158
135
  case "end":
159
136
  return _context.stop();
160
137
  }
@@ -243,7 +220,6 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
243
220
  this.logInfo('Registering network status listener');
244
221
  network === null || network === void 0 || network.addListener('networkStatusChange', /*#__PURE__*/function () {
245
222
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(status) {
246
- var requeuedCount;
247
223
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
248
224
  while (1) switch (_context2.prev = _context2.next) {
249
225
  case 0:
@@ -252,24 +228,11 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
252
228
  connected: status.connected,
253
229
  previousStatus: status.previousStatus
254
230
  });
255
- if (!status.connected) {
256
- _context2.next = 10;
257
- break;
231
+ if (status.connected) {
232
+ _this2.logInfo('Network reconnected');
233
+ // 网络恢复时的处理逻辑可以在这里添加
258
234
  }
259
- _this2.logInfo('Network reconnected - triggering payment sync queue');
260
- // this.runPaymentSyncQueue();
261
- // 1. 先检查并重新排队未同步订单,然后执行队列
262
- _context2.next = 6;
263
- return _this2.recheckAndRequeueUnsyncedOrders();
264
- case 6:
265
- requeuedCount = _context2.sent;
266
- if (!(requeuedCount > 0)) {
267
- _context2.next = 10;
268
- break;
269
- }
270
- _context2.next = 10;
271
- return _this2.runPaymentSyncQueue();
272
- case 10:
235
+ case 3:
273
236
  case "end":
274
237
  return _context2.stop();
275
238
  }
@@ -319,7 +282,9 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
319
282
  return _context3.abrupt("return", cachedMethods);
320
283
  case 16:
321
284
  _context3.next = 18;
322
- return this.request.get('/pay/custom-payment/available');
285
+ return this.request.get('/pay/custom-payment/available', {
286
+ channel: 'pos'
287
+ });
323
288
  case 18:
324
289
  response = _context3.sent;
325
290
  payMethods = response.data || []; // 尝试缓存到 IndexDB
@@ -403,7 +368,9 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
403
368
 
404
369
  // 从服务器获取最新数据
405
370
  _context4.next = 5;
406
- return this.request.get('/pay/custom-payment/available');
371
+ return this.request.get('/pay/custom-payment/available', {
372
+ channel: 'pos'
373
+ });
407
374
  case 5:
408
375
  response = _context4.sent;
409
376
  newPayMethods = response.data || []; // 检查是否有变化
@@ -583,13 +550,13 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
583
550
  return getOrderListAsync;
584
551
  }()
585
552
  /**
586
- * 根据uuid获取指定订单
553
+ * 根据订单UUID获取支付订单(新方法)
587
554
  */
588
555
  )
589
556
  }, {
590
- key: "getOrderByUuidAsync",
557
+ key: "getPaymentOrderByUuidAsync",
591
558
  value: (function () {
592
- var _getOrderByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(orderUuid) {
559
+ var _getPaymentOrderByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(orderUuid) {
593
560
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
594
561
  while (1) switch (_context6.prev = _context6.next) {
595
562
  case 0:
@@ -601,7 +568,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
601
568
  case 6:
602
569
  _context6.prev = 6;
603
570
  _context6.t0 = _context6["catch"](0);
604
- console.error('[PaymentModule] 获取订单失败', _context6.t0);
571
+ console.error('[PaymentModule] 获取支付订单失败', _context6.t0);
605
572
  return _context6.abrupt("return", null);
606
573
  case 10:
607
574
  case "end":
@@ -609,26 +576,26 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
609
576
  }
610
577
  }, _callee6, this, [[0, 6]]);
611
578
  }));
612
- function getOrderByUuidAsync(_x5) {
613
- return _getOrderByUuidAsync.apply(this, arguments);
579
+ function getPaymentOrderByUuidAsync(_x5) {
580
+ return _getPaymentOrderByUuidAsync.apply(this, arguments);
614
581
  }
615
- return getOrderByUuidAsync;
582
+ return getPaymentOrderByUuidAsync;
616
583
  }()
617
584
  /**
618
- * 往交易组中添加订单
585
+ * 创建支付订单(新方法,专注支付数据)
619
586
  */
620
587
  )
621
588
  }, {
622
- key: "pushOrderAsync",
589
+ key: "createPaymentOrderAsync",
623
590
  value: (function () {
624
- var _pushOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
591
+ var _createPaymentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
625
592
  var existingOrders, existingOrder, originalOrder, newOrder;
626
593
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
627
594
  while (1) switch (_context7.prev = _context7.next) {
628
595
  case 0:
629
- this.logInfo('Starting pushOrderAsync', {
630
- orderId: params.order_info.order_id,
631
- totalAmount: params.order_info.total_amount
596
+ this.logInfo('Starting createPaymentOrderAsync', {
597
+ orderId: params.order_id,
598
+ totalAmount: params.total_amount
632
599
  });
633
600
  _context7.prev = 1;
634
601
  _context7.next = 4;
@@ -636,48 +603,46 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
636
603
  case 4:
637
604
  existingOrders = _context7.sent;
638
605
  existingOrder = existingOrders.find(function (order) {
639
- return order.id === params.order_info.order_id;
606
+ return String(order.id) === String(params.order_id);
640
607
  });
641
608
  if (!existingOrder) {
642
609
  _context7.next = 21;
643
610
  break;
644
611
  }
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"));
612
+ // 如果存在相同 order_id 的订单,更新该订单信息
613
+ console.log("[PaymentModule] \u53D1\u73B0\u91CD\u590D\u8BA2\u5355 ID: ".concat(params.order_id, "\uFF0C\u66F4\u65B0\u73B0\u6709\u652F\u4ED8\u8BA2\u5355"));
647
614
  originalOrder = _objectSpread({}, existingOrder);
648
615
  existingOrder.order_info = params.order_info;
649
- existingOrder.total_amount = params.order_info.total_amount;
616
+ existingOrder.total_amount = params.total_amount;
617
+ existingOrder.is_deposit = params.is_deposit || 0;
618
+ existingOrder.deposit_amount = params.deposit_amount || '0.00';
650
619
 
651
620
  // 重新计算待付金额
652
621
  this.recalculateOrderAmount(existingOrder);
653
622
 
654
623
  // 更新到数据库
655
- _context7.next = 14;
656
- return this.dbManager.update('order', existingOrder);
657
- case 14:
658
624
  _context7.next = 16;
659
- return this.core.effects.emit(PaymentHooks.OnOrderUpdated, existingOrder);
625
+ return this.dbManager.update('order', existingOrder);
660
626
  case 16:
661
627
  _context7.next = 18;
662
- return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
663
- action: 'update',
664
- order: existingOrder,
665
- originalOrder: originalOrder
666
- });
628
+ return this.core.effects.emit(PaymentHooks.OnOrderUpdated, existingOrder);
667
629
  case 18:
668
630
  return _context7.abrupt("return", existingOrder);
669
631
  case 21:
670
- // 如果不存在相同 order_id 的订单,创建新订单
632
+ // 创建新的支付订单
671
633
  newOrder = {
672
634
  uuid: getUniqueId('pay_order_'),
673
- id: params.order_info.order_id,
635
+ id: params.order_id,
636
+ order_id: params.order_id,
674
637
  order_info: params.order_info,
675
638
  payment_status: PaymentStatus.Processing,
676
639
  payment: [],
677
640
  adjust_offline_payments: [],
678
- total_amount: params.order_info.total_amount,
679
- expect_amount: params.order_info.total_amount,
680
- tax_fee: '0.00'
641
+ total_amount: params.total_amount,
642
+ expect_amount: params.total_amount,
643
+ tax_fee: '0.00',
644
+ is_deposit: params.is_deposit || 0,
645
+ deposit_amount: params.deposit_amount || '0.00'
681
646
  };
682
647
  _context7.next = 24;
683
648
  return this.dbManager.add('order', newOrder);
@@ -685,47 +650,41 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
685
650
  _context7.next = 26;
686
651
  return this.core.effects.emit(PaymentHooks.OnOrderAdded, newOrder);
687
652
  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', {
653
+ this.logInfo('createPaymentOrderAsync completed - new payment order created', {
695
654
  orderUuid: newOrder.uuid,
696
655
  orderId: newOrder.id
697
656
  });
698
657
  return _context7.abrupt("return", newOrder);
699
- case 30:
700
- _context7.next = 37;
658
+ case 28:
659
+ _context7.next = 35;
701
660
  break;
702
- case 32:
703
- _context7.prev = 32;
661
+ case 30:
662
+ _context7.prev = 30;
704
663
  _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
664
+ console.error('[PaymentModule] 创建支付订单失败', _context7.t0);
665
+ this.logError('createPaymentOrderAsync failed', _context7.t0, {
666
+ orderId: params.order_id
708
667
  });
709
668
  throw _context7.t0;
710
- case 37:
669
+ case 35:
711
670
  case "end":
712
671
  return _context7.stop();
713
672
  }
714
- }, _callee7, this, [[1, 32]]);
673
+ }, _callee7, this, [[1, 30]]);
715
674
  }));
716
- function pushOrderAsync(_x6) {
717
- return _pushOrderAsync.apply(this, arguments);
675
+ function createPaymentOrderAsync(_x6) {
676
+ return _createPaymentOrderAsync.apply(this, arguments);
718
677
  }
719
- return pushOrderAsync;
678
+ return createPaymentOrderAsync;
720
679
  }()
721
680
  /**
722
- * 删除订单
681
+ * 删除支付订单(新方法)
723
682
  */
724
683
  )
725
684
  }, {
726
- key: "deleteOrderAsync",
685
+ key: "deletePaymentOrderAsync",
727
686
  value: (function () {
728
- var _deleteOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(orderUuid) {
687
+ var _deletePaymentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(orderUuid) {
729
688
  var order;
730
689
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
731
690
  while (1) switch (_context8.prev = _context8.next) {
@@ -736,7 +695,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
736
695
  case 3:
737
696
  order = _context8.sent;
738
697
  if (!order) {
739
- _context8.next = 11;
698
+ _context8.next = 10;
740
699
  break;
741
700
  }
742
701
  _context8.next = 7;
@@ -745,29 +704,25 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
745
704
  _context8.next = 9;
746
705
  return this.core.effects.emit(PaymentHooks.OnOrderDeleted, order);
747
706
  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;
707
+ console.log('[PaymentModule] 支付订单删除成功:', orderUuid);
708
+ case 10:
709
+ _context8.next = 16;
755
710
  break;
756
- case 13:
757
- _context8.prev = 13;
711
+ case 12:
712
+ _context8.prev = 12;
758
713
  _context8.t0 = _context8["catch"](0);
759
- console.error('[PaymentModule] 删除订单失败', _context8.t0);
714
+ console.error('[PaymentModule] 删除支付订单失败', _context8.t0);
760
715
  throw _context8.t0;
761
- case 17:
716
+ case 16:
762
717
  case "end":
763
718
  return _context8.stop();
764
719
  }
765
- }, _callee8, this, [[0, 13]]);
720
+ }, _callee8, this, [[0, 12]]);
766
721
  }));
767
- function deleteOrderAsync(_x7) {
768
- return _deleteOrderAsync.apply(this, arguments);
722
+ function deletePaymentOrderAsync(_x7) {
723
+ return _deletePaymentOrderAsync.apply(this, arguments);
769
724
  }
770
- return deleteOrderAsync;
725
+ return deletePaymentOrderAsync;
771
726
  }()
772
727
  /**
773
728
  * 更新订单
@@ -823,194 +778,542 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
823
778
  return updateOrderAsync;
824
779
  }()
825
780
  /**
826
- * 获取支付项
781
+ * 基于UUID替换订单ID
782
+ *
783
+ * 此方法用于将本地虚拟订单ID替换为真实的订单ID。
784
+ * 当前端模拟下单流程完成后,后端返回真实订单ID时调用此方法。
785
+ *
786
+ * @param orderUuid 订单的UUID
787
+ * @param newOrderId 新的订单ID (来自后端)
788
+ * @returns 更新后的订单对象,如果订单不存在则返回null
827
789
  */
828
790
  )
829
791
  }, {
830
- key: "getPaymentAsync",
792
+ key: "replaceOrderIdByUuidAsync",
831
793
  value: (function () {
832
- var _getPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(orderUuid) {
833
- var order;
794
+ var _replaceOrderIdByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(orderUuid, newOrderId) {
795
+ var existingOrder, allOrders, duplicateOrder, originalOrderId, updatedOrder;
834
796
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
835
797
  while (1) switch (_context10.prev = _context10.next) {
836
798
  case 0:
837
- if (orderUuid) {
838
- _context10.next = 2;
839
- break;
840
- }
841
- throw new Error('orderUuid is required');
842
- case 2:
799
+ this.logInfo('Starting replaceOrderIdByUuidAsync', {
800
+ orderUuid: orderUuid,
801
+ newOrderId: newOrderId
802
+ });
803
+ _context10.prev = 1;
843
804
  _context10.next = 4;
844
- return this.getOrderByUuidAsync(orderUuid);
805
+ return this.dbManager.get('order', orderUuid);
845
806
  case 4:
846
- order = _context10.sent;
847
- return _context10.abrupt("return", (order === null || order === void 0 ? void 0 : order.payment) || []);
848
- case 6:
807
+ existingOrder = _context10.sent;
808
+ if (existingOrder) {
809
+ _context10.next = 8;
810
+ break;
811
+ }
812
+ this.logWarning('Order not found for UUID replacement', {
813
+ orderUuid: orderUuid
814
+ });
815
+ return _context10.abrupt("return", null);
816
+ case 8:
817
+ _context10.next = 10;
818
+ return this.dbManager.getAll('order');
819
+ case 10:
820
+ allOrders = _context10.sent;
821
+ duplicateOrder = allOrders.find(function (order) {
822
+ return String(order.order_id) === String(newOrderId) && order.uuid !== orderUuid;
823
+ });
824
+ if (!duplicateOrder) {
825
+ _context10.next = 15;
826
+ break;
827
+ }
828
+ this.logWarning('New order ID already exists', {
829
+ newOrderId: newOrderId,
830
+ existingOrderUuid: duplicateOrder.uuid
831
+ });
832
+ throw new Error("\u8BA2\u5355ID ".concat(newOrderId, " \u5DF2\u5B58\u5728"));
833
+ case 15:
834
+ // 保存原始订单ID用于日志
835
+ originalOrderId = existingOrder.id; // 更新订单ID
836
+ updatedOrder = _objectSpread(_objectSpread({}, existingOrder), {}, {
837
+ id: newOrderId,
838
+ order_id: newOrderId,
839
+ // 🔧 修复:同时更新根级的 order_id 字段
840
+ order_info: _objectSpread(_objectSpread({}, existingOrder.order_info), {}, {
841
+ order_id: newOrderId,
842
+ // 保留原始本地订单ID作为参考
843
+ original_local_order_id: originalOrderId,
844
+ updated_at: new Date().toISOString()
845
+ })
846
+ }); // 更新到数据库
847
+ _context10.next = 19;
848
+ return this.dbManager.update('order', updatedOrder);
849
+ case 19:
850
+ _context10.next = 21;
851
+ return this.core.effects.emit(PaymentHooks.OnOrderUpdated, updatedOrder);
852
+ case 21:
853
+ _context10.next = 23;
854
+ return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
855
+ action: 'order_id_replaced',
856
+ order: updatedOrder,
857
+ originalOrder: existingOrder,
858
+ metadata: {
859
+ originalOrderId: originalOrderId,
860
+ newOrderId: newOrderId
861
+ }
862
+ });
863
+ case 23:
864
+ this.logInfo('Order ID replacement completed successfully', {
865
+ orderUuid: orderUuid,
866
+ originalOrderId: originalOrderId,
867
+ newOrderId: newOrderId
868
+ });
869
+ console.log("[PaymentModule] \u8BA2\u5355ID\u66FF\u6362\u6210\u529F: ".concat(originalOrderId, " \u2192 ").concat(newOrderId));
870
+ return _context10.abrupt("return", updatedOrder);
871
+ case 28:
872
+ _context10.prev = 28;
873
+ _context10.t0 = _context10["catch"](1);
874
+ console.error('[PaymentModule] 替换订单ID失败', _context10.t0);
875
+ this.logError('replaceOrderIdByUuidAsync failed', _context10.t0, {
876
+ orderUuid: orderUuid,
877
+ newOrderId: newOrderId
878
+ });
879
+ throw _context10.t0;
880
+ case 33:
849
881
  case "end":
850
882
  return _context10.stop();
851
883
  }
852
- }, _callee10, this);
884
+ }, _callee10, this, [[1, 28]]);
853
885
  }));
854
- function getPaymentAsync(_x10) {
855
- return _getPaymentAsync.apply(this, arguments);
886
+ function replaceOrderIdByUuidAsync(_x10, _x11) {
887
+ return _replaceOrderIdByUuidAsync.apply(this, arguments);
856
888
  }
857
- return getPaymentAsync;
889
+ return replaceOrderIdByUuidAsync;
858
890
  }()
859
891
  /**
860
- * 为某个订单设置一个支付项
892
+ * 获取支付项(新方法)
893
+ *
894
+ * @param orderUuid 订单UUID
895
+ * @param includeVoided 是否包含已撤销的支付项,默认为false
896
+ * @returns 支付项数组
861
897
  */
862
898
  )
863
899
  }, {
864
- key: "pushPaymentAsync",
900
+ key: "getPaymentItemsAsync",
865
901
  value: (function () {
866
- var _pushPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(orderUuid, paymentItem) {
867
- var order, newPaymentItem;
902
+ var _getPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(orderUuid) {
903
+ var includeVoided,
904
+ order,
905
+ allPayments,
906
+ _args11 = arguments;
868
907
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
869
908
  while (1) switch (_context11.prev = _context11.next) {
870
909
  case 0:
871
- this.logInfo('Starting pushPaymentAsync', {
910
+ includeVoided = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : false;
911
+ if (orderUuid) {
912
+ _context11.next = 3;
913
+ break;
914
+ }
915
+ throw new Error('orderUuid is required');
916
+ case 3:
917
+ _context11.next = 5;
918
+ return this.getPaymentOrderByUuidAsync(orderUuid);
919
+ case 5:
920
+ order = _context11.sent;
921
+ allPayments = (order === null || order === void 0 ? void 0 : order.payment) || [];
922
+ if (!includeVoided) {
923
+ _context11.next = 9;
924
+ break;
925
+ }
926
+ return _context11.abrupt("return", allPayments);
927
+ case 9:
928
+ return _context11.abrupt("return", allPayments.filter(function (payment) {
929
+ return payment.status !== 'voided';
930
+ }));
931
+ case 10:
932
+ case "end":
933
+ return _context11.stop();
934
+ }
935
+ }, _callee11, this);
936
+ }));
937
+ function getPaymentItemsAsync(_x12) {
938
+ return _getPaymentItemsAsync.apply(this, arguments);
939
+ }
940
+ return getPaymentItemsAsync;
941
+ }()
942
+ /**
943
+ * 获取所有支付项(包括已撤销的)
944
+ *
945
+ * @param orderUuid 订单UUID
946
+ * @returns 所有支付项数组(包括撤销的)
947
+ */
948
+ )
949
+ }, {
950
+ key: "getAllPaymentItemsAsync",
951
+ value: (function () {
952
+ var _getAllPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(orderUuid) {
953
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
954
+ while (1) switch (_context12.prev = _context12.next) {
955
+ case 0:
956
+ return _context12.abrupt("return", this.getPaymentItemsAsync(orderUuid, true));
957
+ case 1:
958
+ case "end":
959
+ return _context12.stop();
960
+ }
961
+ }, _callee12, this);
962
+ }));
963
+ function getAllPaymentItemsAsync(_x13) {
964
+ return _getAllPaymentItemsAsync.apply(this, arguments);
965
+ }
966
+ return getAllPaymentItemsAsync;
967
+ }()
968
+ /**
969
+ * 为某个订单添加支付项(新方法)
970
+ */
971
+ )
972
+ }, {
973
+ key: "addPaymentItemAsync",
974
+ value: (function () {
975
+ var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderUuid, paymentItem) {
976
+ var _newPaymentItem$metad, order, paymentUuid, newPaymentItem;
977
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
978
+ while (1) switch (_context13.prev = _context13.next) {
979
+ case 0:
980
+ this.logInfo('Starting addPaymentItemAsync', {
872
981
  orderUuid: orderUuid,
873
982
  paymentAmount: paymentItem.amount,
874
983
  paymentCode: paymentItem.code
875
984
  });
876
- _context11.prev = 1;
877
- _context11.next = 4;
878
- return this.dbManager.get('order', orderUuid);
985
+ _context13.prev = 1;
986
+ _context13.next = 4;
987
+ return this.getPaymentOrderByUuidAsync(orderUuid);
879
988
  case 4:
880
- order = _context11.sent;
989
+ order = _context13.sent;
881
990
  if (order) {
882
- _context11.next = 7;
991
+ _context13.next = 7;
883
992
  break;
884
993
  }
885
- throw new Error('订单不存在');
994
+ throw new Error("Order not found: ".concat(orderUuid));
886
995
  case 7:
887
- newPaymentItem = _objectSpread(_objectSpread({}, paymentItem), {}, {
996
+ paymentUuid = getUniqueId('payment_');
997
+ newPaymentItem = {
998
+ uuid: paymentUuid,
999
+ id: paymentItem.id || 0,
1000
+ name: paymentItem.name,
1001
+ code: paymentItem.code,
1002
+ type: paymentItem.type,
888
1003
  amount: formatAmount(paymentItem.amount),
889
- // 格式化金额为保留两位小数的字符串
890
- uuid: getUniqueId('pay_item_'),
891
- isSynced: false
892
- });
1004
+ voucher_id: paymentItem.voucher_id || '',
1005
+ rounding_amount: '0.00',
1006
+ service_charge: paymentItem.service_charge,
1007
+ status: 'active',
1008
+ // 新支付项默认为活跃状态
1009
+ metadata: {
1010
+ unique_payment_number: paymentUuid // 设置唯一支付号为支付项的 uuid
1011
+ }
1012
+ };
893
1013
  order.payment.push(newPaymentItem);
894
-
895
- // 重新计算待付金额
896
1014
  this.recalculateOrderAmount(order);
897
-
898
- // 更新到 IndexDB
899
- _context11.next = 12;
1015
+ _context13.next = 13;
900
1016
  return this.dbManager.update('order', order);
901
- case 12:
902
- _context11.next = 14;
1017
+ case 13:
1018
+ _context13.next = 15;
903
1019
  return this.core.effects.emit(PaymentHooks.OnPaymentAdded, {
904
- order: order,
905
- paymentItem: newPaymentItem
906
- });
907
- case 14:
908
- _context11.next = 16;
909
- return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
910
- action: 'payment_add',
911
- order: order,
912
- paymentItem: newPaymentItem
1020
+ orderUuid: orderUuid,
1021
+ payment: newPaymentItem
913
1022
  });
914
- case 16:
915
- this.logInfo('pushPaymentAsync completed successfully', {
1023
+ case 15:
1024
+ this.logInfo('addPaymentItemAsync completed successfully', {
916
1025
  orderUuid: orderUuid,
917
1026
  paymentUuid: newPaymentItem.uuid,
1027
+ uniquePaymentNumber: (_newPaymentItem$metad = newPaymentItem.metadata) === null || _newPaymentItem$metad === void 0 ? void 0 : _newPaymentItem$metad.unique_payment_number,
918
1028
  newExpectAmount: order.expect_amount
919
1029
  });
920
- _context11.next = 24;
1030
+ _context13.next = 23;
921
1031
  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, {
1032
+ case 18:
1033
+ _context13.prev = 18;
1034
+ _context13.t0 = _context13["catch"](1);
1035
+ console.error('[PaymentModule] 添加支付项失败', _context13.t0);
1036
+ this.logError('addPaymentItemAsync failed', _context13.t0, {
927
1037
  orderUuid: orderUuid,
928
1038
  paymentItem: paymentItem
929
1039
  });
930
- throw _context11.t0;
931
- case 24:
1040
+ throw _context13.t0;
1041
+ case 23:
932
1042
  case "end":
933
- return _context11.stop();
1043
+ return _context13.stop();
934
1044
  }
935
- }, _callee11, this, [[1, 19]]);
1045
+ }, _callee13, this, [[1, 18]]);
936
1046
  }));
937
- function pushPaymentAsync(_x11, _x12) {
938
- return _pushPaymentAsync.apply(this, arguments);
1047
+ function addPaymentItemAsync(_x14, _x15) {
1048
+ return _addPaymentItemAsync.apply(this, arguments);
939
1049
  }
940
- return pushPaymentAsync;
1050
+ return addPaymentItemAsync;
941
1051
  }()
942
1052
  /**
943
- * 删除一个支付项
1053
+ * 删除一个支付项 - 标记删除而非物理删除
944
1054
  */
945
1055
  )
946
1056
  }, {
947
1057
  key: "deletePaymentAsync",
948
1058
  value: (function () {
949
- var _deletePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(orderUuid, paymentUuid) {
950
- var order, index, deletedPayment;
951
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
952
- while (1) switch (_context12.prev = _context12.next) {
1059
+ var _deletePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderUuid, paymentUuid) {
1060
+ var order, paymentItem;
1061
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1062
+ while (1) switch (_context14.prev = _context14.next) {
953
1063
  case 0:
954
- this.logInfo('Starting deletePaymentAsync', {
1064
+ this.logInfo('Starting deletePaymentAsync (mark as voided)', {
955
1065
  orderUuid: orderUuid,
956
1066
  paymentUuid: paymentUuid
957
1067
  });
958
- _context12.prev = 1;
959
- _context12.next = 4;
1068
+ _context14.prev = 1;
1069
+ _context14.next = 4;
960
1070
  return this.dbManager.get('order', orderUuid);
961
1071
  case 4:
962
- order = _context12.sent;
1072
+ order = _context14.sent;
963
1073
  if (order) {
964
- _context12.next = 7;
1074
+ _context14.next = 7;
965
1075
  break;
966
1076
  }
967
1077
  throw new Error('订单不存在');
968
1078
  case 7:
969
- index = order.payment.findIndex(function (payment) {
1079
+ paymentItem = order.payment.find(function (payment) {
970
1080
  return payment.uuid === paymentUuid;
971
1081
  });
972
- if (!(index > -1)) {
973
- _context12.next = 17;
1082
+ if (paymentItem) {
1083
+ _context14.next = 10;
1084
+ break;
1085
+ }
1086
+ throw new Error("\u652F\u4ED8\u9879\u4E0D\u5B58\u5728: ".concat(paymentUuid));
1087
+ case 10:
1088
+ if (!(paymentItem.status === 'voided')) {
1089
+ _context14.next = 13;
974
1090
  break;
975
1091
  }
976
- deletedPayment = order.payment.splice(index, 1)[0]; // 重新计算待付金额
1092
+ console.warn("[PaymentModule] \u652F\u4ED8\u9879 ".concat(paymentUuid, " \u5DF2\u7ECF\u88AB\u5220\u9664\uFF0C\u8DF3\u8FC7\u64CD\u4F5C"));
1093
+ return _context14.abrupt("return");
1094
+ case 13:
1095
+ // 标记删除而不是物理删除
1096
+ paymentItem.status = 'voided';
1097
+ paymentItem.origin_amount = paymentItem.amount; // 保存原始金额
1098
+ paymentItem.amount = '0.00'; // 将金额设为0,不参与订单金额计算
1099
+
1100
+ console.log("[PaymentModule] \u652F\u4ED8\u9879\u6807\u8BB0\u4E3A\u5220\u9664:", {
1101
+ uuid: paymentItem.uuid,
1102
+ originalAmount: paymentItem.origin_amount,
1103
+ status: paymentItem.status
1104
+ });
1105
+
1106
+ // 重新计算待付金额
977
1107
  this.recalculateOrderAmount(order);
978
1108
 
979
1109
  // 更新到 IndexDB
980
- _context12.next = 13;
1110
+ _context14.next = 20;
981
1111
  return this.dbManager.update('order', order);
982
- case 13:
983
- _context12.next = 15;
1112
+ case 20:
1113
+ _context14.next = 22;
984
1114
  return this.core.effects.emit(PaymentHooks.OnPaymentDeleted, {
985
1115
  order: order,
986
- paymentItem: deletedPayment
1116
+ paymentItem: paymentItem
987
1117
  });
988
- case 15:
989
- _context12.next = 17;
1118
+ case 22:
1119
+ _context14.next = 24;
990
1120
  return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
991
1121
  action: 'payment_delete',
992
1122
  order: order,
993
- paymentItem: deletedPayment
1123
+ paymentItem: paymentItem
994
1124
  });
995
- case 17:
996
- _context12.next = 23;
1125
+ case 24:
1126
+ this.logInfo('deletePaymentAsync completed successfully (marked as voided)', {
1127
+ orderUuid: orderUuid,
1128
+ paymentUuid: paymentUuid,
1129
+ originalAmount: paymentItem.origin_amount,
1130
+ newExpectAmount: order.expect_amount
1131
+ });
1132
+ _context14.next = 32;
997
1133
  break;
998
- case 19:
999
- _context12.prev = 19;
1000
- _context12.t0 = _context12["catch"](1);
1001
- console.error('[PaymentModule] 删除支付项失败', _context12.t0);
1002
- throw _context12.t0;
1003
- case 23:
1134
+ case 27:
1135
+ _context14.prev = 27;
1136
+ _context14.t0 = _context14["catch"](1);
1137
+ console.error('[PaymentModule] 删除支付项失败', _context14.t0);
1138
+ this.logError('deletePaymentAsync failed', _context14.t0, {
1139
+ orderUuid: orderUuid,
1140
+ paymentUuid: paymentUuid
1141
+ });
1142
+ throw _context14.t0;
1143
+ case 32:
1004
1144
  case "end":
1005
- return _context12.stop();
1145
+ return _context14.stop();
1006
1146
  }
1007
- }, _callee12, this, [[1, 19]]);
1147
+ }, _callee14, this, [[1, 27]]);
1008
1148
  }));
1009
- function deletePaymentAsync(_x13, _x14) {
1149
+ function deletePaymentAsync(_x16, _x17) {
1010
1150
  return _deletePaymentAsync.apply(this, arguments);
1011
1151
  }
1012
1152
  return deletePaymentAsync;
1013
1153
  }()
1154
+ /**
1155
+ * 批量更新代金券类支付项(覆盖更新)
1156
+ *
1157
+ * 删除所有现有的带 voucher_id 的支付项,然后添加新的代金券支付项
1158
+ * 这是一个覆盖式更新,确保代金券支付项的一致性
1159
+ */
1160
+ )
1161
+ }, {
1162
+ key: "updateVoucherPaymentItemsAsync",
1163
+ value: (function () {
1164
+ var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(orderUuid, voucherPaymentItems) {
1165
+ var order, existingVoucherItems, _iterator5, _step5, voucherItem, _iterator6, _step6, _voucherItem, updatedOrder;
1166
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1167
+ while (1) switch (_context15.prev = _context15.next) {
1168
+ case 0:
1169
+ this.logInfo('Starting updateVoucherPaymentItemsAsync', {
1170
+ orderUuid: orderUuid,
1171
+ newVoucherCount: voucherPaymentItems.length,
1172
+ voucherItems: voucherPaymentItems.map(function (item) {
1173
+ return {
1174
+ code: item.code,
1175
+ amount: item.amount,
1176
+ voucher_id: item.voucher_id
1177
+ };
1178
+ })
1179
+ });
1180
+ _context15.prev = 1;
1181
+ _context15.next = 4;
1182
+ return this.getPaymentOrderByUuidAsync(orderUuid);
1183
+ case 4:
1184
+ order = _context15.sent;
1185
+ if (order) {
1186
+ _context15.next = 7;
1187
+ break;
1188
+ }
1189
+ throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728: ".concat(orderUuid));
1190
+ case 7:
1191
+ // 1. 查找所有现有的代金券类支付项(带 voucher_id 且状态不是 voided)
1192
+ existingVoucherItems = order.payment.filter(function (payment) {
1193
+ return payment.voucher_id && payment.status !== 'voided';
1194
+ });
1195
+ console.log('[PaymentModule] 发现现有代金券支付项:', {
1196
+ orderUuid: orderUuid,
1197
+ existingVoucherCount: existingVoucherItems.length,
1198
+ existingItems: existingVoucherItems.map(function (item) {
1199
+ return {
1200
+ uuid: item.uuid,
1201
+ code: item.code,
1202
+ amount: item.amount,
1203
+ voucher_id: item.voucher_id
1204
+ };
1205
+ })
1206
+ });
1207
+
1208
+ // 2. 删除所有现有的代金券支付项
1209
+ _iterator5 = _createForOfIteratorHelper(existingVoucherItems);
1210
+ _context15.prev = 10;
1211
+ _iterator5.s();
1212
+ case 12:
1213
+ if ((_step5 = _iterator5.n()).done) {
1214
+ _context15.next = 19;
1215
+ break;
1216
+ }
1217
+ voucherItem = _step5.value;
1218
+ console.log("[PaymentModule] \u5220\u9664\u73B0\u6709\u4EE3\u91D1\u5238\u652F\u4ED8\u9879: ".concat(voucherItem.uuid));
1219
+ _context15.next = 17;
1220
+ return this.deletePaymentAsync(orderUuid, voucherItem.uuid);
1221
+ case 17:
1222
+ _context15.next = 12;
1223
+ break;
1224
+ case 19:
1225
+ _context15.next = 24;
1226
+ break;
1227
+ case 21:
1228
+ _context15.prev = 21;
1229
+ _context15.t0 = _context15["catch"](10);
1230
+ _iterator5.e(_context15.t0);
1231
+ case 24:
1232
+ _context15.prev = 24;
1233
+ _iterator5.f();
1234
+ return _context15.finish(24);
1235
+ case 27:
1236
+ // 3. 添加新的代金券支付项
1237
+ console.log('[PaymentModule] 添加新的代金券支付项:', {
1238
+ orderUuid: orderUuid,
1239
+ newItemCount: voucherPaymentItems.length
1240
+ });
1241
+ _iterator6 = _createForOfIteratorHelper(voucherPaymentItems);
1242
+ _context15.prev = 29;
1243
+ _iterator6.s();
1244
+ case 31:
1245
+ if ((_step6 = _iterator6.n()).done) {
1246
+ _context15.next = 40;
1247
+ break;
1248
+ }
1249
+ _voucherItem = _step6.value;
1250
+ if (_voucherItem.voucher_id) {
1251
+ _context15.next = 35;
1252
+ break;
1253
+ }
1254
+ throw new Error("\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u7F3A\u5C11 voucher_id: ".concat(JSON.stringify(_voucherItem)));
1255
+ case 35:
1256
+ console.log("[PaymentModule] \u6DFB\u52A0\u4EE3\u91D1\u5238\u652F\u4ED8\u9879:", {
1257
+ code: _voucherItem.code,
1258
+ amount: _voucherItem.amount,
1259
+ voucher_id: _voucherItem.voucher_id
1260
+ });
1261
+ _context15.next = 38;
1262
+ return this.addPaymentItemAsync(orderUuid, _voucherItem);
1263
+ case 38:
1264
+ _context15.next = 31;
1265
+ break;
1266
+ case 40:
1267
+ _context15.next = 45;
1268
+ break;
1269
+ case 42:
1270
+ _context15.prev = 42;
1271
+ _context15.t1 = _context15["catch"](29);
1272
+ _iterator6.e(_context15.t1);
1273
+ case 45:
1274
+ _context15.prev = 45;
1275
+ _iterator6.f();
1276
+ return _context15.finish(45);
1277
+ case 48:
1278
+ _context15.next = 50;
1279
+ return this.getPaymentOrderByUuidAsync(orderUuid);
1280
+ case 50:
1281
+ updatedOrder = _context15.sent;
1282
+ _context15.next = 53;
1283
+ return this.core.effects.emit(PaymentHooks.OnPaymentAdded, {
1284
+ orderUuid: orderUuid,
1285
+ order: updatedOrder,
1286
+ payment: null // 批量操作不提供单个支付项
1287
+ });
1288
+ case 53:
1289
+ this.logInfo('updateVoucherPaymentItemsAsync completed successfully', {
1290
+ orderUuid: orderUuid,
1291
+ removedVoucherCount: existingVoucherItems.length,
1292
+ addedVoucherCount: voucherPaymentItems.length,
1293
+ finalExpectAmount: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.expect_amount
1294
+ });
1295
+ _context15.next = 61;
1296
+ break;
1297
+ case 56:
1298
+ _context15.prev = 56;
1299
+ _context15.t2 = _context15["catch"](1);
1300
+ console.error('[PaymentModule] 批量更新代金券支付项失败:', _context15.t2);
1301
+ this.logError('updateVoucherPaymentItemsAsync failed', _context15.t2, {
1302
+ orderUuid: orderUuid,
1303
+ voucherPaymentItems: voucherPaymentItems
1304
+ });
1305
+ throw _context15.t2;
1306
+ case 61:
1307
+ case "end":
1308
+ return _context15.stop();
1309
+ }
1310
+ }, _callee15, this, [[1, 56], [10, 21, 24, 27], [29, 42, 45, 48]]);
1311
+ }));
1312
+ function updateVoucherPaymentItemsAsync(_x18, _x19) {
1313
+ return _updateVoucherPaymentItemsAsync.apply(this, arguments);
1314
+ }
1315
+ return updateVoucherPaymentItemsAsync;
1316
+ }()
1014
1317
  /**
1015
1318
  * 更新一个支付项
1016
1319
  */
@@ -1018,18 +1321,18 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1018
1321
  }, {
1019
1322
  key: "updatePaymentAsync",
1020
1323
  value: (function () {
1021
- var _updatePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderUuid, paymentUuid, params) {
1324
+ var _updatePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(orderUuid, paymentUuid, params) {
1022
1325
  var order, paymentItem, formattedParams;
1023
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1024
- while (1) switch (_context13.prev = _context13.next) {
1326
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1327
+ while (1) switch (_context16.prev = _context16.next) {
1025
1328
  case 0:
1026
- _context13.prev = 0;
1027
- _context13.next = 3;
1329
+ _context16.prev = 0;
1330
+ _context16.next = 3;
1028
1331
  return this.dbManager.get('order', orderUuid);
1029
1332
  case 3:
1030
- order = _context13.sent;
1333
+ order = _context16.sent;
1031
1334
  if (order) {
1032
- _context13.next = 6;
1335
+ _context16.next = 6;
1033
1336
  break;
1034
1337
  }
1035
1338
  throw new Error('订单不存在');
@@ -1038,7 +1341,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1038
1341
  return payment.uuid === paymentUuid;
1039
1342
  });
1040
1343
  if (!paymentItem) {
1041
- _context13.next = 18;
1344
+ _context16.next = 18;
1042
1345
  break;
1043
1346
  }
1044
1347
  // 如果更新参数中包含 amount,先格式化
@@ -1052,36 +1355,36 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1052
1355
  this.recalculateOrderAmount(order);
1053
1356
 
1054
1357
  // 更新到 IndexDB
1055
- _context13.next = 14;
1358
+ _context16.next = 14;
1056
1359
  return this.dbManager.update('order', order);
1057
1360
  case 14:
1058
- _context13.next = 16;
1361
+ _context16.next = 16;
1059
1362
  return this.core.effects.emit(PaymentHooks.OnPaymentUpdated, {
1060
1363
  order: order,
1061
1364
  paymentItem: paymentItem
1062
1365
  });
1063
1366
  case 16:
1064
- _context13.next = 18;
1367
+ _context16.next = 18;
1065
1368
  return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
1066
1369
  action: 'payment_update',
1067
1370
  order: order,
1068
1371
  paymentItem: paymentItem
1069
1372
  });
1070
1373
  case 18:
1071
- _context13.next = 24;
1374
+ _context16.next = 24;
1072
1375
  break;
1073
1376
  case 20:
1074
- _context13.prev = 20;
1075
- _context13.t0 = _context13["catch"](0);
1076
- console.error('[PaymentModule] 更新支付项失败', _context13.t0);
1077
- throw _context13.t0;
1377
+ _context16.prev = 20;
1378
+ _context16.t0 = _context16["catch"](0);
1379
+ console.error('[PaymentModule] 更新支付项失败', _context16.t0);
1380
+ throw _context16.t0;
1078
1381
  case 24:
1079
1382
  case "end":
1080
- return _context13.stop();
1383
+ return _context16.stop();
1081
1384
  }
1082
- }, _callee13, this, [[0, 20]]);
1385
+ }, _callee16, this, [[0, 20]]);
1083
1386
  }));
1084
- function updatePaymentAsync(_x15, _x16, _x17) {
1387
+ function updatePaymentAsync(_x20, _x21, _x22) {
1085
1388
  return _updatePaymentAsync.apply(this, arguments);
1086
1389
  }
1087
1390
  return updatePaymentAsync;
@@ -1093,113 +1396,87 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1093
1396
  }, {
1094
1397
  key: "submitPayAsync",
1095
1398
  value: (function () {
1096
- var _submitPayAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderUuid) {
1097
- 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) {
1399
+ var _submitPayAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(orderUuid) {
1400
+ var orderToSubmit, order, allOrders, _iterator7, _step7, _order, result;
1401
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1402
+ while (1) switch (_context17.prev = _context17.next) {
1100
1403
  case 0:
1101
1404
  this.logInfo('Starting submitPayAsync', {
1102
1405
  orderUuid: orderUuid
1103
1406
  });
1104
- _context14.prev = 1;
1407
+ _context17.prev = 1;
1105
1408
  if (!orderUuid) {
1106
- _context14.next = 9;
1409
+ _context17.next = 9;
1107
1410
  break;
1108
1411
  }
1109
- _context14.next = 5;
1412
+ _context17.next = 5;
1110
1413
  return this.dbManager.get('order', orderUuid);
1111
1414
  case 5:
1112
- order = _context14.sent;
1415
+ order = _context17.sent;
1113
1416
  orderToSubmit = order ? [order] : [];
1114
- _context14.next = 13;
1417
+ _context17.next = 13;
1115
1418
  break;
1116
1419
  case 9:
1117
- _context14.next = 11;
1420
+ _context17.next = 11;
1118
1421
  return this.dbManager.getAll('order');
1119
1422
  case 11:
1120
- _allOrders = _context14.sent;
1423
+ allOrders = _context17.sent;
1121
1424
  // 包括正在处理中的订单和部分支付的订单(可能添加了新的支付项)
1122
- orderToSubmit = _allOrders.filter(function (order) {
1425
+ orderToSubmit = allOrders.filter(function (order) {
1123
1426
  return order.payment_status === PaymentStatus.Processing || order.payment_status === PaymentStatus.PartiallyPaid;
1124
1427
  });
1125
1428
  case 13:
1126
- _iterator5 = _createForOfIteratorHelper(orderToSubmit);
1127
- _context14.prev = 14;
1128
- _iterator5.s();
1429
+ _iterator7 = _createForOfIteratorHelper(orderToSubmit);
1430
+ _context17.prev = 14;
1431
+ _iterator7.s();
1129
1432
  case 16:
1130
- if ((_step5 = _iterator5.n()).done) {
1131
- _context14.next = 22;
1433
+ if ((_step7 = _iterator7.n()).done) {
1434
+ _context17.next = 22;
1132
1435
  break;
1133
1436
  }
1134
- _order = _step5.value;
1135
- _context14.next = 20;
1437
+ _order = _step7.value;
1438
+ _context17.next = 20;
1136
1439
  return this.submitSingleOrderPayment(_order);
1137
1440
  case 20:
1138
- _context14.next = 16;
1441
+ _context17.next = 16;
1139
1442
  break;
1140
1443
  case 22:
1141
- _context14.next = 27;
1444
+ _context17.next = 27;
1142
1445
  break;
1143
1446
  case 24:
1144
- _context14.prev = 24;
1145
- _context14.t0 = _context14["catch"](14);
1146
- _iterator5.e(_context14.t0);
1447
+ _context17.prev = 24;
1448
+ _context17.t0 = _context17["catch"](14);
1449
+ _iterator7.e(_context17.t0);
1147
1450
  case 27:
1148
- _context14.prev = 27;
1149
- _iterator5.f();
1150
- return _context14.finish(27);
1451
+ _context17.prev = 27;
1452
+ _iterator7.f();
1453
+ return _context17.finish(27);
1151
1454
  case 30:
1152
- _context14.next = 32;
1153
- return this.runPaymentSyncQueue();
1154
- case 32:
1155
- _context14.next = 34;
1156
- return this.dbManager.getAll('order');
1157
- case 34:
1158
- allOrders = _context14.sent;
1159
- allOrdersProcessed = allOrders.every(function (order) {
1160
- return order.payment.every(function (payment) {
1161
- return payment.isSynced === true;
1162
- });
1163
- });
1164
- if (!allOrdersProcessed) {
1165
- _context14.next = 42;
1166
- break;
1167
- }
1168
1455
  result = {
1169
1456
  status: 'success'
1170
1457
  };
1171
1458
  this.logInfo('submitPayAsync completed', {
1172
1459
  result: result.status,
1173
- processedOrdersCount: allOrders.length
1460
+ processedOrdersCount: orderToSubmit.length
1174
1461
  });
1175
- return _context14.abrupt("return", result);
1176
- case 42:
1177
- this.logWarning('submitPayAsync completed with unprocessed orders', {
1178
- totalOrders: allOrders.length
1179
- });
1180
- return _context14.abrupt("return", {
1181
- status: 'failed'
1182
- });
1183
- case 44:
1184
- _context14.next = 51;
1185
- break;
1186
- 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, {
1462
+ return _context17.abrupt("return", result);
1463
+ case 35:
1464
+ _context17.prev = 35;
1465
+ _context17.t1 = _context17["catch"](1);
1466
+ console.error('[PaymentModule] 提交支付失败', _context17.t1);
1467
+ this.logError('submitPayAsync failed', _context17.t1, {
1191
1468
  orderUuid: orderUuid
1192
1469
  });
1193
- return _context14.abrupt("return", {
1470
+ return _context17.abrupt("return", {
1194
1471
  status: 'failed'
1195
1472
  });
1196
- case 51:
1473
+ case 40:
1197
1474
  case "end":
1198
- return _context14.stop();
1475
+ return _context17.stop();
1199
1476
  }
1200
- }, _callee14, this, [[1, 46], [14, 24, 27, 30]]);
1477
+ }, _callee17, this, [[1, 35], [14, 24, 27, 30]]);
1201
1478
  }));
1202
- function submitPayAsync(_x18) {
1479
+ function submitPayAsync(_x23) {
1203
1480
  return _submitPayAsync.apply(this, arguments);
1204
1481
  }
1205
1482
  return submitPayAsync;
@@ -1211,12 +1488,12 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1211
1488
  }, {
1212
1489
  key: "submitSingleOrderPayment",
1213
1490
  value: (function () {
1214
- var _submitSingleOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(order) {
1491
+ var _submitSingleOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(order) {
1215
1492
  var paymentData, totalPaidAmount, orderTotalAmount;
1216
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1217
- while (1) switch (_context15.prev = _context15.next) {
1493
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1494
+ while (1) switch (_context18.prev = _context18.next) {
1218
1495
  case 0:
1219
- _context15.prev = 0;
1496
+ _context18.prev = 0;
1220
1497
  paymentData = {
1221
1498
  payments: order.payment.map(function (payment) {
1222
1499
  return {
@@ -1237,7 +1514,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1237
1514
  totalPaidAmount = paymentData.payments.reduce(function (sum, payment) {
1238
1515
  return sum.plus(payment.amount);
1239
1516
  }, new Decimal(0));
1240
- orderTotalAmount = new Decimal(order.order_info.total_amount); // 根据支付金额判断订单状态
1517
+ orderTotalAmount = new Decimal(order.total_amount); // 根据支付金额判断订单状态
1241
1518
  if (totalPaidAmount.gte(orderTotalAmount)) {
1242
1519
  // 支付金额足够,标记为已完成
1243
1520
  order.payment_status = PaymentStatus.Finished;
@@ -1252,101 +1529,47 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1252
1529
  paymentData.payment_status = order.payment_status === PaymentStatus.Finished ? 'paid' : 'partially_paid';
1253
1530
 
1254
1531
  // 更新订单状态到数据库
1255
- // 注意:isSynced 保持为 false,直到网络同步成功后才设为 true
1256
- _context15.next = 8;
1532
+ _context18.next = 8;
1257
1533
  return this.dbManager.update('order', order);
1258
1534
  case 8:
1259
1535
  if (!(paymentData.payments.length === 0)) {
1260
- _context15.next = 12;
1536
+ _context18.next = 12;
1261
1537
  break;
1262
1538
  }
1263
- console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u5217\u8868\u4E3A\u7A7A\uFF0C\u8DF3\u8FC7\u961F\u5217\u63A8\u9001"));
1264
- this.logWarning('Empty payment queue submission', {
1539
+ console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u5217\u8868\u4E3A\u7A7A\uFF0C\u8DF3\u8FC7\u652F\u4ED8\u5904\u7406"));
1540
+ this.logWarning('Empty payment list', {
1265
1541
  orderUuid: order.uuid,
1266
- orderId: order.order_info.order_id
1542
+ orderId: order.order_id
1267
1543
  });
1268
- return _context15.abrupt("return");
1544
+ return _context18.abrupt("return");
1269
1545
  case 12:
1270
- _context15.next = 14;
1271
- return this.addToSyncQueue(order, paymentData);
1272
- case 14:
1273
- _context15.next = 16;
1546
+ _context18.next = 14;
1274
1547
  return this.core.effects.emit(PaymentHooks.OnPaymentSubmitted, order);
1275
- case 16:
1276
- _context15.next = 18;
1548
+ case 14:
1549
+ _context18.next = 16;
1277
1550
  return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
1278
1551
  action: 'submit',
1279
1552
  order: order
1280
1553
  });
1281
- case 18:
1282
- _context15.next = 24;
1554
+ case 16:
1555
+ _context18.next = 22;
1283
1556
  break;
1284
- 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;
1289
- case 24:
1557
+ case 18:
1558
+ _context18.prev = 18;
1559
+ _context18.t0 = _context18["catch"](0);
1560
+ console.error("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u63D0\u4EA4\u5931\u8D25"), _context18.t0);
1561
+ throw _context18.t0;
1562
+ case 22:
1290
1563
  case "end":
1291
- return _context15.stop();
1564
+ return _context18.stop();
1292
1565
  }
1293
- }, _callee15, this, [[0, 20]]);
1566
+ }, _callee18, this, [[0, 18]]);
1294
1567
  }));
1295
- function submitSingleOrderPayment(_x19) {
1568
+ function submitSingleOrderPayment(_x24) {
1296
1569
  return _submitSingleOrderPayment.apply(this, arguments);
1297
1570
  }
1298
1571
  return submitSingleOrderPayment;
1299
1572
  }()
1300
- /**
1301
- * 添加到同步任务队列
1302
- */
1303
- )
1304
- }, {
1305
- key: "addToSyncQueue",
1306
- 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) {
1310
- case 0:
1311
- try {
1312
- console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u5DF2\u6DFB\u52A0\u5230\u540C\u6B65\u961F\u5217"));
1313
-
1314
- // 集成TasksManager
1315
- if (this.app.tasksManager) {
1316
- this.app.tasksManager.addTask({
1317
- module: 'payment',
1318
- queueId: 'payment_sync',
1319
- tasks: [{
1320
- id: "payment_".concat(order.uuid),
1321
- action: 'syncPayment',
1322
- payload: {
1323
- orderUuid: order.uuid,
1324
- orderId: order.order_info.order_id,
1325
- paymentData: paymentData,
1326
- core: this.core
1327
- },
1328
- maxRetries: 3,
1329
- type: 'cloud'
1330
- }]
1331
- });
1332
- console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u540C\u6B65\u4EFB\u52A1\u5DF2\u6DFB\u52A0\u5230\u961F\u5217"));
1333
- } else {
1334
- console.warn('[PaymentModule] TasksManager 未初始化,无法添加同步任务');
1335
- }
1336
- } catch (error) {
1337
- console.error('[PaymentModule] 添加同步任务失败', error);
1338
- }
1339
- case 1:
1340
- case "end":
1341
- return _context16.stop();
1342
- }
1343
- }, _callee16, this);
1344
- }));
1345
- function addToSyncQueue(_x20, _x21) {
1346
- return _addToSyncQueue.apply(this, arguments);
1347
- }
1348
- return addToSyncQueue;
1349
- }()
1350
1573
  /**
1351
1574
  * 获取订单剩余待付金额
1352
1575
  */
@@ -1354,29 +1577,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1354
1577
  }, {
1355
1578
  key: "getRemainingOrderAmountAsync",
1356
1579
  value: (function () {
1357
- var _getRemainingOrderAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(orderUuid) {
1580
+ var _getRemainingOrderAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(orderUuid) {
1358
1581
  var order;
1359
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1360
- while (1) switch (_context17.prev = _context17.next) {
1582
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1583
+ while (1) switch (_context19.prev = _context19.next) {
1361
1584
  case 0:
1362
- _context17.next = 2;
1363
- return this.getOrderByUuidAsync(orderUuid);
1585
+ _context19.next = 2;
1586
+ return this.getPaymentOrderByUuidAsync(orderUuid);
1364
1587
  case 2:
1365
- order = _context17.sent;
1588
+ order = _context19.sent;
1366
1589
  if (order) {
1367
- _context17.next = 5;
1590
+ _context19.next = 5;
1368
1591
  break;
1369
1592
  }
1370
1593
  throw new Error('订单不存在');
1371
1594
  case 5:
1372
- return _context17.abrupt("return", new Decimal(order.expect_amount).toNumber());
1595
+ return _context19.abrupt("return", new Decimal(order.expect_amount).toNumber());
1373
1596
  case 6:
1374
1597
  case "end":
1375
- return _context17.stop();
1598
+ return _context19.stop();
1376
1599
  }
1377
- }, _callee17, this);
1600
+ }, _callee19, this);
1378
1601
  }));
1379
- function getRemainingOrderAmountAsync(_x22) {
1602
+ function getRemainingOrderAmountAsync(_x25) {
1380
1603
  return _getRemainingOrderAmountAsync.apply(this, arguments);
1381
1604
  }
1382
1605
  return getRemainingOrderAmountAsync;
@@ -1388,65 +1611,65 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1388
1611
  }, {
1389
1612
  key: "getRemainingOrderAmountWithInputAsync",
1390
1613
  value: (function () {
1391
- var _getRemainingOrderAmountWithInputAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(inputAmount, orderUuid) {
1614
+ var _getRemainingOrderAmountWithInputAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(inputAmount, orderUuid) {
1392
1615
  var order, inputDecimal;
1393
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1394
- while (1) switch (_context18.prev = _context18.next) {
1616
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1617
+ while (1) switch (_context20.prev = _context20.next) {
1395
1618
  case 0:
1396
- _context18.next = 2;
1397
- return this.getOrderByUuidAsync(orderUuid);
1619
+ _context20.next = 2;
1620
+ return this.getPaymentOrderByUuidAsync(orderUuid);
1398
1621
  case 2:
1399
- order = _context18.sent;
1622
+ order = _context20.sent;
1400
1623
  if (order) {
1401
- _context18.next = 5;
1624
+ _context20.next = 5;
1402
1625
  break;
1403
1626
  }
1404
1627
  throw new Error('订单不存在');
1405
1628
  case 5:
1406
1629
  if (!(inputAmount === null || inputAmount === undefined)) {
1407
- _context18.next = 7;
1630
+ _context20.next = 7;
1408
1631
  break;
1409
1632
  }
1410
- return _context18.abrupt("return", new Decimal(order.expect_amount).toNumber());
1633
+ return _context20.abrupt("return", new Decimal(order.expect_amount).toNumber());
1411
1634
  case 7:
1412
1635
  if (!(typeof inputAmount === 'string')) {
1413
- _context18.next = 10;
1636
+ _context20.next = 10;
1414
1637
  break;
1415
1638
  }
1416
1639
  if (!(inputAmount.trim() === '')) {
1417
- _context18.next = 10;
1640
+ _context20.next = 10;
1418
1641
  break;
1419
1642
  }
1420
- return _context18.abrupt("return", new Decimal(order.expect_amount).toNumber());
1643
+ return _context20.abrupt("return", new Decimal(order.expect_amount).toNumber());
1421
1644
  case 10:
1422
1645
  if (!(typeof inputAmount === 'number')) {
1423
- _context18.next = 14;
1646
+ _context20.next = 14;
1424
1647
  break;
1425
1648
  }
1426
1649
  if (!(isNaN(inputAmount) || !isFinite(inputAmount))) {
1427
- _context18.next = 14;
1650
+ _context20.next = 14;
1428
1651
  break;
1429
1652
  }
1430
1653
  // 如果输入是 NaN 或无穷大,返回原始的待付金额
1431
1654
  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());
1655
+ return _context20.abrupt("return", new Decimal(order.expect_amount).toNumber());
1433
1656
  case 14:
1434
- _context18.prev = 14;
1657
+ _context20.prev = 14;
1435
1658
  inputDecimal = new Decimal(inputAmount);
1436
- return _context18.abrupt("return", new Decimal(order.expect_amount).minus(inputDecimal).toNumber());
1659
+ return _context20.abrupt("return", new Decimal(order.expect_amount).minus(inputDecimal).toNumber());
1437
1660
  case 19:
1438
- _context18.prev = 19;
1439
- _context18.t0 = _context18["catch"](14);
1661
+ _context20.prev = 19;
1662
+ _context20.t0 = _context20["catch"](14);
1440
1663
  // 如果输入不是有效的数字,返回原始的待付金额
1441
1664
  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());
1665
+ return _context20.abrupt("return", new Decimal(order.expect_amount).toNumber());
1443
1666
  case 23:
1444
1667
  case "end":
1445
- return _context18.stop();
1668
+ return _context20.stop();
1446
1669
  }
1447
- }, _callee18, this, [[14, 19]]);
1670
+ }, _callee20, this, [[14, 19]]);
1448
1671
  }));
1449
- function getRemainingOrderAmountWithInputAsync(_x23, _x24) {
1672
+ function getRemainingOrderAmountWithInputAsync(_x26, _x27) {
1450
1673
  return _getRemainingOrderAmountWithInputAsync.apply(this, arguments);
1451
1674
  }
1452
1675
  return getRemainingOrderAmountWithInputAsync;
@@ -1458,12 +1681,33 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1458
1681
  }, {
1459
1682
  key: "recalculateOrderAmount",
1460
1683
  value: function recalculateOrderAmount(order) {
1461
- var totalAmount = new Decimal(order.order_info.total_amount);
1684
+ var totalAmount = new Decimal(order.total_amount);
1462
1685
  var paidAmount = order.payment.reduce(function (sum, payment) {
1463
- return sum.plus(payment.amount);
1686
+ try {
1687
+ // 忽略已撤销的支付项
1688
+ if (payment.status === 'voided') {
1689
+ return sum;
1690
+ }
1691
+ return sum.plus(payment.amount);
1692
+ } catch (error) {
1693
+ console.warn("[PaymentModule] \u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: ".concat(payment.amount, "\uFF0C\u8DF3\u8FC7\u8BA1\u7B97"));
1694
+ return sum;
1695
+ }
1464
1696
  }, new Decimal(0));
1465
1697
  var remainingAmount = totalAmount.minus(paidAmount);
1466
1698
  order.expect_amount = Decimal.max(0, remainingAmount).toFixed(2);
1699
+ console.log("[PaymentModule] \u91CD\u65B0\u8BA1\u7B97\u8BA2\u5355\u91D1\u989D:", {
1700
+ orderUuid: order.uuid,
1701
+ totalAmount: order.total_amount,
1702
+ paidAmount: paidAmount.toFixed(2),
1703
+ remainingAmount: order.expect_amount,
1704
+ activePayments: order.payment.filter(function (p) {
1705
+ return p.status !== 'voided';
1706
+ }).length,
1707
+ voidedPayments: order.payment.filter(function (p) {
1708
+ return p.status === 'voided';
1709
+ }).length
1710
+ });
1467
1711
  }
1468
1712
 
1469
1713
  /**
@@ -1472,29 +1716,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1472
1716
  }, {
1473
1717
  key: "getCashPaymentMethod",
1474
1718
  value: (function () {
1475
- var _getCashPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1719
+ var _getCashPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1476
1720
  var payMethods;
1477
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1478
- while (1) switch (_context19.prev = _context19.next) {
1721
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1722
+ while (1) switch (_context21.prev = _context21.next) {
1479
1723
  case 0:
1480
- _context19.prev = 0;
1481
- _context19.next = 3;
1724
+ _context21.prev = 0;
1725
+ _context21.next = 3;
1482
1726
  return this.dbManager.getAll('pay_method');
1483
1727
  case 3:
1484
- payMethods = _context19.sent;
1485
- return _context19.abrupt("return", payMethods.find(function (method) {
1728
+ payMethods = _context21.sent;
1729
+ return _context21.abrupt("return", payMethods.find(function (method) {
1486
1730
  return method.code === PaymentMethodType.Cash;
1487
1731
  }) || null);
1488
1732
  case 7:
1489
- _context19.prev = 7;
1490
- _context19.t0 = _context19["catch"](0);
1491
- console.error('[PaymentModule] 获取现金支付方式失败', _context19.t0);
1492
- return _context19.abrupt("return", null);
1733
+ _context21.prev = 7;
1734
+ _context21.t0 = _context21["catch"](0);
1735
+ console.error('[PaymentModule] 获取现金支付方式失败', _context21.t0);
1736
+ return _context21.abrupt("return", null);
1493
1737
  case 11:
1494
1738
  case "end":
1495
- return _context19.stop();
1739
+ return _context21.stop();
1496
1740
  }
1497
- }, _callee19, this, [[0, 7]]);
1741
+ }, _callee21, this, [[0, 7]]);
1498
1742
  }));
1499
1743
  function getCashPaymentMethod() {
1500
1744
  return _getCashPaymentMethod.apply(this, arguments);
@@ -1508,29 +1752,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1508
1752
  }, {
1509
1753
  key: "getEftposPaymentMethod",
1510
1754
  value: (function () {
1511
- var _getEftposPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1755
+ var _getEftposPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1512
1756
  var payMethods;
1513
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1514
- while (1) switch (_context20.prev = _context20.next) {
1757
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1758
+ while (1) switch (_context22.prev = _context22.next) {
1515
1759
  case 0:
1516
- _context20.prev = 0;
1517
- _context20.next = 3;
1760
+ _context22.prev = 0;
1761
+ _context22.next = 3;
1518
1762
  return this.dbManager.getAll('pay_method');
1519
1763
  case 3:
1520
- payMethods = _context20.sent;
1521
- return _context20.abrupt("return", payMethods.find(function (method) {
1764
+ payMethods = _context22.sent;
1765
+ return _context22.abrupt("return", payMethods.find(function (method) {
1522
1766
  return method.code === PaymentMethodType.Eftpos;
1523
1767
  }) || null);
1524
1768
  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);
1769
+ _context22.prev = 7;
1770
+ _context22.t0 = _context22["catch"](0);
1771
+ console.error('[PaymentModule] 获取Eftpos支付方式失败', _context22.t0);
1772
+ return _context22.abrupt("return", null);
1529
1773
  case 11:
1530
1774
  case "end":
1531
- return _context20.stop();
1775
+ return _context22.stop();
1532
1776
  }
1533
- }, _callee20, this, [[0, 7]]);
1777
+ }, _callee22, this, [[0, 7]]);
1534
1778
  }));
1535
1779
  function getEftposPaymentMethod() {
1536
1780
  return _getEftposPaymentMethod.apply(this, arguments);
@@ -1544,29 +1788,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1544
1788
  }, {
1545
1789
  key: "getWalletPaymentMethod",
1546
1790
  value: (function () {
1547
- var _getWalletPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1791
+ var _getWalletPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1548
1792
  var payMethods;
1549
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1550
- while (1) switch (_context21.prev = _context21.next) {
1793
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1794
+ while (1) switch (_context23.prev = _context23.next) {
1551
1795
  case 0:
1552
- _context21.prev = 0;
1553
- _context21.next = 3;
1796
+ _context23.prev = 0;
1797
+ _context23.next = 3;
1554
1798
  return this.dbManager.getAll('pay_method');
1555
1799
  case 3:
1556
- payMethods = _context21.sent;
1557
- return _context21.abrupt("return", payMethods.find(function (method) {
1800
+ payMethods = _context23.sent;
1801
+ return _context23.abrupt("return", payMethods.find(function (method) {
1558
1802
  return method.code === PaymentMethodType.Wallet;
1559
1803
  }) || null);
1560
1804
  case 7:
1561
- _context21.prev = 7;
1562
- _context21.t0 = _context21["catch"](0);
1563
- console.error('[PaymentModule] 获取钱包支付方式失败', _context21.t0);
1564
- return _context21.abrupt("return", null);
1805
+ _context23.prev = 7;
1806
+ _context23.t0 = _context23["catch"](0);
1807
+ console.error('[PaymentModule] 获取钱包支付方式失败', _context23.t0);
1808
+ return _context23.abrupt("return", null);
1565
1809
  case 11:
1566
1810
  case "end":
1567
- return _context21.stop();
1811
+ return _context23.stop();
1568
1812
  }
1569
- }, _callee21, this, [[0, 7]]);
1813
+ }, _callee23, this, [[0, 7]]);
1570
1814
  }));
1571
1815
  function getWalletPaymentMethod() {
1572
1816
  return _getWalletPaymentMethod.apply(this, arguments);
@@ -1574,64 +1818,44 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1574
1818
  return getWalletPaymentMethod;
1575
1819
  }()
1576
1820
  /**
1577
- * 注册任务处理函数
1821
+ * 确保支付模块所需的数据库表已创建
1578
1822
  */
1579
1823
  )
1580
- }, {
1581
- key: "registerTaskHandlers",
1582
- value: function registerTaskHandlers() {
1583
- if (this.app.tasksManager) {
1584
- // 注册支付同步任务处理函数
1585
- this.app.tasksManager.addTaskFunction('syncPayment', PaymentModule.syncPaymentTask);
1586
- console.log('[PaymentModule] 任务处理函数已注册');
1587
- } else {
1588
- console.warn('[PaymentModule] TasksManager 未初始化,无法注册任务处理函数');
1589
- }
1590
- }
1591
-
1592
- /**
1593
- * 静态方法:处理支付同步任务(后台网络同步)
1594
- * 这个方法里不允许用 this,因为需要作为静态方法注入到任务队列里
1595
- */
1596
1824
  }, {
1597
1825
  key: "ensurePaymentTables",
1598
- value: (
1599
- /**
1600
- * 确保支付模块所需的数据库表已创建
1601
- */
1602
- 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) {
1826
+ value: (function () {
1827
+ var _ensurePaymentTables = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
1828
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1829
+ while (1) switch (_context24.prev = _context24.next) {
1606
1830
  case 0:
1607
- _context22.prev = 0;
1608
- _context22.next = 3;
1831
+ _context24.prev = 0;
1832
+ _context24.next = 3;
1609
1833
  return this.dbManager.getAll('pay_method');
1610
1834
  case 3:
1611
- _context22.next = 9;
1835
+ _context24.next = 9;
1612
1836
  break;
1613
1837
  case 5:
1614
- _context22.prev = 5;
1615
- _context22.t0 = _context22["catch"](0);
1838
+ _context24.prev = 5;
1839
+ _context24.t0 = _context24["catch"](0);
1616
1840
  console.warn('[PaymentModule] pay_method 表不存在,请在数据库配置中添加以下配置:');
1617
1841
  console.warn('{ name: "pay_method", keyPath: "id" }');
1618
1842
  case 9:
1619
- _context22.prev = 9;
1620
- _context22.next = 12;
1843
+ _context24.prev = 9;
1844
+ _context24.next = 12;
1621
1845
  return this.dbManager.getAll('order');
1622
1846
  case 12:
1623
- _context22.next = 18;
1847
+ _context24.next = 18;
1624
1848
  break;
1625
1849
  case 14:
1626
- _context22.prev = 14;
1627
- _context22.t1 = _context22["catch"](9);
1850
+ _context24.prev = 14;
1851
+ _context24.t1 = _context24["catch"](9);
1628
1852
  console.warn('[PaymentModule] order 表不存在,请在数据库配置中添加以下配置:');
1629
1853
  console.warn('{ name: "order", keyPath: "uuid" }');
1630
1854
  case 18:
1631
1855
  case "end":
1632
- return _context22.stop();
1856
+ return _context24.stop();
1633
1857
  }
1634
- }, _callee22, this, [[0, 5], [9, 14]]);
1858
+ }, _callee24, this, [[0, 5], [9, 14]]);
1635
1859
  }));
1636
1860
  function ensurePaymentTables() {
1637
1861
  return _ensurePaymentTables.apply(this, arguments);
@@ -1645,665 +1869,142 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1645
1869
  }, {
1646
1870
  key: "getPartiallyPaidOrdersAsync",
1647
1871
  value: (function () {
1648
- var _getPartiallyPaidOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1872
+ var _getPartiallyPaidOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1649
1873
  var allOrders;
1650
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1651
- while (1) switch (_context23.prev = _context23.next) {
1874
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1875
+ while (1) switch (_context25.prev = _context25.next) {
1652
1876
  case 0:
1653
- _context23.prev = 0;
1654
- _context23.next = 3;
1877
+ _context25.prev = 0;
1878
+ _context25.next = 3;
1655
1879
  return this.dbManager.getAll('order');
1656
1880
  case 3:
1657
- allOrders = _context23.sent;
1658
- return _context23.abrupt("return", allOrders.filter(function (order) {
1881
+ allOrders = _context25.sent;
1882
+ return _context25.abrupt("return", allOrders.filter(function (order) {
1659
1883
  return order.payment_status === PaymentStatus.PartiallyPaid;
1660
1884
  }));
1661
1885
  case 7:
1662
- _context23.prev = 7;
1663
- _context23.t0 = _context23["catch"](0);
1664
- console.error('[PaymentModule] 获取部分支付订单失败', _context23.t0);
1665
- return _context23.abrupt("return", []);
1886
+ _context25.prev = 7;
1887
+ _context25.t0 = _context25["catch"](0);
1888
+ console.error('[PaymentModule] 获取部分支付订单失败', _context25.t0);
1889
+ return _context25.abrupt("return", []);
1666
1890
  case 11:
1667
1891
  case "end":
1668
- return _context23.stop();
1892
+ return _context25.stop();
1669
1893
  }
1670
- }, _callee23, this, [[0, 7]]);
1894
+ }, _callee25, this, [[0, 7]]);
1671
1895
  }));
1672
1896
  function getPartiallyPaidOrdersAsync() {
1673
1897
  return _getPartiallyPaidOrdersAsync.apply(this, arguments);
1674
1898
  }
1675
1899
  return getPartiallyPaidOrdersAsync;
1676
- }()
1677
- /**
1678
- * 获取未同步到服务器的订单
1679
- */
1680
- )
1681
- }, {
1682
- key: "getUnsyncedOrdersAsync",
1683
- value: (function () {
1684
- var _getUnsyncedOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
1685
- var allOrders;
1686
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1687
- while (1) switch (_context24.prev = _context24.next) {
1688
- case 0:
1689
- _context24.prev = 0;
1690
- _context24.next = 3;
1691
- return this.dbManager.getAll('order');
1692
- case 3:
1693
- allOrders = _context24.sent;
1694
- return _context24.abrupt("return", allOrders.filter(function (order) {
1695
- // 订单已完成或部分支付,但支付项还未同步
1696
- return (order.payment_status === PaymentStatus.Finished || order.payment_status === PaymentStatus.PartiallyPaid) && order.payment.some(function (payment) {
1697
- return !payment.isSynced;
1698
- });
1699
- }));
1700
- case 7:
1701
- _context24.prev = 7;
1702
- _context24.t0 = _context24["catch"](0);
1703
- console.error('[PaymentModule] 获取未同步订单失败', _context24.t0);
1704
- return _context24.abrupt("return", []);
1705
- case 11:
1706
- case "end":
1707
- return _context24.stop();
1708
- }
1709
- }, _callee24, this, [[0, 7]]);
1710
- }));
1711
- function getUnsyncedOrdersAsync() {
1712
- return _getUnsyncedOrdersAsync.apply(this, arguments);
1713
- }
1714
- return getUnsyncedOrdersAsync;
1715
- }()
1900
+ }() // === 新的 API 方法实现 ===
1716
1901
  /**
1717
- * 清理已完成且已同步的订单
1718
- * 注意:只清理完全支付的订单,部分支付的订单保留以便继续支付
1902
+ * 智能金额舍入
1903
+ *
1904
+ * 根据指定的舍入间隔和规则对金额进行舍入处理
1905
+ *
1906
+ * @param originalAmount 原始金额
1907
+ * @param interval 舍入间隔 (0.05, 0.1, 0.5, 1)
1908
+ * @param rule 舍入规则 (standard, standard_down, always_up, always_down)
1909
+ * @returns 舍入后的金额(保留两位小数的字符串)
1719
1910
  */
1720
1911
  )
1721
1912
  }, {
1722
- key: "cleanupFinishedOrders",
1723
- value: (function () {
1724
- var _cleanupFinishedOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1725
- var allOrders, finishedAndSyncedOrders, _iterator6, _step6, order;
1726
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1727
- while (1) switch (_context25.prev = _context25.next) {
1728
- case 0:
1729
- _context25.prev = 0;
1730
- _context25.next = 3;
1731
- return this.dbManager.getAll('order');
1732
- case 3:
1733
- allOrders = _context25.sent;
1734
- finishedAndSyncedOrders = allOrders.filter(function (order) {
1735
- return order.payment_status === PaymentStatus.Finished && order.payment.every(function (payment) {
1736
- return payment.isSynced;
1737
- });
1738
- });
1739
- _iterator6 = _createForOfIteratorHelper(finishedAndSyncedOrders);
1740
- _context25.prev = 6;
1741
- _iterator6.s();
1742
- case 8:
1743
- if ((_step6 = _iterator6.n()).done) {
1744
- _context25.next = 14;
1745
- break;
1746
- }
1747
- order = _step6.value;
1748
- _context25.next = 12;
1749
- return this.deleteOrderAsync(order.uuid);
1750
- case 12:
1751
- _context25.next = 8;
1752
- break;
1753
- case 14:
1754
- _context25.next = 19;
1755
- break;
1756
- case 16:
1757
- _context25.prev = 16;
1758
- _context25.t0 = _context25["catch"](6);
1759
- _iterator6.e(_context25.t0);
1760
- case 19:
1761
- _context25.prev = 19;
1762
- _iterator6.f();
1763
- return _context25.finish(19);
1764
- case 22:
1765
- console.log("[PaymentModule] \u6E05\u7406\u4E86 ".concat(finishedAndSyncedOrders.length, " \u4E2A\u5DF2\u5B8C\u6210\u4E14\u5DF2\u540C\u6B65\u7684\u8BA2\u5355"));
1766
- _context25.next = 28;
1767
- break;
1768
- case 25:
1769
- _context25.prev = 25;
1770
- _context25.t1 = _context25["catch"](0);
1771
- console.error('[PaymentModule] 清理已完成订单失败', _context25.t1);
1772
- case 28:
1773
- case "end":
1774
- return _context25.stop();
1775
- }
1776
- }, _callee25, this, [[0, 25], [6, 16, 19, 22]]);
1777
- }));
1778
- function cleanupFinishedOrders() {
1779
- return _cleanupFinishedOrders.apply(this, arguments);
1780
- }
1781
- return cleanupFinishedOrders;
1782
- }()
1783
- /**
1784
- * 检测未同步的订单并重新加入任务队列
1785
- *
1786
- * 此方法专门用于处理因网络问题导致任务队列执行失败但队列被清空的情况。
1787
- * 它会检查本地 IndexDB 中所有未同步的订单(isSynced: false),
1788
- * 并将这些订单重新添加到任务队列中。
1789
- *
1790
- * 使用场景:
1791
- * - 网络恢复后重新检查未同步的订单
1792
- * - 应用启动时检查并重新排队未完成的支付
1793
- * - 用户手动重试前的预检查
1794
- *
1795
- * @returns Promise<number> 返回重新加入队列的订单数量
1796
- */
1797
- )
1798
- }, {
1799
- key: "recheckAndRequeueUnsyncedOrders",
1800
- value: (function () {
1801
- var _recheckAndRequeueUnsyncedOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
1802
- var unsyncedOrders, requeuedCount, _iterator7, _step7, order, success;
1913
+ key: "roundAmountAsync",
1914
+ value: function () {
1915
+ var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(originalAmount, interval, rule) {
1916
+ var amount, roundingInterval, supportedIntervals, intervalValue, baseValue, roundedValue, finalAmount, result;
1803
1917
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
1804
1918
  while (1) switch (_context26.prev = _context26.next) {
1805
1919
  case 0:
1806
- this.logInfo('Starting recheckAndRequeueUnsyncedOrders');
1807
- _context26.prev = 1;
1808
- if (this.app.tasksManager) {
1809
- _context26.next = 6;
1920
+ _context26.prev = 0;
1921
+ // 参数验证
1922
+ amount = new Decimal(originalAmount);
1923
+ roundingInterval = new Decimal(interval);
1924
+ if (!roundingInterval.lte(0)) {
1925
+ _context26.next = 5;
1810
1926
  break;
1811
1927
  }
1812
- console.warn('[PaymentModule] TasksManager 未初始化,无法重新排队未同步订单');
1813
- this.logWarning('TasksManager not initialized, cannot requeue unsynced orders');
1814
- return _context26.abrupt("return", 0);
1815
- case 6:
1816
- _context26.next = 8;
1817
- return this.getUnsyncedOrdersAsync();
1818
- case 8:
1819
- unsyncedOrders = _context26.sent;
1820
- if (!(unsyncedOrders.length === 0)) {
1821
- _context26.next = 13;
1822
- break;
1928
+ throw new Error('舍入间隔必须大于 0');
1929
+ case 5:
1930
+ // 支持的舍入间隔
1931
+ supportedIntervals = [0.05, 0.1, 0.5, 1];
1932
+ intervalValue = roundingInterval.toNumber();
1933
+ if (!supportedIntervals.includes(intervalValue)) {
1934
+ console.warn("[PaymentModule] \u4E0D\u652F\u6301\u7684\u820D\u5165\u95F4\u9694: ".concat(intervalValue, ", \u652F\u6301\u7684\u95F4\u9694: ").concat(supportedIntervals.join(', ')));
1823
1935
  }
1824
- console.log('[PaymentModule] 没有发现未同步的订单');
1825
- this.logInfo('No unsynced orders found');
1826
- return _context26.abrupt("return", 0);
1936
+
1937
+ // 计算基础值:x / interval
1938
+ baseValue = amount.div(roundingInterval);
1939
+ console.log("[PaymentModule] \u820D\u5165\u8BA1\u7B97 - \u539F\u59CB\u91D1\u989D: ".concat(amount.toString(), ", \u95F4\u9694: ").concat(intervalValue, ", \u57FA\u7840\u503C: ").concat(baseValue.toString(), ", \u89C4\u5219: ").concat(rule));
1940
+ _context26.t0 = rule;
1941
+ _context26.next = _context26.t0 === RoundingRule.Standard ? 13 : _context26.t0 === 'standard' ? 13 : _context26.t0 === RoundingRule.StandardDown ? 15 : _context26.t0 === 'standard_down' ? 15 : _context26.t0 === RoundingRule.AlwaysUp ? 17 : _context26.t0 === 'always_up' ? 17 : _context26.t0 === RoundingRule.AlwaysDown ? 19 : _context26.t0 === 'always_down' ? 19 : 21;
1942
+ break;
1827
1943
  case 13:
1828
- 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
- this.logInfo('Found unsynced orders, adding to sync queue', {
1830
- unsyncedCount: unsyncedOrders.length,
1831
- orderUuids: unsyncedOrders.map(function (o) {
1832
- return o.uuid;
1833
- })
1834
- });
1835
- requeuedCount = 0; // 将未同步的订单重新添加到任务队列
1836
- _iterator7 = _createForOfIteratorHelper(unsyncedOrders);
1837
- _context26.prev = 17;
1838
- _iterator7.s();
1944
+ // 标准舍入(中点向上)
1945
+ roundedValue = this.standardRound(baseValue, true);
1946
+ return _context26.abrupt("break", 22);
1947
+ case 15:
1948
+ // 标准舍入(中点向下)
1949
+ roundedValue = this.standardRound(baseValue, false);
1950
+ return _context26.abrupt("break", 22);
1951
+ case 17:
1952
+ // 总是向上舍入
1953
+ roundedValue = baseValue.ceil();
1954
+ return _context26.abrupt("break", 22);
1839
1955
  case 19:
1840
- if ((_step7 = _iterator7.n()).done) {
1841
- _context26.next = 27;
1842
- break;
1843
- }
1844
- order = _step7.value;
1845
- _context26.next = 23;
1846
- return this.reAddOrderToSyncQueue(order);
1847
- case 23:
1848
- success = _context26.sent;
1849
- if (success) {
1850
- requeuedCount++;
1851
- }
1852
- case 25:
1853
- _context26.next = 19;
1854
- break;
1855
- case 27:
1856
- _context26.next = 32;
1857
- break;
1858
- case 29:
1859
- _context26.prev = 29;
1860
- _context26.t0 = _context26["catch"](17);
1861
- _iterator7.e(_context26.t0);
1956
+ // 总是向下舍入
1957
+ roundedValue = baseValue.floor();
1958
+ return _context26.abrupt("break", 22);
1959
+ case 21:
1960
+ throw new Error("\u4E0D\u652F\u6301\u7684\u820D\u5165\u89C4\u5219: ".concat(rule));
1961
+ case 22:
1962
+ // 计算最终金额:roundedValue * interval
1963
+ finalAmount = roundedValue.mul(roundingInterval);
1964
+ result = finalAmount.toFixed(2);
1965
+ console.log("[PaymentModule] \u820D\u5165\u7ED3\u679C - \u820D\u5165\u503C: ".concat(roundedValue.toString(), ", \u6700\u7EC8\u91D1\u989D: ").concat(result));
1966
+ return _context26.abrupt("return", result);
1967
+ case 28:
1968
+ _context26.prev = 28;
1969
+ _context26.t1 = _context26["catch"](0);
1970
+ console.error('[PaymentModule] 金额舍入失败:', _context26.t1);
1971
+ throw new Error("\u91D1\u989D\u820D\u5165\u5931\u8D25: ".concat(_context26.t1 instanceof Error ? _context26.t1.message : String(_context26.t1)));
1862
1972
  case 32:
1863
- _context26.prev = 32;
1864
- _iterator7.f();
1865
- return _context26.finish(32);
1866
- case 35:
1867
- console.log("[PaymentModule] \u6210\u529F\u91CD\u65B0\u52A0\u5165 ".concat(requeuedCount, " \u4E2A\u8BA2\u5355\u5230\u4EFB\u52A1\u961F\u5217"));
1868
- this.logInfo('Successfully requeued unsynced orders', {
1869
- requeuedCount: requeuedCount,
1870
- totalFound: unsyncedOrders.length
1871
- });
1872
- return _context26.abrupt("return", requeuedCount);
1873
- 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);
1879
- case 45:
1880
1973
  case "end":
1881
1974
  return _context26.stop();
1882
1975
  }
1883
- }, _callee26, this, [[1, 40], [17, 29, 32, 35]]);
1884
- }));
1885
- function recheckAndRequeueUnsyncedOrders() {
1886
- return _recheckAndRequeueUnsyncedOrders.apply(this, arguments);
1887
- }
1888
- return recheckAndRequeueUnsyncedOrders;
1889
- }()
1890
- /**
1891
- * 手动执行支付同步队列
1892
- * 外部可以调用此方法来触发支付同步任务的执行
1893
- *
1894
- * 注意:此方法只执行现有队列中的任务,不会检查未同步的订单。
1895
- * 如果需要检查未同步订单,请先调用 recheckAndRequeueUnsyncedOrders()
1896
- *
1897
- * 使用示例:
1898
- * ```typescript
1899
- * // 1. 先检查并重新排队未同步订单,然后执行队列
1900
- * const requeuedCount = await paymentModule.recheckAndRequeueUnsyncedOrders();
1901
- * if (requeuedCount > 0) {
1902
- * await paymentModule.runPaymentSyncQueue();
1903
- * }
1904
- *
1905
- * // 2. 或者直接执行现有队列(不检查未同步订单)
1906
- * await paymentModule.runPaymentSyncQueue();
1907
- * ```
1908
- */
1909
- )
1910
- }, {
1911
- key: "runPaymentSyncQueue",
1912
- value: (function () {
1913
- var _runPaymentSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
1914
- var _this3 = this;
1915
- var queue;
1916
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
1917
- while (1) switch (_context27.prev = _context27.next) {
1918
- case 0:
1919
- this.logInfo('Starting runPaymentSyncQueue');
1920
- _context27.prev = 1;
1921
- if (this.app.tasksManager) {
1922
- _context27.next = 6;
1923
- break;
1924
- }
1925
- console.warn('[PaymentModule] TasksManager 未初始化,无法执行同步队列');
1926
- this.logWarning('TasksManager not initialized, cannot run sync queue');
1927
- return _context27.abrupt("return");
1928
- case 6:
1929
- // 检查队列里有没有要跑的东西,没有就不 run 了
1930
- queue = this.app.tasksManager.getTaskQueue({
1931
- module: 'payment',
1932
- queueId: 'payment_sync'
1933
- });
1934
- if (queue !== null && queue !== void 0 && queue.length) {
1935
- _context27.next = 10;
1936
- break;
1937
- }
1938
- console.log('[PaymentModule] 支付同步队列无内容,不执行');
1939
- return _context27.abrupt("return");
1940
- case 10:
1941
- console.log('[PaymentModule] 开始执行支付同步队列');
1942
- _context27.next = 13;
1943
- return this.app.tasksManager.run({
1944
- module: 'payment',
1945
- queueId: 'payment_sync',
1946
- callback: function callback() {
1947
- console.log('[PaymentModule] 支付同步队列执行完成');
1948
- if (_this3.logger) {
1949
- _this3.logger.addLog({
1950
- type: 'info',
1951
- title: '[PaymentModule] Payment sync queue completed',
1952
- metadata: {}
1953
- });
1954
- }
1955
- }
1956
- });
1957
- case 13:
1958
- this.logInfo('runPaymentSyncQueue completed successfully');
1959
- _context27.next = 20;
1960
- break;
1961
- 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);
1966
- // 不抛出错误,避免影响主流程
1967
- case 20:
1968
- case "end":
1969
- return _context27.stop();
1970
- }
1971
- }, _callee27, this, [[1, 16]]);
1976
+ }, _callee26, this, [[0, 28]]);
1972
1977
  }));
1973
- function runPaymentSyncQueue() {
1974
- return _runPaymentSyncQueue.apply(this, arguments);
1978
+ function roundAmountAsync(_x28, _x29, _x30) {
1979
+ return _roundAmountAsync.apply(this, arguments);
1975
1980
  }
1976
- return runPaymentSyncQueue;
1981
+ return roundAmountAsync;
1977
1982
  }()
1978
1983
  /**
1979
- * 重新将订单添加到同步队列
1980
- * 用于处理因网络问题导致任务队列清空但订单未同步的情况
1981
- *
1982
- * @param order 要重新添加的订单
1983
- * @returns Promise<boolean> 是否成功添加到队列
1984
+ * 标准舍入处理(处理中点情况)
1985
+ *
1986
+ * @param value 要舍入的值
1987
+ * @param midpointUp 中点是否向上舍入
1988
+ * @returns 舍入后的值
1984
1989
  */
1985
- )
1986
1990
  }, {
1987
- key: "reAddOrderToSyncQueue",
1988
- value: (function () {
1989
- var _reAddOrderToSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(order) {
1990
- var paymentData, existingQueue, taskId, taskExists;
1991
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
1992
- while (1) switch (_context28.prev = _context28.next) {
1993
- case 0:
1994
- _context28.prev = 0;
1995
- // 构造支付数据
1996
- paymentData = {
1997
- payments: order.payment.map(function (payment) {
1998
- return {
1999
- uuid: payment.uuid,
2000
- amount: payment.amount,
2001
- code: payment.code,
2002
- id: payment.id,
2003
- name: payment.name,
2004
- type: payment.type,
2005
- voucher_id: payment.voucher_id,
2006
- metadata: payment.metadata,
2007
- rounding_amount: payment.rounding_amount,
2008
- service_charge: payment.service_charge
2009
- };
2010
- }),
2011
- payment_status: order.payment_status === PaymentStatus.Finished ? 'paid' : 'partially_paid'
2012
- }; // 检查是否已经在队列中,避免重复添加
2013
- existingQueue = this.app.tasksManager.getTaskQueue({
2014
- module: 'payment',
2015
- queueId: 'payment_sync'
2016
- });
2017
- taskId = "payment_".concat(order.uuid);
2018
- taskExists = existingQueue === null || existingQueue === void 0 ? void 0 : existingQueue.some(function (task) {
2019
- return task.id === taskId;
2020
- });
2021
- if (!taskExists) {
2022
- _context28.next = 8;
2023
- break;
2024
- }
2025
- 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);
2027
- case 8:
2028
- _context28.next = 10;
2029
- return this.addToSyncQueue(order, paymentData);
2030
- case 10:
2031
- console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u5DF2\u91CD\u65B0\u6DFB\u52A0\u5230\u540C\u6B65\u961F\u5217"));
2032
- this.logInfo('Order re-added to sync queue', {
2033
- orderUuid: order.uuid,
2034
- orderId: order.order_info.order_id,
2035
- paymentStatus: order.payment_status,
2036
- unsyncedPayments: order.payment.filter(function (p) {
2037
- return !p.isSynced;
2038
- }).length
2039
- });
2040
- return _context28.abrupt("return", true);
2041
- 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, {
2046
- orderUuid: order.uuid,
2047
- orderId: order.order_info.order_id
2048
- });
2049
- return _context28.abrupt("return", false);
2050
- case 20:
2051
- case "end":
2052
- return _context28.stop();
2053
- }
2054
- }, _callee28, this, [[0, 15]]);
2055
- }));
2056
- function reAddOrderToSyncQueue(_x25) {
2057
- return _reAddOrderToSyncQueue.apply(this, arguments);
2058
- }
2059
- return reAddOrderToSyncQueue;
2060
- }())
2061
- }], [{
2062
- key: "syncPaymentTask",
2063
- value: (function () {
2064
- var _syncPaymentTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(payload) {
2065
- 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) {
2068
- case 0:
2069
- _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
- console.log("[PaymentModule] \u5F00\u59CB\u540E\u53F0\u540C\u6B65\u652F\u4ED8\uFF0C\u8BA2\u5355ID: ".concat(orderId));
2071
-
2072
- // 生成request_unique: 年月日时分秒毫秒+4位随机数
2073
- paymentData.request_unique = generateRequestUniqueId();
2074
-
2075
- // 从全局获取必要的实例
2076
- app = window.app;
2077
- logger = app === null || app === void 0 ? void 0 : app.logger; // 记录开始日志
2078
- if (logger) {
2079
- logger.addLog({
2080
- type: 'info',
2081
- title: '[PaymentModule] Starting syncPaymentTask',
2082
- metadata: {
2083
- orderUuid: orderUuid,
2084
- orderId: orderId,
2085
- paymentDataKeys: Object.keys(paymentData)
2086
- }
2087
- });
2088
- }
2089
- if (app) {
2090
- _context29.next = 8;
2091
- break;
2092
- }
2093
- throw new Error('App 实例未找到');
2094
- case 8:
2095
- request = app.request;
2096
- if (request) {
2097
- _context29.next = 11;
2098
- break;
2099
- }
2100
- throw new Error('Request 插件未找到');
2101
- case 11:
2102
- dbManager = app.dbManager;
2103
- if (dbManager) {
2104
- _context29.next = 14;
2105
- break;
2106
- }
2107
- throw new Error('DBManager 未找到');
2108
- case 14:
2109
- _context29.prev = 14;
2110
- _context29.next = 17;
2111
- return request.post("/shop/order/".concat(orderId, "/order-payment"), paymentData, {
2112
- noToast: true
2113
- });
2114
- case 17:
2115
- requestRes = _context29.sent;
2116
- if (!(requestRes.status === true)) {
2117
- _context29.next = 35;
2118
- break;
2119
- }
2120
- _context29.next = 21;
2121
- return dbManager.get('order', orderUuid);
2122
- case 21:
2123
- order = _context29.sent;
2124
- if (!order) {
2125
- _context29.next = 27;
2126
- break;
2127
- }
2128
- order.payment.forEach(function (payment) {
2129
- payment.isSynced = true;
2130
- // 清除之前的错误状态
2131
- delete payment.syncError;
2132
- });
2133
- _context29.next = 26;
2134
- return dbManager.update('order', order);
2135
- case 26:
2136
- console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u72B6\u6001\u5DF2\u66F4\u65B0"));
2137
- case 27:
2138
- console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u540E\u53F0\u540C\u6B65\u6210\u529F"));
2139
- _context29.next = 30;
2140
- return core.effects.emit('payment:onPaymentSyncSuccess', {
2141
- orderUuid: orderUuid,
2142
- orderId: orderId,
2143
- timestamp: Date.now()
2144
- });
2145
- case 30:
2146
- console.log("[PaymentModule] \u5DF2\u901A\u8FC7 effects \u901A\u77E5\u524D\u7AEF\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u6210\u529F"));
2147
-
2148
- // 记录成功日志
2149
- if (logger) {
2150
- logger.addLog({
2151
- type: 'info',
2152
- title: '[PaymentModule] syncPaymentTask completed successfully',
2153
- metadata: {
2154
- orderUuid: orderUuid,
2155
- orderId: orderId
2156
- }
2157
- });
2158
- }
2159
- return _context29.abrupt("return", {
2160
- status: 'success',
2161
- orderUuid: orderUuid,
2162
- orderId: orderId
2163
- });
2164
- case 35:
2165
- // 接口返回失败,视为业务错误处理
2166
- console.log("[PaymentModule] \u63A5\u53E3\u8FD4\u56DE\u5931\u8D25\uFF0C\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u5931\u8D25"));
2167
-
2168
- // 模拟业务错误,抛出一个包含响应信息的错误
2169
- businessError = new Error(requestRes.message || '接口返回失败');
2170
- businessError.response = {
2171
- status: 200
2172
- }; // HTTP 状态码是 200,但业务失败
2173
- businessError.isBusinessError = true;
2174
- businessError.responseData = requestRes;
2175
- throw businessError;
2176
- case 41:
2177
- _context29.next = 80;
2178
- break;
2179
- case 43:
2180
- _context29.prev = 43;
2181
- _context29.t0 = _context29["catch"](14);
2182
- console.error('[PaymentModule] 后台同步失败:', _context29.t0);
2183
-
2184
- // 检查是否是网络错误(没有响应码)还是业务错误(有响应码)
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')));
2186
- if (!isNetworkError) {
2187
- _context29.next = 53;
2188
- break;
2189
- }
2190
- // 网络错误:重试
2191
- console.log("[PaymentModule] \u7F51\u7EDC\u9519\u8BEF\uFF0C\u8BA2\u5355 ".concat(orderUuid, " \u5C06\u91CD\u8BD5\u540C\u6B65"));
1991
+ key: "standardRound",
1992
+ value: function standardRound(value, midpointUp) {
1993
+ var floorValue = value.floor();
1994
+ var fractionalPart = value.minus(floorValue);
2192
1995
 
2193
- // 记录网络错误日志
2194
- if (logger) {
2195
- logger.addLog({
2196
- type: 'warning',
2197
- title: '[PaymentModule] syncPaymentTask network error - will retry',
2198
- metadata: {
2199
- orderUuid: orderUuid,
2200
- orderId: orderId,
2201
- errorCode: _context29.t0.code,
2202
- errorMessage: _context29.t0.message
2203
- }
2204
- });
2205
- }
2206
- throw _context29.t0;
2207
- case 53:
2208
- // 业务错误(有响应码):不标记为已同步,通过 effects 通知前端,但不重试
2209
- 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;
2211
- if (!(core && core.effects)) {
2212
- _context29.next = 63;
2213
- break;
2214
- }
2215
- // 通过 effects 通知前端同步错误
2216
- errorData = {
2217
- orderUuid: orderUuid,
2218
- 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,
2222
- timestamp: Date.now()
2223
- }; // 如果是业务错误,添加响应数据
2224
- if (_context29.t0.isBusinessError && _context29.t0.responseData) {
2225
- errorData.error = _context29.t0.responseData.message || _context29.t0.message || '接口返回失败';
2226
- // 可以添加更多响应数据
2227
- errorData.responseData = _context29.t0.responseData;
2228
- }
2229
- _context29.next = 60;
2230
- return core.effects.emit('payment:onPaymentSyncError', errorData);
2231
- case 60:
2232
- console.log("[PaymentModule] \u5DF2\u901A\u8FC7 effects \u901A\u77E5\u524D\u7AEF\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u9519\u8BEF"));
2233
- _context29.next = 64;
2234
- break;
2235
- case 63:
2236
- console.warn("[PaymentModule] \u65E0\u6CD5\u83B7\u53D6 core \u5B9E\u4F8B\uFF0C\u65E0\u6CD5\u901A\u77E5\u524D\u7AEF\u9519\u8BEF");
2237
- case 64:
2238
- // 记录业务错误日志
2239
- if (logger) {
2240
- logger.addLog({
2241
- type: 'error',
2242
- title: '[PaymentModule] syncPaymentTask business error',
2243
- metadata: {
2244
- orderUuid: orderUuid,
2245
- 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
2250
- }
2251
- });
2252
- }
2253
- _context29.next = 71;
2254
- break;
2255
- 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);
2259
-
2260
- // 记录通知错误日志
2261
- if (logger) {
2262
- logger.addLog({
2263
- type: 'error',
2264
- title: '[PaymentModule] Failed to notify frontend of sync error',
2265
- metadata: {
2266
- orderUuid: orderUuid,
2267
- orderId: orderId,
2268
- notifyError: _context29.t1 instanceof Error ? _context29.t1.message : String(_context29.t1)
2269
- }
2270
- });
2271
- }
2272
- case 71:
2273
- _context29.next = 73;
2274
- return dbManager.get('order', orderUuid);
2275
- case 73:
2276
- _order2 = _context29.sent;
2277
- if (!_order2) {
2278
- _context29.next = 79;
2279
- break;
2280
- }
2281
- _order2.payment.forEach(function (payment) {
2282
- payment.isSynced = true;
2283
- });
2284
- _context29.next = 78;
2285
- return dbManager.update('order', _order2);
2286
- case 78:
2287
- console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u4E1A\u52A1\u9519\u8BEF\uFF0C\u5DF2\u6807\u8BB0\u4E3A\u5DF2\u540C\u6B65"));
2288
- case 79:
2289
- return _context29.abrupt("return", {
2290
- status: 'completed_with_error',
2291
- orderUuid: orderUuid,
2292
- 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
2295
- });
2296
- case 80:
2297
- case "end":
2298
- return _context29.stop();
2299
- }
2300
- }, _callee29, null, [[14, 43], [54, 67]]);
2301
- }));
2302
- function syncPaymentTask(_x26) {
2303
- return _syncPaymentTask.apply(this, arguments);
1996
+ // 检查是否是中点(小数部分 = 0.5)
1997
+ if (fractionalPart.eq(0.5)) {
1998
+ // 中点情况,根据规则决定
1999
+ return midpointUp ? floorValue.plus(1) : floorValue;
2000
+ } else if (fractionalPart.gt(0.5)) {
2001
+ // 大于中点,向上舍入
2002
+ return floorValue.plus(1);
2003
+ } else {
2004
+ // 小于中点,向下舍入
2005
+ return floorValue;
2304
2006
  }
2305
- return syncPaymentTask;
2306
- }())
2007
+ }
2307
2008
  }]);
2308
2009
  return PaymentModule;
2309
2010
  }(BaseModule);