@pisell/pisellos 0.0.252 → 0.0.253

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.
@@ -1,3 +1,4 @@
1
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
1
2
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
3
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
4
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -27,8 +28,8 @@ import { BaseModule } from "../../modules/BaseModule";
27
28
  import { OrderModule } from "../../modules/Order";
28
29
  import { PaymentModule } from "../../modules/Payment";
29
30
  import { CheckoutStatus, CheckoutStep, CheckoutHooks, CheckoutErrorType } from "./types";
30
- import { PaymentStatus, PaymentHooks, PaymentMethodType } from "../../modules/Payment/types";
31
- import { validateCheckoutData, createCheckoutError, calculateProgress } from "./utils";
31
+ import { PaymentStatus, PaymentHooks } from "../../modules/Payment/types";
32
+ import { validateCheckoutData, createCheckoutError, calculateProgress, validateLocalOrderData, generateLocalOrderId, formatDateTime, extractAmountFromCartSummary, calculateTotalAmount, isVirtualOrderId } from "./utils";
32
33
  export * from "./types";
33
34
 
34
35
  /**
@@ -50,6 +51,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
50
51
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
51
52
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
52
53
  _defineProperty(_assertThisInitialized(_this), "otherParams", {});
54
+ _defineProperty(_assertThisInitialized(_this), "logger", void 0);
55
+ // LoggerManager 实例
53
56
  // 直接挂载的模块
54
57
  _defineProperty(_assertThisInitialized(_this), "order", void 0);
55
58
  _defineProperty(_assertThisInitialized(_this), "payment", void 0);
@@ -73,6 +76,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
73
76
  }
74
77
  throw new Error('Checkout 解决方案需要 request 插件支持');
75
78
  case 5:
79
+ // 获取 logger 实例
80
+ this.logger = core.getPlugin('logger');
81
+
76
82
  // 初始化模块
77
83
  this.order = new OrderModule();
78
84
  this.payment = new PaymentModule();
@@ -91,21 +97,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
91
97
  };
92
98
 
93
99
  // 注册并初始化子模块
94
- _context.next = 10;
100
+ _context.next = 11;
95
101
  return this.initializeSubModules(core, options);
96
- case 10:
97
- _context.next = 12;
102
+ case 11:
103
+ _context.next = 13;
98
104
  return this.preloadPaymentMethods();
99
- case 12:
100
- _context.next = 14;
101
- return this.setStatus(CheckoutStatus.Ready);
102
- case 14:
105
+ case 13:
106
+ _context.next = 15;
107
+ return this.cleanupExpiredOrdersAsync();
108
+ case 15:
109
+ // 设置状态为就绪
110
+ this.setStatus(CheckoutStatus.Ready);
103
111
  console.log('[Checkout] 初始化完成');
104
- _context.next = 17;
112
+ _context.next = 19;
105
113
  return this.core.effects.emit(CheckoutHooks.OnCheckoutInitialized, {
106
114
  timestamp: Date.now()
107
115
  });
108
- case 17:
116
+ case 19:
117
+ this.logInfo('CheckoutModule initialized successfully');
118
+ case 20:
109
119
  case "end":
110
120
  return _context.stop();
111
121
  }
@@ -116,6 +126,51 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
116
126
  }
117
127
  return initialize;
118
128
  }()
129
+ /**
130
+ * 记录信息日志
131
+ */
132
+ }, {
133
+ key: "logInfo",
134
+ value: function logInfo(title, metadata) {
135
+ if (this.logger) {
136
+ this.logger.addLog({
137
+ type: 'info',
138
+ title: "[CheckoutModule] ".concat(title),
139
+ metadata: metadata || {}
140
+ });
141
+ }
142
+ }
143
+
144
+ /**
145
+ * 记录警告日志
146
+ */
147
+ }, {
148
+ key: "logWarning",
149
+ value: function logWarning(title, metadata) {
150
+ if (this.logger) {
151
+ this.logger.addLog({
152
+ type: 'warning',
153
+ title: "[CheckoutModule] ".concat(title),
154
+ metadata: metadata || {}
155
+ });
156
+ }
157
+ }
158
+
159
+ /**
160
+ * 记录错误日志
161
+ */
162
+ }, {
163
+ key: "logError",
164
+ value: function logError(title, metadata) {
165
+ if (this.logger) {
166
+ this.logger.addLog({
167
+ type: 'error',
168
+ title: "[CheckoutModule] ".concat(title),
169
+ metadata: metadata || {}
170
+ });
171
+ }
172
+ }
173
+
119
174
  /**
120
175
  * 初始化子模块
121
176
  */
@@ -261,14 +316,19 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
261
316
  key: "initializeCheckoutAsync",
262
317
  value: (function () {
263
318
  var _initializeCheckoutAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
319
+ var _params$cartItems;
264
320
  var validation;
265
321
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
266
322
  while (1) switch (_context7.prev = _context7.next) {
267
323
  case 0:
268
- _context7.prev = 0;
269
- _context7.next = 3;
270
- return this.setStatus(CheckoutStatus.Initializing);
271
- case 3:
324
+ this.logInfo('initializeCheckoutAsync called', {
325
+ cartItemsCount: ((_params$cartItems = params.cartItems) === null || _params$cartItems === void 0 ? void 0 : _params$cartItems.length) || 0,
326
+ orderType: params.orderType,
327
+ platform: params.platform
328
+ });
329
+ _context7.prev = 1;
330
+ this.setStatus(CheckoutStatus.Initializing);
331
+
272
332
  // 验证参数
273
333
  validation = this.validateCheckoutParams(params);
274
334
  if (validation.valid) {
@@ -281,27 +341,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
281
341
  this.store.cartItems = params.cartItems;
282
342
 
283
343
  // 设置为就绪状态
284
- _context7.next = 9;
285
- return this.setStatus(CheckoutStatus.Ready);
286
- case 9:
287
- _context7.next = 11;
288
- return this.setStep(CheckoutStep.OrderConfirmation);
289
- case 11:
344
+ this.setStatus(CheckoutStatus.Ready);
345
+ this.setStep(CheckoutStep.OrderConfirmation);
290
346
  console.log('[Checkout] 结账流程初始化完成');
291
- _context7.next = 19;
347
+ _context7.next = 17;
292
348
  break;
293
- case 14:
294
- _context7.prev = 14;
295
- _context7.t0 = _context7["catch"](0);
296
- _context7.next = 18;
349
+ case 12:
350
+ _context7.prev = 12;
351
+ _context7.t0 = _context7["catch"](1);
352
+ _context7.next = 16;
297
353
  return this.handleError(_context7.t0, CheckoutErrorType.UnknownError);
298
- case 18:
354
+ case 16:
299
355
  throw _context7.t0;
300
- case 19:
356
+ case 17:
301
357
  case "end":
302
358
  return _context7.stop();
303
359
  }
304
- }, _callee7, this, [[0, 14]]);
360
+ }, _callee7, this, [[1, 12]]);
305
361
  }));
306
362
  function initializeCheckoutAsync(_x9) {
307
363
  return _initializeCheckoutAsync.apply(this, arguments);
@@ -399,31 +455,43 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
399
455
  key: "createLocalOrderAsync",
400
456
  value: (function () {
401
457
  var _createLocalOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
458
+ var _params$orderData, _params$orderData2, _params$orderData3, _params$orderData4, _params$orderData5, _params$cartSummary;
402
459
  var _params$totalInfo, _params$totalInfo2, _params$totalInfo3, _params$totalInfo4, validation, localOrderId, amountInfo, customerInfo, paymentOrder;
403
460
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
404
461
  while (1) switch (_context9.prev = _context9.next) {
405
462
  case 0:
406
- _context9.prev = 0;
407
- _context9.next = 3;
408
- return this.resetStoreStateAsync();
409
- case 3:
463
+ this.logInfo('createLocalOrderAsync called', {
464
+ orderDataType: (_params$orderData = params.orderData) === null || _params$orderData === void 0 ? void 0 : _params$orderData.type,
465
+ platform: (_params$orderData2 = params.orderData) === null || _params$orderData2 === void 0 ? void 0 : _params$orderData2.platform,
466
+ bookingsCount: ((_params$orderData3 = params.orderData) === null || _params$orderData3 === void 0 || (_params$orderData3 = _params$orderData3.bookings) === null || _params$orderData3 === void 0 ? void 0 : _params$orderData3.length) || 0,
467
+ relationProductsCount: ((_params$orderData4 = params.orderData) === null || _params$orderData4 === void 0 || (_params$orderData4 = _params$orderData4.relation_products) === null || _params$orderData4 === void 0 ? void 0 : _params$orderData4.length) || 0,
468
+ customerId: (_params$orderData5 = params.orderData) === null || _params$orderData5 === void 0 ? void 0 : _params$orderData5.customer_id,
469
+ autoPayment: params.autoPayment,
470
+ cartSummaryCount: ((_params$cartSummary = params.cartSummary) === null || _params$cartSummary === void 0 ? void 0 : _params$cartSummary.length) || 0,
471
+ totalInfoKeys: params.totalInfo ? Object.keys(params.totalInfo) : []
472
+ });
473
+ _context9.prev = 1;
474
+ console.time('createLocalOrderAsync');
475
+ // 🔧 修改:在创建新订单前,直接重置 store 状态
410
476
  _context9.next = 5;
411
- return this.setStatus(CheckoutStatus.CreatingOrder);
477
+ return this.resetStoreStateAsync();
412
478
  case 5:
479
+ this.setStatus(CheckoutStatus.CreatingOrder);
480
+
413
481
  // 验证订单数据
414
- validation = this.validateLocalOrderData(params.orderData);
482
+ validation = validateLocalOrderData(params.orderData);
415
483
  if (validation.valid) {
416
- _context9.next = 8;
484
+ _context9.next = 9;
417
485
  break;
418
486
  }
419
487
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u8BA2\u5355\u6570\u636E\u9A8C\u8BC1\u5931\u8D25: ".concat(validation.errors.join(', ')));
420
- case 8:
488
+ case 9:
421
489
  // 生成本地虚拟订单ID (后续可以被真实订单ID替换)
422
- localOrderId = this.generateLocalOrderId(); // 从购物车小计数据中提取金额信息
423
- amountInfo = this.extractAmountFromCartSummary(params.cartSummary); // TODO: 外面传的是 pos ,但是现在 后端只有 shop 和 kiosk
490
+ localOrderId = generateLocalOrderId(); // 从购物车小计数据中提取金额信息
491
+ amountInfo = extractAmountFromCartSummary(params.cartSummary); // TODO: 外面传的是 pos ,但是现在 后端只有 shop 和 kiosk
424
492
  params.orderData.platform = 'pos';
425
493
  // 补充 created_at 时间 (YYYY-MM-DD hh:mm:ss 格式)
426
- params.orderData.created_at = this.formatDateTime(new Date());
494
+ params.orderData.created_at = formatDateTime(new Date());
427
495
  // 补充附加费信息
428
496
  params.orderData.surcharge_fee = (_params$totalInfo = params.totalInfo) === null || _params$totalInfo === void 0 || (_params$totalInfo = _params$totalInfo.total) === null || _params$totalInfo === void 0 ? void 0 : _params$totalInfo.otherAmount;
429
497
  params.orderData.surcharges = (_params$totalInfo2 = params.totalInfo) === null || _params$totalInfo2 === void 0 || (_params$totalInfo2 = _params$totalInfo2.total) === null || _params$totalInfo2 === void 0 ? void 0 : _params$totalInfo2.surcharge;
@@ -450,7 +518,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
450
518
  }
451
519
 
452
520
  // 创建支付订单对象
453
- _context9.next = 22;
521
+ _context9.next = 23;
454
522
  return this.payment.createPaymentOrderAsync({
455
523
  order_id: localOrderId,
456
524
  total_amount: amountInfo.totalAmount,
@@ -467,32 +535,27 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
467
535
  amount_breakdown: amountInfo
468
536
  }
469
537
  });
470
- case 22:
538
+ case 23:
471
539
  paymentOrder = _context9.sent;
540
+ console.timeEnd('createLocalOrderAsync');
472
541
  this.store.currentOrder = paymentOrder;
473
542
  this.initWalletData();
474
- _context9.next = 27;
475
- return this.setStatus(CheckoutStatus.OrderCreated);
476
- case 27:
477
- _context9.next = 29;
478
- return this.setStep(CheckoutStep.PaymentMethod);
479
- case 29:
480
- if (!params.autoPayment) {
481
- _context9.next = 32;
482
- break;
543
+ this.setStatus(CheckoutStatus.OrderCreated);
544
+ this.setStep(CheckoutStep.PaymentMethod);
545
+
546
+ // 如果设置了自动支付,直接跳转到支付步骤
547
+ if (params.autoPayment) {
548
+ this.setStep(CheckoutStep.PaymentProcessing);
483
549
  }
484
- _context9.next = 32;
485
- return this.setStep(CheckoutStep.PaymentProcessing);
486
- case 32:
487
550
  this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
488
551
  order: paymentOrder,
489
552
  timestamp: Date.now()
490
553
  });
491
554
 
492
555
  // 自动设置 stateAmount 为剩余未支付金额
493
- _context9.next = 35;
556
+ _context9.next = 33;
494
557
  return this.updateStateAmountToRemaining();
495
- case 35:
558
+ case 33:
496
559
  console.log('[Checkout] 本地订单创建成功:', {
497
560
  localOrderId: localOrderId,
498
561
  uuid: paymentOrder.uuid,
@@ -502,22 +565,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
502
565
  stateAmount: this.store.stateAmount
503
566
  });
504
567
  return _context9.abrupt("return", paymentOrder);
505
- case 39:
506
- _context9.prev = 39;
507
- _context9.t0 = _context9["catch"](0);
508
- _context9.next = 43;
568
+ case 37:
569
+ _context9.prev = 37;
570
+ _context9.t0 = _context9["catch"](1);
571
+ _context9.next = 41;
509
572
  return this.handleError(_context9.t0, CheckoutErrorType.OrderCreationFailed);
510
- case 43:
573
+ case 41:
511
574
  this.core.effects.emit(CheckoutHooks.OnOrderCreationFailed, {
512
575
  error: this.store.lastError,
513
576
  timestamp: Date.now()
514
577
  });
515
578
  throw _context9.t0;
516
- case 45:
579
+ case 43:
517
580
  case "end":
518
581
  return _context9.stop();
519
582
  }
520
- }, _callee9, this, [[0, 39]]);
583
+ }, _callee9, this, [[1, 37]]);
521
584
  }));
522
585
  function createLocalOrderAsync(_x11) {
523
586
  return _createLocalOrderAsync.apply(this, arguments);
@@ -534,6 +597,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
534
597
  key: "placeOrderAsync",
535
598
  value: (function () {
536
599
  var _placeOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
600
+ var _this$store$currentOr5;
537
601
  var params,
538
602
  _data,
539
603
  orderData,
@@ -546,23 +610,30 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
546
610
  while (1) switch (_context10.prev = _context10.next) {
547
611
  case 0:
548
612
  params = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : {};
549
- _context10.prev = 1;
613
+ this.logInfo('placeOrderAsync called', {
614
+ url: params.url,
615
+ autoReplaceOrderId: params.autoReplaceOrderId,
616
+ hasLocalOrderData: !!this.store.localOrderData,
617
+ hasCurrentOrder: !!this.store.currentOrder,
618
+ currentOrderId: (_this$store$currentOr5 = this.store.currentOrder) === null || _this$store$currentOr5 === void 0 ? void 0 : _this$store$currentOr5.order_id,
619
+ isOrderSynced: this.store.isOrderSynced
620
+ });
621
+ _context10.prev = 2;
550
622
  if (this.store.localOrderData) {
551
- _context10.next = 4;
623
+ _context10.next = 5;
552
624
  break;
553
625
  }
554
626
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '没有找到本地订单数据,请先调用 createLocalOrderAsync 创建虚拟订单');
555
- case 4:
627
+ case 5:
556
628
  if (this.store.currentOrder) {
557
- _context10.next = 6;
629
+ _context10.next = 7;
558
630
  break;
559
631
  }
560
632
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '没有找到当前订单,请先创建虚拟订单');
561
- case 6:
633
+ case 7:
562
634
  console.log('[Checkout] 开始手动下单流程...');
563
- _context10.next = 9;
564
- return this.setStatus(CheckoutStatus.CreatingOrder);
565
- case 9:
635
+ this.setStatus(CheckoutStatus.CreatingOrder);
636
+
566
637
  // 准备订单数据,使用 Order 模块期望的格式
567
638
  orderData = {
568
639
  cartItems: this.store.cartItems,
@@ -605,15 +676,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
605
676
  });
606
677
  }
607
678
  case 23:
608
- _context10.next = 25;
609
- return this.setStatus(CheckoutStatus.OrderCreated);
610
- case 25:
611
- _context10.next = 27;
679
+ this.setStatus(CheckoutStatus.OrderCreated);
680
+
681
+ // 发射订单创建成功事件
682
+ _context10.next = 26;
612
683
  return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
613
684
  order: this.store.currentOrder,
614
685
  timestamp: Date.now()
615
686
  });
616
- case 27:
687
+ case 26:
617
688
  // 标记订单已同步
618
689
  this.store.isOrderSynced = true;
619
690
  console.log('[Checkout] 手动下单流程完成');
@@ -621,9 +692,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
621
692
  success: true,
622
693
  orderId: realOrderId
623
694
  });
624
- case 32:
625
- _context10.prev = 32;
626
- _context10.t0 = _context10["catch"](1);
695
+ case 31:
696
+ _context10.prev = 31;
697
+ _context10.t0 = _context10["catch"](2);
627
698
  // 处理 CheckoutError 对象
628
699
  errorMessage = '下单失败';
629
700
  if (_context10.t0 && _typeof(_context10.t0) === 'object' && 'message' in _context10.t0) {
@@ -632,18 +703,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
632
703
  errorMessage = _context10.t0.message;
633
704
  }
634
705
  console.error('[Checkout] 手动下单失败:', errorMessage);
635
- _context10.next = 39;
706
+ _context10.next = 38;
636
707
  return this.handleError(_context10.t0, CheckoutErrorType.OrderCreationFailed);
637
- case 39:
708
+ case 38:
638
709
  return _context10.abrupt("return", {
639
710
  success: false,
640
711
  error: errorMessage
641
712
  });
642
- case 40:
713
+ case 39:
643
714
  case "end":
644
715
  return _context10.stop();
645
716
  }
646
- }, _callee10, this, [[1, 32]]);
717
+ }, _callee10, this, [[2, 31]]);
647
718
  }));
648
719
  function placeOrderAsync() {
649
720
  return _placeOrderAsync.apply(this, arguments);
@@ -663,21 +734,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
663
734
  while (1) switch (_context11.prev = _context11.next) {
664
735
  case 0:
665
736
  _context11.prev = 0;
666
- _context11.next = 3;
667
- return this.setStatus(CheckoutStatus.CreatingOrder);
668
- case 3:
737
+ this.setStatus(CheckoutStatus.CreatingOrder);
738
+
669
739
  // 验证购物车数据
670
740
  checkResult = this.order.checkBeforeSubmitOrder({
671
741
  cartItems: params.cartItems,
672
742
  type: 'account' // 默认使用 account 类型
673
743
  });
674
744
  if (checkResult) {
675
- _context11.next = 6;
745
+ _context11.next = 5;
676
746
  break;
677
747
  }
678
748
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '购物车数据验证失败,请检查商品信息');
679
- case 6:
680
- _context11.next = 8;
749
+ case 5:
750
+ _context11.next = 7;
681
751
  return this.order.submitOrder({
682
752
  query: {
683
753
  cartItems: params.cartItems,
@@ -685,56 +755,52 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
685
755
  platform: params.platform || 'pc'
686
756
  }
687
757
  });
688
- case 8:
758
+ case 7:
689
759
  orderResponse = _context11.sent;
690
- _context11.next = 11;
760
+ _context11.next = 10;
691
761
  return this.payment.createPaymentOrderAsync({
692
762
  order_id: (orderResponse === null || orderResponse === void 0 || (_data2 = orderResponse.data) === null || _data2 === void 0 ? void 0 : _data2.order_id) || "order_".concat(Date.now()),
693
- total_amount: this.calculateTotalAmount(params.cartItems),
763
+ total_amount: calculateTotalAmount(params.cartItems),
694
764
  order_info: orderResponse === null || orderResponse === void 0 ? void 0 : orderResponse.data
695
765
  });
696
- case 11:
766
+ case 10:
697
767
  paymentOrder = _context11.sent;
698
768
  this.store.currentOrder = paymentOrder;
699
- _context11.next = 15;
700
- return this.setStatus(CheckoutStatus.OrderCreated);
701
- case 15:
702
- _context11.next = 17;
703
- return this.setStep(CheckoutStep.PaymentMethod);
704
- case 17:
705
- _context11.next = 19;
769
+ this.setStatus(CheckoutStatus.OrderCreated);
770
+ this.setStep(CheckoutStep.PaymentMethod);
771
+ _context11.next = 16;
706
772
  return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
707
773
  order: paymentOrder,
708
774
  timestamp: Date.now()
709
775
  });
710
- case 19:
776
+ case 16:
711
777
  // 标记订单已同步(createOrderAsync 创建的是真实订单)
712
778
  this.store.isOrderSynced = true;
713
779
 
714
780
  // 自动设置 stateAmount 为剩余未支付金额
715
- _context11.next = 22;
781
+ _context11.next = 19;
716
782
  return this.updateStateAmountToRemaining();
717
- case 22:
783
+ case 19:
718
784
  console.log('[Checkout] 订单创建成功:', paymentOrder.id);
719
785
  return _context11.abrupt("return", paymentOrder);
720
- case 26:
721
- _context11.prev = 26;
786
+ case 23:
787
+ _context11.prev = 23;
722
788
  _context11.t0 = _context11["catch"](0);
723
- _context11.next = 30;
789
+ _context11.next = 27;
724
790
  return this.handleError(_context11.t0, CheckoutErrorType.OrderCreationFailed);
725
- case 30:
726
- _context11.next = 32;
791
+ case 27:
792
+ _context11.next = 29;
727
793
  return this.core.effects.emit(CheckoutHooks.OnOrderCreationFailed, {
728
794
  error: this.store.lastError,
729
795
  timestamp: Date.now()
730
796
  });
731
- case 32:
797
+ case 29:
732
798
  throw _context11.t0;
733
- case 33:
799
+ case 30:
734
800
  case "end":
735
801
  return _context11.stop();
736
802
  }
737
- }, _callee11, this, [[0, 26]]);
803
+ }, _callee11, this, [[0, 23]]);
738
804
  }));
739
805
  function createOrderAsync(_x12) {
740
806
  return _createOrderAsync.apply(this, arguments);
@@ -760,22 +826,19 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
760
826
  }
761
827
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,请先创建订单');
762
828
  case 3:
763
- _context12.next = 5;
764
- return this.setStatus(CheckoutStatus.ProcessingPayment);
765
- case 5:
766
- _context12.next = 7;
767
- return this.setStep(CheckoutStep.PaymentProcessing);
768
- case 7:
829
+ this.setStatus(CheckoutStatus.ProcessingPayment);
830
+ this.setStep(CheckoutStep.PaymentProcessing);
831
+
769
832
  // 查找支付方式
770
833
  paymentMethod = this.store.paymentMethods.find(function (method) {
771
834
  return method.code === params.paymentMethodCode;
772
835
  });
773
836
  if (paymentMethod) {
774
- _context12.next = 10;
837
+ _context12.next = 8;
775
838
  break;
776
839
  }
777
840
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u672A\u627E\u5230\u652F\u4ED8\u65B9\u5F0F: ".concat(params.paymentMethodCode));
778
- case 10:
841
+ case 8:
779
842
  // 创建支付项
780
843
  paymentItem = {
781
844
  code: paymentMethod.code,
@@ -784,56 +847,56 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
784
847
  amount: String(params.amount),
785
848
  id: paymentMethod.id
786
849
  }; // 添加支付项到订单
787
- _context12.next = 13;
850
+ _context12.next = 11;
788
851
  return this.payment.addPaymentItemAsync(this.store.currentOrder.uuid, paymentItem);
789
- case 13:
790
- _context12.next = 15;
852
+ case 11:
853
+ _context12.next = 13;
791
854
  return this.payment.submitPayAsync(this.store.currentOrder.uuid);
792
- case 15:
855
+ case 13:
793
856
  result = _context12.sent;
794
- _context12.next = 18;
857
+ _context12.next = 16;
795
858
  return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
796
859
  orderUuid: this.store.currentOrder.uuid,
797
860
  paymentMethodCode: params.paymentMethodCode,
798
861
  amount: String(params.amount),
799
862
  timestamp: Date.now()
800
863
  });
801
- case 18:
864
+ case 16:
802
865
  if (!(result.status === 'success')) {
803
- _context12.next = 27;
866
+ _context12.next = 24;
804
867
  break;
805
868
  }
806
- _context12.next = 21;
807
- return this.setStatus(CheckoutStatus.PaymentCompleted);
808
- case 21:
809
- _context12.next = 23;
869
+ this.setStatus(CheckoutStatus.PaymentCompleted);
870
+
871
+ // 支付提交成功后更新 stateAmount
872
+ _context12.next = 20;
810
873
  return this.updateStateAmountToRemaining();
811
- case 23:
812
- _context12.next = 25;
874
+ case 20:
875
+ _context12.next = 22;
813
876
  return this.handlePaymentSuccess({
814
877
  orderUuid: this.store.currentOrder.uuid,
815
878
  timestamp: Date.now()
816
879
  });
817
- case 25:
818
- _context12.next = 28;
880
+ case 22:
881
+ _context12.next = 25;
819
882
  break;
820
- case 27:
883
+ case 24:
821
884
  throw createCheckoutError(CheckoutErrorType.PaymentFailed, '支付处理失败,请重试');
822
- case 28:
823
- _context12.next = 35;
885
+ case 25:
886
+ _context12.next = 32;
824
887
  break;
825
- case 30:
826
- _context12.prev = 30;
888
+ case 27:
889
+ _context12.prev = 27;
827
890
  _context12.t0 = _context12["catch"](0);
828
- _context12.next = 34;
891
+ _context12.next = 31;
829
892
  return this.handleError(_context12.t0, CheckoutErrorType.PaymentFailed);
830
- case 34:
893
+ case 31:
831
894
  throw _context12.t0;
832
- case 35:
895
+ case 32:
833
896
  case "end":
834
897
  return _context12.stop();
835
898
  }
836
- }, _callee12, this, [[0, 30]]);
899
+ }, _callee12, this, [[0, 27]]);
837
900
  }));
838
901
  function processPaymentAsync(_x13) {
839
902
  return _processPaymentAsync.apply(this, arguments);
@@ -871,42 +934,38 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
871
934
  case 8:
872
935
  // 清理钱包模块的所有缓存数据
873
936
  this.payment.wallet.clearAllCache();
874
- _context13.next = 11;
875
- return this.setStatus(CheckoutStatus.Completed);
876
- case 11:
937
+ this.setStatus(CheckoutStatus.Completed);
938
+ this.setStep(CheckoutStep.Complete);
877
939
  _context13.next = 13;
878
- return this.setStep(CheckoutStep.Complete);
879
- case 13:
880
- _context13.next = 15;
881
940
  return this.core.effects.emit(CheckoutHooks.OnCheckoutCompleted, {
882
941
  orderId: order.id,
883
942
  timestamp: Date.now()
884
943
  });
885
- case 15:
944
+ case 13:
886
945
  console.log('[Checkout] 结账流程完成:', order.id);
887
946
 
888
947
  // 🔧 新增:自动重置 store 状态
889
- _context13.next = 18;
948
+ _context13.next = 16;
890
949
  return this.resetStoreStateAsync();
891
- case 18:
950
+ case 16:
892
951
  return _context13.abrupt("return", {
893
952
  success: true,
894
953
  orderId: String(order.id)
895
954
  });
896
- case 21:
897
- _context13.prev = 21;
955
+ case 19:
956
+ _context13.prev = 19;
898
957
  _context13.t0 = _context13["catch"](0);
899
- _context13.next = 25;
958
+ _context13.next = 23;
900
959
  return this.handleError(_context13.t0, CheckoutErrorType.UnknownError);
901
- case 25:
960
+ case 23:
902
961
  return _context13.abrupt("return", {
903
962
  success: false
904
963
  });
905
- case 26:
964
+ case 24:
906
965
  case "end":
907
966
  return _context13.stop();
908
967
  }
909
- }, _callee13, this, [[0, 21]]);
968
+ }, _callee13, this, [[0, 19]]);
910
969
  }));
911
970
  function completeCheckoutAsync() {
912
971
  return _completeCheckoutAsync.apply(this, arguments);
@@ -943,28 +1002,26 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
943
1002
  this.store.balanceDueAmount = '0.00';
944
1003
  this.store.isOrderSynced = false;
945
1004
  this.store.currentCustomer = undefined;
946
- _context14.next = 15;
947
- return this.setStatus(CheckoutStatus.Cancelled);
948
- case 15:
949
- _context14.next = 17;
1005
+ this.setStatus(CheckoutStatus.Cancelled);
1006
+ _context14.next = 16;
950
1007
  return this.core.effects.emit(CheckoutHooks.OnCheckoutCancelled, {
951
1008
  timestamp: Date.now()
952
1009
  });
953
- case 17:
1010
+ case 16:
954
1011
  console.log('[Checkout] 结账流程已取消');
955
- _context14.next = 25;
1012
+ _context14.next = 24;
956
1013
  break;
957
- case 20:
958
- _context14.prev = 20;
1014
+ case 19:
1015
+ _context14.prev = 19;
959
1016
  _context14.t0 = _context14["catch"](0);
960
1017
  console.error('[Checkout] 取消结账失败:', _context14.t0);
961
- _context14.next = 25;
1018
+ _context14.next = 24;
962
1019
  return this.handleError(_context14.t0, CheckoutErrorType.UnknownError);
963
- case 25:
1020
+ case 24:
964
1021
  case "end":
965
1022
  return _context14.stop();
966
1023
  }
967
- }, _callee14, this, [[0, 20]]);
1024
+ }, _callee14, this, [[0, 19]]);
968
1025
  }));
969
1026
  function cancelCheckoutAsync() {
970
1027
  return _cancelCheckoutAsync.apply(this, arguments);
@@ -994,12 +1051,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
994
1051
  key: "getCheckoutSummaryAsync",
995
1052
  value: (function () {
996
1053
  var _getCheckoutSummaryAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
997
- var _this$store$currentOr5, _this$store$currentOr6;
1054
+ var _this$store$currentOr6, _this$store$currentOr7;
998
1055
  var totalAmount, paidAmount, remainingAmount;
999
1056
  return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1000
1057
  while (1) switch (_context15.prev = _context15.next) {
1001
1058
  case 0:
1002
- totalAmount = ((_this$store$currentOr5 = this.store.currentOrder) === null || _this$store$currentOr5 === void 0 ? void 0 : _this$store$currentOr5.total_amount) || '0.00';
1059
+ totalAmount = ((_this$store$currentOr6 = this.store.currentOrder) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.total_amount) || '0.00';
1003
1060
  _context15.next = 3;
1004
1061
  return this.calculatePaidAmountAsync();
1005
1062
  case 3:
@@ -1013,7 +1070,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1013
1070
  totalAmount: totalAmount,
1014
1071
  paidAmount: paidAmount,
1015
1072
  remainingAmount: remainingAmount,
1016
- paymentStatus: ((_this$store$currentOr6 = this.store.currentOrder) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.payment_status) || PaymentStatus.Processing,
1073
+ paymentStatus: ((_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.payment_status) || PaymentStatus.Processing,
1017
1074
  availablePaymentMethods: this.store.paymentMethods
1018
1075
  });
1019
1076
  case 8:
@@ -1100,8 +1157,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1100
1157
  }, {
1101
1158
  key: "getOrderOriginalData",
1102
1159
  value: function getOrderOriginalData() {
1103
- var _this$store$currentOr7;
1104
- return (_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.order_info;
1160
+ var _this$store$currentOr8;
1161
+ return (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.order_info;
1105
1162
  }
1106
1163
 
1107
1164
  /**
@@ -1594,7 +1651,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1594
1651
  console.warn('[Checkout] 没有可用的购物车小计数据,无法提取金额信息');
1595
1652
  return null;
1596
1653
  }
1597
- var extractedInfo = this.extractAmountFromCartSummary(this.store.cartSummary);
1654
+ var extractedInfo = extractAmountFromCartSummary(this.store.cartSummary);
1598
1655
  console.log('[Checkout] 获取提取的金额信息:', extractedInfo);
1599
1656
  return extractedInfo;
1600
1657
  }
@@ -1662,17 +1719,30 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1662
1719
  key: "addPaymentItemAsync",
1663
1720
  value: (function () {
1664
1721
  var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(paymentItem) {
1722
+ var _this$store$currentOr9, _this$store$currentOr10;
1665
1723
  var _paymentItem$type, _paymentItem$code, orderPaymentType, metadata, paymentItemWithType, isEftposPayment, syncResult;
1666
1724
  return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1667
1725
  while (1) switch (_context25.prev = _context25.next) {
1668
1726
  case 0:
1669
- _context25.prev = 0;
1727
+ this.logInfo('addPaymentItemAsync called', {
1728
+ paymentCode: paymentItem.code,
1729
+ paymentType: paymentItem.type,
1730
+ amount: paymentItem.amount,
1731
+ voucherId: paymentItem.voucher_id,
1732
+ serviceCharge: paymentItem.service_charge,
1733
+ roundingAmount: paymentItem.rounding_amount,
1734
+ hasMetadata: !!paymentItem.metadata,
1735
+ hasCurrentOrder: !!this.store.currentOrder,
1736
+ currentOrderId: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.order_id,
1737
+ isDepositOrder: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.is_deposit
1738
+ });
1739
+ _context25.prev = 1;
1670
1740
  if (this.store.currentOrder) {
1671
- _context25.next = 3;
1741
+ _context25.next = 4;
1672
1742
  break;
1673
1743
  }
1674
1744
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法添加支付项');
1675
- case 3:
1745
+ case 4:
1676
1746
  // 根据当前订单的定金状态设置订单支付类型
1677
1747
  orderPaymentType = this.store.currentOrder.is_deposit === 1 ? 'deposit' : 'normal'; // 从 otherParams 获取 metadata 字段
1678
1748
  metadata = _objectSpread(_objectSpread({}, paymentItem.metadata), {}, {
@@ -1701,9 +1771,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1701
1771
  });
1702
1772
 
1703
1773
  // 添加支付项到订单
1704
- _context25.next = 9;
1774
+ _context25.next = 10;
1705
1775
  return this.payment.addPaymentItemAsync(this.store.currentOrder.uuid, paymentItemWithType);
1706
- case 9:
1776
+ case 10:
1707
1777
  console.log('[Checkout] 支付项添加成功');
1708
1778
 
1709
1779
  // 检查是否是 EFTPOS 支付,如果是则立即同步订单
@@ -1715,56 +1785,56 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1715
1785
  currentOrderSynced: this.store.isOrderSynced
1716
1786
  });
1717
1787
  if (!isEftposPayment) {
1718
- _context25.next = 26;
1788
+ _context25.next = 27;
1719
1789
  break;
1720
1790
  }
1721
1791
  console.log('[Checkout] 检测到 EFTPOS 支付,立即同步订单到后端...');
1722
- _context25.prev = 14;
1723
- _context25.next = 17;
1792
+ _context25.prev = 15;
1793
+ _context25.next = 18;
1724
1794
  return this.syncOrderToBackendWithReturn(true);
1725
- case 17:
1795
+ case 18:
1726
1796
  syncResult = _context25.sent;
1727
1797
  console.log('[Checkout] EFTPOS 支付后订单同步完成 (已标记为手动同步):', {
1728
1798
  订单ID: syncResult.orderId,
1729
1799
  是否已同步: this.store.isOrderSynced,
1730
1800
  后端响应: syncResult.response
1731
1801
  });
1732
- _context25.next = 26;
1802
+ _context25.next = 27;
1733
1803
  break;
1734
- case 21:
1735
- _context25.prev = 21;
1736
- _context25.t0 = _context25["catch"](14);
1804
+ case 22:
1805
+ _context25.prev = 22;
1806
+ _context25.t0 = _context25["catch"](15);
1737
1807
  console.error('[Checkout] EFTPOS 支付后订单同步失败:', _context25.t0);
1738
1808
  // 不抛出错误,避免影响支付流程,但记录错误
1739
- _context25.next = 26;
1809
+ _context25.next = 27;
1740
1810
  return this.handleError(new Error("EFTPOS \u652F\u4ED8\u540E\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0))), CheckoutErrorType.OrderCreationFailed);
1741
- case 26:
1742
- _context25.next = 28;
1811
+ case 27:
1812
+ _context25.next = 29;
1743
1813
  return this.updateStateAmountToRemaining();
1744
- case 28:
1745
- _context25.next = 30;
1814
+ case 29:
1815
+ _context25.next = 31;
1746
1816
  return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1747
1817
  orderUuid: this.store.currentOrder.uuid,
1748
1818
  paymentMethodCode: paymentItem.code,
1749
1819
  amount: String(paymentItem.amount),
1750
1820
  timestamp: Date.now()
1751
1821
  });
1752
- case 30:
1753
- _context25.next = 38;
1822
+ case 31:
1823
+ _context25.next = 39;
1754
1824
  break;
1755
- case 32:
1756
- _context25.prev = 32;
1757
- _context25.t1 = _context25["catch"](0);
1825
+ case 33:
1826
+ _context25.prev = 33;
1827
+ _context25.t1 = _context25["catch"](1);
1758
1828
  console.error('[Checkout] 添加支付项失败:', _context25.t1);
1759
- _context25.next = 37;
1829
+ _context25.next = 38;
1760
1830
  return this.handleError(_context25.t1, CheckoutErrorType.PaymentFailed);
1761
- case 37:
1762
- throw _context25.t1;
1763
1831
  case 38:
1832
+ throw _context25.t1;
1833
+ case 39:
1764
1834
  case "end":
1765
1835
  return _context25.stop();
1766
1836
  }
1767
- }, _callee25, this, [[0, 32], [14, 21]]);
1837
+ }, _callee25, this, [[1, 33], [15, 22]]);
1768
1838
  }));
1769
1839
  function addPaymentItemAsync(_x16) {
1770
1840
  return _addPaymentItemAsync.apply(this, arguments);
@@ -1831,14 +1901,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1831
1901
 
1832
1902
  // 重新从Payment模块获取最新的订单数据,确保支付项同步
1833
1903
  currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1834
- isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
1904
+ isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
1835
1905
  _context26.next = 18;
1836
1906
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1837
1907
  case 18:
1838
1908
  updatedOrder = _context26.sent;
1839
1909
  if (updatedOrder) {
1840
1910
  // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
1841
- if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
1911
+ if (isCurrentOrderReal && isVirtualOrderId(updatedOrder.order_id)) {
1842
1912
  console.warn('[Checkout] deletePaymentItemAsync: 检测到订单ID回退,保护真实订单ID:', {
1843
1913
  当前真实ID: currentOrderId,
1844
1914
  获取到的虚拟ID: updatedOrder.order_id
@@ -1948,14 +2018,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1948
2018
 
1949
2019
  // 重新从Payment模块获取最新的订单数据,确保支付项同步
1950
2020
  currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1951
- isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
2021
+ isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
1952
2022
  _context27.next = 14;
1953
2023
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1954
2024
  case 14:
1955
2025
  updatedOrder = _context27.sent;
1956
2026
  if (updatedOrder) {
1957
2027
  // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
1958
- if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
2028
+ if (isCurrentOrderReal && isVirtualOrderId(updatedOrder.order_id)) {
1959
2029
  console.warn('[Checkout] updateVoucherPaymentItemsAsync: 检测到订单ID回退,保护真实订单ID:', {
1960
2030
  当前真实ID: currentOrderId,
1961
2031
  获取到的虚拟ID: updatedOrder.order_id
@@ -2274,20 +2344,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2274
2344
  key: "manualSyncOrderAsync",
2275
2345
  value: (function () {
2276
2346
  var _manualSyncOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2277
- var orderUuid, oldOrderId, syncResult, finalOrderId, finalIsVirtual, _this$store$currentOr8, errorMessage;
2347
+ var _this$store$currentOr11, _this$store$currentOr12, _this$store$currentOr13;
2348
+ var orderUuid, oldOrderId, syncResult, finalOrderId, finalIsVirtual, _this$store$currentOr14, errorMessage;
2278
2349
  return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2279
2350
  while (1) switch (_context31.prev = _context31.next) {
2280
2351
  case 0:
2281
- _context31.prev = 0;
2352
+ this.logInfo('manualSyncOrderAsync called', {
2353
+ hasCurrentOrder: !!this.store.currentOrder,
2354
+ currentOrderId: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.order_id,
2355
+ orderUuid: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.uuid,
2356
+ totalAmount: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.total_amount,
2357
+ isOrderSynced: this.store.isOrderSynced,
2358
+ isVirtualOrderId: this.store.currentOrder ? isVirtualOrderId(this.store.currentOrder.order_id) : false
2359
+ });
2360
+ _context31.prev = 1;
2282
2361
  if (this.store.currentOrder) {
2283
- _context31.next = 3;
2362
+ _context31.next = 4;
2284
2363
  break;
2285
2364
  }
2286
2365
  return _context31.abrupt("return", {
2287
2366
  success: false,
2288
2367
  message: '当前没有活跃订单,无法同步'
2289
2368
  });
2290
- case 3:
2369
+ case 4:
2291
2370
  orderUuid = this.store.currentOrder.uuid;
2292
2371
  oldOrderId = this.store.currentOrder.order_id; // 检查订单是否已经同步
2293
2372
  if (this.store.isOrderSynced) {
@@ -2297,9 +2376,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2297
2376
  _context31.t1 = orderUuid;
2298
2377
  _context31.t2 = oldOrderId;
2299
2378
  _context31.t3 = this.store.currentOrder.total_amount;
2300
- _context31.next = 12;
2379
+ _context31.next = 13;
2301
2380
  return this.calculateRemainingAmountAsync();
2302
- case 12:
2381
+ case 13:
2303
2382
  _context31.t4 = _context31.sent;
2304
2383
  _context31.t5 = {
2305
2384
  orderUuid: _context31.t1,
@@ -2308,9 +2387,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2308
2387
  remainingAmount: _context31.t4
2309
2388
  };
2310
2389
  _context31.t0.log.call(_context31.t0, '[Checkout] 开始手动同步订单到后端:', _context31.t5);
2311
- _context31.next = 17;
2390
+ _context31.next = 18;
2312
2391
  return this.syncOrderToBackendWithReturn(true);
2313
- case 17:
2392
+ case 18:
2314
2393
  syncResult = _context31.sent;
2315
2394
  console.log('[Checkout] 手动同步订单完成:', {
2316
2395
  orderUuid: orderUuid,
@@ -2322,7 +2401,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2322
2401
 
2323
2402
  // 🔍 关键验证:检查最终状态是否正确
2324
2403
  finalOrderId = this.store.currentOrder.order_id;
2325
- finalIsVirtual = this.isVirtualOrderId(finalOrderId);
2404
+ finalIsVirtual = isVirtualOrderId(finalOrderId);
2326
2405
  console.log('[Checkout] manualSyncOrderAsync 最终状态验证:', {
2327
2406
  返回的订单ID: syncResult.orderId,
2328
2407
  存储的订单ID: finalOrderId,
@@ -2337,21 +2416,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2337
2416
  console.error('[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!');
2338
2417
  }
2339
2418
  return _context31.abrupt("return", syncResult);
2340
- case 27:
2341
- _context31.prev = 27;
2342
- _context31.t6 = _context31["catch"](0);
2419
+ case 28:
2420
+ _context31.prev = 28;
2421
+ _context31.t6 = _context31["catch"](1);
2343
2422
  console.error('[Checkout] 手动同步订单失败:', _context31.t6);
2344
2423
  errorMessage = _context31.t6 instanceof Error ? _context31.t6.message : '同步失败';
2345
2424
  return _context31.abrupt("return", {
2346
2425
  success: false,
2347
2426
  message: "\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(errorMessage),
2348
- orderUuid: (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.uuid
2427
+ orderUuid: (_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.uuid
2349
2428
  });
2350
- case 32:
2429
+ case 33:
2351
2430
  case "end":
2352
2431
  return _context31.stop();
2353
2432
  }
2354
- }, _callee31, this, [[0, 27]]);
2433
+ }, _callee31, this, [[1, 28]]);
2355
2434
  }));
2356
2435
  function manualSyncOrderAsync() {
2357
2436
  return _manualSyncOrderAsync.apply(this, arguments);
@@ -2422,15 +2501,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2422
2501
  key: "cancelCurrentOrderAsync",
2423
2502
  value: (function () {
2424
2503
  var _cancelCurrentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(cancelReason) {
2425
- var _this$store$currentOr9, _this$store$currentOr10, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
2504
+ var _this$store$currentOr15, _this$store$currentOr16, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
2426
2505
  return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2427
2506
  while (1) switch (_context32.prev = _context32.next) {
2428
2507
  case 0:
2429
2508
  _context32.prev = 0;
2430
2509
  console.log('[Checkout] 开始取消当前本地订单:', {
2431
2510
  hasCurrentOrder: !!this.store.currentOrder,
2432
- orderUuid: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.uuid,
2433
- orderId: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.order_id,
2511
+ orderUuid: (_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.uuid,
2512
+ orderId: (_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.order_id,
2434
2513
  isOrderSynced: this.store.isOrderSynced,
2435
2514
  cancelReason: cancelReason
2436
2515
  });
@@ -2544,7 +2623,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2544
2623
  key: "saveForLaterPaymentAsync",
2545
2624
  value: (function () {
2546
2625
  var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2547
- var orderUuid, currentOrderId, allPaymentItems, syncResult, finalOrderId, _this$store$currentOr11, errorMessage;
2626
+ var orderUuid, currentOrderId, allPaymentItems, syncResult, finalOrderId, _this$store$currentOr17, errorMessage;
2548
2627
  return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2549
2628
  while (1) switch (_context33.prev = _context33.next) {
2550
2629
  case 0:
@@ -2607,7 +2686,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2607
2686
  return _context33.abrupt("return", {
2608
2687
  success: false,
2609
2688
  message: "\u8BA2\u5355\u4FDD\u5B58\u5931\u8D25: ".concat(errorMessage),
2610
- orderUuid: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.uuid
2689
+ orderUuid: (_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.uuid
2611
2690
  });
2612
2691
  case 23:
2613
2692
  case "end":
@@ -2658,14 +2737,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2658
2737
  key: "updateShopDiscountAsync",
2659
2738
  value: (function () {
2660
2739
  var _updateShopDiscountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(discountAmount) {
2661
- var _this$store$currentOr12, _this$store$currentOr13, oldDiscount, shopDiscountItem, updatedAmountInfo;
2740
+ var _this$store$currentOr18, _this$store$currentOr19, oldDiscount, shopDiscountItem, updatedAmountInfo;
2662
2741
  return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2663
2742
  while (1) switch (_context34.prev = _context34.next) {
2664
2743
  case 0:
2665
2744
  _context34.prev = 0;
2666
2745
  oldDiscount = this.getShopDiscount();
2667
2746
  console.log('[Checkout] 更新商店折扣:', {
2668
- orderUuid: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.uuid,
2747
+ orderUuid: (_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.uuid,
2669
2748
  oldDiscount: oldDiscount,
2670
2749
  newDiscount: discountAmount
2671
2750
  });
@@ -2701,7 +2780,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2701
2780
  // 3. 如果有当前订单,可能需要重新计算订单金额
2702
2781
  if (this.store.currentOrder && this.store.cartSummary) {
2703
2782
  // 重新提取金额信息
2704
- updatedAmountInfo = this.extractAmountFromCartSummary(this.store.cartSummary);
2783
+ updatedAmountInfo = extractAmountFromCartSummary(this.store.cartSummary);
2705
2784
  console.log('[Checkout] 重新计算订单金额:', updatedAmountInfo);
2706
2785
 
2707
2786
  // 更新订单的总金额等信息
@@ -2715,7 +2794,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2715
2794
  case 8:
2716
2795
  _context34.next = 10;
2717
2796
  return this.core.effects.emit(CheckoutHooks.OnShopDiscountChanged, {
2718
- orderUuid: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.uuid,
2797
+ orderUuid: (_this$store$currentOr19 = this.store.currentOrder) === null || _this$store$currentOr19 === void 0 ? void 0 : _this$store$currentOr19.uuid,
2719
2798
  oldDiscount: oldDiscount,
2720
2799
  newDiscount: discountAmount,
2721
2800
  timestamp: Date.now()
@@ -2756,7 +2835,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2756
2835
  key: "updateOrderNoteAsync",
2757
2836
  value: (function () {
2758
2837
  var _updateOrderNoteAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(note) {
2759
- var _this$store$currentOr14, _this$store$currentOr15, oldNote, orderInPayment;
2838
+ var _this$store$currentOr20, _this$store$currentOr21, oldNote, orderInPayment;
2760
2839
  return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2761
2840
  while (1) switch (_context35.prev = _context35.next) {
2762
2841
  case 0:
@@ -2768,7 +2847,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2768
2847
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '没有本地订单数据,无法更新备注');
2769
2848
  case 3:
2770
2849
  console.log('[Checkout] 更新订单备注:', {
2771
- orderUuid: (_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.uuid,
2850
+ orderUuid: (_this$store$currentOr20 = this.store.currentOrder) === null || _this$store$currentOr20 === void 0 ? void 0 : _this$store$currentOr20.uuid,
2772
2851
  oldNote: this.store.localOrderData.shop_note,
2773
2852
  newNote: note
2774
2853
  });
@@ -2801,7 +2880,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2801
2880
  case 17:
2802
2881
  _context35.next = 19;
2803
2882
  return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
2804
- orderUuid: (_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.uuid,
2883
+ orderUuid: (_this$store$currentOr21 = this.store.currentOrder) === null || _this$store$currentOr21 === void 0 ? void 0 : _this$store$currentOr21.uuid,
2805
2884
  oldNote: oldNote,
2806
2885
  newNote: note,
2807
2886
  timestamp: Date.now()
@@ -2838,80 +2917,46 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2838
2917
  )
2839
2918
  }, {
2840
2919
  key: "setStatus",
2841
- value: (function () {
2842
- var _setStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(status) {
2843
- var oldStatus;
2844
- return _regeneratorRuntime().wrap(function _callee36$(_context36) {
2845
- while (1) switch (_context36.prev = _context36.next) {
2846
- case 0:
2847
- oldStatus = this.store.status;
2848
- this.store.status = status;
2849
- _context36.next = 4;
2850
- return this.core.effects.emit(CheckoutHooks.OnStatusChanged, {
2851
- oldStatus: oldStatus,
2852
- newStatus: status,
2853
- timestamp: Date.now()
2854
- });
2855
- case 4:
2856
- case "end":
2857
- return _context36.stop();
2858
- }
2859
- }, _callee36, this);
2860
- }));
2861
- function setStatus(_x24) {
2862
- return _setStatus.apply(this, arguments);
2863
- }
2864
- return setStatus;
2865
- }()
2920
+ value: function setStatus(status) {
2921
+ var oldStatus = this.store.status;
2922
+ this.store.status = status;
2923
+ this.core.effects.emit(CheckoutHooks.OnStatusChanged, {
2924
+ oldStatus: oldStatus,
2925
+ newStatus: status,
2926
+ timestamp: Date.now()
2927
+ });
2928
+ }
2929
+
2866
2930
  /**
2867
2931
  * 设置步骤
2868
2932
  */
2869
- )
2870
2933
  }, {
2871
2934
  key: "setStep",
2872
- value: (function () {
2873
- var _setStep = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(step) {
2874
- var oldStep;
2875
- return _regeneratorRuntime().wrap(function _callee37$(_context37) {
2876
- while (1) switch (_context37.prev = _context37.next) {
2877
- case 0:
2878
- oldStep = this.store.step;
2879
- this.store.step = step;
2880
- _context37.next = 4;
2881
- return this.core.effects.emit(CheckoutHooks.OnStepChanged, {
2882
- oldStep: oldStep,
2883
- newStep: step,
2884
- timestamp: Date.now()
2885
- });
2886
- case 4:
2887
- case "end":
2888
- return _context37.stop();
2889
- }
2890
- }, _callee37, this);
2891
- }));
2892
- function setStep(_x25) {
2893
- return _setStep.apply(this, arguments);
2894
- }
2895
- return setStep;
2896
- }()
2935
+ value: function setStep(step) {
2936
+ var oldStep = this.store.step;
2937
+ this.store.step = step;
2938
+ this.core.effects.emit(CheckoutHooks.OnStepChanged, {
2939
+ oldStep: oldStep,
2940
+ newStep: step,
2941
+ timestamp: Date.now()
2942
+ });
2943
+ }
2944
+
2897
2945
  /**
2898
2946
  * 处理错误
2899
2947
  */
2900
- )
2901
2948
  }, {
2902
2949
  key: "handleError",
2903
2950
  value: (function () {
2904
- var _handleError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(error, type) {
2951
+ var _handleError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(error, type) {
2905
2952
  var checkoutError;
2906
- return _regeneratorRuntime().wrap(function _callee38$(_context38) {
2907
- while (1) switch (_context38.prev = _context38.next) {
2953
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
2954
+ while (1) switch (_context36.prev = _context36.next) {
2908
2955
  case 0:
2909
2956
  checkoutError = error instanceof Error && 'type' in error ? error : createCheckoutError(type, error.message, error);
2910
2957
  this.store.lastError = checkoutError;
2911
- _context38.next = 4;
2912
- return this.setStatus(CheckoutStatus.Error);
2913
- case 4:
2914
- _context38.next = 6;
2958
+ this.setStatus(CheckoutStatus.Error);
2959
+ _context36.next = 5;
2915
2960
  return this.core.effects.emit(CheckoutHooks.OnError, {
2916
2961
  error: checkoutError,
2917
2962
  context: {
@@ -2920,15 +2965,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2920
2965
  },
2921
2966
  timestamp: Date.now()
2922
2967
  });
2923
- case 6:
2968
+ case 5:
2924
2969
  console.error('[Checkout] 错误:', checkoutError);
2925
- case 7:
2970
+ case 6:
2926
2971
  case "end":
2927
- return _context38.stop();
2972
+ return _context36.stop();
2928
2973
  }
2929
- }, _callee38, this);
2974
+ }, _callee36, this);
2930
2975
  }));
2931
- function handleError(_x26, _x27) {
2976
+ function handleError(_x24, _x25) {
2932
2977
  return _handleError.apply(this, arguments);
2933
2978
  }
2934
2979
  return handleError;
@@ -2940,34 +2985,34 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2940
2985
  }, {
2941
2986
  key: "handlePaymentSuccess",
2942
2987
  value: (function () {
2943
- var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(data) {
2944
- var _this$store$currentOr16;
2945
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
2946
- while (1) switch (_context39.prev = _context39.next) {
2988
+ var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(data) {
2989
+ var _this$store$currentOr22;
2990
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
2991
+ while (1) switch (_context37.prev = _context37.next) {
2947
2992
  case 0:
2948
- _context39.next = 2;
2949
- return this.setStatus(CheckoutStatus.PaymentCompleted);
2950
- case 2:
2951
- _context39.next = 4;
2993
+ this.setStatus(CheckoutStatus.PaymentCompleted);
2994
+
2995
+ // 支付状态变更后更新 stateAmount
2996
+ _context37.next = 3;
2952
2997
  return this.updateStateAmountToRemaining();
2953
- case 4:
2954
- _context39.next = 6;
2998
+ case 3:
2999
+ _context37.next = 5;
2955
3000
  return this.core.effects.emit(CheckoutHooks.OnPaymentSuccess, {
2956
3001
  orderUuid: data.orderUuid,
2957
3002
  paymentMethodCode: '',
2958
- amount: ((_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.total_amount) || '0',
3003
+ amount: ((_this$store$currentOr22 = this.store.currentOrder) === null || _this$store$currentOr22 === void 0 ? void 0 : _this$store$currentOr22.total_amount) || '0',
2959
3004
  timestamp: data.timestamp
2960
3005
  });
2961
- case 6:
2962
- _context39.next = 8;
3006
+ case 5:
3007
+ _context37.next = 7;
2963
3008
  return this.completeCheckoutAsync();
2964
- case 8:
3009
+ case 7:
2965
3010
  case "end":
2966
- return _context39.stop();
3011
+ return _context37.stop();
2967
3012
  }
2968
- }, _callee39, this);
3013
+ }, _callee37, this);
2969
3014
  }));
2970
- function handlePaymentSuccess(_x28) {
3015
+ function handlePaymentSuccess(_x26) {
2971
3016
  return _handlePaymentSuccess.apply(this, arguments);
2972
3017
  }
2973
3018
  return handlePaymentSuccess;
@@ -2979,30 +3024,30 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2979
3024
  }, {
2980
3025
  key: "handlePaymentError",
2981
3026
  value: (function () {
2982
- var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(data) {
2983
- var _this$store$currentOr17;
3027
+ var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(data) {
3028
+ var _this$store$currentOr23;
2984
3029
  var error;
2985
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
2986
- while (1) switch (_context40.prev = _context40.next) {
3030
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3031
+ while (1) switch (_context38.prev = _context38.next) {
2987
3032
  case 0:
2988
3033
  error = createCheckoutError(CheckoutErrorType.PaymentFailed, data.error || '支付同步失败');
2989
- _context40.next = 3;
3034
+ _context38.next = 3;
2990
3035
  return this.handleError(error instanceof Error ? error : new Error(String(error)), CheckoutErrorType.PaymentFailed);
2991
3036
  case 3:
2992
- _context40.next = 5;
3037
+ _context38.next = 5;
2993
3038
  return this.core.effects.emit(CheckoutHooks.OnPaymentFailed, {
2994
3039
  orderUuid: data.orderUuid,
2995
3040
  paymentMethodCode: '',
2996
- amount: ((_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.total_amount) || '0',
3041
+ amount: ((_this$store$currentOr23 = this.store.currentOrder) === null || _this$store$currentOr23 === void 0 ? void 0 : _this$store$currentOr23.total_amount) || '0',
2997
3042
  timestamp: data.timestamp
2998
3043
  });
2999
3044
  case 5:
3000
3045
  case "end":
3001
- return _context40.stop();
3046
+ return _context38.stop();
3002
3047
  }
3003
- }, _callee40, this);
3048
+ }, _callee38, this);
3004
3049
  }));
3005
- function handlePaymentError(_x29) {
3050
+ function handlePaymentError(_x27) {
3006
3051
  return _handlePaymentError.apply(this, arguments);
3007
3052
  }
3008
3053
  return handlePaymentError;
@@ -3017,163 +3062,37 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3017
3062
  return validateCheckoutData(params);
3018
3063
  }
3019
3064
 
3020
- /**
3021
- * 验证本地订单数据
3022
- */
3023
- }, {
3024
- key: "validateLocalOrderData",
3025
- value: function validateLocalOrderData(orderData) {
3026
- var _orderData$relation_p;
3027
- var errors = [];
3028
-
3029
- // 验证基本字段
3030
- if (!orderData.type) {
3031
- errors.push('订单类型不能为空');
3032
- }
3033
- if (!orderData.platform) {
3034
- errors.push('平台信息不能为空');
3035
- }
3036
- if ((!orderData.bookings || orderData.bookings.length === 0) && !(orderData !== null && orderData !== void 0 && (_orderData$relation_p = orderData.relation_products) !== null && _orderData$relation_p !== void 0 && _orderData$relation_p.length)) {
3037
- errors.push('预订信息不能为空');
3038
- }
3039
-
3040
- // 验证预订信息
3041
- if (orderData.bookings) {
3042
- orderData.bookings.forEach(function (booking, index) {
3043
- if (!booking.product || !booking.product.product_id) {
3044
- errors.push("\u9884\u8BA2\u9879 ".concat(index + 1, " \u7F3A\u5C11\u5546\u54C1\u4FE1\u606F"));
3045
- }
3046
- if (!booking.start_date) {
3047
- errors.push("\u9884\u8BA2\u9879 ".concat(index + 1, " \u7F3A\u5C11\u5F00\u59CB\u65E5\u671F"));
3048
- }
3049
- if (!booking.start_time) {
3050
- errors.push("\u9884\u8BA2\u9879 ".concat(index + 1, " \u7F3A\u5C11\u5F00\u59CB\u65F6\u95F4"));
3051
- }
3052
- });
3053
- }
3054
- return {
3055
- valid: errors.length === 0,
3056
- errors: errors
3057
- };
3058
- }
3059
-
3060
- /**
3061
- * 生成本地订单ID
3062
- */
3063
- }, {
3064
- key: "generateLocalOrderId",
3065
- value: function generateLocalOrderId() {
3066
- var timestamp = Date.now();
3067
- var random = Math.floor(Math.random() * 10000).toString().padStart(4, '0');
3068
- return "local_order_".concat(timestamp, "_").concat(random);
3069
- }
3070
-
3071
- /**
3072
- * 格式化日期时间为 YYYY-MM-DD hh:mm:ss 格式
3073
- *
3074
- * @param date 要格式化的日期对象
3075
- * @returns 格式化后的日期时间字符串
3076
- */
3077
- }, {
3078
- key: "formatDateTime",
3079
- value: function formatDateTime(date) {
3080
- var year = date.getFullYear();
3081
- var month = String(date.getMonth() + 1).padStart(2, '0');
3082
- var day = String(date.getDate()).padStart(2, '0');
3083
- var hours = String(date.getHours()).padStart(2, '0');
3084
- var minutes = String(date.getMinutes()).padStart(2, '0');
3085
- var seconds = String(date.getSeconds()).padStart(2, '0');
3086
- return "".concat(year, "-").concat(month, "-").concat(day, " ").concat(hours, ":").concat(minutes, ":").concat(seconds);
3087
- }
3088
-
3089
- /**
3090
- * 从购物车小计数据中提取金额信息
3091
- */
3092
- }, {
3093
- key: "extractAmountFromCartSummary",
3094
- value: function extractAmountFromCartSummary(cartSummary) {
3095
- var result = {
3096
- totalAmount: '0.00',
3097
- subTotal: '0.00',
3098
- taxAmount: '0.00',
3099
- discountAmount: '0.00',
3100
- shopDiscountAmount: '0.00',
3101
- roundingAmount: '0.00'
3102
- };
3103
- cartSummary.forEach(function (item) {
3104
- var value = Number(item.value).toFixed(2);
3105
- switch (item.key) {
3106
- case 'expect_amount':
3107
- result.totalAmount = value;
3108
- break;
3109
- case 'sub_total':
3110
- result.subTotal = value;
3111
- break;
3112
- case 'tax':
3113
- result.taxAmount = value;
3114
- if (item.tax) {
3115
- result.taxDetails = item.tax;
3116
- }
3117
- break;
3118
- case 'discount':
3119
- result.discountAmount = value;
3120
- break;
3121
- case 'shop_discount':
3122
- result.shopDiscountAmount = value;
3123
- break;
3124
- case 'custom_roundingAmount':
3125
- result.roundingAmount = value;
3126
- break;
3127
- default:
3128
- // 处理其他可能的键,如定金等
3129
- if (item.key.includes('deposit')) {
3130
- result.depositAmount = value;
3131
- }
3132
- break;
3133
- }
3134
- });
3135
- console.log('[Checkout] 从购物车小计提取金额信息:', {
3136
- totalAmount: result.totalAmount,
3137
- subTotal: result.subTotal,
3138
- taxAmount: result.taxAmount,
3139
- discountAmount: result.discountAmount,
3140
- shopDiscountAmount: result.shopDiscountAmount,
3141
- roundingAmount: result.roundingAmount
3142
- });
3143
- return result;
3144
- }
3145
-
3146
3065
  /**
3147
3066
  * 预加载支付方式(在初始化时调用)
3148
3067
  */
3149
3068
  }, {
3150
3069
  key: "preloadPaymentMethods",
3151
3070
  value: (function () {
3152
- var _preloadPaymentMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
3071
+ var _preloadPaymentMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
3153
3072
  var methods;
3154
- return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3155
- while (1) switch (_context41.prev = _context41.next) {
3073
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3074
+ while (1) switch (_context39.prev = _context39.next) {
3156
3075
  case 0:
3157
- _context41.prev = 0;
3076
+ _context39.prev = 0;
3158
3077
  console.log('[Checkout] 预加载支付方式...');
3159
- _context41.next = 4;
3078
+ _context39.next = 4;
3160
3079
  return this.payment.getPayMethodListAsync();
3161
3080
  case 4:
3162
- methods = _context41.sent;
3081
+ methods = _context39.sent;
3163
3082
  this.store.paymentMethods = methods;
3164
3083
  console.log("[Checkout] \u9884\u52A0\u8F7D\u5B8C\u6210\uFF0C\u5171 ".concat(methods.length, " \u79CD\u652F\u4ED8\u65B9\u5F0F"));
3165
- _context41.next = 13;
3084
+ _context39.next = 13;
3166
3085
  break;
3167
3086
  case 9:
3168
- _context41.prev = 9;
3169
- _context41.t0 = _context41["catch"](0);
3170
- console.error('[Checkout] 预加载支付方式失败:', _context41.t0);
3087
+ _context39.prev = 9;
3088
+ _context39.t0 = _context39["catch"](0);
3089
+ console.error('[Checkout] 预加载支付方式失败:', _context39.t0);
3171
3090
  this.store.paymentMethods = [];
3172
3091
  case 13:
3173
3092
  case "end":
3174
- return _context41.stop();
3093
+ return _context39.stop();
3175
3094
  }
3176
- }, _callee41, this, [[0, 9]]);
3095
+ }, _callee39, this, [[0, 9]]);
3177
3096
  }));
3178
3097
  function preloadPaymentMethods() {
3179
3098
  return _preloadPaymentMethods.apply(this, arguments);
@@ -3181,44 +3100,219 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3181
3100
  return preloadPaymentMethods;
3182
3101
  }()
3183
3102
  /**
3184
- * 计算总金额
3103
+ * 清理过期的已同步订单数据
3104
+ *
3105
+ * 删除本地 IndexDB 中超过指定天数且已同步到后端的订单数据
3185
3106
  */
3186
3107
  )
3187
3108
  }, {
3188
- key: "calculateTotalAmount",
3189
- value: function calculateTotalAmount(cartItems) {
3190
- var total = cartItems.reduce(function (sum, item) {
3191
- var price = parseFloat(String(item.price) || '0');
3192
- var quantity = item.quantity || 1;
3193
- return sum + price * quantity;
3194
- }, 0);
3195
- return total.toFixed(2);
3196
- }
3109
+ key: "cleanupExpiredOrdersAsync",
3110
+ value: (function () {
3111
+ var _cleanupExpiredOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40() {
3112
+ var cleanupConfig, isCleanupEnabled, retentionDays, maxOrdersToDelete, allOrders, thresholdDate, deletedCount, ordersToDelete, _iterator, _step, order, _order$order_info, _order$order_info2, isSynced, orderCreatedAt, actualOrdersToDelete, _iterator2, _step2, orderInfo, summary, errorMessage;
3113
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3114
+ while (1) switch (_context40.prev = _context40.next) {
3115
+ case 0:
3116
+ _context40.prev = 0;
3117
+ // 检查是否启用了清理功能
3118
+ cleanupConfig = this.otherParams.orderDataCleanup || {};
3119
+ isCleanupEnabled = cleanupConfig.enabled !== false; // 默认启用
3120
+ retentionDays = cleanupConfig.retentionDays || 7; // 默认保留7天
3121
+ maxOrdersToDelete = cleanupConfig.maxOrdersToDelete || 100; // 默认最多删除100个订单
3122
+ if (isCleanupEnabled) {
3123
+ _context40.next = 8;
3124
+ break;
3125
+ }
3126
+ console.log('[Checkout] 订单数据清理功能已禁用');
3127
+ return _context40.abrupt("return");
3128
+ case 8:
3129
+ console.log("[Checkout] \u5F00\u59CB\u6E05\u7406\u8FC7\u671F\u8BA2\u5355\u6570\u636E\uFF08\u4FDD\u7559 ".concat(retentionDays, " \u5929\u5185\u7684\u6570\u636E\uFF09..."));
3197
3130
 
3131
+ // 获取所有订单
3132
+ _context40.next = 11;
3133
+ return this.payment.getOrderListAsync();
3134
+ case 11:
3135
+ allOrders = _context40.sent;
3136
+ if (!(!allOrders || allOrders.length === 0)) {
3137
+ _context40.next = 15;
3138
+ break;
3139
+ }
3140
+ console.log('[Checkout] 没有找到需要清理的订单数据');
3141
+ return _context40.abrupt("return");
3142
+ case 15:
3143
+ thresholdDate = new Date();
3144
+ thresholdDate.setDate(thresholdDate.getDate() - retentionDays);
3145
+ deletedCount = 0;
3146
+ ordersToDelete = [];
3147
+ _iterator = _createForOfIteratorHelper(allOrders);
3148
+ _context40.prev = 20;
3149
+ _iterator.s();
3150
+ case 22:
3151
+ if ((_step = _iterator.n()).done) {
3152
+ _context40.next = 41;
3153
+ break;
3154
+ }
3155
+ order = _step.value;
3156
+ _context40.prev = 24;
3157
+ // 检查订单是否已同步(订单ID不是虚拟ID)
3158
+ isSynced = order.order_id && !isVirtualOrderId(order.order_id);
3159
+ if (isSynced) {
3160
+ _context40.next = 28;
3161
+ break;
3162
+ }
3163
+ return _context40.abrupt("continue", 39);
3164
+ case 28:
3165
+ // 检查创建时间
3166
+ orderCreatedAt = null; // 尝试从 order_info.created_at 获取创建时间
3167
+ if ((_order$order_info = order.order_info) !== null && _order$order_info !== void 0 && _order$order_info.created_at) {
3168
+ orderCreatedAt = new Date(order.order_info.created_at);
3169
+ }
3170
+ // 如果没有,尝试从 order_info.original_order_data.created_at 获取
3171
+ else if ((_order$order_info2 = order.order_info) !== null && _order$order_info2 !== void 0 && (_order$order_info2 = _order$order_info2.original_order_data) !== null && _order$order_info2 !== void 0 && _order$order_info2.created_at) {
3172
+ orderCreatedAt = new Date(order.order_info.original_order_data.created_at);
3173
+ }
3174
+
3175
+ // 如果无法获取创建时间,跳过此订单
3176
+ if (!(!orderCreatedAt || isNaN(orderCreatedAt.getTime()))) {
3177
+ _context40.next = 32;
3178
+ break;
3179
+ }
3180
+ return _context40.abrupt("continue", 39);
3181
+ case 32:
3182
+ // 检查是否超过指定天数
3183
+ if (orderCreatedAt < thresholdDate) {
3184
+ ordersToDelete.push({
3185
+ uuid: order.uuid,
3186
+ orderId: order.order_id,
3187
+ createdAt: orderCreatedAt.toISOString(),
3188
+ daysSinceCreated: Math.floor((Date.now() - orderCreatedAt.getTime()) / (1000 * 60 * 60 * 24))
3189
+ });
3190
+ }
3191
+ _context40.next = 39;
3192
+ break;
3193
+ case 35:
3194
+ _context40.prev = 35;
3195
+ _context40.t0 = _context40["catch"](24);
3196
+ console.warn("[Checkout] \u5904\u7406\u8BA2\u5355 ".concat(order.uuid, " \u65F6\u51FA\u9519:"), _context40.t0);
3197
+ return _context40.abrupt("continue", 39);
3198
+ case 39:
3199
+ _context40.next = 22;
3200
+ break;
3201
+ case 41:
3202
+ _context40.next = 46;
3203
+ break;
3204
+ case 43:
3205
+ _context40.prev = 43;
3206
+ _context40.t1 = _context40["catch"](20);
3207
+ _iterator.e(_context40.t1);
3208
+ case 46:
3209
+ _context40.prev = 46;
3210
+ _iterator.f();
3211
+ return _context40.finish(46);
3212
+ case 49:
3213
+ // 按创建时间排序(最老的先删除)并限制删除数量
3214
+ ordersToDelete.sort(function (a, b) {
3215
+ return new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime();
3216
+ });
3217
+ actualOrdersToDelete = ordersToDelete.slice(0, maxOrdersToDelete); // 删除符合条件的订单
3218
+ _iterator2 = _createForOfIteratorHelper(actualOrdersToDelete);
3219
+ _context40.prev = 52;
3220
+ _iterator2.s();
3221
+ case 54:
3222
+ if ((_step2 = _iterator2.n()).done) {
3223
+ _context40.next = 68;
3224
+ break;
3225
+ }
3226
+ orderInfo = _step2.value;
3227
+ _context40.prev = 56;
3228
+ _context40.next = 59;
3229
+ return this.payment.deletePaymentOrderAsync(orderInfo.uuid);
3230
+ case 59:
3231
+ deletedCount++;
3232
+ console.log("[Checkout] \u5DF2\u5220\u9664\u8FC7\u671F\u8BA2\u5355: ".concat(orderInfo.orderId, " (").concat(orderInfo.daysSinceCreated, " \u5929\u524D\u521B\u5EFA)"));
3233
+ _context40.next = 66;
3234
+ break;
3235
+ case 63:
3236
+ _context40.prev = 63;
3237
+ _context40.t2 = _context40["catch"](56);
3238
+ console.error("[Checkout] \u5220\u9664\u8BA2\u5355 ".concat(orderInfo.uuid, " \u5931\u8D25:"), _context40.t2);
3239
+ case 66:
3240
+ _context40.next = 54;
3241
+ break;
3242
+ case 68:
3243
+ _context40.next = 73;
3244
+ break;
3245
+ case 70:
3246
+ _context40.prev = 70;
3247
+ _context40.t3 = _context40["catch"](52);
3248
+ _iterator2.e(_context40.t3);
3249
+ case 73:
3250
+ _context40.prev = 73;
3251
+ _iterator2.f();
3252
+ return _context40.finish(73);
3253
+ case 76:
3254
+ summary = {
3255
+ totalOrders: allOrders.length,
3256
+ expiredSyncedOrders: ordersToDelete.length,
3257
+ maxOrdersToDelete: maxOrdersToDelete,
3258
+ actualDeletedOrders: deletedCount,
3259
+ retentionDays: retentionDays,
3260
+ cleanupDate: new Date().toISOString(),
3261
+ thresholdDate: thresholdDate.toISOString(),
3262
+ skippedOrders: Math.max(0, ordersToDelete.length - maxOrdersToDelete)
3263
+ }; // 记录清理结果
3264
+ this.logInfo('Expired orders cleanup completed', summary);
3265
+ if (ordersToDelete.length > maxOrdersToDelete) {
3266
+ console.log("[Checkout] \u8FC7\u671F\u8BA2\u5355\u6E05\u7406\u5B8C\u6210: \u603B\u8BA1 ".concat(allOrders.length, " \u4E2A\u8BA2\u5355\uFF0C\u53D1\u73B0 ").concat(ordersToDelete.length, " \u4E2A\u8FC7\u671F\u5DF2\u540C\u6B65\u8BA2\u5355\uFF0C\u5220\u9664\u4E86 ").concat(deletedCount, " \u4E2A\uFF08\u9650\u5236\u4E3A ").concat(maxOrdersToDelete, " \u4E2A\uFF09"));
3267
+ } else {
3268
+ console.log("[Checkout] \u8FC7\u671F\u8BA2\u5355\u6E05\u7406\u5B8C\u6210: \u603B\u8BA1 ".concat(allOrders.length, " \u4E2A\u8BA2\u5355\uFF0C\u5220\u9664\u4E86 ").concat(deletedCount, " \u4E2A\u8FC7\u671F\u5DF2\u540C\u6B65\u8BA2\u5355"));
3269
+ }
3270
+ _context40.next = 86;
3271
+ break;
3272
+ case 81:
3273
+ _context40.prev = 81;
3274
+ _context40.t4 = _context40["catch"](0);
3275
+ errorMessage = _context40.t4 instanceof Error ? _context40.t4.message : String(_context40.t4);
3276
+ console.error('[Checkout] 清理过期订单数据失败:', _context40.t4);
3277
+ this.logError('Expired orders cleanup failed', {
3278
+ error: errorMessage
3279
+ });
3280
+ case 86:
3281
+ case "end":
3282
+ return _context40.stop();
3283
+ }
3284
+ }, _callee40, this, [[0, 81], [20, 43, 46, 49], [24, 35], [52, 70, 73, 76], [56, 63]]);
3285
+ }));
3286
+ function cleanupExpiredOrdersAsync() {
3287
+ return _cleanupExpiredOrdersAsync.apply(this, arguments);
3288
+ }
3289
+ return cleanupExpiredOrdersAsync;
3290
+ }()
3198
3291
  /**
3199
3292
  * 计算已支付金额(从 Payment 模块获取最新数据)
3200
3293
  */
3294
+ )
3201
3295
  }, {
3202
3296
  key: "calculatePaidAmountAsync",
3203
3297
  value: (function () {
3204
- var _calculatePaidAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42() {
3298
+ var _calculatePaidAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
3205
3299
  var payments, paidAmount, result;
3206
- return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3207
- while (1) switch (_context42.prev = _context42.next) {
3300
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3301
+ while (1) switch (_context41.prev = _context41.next) {
3208
3302
  case 0:
3209
3303
  if (this.store.currentOrder) {
3210
- _context42.next = 3;
3304
+ _context41.next = 3;
3211
3305
  break;
3212
3306
  }
3213
3307
  console.log('[Checkout] calculatePaidAmountAsync: 没有当前订单');
3214
- return _context42.abrupt("return", '0.00');
3308
+ return _context41.abrupt("return", '0.00');
3215
3309
  case 3:
3216
- _context42.prev = 3;
3217
- _context42.next = 6;
3310
+ _context41.prev = 3;
3311
+ _context41.next = 6;
3218
3312
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
3219
3313
  );
3220
3314
  case 6:
3221
- payments = _context42.sent;
3315
+ payments = _context41.sent;
3222
3316
  console.log('[Checkout] calculatePaidAmountAsync: 支付项详情:', {
3223
3317
  paymentCount: payments.length,
3224
3318
  payments: payments.map(function (p) {
@@ -3252,17 +3346,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3252
3346
  }, 0);
3253
3347
  result = paidAmount.toFixed(2);
3254
3348
  console.log('[Checkout] calculatePaidAmountAsync: 计算结果 =', result);
3255
- return _context42.abrupt("return", result);
3349
+ return _context41.abrupt("return", result);
3256
3350
  case 14:
3257
- _context42.prev = 14;
3258
- _context42.t0 = _context42["catch"](3);
3259
- console.error('[Checkout] calculatePaidAmountAsync 失败:', _context42.t0);
3260
- return _context42.abrupt("return", '0.00');
3351
+ _context41.prev = 14;
3352
+ _context41.t0 = _context41["catch"](3);
3353
+ console.error('[Checkout] calculatePaidAmountAsync 失败:', _context41.t0);
3354
+ return _context41.abrupt("return", '0.00');
3261
3355
  case 18:
3262
3356
  case "end":
3263
- return _context42.stop();
3357
+ return _context41.stop();
3264
3358
  }
3265
- }, _callee42, this, [[3, 14]]);
3359
+ }, _callee41, this, [[3, 14]]);
3266
3360
  }));
3267
3361
  function calculatePaidAmountAsync() {
3268
3362
  return _calculatePaidAmountAsync.apply(this, arguments);
@@ -3276,25 +3370,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3276
3370
  }, {
3277
3371
  key: "calculateRemainingAmountAsync",
3278
3372
  value: (function () {
3279
- var _calculateRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43() {
3373
+ var _calculateRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42() {
3280
3374
  var totalAmount, paidAmount, remainingAmount, result;
3281
- return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3282
- while (1) switch (_context43.prev = _context43.next) {
3375
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3376
+ while (1) switch (_context42.prev = _context42.next) {
3283
3377
  case 0:
3284
3378
  if (this.store.currentOrder) {
3285
- _context43.next = 3;
3379
+ _context42.next = 3;
3286
3380
  break;
3287
3381
  }
3288
3382
  console.log('[Checkout] calculateRemainingAmountAsync: 没有当前订单');
3289
- return _context43.abrupt("return", '0.00');
3383
+ return _context42.abrupt("return", '0.00');
3290
3384
  case 3:
3291
3385
  totalAmount = parseFloat(this.store.currentOrder.total_amount || '0');
3292
- _context43.t0 = parseFloat;
3293
- _context43.next = 7;
3386
+ _context42.t0 = parseFloat;
3387
+ _context42.next = 7;
3294
3388
  return this.calculatePaidAmountAsync();
3295
3389
  case 7:
3296
- _context43.t1 = _context43.sent;
3297
- paidAmount = (0, _context43.t0)(_context43.t1);
3390
+ _context42.t1 = _context42.sent;
3391
+ paidAmount = (0, _context42.t0)(_context42.t1);
3298
3392
  remainingAmount = totalAmount - paidAmount;
3299
3393
  result = Math.max(0, remainingAmount).toFixed(2);
3300
3394
  console.log('[Checkout] calculateRemainingAmountAsync: 计算详情:', {
@@ -3305,12 +3399,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3305
3399
  finalResult: result,
3306
3400
  说明: '已支付金额包含抹零计算(amount + |rounding_amount|)'
3307
3401
  });
3308
- return _context43.abrupt("return", result);
3402
+ return _context42.abrupt("return", result);
3309
3403
  case 13:
3310
3404
  case "end":
3311
- return _context43.stop();
3405
+ return _context42.stop();
3312
3406
  }
3313
- }, _callee43, this);
3407
+ }, _callee42, this);
3314
3408
  }));
3315
3409
  function calculateRemainingAmountAsync() {
3316
3410
  return _calculateRemainingAmountAsync.apply(this, arguments);
@@ -3324,33 +3418,33 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3324
3418
  }, {
3325
3419
  key: "updateBalanceDueAmount",
3326
3420
  value: (function () {
3327
- var _updateBalanceDueAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44() {
3328
- var _this$store$currentOr18, remainingAmount, currentBalanceDueAmount;
3329
- return _regeneratorRuntime().wrap(function _callee44$(_context44) {
3330
- while (1) switch (_context44.prev = _context44.next) {
3421
+ var _updateBalanceDueAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43() {
3422
+ var _this$store$currentOr24, remainingAmount, currentBalanceDueAmount;
3423
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3424
+ while (1) switch (_context43.prev = _context43.next) {
3331
3425
  case 0:
3332
- _context44.prev = 0;
3333
- _context44.next = 3;
3426
+ _context43.prev = 0;
3427
+ _context43.next = 3;
3334
3428
  return this.calculateRemainingAmountAsync();
3335
3429
  case 3:
3336
- remainingAmount = _context44.sent;
3430
+ remainingAmount = _context43.sent;
3337
3431
  currentBalanceDueAmount = this.store.balanceDueAmount;
3338
3432
  console.log('[Checkout] updateBalanceDueAmount: 状态检查:', {
3339
3433
  calculatedRemainingAmount: remainingAmount,
3340
3434
  currentBalanceDueAmount: currentBalanceDueAmount,
3341
3435
  needsUpdate: remainingAmount !== currentBalanceDueAmount,
3342
- orderUuid: (_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.uuid
3436
+ orderUuid: (_this$store$currentOr24 = this.store.currentOrder) === null || _this$store$currentOr24 === void 0 ? void 0 : _this$store$currentOr24.uuid
3343
3437
  });
3344
3438
 
3345
3439
  // 只有当剩余金额与当前 balanceDueAmount 不同时才更新
3346
3440
  if (!(remainingAmount !== currentBalanceDueAmount)) {
3347
- _context44.next = 13;
3441
+ _context43.next = 13;
3348
3442
  break;
3349
3443
  }
3350
3444
  this.store.balanceDueAmount = remainingAmount;
3351
3445
 
3352
3446
  // 发出 balanceDueAmount 变更事件
3353
- _context44.next = 10;
3447
+ _context43.next = 10;
3354
3448
  return this.core.effects.emit(CheckoutHooks.OnBalanceDueAmountChanged, {
3355
3449
  oldAmount: currentBalanceDueAmount,
3356
3450
  newAmount: remainingAmount,
@@ -3361,7 +3455,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3361
3455
  oldAmount: currentBalanceDueAmount,
3362
3456
  newAmount: remainingAmount
3363
3457
  });
3364
- _context44.next = 14;
3458
+ _context43.next = 14;
3365
3459
  break;
3366
3460
  case 13:
3367
3461
  console.log('[Checkout] balanceDueAmount 无需更新,当前值已是最新:', {
@@ -3369,17 +3463,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3369
3463
  remainingAmount: remainingAmount
3370
3464
  });
3371
3465
  case 14:
3372
- _context44.next = 19;
3466
+ _context43.next = 19;
3373
3467
  break;
3374
3468
  case 16:
3375
- _context44.prev = 16;
3376
- _context44.t0 = _context44["catch"](0);
3377
- console.error('[Checkout] 更新 balanceDueAmount 失败:', _context44.t0);
3469
+ _context43.prev = 16;
3470
+ _context43.t0 = _context43["catch"](0);
3471
+ console.error('[Checkout] 更新 balanceDueAmount 失败:', _context43.t0);
3378
3472
  case 19:
3379
3473
  case "end":
3380
- return _context44.stop();
3474
+ return _context43.stop();
3381
3475
  }
3382
- }, _callee44, this, [[0, 16]]);
3476
+ }, _callee43, this, [[0, 16]]);
3383
3477
  }));
3384
3478
  function updateBalanceDueAmount() {
3385
3479
  return _updateBalanceDueAmount.apply(this, arguments);
@@ -3393,68 +3487,63 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3393
3487
  }, {
3394
3488
  key: "updateStateAmountToRemaining",
3395
3489
  value: (function () {
3396
- var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45() {
3397
- var _this$store$currentOr19, remainingAmount, currentStateAmount;
3398
- return _regeneratorRuntime().wrap(function _callee45$(_context45) {
3399
- while (1) switch (_context45.prev = _context45.next) {
3490
+ var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44() {
3491
+ var _this$store$currentOr25, remainingAmount, currentStateAmount;
3492
+ return _regeneratorRuntime().wrap(function _callee44$(_context44) {
3493
+ while (1) switch (_context44.prev = _context44.next) {
3400
3494
  case 0:
3401
- _context45.prev = 0;
3402
- _context45.next = 3;
3495
+ _context44.prev = 0;
3496
+ _context44.next = 3;
3403
3497
  return this.calculateRemainingAmountAsync();
3404
3498
  case 3:
3405
- remainingAmount = _context45.sent;
3499
+ remainingAmount = _context44.sent;
3406
3500
  currentStateAmount = this.store.stateAmount;
3407
3501
  console.log('[Checkout] updateStateAmountToRemaining: 状态检查:', {
3408
3502
  calculatedRemainingAmount: remainingAmount,
3409
3503
  currentStateAmount: currentStateAmount,
3410
3504
  needsUpdate: remainingAmount !== currentStateAmount,
3411
- orderUuid: (_this$store$currentOr19 = this.store.currentOrder) === null || _this$store$currentOr19 === void 0 ? void 0 : _this$store$currentOr19.uuid
3505
+ orderUuid: (_this$store$currentOr25 = this.store.currentOrder) === null || _this$store$currentOr25 === void 0 ? void 0 : _this$store$currentOr25.uuid
3412
3506
  });
3413
3507
 
3414
3508
  // 只有当剩余金额与当前 stateAmount 不同时才更新
3415
- if (!(remainingAmount !== currentStateAmount)) {
3416
- _context45.next = 13;
3417
- break;
3509
+ if (remainingAmount !== currentStateAmount) {
3510
+ this.store.stateAmount = remainingAmount;
3511
+
3512
+ // 发出 stateAmount 变更事件
3513
+ this.core.effects.emit(CheckoutHooks.OnStateAmountChanged, {
3514
+ oldAmount: currentStateAmount,
3515
+ newAmount: remainingAmount,
3516
+ timestamp: Date.now()
3517
+ });
3518
+ console.log('[Checkout] stateAmount 已自动更新为剩余金额:', {
3519
+ oldAmount: currentStateAmount,
3520
+ newAmount: remainingAmount
3521
+ });
3522
+ } else {
3523
+ console.log('[Checkout] stateAmount 无需更新,当前值已是最新:', {
3524
+ stateAmount: currentStateAmount,
3525
+ remainingAmount: remainingAmount
3526
+ });
3418
3527
  }
3419
- this.store.stateAmount = remainingAmount;
3420
3528
 
3421
- // 发出 stateAmount 变更事件
3422
- _context45.next = 10;
3423
- return this.core.effects.emit(CheckoutHooks.OnStateAmountChanged, {
3424
- oldAmount: currentStateAmount,
3425
- newAmount: remainingAmount,
3426
- timestamp: Date.now()
3427
- });
3428
- case 10:
3429
- console.log('[Checkout] stateAmount 已自动更新为剩余金额:', {
3430
- oldAmount: currentStateAmount,
3431
- newAmount: remainingAmount
3432
- });
3433
- _context45.next = 14;
3434
- break;
3435
- case 13:
3436
- console.log('[Checkout] stateAmount 无需更新,当前值已是最新:', {
3437
- stateAmount: currentStateAmount,
3438
- remainingAmount: remainingAmount
3439
- });
3440
- case 14:
3441
- _context45.next = 16;
3529
+ // 同步更新系统内部的 balanceDueAmount
3530
+ _context44.next = 9;
3442
3531
  return this.updateBalanceDueAmount();
3443
- case 16:
3444
- _context45.next = 18;
3532
+ case 9:
3533
+ _context44.next = 11;
3445
3534
  return this.checkOrderPaymentCompletion();
3446
- case 18:
3447
- _context45.next = 23;
3535
+ case 11:
3536
+ _context44.next = 16;
3448
3537
  break;
3449
- case 20:
3450
- _context45.prev = 20;
3451
- _context45.t0 = _context45["catch"](0);
3452
- console.error('[Checkout] 更新 stateAmount 为剩余金额失败:', _context45.t0);
3453
- case 23:
3538
+ case 13:
3539
+ _context44.prev = 13;
3540
+ _context44.t0 = _context44["catch"](0);
3541
+ console.error('[Checkout] 更新 stateAmount 为剩余金额失败:', _context44.t0);
3542
+ case 16:
3454
3543
  case "end":
3455
- return _context45.stop();
3544
+ return _context44.stop();
3456
3545
  }
3457
- }, _callee45, this, [[0, 20]]);
3546
+ }, _callee44, this, [[0, 13]]);
3458
3547
  }));
3459
3548
  function updateStateAmountToRemaining() {
3460
3549
  return _updateStateAmountToRemaining.apply(this, arguments);
@@ -3470,32 +3559,32 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3470
3559
  }, {
3471
3560
  key: "checkOrderPaymentCompletion",
3472
3561
  value: (function () {
3473
- var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46() {
3562
+ var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45() {
3474
3563
  var remainingAmount, remainingValue, totalAmount, paidAmount, currentPayments, hasPaymentItems, allPaymentsHaveVoucherId, shouldAutoSync;
3475
- return _regeneratorRuntime().wrap(function _callee46$(_context46) {
3476
- while (1) switch (_context46.prev = _context46.next) {
3564
+ return _regeneratorRuntime().wrap(function _callee45$(_context45) {
3565
+ while (1) switch (_context45.prev = _context45.next) {
3477
3566
  case 0:
3478
- _context46.prev = 0;
3567
+ _context45.prev = 0;
3479
3568
  if (this.store.currentOrder) {
3480
- _context46.next = 3;
3569
+ _context45.next = 3;
3481
3570
  break;
3482
3571
  }
3483
- return _context46.abrupt("return");
3572
+ return _context45.abrupt("return");
3484
3573
  case 3:
3485
- _context46.next = 5;
3574
+ _context45.next = 5;
3486
3575
  return this.calculateRemainingAmountAsync();
3487
3576
  case 5:
3488
- remainingAmount = _context46.sent;
3577
+ remainingAmount = _context45.sent;
3489
3578
  remainingValue = parseFloat(remainingAmount); // 当剩余金额小于等于0时,认为订单已完成支付
3490
3579
  if (!(remainingValue <= 0)) {
3491
- _context46.next = 29;
3580
+ _context45.next = 29;
3492
3581
  break;
3493
3582
  }
3494
3583
  totalAmount = this.store.currentOrder.total_amount;
3495
- _context46.next = 11;
3584
+ _context45.next = 11;
3496
3585
  return this.calculatePaidAmountAsync();
3497
3586
  case 11:
3498
- paidAmount = _context46.sent;
3587
+ paidAmount = _context45.sent;
3499
3588
  console.log('[Checkout] 检测到订单支付完成:', {
3500
3589
  orderUuid: this.store.currentOrder.uuid,
3501
3590
  orderId: this.store.currentOrder.order_id,
@@ -3506,11 +3595,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3506
3595
  });
3507
3596
 
3508
3597
  // 从 Payment 模块获取最新支付项,检查自动同步条件
3509
- _context46.next = 15;
3598
+ _context45.next = 15;
3510
3599
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
3511
3600
  );
3512
3601
  case 15:
3513
- currentPayments = _context46.sent;
3602
+ currentPayments = _context45.sent;
3514
3603
  // 检查自动同步条件:
3515
3604
  // 1. 待付金额为 0 ✓ (已在上面检查)
3516
3605
  // 2. 需要有支付项
@@ -3544,14 +3633,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3544
3633
  })
3545
3634
  });
3546
3635
  if (!shouldAutoSync) {
3547
- _context46.next = 26;
3636
+ _context45.next = 26;
3548
3637
  break;
3549
3638
  }
3550
3639
  console.log('[Checkout] 满足自动同步条件,开始同步订单到后端...');
3551
- _context46.next = 24;
3640
+ _context45.next = 24;
3552
3641
  return this.syncOrderToBackend();
3553
3642
  case 24:
3554
- _context46.next = 27;
3643
+ _context45.next = 27;
3555
3644
  break;
3556
3645
  case 26:
3557
3646
  if (!hasPaymentItems) {
@@ -3560,7 +3649,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3560
3649
  console.log('[Checkout] 所有支付项均为代金券类型,跳过订单同步');
3561
3650
  }
3562
3651
  case 27:
3563
- _context46.next = 29;
3652
+ _context45.next = 29;
3564
3653
  return this.core.effects.emit(CheckoutHooks.OnOrderPaymentCompleted, {
3565
3654
  orderUuid: this.store.currentOrder.uuid,
3566
3655
  orderId: this.store.currentOrder.order_id,
@@ -3570,78 +3659,28 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3570
3659
  timestamp: Date.now()
3571
3660
  });
3572
3661
  case 29:
3573
- _context46.next = 34;
3662
+ _context45.next = 34;
3574
3663
  break;
3575
3664
  case 31:
3576
- _context46.prev = 31;
3577
- _context46.t0 = _context46["catch"](0);
3578
- console.error('[Checkout] 检查订单支付完成状态失败:', _context46.t0);
3665
+ _context45.prev = 31;
3666
+ _context45.t0 = _context45["catch"](0);
3667
+ console.error('[Checkout] 检查订单支付完成状态失败:', _context45.t0);
3579
3668
  case 34:
3580
3669
  case "end":
3581
- return _context46.stop();
3670
+ return _context45.stop();
3582
3671
  }
3583
- }, _callee46, this, [[0, 31]]);
3672
+ }, _callee45, this, [[0, 31]]);
3584
3673
  }));
3585
3674
  function checkOrderPaymentCompletion() {
3586
3675
  return _checkOrderPaymentCompletion.apply(this, arguments);
3587
3676
  }
3588
3677
  return checkOrderPaymentCompletion;
3589
3678
  }()
3590
- /**
3591
- * 判断支付方式是否需要同步订单到后端
3592
- *
3593
- * 现金支付(CASHMANUAL)和自定义支付不需要同步,其他支付方式需要同步
3594
- *
3595
- * @param paymentCode 支付方式代码
3596
- * @param paymentType 支付方式类型
3597
- * @returns 是否需要同步订单
3598
- */
3599
- )
3600
- }, {
3601
- key: "shouldSyncOrderForPayment",
3602
- value: function shouldSyncOrderForPayment(paymentCode, paymentType) {
3603
- var codeUpper = (paymentCode === null || paymentCode === void 0 ? void 0 : paymentCode.toUpperCase()) || '';
3604
- var typeUpper = (paymentType === null || paymentType === void 0 ? void 0 : paymentType.toUpperCase()) || '';
3605
-
3606
- // 现金支付不需要同步 - 支持多种现金支付识别方式
3607
- var cashIdentifiers = ['CASHMANUAL', 'CASH', 'MANUAL'];
3608
- if (cashIdentifiers.some(function (id) {
3609
- return codeUpper.includes(id) || typeUpper.includes(id);
3610
- })) {
3611
- return false;
3612
- }
3613
-
3614
- // 标准现金支付代码检查
3615
- if (paymentCode === PaymentMethodType.Cash || paymentType === PaymentMethodType.Cash) {
3616
- return false;
3617
- }
3618
-
3619
- // 自定义支付不需要同步
3620
- if (codeUpper.includes('CUSTOM') || typeUpper.includes('CUSTOM')) {
3621
- return false;
3622
- }
3623
-
3624
- // 其他支付方式都需要同步
3625
- return true;
3626
- }
3627
-
3628
3679
  /**
3629
3680
  * 同步订单到后端
3630
3681
  *
3631
3682
  * 调用后端 /order/checkout 接口创建真实订单
3632
3683
  */
3633
- /**
3634
- * 判断订单ID是否为本地生成的虚拟ID
3635
- *
3636
- * @param orderId 订单ID
3637
- * @returns true 表示是虚拟ID,false 表示是真实的后端ID
3638
- */
3639
- }, {
3640
- key: "isVirtualOrderId",
3641
- value: function isVirtualOrderId(orderId) {
3642
- return orderId.startsWith('local_order_');
3643
- }
3644
-
3645
3684
  /**
3646
3685
  * 同步订单到后端并返回真实订单ID
3647
3686
  *
@@ -3649,15 +3688,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3649
3688
  * @param customPaymentItems 自定义支付项列表,如果提供则使用此列表而不是从数据库获取
3650
3689
  * @returns 包含订单ID、UUID和完整后端响应的对象
3651
3690
  */
3691
+ )
3652
3692
  }, {
3653
3693
  key: "syncOrderToBackendWithReturn",
3654
3694
  value: (function () {
3655
- var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47() {
3656
- var _this4 = this,
3695
+ var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46() {
3696
+ var _this$store$currentCu2,
3697
+ _this4 = this,
3657
3698
  _processedPaymentItem,
3658
- _this$store$currentCu2,
3659
- _this$store$currentOr20,
3660
- _this$store$currentOr21,
3699
+ _this$store$currentCu3,
3700
+ _this$store$currentOr26,
3701
+ _this$store$currentOr27,
3661
3702
  _checkoutResponse3,
3662
3703
  _checkoutResponse4,
3663
3704
  _checkoutResponse5,
@@ -3679,6 +3720,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3679
3720
  checkoutResponse,
3680
3721
  submitSuccess,
3681
3722
  submitError,
3723
+ _orderParams$bookings,
3724
+ _orderParams$relation,
3725
+ _orderParams$payments,
3726
+ _orderParams$payments2,
3682
3727
  _checkoutResponse,
3683
3728
  _checkoutResponse2,
3684
3729
  responseStatus,
@@ -3695,21 +3740,33 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3695
3740
  beforeManualUpdate,
3696
3741
  finalOrderId,
3697
3742
  finalIsVirtual,
3698
- _args47 = arguments;
3699
- return _regeneratorRuntime().wrap(function _callee47$(_context47) {
3700
- while (1) switch (_context47.prev = _context47.next) {
3743
+ _args46 = arguments;
3744
+ return _regeneratorRuntime().wrap(function _callee46$(_context46) {
3745
+ while (1) switch (_context46.prev = _context46.next) {
3701
3746
  case 0:
3702
- isManual = _args47.length > 0 && _args47[0] !== undefined ? _args47[0] : false;
3703
- customPaymentItems = _args47.length > 1 ? _args47[1] : undefined;
3747
+ isManual = _args46.length > 0 && _args46[0] !== undefined ? _args46[0] : false;
3748
+ customPaymentItems = _args46.length > 1 ? _args46[1] : undefined;
3704
3749
  if (!(!this.store.localOrderData || !this.store.currentOrder)) {
3705
- _context47.next = 4;
3750
+ _context46.next = 4;
3706
3751
  break;
3707
3752
  }
3708
3753
  throw new Error('缺少必要的订单数据,无法同步到后端');
3709
3754
  case 4:
3755
+ this.logInfo('syncOrderToBackendWithReturn called', {
3756
+ isManual: isManual,
3757
+ hasCustomPaymentItems: !!customPaymentItems,
3758
+ customPaymentItemsCount: (customPaymentItems === null || customPaymentItems === void 0 ? void 0 : customPaymentItems.length) || 0,
3759
+ currentOrderId: this.store.currentOrder.order_id,
3760
+ orderUuid: this.store.currentOrder.uuid,
3761
+ isOrderSynced: this.store.isOrderSynced,
3762
+ isVirtualOrderId: isVirtualOrderId(this.store.currentOrder.order_id),
3763
+ localOrderDataType: this.store.localOrderData.type,
3764
+ platform: this.store.localOrderData.platform,
3765
+ customerId: (_this$store$currentCu2 = this.store.currentCustomer) === null || _this$store$currentCu2 === void 0 ? void 0 : _this$store$currentCu2.customer_id
3766
+ });
3710
3767
  syncType = isManual ? '手动' : '自动'; // 判断是创建订单还是更新订单
3711
3768
  currentOrderId = this.store.currentOrder.order_id;
3712
- hasRealOrderId = currentOrderId && !this.isVirtualOrderId(currentOrderId); // 更准确的判断:优先考虑同步状态
3769
+ hasRealOrderId = currentOrderId && !isVirtualOrderId(currentOrderId); // 更准确的判断:优先考虑同步状态
3713
3770
  // 1. 如果订单已经同步过,无论订单ID是什么,都应该是更新操作(防止ID被意外重置)
3714
3771
  // 2. 如果订单未同步但有真实订单ID,也认为是更新操作
3715
3772
  // 3. 其他情况都是创建操作
@@ -3736,24 +3793,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3736
3793
  });
3737
3794
  console.log("[Checkout] \u5F00\u59CB".concat(syncType).concat(operation, "\u8BA2\u5355\u5230\u540E\u7AEF..."), {
3738
3795
  currentOrderId: currentOrderId,
3739
- isVirtualId: this.isVirtualOrderId(currentOrderId || ''),
3796
+ isVirtualId: isVirtualOrderId(currentOrderId || ''),
3740
3797
  operation: operation,
3741
3798
  orderUuid: this.store.currentOrder.uuid,
3742
3799
  isOrderSynced: this.store.isOrderSynced
3743
3800
  });
3744
3801
 
3745
3802
  // 获取当前订单的支付项
3746
- _context47.t0 = customPaymentItems;
3747
- if (_context47.t0) {
3748
- _context47.next = 18;
3803
+ _context46.t0 = customPaymentItems;
3804
+ if (_context46.t0) {
3805
+ _context46.next = 19;
3749
3806
  break;
3750
3807
  }
3751
- _context47.next = 17;
3808
+ _context46.next = 18;
3752
3809
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
3753
- case 17:
3754
- _context47.t0 = _context47.sent;
3755
3810
  case 18:
3756
- paymentItems = _context47.t0;
3811
+ _context46.t0 = _context46.sent;
3812
+ case 19:
3813
+ paymentItems = _context46.t0;
3757
3814
  console.log('[Checkout] 获取到支付项:', {
3758
3815
  count: paymentItems.length,
3759
3816
  isCustomFiltered: !!customPaymentItems,
@@ -3806,7 +3863,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3806
3863
  platform: this.store.localOrderData.platform,
3807
3864
  payments: processedPaymentItems,
3808
3865
  // 使用处理过的支付项数据
3809
- customer_id: (_this$store$currentCu2 = this.store.currentCustomer) === null || _this$store$currentCu2 === void 0 ? void 0 : _this$store$currentCu2.customer_id,
3866
+ customer_id: (_this$store$currentCu3 = this.store.currentCustomer) === null || _this$store$currentCu3 === void 0 ? void 0 : _this$store$currentCu3.customer_id,
3810
3867
  // 添加客户ID
3811
3868
  is_price_include_tax: this.otherParams.is_price_include_tax,
3812
3869
  // core 有
@@ -3819,8 +3876,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3819
3876
  currency_code: this.otherParams.currency_code,
3820
3877
  currency_symbol: this.otherParams.currency_symbol,
3821
3878
  currency_format: this.otherParams.currency_format,
3822
- is_deposit: ((_this$store$currentOr20 = this.store.currentOrder) === null || _this$store$currentOr20 === void 0 ? void 0 : _this$store$currentOr20.is_deposit) || 0,
3823
- deposit_amount: ((_this$store$currentOr21 = this.store.currentOrder) === null || _this$store$currentOr21 === void 0 ? void 0 : _this$store$currentOr21.deposit_amount) || '0.00',
3879
+ is_deposit: ((_this$store$currentOr26 = this.store.currentOrder) === null || _this$store$currentOr26 === void 0 ? void 0 : _this$store$currentOr26.is_deposit) || 0,
3880
+ deposit_amount: ((_this$store$currentOr27 = this.store.currentOrder) === null || _this$store$currentOr27 === void 0 ? void 0 : _this$store$currentOr27.deposit_amount) || '0.00',
3824
3881
  // surcharge_fee: this.otherParams.surcharge_fee,
3825
3882
  // surcharges: ,
3826
3883
  product_tax_fee: this.store.localOrderData.tax_fee,
@@ -3830,7 +3887,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3830
3887
 
3831
3888
  if (isUpdateOperation) {
3832
3889
  // 如果当前订单ID是虚拟ID,但订单已同步过,可能存在数据不一致的问题
3833
- if (this.isVirtualOrderId(currentOrderId)) {
3890
+ if (isVirtualOrderId(currentOrderId)) {
3834
3891
  console.error('[Checkout] 数据不一致警告:更新操作但订单ID仍为虚拟ID!', {
3835
3892
  currentOrderId: currentOrderId,
3836
3893
  isOrderSynced: this.store.isOrderSynced,
@@ -3852,7 +3909,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3852
3909
 
3853
3910
  // 发送下单接口请求开始事件
3854
3911
  startTime = Date.now();
3855
- _context47.next = 27;
3912
+ _context46.next = 28;
3856
3913
  return this.core.effects.emit(CheckoutHooks.OnOrderSubmitStart, {
3857
3914
  orderUuid: this.store.currentOrder.uuid,
3858
3915
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3860,26 +3917,50 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3860
3917
  paymentItemCount: paymentItems.length,
3861
3918
  timestamp: startTime
3862
3919
  });
3863
- case 27:
3920
+ case 28:
3864
3921
  submitSuccess = false;
3865
- _context47.prev = 28;
3866
- _context47.next = 31;
3922
+ _context46.prev = 29;
3923
+ // 记录接口调用参数
3924
+ this.logInfo('Calling backend checkout API', {
3925
+ url: '/order/checkout',
3926
+ operation: operation,
3927
+ isManual: isManual,
3928
+ orderType: orderParams.type,
3929
+ platform: orderParams.platform,
3930
+ customerId: orderParams.customer_id,
3931
+ isDeposit: orderParams.is_deposit,
3932
+ depositAmount: orderParams.deposit_amount,
3933
+ bookingsCount: ((_orderParams$bookings = orderParams.bookings) === null || _orderParams$bookings === void 0 ? void 0 : _orderParams$bookings.length) || 0,
3934
+ relationProductsCount: ((_orderParams$relation = orderParams.relation_products) === null || _orderParams$relation === void 0 ? void 0 : _orderParams$relation.length) || 0,
3935
+ paymentsCount: ((_orderParams$payments = orderParams.payments) === null || _orderParams$payments === void 0 ? void 0 : _orderParams$payments.length) || 0,
3936
+ paymentMethods: ((_orderParams$payments2 = orderParams.payments) === null || _orderParams$payments2 === void 0 ? void 0 : _orderParams$payments2.map(function (p) {
3937
+ return p.code;
3938
+ })) || [],
3939
+ hasOrderId: !!orderParams.order_id,
3940
+ orderIdIncluded: orderParams.order_id,
3941
+ productTaxFee: orderParams.product_tax_fee,
3942
+ note: orderParams.note,
3943
+ scheduleDate: orderParams.schedule_date
3944
+ });
3945
+
3946
+ // 调用 Order 模块的专用 createOrderByCheckout 方法
3947
+ _context46.next = 33;
3867
3948
  return this.order.createOrderByCheckout(orderParams);
3868
- case 31:
3869
- checkoutResponse = _context47.sent;
3949
+ case 33:
3950
+ checkoutResponse = _context46.sent;
3870
3951
  submitSuccess = true;
3871
3952
  console.log('[Checkout] 下单接口调用成功');
3872
- _context47.next = 43;
3953
+ _context46.next = 45;
3873
3954
  break;
3874
- case 36:
3875
- _context47.prev = 36;
3876
- _context47.t1 = _context47["catch"](28);
3955
+ case 38:
3956
+ _context46.prev = 38;
3957
+ _context46.t1 = _context46["catch"](29);
3877
3958
  submitSuccess = false;
3878
- submitError = _context47.t1 instanceof Error ? _context47.t1.message : String(_context47.t1);
3959
+ submitError = _context46.t1 instanceof Error ? _context46.t1.message : String(_context46.t1);
3879
3960
  // console.error('[Checkout] 下单接口调用失败:', submitError);
3880
3961
 
3881
3962
  // 发送订单同步失败事件(网络错误或请求失败)
3882
- _context47.next = 42;
3963
+ _context46.next = 44;
3883
3964
  return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
3884
3965
  orderUuid: this.store.currentOrder.uuid,
3885
3966
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3889,11 +3970,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3889
3970
  duration: Date.now() - startTime,
3890
3971
  timestamp: Date.now()
3891
3972
  });
3892
- case 42:
3893
- throw _context47.t1;
3894
- case 43:
3895
- _context47.prev = 43;
3896
- _context47.next = 46;
3973
+ case 44:
3974
+ throw _context46.t1;
3975
+ case 45:
3976
+ _context46.prev = 45;
3977
+ _context46.next = 48;
3897
3978
  return this.core.effects.emit(CheckoutHooks.OnOrderSubmitEnd, {
3898
3979
  success: submitSuccess,
3899
3980
  orderUuid: this.store.currentOrder.uuid,
@@ -3904,9 +3985,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3904
3985
  duration: Date.now() - startTime,
3905
3986
  timestamp: Date.now()
3906
3987
  });
3907
- case 46:
3908
- return _context47.finish(43);
3909
- case 47:
3988
+ case 48:
3989
+ return _context46.finish(45);
3990
+ case 49:
3910
3991
  console.log('[Checkout] 后端返回的响应数据:', {
3911
3992
  status: (_checkoutResponse3 = checkoutResponse) === null || _checkoutResponse3 === void 0 ? void 0 : _checkoutResponse3.status,
3912
3993
  code: (_checkoutResponse4 = checkoutResponse) === null || _checkoutResponse4 === void 0 ? void 0 : _checkoutResponse4.code,
@@ -3918,7 +3999,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3918
3999
  responseStatus = (_checkoutResponse7 = checkoutResponse) === null || _checkoutResponse7 === void 0 ? void 0 : _checkoutResponse7.status;
3919
4000
  isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse8 = checkoutResponse) === null || _checkoutResponse8 === void 0 ? void 0 : _checkoutResponse8.code) === 200;
3920
4001
  if (isSuccessResponse) {
3921
- _context47.next = 56;
4002
+ _context46.next = 58;
3922
4003
  break;
3923
4004
  }
3924
4005
  errorMessage = ((_checkoutResponse9 = checkoutResponse) === null || _checkoutResponse9 === void 0 ? void 0 : _checkoutResponse9.message) || '订单同步失败,后端返回非成功状态';
@@ -3931,7 +4012,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3931
4012
  });
3932
4013
 
3933
4014
  // 发送订单同步失败事件
3934
- _context47.next = 55;
4015
+ _context46.next = 57;
3935
4016
  return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
3936
4017
  orderUuid: this.store.currentOrder.uuid,
3937
4018
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3942,20 +4023,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3942
4023
  duration: Date.now() - startTime,
3943
4024
  timestamp: Date.now()
3944
4025
  });
3945
- case 55:
4026
+ case 57:
3946
4027
  throw new Error(errorMessage);
3947
- case 56:
4028
+ case 58:
3948
4029
  console.log('[Checkout] 响应状态检查通过,开始处理订单数据');
3949
4030
  if (!isUpdateOperation) {
3950
- _context47.next = 62;
4031
+ _context46.next = 64;
3951
4032
  break;
3952
4033
  }
3953
4034
  // 更新操作:使用现有的订单ID
3954
4035
  realOrderId = currentOrderId;
3955
4036
  console.log("[Checkout] \u8BA2\u5355\u66F4\u65B0\u6210\u529F\uFF0C\u8BA2\u5355ID: ".concat(realOrderId));
3956
- _context47.next = 83;
4037
+ _context46.next = 85;
3957
4038
  break;
3958
- case 62:
4039
+ case 64:
3959
4040
  // 创建操作:从响应中提取新的订单ID
3960
4041
  extractedOrderId = (_checkoutResponse12 = checkoutResponse) === null || _checkoutResponse12 === void 0 || (_checkoutResponse12 = _checkoutResponse12.data) === null || _checkoutResponse12 === void 0 ? void 0 : _checkoutResponse12.order_id; // 如果data.order_id不存在,尝试直接从根级获取
3961
4042
  if (!extractedOrderId) {
@@ -3967,11 +4048,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3967
4048
  extractedOrderId = String(extractedOrderId);
3968
4049
  }
3969
4050
  if (extractedOrderId) {
3970
- _context47.next = 67;
4051
+ _context46.next = 69;
3971
4052
  break;
3972
4053
  }
3973
4054
  throw new Error('后端返回的订单信息中未包含订单ID');
3974
- case 67:
4055
+ case 69:
3975
4056
  realOrderId = extractedOrderId;
3976
4057
  console.log('[Checkout] 订单创建成功,真实订单ID:', realOrderId);
3977
4058
 
@@ -3981,11 +4062,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3981
4062
  oldOrderId: this.store.currentOrder.order_id,
3982
4063
  newOrderId: realOrderId
3983
4064
  });
3984
- _context47.prev = 70;
3985
- _context47.next = 73;
4065
+ _context46.prev = 72;
4066
+ _context46.next = 75;
3986
4067
  return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, realOrderId);
3987
- case 73:
3988
- updatedOrder = _context47.sent;
4068
+ case 75:
4069
+ updatedOrder = _context46.sent;
3989
4070
  console.log('[Checkout] Payment模块替换订单ID结果:', {
3990
4071
  wasSuccessful: !!updatedOrder,
3991
4072
  returnedOrderId: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.order_id,
@@ -4011,22 +4092,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4011
4092
  目标ID: realOrderId
4012
4093
  });
4013
4094
  }
4014
- _context47.next = 83;
4095
+ _context46.next = 85;
4015
4096
  break;
4016
- case 78:
4017
- _context47.prev = 78;
4018
- _context47.t2 = _context47["catch"](70);
4019
- console.error('[Checkout] 调用Payment模块替换订单ID时发生错误:', _context47.t2);
4097
+ case 80:
4098
+ _context46.prev = 80;
4099
+ _context46.t2 = _context46["catch"](72);
4100
+ console.error('[Checkout] 调用Payment模块替换订单ID时发生错误:', _context46.t2);
4020
4101
 
4021
4102
  // 发生错误时也进行手动替换
4022
4103
  this.store.currentOrder.order_id = realOrderId;
4023
4104
  console.log('[Checkout] 错误恢复:手动设置订单ID:', realOrderId);
4024
- case 83:
4105
+ case 85:
4025
4106
  // 标记订单已同步
4026
4107
  this.store.isOrderSynced = true;
4027
4108
 
4028
4109
  // 触发订单同步完成事件
4029
- _context47.next = 86;
4110
+ _context46.next = 88;
4030
4111
  return this.core.effects.emit(CheckoutHooks.OnOrderSynced, {
4031
4112
  orderUuid: this.store.currentOrder.uuid,
4032
4113
  realOrderId: realOrderId,
@@ -4035,10 +4116,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4035
4116
  isManual: isManual,
4036
4117
  response: checkoutResponse
4037
4118
  });
4038
- case 86:
4119
+ case 88:
4039
4120
  // 验证最终状态
4040
4121
  finalOrderId = this.store.currentOrder.order_id;
4041
- finalIsVirtual = this.isVirtualOrderId(finalOrderId || '');
4122
+ finalIsVirtual = isVirtualOrderId(finalOrderId || '');
4042
4123
  console.log("[Checkout] ".concat(syncType).concat(operation, "\u8BA2\u5355\u5230\u540E\u7AEF\u5B8C\u6210"), {
4043
4124
  返回的订单ID: realOrderId,
4044
4125
  当前存储的订单ID: finalOrderId,
@@ -4052,18 +4133,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4052
4133
  }
4053
4134
 
4054
4135
  // 返回同步结果
4055
- return _context47.abrupt("return", {
4136
+ return _context46.abrupt("return", {
4056
4137
  success: true,
4057
4138
  message: "\u8BA2\u5355".concat(operation, "\u6210\u529F"),
4058
4139
  orderId: realOrderId,
4059
4140
  orderUuid: this.store.currentOrder.uuid,
4060
4141
  response: checkoutResponse
4061
4142
  });
4062
- case 91:
4143
+ case 93:
4063
4144
  case "end":
4064
- return _context47.stop();
4145
+ return _context46.stop();
4065
4146
  }
4066
- }, _callee47, this, [[28, 36, 43, 47], [70, 78]]);
4147
+ }, _callee46, this, [[29, 38, 45, 49], [72, 80]]);
4067
4148
  }));
4068
4149
  function syncOrderToBackendWithReturn() {
4069
4150
  return _syncOrderToBackendWithReturn.apply(this, arguments);
@@ -4073,30 +4154,30 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4073
4154
  }, {
4074
4155
  key: "syncOrderToBackend",
4075
4156
  value: function () {
4076
- var _syncOrderToBackend = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee48() {
4157
+ var _syncOrderToBackend = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47() {
4077
4158
  var syncResult;
4078
- return _regeneratorRuntime().wrap(function _callee48$(_context48) {
4079
- while (1) switch (_context48.prev = _context48.next) {
4159
+ return _regeneratorRuntime().wrap(function _callee47$(_context47) {
4160
+ while (1) switch (_context47.prev = _context47.next) {
4080
4161
  case 0:
4081
- _context48.prev = 0;
4082
- _context48.next = 3;
4162
+ _context47.prev = 0;
4163
+ _context47.next = 3;
4083
4164
  return this.syncOrderToBackendWithReturn(false);
4084
4165
  case 3:
4085
- syncResult = _context48.sent;
4166
+ syncResult = _context47.sent;
4086
4167
  console.log('[Checkout] 自动同步订单完成:', syncResult);
4087
- _context48.next = 12;
4168
+ _context47.next = 12;
4088
4169
  break;
4089
4170
  case 7:
4090
- _context48.prev = 7;
4091
- _context48.t0 = _context48["catch"](0);
4092
- console.error('[Checkout] 同步订单到后端失败:', _context48.t0);
4093
- _context48.next = 12;
4094
- return this.handleError(new Error("\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context48.t0 instanceof Error ? _context48.t0.message : String(_context48.t0))), CheckoutErrorType.OrderCreationFailed);
4171
+ _context47.prev = 7;
4172
+ _context47.t0 = _context47["catch"](0);
4173
+ console.error('[Checkout] 同步订单到后端失败:', _context47.t0);
4174
+ _context47.next = 12;
4175
+ return this.handleError(new Error("\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context47.t0 instanceof Error ? _context47.t0.message : String(_context47.t0))), CheckoutErrorType.OrderCreationFailed);
4095
4176
  case 12:
4096
4177
  case "end":
4097
- return _context48.stop();
4178
+ return _context47.stop();
4098
4179
  }
4099
- }, _callee48, this, [[0, 7]]);
4180
+ }, _callee47, this, [[0, 7]]);
4100
4181
  }));
4101
4182
  function syncOrderToBackend() {
4102
4183
  return _syncOrderToBackend.apply(this, arguments);
@@ -4136,15 +4217,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4136
4217
  }, {
4137
4218
  key: "setOtherParams",
4138
4219
  value: function () {
4139
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee49(params) {
4220
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee48(params) {
4140
4221
  var _ref5,
4141
4222
  _ref5$cover,
4142
4223
  cover,
4143
- _args49 = arguments;
4144
- return _regeneratorRuntime().wrap(function _callee49$(_context49) {
4145
- while (1) switch (_context49.prev = _context49.next) {
4224
+ _args48 = arguments;
4225
+ return _regeneratorRuntime().wrap(function _callee48$(_context48) {
4226
+ while (1) switch (_context48.prev = _context48.next) {
4146
4227
  case 0:
4147
- _ref5 = _args49.length > 1 && _args49[1] !== undefined ? _args49[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
4228
+ _ref5 = _args48.length > 1 && _args48[1] !== undefined ? _args48[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
4148
4229
  if (cover) {
4149
4230
  this.otherParams = params;
4150
4231
  } else {
@@ -4152,11 +4233,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4152
4233
  }
4153
4234
  case 2:
4154
4235
  case "end":
4155
- return _context49.stop();
4236
+ return _context48.stop();
4156
4237
  }
4157
- }, _callee49, this);
4238
+ }, _callee48, this);
4158
4239
  }));
4159
- function setOtherParams(_x30) {
4240
+ function setOtherParams(_x28) {
4160
4241
  return _setOtherParams.apply(this, arguments);
4161
4242
  }
4162
4243
  return setOtherParams;
@@ -4173,12 +4254,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4173
4254
  }, {
4174
4255
  key: "editOrderNoteByOrderIdAsync",
4175
4256
  value: (function () {
4176
- var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee50(orderId, note) {
4257
+ var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee49(orderId, note) {
4177
4258
  var response, previousNote, errorMessage, _errorMessage;
4178
- return _regeneratorRuntime().wrap(function _callee50$(_context50) {
4179
- while (1) switch (_context50.prev = _context50.next) {
4259
+ return _regeneratorRuntime().wrap(function _callee49$(_context49) {
4260
+ while (1) switch (_context49.prev = _context49.next) {
4180
4261
  case 0:
4181
- _context50.prev = 0;
4262
+ this.logInfo('editOrderNoteByOrderIdAsync called', {
4263
+ orderId: orderId,
4264
+ note: note,
4265
+ noteLength: note.length,
4266
+ isCurrentOrder: this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId))
4267
+ });
4268
+ _context49.prev = 1;
4182
4269
  console.log('[Checkout] 开始编辑订单备注:', {
4183
4270
  orderId: orderId,
4184
4271
  note: note,
@@ -4187,21 +4274,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4187
4274
 
4188
4275
  // 参数验证
4189
4276
  if (orderId) {
4190
- _context50.next = 4;
4277
+ _context49.next = 5;
4191
4278
  break;
4192
4279
  }
4193
- return _context50.abrupt("return", {
4280
+ return _context49.abrupt("return", {
4194
4281
  success: false,
4195
4282
  message: '订单ID不能为空',
4196
4283
  orderId: orderId
4197
4284
  });
4198
- case 4:
4199
- _context50.next = 6;
4285
+ case 5:
4286
+ // 记录接口调用
4287
+ this.logInfo('Calling order note edit API', {
4288
+ url: "/order/order/".concat(orderId, "/note"),
4289
+ method: 'PUT',
4290
+ orderId: orderId,
4291
+ note: note,
4292
+ noteLength: note.length
4293
+ });
4294
+
4295
+ // 调用后端API修改订单备注
4296
+ _context49.next = 8;
4200
4297
  return this.request.put("/order/order/".concat(orderId, "/note"), {
4201
4298
  note: note
4202
4299
  });
4203
- case 6:
4204
- response = _context50.sent;
4300
+ case 8:
4301
+ response = _context49.sent;
4205
4302
  console.log('[Checkout] 订单备注编辑响应:', {
4206
4303
  orderId: orderId,
4207
4304
  status: response.status,
@@ -4211,14 +4308,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4211
4308
 
4212
4309
  // 检查响应状态
4213
4310
  if (!(response.status === true || response.status === 200)) {
4214
- _context50.next = 19;
4311
+ _context49.next = 21;
4215
4312
  break;
4216
4313
  }
4217
4314
  console.log("[Checkout] \u8BA2\u5355 ".concat(orderId, " \u5907\u6CE8\u4FEE\u6539\u6210\u529F"));
4218
4315
 
4219
4316
  // 如果当前订单就是被修改的订单,同时更新本地状态
4220
4317
  if (!(this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId)))) {
4221
- _context50.next = 16;
4318
+ _context49.next = 18;
4222
4319
  break;
4223
4320
  }
4224
4321
  console.log('[Checkout] 更新本地订单备注状态');
@@ -4230,48 +4327,48 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4230
4327
  }
4231
4328
 
4232
4329
  // 触发订单备注变更事件
4233
- _context50.next = 16;
4330
+ _context49.next = 18;
4234
4331
  return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
4235
4332
  orderUuid: this.store.currentOrder.uuid,
4236
4333
  oldNote: previousNote,
4237
4334
  newNote: note,
4238
4335
  timestamp: Date.now()
4239
4336
  });
4240
- case 16:
4241
- return _context50.abrupt("return", {
4337
+ case 18:
4338
+ return _context49.abrupt("return", {
4242
4339
  success: true,
4243
4340
  message: response.message || '订单备注修改成功',
4244
4341
  orderId: orderId
4245
4342
  });
4246
- case 19:
4343
+ case 21:
4247
4344
  // API返回失败状态
4248
4345
  errorMessage = response.message || '订单备注修改失败';
4249
4346
  console.error("[Checkout] \u8BA2\u5355 ".concat(orderId, " \u5907\u6CE8\u4FEE\u6539\u5931\u8D25:"), errorMessage);
4250
- return _context50.abrupt("return", {
4347
+ return _context49.abrupt("return", {
4251
4348
  success: false,
4252
4349
  message: errorMessage,
4253
4350
  orderId: orderId
4254
4351
  });
4255
- case 22:
4256
- _context50.next = 29;
4257
- break;
4258
4352
  case 24:
4259
- _context50.prev = 24;
4260
- _context50.t0 = _context50["catch"](0);
4261
- console.error('[Checkout] 编辑订单备注失败:', _context50.t0);
4262
- _errorMessage = _context50.t0 instanceof Error ? _context50.t0.message : '网络错误或服务器异常';
4263
- return _context50.abrupt("return", {
4353
+ _context49.next = 31;
4354
+ break;
4355
+ case 26:
4356
+ _context49.prev = 26;
4357
+ _context49.t0 = _context49["catch"](1);
4358
+ console.error('[Checkout] 编辑订单备注失败:', _context49.t0);
4359
+ _errorMessage = _context49.t0 instanceof Error ? _context49.t0.message : '网络错误或服务器异常';
4360
+ return _context49.abrupt("return", {
4264
4361
  success: false,
4265
4362
  message: "\u7F16\u8F91\u8BA2\u5355\u5907\u6CE8\u5931\u8D25: ".concat(_errorMessage),
4266
4363
  orderId: orderId
4267
4364
  });
4268
- case 29:
4365
+ case 31:
4269
4366
  case "end":
4270
- return _context50.stop();
4367
+ return _context49.stop();
4271
4368
  }
4272
- }, _callee50, this, [[0, 24]]);
4369
+ }, _callee49, this, [[1, 26]]);
4273
4370
  }));
4274
- function editOrderNoteByOrderIdAsync(_x31, _x32) {
4371
+ function editOrderNoteByOrderIdAsync(_x29, _x30) {
4275
4372
  return _editOrderNoteByOrderIdAsync.apply(this, arguments);
4276
4373
  }
4277
4374
  return editOrderNoteByOrderIdAsync;
@@ -4288,12 +4385,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4288
4385
  }, {
4289
4386
  key: "sendCustomerPayLinkAsync",
4290
4387
  value: (function () {
4291
- var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee51(params) {
4388
+ var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee50(params) {
4389
+ var _params$order_ids, _params$emails;
4292
4390
  var emailRegex, invalidEmails, requestBody, response, errorMessage, _errorMessage2;
4293
- return _regeneratorRuntime().wrap(function _callee51$(_context51) {
4294
- while (1) switch (_context51.prev = _context51.next) {
4391
+ return _regeneratorRuntime().wrap(function _callee50$(_context50) {
4392
+ while (1) switch (_context50.prev = _context50.next) {
4295
4393
  case 0:
4296
- _context51.prev = 0;
4394
+ this.logInfo('sendCustomerPayLinkAsync called', {
4395
+ orderIds: params.order_ids,
4396
+ orderIdsCount: ((_params$order_ids = params.order_ids) === null || _params$order_ids === void 0 ? void 0 : _params$order_ids.length) || 0,
4397
+ emails: params.emails,
4398
+ emailsCount: ((_params$emails = params.emails) === null || _params$emails === void 0 ? void 0 : _params$emails.length) || 0,
4399
+ notifyAction: params.notify_action || 'order_payment_reminder'
4400
+ });
4401
+ _context50.prev = 1;
4297
4402
  console.log('[Checkout] 开始发送客户支付链接邮件:', {
4298
4403
  orderIds: params.order_ids,
4299
4404
  emails: params.emails,
@@ -4302,37 +4407,37 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4302
4407
 
4303
4408
  // 参数验证
4304
4409
  if (!(!params.order_ids || params.order_ids.length === 0)) {
4305
- _context51.next = 4;
4410
+ _context50.next = 5;
4306
4411
  break;
4307
4412
  }
4308
- return _context51.abrupt("return", {
4413
+ return _context50.abrupt("return", {
4309
4414
  success: false,
4310
4415
  message: '订单ID列表不能为空'
4311
4416
  });
4312
- case 4:
4417
+ case 5:
4313
4418
  if (!(!params.emails || params.emails.length === 0)) {
4314
- _context51.next = 6;
4419
+ _context50.next = 7;
4315
4420
  break;
4316
4421
  }
4317
- return _context51.abrupt("return", {
4422
+ return _context50.abrupt("return", {
4318
4423
  success: false,
4319
4424
  message: '邮箱地址列表不能为空'
4320
4425
  });
4321
- case 6:
4426
+ case 7:
4322
4427
  // 验证邮箱格式
4323
4428
  emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
4324
4429
  invalidEmails = params.emails.filter(function (email) {
4325
4430
  return !emailRegex.test(email);
4326
4431
  });
4327
4432
  if (!(invalidEmails.length > 0)) {
4328
- _context51.next = 10;
4433
+ _context50.next = 11;
4329
4434
  break;
4330
4435
  }
4331
- return _context51.abrupt("return", {
4436
+ return _context50.abrupt("return", {
4332
4437
  success: false,
4333
4438
  message: "\u90AE\u7BB1\u683C\u5F0F\u65E0\u6548: ".concat(invalidEmails.join(', '))
4334
4439
  });
4335
- case 10:
4440
+ case 11:
4336
4441
  // 构建请求参数
4337
4442
  requestBody = {
4338
4443
  order_ids: params.order_ids,
@@ -4341,11 +4446,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4341
4446
  };
4342
4447
  console.log('[Checkout] 发送支付链接邮件请求参数:', requestBody);
4343
4448
 
4449
+ // 记录接口调用
4450
+ this.logInfo('Calling batch email API', {
4451
+ url: '/order/batch-email',
4452
+ orderIds: requestBody.order_ids,
4453
+ orderIdsCount: requestBody.order_ids.length,
4454
+ notifyAction: requestBody.notify_action,
4455
+ emails: requestBody.emails,
4456
+ emailsCount: requestBody.emails.length
4457
+ });
4458
+
4344
4459
  // 调用后端API发送邮件
4345
- _context51.next = 14;
4460
+ _context50.next = 16;
4346
4461
  return this.request.post('/order/batch-email', requestBody);
4347
- case 14:
4348
- response = _context51.sent;
4462
+ case 16:
4463
+ response = _context50.sent;
4349
4464
  console.log('[Checkout] 支付链接邮件发送响应:', {
4350
4465
  status: response.status,
4351
4466
  message: response.message,
@@ -4355,41 +4470,41 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4355
4470
 
4356
4471
  // 检查响应状态
4357
4472
  if (!(response.status === true || response.status === 200)) {
4358
- _context51.next = 21;
4473
+ _context50.next = 23;
4359
4474
  break;
4360
4475
  }
4361
4476
  console.log('[Checkout] 支付链接邮件发送成功');
4362
- return _context51.abrupt("return", {
4477
+ return _context50.abrupt("return", {
4363
4478
  success: true,
4364
4479
  message: response.message || '支付链接邮件发送成功'
4365
4480
  });
4366
- case 21:
4481
+ case 23:
4367
4482
  // API返回失败状态
4368
4483
  errorMessage = response.message || '支付链接邮件发送失败';
4369
4484
  console.error('[Checkout] 支付链接邮件发送失败:', errorMessage);
4370
- return _context51.abrupt("return", {
4485
+ return _context50.abrupt("return", {
4371
4486
  success: false,
4372
4487
  message: errorMessage
4373
4488
  });
4374
- case 24:
4375
- _context51.next = 31;
4376
- break;
4377
4489
  case 26:
4378
- _context51.prev = 26;
4379
- _context51.t0 = _context51["catch"](0);
4380
- console.error('[Checkout] 发送客户支付链接邮件失败:', _context51.t0);
4381
- _errorMessage2 = _context51.t0 instanceof Error ? _context51.t0.message : '网络错误或服务器异常';
4382
- return _context51.abrupt("return", {
4490
+ _context50.next = 33;
4491
+ break;
4492
+ case 28:
4493
+ _context50.prev = 28;
4494
+ _context50.t0 = _context50["catch"](1);
4495
+ console.error('[Checkout] 发送客户支付链接邮件失败:', _context50.t0);
4496
+ _errorMessage2 = _context50.t0 instanceof Error ? _context50.t0.message : '网络错误或服务器异常';
4497
+ return _context50.abrupt("return", {
4383
4498
  success: false,
4384
4499
  message: "\u53D1\u9001\u652F\u4ED8\u94FE\u63A5\u90AE\u4EF6\u5931\u8D25: ".concat(_errorMessage2)
4385
4500
  });
4386
- case 31:
4501
+ case 33:
4387
4502
  case "end":
4388
- return _context51.stop();
4503
+ return _context50.stop();
4389
4504
  }
4390
- }, _callee51, this, [[0, 26]]);
4505
+ }, _callee50, this, [[1, 28]]);
4391
4506
  }));
4392
- function sendCustomerPayLinkAsync(_x33) {
4507
+ function sendCustomerPayLinkAsync(_x31) {
4393
4508
  return _sendCustomerPayLinkAsync.apply(this, arguments);
4394
4509
  }
4395
4510
  return sendCustomerPayLinkAsync;
@@ -4404,25 +4519,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4404
4519
  }, {
4405
4520
  key: "roundAmountAsync",
4406
4521
  value: (function () {
4407
- var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee52(amount) {
4522
+ var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee51(amount) {
4408
4523
  var _this$otherParams$ord, _this$otherParams$ord2;
4409
4524
  var result;
4410
- return _regeneratorRuntime().wrap(function _callee52$(_context52) {
4411
- while (1) switch (_context52.prev = _context52.next) {
4525
+ return _regeneratorRuntime().wrap(function _callee51$(_context51) {
4526
+ while (1) switch (_context51.prev = _context51.next) {
4412
4527
  case 0:
4413
- _context52.next = 2;
4528
+ _context51.next = 2;
4414
4529
  return this.payment.roundAmountAsync(amount, (_this$otherParams$ord = this.otherParams.order_rounding_setting) === null || _this$otherParams$ord === void 0 ? void 0 : _this$otherParams$ord.interval, (_this$otherParams$ord2 = this.otherParams.order_rounding_setting) === null || _this$otherParams$ord2 === void 0 ? void 0 : _this$otherParams$ord2.type);
4415
4530
  case 2:
4416
- result = _context52.sent;
4531
+ result = _context51.sent;
4417
4532
  console.log("[Checkout] \u91D1\u989D\u820D\u5165\u5B8C\u6210 - \u539F\u59CB: ".concat(result.originalAmount, ", \u820D\u5165\u540E: ").concat(result.roundedAmount, ", \u5DEE\u989D: ").concat(result.roundingDifference));
4418
- return _context52.abrupt("return", result);
4533
+ return _context51.abrupt("return", result);
4419
4534
  case 5:
4420
4535
  case "end":
4421
- return _context52.stop();
4536
+ return _context51.stop();
4422
4537
  }
4423
- }, _callee52, this);
4538
+ }, _callee51, this);
4424
4539
  }));
4425
- function roundAmountAsync(_x34) {
4540
+ function roundAmountAsync(_x32) {
4426
4541
  return _roundAmountAsync.apply(this, arguments);
4427
4542
  }
4428
4543
  return roundAmountAsync;
@@ -4430,10 +4545,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4430
4545
  }, {
4431
4546
  key: "destroy",
4432
4547
  value: function () {
4433
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee53() {
4548
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee52() {
4434
4549
  var _this$order, _this$order$destroy, _this$payment, _this$payment$destroy;
4435
- return _regeneratorRuntime().wrap(function _callee53$(_context53) {
4436
- while (1) switch (_context53.prev = _context53.next) {
4550
+ return _regeneratorRuntime().wrap(function _callee52$(_context52) {
4551
+ while (1) switch (_context52.prev = _context52.next) {
4437
4552
  case 0:
4438
4553
  // 清理钱包模块的所有缓存数据
4439
4554
  this.payment.wallet.clearAllCache();
@@ -4442,10 +4557,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4442
4557
  this.core.effects.offByModuleDestroy(this.name);
4443
4558
 
4444
4559
  // 销毁子模块
4445
- _context53.next = 4;
4560
+ _context52.next = 4;
4446
4561
  return (_this$order = this.order) === null || _this$order === void 0 || (_this$order$destroy = _this$order.destroy) === null || _this$order$destroy === void 0 ? void 0 : _this$order$destroy.call(_this$order);
4447
4562
  case 4:
4448
- _context53.next = 6;
4563
+ _context52.next = 6;
4449
4564
  return (_this$payment = this.payment) === null || _this$payment === void 0 || (_this$payment$destroy = _this$payment.destroy) === null || _this$payment$destroy === void 0 ? void 0 : _this$payment$destroy.call(_this$payment);
4450
4565
  case 6:
4451
4566
  // 取消注册模块
@@ -4453,9 +4568,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4453
4568
  console.log('[Checkout] 已销毁');
4454
4569
  case 8:
4455
4570
  case "end":
4456
- return _context53.stop();
4571
+ return _context52.stop();
4457
4572
  }
4458
- }, _callee53, this);
4573
+ }, _callee52, this);
4459
4574
  }));
4460
4575
  function destroy() {
4461
4576
  return _destroy.apply(this, arguments);
@@ -4470,12 +4585,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4470
4585
  }, {
4471
4586
  key: "resetStoreStateAsync",
4472
4587
  value: (function () {
4473
- var _resetStoreStateAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee54() {
4588
+ var _resetStoreStateAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee53() {
4474
4589
  var prevOrderInfo;
4475
- return _regeneratorRuntime().wrap(function _callee54$(_context54) {
4476
- while (1) switch (_context54.prev = _context54.next) {
4590
+ return _regeneratorRuntime().wrap(function _callee53$(_context53) {
4591
+ while (1) switch (_context53.prev = _context53.next) {
4477
4592
  case 0:
4478
- _context54.prev = 0;
4593
+ _context53.prev = 0;
4479
4594
  prevOrderInfo = this.store.currentOrder ? {
4480
4595
  uuid: this.store.currentOrder.uuid,
4481
4596
  orderId: this.store.currentOrder.order_id
@@ -4501,36 +4616,32 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4501
4616
  // 注意:故意保留 this.store.paymentMethods,因为支付方式数据不易变更,保留在内存中提高性能
4502
4617
 
4503
4618
  // 重置状态和步骤为初始状态
4504
- _context54.next = 15;
4505
- return this.setStatus(CheckoutStatus.Ready);
4506
- case 15:
4507
- _context54.next = 17;
4508
- return this.setStep(CheckoutStep.OrderConfirmation);
4509
- case 17:
4619
+ this.setStatus(CheckoutStatus.Ready);
4620
+ this.setStep(CheckoutStep.OrderConfirmation);
4510
4621
  console.log('[Checkout] Store 状态重置完成');
4511
4622
 
4512
4623
  // 触发订单清理事件(如果之前有订单)
4513
4624
  if (!prevOrderInfo) {
4514
- _context54.next = 21;
4625
+ _context53.next = 19;
4515
4626
  break;
4516
4627
  }
4517
- _context54.next = 21;
4628
+ _context53.next = 19;
4518
4629
  return this.core.effects.emit(CheckoutHooks.OnOrderCleared, {
4519
4630
  previousOrder: prevOrderInfo,
4520
4631
  timestamp: Date.now()
4521
4632
  });
4522
- case 21:
4523
- _context54.next = 26;
4633
+ case 19:
4634
+ _context53.next = 24;
4524
4635
  break;
4525
- case 23:
4526
- _context54.prev = 23;
4527
- _context54.t0 = _context54["catch"](0);
4528
- console.error('[Checkout] 重置 store 状态失败:', _context54.t0);
4529
- case 26:
4636
+ case 21:
4637
+ _context53.prev = 21;
4638
+ _context53.t0 = _context53["catch"](0);
4639
+ console.error('[Checkout] 重置 store 状态失败:', _context53.t0);
4640
+ case 24:
4530
4641
  case "end":
4531
- return _context54.stop();
4642
+ return _context53.stop();
4532
4643
  }
4533
- }, _callee54, this, [[0, 23]]);
4644
+ }, _callee53, this, [[0, 21]]);
4534
4645
  }));
4535
4646
  function resetStoreStateAsync() {
4536
4647
  return _resetStoreStateAsync.apply(this, arguments);
@@ -4548,37 +4659,37 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4548
4659
  }, {
4549
4660
  key: "clearCompletedOrderAsync",
4550
4661
  value: (function () {
4551
- var _clearCompletedOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee55() {
4662
+ var _clearCompletedOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee54() {
4552
4663
  var prevOrderInfo;
4553
- return _regeneratorRuntime().wrap(function _callee55$(_context55) {
4554
- while (1) switch (_context55.prev = _context55.next) {
4664
+ return _regeneratorRuntime().wrap(function _callee54$(_context54) {
4665
+ while (1) switch (_context54.prev = _context54.next) {
4555
4666
  case 0:
4556
- _context55.prev = 0;
4667
+ _context54.prev = 0;
4557
4668
  prevOrderInfo = this.store.currentOrder ? {
4558
4669
  uuid: this.store.currentOrder.uuid,
4559
4670
  orderId: this.store.currentOrder.order_id
4560
4671
  } : null;
4561
- _context55.next = 4;
4672
+ _context54.next = 4;
4562
4673
  return this.resetStoreStateAsync();
4563
4674
  case 4:
4564
- return _context55.abrupt("return", {
4675
+ return _context54.abrupt("return", {
4565
4676
  success: true,
4566
4677
  message: prevOrderInfo ? '订单状态已成功清理' : '没有需要清理的订单状态',
4567
4678
  clearedOrder: prevOrderInfo
4568
4679
  });
4569
4680
  case 7:
4570
- _context55.prev = 7;
4571
- _context55.t0 = _context55["catch"](0);
4572
- console.error('[Checkout] 手动清理订单状态失败:', _context55.t0);
4573
- return _context55.abrupt("return", {
4681
+ _context54.prev = 7;
4682
+ _context54.t0 = _context54["catch"](0);
4683
+ console.error('[Checkout] 手动清理订单状态失败:', _context54.t0);
4684
+ return _context54.abrupt("return", {
4574
4685
  success: false,
4575
- message: _context55.t0 instanceof Error ? _context55.t0.message : '清理失败'
4686
+ message: _context54.t0 instanceof Error ? _context54.t0.message : '清理失败'
4576
4687
  });
4577
4688
  case 11:
4578
4689
  case "end":
4579
- return _context55.stop();
4690
+ return _context54.stop();
4580
4691
  }
4581
- }, _callee55, this, [[0, 7]]);
4692
+ }, _callee54, this, [[0, 7]]);
4582
4693
  }));
4583
4694
  function clearCompletedOrderAsync() {
4584
4695
  return _clearCompletedOrderAsync.apply(this, arguments);