@pisell/pisellos 0.0.230 → 0.0.231

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/modules/Order/index.d.ts +13 -2
  2. package/dist/modules/Order/index.js +84 -1
  3. package/dist/modules/Order/types.d.ts +43 -0
  4. package/dist/modules/Order/types.js +8 -0
  5. package/dist/modules/Payment/cash.d.ts +8 -0
  6. package/dist/modules/Payment/cash.js +20 -1
  7. package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  8. package/dist/modules/Payment/cashRecommendationAlgorithm.js +423 -0
  9. package/dist/modules/Payment/eftpos.js +1 -1
  10. package/dist/modules/Payment/index.d.ts +34 -124
  11. package/dist/modules/Payment/index.js +662 -1280
  12. package/dist/modules/Payment/mx51.d.ts +0 -0
  13. package/dist/modules/Payment/mx51.js +0 -0
  14. package/dist/modules/Payment/types.d.ts +323 -45
  15. package/dist/modules/Payment/types.js +101 -2
  16. package/dist/modules/Payment/utils.d.ts +17 -0
  17. package/dist/modules/Payment/utils.js +62 -0
  18. package/dist/modules/Payment/walletpass.d.ts +96 -0
  19. package/dist/modules/Payment/walletpass.js +492 -0
  20. package/dist/modules/Schedule/index.d.ts +9 -0
  21. package/dist/modules/Schedule/index.js +60 -0
  22. package/dist/solution/Checkout/index.d.ts +236 -2
  23. package/dist/solution/Checkout/index.js +2334 -308
  24. package/dist/solution/Checkout/types.d.ts +193 -6
  25. package/dist/solution/Checkout/types.js +5 -0
  26. package/lib/modules/Order/index.d.ts +13 -2
  27. package/lib/modules/Order/index.js +58 -1
  28. package/lib/modules/Order/types.d.ts +43 -0
  29. package/lib/modules/Payment/cash.d.ts +8 -0
  30. package/lib/modules/Payment/cash.js +14 -1
  31. package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  32. package/lib/modules/Payment/cashRecommendationAlgorithm.js +342 -0
  33. package/lib/modules/Payment/eftpos.js +1 -1
  34. package/lib/modules/Payment/index.d.ts +34 -124
  35. package/lib/modules/Payment/index.js +232 -533
  36. package/lib/modules/Payment/mx51.d.ts +0 -0
  37. package/lib/modules/Payment/mx51.js +0 -0
  38. package/lib/modules/Payment/types.d.ts +323 -45
  39. package/lib/modules/Payment/types.js +37 -2
  40. package/lib/modules/Payment/utils.d.ts +17 -0
  41. package/lib/modules/Payment/utils.js +67 -0
  42. package/lib/modules/Payment/walletpass.d.ts +96 -0
  43. package/lib/modules/Payment/walletpass.js +304 -0
  44. package/lib/modules/Schedule/index.d.ts +9 -0
  45. package/lib/modules/Schedule/index.js +36 -0
  46. package/lib/solution/Checkout/index.d.ts +236 -2
  47. package/lib/solution/Checkout/index.js +1282 -39
  48. package/lib/solution/Checkout/types.d.ts +193 -6
  49. package/lib/solution/Checkout/types.js +5 -0
  50. package/package.json +1 -1
  51. package/dist/modules/Payment/wallet.d.ts +0 -11
  52. package/dist/modules/Payment/wallet.js +0 -78
  53. package/lib/modules/Payment/wallet.d.ts +0 -11
  54. package/lib/modules/Payment/wallet.js +0 -51
@@ -1,3 +1,10 @@
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; } } }; }
2
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
+ 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."); }
4
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
1
8
  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
9
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
10
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -21,7 +28,7 @@ import { BaseModule } from "../../modules/BaseModule";
21
28
  import { OrderModule } from "../../modules/Order";
22
29
  import { PaymentModule } from "../../modules/Payment";
23
30
  import { CheckoutStatus, CheckoutStep, CheckoutHooks, CheckoutErrorType } from "./types";
24
- import { PaymentStatus } from "../../modules/Payment/types";
31
+ import { PaymentStatus, PaymentMethodType } from "../../modules/Payment/types";
25
32
  import { validateCheckoutData, createCheckoutError, calculateProgress } from "./utils";
26
33
  export * from "./types";
27
34
 
@@ -44,6 +51,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
44
51
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
45
52
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
46
53
  _defineProperty(_assertThisInitialized(_this), "otherParams", {});
54
+ // 直接挂载的模块
55
+ _defineProperty(_assertThisInitialized(_this), "order", void 0);
56
+ _defineProperty(_assertThisInitialized(_this), "payment", void 0);
47
57
  return _this;
48
58
  }
49
59
  _createClass(CheckoutImpl, [{
@@ -64,32 +74,38 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
64
74
  }
65
75
  throw new Error('Checkout 解决方案需要 request 插件支持');
66
76
  case 5:
77
+ // 初始化模块
78
+ this.order = new OrderModule();
79
+ this.payment = new PaymentModule();
80
+
67
81
  // 初始化状态
68
82
  this.store = {
69
- order: new OrderModule(),
70
- payment: new PaymentModule(),
71
83
  status: CheckoutStatus.Initializing,
72
84
  step: CheckoutStep.OrderConfirmation,
73
85
  cartItems: [],
74
- paymentMethods: []
86
+ paymentMethods: [],
87
+ stateAmount: '0.00',
88
+ cartSummary: undefined,
89
+ isOrderSynced: false,
90
+ currentCustomer: undefined
75
91
  };
76
92
 
77
93
  // 注册并初始化子模块
78
- _context.next = 8;
79
- return this.initializeSubModules(core, options);
80
- case 8:
81
94
  _context.next = 10;
82
- return this.preloadPaymentMethods();
95
+ return this.initializeSubModules(core, options);
83
96
  case 10:
84
97
  _context.next = 12;
85
- return this.setStatus(CheckoutStatus.Ready);
98
+ return this.preloadPaymentMethods();
86
99
  case 12:
100
+ _context.next = 14;
101
+ return this.setStatus(CheckoutStatus.Ready);
102
+ case 14:
87
103
  console.log('[Checkout] 初始化完成');
88
- _context.next = 15;
104
+ _context.next = 17;
89
105
  return this.core.effects.emit(CheckoutHooks.OnCheckoutInitialized, {
90
106
  timestamp: Date.now()
91
107
  });
92
- case 15:
108
+ case 17:
93
109
  case "end":
94
110
  return _context.stop();
95
111
  }
@@ -112,7 +128,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
112
128
  while (1) switch (_context2.prev = _context2.next) {
113
129
  case 0:
114
130
  // 初始化订单模块
115
- core.registerModule(this.store.order, {
131
+ core.registerModule(this.order, {
116
132
  store: ((_options$store = options.store) === null || _options$store === void 0 ? void 0 : _options$store.order) || {},
117
133
  otherParams: _objectSpread(_objectSpread({}, this.otherParams), {}, {
118
134
  parentModule: this.name
@@ -120,7 +136,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
120
136
  });
121
137
 
122
138
  // 初始化支付模块
123
- core.registerModule(this.store.payment, {
139
+ core.registerModule(this.payment, {
124
140
  store: ((_options$store2 = options.store) === null || _options$store2 === void 0 ? void 0 : _options$store2.payment) || {},
125
141
  otherParams: _objectSpread(_objectSpread({}, this.otherParams), {}, {
126
142
  parentModule: this.name
@@ -252,7 +268,25 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
252
268
  return _initializeCheckoutAsync.apply(this, arguments);
253
269
  }
254
270
  return initializeCheckoutAsync;
255
- }()
271
+ }())
272
+ }, {
273
+ key: "getProductListByOrder",
274
+ value: function getProductListByOrder() {
275
+ var _this$store$currentOr;
276
+ if (!this.store.currentOrder) {
277
+ return [];
278
+ }
279
+ var productList = (_this$store$currentOr = this.store.currentOrder.order_info) === null || _this$store$currentOr === void 0 ? void 0 : _this$store$currentOr.original_order_data.bookings.map(function (item) {
280
+ return {
281
+ product_id: item.product.product_id,
282
+ product_variant_id: item.product.product_variant_id,
283
+ quantity: item.product.num,
284
+ selling_price: item.product.price - (item.product.discount_amount || 0)
285
+ };
286
+ });
287
+ return productList;
288
+ }
289
+
256
290
  /**
257
291
  * 创建本地订单 (前端模拟下单流程)
258
292
  *
@@ -260,12 +294,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
260
294
  * 用户在购物车点击下单时,会把购物车参数传递给此方法,
261
295
  * 方法会记录参数并创建本地虚拟订单,然后用 Payment 模块管理支付流程。
262
296
  */
263
- )
264
297
  }, {
265
298
  key: "createLocalOrderAsync",
266
299
  value: (function () {
267
300
  var _createLocalOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
268
- var validation, localOrderId, amountInfo, paymentOrder;
301
+ var _params$totalInfo, _params$totalInfo2, _this$store$currentCu, validation, localOrderId, amountInfo, customerInfo, paymentOrder, walletBusinessData, walletData;
269
302
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
270
303
  while (1) switch (_context6.prev = _context6.next) {
271
304
  case 0:
@@ -285,12 +318,35 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
285
318
  case 8:
286
319
  // 生成本地虚拟订单ID (后续可以被真实订单ID替换)
287
320
  localOrderId = this.generateLocalOrderId(); // 从购物车小计数据中提取金额信息
288
- amountInfo = this.extractAmountFromCartSummary(params.cartSummary); // 保存原始订单数据到状态中
321
+ amountInfo = this.extractAmountFromCartSummary(params.cartSummary); // TODO: 外面传的是 pos ,但是现在 后端只有 shop 和 kiosk
322
+ params.orderData.platform = 'pos';
323
+ // 补充 created_at 时间 (YYYY-MM-DD hh:mm:ss 格式)
324
+ params.orderData.created_at = this.formatDateTime(new Date());
325
+ // 补充税费信息
326
+ 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.paySurchargeFee;
327
+ // 补充订单折扣信息
328
+ params.orderData.shop_discount = (_params$totalInfo2 = params.totalInfo) === null || _params$totalInfo2 === void 0 || (_params$totalInfo2 = _params$totalInfo2.total) === null || _params$totalInfo2 === void 0 ? void 0 : _params$totalInfo2.shopDiscount;
329
+
330
+ // 保存原始订单数据和小计数据到状态中
289
331
  this.store.localOrderData = params.orderData;
332
+ this.store.cartSummary = params.cartSummary;
333
+
334
+ // 提取并保存客户信息(如果有)
335
+ customerInfo = {
336
+ customer_id: params.orderData.customer_id,
337
+ customer_name: params.orderData.customer_name
338
+ }; // 只有在有客户信息时才存储
339
+ if (customerInfo.customer_id || customerInfo.customer_name) {
340
+ this.store.currentCustomer = customerInfo;
341
+ console.log('[Checkout] 保存客户信息:', customerInfo);
342
+ } else {
343
+ this.store.currentCustomer = undefined;
344
+ console.log('[Checkout] 未提供客户信息');
345
+ }
290
346
 
291
347
  // 创建支付订单对象
292
- _context6.next = 13;
293
- return this.store.payment.createPaymentOrderAsync({
348
+ _context6.next = 20;
349
+ return this.payment.createPaymentOrderAsync({
294
350
  order_id: localOrderId,
295
351
  total_amount: amountInfo.totalAmount,
296
352
  is_deposit: params.orderData.is_deposit || 0,
@@ -299,61 +355,81 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
299
355
  original_order_data: params.orderData,
300
356
  cart_summary: params.cartSummary,
301
357
  created_at: new Date().toISOString(),
302
- platform: params.orderData.platform.toLowerCase(),
358
+ platform: params.orderData.platform,
303
359
  type: params.orderData.type,
304
360
  schedule_date: params.orderData.schedule_date,
305
361
  shop_note: params.orderData.shop_note,
306
362
  amount_breakdown: amountInfo
307
363
  }
308
364
  });
309
- case 13:
365
+ case 20:
310
366
  paymentOrder = _context6.sent;
311
367
  this.store.currentOrder = paymentOrder;
312
- _context6.next = 17;
368
+
369
+ // 准备钱包初始化的业务数据
370
+ walletBusinessData = {
371
+ customer_id: (_this$store$currentCu = this.store.currentCustomer) !== null && _this$store$currentCu !== void 0 && _this$store$currentCu.customer_id ? Number(this.store.currentCustomer.customer_id) : undefined,
372
+ amountInfo: {
373
+ totalAmount: amountInfo.totalAmount,
374
+ subTotal: amountInfo.subTotal
375
+ },
376
+ products: this.getProductListByOrder()
377
+ }; // 调用WalletPass模块的业务数据初始化函数
378
+ _context6.next = 25;
379
+ return this.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
380
+ case 25:
381
+ walletData = _context6.sent;
382
+ console.log(walletData.walletRecommendList, 'walletRecommendList');
383
+ console.log(walletData.userIdentificationCodes, 'userIdentificationCodes');
384
+ _context6.next = 30;
313
385
  return this.setStatus(CheckoutStatus.OrderCreated);
314
- case 17:
315
- _context6.next = 19;
386
+ case 30:
387
+ _context6.next = 32;
316
388
  return this.setStep(CheckoutStep.PaymentMethod);
317
- case 19:
389
+ case 32:
318
390
  if (!params.autoPayment) {
319
- _context6.next = 22;
391
+ _context6.next = 35;
320
392
  break;
321
393
  }
322
- _context6.next = 22;
394
+ _context6.next = 35;
323
395
  return this.setStep(CheckoutStep.PaymentProcessing);
324
- case 22:
325
- _context6.next = 24;
396
+ case 35:
397
+ _context6.next = 37;
326
398
  return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
327
399
  order: paymentOrder,
328
400
  timestamp: Date.now()
329
401
  });
330
- case 24:
402
+ case 37:
403
+ _context6.next = 39;
404
+ return this.updateStateAmountToRemaining();
405
+ case 39:
331
406
  console.log('[Checkout] 本地订单创建成功:', {
332
407
  localOrderId: localOrderId,
333
408
  uuid: paymentOrder.uuid,
334
409
  totalAmount: amountInfo.totalAmount,
335
410
  subTotal: amountInfo.subTotal,
336
- taxAmount: amountInfo.taxAmount
411
+ taxAmount: amountInfo.taxAmount,
412
+ stateAmount: this.store.stateAmount
337
413
  });
338
414
  return _context6.abrupt("return", paymentOrder);
339
- case 28:
340
- _context6.prev = 28;
415
+ case 43:
416
+ _context6.prev = 43;
341
417
  _context6.t0 = _context6["catch"](0);
342
- _context6.next = 32;
418
+ _context6.next = 47;
343
419
  return this.handleError(_context6.t0, CheckoutErrorType.OrderCreationFailed);
344
- case 32:
345
- _context6.next = 34;
420
+ case 47:
421
+ _context6.next = 49;
346
422
  return this.core.effects.emit(CheckoutHooks.OnOrderCreationFailed, {
347
423
  error: this.store.lastError,
348
424
  timestamp: Date.now()
349
425
  });
350
- case 34:
426
+ case 49:
351
427
  throw _context6.t0;
352
- case 35:
428
+ case 50:
353
429
  case "end":
354
430
  return _context6.stop();
355
431
  }
356
- }, _callee6, this, [[0, 28]]);
432
+ }, _callee6, this, [[0, 43]]);
357
433
  }));
358
434
  function createLocalOrderAsync(_x8) {
359
435
  return _createLocalOrderAsync.apply(this, arguments);
@@ -371,7 +447,6 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
371
447
  value: (function () {
372
448
  var _placeOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
373
449
  var params,
374
- _this$store$localOrde,
375
450
  _data,
376
451
  orderData,
377
452
  orderResponse,
@@ -404,10 +479,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
404
479
  orderData = {
405
480
  cartItems: this.store.cartItems,
406
481
  type: this.store.localOrderData.type,
407
- platform: (_this$store$localOrde = this.store.localOrderData.platform) === null || _this$store$localOrde === void 0 ? void 0 : _this$store$localOrde.toLowerCase()
482
+ platform: this.store.localOrderData.platform
408
483
  }; // 调用 Order 模块提交订单
409
484
  _context7.next = 12;
410
- return this.store.order.submitOrder({
485
+ return this.order.submitOrder({
411
486
  url: params.url,
412
487
  // 可选的自定义 URL
413
488
  query: orderData
@@ -451,13 +526,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
451
526
  timestamp: Date.now()
452
527
  });
453
528
  case 27:
529
+ // 标记订单已同步
530
+ this.store.isOrderSynced = true;
454
531
  console.log('[Checkout] 手动下单流程完成');
455
532
  return _context7.abrupt("return", {
456
533
  success: true,
457
534
  orderId: realOrderId
458
535
  });
459
- case 31:
460
- _context7.prev = 31;
536
+ case 32:
537
+ _context7.prev = 32;
461
538
  _context7.t0 = _context7["catch"](1);
462
539
  // 处理 CheckoutError 对象
463
540
  errorMessage = '下单失败';
@@ -467,18 +544,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
467
544
  errorMessage = _context7.t0.message;
468
545
  }
469
546
  console.error('[Checkout] 手动下单失败:', errorMessage);
470
- _context7.next = 38;
547
+ _context7.next = 39;
471
548
  return this.handleError(_context7.t0, CheckoutErrorType.OrderCreationFailed);
472
- case 38:
549
+ case 39:
473
550
  return _context7.abrupt("return", {
474
551
  success: false,
475
552
  error: errorMessage
476
553
  });
477
- case 39:
554
+ case 40:
478
555
  case "end":
479
556
  return _context7.stop();
480
557
  }
481
- }, _callee7, this, [[1, 31]]);
558
+ }, _callee7, this, [[1, 32]]);
482
559
  }));
483
560
  function placeOrderAsync() {
484
561
  return _placeOrderAsync.apply(this, arguments);
@@ -502,7 +579,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
502
579
  return this.setStatus(CheckoutStatus.CreatingOrder);
503
580
  case 3:
504
581
  // 验证购物车数据
505
- checkResult = this.store.order.checkBeforeSubmitOrder({
582
+ checkResult = this.order.checkBeforeSubmitOrder({
506
583
  cartItems: params.cartItems,
507
584
  type: 'account' // 默认使用 account 类型
508
585
  });
@@ -513,7 +590,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
513
590
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '购物车数据验证失败,请检查商品信息');
514
591
  case 6:
515
592
  _context8.next = 8;
516
- return this.store.order.submitOrder({
593
+ return this.order.submitOrder({
517
594
  query: {
518
595
  cartItems: params.cartItems,
519
596
  type: params.type || 'appointment_booking',
@@ -523,7 +600,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
523
600
  case 8:
524
601
  orderResponse = _context8.sent;
525
602
  _context8.next = 11;
526
- return this.store.payment.createPaymentOrderAsync({
603
+ return this.payment.createPaymentOrderAsync({
527
604
  order_id: (orderResponse === null || orderResponse === void 0 || (_data2 = orderResponse.data) === null || _data2 === void 0 ? void 0 : _data2.order_id) || "order_".concat(Date.now()),
528
605
  total_amount: this.calculateTotalAmount(params.cartItems),
529
606
  order_info: orderResponse === null || orderResponse === void 0 ? void 0 : orderResponse.data
@@ -543,26 +620,33 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
543
620
  timestamp: Date.now()
544
621
  });
545
622
  case 19:
623
+ // 标记订单已同步(createOrderAsync 创建的是真实订单)
624
+ this.store.isOrderSynced = true;
625
+
626
+ // 自动设置 stateAmount 为剩余未支付金额
627
+ _context8.next = 22;
628
+ return this.updateStateAmountToRemaining();
629
+ case 22:
546
630
  console.log('[Checkout] 订单创建成功:', paymentOrder.id);
547
631
  return _context8.abrupt("return", paymentOrder);
548
- case 23:
549
- _context8.prev = 23;
632
+ case 26:
633
+ _context8.prev = 26;
550
634
  _context8.t0 = _context8["catch"](0);
551
- _context8.next = 27;
635
+ _context8.next = 30;
552
636
  return this.handleError(_context8.t0, CheckoutErrorType.OrderCreationFailed);
553
- case 27:
554
- _context8.next = 29;
637
+ case 30:
638
+ _context8.next = 32;
555
639
  return this.core.effects.emit(CheckoutHooks.OnOrderCreationFailed, {
556
640
  error: this.store.lastError,
557
641
  timestamp: Date.now()
558
642
  });
559
- case 29:
643
+ case 32:
560
644
  throw _context8.t0;
561
- case 30:
645
+ case 33:
562
646
  case "end":
563
647
  return _context8.stop();
564
648
  }
565
- }, _callee8, this, [[0, 23]]);
649
+ }, _callee8, this, [[0, 26]]);
566
650
  }));
567
651
  function createOrderAsync(_x9) {
568
652
  return _createOrderAsync.apply(this, arguments);
@@ -613,10 +697,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
613
697
  id: paymentMethod.id
614
698
  }; // 添加支付项到订单
615
699
  _context9.next = 13;
616
- return this.store.payment.pushPaymentAsync(this.store.currentOrder.uuid, paymentItem);
700
+ return this.payment.addPaymentItemAsync(this.store.currentOrder.uuid, paymentItem);
617
701
  case 13:
618
702
  _context9.next = 15;
619
- return this.store.payment.submitPayAsync(this.store.currentOrder.uuid);
703
+ return this.payment.submitPayAsync(this.store.currentOrder.uuid);
620
704
  case 15:
621
705
  result = _context9.sent;
622
706
  _context9.next = 18;
@@ -628,37 +712,40 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
628
712
  });
629
713
  case 18:
630
714
  if (!(result.status === 'success')) {
631
- _context9.next = 25;
715
+ _context9.next = 27;
632
716
  break;
633
717
  }
634
718
  _context9.next = 21;
635
719
  return this.setStatus(CheckoutStatus.PaymentCompleted);
636
720
  case 21:
637
721
  _context9.next = 23;
722
+ return this.updateStateAmountToRemaining();
723
+ case 23:
724
+ _context9.next = 25;
638
725
  return this.handlePaymentSuccess({
639
726
  orderUuid: this.store.currentOrder.uuid,
640
727
  timestamp: Date.now()
641
728
  });
642
- case 23:
643
- _context9.next = 26;
644
- break;
645
729
  case 25:
646
- throw createCheckoutError(CheckoutErrorType.PaymentFailed, '支付处理失败,请重试');
647
- case 26:
648
- _context9.next = 33;
730
+ _context9.next = 28;
649
731
  break;
732
+ case 27:
733
+ throw createCheckoutError(CheckoutErrorType.PaymentFailed, '支付处理失败,请重试');
650
734
  case 28:
651
- _context9.prev = 28;
735
+ _context9.next = 35;
736
+ break;
737
+ case 30:
738
+ _context9.prev = 30;
652
739
  _context9.t0 = _context9["catch"](0);
653
- _context9.next = 32;
740
+ _context9.next = 34;
654
741
  return this.handleError(_context9.t0, CheckoutErrorType.PaymentFailed);
655
- case 32:
742
+ case 34:
656
743
  throw _context9.t0;
657
- case 33:
744
+ case 35:
658
745
  case "end":
659
746
  return _context9.stop();
660
747
  }
661
- }, _callee9, this, [[0, 28]]);
748
+ }, _callee9, this, [[0, 30]]);
662
749
  }));
663
750
  function processPaymentAsync(_x10) {
664
751
  return _processPaymentAsync.apply(this, arguments);
@@ -685,7 +772,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
685
772
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单');
686
773
  case 3:
687
774
  _context10.next = 5;
688
- return this.store.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
775
+ return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
689
776
  case 5:
690
777
  order = _context10.sent;
691
778
  if (!(!order || order.payment_status !== PaymentStatus.Finished)) {
@@ -694,37 +781,39 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
694
781
  }
695
782
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '订单支付未完成,无法完成结账');
696
783
  case 8:
697
- _context10.next = 10;
784
+ // 清理钱包模块的所有缓存数据
785
+ this.payment.wallet.clearAllCache();
786
+ _context10.next = 11;
698
787
  return this.setStatus(CheckoutStatus.Completed);
699
- case 10:
700
- _context10.next = 12;
788
+ case 11:
789
+ _context10.next = 13;
701
790
  return this.setStep(CheckoutStep.Complete);
702
- case 12:
703
- _context10.next = 14;
791
+ case 13:
792
+ _context10.next = 15;
704
793
  return this.core.effects.emit(CheckoutHooks.OnCheckoutCompleted, {
705
794
  orderId: order.id,
706
795
  timestamp: Date.now()
707
796
  });
708
- case 14:
797
+ case 15:
709
798
  console.log('[Checkout] 结账流程完成:', order.id);
710
799
  return _context10.abrupt("return", {
711
800
  success: true,
712
801
  orderId: String(order.id)
713
802
  });
714
- case 18:
715
- _context10.prev = 18;
803
+ case 19:
804
+ _context10.prev = 19;
716
805
  _context10.t0 = _context10["catch"](0);
717
- _context10.next = 22;
806
+ _context10.next = 23;
718
807
  return this.handleError(_context10.t0, CheckoutErrorType.UnknownError);
719
- case 22:
808
+ case 23:
720
809
  return _context10.abrupt("return", {
721
810
  success: false
722
811
  });
723
- case 23:
812
+ case 24:
724
813
  case "end":
725
814
  return _context10.stop();
726
815
  }
727
- }, _callee10, this, [[0, 18]]);
816
+ }, _callee10, this, [[0, 19]]);
728
817
  }));
729
818
  function completeCheckoutAsync() {
730
819
  return _completeCheckoutAsync.apply(this, arguments);
@@ -748,32 +837,40 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
748
837
  break;
749
838
  }
750
839
  _context11.next = 4;
751
- return this.store.payment.deleteOrderAsync(this.store.currentOrder.uuid);
840
+ return this.payment.deletePaymentOrderAsync(this.store.currentOrder.uuid);
752
841
  case 4:
753
842
  this.store.currentOrder = undefined;
754
843
  case 5:
755
- _context11.next = 7;
844
+ // 清理状态数据
845
+ this.store.localOrderData = undefined;
846
+ this.store.cartSummary = undefined;
847
+ this.payment.wallet.clearAllCache();
848
+ this.store.cartItems = [];
849
+ this.store.stateAmount = '0.00';
850
+ this.store.isOrderSynced = false;
851
+ this.store.currentCustomer = undefined;
852
+ _context11.next = 14;
756
853
  return this.setStatus(CheckoutStatus.Cancelled);
757
- case 7:
758
- _context11.next = 9;
854
+ case 14:
855
+ _context11.next = 16;
759
856
  return this.core.effects.emit(CheckoutHooks.OnCheckoutCancelled, {
760
857
  timestamp: Date.now()
761
858
  });
762
- case 9:
859
+ case 16:
763
860
  console.log('[Checkout] 结账流程已取消');
764
- _context11.next = 17;
861
+ _context11.next = 24;
765
862
  break;
766
- case 12:
767
- _context11.prev = 12;
863
+ case 19:
864
+ _context11.prev = 19;
768
865
  _context11.t0 = _context11["catch"](0);
769
866
  console.error('[Checkout] 取消结账失败:', _context11.t0);
770
- _context11.next = 17;
867
+ _context11.next = 24;
771
868
  return this.handleError(_context11.t0, CheckoutErrorType.UnknownError);
772
- case 17:
869
+ case 24:
773
870
  case "end":
774
871
  return _context11.stop();
775
872
  }
776
- }, _callee11, this, [[0, 12]]);
873
+ }, _callee11, this, [[0, 19]]);
777
874
  }));
778
875
  function cancelCheckoutAsync() {
779
876
  return _cancelCheckoutAsync.apply(this, arguments);
@@ -803,14 +900,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
803
900
  key: "getCheckoutSummaryAsync",
804
901
  value: (function () {
805
902
  var _getCheckoutSummaryAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
806
- var _this$store$currentOr, _this$store$currentOr2, _this$store$currentOr3;
903
+ var _this$store$currentOr2, _this$store$currentOr3;
807
904
  var totalAmount, paidAmount, remainingAmount;
808
905
  return _regeneratorRuntime().wrap(function _callee12$(_context12) {
809
906
  while (1) switch (_context12.prev = _context12.next) {
810
907
  case 0:
811
- totalAmount = ((_this$store$currentOr = this.store.currentOrder) === null || _this$store$currentOr === void 0 ? void 0 : _this$store$currentOr.total_amount) || '0.00';
908
+ totalAmount = ((_this$store$currentOr2 = this.store.currentOrder) === null || _this$store$currentOr2 === void 0 ? void 0 : _this$store$currentOr2.total_amount) || '0.00';
812
909
  paidAmount = this.calculatePaidAmount();
813
- remainingAmount = ((_this$store$currentOr2 = this.store.currentOrder) === null || _this$store$currentOr2 === void 0 ? void 0 : _this$store$currentOr2.expect_amount) || totalAmount;
910
+ remainingAmount = this.calculateRemainingAmount();
814
911
  return _context12.abrupt("return", {
815
912
  order: this.store.currentOrder,
816
913
  totalAmount: totalAmount,
@@ -900,33 +997,32 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
900
997
  key: "getCurrentOrderInfo",
901
998
  value: function getCurrentOrderInfo() {
902
999
  try {
903
- var _localOrderData$platf;
904
1000
  var _this$store = this.store,
905
- currentOrder = _this$store.currentOrder,
1001
+ _currentOrder = _this$store.currentOrder,
906
1002
  status = _this$store.status,
907
1003
  step = _this$store.step,
908
1004
  cartItems = _this$store.cartItems,
909
1005
  localOrderData = _this$store.localOrderData;
910
- if (!currentOrder) {
1006
+ if (!_currentOrder) {
911
1007
  console.log('[Checkout] 当前没有活跃订单');
912
1008
  return null;
913
1009
  }
914
1010
 
915
1011
  // 从本地订单数据或订单信息中提取基础信息
916
- var orderInfo = currentOrder.order_info || {};
1012
+ var orderInfo = _currentOrder.order_info || {};
917
1013
  var createdAt = orderInfo.created_at || new Date().toISOString();
918
1014
  var orderType = (localOrderData === null || localOrderData === void 0 ? void 0 : localOrderData.type) || orderInfo.type || 'virtual';
919
- var platform = (localOrderData === null || localOrderData === void 0 || (_localOrderData$platf = localOrderData.platform) === null || _localOrderData$platf === void 0 ? void 0 : _localOrderData$platf.toLowerCase()) || orderInfo.platform || 'pc';
1015
+ var platform = (localOrderData === null || localOrderData === void 0 ? void 0 : localOrderData.platform) || orderInfo.platform || 'pc';
920
1016
  var result = {
921
- uuid: currentOrder.uuid,
922
- orderId: currentOrder.order_id,
1017
+ uuid: _currentOrder.uuid,
1018
+ orderId: _currentOrder.order_id,
923
1019
  status: status,
924
1020
  step: step,
925
- totalAmount: currentOrder.total_amount,
926
- remainingAmount: currentOrder.expect_amount,
927
- paymentStatus: currentOrder.payment_status,
928
- isDeposit: Boolean(currentOrder.is_deposit),
929
- depositAmount: currentOrder.deposit_amount,
1021
+ totalAmount: _currentOrder.total_amount,
1022
+ remainingAmount: _currentOrder.expect_amount,
1023
+ paymentStatus: _currentOrder.payment_status,
1024
+ isDeposit: Boolean(_currentOrder.is_deposit),
1025
+ depositAmount: _currentOrder.deposit_amount,
930
1026
  orderType: orderType,
931
1027
  platform: platform,
932
1028
  createdAt: createdAt,
@@ -947,16 +1043,90 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
947
1043
  }
948
1044
  }
949
1045
 
1046
+ /**
1047
+ * 获取当前订单的支付项
1048
+ *
1049
+ * 返回当前订单的所有支付项,包括活跃和已撤销的支付项
1050
+ */
1051
+ }, {
1052
+ key: "getCurrentOrderPaymentItemsAsync",
1053
+ value: (function () {
1054
+ var _getCurrentOrderPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1055
+ var _currentOrder2, paymentItems;
1056
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1057
+ while (1) switch (_context15.prev = _context15.next) {
1058
+ case 0:
1059
+ _context15.prev = 0;
1060
+ _currentOrder2 = this.store.currentOrder;
1061
+ if (_currentOrder2) {
1062
+ _context15.next = 5;
1063
+ break;
1064
+ }
1065
+ console.log('[Checkout] 当前没有活跃订单,无法获取支付项');
1066
+ return _context15.abrupt("return", []);
1067
+ case 5:
1068
+ console.log('[Checkout] 获取当前订单支付项:', {
1069
+ orderUuid: _currentOrder2.uuid,
1070
+ orderId: _currentOrder2.order_id
1071
+ });
1072
+
1073
+ // 调用Payment模块获取支付项
1074
+ _context15.next = 8;
1075
+ return this.payment.getPaymentItemsAsync(_currentOrder2.uuid);
1076
+ case 8:
1077
+ paymentItems = _context15.sent;
1078
+ console.log('[Checkout] 成功获取支付项:', {
1079
+ orderUuid: _currentOrder2.uuid,
1080
+ paymentItemCount: paymentItems.length,
1081
+ activeItems: paymentItems.filter(function (item) {
1082
+ return item.status !== 'voided';
1083
+ }).length,
1084
+ voidedItems: paymentItems.filter(function (item) {
1085
+ return item.status === 'voided';
1086
+ }).length,
1087
+ totalPaidAmount: paymentItems.filter(function (item) {
1088
+ return item.status !== 'voided';
1089
+ }).reduce(function (sum, item) {
1090
+ return sum + parseFloat(item.amount || '0');
1091
+ }, 0).toFixed(2),
1092
+ paymentMethods: paymentItems.map(function (item) {
1093
+ return {
1094
+ uuid: item.uuid,
1095
+ code: item.code,
1096
+ amount: item.amount,
1097
+ status: item.status,
1098
+ voucher_id: item.voucher_id
1099
+ };
1100
+ })
1101
+ });
1102
+ return _context15.abrupt("return", paymentItems);
1103
+ case 13:
1104
+ _context15.prev = 13;
1105
+ _context15.t0 = _context15["catch"](0);
1106
+ console.error('[Checkout] 获取当前订单支付项失败:', _context15.t0);
1107
+ return _context15.abrupt("return", []);
1108
+ case 17:
1109
+ case "end":
1110
+ return _context15.stop();
1111
+ }
1112
+ }, _callee15, this, [[0, 13]]);
1113
+ }));
1114
+ function getCurrentOrderPaymentItemsAsync() {
1115
+ return _getCurrentOrderPaymentItemsAsync.apply(this, arguments);
1116
+ }
1117
+ return getCurrentOrderPaymentItemsAsync;
1118
+ }()
950
1119
  /**
951
1120
  * 验证结账前置条件
952
1121
  */
1122
+ )
953
1123
  }, {
954
1124
  key: "validateCheckoutAsync",
955
1125
  value: (function () {
956
- var _validateCheckoutAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1126
+ var _validateCheckoutAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
957
1127
  var errors;
958
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
959
- while (1) switch (_context15.prev = _context15.next) {
1128
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1129
+ while (1) switch (_context16.prev = _context16.next) {
960
1130
  case 0:
961
1131
  errors = []; // 验证购物车
962
1132
  if (!this.store.cartItems || this.store.cartItems.length === 0) {
@@ -972,15 +1142,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
972
1142
  if (this.store.status === CheckoutStatus.Error) {
973
1143
  errors.push('结账流程存在错误');
974
1144
  }
975
- return _context15.abrupt("return", {
1145
+ return _context16.abrupt("return", {
976
1146
  valid: errors.length === 0,
977
1147
  errors: errors
978
1148
  });
979
1149
  case 5:
980
1150
  case "end":
981
- return _context15.stop();
1151
+ return _context16.stop();
982
1152
  }
983
- }, _callee15, this);
1153
+ }, _callee16, this);
984
1154
  }));
985
1155
  function validateCheckoutAsync() {
986
1156
  return _validateCheckoutAsync.apply(this, arguments);
@@ -994,53 +1164,44 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
994
1164
  }, {
995
1165
  key: "retryFailedOperationAsync",
996
1166
  value: (function () {
997
- var _retryFailedOperationAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
998
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
999
- while (1) switch (_context16.prev = _context16.next) {
1167
+ var _retryFailedOperationAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1168
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1169
+ while (1) switch (_context17.prev = _context17.next) {
1000
1170
  case 0:
1001
- _context16.prev = 0;
1171
+ _context17.prev = 0;
1002
1172
  if (!(this.store.status === CheckoutStatus.Error && this.store.lastError)) {
1003
- _context16.next = 14;
1173
+ _context17.next = 10;
1004
1174
  break;
1005
1175
  }
1006
- _context16.t0 = this.store.lastError.type;
1007
- _context16.next = _context16.t0 === CheckoutErrorType.OrderCreationFailed ? 5 : _context16.t0 === CheckoutErrorType.PaymentFailed ? 9 : 13;
1176
+ _context17.t0 = this.store.lastError.type;
1177
+ _context17.next = _context17.t0 === CheckoutErrorType.OrderCreationFailed ? 5 : 9;
1008
1178
  break;
1009
1179
  case 5:
1010
1180
  if (!(this.store.cartItems.length > 0)) {
1011
- _context16.next = 8;
1181
+ _context17.next = 8;
1012
1182
  break;
1013
1183
  }
1014
- _context16.next = 8;
1184
+ _context17.next = 8;
1015
1185
  return this.createOrderAsync({
1016
1186
  cartItems: this.store.cartItems
1017
1187
  });
1018
1188
  case 8:
1019
- return _context16.abrupt("break", 14);
1189
+ return _context17.abrupt("break", 10);
1020
1190
  case 9:
1021
- if (!this.store.currentOrder) {
1022
- _context16.next = 12;
1023
- break;
1024
- }
1025
- _context16.next = 12;
1026
- return this.store.payment.runPaymentSyncQueue();
1027
- case 12:
1028
- return _context16.abrupt("break", 14);
1029
- case 13:
1030
1191
  console.warn('[Checkout] 无法重试此类型的错误:', this.store.lastError.type);
1031
- case 14:
1032
- _context16.next = 20;
1192
+ case 10:
1193
+ _context17.next = 16;
1033
1194
  break;
1195
+ case 12:
1196
+ _context17.prev = 12;
1197
+ _context17.t1 = _context17["catch"](0);
1198
+ _context17.next = 16;
1199
+ return this.handleError(_context17.t1, CheckoutErrorType.UnknownError);
1034
1200
  case 16:
1035
- _context16.prev = 16;
1036
- _context16.t1 = _context16["catch"](0);
1037
- _context16.next = 20;
1038
- return this.handleError(_context16.t1, CheckoutErrorType.UnknownError);
1039
- case 20:
1040
1201
  case "end":
1041
- return _context16.stop();
1202
+ return _context17.stop();
1042
1203
  }
1043
- }, _callee16, this, [[0, 16]]);
1204
+ }, _callee17, this, [[0, 12]]);
1044
1205
  }));
1045
1206
  function retryFailedOperationAsync() {
1046
1207
  return _retryFailedOperationAsync.apply(this, arguments);
@@ -1069,7 +1230,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1069
1230
  }, {
1070
1231
  key: "getOrderModule",
1071
1232
  value: function getOrderModule() {
1072
- return this.store.order;
1233
+ return this.order;
1073
1234
  }
1074
1235
 
1075
1236
  /**
@@ -1078,7 +1239,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1078
1239
  }, {
1079
1240
  key: "getPaymentModule",
1080
1241
  value: function getPaymentModule() {
1081
- return this.store.payment;
1242
+ return this.payment;
1082
1243
  }
1083
1244
 
1084
1245
  /**
@@ -1092,32 +1253,32 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1092
1253
  }, {
1093
1254
  key: "replaceLocalOrderIdAsync",
1094
1255
  value: (function () {
1095
- var _replaceLocalOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(newOrderId) {
1256
+ var _replaceLocalOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(newOrderId) {
1096
1257
  var updatedOrder;
1097
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1098
- while (1) switch (_context17.prev = _context17.next) {
1258
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1259
+ while (1) switch (_context18.prev = _context18.next) {
1099
1260
  case 0:
1100
- _context17.prev = 0;
1261
+ _context18.prev = 0;
1101
1262
  if (this.store.currentOrder) {
1102
- _context17.next = 4;
1263
+ _context18.next = 4;
1103
1264
  break;
1104
1265
  }
1105
1266
  console.warn('[Checkout] 没有当前订单,无法替换订单ID');
1106
- return _context17.abrupt("return", null);
1267
+ return _context18.abrupt("return", null);
1107
1268
  case 4:
1108
- _context17.next = 6;
1109
- return this.store.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, newOrderId);
1269
+ _context18.next = 6;
1270
+ return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, newOrderId);
1110
1271
  case 6:
1111
- updatedOrder = _context17.sent;
1272
+ updatedOrder = _context18.sent;
1112
1273
  if (!updatedOrder) {
1113
- _context17.next = 12;
1274
+ _context18.next = 15;
1114
1275
  break;
1115
1276
  }
1116
1277
  // 更新当前订单引用
1117
1278
  this.store.currentOrder = updatedOrder;
1118
1279
 
1119
1280
  // 触发订单更新事件
1120
- _context17.next = 11;
1281
+ _context18.next = 11;
1121
1282
  return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
1122
1283
  order: updatedOrder,
1123
1284
  timestamp: Date.now()
@@ -1127,21 +1288,28 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1127
1288
  uuid: updatedOrder.uuid,
1128
1289
  newOrderId: updatedOrder.id
1129
1290
  });
1130
- case 12:
1131
- return _context17.abrupt("return", updatedOrder);
1291
+
1292
+ // 标记订单已同步(替换ID意味着订单已在后端创建)
1293
+ this.store.isOrderSynced = true;
1294
+
1295
+ // 订单ID替换后更新 stateAmount
1296
+ _context18.next = 15;
1297
+ return this.updateStateAmountToRemaining();
1132
1298
  case 15:
1133
- _context17.prev = 15;
1134
- _context17.t0 = _context17["catch"](0);
1135
- console.error('[Checkout] 替换订单ID失败:', _context17.t0);
1136
- _context17.next = 20;
1137
- return this.handleError(_context17.t0, CheckoutErrorType.UnknownError);
1138
- case 20:
1139
- return _context17.abrupt("return", null);
1140
- case 21:
1299
+ return _context18.abrupt("return", updatedOrder);
1300
+ case 18:
1301
+ _context18.prev = 18;
1302
+ _context18.t0 = _context18["catch"](0);
1303
+ console.error('[Checkout] 替换订单ID失败:', _context18.t0);
1304
+ _context18.next = 23;
1305
+ return this.handleError(_context18.t0, CheckoutErrorType.UnknownError);
1306
+ case 23:
1307
+ return _context18.abrupt("return", null);
1308
+ case 24:
1141
1309
  case "end":
1142
- return _context17.stop();
1310
+ return _context18.stop();
1143
1311
  }
1144
- }, _callee17, this, [[0, 15]]);
1312
+ }, _callee18, this, [[0, 18]]);
1145
1313
  }));
1146
1314
  function replaceLocalOrderIdAsync(_x11) {
1147
1315
  return _replaceLocalOrderIdAsync.apply(this, arguments);
@@ -1149,138 +1317,1361 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1149
1317
  return replaceLocalOrderIdAsync;
1150
1318
  }()
1151
1319
  /**
1152
- * 设置状态
1153
- */
1154
- )
1155
- }, {
1156
- key: "setStatus",
1157
- value: (function () {
1158
- var _setStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(status) {
1159
- var oldStatus;
1160
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1161
- while (1) switch (_context18.prev = _context18.next) {
1162
- case 0:
1163
- oldStatus = this.store.status;
1164
- this.store.status = status;
1165
- _context18.next = 4;
1166
- return this.core.effects.emit(CheckoutHooks.OnStatusChanged, {
1167
- oldStatus: oldStatus,
1168
- newStatus: status,
1169
- timestamp: Date.now()
1170
- });
1171
- case 4:
1172
- case "end":
1173
- return _context18.stop();
1174
- }
1175
- }, _callee18, this);
1176
- }));
1177
- function setStatus(_x12) {
1178
- return _setStatus.apply(this, arguments);
1179
- }
1180
- return setStatus;
1181
- }()
1182
- /**
1183
- * 设置步骤
1320
+ * 设置自定义支付金额
1321
+ *
1322
+ * 允许UI自定义本次支付的金额,通常用于部分支付或调整支付金额场景
1323
+ *
1324
+ * @param amount 自定义支付金额,必须是有效的数字字符串
1184
1325
  */
1185
1326
  )
1186
1327
  }, {
1187
- key: "setStep",
1328
+ key: "setStateAmountAsync",
1188
1329
  value: (function () {
1189
- var _setStep = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(step) {
1190
- var oldStep;
1330
+ var _setStateAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(amount) {
1331
+ var numAmount, oldAmount, formattedAmount, errorMessage;
1191
1332
  return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1192
1333
  while (1) switch (_context19.prev = _context19.next) {
1193
1334
  case 0:
1194
- oldStep = this.store.step;
1195
- this.store.step = step;
1196
- _context19.next = 4;
1197
- return this.core.effects.emit(CheckoutHooks.OnStepChanged, {
1198
- oldStep: oldStep,
1199
- newStep: step,
1335
+ _context19.prev = 0;
1336
+ // 验证金额格式
1337
+ numAmount = parseFloat(amount);
1338
+ if (!(isNaN(numAmount) || numAmount < 0)) {
1339
+ _context19.next = 4;
1340
+ break;
1341
+ }
1342
+ throw new Error("\u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: ".concat(amount));
1343
+ case 4:
1344
+ oldAmount = this.store.stateAmount;
1345
+ formattedAmount = numAmount.toFixed(2); // 如果金额没有变化,直接返回
1346
+ if (!(oldAmount === formattedAmount)) {
1347
+ _context19.next = 8;
1348
+ break;
1349
+ }
1350
+ return _context19.abrupt("return");
1351
+ case 8:
1352
+ // 更新状态
1353
+ this.store.stateAmount = formattedAmount;
1354
+
1355
+ // 触发金额变更事件
1356
+ _context19.next = 11;
1357
+ return this.core.effects.emit(CheckoutHooks.OnStateAmountChanged, {
1358
+ oldAmount: oldAmount,
1359
+ newAmount: formattedAmount,
1200
1360
  timestamp: Date.now()
1201
1361
  });
1202
- case 4:
1362
+ case 11:
1363
+ console.log('[Checkout] 自定义支付金额已更新:', {
1364
+ oldAmount: oldAmount,
1365
+ newAmount: formattedAmount
1366
+ });
1367
+ _context19.next = 21;
1368
+ break;
1369
+ case 14:
1370
+ _context19.prev = 14;
1371
+ _context19.t0 = _context19["catch"](0);
1372
+ errorMessage = _context19.t0 instanceof Error ? _context19.t0.message : '设置支付金额失败';
1373
+ console.error('[Checkout] 设置自定义支付金额失败:', errorMessage);
1374
+ _context19.next = 20;
1375
+ return this.handleError(new Error(errorMessage), CheckoutErrorType.ValidationFailed);
1376
+ case 20:
1377
+ throw _context19.t0;
1378
+ case 21:
1203
1379
  case "end":
1204
1380
  return _context19.stop();
1205
1381
  }
1206
- }, _callee19, this);
1382
+ }, _callee19, this, [[0, 14]]);
1207
1383
  }));
1208
- function setStep(_x13) {
1209
- return _setStep.apply(this, arguments);
1384
+ function setStateAmountAsync(_x12) {
1385
+ return _setStateAmountAsync.apply(this, arguments);
1210
1386
  }
1211
- return setStep;
1387
+ return setStateAmountAsync;
1212
1388
  }()
1213
1389
  /**
1214
- * 处理错误
1390
+ * 获取当前自定义支付金额
1391
+ *
1392
+ * @returns 当前设置的自定义支付金额
1215
1393
  */
1216
1394
  )
1217
1395
  }, {
1218
- key: "handleError",
1396
+ key: "getStateAmount",
1397
+ value: function getStateAmount() {
1398
+ return this.store.stateAmount;
1399
+ }
1400
+
1401
+ /**
1402
+ * 刷新 stateAmount 为当前剩余未支付金额
1403
+ *
1404
+ * UI 可以调用此方法来主动刷新支付金额状态
1405
+ */
1406
+ }, {
1407
+ key: "refreshStateAmountAsync",
1219
1408
  value: (function () {
1220
- var _handleError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(error, type) {
1221
- var checkoutError;
1409
+ var _refreshStateAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1222
1410
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1223
1411
  while (1) switch (_context20.prev = _context20.next) {
1224
1412
  case 0:
1225
- checkoutError = error instanceof Error && 'type' in error ? error : createCheckoutError(type, error.message, error);
1226
- this.store.lastError = checkoutError;
1227
- _context20.next = 4;
1228
- return this.setStatus(CheckoutStatus.Error);
1229
- case 4:
1230
- _context20.next = 6;
1231
- return this.core.effects.emit(CheckoutHooks.OnError, {
1232
- error: checkoutError,
1233
- context: {
1234
- status: this.store.status,
1235
- step: this.store.step
1236
- },
1237
- timestamp: Date.now()
1238
- });
1239
- case 6:
1240
- console.error('[Checkout] 错误:', checkoutError);
1241
- case 7:
1413
+ _context20.next = 2;
1414
+ return this.updateStateAmountToRemaining();
1415
+ case 2:
1242
1416
  case "end":
1243
1417
  return _context20.stop();
1244
1418
  }
1245
1419
  }, _callee20, this);
1246
1420
  }));
1247
- function handleError(_x14, _x15) {
1248
- return _handleError.apply(this, arguments);
1421
+ function refreshStateAmountAsync() {
1422
+ return _refreshStateAmountAsync.apply(this, arguments);
1249
1423
  }
1250
- return handleError;
1424
+ return refreshStateAmountAsync;
1251
1425
  }()
1252
1426
  /**
1253
- * 处理支付成功
1427
+ * 获取购物车小计数据
1428
+ *
1429
+ * 返回当前结账流程中的购物车小计项数据,包含各种费用明细
1430
+ *
1431
+ * @returns 购物车小计数据数组,如果没有则返回 null
1254
1432
  */
1255
1433
  )
1256
1434
  }, {
1257
- key: "handlePaymentSuccess",
1435
+ key: "getCartSummary",
1436
+ value: function getCartSummary() {
1437
+ if (!this.store.cartSummary || this.store.cartSummary.length === 0) {
1438
+ console.warn('[Checkout] 没有可用的购物车小计数据');
1439
+ return null;
1440
+ }
1441
+ console.log('[Checkout] 获取购物车小计数据:', {
1442
+ itemCount: this.store.cartSummary.length,
1443
+ items: this.store.cartSummary.map(function (item) {
1444
+ return {
1445
+ key: item.key,
1446
+ value: item.value,
1447
+ label: item.label
1448
+ };
1449
+ })
1450
+ });
1451
+ return _toConsumableArray(this.store.cartSummary); // 返回副本,避免外部修改
1452
+ }
1453
+
1454
+ /**
1455
+ * 获取提取的金额详细信息
1456
+ *
1457
+ * 从当前的购物车小计数据中提取结构化的金额信息
1458
+ *
1459
+ * @returns 提取的金额信息对象,如果没有小计数据则返回 null
1460
+ */
1461
+ }, {
1462
+ key: "getExtractedAmountInfo",
1463
+ value: function getExtractedAmountInfo() {
1464
+ if (!this.store.cartSummary || this.store.cartSummary.length === 0) {
1465
+ console.warn('[Checkout] 没有可用的购物车小计数据,无法提取金额信息');
1466
+ return null;
1467
+ }
1468
+ var extractedInfo = this.extractAmountFromCartSummary(this.store.cartSummary);
1469
+ console.log('[Checkout] 获取提取的金额信息:', extractedInfo);
1470
+ return extractedInfo;
1471
+ }
1472
+
1473
+ /**
1474
+ * 获取支付方式列表
1475
+ *
1476
+ * 直接调用 Payment 模块的 getPayMethodListAsync 方法
1477
+ *
1478
+ * @returns 支付方式列表
1479
+ */
1480
+ }, {
1481
+ key: "getPaymentMethodsAsync",
1258
1482
  value: (function () {
1259
- var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(data) {
1260
- var _this$store$currentOr4;
1483
+ var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1261
1484
  return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1262
1485
  while (1) switch (_context21.prev = _context21.next) {
1263
1486
  case 0:
1264
1487
  _context21.next = 2;
1265
- return this.setStatus(CheckoutStatus.PaymentCompleted);
1488
+ return this.payment.getPayMethodListAsync();
1266
1489
  case 2:
1267
- _context21.next = 4;
1490
+ return _context21.abrupt("return", _context21.sent);
1491
+ case 3:
1492
+ case "end":
1493
+ return _context21.stop();
1494
+ }
1495
+ }, _callee21, this);
1496
+ }));
1497
+ function getPaymentMethodsAsync() {
1498
+ return _getPaymentMethodsAsync.apply(this, arguments);
1499
+ }
1500
+ return getPaymentMethodsAsync;
1501
+ }()
1502
+ /**
1503
+ * 为当前订单添加支付项
1504
+ *
1505
+ * 向当前活跃订单添加一个支付项,支付项包含支付方式信息和金额
1506
+ *
1507
+ * @param paymentItem 支付项数据
1508
+ * @throws 当前没有活跃订单时抛出错误
1509
+ */
1510
+ )
1511
+ }, {
1512
+ key: "addPaymentItemAsync",
1513
+ value: (function () {
1514
+ var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(paymentItem) {
1515
+ var currentOrderId, isCurrentOrderReal, updatedOrder, needsOrderSync;
1516
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1517
+ while (1) switch (_context22.prev = _context22.next) {
1518
+ case 0:
1519
+ _context22.prev = 0;
1520
+ if (this.store.currentOrder) {
1521
+ _context22.next = 3;
1522
+ break;
1523
+ }
1524
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法添加支付项');
1525
+ case 3:
1526
+ console.log('[Checkout] 为当前订单添加支付项:', {
1527
+ orderUuid: this.store.currentOrder.uuid,
1528
+ paymentItem: {
1529
+ code: paymentItem.code,
1530
+ name: paymentItem.name,
1531
+ type: paymentItem.type,
1532
+ amount: paymentItem.amount,
1533
+ service_charge: paymentItem.service_charge
1534
+ }
1535
+ });
1536
+
1537
+ // 添加支付项到订单
1538
+ _context22.next = 6;
1539
+ return this.payment.addPaymentItemAsync(this.store.currentOrder.uuid, paymentItem);
1540
+ case 6:
1541
+ console.log('[Checkout] 支付项添加成功');
1542
+
1543
+ // 重新从Payment模块获取最新的订单数据,确保支付项同步
1544
+ currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1545
+ isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
1546
+ console.log('[Checkout] 准备同步订单数据:', {
1547
+ 当前订单ID: currentOrderId,
1548
+ 是否为真实ID: isCurrentOrderReal
1549
+ });
1550
+ _context22.next = 12;
1551
+ return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1552
+ case 12:
1553
+ updatedOrder = _context22.sent;
1554
+ if (updatedOrder) {
1555
+ // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
1556
+ if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
1557
+ console.warn('[Checkout] 检测到订单ID回退,保护真实订单ID:', {
1558
+ 当前真实ID: currentOrderId,
1559
+ 获取到的虚拟ID: updatedOrder.order_id
1560
+ });
1561
+ updatedOrder.order_id = currentOrderId; // 恢复真实的订单ID
1562
+ }
1563
+ this.store.currentOrder = updatedOrder;
1564
+ console.log('[Checkout] 订单数据已同步:', {
1565
+ 支付项数量: updatedOrder.payment.length,
1566
+ 最终订单ID: updatedOrder.order_id,
1567
+ 是否为虚拟ID: this.isVirtualOrderId(updatedOrder.order_id)
1568
+ });
1569
+ }
1570
+
1571
+ // 检查是否需要同步订单到后端
1572
+ needsOrderSync = this.shouldSyncOrderForPayment(paymentItem.code, paymentItem.type);
1573
+ console.log('[Checkout] 支付项同步检查:', {
1574
+ paymentCode: paymentItem.code,
1575
+ paymentType: paymentItem.type,
1576
+ paymentAmount: paymentItem.amount,
1577
+ expectedCashCode: PaymentMethodType.Cash,
1578
+ needsOrderSync: needsOrderSync,
1579
+ isOrderSynced: this.store.isOrderSynced
1580
+ });
1581
+ if (!needsOrderSync) {
1582
+ _context22.next = 21;
1583
+ break;
1584
+ }
1585
+ console.log('[Checkout] 检测到非现金/自定义支付,开始同步订单到后端...', {
1586
+ 同步前订单ID: this.store.currentOrder.order_id,
1587
+ 是否为虚拟ID: this.isVirtualOrderId(this.store.currentOrder.order_id),
1588
+ 订单同步状态: this.store.isOrderSynced,
1589
+ 订单UUID: this.store.currentOrder.uuid
1590
+ });
1591
+ _context22.next = 20;
1592
+ return this.syncOrderToBackend();
1593
+ case 20:
1594
+ console.log('[Checkout] addPaymentItemAsync 中的同步完成:', {
1595
+ 同步后订单ID: this.store.currentOrder.order_id,
1596
+ 是否为虚拟ID: this.isVirtualOrderId(this.store.currentOrder.order_id),
1597
+ 订单同步状态: this.store.isOrderSynced
1598
+ });
1599
+ case 21:
1600
+ _context22.next = 23;
1601
+ return this.updateStateAmountToRemaining();
1602
+ case 23:
1603
+ _context22.next = 25;
1604
+ return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1605
+ orderUuid: this.store.currentOrder.uuid,
1606
+ paymentMethodCode: paymentItem.code,
1607
+ amount: String(paymentItem.amount),
1608
+ timestamp: Date.now()
1609
+ });
1610
+ case 25:
1611
+ _context22.next = 33;
1612
+ break;
1613
+ case 27:
1614
+ _context22.prev = 27;
1615
+ _context22.t0 = _context22["catch"](0);
1616
+ console.error('[Checkout] 添加支付项失败:', _context22.t0);
1617
+ _context22.next = 32;
1618
+ return this.handleError(_context22.t0, CheckoutErrorType.PaymentFailed);
1619
+ case 32:
1620
+ throw _context22.t0;
1621
+ case 33:
1622
+ case "end":
1623
+ return _context22.stop();
1624
+ }
1625
+ }, _callee22, this, [[0, 27]]);
1626
+ }));
1627
+ function addPaymentItemAsync(_x13) {
1628
+ return _addPaymentItemAsync.apply(this, arguments);
1629
+ }
1630
+ return addPaymentItemAsync;
1631
+ }()
1632
+ /**
1633
+ * 删除当前订单的支付项
1634
+ *
1635
+ * 从当前活跃订单中删除指定的支付项,支付项将被标记为已撤销状态
1636
+ *
1637
+ * @param paymentUuid 要删除的支付项UUID
1638
+ * @throws 当前没有活跃订单时抛出错误
1639
+ * @throws 支付项不存在时抛出错误
1640
+ */
1641
+ )
1642
+ }, {
1643
+ key: "deletePaymentItemAsync",
1644
+ value: (function () {
1645
+ var _deletePaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(paymentUuid) {
1646
+ var paymentItem, currentOrderId, isCurrentOrderReal, updatedOrder;
1647
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1648
+ while (1) switch (_context23.prev = _context23.next) {
1649
+ case 0:
1650
+ _context23.prev = 0;
1651
+ if (this.store.currentOrder) {
1652
+ _context23.next = 3;
1653
+ break;
1654
+ }
1655
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, '当前没有活跃订单,无法删除支付项');
1656
+ case 3:
1657
+ console.log('[Checkout] 开始删除支付项:', {
1658
+ orderUuid: this.store.currentOrder.uuid,
1659
+ paymentUuid: paymentUuid
1660
+ });
1661
+
1662
+ // 验证支付项是否存在
1663
+ paymentItem = this.store.currentOrder.payment.find(function (p) {
1664
+ return p.uuid === paymentUuid;
1665
+ });
1666
+ if (paymentItem) {
1667
+ _context23.next = 7;
1668
+ break;
1669
+ }
1670
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u652F\u4ED8\u9879\u4E0D\u5B58\u5728: ".concat(paymentUuid));
1671
+ case 7:
1672
+ console.log('[Checkout] 找到要删除的支付项:', {
1673
+ uuid: paymentItem.uuid,
1674
+ code: paymentItem.code,
1675
+ amount: paymentItem.amount,
1676
+ status: paymentItem.status
1677
+ });
1678
+
1679
+ // 调用 Payment 模块删除支付项
1680
+ _context23.next = 10;
1681
+ return this.payment.deletePaymentAsync(this.store.currentOrder.uuid, paymentUuid);
1682
+ case 10:
1683
+ console.log('[Checkout] Payment模块删除完成');
1684
+
1685
+ // 重新从Payment模块获取最新的订单数据,确保支付项同步
1686
+ currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1687
+ isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
1688
+ _context23.next = 15;
1689
+ return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1690
+ case 15:
1691
+ updatedOrder = _context23.sent;
1692
+ if (updatedOrder) {
1693
+ // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
1694
+ if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
1695
+ console.warn('[Checkout] deletePaymentItemAsync: 检测到订单ID回退,保护真实订单ID:', {
1696
+ 当前真实ID: currentOrderId,
1697
+ 获取到的虚拟ID: updatedOrder.order_id
1698
+ });
1699
+ updatedOrder.order_id = currentOrderId; // 恢复真实的订单ID
1700
+ }
1701
+ this.store.currentOrder = updatedOrder;
1702
+ console.log('[Checkout] 订单数据已同步,当前支付项数量:', updatedOrder.payment.length);
1703
+ }
1704
+
1705
+ // 更新 stateAmount 为剩余未支付金额
1706
+ _context23.next = 19;
1707
+ return this.updateStateAmountToRemaining();
1708
+ case 19:
1709
+ _context23.next = 21;
1710
+ return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1711
+ orderUuid: this.store.currentOrder.uuid,
1712
+ paymentMethodCode: paymentItem.code,
1713
+ amount: "-".concat(paymentItem.amount),
1714
+ // 负数表示删除
1715
+ timestamp: Date.now()
1716
+ });
1717
+ case 21:
1718
+ console.log('[Checkout] 支付项删除成功');
1719
+ _context23.next = 30;
1720
+ break;
1721
+ case 24:
1722
+ _context23.prev = 24;
1723
+ _context23.t0 = _context23["catch"](0);
1724
+ console.error('[Checkout] 删除支付项失败:', _context23.t0);
1725
+ _context23.next = 29;
1726
+ return this.handleError(_context23.t0, CheckoutErrorType.PaymentFailed);
1727
+ case 29:
1728
+ throw _context23.t0;
1729
+ case 30:
1730
+ case "end":
1731
+ return _context23.stop();
1732
+ }
1733
+ }, _callee23, this, [[0, 24]]);
1734
+ }));
1735
+ function deletePaymentItemAsync(_x14) {
1736
+ return _deletePaymentItemAsync.apply(this, arguments);
1737
+ }
1738
+ return deletePaymentItemAsync;
1739
+ }()
1740
+ /**
1741
+ * 批量更新当前订单的代金券支付项(覆盖更新)
1742
+ *
1743
+ * 删除所有现有的代金券支付项,然后添加新的代金券支付项。
1744
+ * 这是一个覆盖式更新操作,确保代金券支付项的一致性。
1745
+ *
1746
+ * @param voucherPaymentItems 新的代金券支付项列表,每个都必须包含 voucher_id
1747
+ * @throws 当前没有活跃订单时抛出错误
1748
+ * @throws 支付项缺少 voucher_id 时抛出错误
1749
+ */
1750
+ )
1751
+ }, {
1752
+ key: "updateVoucherPaymentItemsAsync",
1753
+ value: (function () {
1754
+ var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(voucherPaymentItems) {
1755
+ var _iterator, _step, item, currentOrderId, isCurrentOrderReal, updatedOrder, voucherItems;
1756
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1757
+ while (1) switch (_context24.prev = _context24.next) {
1758
+ case 0:
1759
+ _context24.prev = 0;
1760
+ if (this.store.currentOrder) {
1761
+ _context24.next = 3;
1762
+ break;
1763
+ }
1764
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, '当前没有活跃订单,无法更新代金券支付项');
1765
+ case 3:
1766
+ console.log('[Checkout] 开始批量更新代金券支付项:', {
1767
+ orderUuid: this.store.currentOrder.uuid,
1768
+ newVoucherCount: voucherPaymentItems.length,
1769
+ voucherPaymentItems: voucherPaymentItems
1770
+ });
1771
+
1772
+ // 验证所有支付项都包含 voucher_id
1773
+ _iterator = _createForOfIteratorHelper(voucherPaymentItems);
1774
+ _context24.prev = 5;
1775
+ _iterator.s();
1776
+ case 7:
1777
+ if ((_step = _iterator.n()).done) {
1778
+ _context24.next = 13;
1779
+ break;
1780
+ }
1781
+ item = _step.value;
1782
+ if (item.voucher_id) {
1783
+ _context24.next = 11;
1784
+ break;
1785
+ }
1786
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u7F3A\u5C11 voucher_id: ".concat(JSON.stringify(item)));
1787
+ case 11:
1788
+ _context24.next = 7;
1789
+ break;
1790
+ case 13:
1791
+ _context24.next = 18;
1792
+ break;
1793
+ case 15:
1794
+ _context24.prev = 15;
1795
+ _context24.t0 = _context24["catch"](5);
1796
+ _iterator.e(_context24.t0);
1797
+ case 18:
1798
+ _context24.prev = 18;
1799
+ _iterator.f();
1800
+ return _context24.finish(18);
1801
+ case 21:
1802
+ _context24.next = 23;
1803
+ return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItems);
1804
+ case 23:
1805
+ console.log('[Checkout] Payment模块批量更新完成');
1806
+
1807
+ // 重新从Payment模块获取最新的订单数据,确保支付项同步
1808
+ currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1809
+ isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
1810
+ _context24.next = 28;
1811
+ return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1812
+ case 28:
1813
+ updatedOrder = _context24.sent;
1814
+ if (updatedOrder) {
1815
+ // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
1816
+ if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
1817
+ console.warn('[Checkout] updateVoucherPaymentItemsAsync: 检测到订单ID回退,保护真实订单ID:', {
1818
+ 当前真实ID: currentOrderId,
1819
+ 获取到的虚拟ID: updatedOrder.order_id
1820
+ });
1821
+ updatedOrder.order_id = currentOrderId; // 恢复真实的订单ID
1822
+ }
1823
+ this.store.currentOrder = updatedOrder;
1824
+ console.log('[Checkout] 订单数据已同步,当前支付项数量:', updatedOrder.payment.length);
1825
+
1826
+ // 打印更新后的代金券支付项
1827
+ voucherItems = updatedOrder.payment.filter(function (payment) {
1828
+ return payment.voucher_id && payment.status !== 'voided';
1829
+ });
1830
+ console.log('[Checkout] 更新后的代金券支付项:', {
1831
+ voucherCount: voucherItems.length,
1832
+ items: voucherItems.map(function (item) {
1833
+ return {
1834
+ uuid: item.uuid,
1835
+ code: item.code,
1836
+ amount: item.amount,
1837
+ voucher_id: item.voucher_id
1838
+ };
1839
+ })
1840
+ });
1841
+ }
1842
+
1843
+ // 更新 stateAmount 为剩余未支付金额
1844
+ _context24.next = 32;
1845
+ return this.updateStateAmountToRemaining();
1846
+ case 32:
1847
+ _context24.next = 34;
1848
+ return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1849
+ orderUuid: this.store.currentOrder.uuid,
1850
+ paymentMethodCode: 'VOUCHER_BATCH',
1851
+ amount: voucherPaymentItems.reduce(function (sum, item) {
1852
+ return sum + parseFloat(String(item.amount));
1853
+ }, 0).toFixed(2),
1854
+ timestamp: Date.now()
1855
+ });
1856
+ case 34:
1857
+ console.log('[Checkout] 代金券支付项批量更新成功');
1858
+ _context24.next = 43;
1859
+ break;
1860
+ case 37:
1861
+ _context24.prev = 37;
1862
+ _context24.t1 = _context24["catch"](0);
1863
+ console.error('[Checkout] 批量更新代金券支付项失败:', _context24.t1);
1864
+ _context24.next = 42;
1865
+ return this.handleError(_context24.t1, CheckoutErrorType.PaymentFailed);
1866
+ case 42:
1867
+ throw _context24.t1;
1868
+ case 43:
1869
+ case "end":
1870
+ return _context24.stop();
1871
+ }
1872
+ }, _callee24, this, [[0, 37], [5, 15, 18, 21]]);
1873
+ }));
1874
+ function updateVoucherPaymentItemsAsync(_x15) {
1875
+ return _updateVoucherPaymentItemsAsync.apply(this, arguments);
1876
+ }
1877
+ return updateVoucherPaymentItemsAsync;
1878
+ }()
1879
+ /**
1880
+ * 修改当前订单的定金状态
1881
+ *
1882
+ * 更新当前订单的 is_deposit 字段,用于标识订单是否为定金订单
1883
+ *
1884
+ * @param isDeposit 定金状态 (1: 定金订单, 0: 全款订单)
1885
+ * @throws 当前没有活跃订单时抛出错误
1886
+ */
1887
+ )
1888
+ }, {
1889
+ key: "updateOrderDepositStatusAsync",
1890
+ value: (function () {
1891
+ var _updateOrderDepositStatusAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(isDeposit) {
1892
+ var newDepositValue, oldDepositValue, updateParams;
1893
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1894
+ while (1) switch (_context25.prev = _context25.next) {
1895
+ case 0:
1896
+ _context25.prev = 0;
1897
+ if (!(isDeposit !== 0 && isDeposit !== 1)) {
1898
+ _context25.next = 3;
1899
+ break;
1900
+ }
1901
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, 'isDeposit 参数只能是 0(全款订单)或 1(定金订单)');
1902
+ case 3:
1903
+ if (this.store.currentOrder) {
1904
+ _context25.next = 5;
1905
+ break;
1906
+ }
1907
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法修改定金状态');
1908
+ case 5:
1909
+ newDepositValue = isDeposit;
1910
+ oldDepositValue = this.store.currentOrder.is_deposit; // 如果状态没有变化,直接返回
1911
+ if (!(oldDepositValue === newDepositValue)) {
1912
+ _context25.next = 10;
1913
+ break;
1914
+ }
1915
+ console.log('[Checkout] 定金状态无变化,跳过更新');
1916
+ return _context25.abrupt("return");
1917
+ case 10:
1918
+ console.log('[Checkout] 更新订单定金状态:', {
1919
+ orderUuid: this.store.currentOrder.uuid,
1920
+ orderId: this.store.currentOrder.order_id,
1921
+ oldIsDeposit: oldDepositValue,
1922
+ newIsDeposit: newDepositValue
1923
+ });
1924
+
1925
+ // 准备更新参数
1926
+ updateParams = {
1927
+ is_deposit: newDepositValue
1928
+ }; // 如果从定金改为全款,可以清空定金金额
1929
+ if (isDeposit === 0 && this.store.currentOrder.deposit_amount !== '0.00') {
1930
+ updateParams.deposit_amount = '0.00';
1931
+ console.log('[Checkout] 订单从定金改为全款,清空定金金额');
1932
+ }
1933
+
1934
+ // 调用 Payment 模块更新订单
1935
+ _context25.next = 15;
1936
+ return this.payment.updateOrderAsync(this.store.currentOrder.uuid, updateParams);
1937
+ case 15:
1938
+ // 更新本地缓存的订单对象
1939
+ this.store.currentOrder = _objectSpread(_objectSpread({}, this.store.currentOrder), updateParams);
1940
+
1941
+ // 同时更新本地订单数据(如果存在)
1942
+ if (this.store.localOrderData) {
1943
+ this.store.localOrderData.is_deposit = newDepositValue;
1944
+ }
1945
+
1946
+ // 触发订单更新事件
1947
+ _context25.next = 19;
1948
+ return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
1949
+ order: this.store.currentOrder,
1950
+ timestamp: Date.now()
1951
+ });
1952
+ case 19:
1953
+ console.log('[Checkout] 订单定金状态更新成功:', {
1954
+ isDeposit: newDepositValue,
1955
+ depositAmount: this.store.currentOrder.deposit_amount
1956
+ });
1957
+ _context25.next = 28;
1958
+ break;
1959
+ case 22:
1960
+ _context25.prev = 22;
1961
+ _context25.t0 = _context25["catch"](0);
1962
+ console.error('[Checkout] 更新订单定金状态失败:', _context25.t0);
1963
+ _context25.next = 27;
1964
+ return this.handleError(_context25.t0, CheckoutErrorType.ValidationFailed);
1965
+ case 27:
1966
+ throw _context25.t0;
1967
+ case 28:
1968
+ case "end":
1969
+ return _context25.stop();
1970
+ }
1971
+ }, _callee25, this, [[0, 22]]);
1972
+ }));
1973
+ function updateOrderDepositStatusAsync(_x16) {
1974
+ return _updateOrderDepositStatusAsync.apply(this, arguments);
1975
+ }
1976
+ return updateOrderDepositStatusAsync;
1977
+ }()
1978
+ /**
1979
+ * 更新当前订单的客户信息
1980
+ *
1981
+ * 更新当前订单关联的客户信息,用于标识订单的所属客户
1982
+ *
1983
+ * @param customer 客户信息 (customer_id 和/或 customer_name)
1984
+ * @throws 当前没有活跃订单时抛出错误
1985
+ */
1986
+ )
1987
+ }, {
1988
+ key: "updateOrderCustomerAsync",
1989
+ value: (function () {
1990
+ var _updateOrderCustomerAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(customer) {
1991
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
1992
+ while (1) switch (_context26.prev = _context26.next) {
1993
+ case 0:
1994
+ _context26.prev = 0;
1995
+ if (this.store.currentOrder) {
1996
+ _context26.next = 3;
1997
+ break;
1998
+ }
1999
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法更新客户信息');
2000
+ case 3:
2001
+ console.log('[Checkout] 更新订单客户信息:', {
2002
+ orderUuid: this.store.currentOrder.uuid,
2003
+ oldCustomer: this.store.currentCustomer,
2004
+ newCustomer: customer
2005
+ });
2006
+
2007
+ // 更新客户信息
2008
+ this.store.currentCustomer = {
2009
+ customer_id: customer.customer_id,
2010
+ customer_name: customer.customer_name
2011
+ };
2012
+
2013
+ // 同时更新本地订单数据中的客户信息(如果存在)
2014
+ if (this.store.localOrderData) {
2015
+ this.store.localOrderData.customer_id = customer.customer_id;
2016
+ this.store.localOrderData.customer_name = customer.customer_name;
2017
+ }
2018
+ console.log('[Checkout] 订单客户信息更新成功:', this.store.currentCustomer);
2019
+ _context26.next = 15;
2020
+ break;
2021
+ case 9:
2022
+ _context26.prev = 9;
2023
+ _context26.t0 = _context26["catch"](0);
2024
+ console.error('[Checkout] 更新订单客户信息失败:', _context26.t0);
2025
+ _context26.next = 14;
2026
+ return this.handleError(_context26.t0, CheckoutErrorType.ValidationFailed);
2027
+ case 14:
2028
+ throw _context26.t0;
2029
+ case 15:
2030
+ case "end":
2031
+ return _context26.stop();
2032
+ }
2033
+ }, _callee26, this, [[0, 9]]);
2034
+ }));
2035
+ function updateOrderCustomerAsync(_x17) {
2036
+ return _updateOrderCustomerAsync.apply(this, arguments);
2037
+ }
2038
+ return updateOrderCustomerAsync;
2039
+ }()
2040
+ /**
2041
+ * 获取当前订单的客户信息
2042
+ *
2043
+ * @returns 当前客户信息,如果没有则返回 null
2044
+ */
2045
+ )
2046
+ }, {
2047
+ key: "getCurrentCustomer",
2048
+ value: function getCurrentCustomer() {
2049
+ return this.store.currentCustomer || null;
2050
+ }
2051
+
2052
+ /**
2053
+ * 检查订单是否需要手动同步
2054
+ *
2055
+ * 返回订单是否为纯代金券支付且待付金额<=0但未同步的状态
2056
+ */
2057
+ }, {
2058
+ key: "needsManualSync",
2059
+ value: function needsManualSync() {
2060
+ try {
2061
+ var _this$store$currentOr4;
2062
+ // 检查基础条件
2063
+ if (!this.store.currentOrder || this.store.isOrderSynced) {
2064
+ return false;
2065
+ }
2066
+
2067
+ // 检查是否支付完成(剩余金额<=0)
2068
+ var remainingAmount = this.calculateRemainingAmount();
2069
+ var remainingValue = parseFloat(remainingAmount);
2070
+ if (remainingValue > 0) {
2071
+ return false;
2072
+ }
2073
+
2074
+ // 检查是否所有支付项都带有 voucher_id
2075
+ var allPaymentsHaveVoucherId = this.store.currentOrder.payment && this.store.currentOrder.payment.length > 0 && this.store.currentOrder.payment.every(function (item) {
2076
+ return item.status !== 'voided' && item.voucher_id;
2077
+ });
2078
+ console.log('[Checkout] needsManualSync 检查结果:', {
2079
+ orderUuid: this.store.currentOrder.uuid,
2080
+ isOrderSynced: this.store.isOrderSynced,
2081
+ remainingAmount: remainingAmount,
2082
+ hasPayments: ((_this$store$currentOr4 = this.store.currentOrder.payment) === null || _this$store$currentOr4 === void 0 ? void 0 : _this$store$currentOr4.length) > 0,
2083
+ allPaymentsHaveVoucherId: allPaymentsHaveVoucherId,
2084
+ needsManualSync: allPaymentsHaveVoucherId
2085
+ });
2086
+ return allPaymentsHaveVoucherId;
2087
+ } catch (error) {
2088
+ console.error('[Checkout] needsManualSync 检查失败:', error);
2089
+ return false;
2090
+ }
2091
+ }
2092
+
2093
+ /**
2094
+ * 手动同步订单到后端
2095
+ *
2096
+ * 用于强制同步订单到后端,特别适用于纯代金券支付完成的订单
2097
+ */
2098
+ }, {
2099
+ key: "manualSyncOrderAsync",
2100
+ value: (function () {
2101
+ var _manualSyncOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
2102
+ var orderUuid, oldOrderId, realOrderId, finalOrderId, finalIsVirtual, _this$store$currentOr5, errorMessage;
2103
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2104
+ while (1) switch (_context27.prev = _context27.next) {
2105
+ case 0:
2106
+ _context27.prev = 0;
2107
+ if (this.store.currentOrder) {
2108
+ _context27.next = 3;
2109
+ break;
2110
+ }
2111
+ return _context27.abrupt("return", {
2112
+ success: false,
2113
+ message: '当前没有活跃订单,无法同步'
2114
+ });
2115
+ case 3:
2116
+ orderUuid = this.store.currentOrder.uuid;
2117
+ oldOrderId = this.store.currentOrder.order_id; // 检查订单是否已经同步
2118
+ if (this.store.isOrderSynced) {
2119
+ console.log('[Checkout] 订单已同步过,将执行更新操作');
2120
+ }
2121
+ console.log('[Checkout] 开始手动同步订单到后端:', {
2122
+ orderUuid: orderUuid,
2123
+ orderId: oldOrderId,
2124
+ totalAmount: this.store.currentOrder.total_amount,
2125
+ remainingAmount: this.calculateRemainingAmount()
2126
+ });
2127
+
2128
+ // 强制同步订单到后端,并获取真实订单ID
2129
+ _context27.next = 9;
2130
+ return this.syncOrderToBackendWithReturn(true);
2131
+ case 9:
2132
+ realOrderId = _context27.sent;
2133
+ console.log('[Checkout] 手动同步订单完成:', {
2134
+ orderUuid: orderUuid,
2135
+ oldOrderId: oldOrderId,
2136
+ realOrderId: realOrderId,
2137
+ isOrderSynced: this.store.isOrderSynced
2138
+ });
2139
+
2140
+ // 🔍 关键验证:检查最终状态是否正确
2141
+ finalOrderId = this.store.currentOrder.order_id;
2142
+ finalIsVirtual = this.isVirtualOrderId(finalOrderId);
2143
+ console.log('[Checkout] manualSyncOrderAsync 最终状态验证:', {
2144
+ 返回的订单ID: realOrderId,
2145
+ 存储的订单ID: finalOrderId,
2146
+ 存储的ID是否虚拟: finalIsVirtual,
2147
+ 是否一致: realOrderId === finalOrderId,
2148
+ 同步状态: this.store.isOrderSynced
2149
+ });
2150
+ if (finalIsVirtual) {
2151
+ console.error('[Checkout] 严重警告:手动同步完成后订单ID仍为虚拟ID!');
2152
+ }
2153
+ if (realOrderId !== finalOrderId) {
2154
+ console.error('[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!');
2155
+ }
2156
+ return _context27.abrupt("return", {
2157
+ success: true,
2158
+ message: '订单同步成功',
2159
+ orderId: realOrderId,
2160
+ // 直接返回从后端获取的真实订单ID
2161
+ orderUuid: orderUuid
2162
+ });
2163
+ case 19:
2164
+ _context27.prev = 19;
2165
+ _context27.t0 = _context27["catch"](0);
2166
+ console.error('[Checkout] 手动同步订单失败:', _context27.t0);
2167
+ errorMessage = _context27.t0 instanceof Error ? _context27.t0.message : '同步失败';
2168
+ return _context27.abrupt("return", {
2169
+ success: false,
2170
+ message: "\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(errorMessage),
2171
+ orderUuid: (_this$store$currentOr5 = this.store.currentOrder) === null || _this$store$currentOr5 === void 0 ? void 0 : _this$store$currentOr5.uuid
2172
+ });
2173
+ case 24:
2174
+ case "end":
2175
+ return _context27.stop();
2176
+ }
2177
+ }, _callee27, this, [[0, 19]]);
2178
+ }));
2179
+ function manualSyncOrderAsync() {
2180
+ return _manualSyncOrderAsync.apply(this, arguments);
2181
+ }
2182
+ return manualSyncOrderAsync;
2183
+ }()
2184
+ /**
2185
+ * 获取当前订单备注
2186
+ *
2187
+ * @returns 当前订单的备注内容,如果没有则返回空字符串
2188
+ */
2189
+ )
2190
+ }, {
2191
+ key: "getOrderNote",
2192
+ value: function getOrderNote() {
2193
+ if (!this.store.localOrderData) {
2194
+ console.log('[Checkout] 没有本地订单数据,无法获取备注');
2195
+ return '';
2196
+ }
2197
+ return this.store.localOrderData.shop_note || '';
2198
+ }
2199
+
2200
+ /**
2201
+ * 获取当前订单ID
2202
+ *
2203
+ * @returns 当前订单的ID,如果没有订单则返回null
2204
+ */
2205
+ }, {
2206
+ key: "getCurrentOrderId",
2207
+ value: function getCurrentOrderId() {
2208
+ if (!this.store.currentOrder) {
2209
+ return null;
2210
+ }
2211
+ return this.store.currentOrder.order_id;
2212
+ }
2213
+
2214
+ /**
2215
+ * 保存订单并稍后支付
2216
+ *
2217
+ * 将当前订单保存到后端,但排除代金券类支付项(voucher_id),
2218
+ * 适用于用户想要保存订单但稍后完成支付的场景
2219
+ */
2220
+ }, {
2221
+ key: "saveForLaterPaymentAsync",
2222
+ value: (function () {
2223
+ var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2224
+ var orderUuid, currentOrderId, allPaymentItems, filteredPaymentItems, voucherItems, realOrderId, finalOrderId, _this$store$currentOr6, errorMessage;
2225
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2226
+ while (1) switch (_context28.prev = _context28.next) {
2227
+ case 0:
2228
+ _context28.prev = 0;
2229
+ if (this.store.currentOrder) {
2230
+ _context28.next = 3;
2231
+ break;
2232
+ }
2233
+ return _context28.abrupt("return", {
2234
+ success: false,
2235
+ message: '当前没有活跃订单,无法保存'
2236
+ });
2237
+ case 3:
2238
+ orderUuid = this.store.currentOrder.uuid;
2239
+ currentOrderId = this.store.currentOrder.order_id;
2240
+ console.log('[Checkout] 开始保存订单并稍后支付:', {
2241
+ orderUuid: orderUuid,
2242
+ orderId: currentOrderId,
2243
+ totalAmount: this.store.currentOrder.total_amount
2244
+ });
2245
+
2246
+ // 获取当前订单的所有支付项
2247
+ _context28.next = 8;
2248
+ return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
2249
+ case 8:
2250
+ allPaymentItems = _context28.sent;
2251
+ // 过滤掉带有 voucher_id 的支付项(代金券类支付项)
2252
+ filteredPaymentItems = allPaymentItems.filter(function (payment) {
2253
+ return !payment.voucher_id || payment.voucher_id.trim() === '';
2254
+ }); // 记录过滤结果
2255
+ voucherItems = allPaymentItems.filter(function (payment) {
2256
+ return payment.voucher_id && payment.voucher_id.trim() !== '';
2257
+ });
2258
+ console.log('[Checkout] 支付项过滤结果:', {
2259
+ 总支付项: allPaymentItems.length,
2260
+ 过滤后支付项: filteredPaymentItems.length,
2261
+ 被过滤的代金券项: voucherItems.length,
2262
+ 代金券详情: voucherItems.map(function (item) {
2263
+ return {
2264
+ uuid: item.uuid,
2265
+ code: item.code,
2266
+ amount: item.amount,
2267
+ voucherId: item.voucher_id
2268
+ };
2269
+ }),
2270
+ 保留的支付项: filteredPaymentItems.map(function (item) {
2271
+ return {
2272
+ uuid: item.uuid,
2273
+ code: item.code,
2274
+ amount: item.amount
2275
+ };
2276
+ })
2277
+ });
2278
+
2279
+ // 调用同步方法,传入过滤后的支付项
2280
+ _context28.next = 14;
2281
+ return this.syncOrderToBackendWithReturn(false, filteredPaymentItems);
2282
+ case 14:
2283
+ realOrderId = _context28.sent;
2284
+ console.log('[Checkout] 保存订单完成:', {
2285
+ orderUuid: orderUuid,
2286
+ oldOrderId: currentOrderId,
2287
+ realOrderId: realOrderId,
2288
+ isOrderSynced: this.store.isOrderSynced,
2289
+ filteredPaymentsCount: filteredPaymentItems.length
2290
+ });
2291
+
2292
+ // 验证最终状态
2293
+ finalOrderId = this.store.currentOrder.order_id;
2294
+ console.log('[Checkout] saveForLaterPaymentAsync 最终状态验证:', {
2295
+ 返回的订单ID: realOrderId,
2296
+ 存储的订单ID: finalOrderId,
2297
+ 是否一致: realOrderId === finalOrderId,
2298
+ 同步状态: this.store.isOrderSynced
2299
+ });
2300
+ return _context28.abrupt("return", {
2301
+ success: true,
2302
+ message: '订单保存成功,可稍后继续支付',
2303
+ orderId: realOrderId,
2304
+ orderUuid: orderUuid
2305
+ });
2306
+ case 21:
2307
+ _context28.prev = 21;
2308
+ _context28.t0 = _context28["catch"](0);
2309
+ console.error('[Checkout] 保存订单失败:', _context28.t0);
2310
+ errorMessage = _context28.t0 instanceof Error ? _context28.t0.message : '保存失败';
2311
+ return _context28.abrupt("return", {
2312
+ success: false,
2313
+ message: "\u8BA2\u5355\u4FDD\u5B58\u5931\u8D25: ".concat(errorMessage),
2314
+ orderUuid: (_this$store$currentOr6 = this.store.currentOrder) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.uuid
2315
+ });
2316
+ case 26:
2317
+ case "end":
2318
+ return _context28.stop();
2319
+ }
2320
+ }, _callee28, this, [[0, 21]]);
2321
+ }));
2322
+ function saveForLaterPaymentAsync() {
2323
+ return _saveForLaterPaymentAsync.apply(this, arguments);
2324
+ }
2325
+ return saveForLaterPaymentAsync;
2326
+ }()
2327
+ /**
2328
+ * 获取当前商店折扣金额
2329
+ *
2330
+ * @returns 当前的商店折扣金额,如果没有则返回0
2331
+ */
2332
+ )
2333
+ }, {
2334
+ key: "getShopDiscount",
2335
+ value: function getShopDiscount() {
2336
+ var _this$store$localOrde;
2337
+ // 优先从 localOrderData 中获取
2338
+ if (((_this$store$localOrde = this.store.localOrderData) === null || _this$store$localOrde === void 0 ? void 0 : _this$store$localOrde.shop_discount) !== undefined) {
2339
+ return this.store.localOrderData.shop_discount;
2340
+ }
2341
+
2342
+ // 从 cartSummary 中查找 shop_discount 项
2343
+ if (this.store.cartSummary) {
2344
+ var shopDiscountItem = this.store.cartSummary.find(function (item) {
2345
+ return item.key === 'shop_discount';
2346
+ });
2347
+ if (shopDiscountItem) {
2348
+ return shopDiscountItem.value;
2349
+ }
2350
+ }
2351
+ return 0;
2352
+ }
2353
+
2354
+ /**
2355
+ * 更新订单商店折扣
2356
+ *
2357
+ * 同时更新cartSummary和localOrderData中的shop_discount值
2358
+ *
2359
+ * @param discountAmount 商店折扣金额
2360
+ */
2361
+ }, {
2362
+ key: "updateShopDiscountAsync",
2363
+ value: (function () {
2364
+ var _updateShopDiscountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(discountAmount) {
2365
+ var _this$store$currentOr7, _this$store$currentOr8, oldDiscount, shopDiscountItem, updatedAmountInfo;
2366
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2367
+ while (1) switch (_context29.prev = _context29.next) {
2368
+ case 0:
2369
+ _context29.prev = 0;
2370
+ oldDiscount = this.getShopDiscount();
2371
+ console.log('[Checkout] 更新商店折扣:', {
2372
+ orderUuid: (_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.uuid,
2373
+ oldDiscount: oldDiscount,
2374
+ newDiscount: discountAmount
2375
+ });
2376
+
2377
+ // 1. 更新 cartSummary 中的 shop_discount 项
2378
+ if (this.store.cartSummary) {
2379
+ shopDiscountItem = this.store.cartSummary.find(function (item) {
2380
+ return item.key === 'shop_discount';
2381
+ });
2382
+ if (shopDiscountItem) {
2383
+ shopDiscountItem.value = discountAmount;
2384
+ console.log('[Checkout] cartSummary 中的商店折扣已更新');
2385
+ } else {
2386
+ // 如果不存在,创建一个新的商店折扣项
2387
+ this.store.cartSummary.push({
2388
+ key: 'shop_discount',
2389
+ value: discountAmount,
2390
+ hidden: true,
2391
+ label: 'Shop Discount'
2392
+ });
2393
+ console.log('[Checkout] cartSummary 中已添加新的商店折扣项');
2394
+ }
2395
+ }
2396
+
2397
+ // 2. 更新 localOrderData 中的 shop_discount
2398
+ if (this.store.localOrderData) {
2399
+ this.store.localOrderData.shop_discount = discountAmount;
2400
+ console.log('[Checkout] localOrderData 中的商店折扣已更新');
2401
+ } else {
2402
+ console.warn('[Checkout] localOrderData 不存在,无法更新商店折扣');
2403
+ }
2404
+
2405
+ // 3. 如果有当前订单,可能需要重新计算订单金额
2406
+ if (this.store.currentOrder && this.store.cartSummary) {
2407
+ // 重新提取金额信息
2408
+ updatedAmountInfo = this.extractAmountFromCartSummary(this.store.cartSummary);
2409
+ console.log('[Checkout] 重新计算订单金额:', updatedAmountInfo);
2410
+
2411
+ // 更新订单的总金额等信息
2412
+ this.store.currentOrder.total_amount = updatedAmountInfo.totalAmount;
2413
+ this.store.currentOrder.expect_amount = updatedAmountInfo.totalAmount;
2414
+ }
2415
+
2416
+ // 4. 更新 stateAmount 为剩余未支付金额
2417
+ _context29.next = 8;
2418
+ return this.updateStateAmountToRemaining();
2419
+ case 8:
2420
+ _context29.next = 10;
2421
+ return this.core.effects.emit(CheckoutHooks.OnShopDiscountChanged, {
2422
+ orderUuid: (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.uuid,
2423
+ oldDiscount: oldDiscount,
2424
+ newDiscount: discountAmount,
2425
+ timestamp: Date.now()
2426
+ });
2427
+ case 10:
2428
+ console.log('[Checkout] 商店折扣更新成功:', {
2429
+ oldDiscount: oldDiscount,
2430
+ newDiscount: discountAmount
2431
+ });
2432
+ _context29.next = 19;
2433
+ break;
2434
+ case 13:
2435
+ _context29.prev = 13;
2436
+ _context29.t0 = _context29["catch"](0);
2437
+ console.error('[Checkout] 更新商店折扣失败:', _context29.t0);
2438
+ _context29.next = 18;
2439
+ return this.handleError(_context29.t0, CheckoutErrorType.ValidationFailed);
2440
+ case 18:
2441
+ throw _context29.t0;
2442
+ case 19:
2443
+ case "end":
2444
+ return _context29.stop();
2445
+ }
2446
+ }, _callee29, this, [[0, 13]]);
2447
+ }));
2448
+ function updateShopDiscountAsync(_x18) {
2449
+ return _updateShopDiscountAsync.apply(this, arguments);
2450
+ }
2451
+ return updateShopDiscountAsync;
2452
+ }()
2453
+ /**
2454
+ * 更新订单备注
2455
+ *
2456
+ * @param note 订单备注内容
2457
+ */
2458
+ )
2459
+ }, {
2460
+ key: "updateOrderNoteAsync",
2461
+ value: (function () {
2462
+ var _updateOrderNoteAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(note) {
2463
+ var _this$store$currentOr9, _this$store$currentOr10, oldNote, orderInPayment;
2464
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2465
+ while (1) switch (_context30.prev = _context30.next) {
2466
+ case 0:
2467
+ _context30.prev = 0;
2468
+ if (this.store.localOrderData) {
2469
+ _context30.next = 3;
2470
+ break;
2471
+ }
2472
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, '没有本地订单数据,无法更新备注');
2473
+ case 3:
2474
+ console.log('[Checkout] 更新订单备注:', {
2475
+ orderUuid: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.uuid,
2476
+ oldNote: this.store.localOrderData.shop_note,
2477
+ newNote: note
2478
+ });
2479
+
2480
+ // 更新备注
2481
+ oldNote = this.store.localOrderData.shop_note;
2482
+ this.store.localOrderData.shop_note = note;
2483
+
2484
+ // 如果有当前订单,也同步到Payment模块中的订单数据
2485
+ if (!this.store.currentOrder) {
2486
+ _context30.next = 17;
2487
+ break;
2488
+ }
2489
+ _context30.prev = 7;
2490
+ _context30.next = 10;
2491
+ return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
2492
+ case 10:
2493
+ orderInPayment = _context30.sent;
2494
+ if (orderInPayment && orderInPayment.note !== undefined) {
2495
+ // 使用Payment模块的更新方法(如果有的话)
2496
+ // 这里可能需要根据Payment模块的实际API来调整
2497
+ console.log('[Checkout] 同步备注到Payment模块的订单数据中');
2498
+ }
2499
+ _context30.next = 17;
2500
+ break;
2501
+ case 14:
2502
+ _context30.prev = 14;
2503
+ _context30.t0 = _context30["catch"](7);
2504
+ console.warn('[Checkout] 同步备注到Payment模块失败,但本地更新成功:', _context30.t0);
2505
+ case 17:
2506
+ _context30.next = 19;
2507
+ return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
2508
+ orderUuid: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.uuid,
2509
+ oldNote: oldNote,
2510
+ newNote: note,
2511
+ timestamp: Date.now()
2512
+ });
2513
+ case 19:
2514
+ console.log('[Checkout] 订单备注更新成功:', {
2515
+ oldNote: oldNote,
2516
+ newNote: note
2517
+ });
2518
+ _context30.next = 28;
2519
+ break;
2520
+ case 22:
2521
+ _context30.prev = 22;
2522
+ _context30.t1 = _context30["catch"](0);
2523
+ console.error('[Checkout] 更新订单备注失败:', _context30.t1);
2524
+ _context30.next = 27;
2525
+ return this.handleError(_context30.t1, CheckoutErrorType.ValidationFailed);
2526
+ case 27:
2527
+ throw _context30.t1;
2528
+ case 28:
2529
+ case "end":
2530
+ return _context30.stop();
2531
+ }
2532
+ }, _callee30, this, [[0, 22], [7, 14]]);
2533
+ }));
2534
+ function updateOrderNoteAsync(_x19) {
2535
+ return _updateOrderNoteAsync.apply(this, arguments);
2536
+ }
2537
+ return updateOrderNoteAsync;
2538
+ }()
2539
+ /**
2540
+ * 设置状态
2541
+ */
2542
+ )
2543
+ }, {
2544
+ key: "setStatus",
2545
+ value: (function () {
2546
+ var _setStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(status) {
2547
+ var oldStatus;
2548
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2549
+ while (1) switch (_context31.prev = _context31.next) {
2550
+ case 0:
2551
+ oldStatus = this.store.status;
2552
+ this.store.status = status;
2553
+ _context31.next = 4;
2554
+ return this.core.effects.emit(CheckoutHooks.OnStatusChanged, {
2555
+ oldStatus: oldStatus,
2556
+ newStatus: status,
2557
+ timestamp: Date.now()
2558
+ });
2559
+ case 4:
2560
+ case "end":
2561
+ return _context31.stop();
2562
+ }
2563
+ }, _callee31, this);
2564
+ }));
2565
+ function setStatus(_x20) {
2566
+ return _setStatus.apply(this, arguments);
2567
+ }
2568
+ return setStatus;
2569
+ }()
2570
+ /**
2571
+ * 设置步骤
2572
+ */
2573
+ )
2574
+ }, {
2575
+ key: "setStep",
2576
+ value: (function () {
2577
+ var _setStep = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(step) {
2578
+ var oldStep;
2579
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2580
+ while (1) switch (_context32.prev = _context32.next) {
2581
+ case 0:
2582
+ oldStep = this.store.step;
2583
+ this.store.step = step;
2584
+ _context32.next = 4;
2585
+ return this.core.effects.emit(CheckoutHooks.OnStepChanged, {
2586
+ oldStep: oldStep,
2587
+ newStep: step,
2588
+ timestamp: Date.now()
2589
+ });
2590
+ case 4:
2591
+ case "end":
2592
+ return _context32.stop();
2593
+ }
2594
+ }, _callee32, this);
2595
+ }));
2596
+ function setStep(_x21) {
2597
+ return _setStep.apply(this, arguments);
2598
+ }
2599
+ return setStep;
2600
+ }()
2601
+ /**
2602
+ * 处理错误
2603
+ */
2604
+ )
2605
+ }, {
2606
+ key: "handleError",
2607
+ value: (function () {
2608
+ var _handleError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(error, type) {
2609
+ var checkoutError;
2610
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2611
+ while (1) switch (_context33.prev = _context33.next) {
2612
+ case 0:
2613
+ checkoutError = error instanceof Error && 'type' in error ? error : createCheckoutError(type, error.message, error);
2614
+ this.store.lastError = checkoutError;
2615
+ _context33.next = 4;
2616
+ return this.setStatus(CheckoutStatus.Error);
2617
+ case 4:
2618
+ _context33.next = 6;
2619
+ return this.core.effects.emit(CheckoutHooks.OnError, {
2620
+ error: checkoutError,
2621
+ context: {
2622
+ status: this.store.status,
2623
+ step: this.store.step
2624
+ },
2625
+ timestamp: Date.now()
2626
+ });
2627
+ case 6:
2628
+ console.error('[Checkout] 错误:', checkoutError);
2629
+ case 7:
2630
+ case "end":
2631
+ return _context33.stop();
2632
+ }
2633
+ }, _callee33, this);
2634
+ }));
2635
+ function handleError(_x22, _x23) {
2636
+ return _handleError.apply(this, arguments);
2637
+ }
2638
+ return handleError;
2639
+ }()
2640
+ /**
2641
+ * 处理支付成功
2642
+ */
2643
+ )
2644
+ }, {
2645
+ key: "handlePaymentSuccess",
2646
+ value: (function () {
2647
+ var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(data) {
2648
+ var _this$store$currentOr11;
2649
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2650
+ while (1) switch (_context34.prev = _context34.next) {
2651
+ case 0:
2652
+ _context34.next = 2;
2653
+ return this.setStatus(CheckoutStatus.PaymentCompleted);
2654
+ case 2:
2655
+ _context34.next = 4;
2656
+ return this.updateStateAmountToRemaining();
2657
+ case 4:
2658
+ _context34.next = 6;
1268
2659
  return this.core.effects.emit(CheckoutHooks.OnPaymentSuccess, {
1269
2660
  orderUuid: data.orderUuid,
1270
2661
  paymentMethodCode: '',
1271
- amount: ((_this$store$currentOr4 = this.store.currentOrder) === null || _this$store$currentOr4 === void 0 ? void 0 : _this$store$currentOr4.total_amount) || '0',
2662
+ amount: ((_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.total_amount) || '0',
1272
2663
  timestamp: data.timestamp
1273
2664
  });
1274
- case 4:
1275
- _context21.next = 6;
1276
- return this.completeCheckoutAsync();
1277
2665
  case 6:
2666
+ _context34.next = 8;
2667
+ return this.completeCheckoutAsync();
2668
+ case 8:
1278
2669
  case "end":
1279
- return _context21.stop();
2670
+ return _context34.stop();
1280
2671
  }
1281
- }, _callee21, this);
2672
+ }, _callee34, this);
1282
2673
  }));
1283
- function handlePaymentSuccess(_x16) {
2674
+ function handlePaymentSuccess(_x24) {
1284
2675
  return _handlePaymentSuccess.apply(this, arguments);
1285
2676
  }
1286
2677
  return handlePaymentSuccess;
@@ -1292,30 +2683,30 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1292
2683
  }, {
1293
2684
  key: "handlePaymentError",
1294
2685
  value: (function () {
1295
- var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(data) {
1296
- var _this$store$currentOr5;
2686
+ var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(data) {
2687
+ var _this$store$currentOr12;
1297
2688
  var error;
1298
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1299
- while (1) switch (_context22.prev = _context22.next) {
2689
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2690
+ while (1) switch (_context35.prev = _context35.next) {
1300
2691
  case 0:
1301
2692
  error = createCheckoutError(CheckoutErrorType.PaymentFailed, data.error || '支付同步失败');
1302
- _context22.next = 3;
2693
+ _context35.next = 3;
1303
2694
  return this.handleError(error instanceof Error ? error : new Error(String(error)), CheckoutErrorType.PaymentFailed);
1304
2695
  case 3:
1305
- _context22.next = 5;
2696
+ _context35.next = 5;
1306
2697
  return this.core.effects.emit(CheckoutHooks.OnPaymentFailed, {
1307
2698
  orderUuid: data.orderUuid,
1308
2699
  paymentMethodCode: '',
1309
- amount: ((_this$store$currentOr5 = this.store.currentOrder) === null || _this$store$currentOr5 === void 0 ? void 0 : _this$store$currentOr5.total_amount) || '0',
2700
+ amount: ((_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.total_amount) || '0',
1310
2701
  timestamp: data.timestamp
1311
2702
  });
1312
2703
  case 5:
1313
2704
  case "end":
1314
- return _context22.stop();
2705
+ return _context35.stop();
1315
2706
  }
1316
- }, _callee22, this);
2707
+ }, _callee35, this);
1317
2708
  }));
1318
- function handlePaymentError(_x17) {
2709
+ function handlePaymentError(_x25) {
1319
2710
  return _handlePaymentError.apply(this, arguments);
1320
2711
  }
1321
2712
  return handlePaymentError;
@@ -1327,18 +2718,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1327
2718
  }, {
1328
2719
  key: "validateCheckoutParams",
1329
2720
  value: (function () {
1330
- var _validateCheckoutParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
1331
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1332
- while (1) switch (_context23.prev = _context23.next) {
2721
+ var _validateCheckoutParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
2722
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
2723
+ while (1) switch (_context36.prev = _context36.next) {
1333
2724
  case 0:
1334
- return _context23.abrupt("return", validateCheckoutData(params));
2725
+ return _context36.abrupt("return", validateCheckoutData(params));
1335
2726
  case 1:
1336
2727
  case "end":
1337
- return _context23.stop();
2728
+ return _context36.stop();
1338
2729
  }
1339
- }, _callee23);
2730
+ }, _callee36);
1340
2731
  }));
1341
- function validateCheckoutParams(_x18) {
2732
+ function validateCheckoutParams(_x26) {
1342
2733
  return _validateCheckoutParams.apply(this, arguments);
1343
2734
  }
1344
2735
  return validateCheckoutParams;
@@ -1350,10 +2741,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1350
2741
  }, {
1351
2742
  key: "validateLocalOrderData",
1352
2743
  value: (function () {
1353
- var _validateLocalOrderData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orderData) {
2744
+ var _validateLocalOrderData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(orderData) {
1354
2745
  var errors;
1355
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1356
- while (1) switch (_context24.prev = _context24.next) {
2746
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
2747
+ while (1) switch (_context37.prev = _context37.next) {
1357
2748
  case 0:
1358
2749
  errors = []; // 验证基本字段
1359
2750
  if (!orderData.type) {
@@ -1380,17 +2771,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1380
2771
  }
1381
2772
  });
1382
2773
  }
1383
- return _context24.abrupt("return", {
2774
+ return _context37.abrupt("return", {
1384
2775
  valid: errors.length === 0,
1385
2776
  errors: errors
1386
2777
  });
1387
2778
  case 6:
1388
2779
  case "end":
1389
- return _context24.stop();
2780
+ return _context37.stop();
1390
2781
  }
1391
- }, _callee24);
2782
+ }, _callee37);
1392
2783
  }));
1393
- function validateLocalOrderData(_x19) {
2784
+ function validateLocalOrderData(_x27) {
1394
2785
  return _validateLocalOrderData.apply(this, arguments);
1395
2786
  }
1396
2787
  return validateLocalOrderData;
@@ -1407,6 +2798,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1407
2798
  return "local_order_".concat(timestamp, "_").concat(random);
1408
2799
  }
1409
2800
 
2801
+ /**
2802
+ * 格式化日期时间为 YYYY-MM-DD hh:mm:ss 格式
2803
+ *
2804
+ * @param date 要格式化的日期对象
2805
+ * @returns 格式化后的日期时间字符串
2806
+ */
2807
+ }, {
2808
+ key: "formatDateTime",
2809
+ value: function formatDateTime(date) {
2810
+ var year = date.getFullYear();
2811
+ var month = String(date.getMonth() + 1).padStart(2, '0');
2812
+ var day = String(date.getDate()).padStart(2, '0');
2813
+ var hours = String(date.getHours()).padStart(2, '0');
2814
+ var minutes = String(date.getMinutes()).padStart(2, '0');
2815
+ var seconds = String(date.getSeconds()).padStart(2, '0');
2816
+ return "".concat(year, "-").concat(month, "-").concat(day, " ").concat(hours, ":").concat(minutes, ":").concat(seconds);
2817
+ }
2818
+
1410
2819
  /**
1411
2820
  * 从购物车小计数据中提取金额信息
1412
2821
  */
@@ -1470,31 +2879,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1470
2879
  }, {
1471
2880
  key: "preloadPaymentMethods",
1472
2881
  value: (function () {
1473
- var _preloadPaymentMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2882
+ var _preloadPaymentMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38() {
1474
2883
  var methods;
1475
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1476
- while (1) switch (_context25.prev = _context25.next) {
2884
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
2885
+ while (1) switch (_context38.prev = _context38.next) {
1477
2886
  case 0:
1478
- _context25.prev = 0;
2887
+ _context38.prev = 0;
1479
2888
  console.log('[Checkout] 预加载支付方式...');
1480
- _context25.next = 4;
1481
- return this.store.payment.getPayMethodListAsync();
2889
+ _context38.next = 4;
2890
+ return this.payment.getPayMethodListAsync();
1482
2891
  case 4:
1483
- methods = _context25.sent;
2892
+ methods = _context38.sent;
1484
2893
  this.store.paymentMethods = methods;
1485
2894
  console.log("[Checkout] \u9884\u52A0\u8F7D\u5B8C\u6210\uFF0C\u5171 ".concat(methods.length, " \u79CD\u652F\u4ED8\u65B9\u5F0F"));
1486
- _context25.next = 13;
2895
+ _context38.next = 13;
1487
2896
  break;
1488
2897
  case 9:
1489
- _context25.prev = 9;
1490
- _context25.t0 = _context25["catch"](0);
1491
- console.error('[Checkout] 预加载支付方式失败:', _context25.t0);
2898
+ _context38.prev = 9;
2899
+ _context38.t0 = _context38["catch"](0);
2900
+ console.error('[Checkout] 预加载支付方式失败:', _context38.t0);
1492
2901
  this.store.paymentMethods = [];
1493
2902
  case 13:
1494
2903
  case "end":
1495
- return _context25.stop();
2904
+ return _context38.stop();
1496
2905
  }
1497
- }, _callee25, this, [[0, 9]]);
2906
+ }, _callee38, this, [[0, 9]]);
1498
2907
  }));
1499
2908
  function preloadPaymentMethods() {
1500
2909
  return _preloadPaymentMethods.apply(this, arguments);
@@ -1522,13 +2931,599 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1522
2931
  }, {
1523
2932
  key: "calculatePaidAmount",
1524
2933
  value: function calculatePaidAmount() {
1525
- if (!this.store.currentOrder) return '0.00';
1526
- var paidAmount = this.store.currentOrder.payment.reduce(function (sum, payment) {
1527
- return sum + parseFloat(payment.amount);
2934
+ if (!this.store.currentOrder) {
2935
+ console.log('[Checkout] calculatePaidAmount: 没有当前订单');
2936
+ return '0.00';
2937
+ }
2938
+ var payments = this.store.currentOrder.payment || [];
2939
+ console.log('[Checkout] calculatePaidAmount: 支付项详情:', {
2940
+ paymentCount: payments.length,
2941
+ payments: payments.map(function (p) {
2942
+ return {
2943
+ uuid: p.uuid,
2944
+ amount: p.amount,
2945
+ code: p.code,
2946
+ status: p.status
2947
+ };
2948
+ })
2949
+ });
2950
+ var paidAmount = payments.filter(function (payment) {
2951
+ return payment.status !== 'voided';
2952
+ }) // 只计算未撤销的支付项
2953
+ .reduce(function (sum, payment) {
2954
+ var amount = parseFloat(payment.amount || '0');
2955
+ console.log("[Checkout] \u8BA1\u7B97\u652F\u4ED8\u9879: ".concat(payment.code, " = ").concat(amount));
2956
+ return sum + amount;
1528
2957
  }, 0);
1529
- return paidAmount.toFixed(2);
2958
+ var result = paidAmount.toFixed(2);
2959
+ console.log('[Checkout] calculatePaidAmount: 计算结果 =', result);
2960
+ return result;
2961
+ }
2962
+
2963
+ /**
2964
+ * 计算剩余未支付金额
2965
+ */
2966
+ }, {
2967
+ key: "calculateRemainingAmount",
2968
+ value: function calculateRemainingAmount() {
2969
+ if (!this.store.currentOrder) {
2970
+ console.log('[Checkout] calculateRemainingAmount: 没有当前订单');
2971
+ return '0.00';
2972
+ }
2973
+ var totalAmount = parseFloat(this.store.currentOrder.total_amount || '0');
2974
+ var paidAmount = parseFloat(this.calculatePaidAmount());
2975
+ var remainingAmount = totalAmount - paidAmount;
2976
+ var result = Math.max(0, remainingAmount).toFixed(2);
2977
+ console.log('[Checkout] calculateRemainingAmount: 计算详情:', {
2978
+ orderUuid: this.store.currentOrder.uuid,
2979
+ totalAmount: totalAmount.toFixed(2),
2980
+ paidAmount: paidAmount.toFixed(2),
2981
+ calculatedRemaining: remainingAmount.toFixed(2),
2982
+ finalResult: result
2983
+ });
2984
+ return result;
2985
+ }
2986
+
2987
+ /**
2988
+ * 更新 stateAmount 为当前剩余未支付金额
2989
+ */
2990
+ }, {
2991
+ key: "updateStateAmountToRemaining",
2992
+ value: (function () {
2993
+ var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
2994
+ var _this$store$currentOr13, remainingAmount, currentStateAmount;
2995
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
2996
+ while (1) switch (_context39.prev = _context39.next) {
2997
+ case 0:
2998
+ _context39.prev = 0;
2999
+ remainingAmount = this.calculateRemainingAmount();
3000
+ currentStateAmount = this.store.stateAmount;
3001
+ console.log('[Checkout] updateStateAmountToRemaining: 状态检查:', {
3002
+ calculatedRemainingAmount: remainingAmount,
3003
+ currentStateAmount: currentStateAmount,
3004
+ needsUpdate: remainingAmount !== currentStateAmount,
3005
+ orderUuid: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.uuid
3006
+ });
3007
+
3008
+ // 只有当剩余金额与当前 stateAmount 不同时才更新
3009
+ if (!(remainingAmount !== currentStateAmount)) {
3010
+ _context39.next = 11;
3011
+ break;
3012
+ }
3013
+ this.store.stateAmount = remainingAmount;
3014
+
3015
+ // 发出 stateAmount 变更事件
3016
+ _context39.next = 8;
3017
+ return this.core.effects.emit(CheckoutHooks.OnStateAmountChanged, {
3018
+ oldAmount: currentStateAmount,
3019
+ newAmount: remainingAmount,
3020
+ timestamp: Date.now()
3021
+ });
3022
+ case 8:
3023
+ console.log('[Checkout] stateAmount 已自动更新为剩余金额:', {
3024
+ oldAmount: currentStateAmount,
3025
+ newAmount: remainingAmount
3026
+ });
3027
+ _context39.next = 12;
3028
+ break;
3029
+ case 11:
3030
+ console.log('[Checkout] stateAmount 无需更新,当前值已是最新:', {
3031
+ stateAmount: currentStateAmount,
3032
+ remainingAmount: remainingAmount
3033
+ });
3034
+ case 12:
3035
+ _context39.next = 14;
3036
+ return this.checkOrderPaymentCompletion();
3037
+ case 14:
3038
+ _context39.next = 19;
3039
+ break;
3040
+ case 16:
3041
+ _context39.prev = 16;
3042
+ _context39.t0 = _context39["catch"](0);
3043
+ console.error('[Checkout] 更新 stateAmount 为剩余金额失败:', _context39.t0);
3044
+ case 19:
3045
+ case "end":
3046
+ return _context39.stop();
3047
+ }
3048
+ }, _callee39, this, [[0, 16]]);
3049
+ }));
3050
+ function updateStateAmountToRemaining() {
3051
+ return _updateStateAmountToRemaining.apply(this, arguments);
3052
+ }
3053
+ return updateStateAmountToRemaining;
3054
+ }()
3055
+ /**
3056
+ * 检查订单支付是否完成
3057
+ *
3058
+ * 当剩余待付款金额 <= 0 时,触发订单支付完成事件
3059
+ */
3060
+ )
3061
+ }, {
3062
+ key: "checkOrderPaymentCompletion",
3063
+ value: (function () {
3064
+ var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40() {
3065
+ var remainingAmount, remainingValue, _this$store$currentOr14, _this$store$currentOr15, totalAmount, paidAmount, allPaymentsHaveVoucherId;
3066
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3067
+ while (1) switch (_context40.prev = _context40.next) {
3068
+ case 0:
3069
+ _context40.prev = 0;
3070
+ if (this.store.currentOrder) {
3071
+ _context40.next = 3;
3072
+ break;
3073
+ }
3074
+ return _context40.abrupt("return");
3075
+ case 3:
3076
+ remainingAmount = this.calculateRemainingAmount();
3077
+ remainingValue = parseFloat(remainingAmount); // 当剩余金额小于等于0时,认为订单已完成支付
3078
+ if (!(remainingValue <= 0)) {
3079
+ _context40.next = 21;
3080
+ break;
3081
+ }
3082
+ totalAmount = this.store.currentOrder.total_amount;
3083
+ paidAmount = this.calculatePaidAmount();
3084
+ console.log('[Checkout] 检测到订单支付完成:', {
3085
+ orderUuid: this.store.currentOrder.uuid,
3086
+ orderId: this.store.currentOrder.order_id,
3087
+ totalAmount: totalAmount,
3088
+ paidAmount: paidAmount,
3089
+ remainingAmount: remainingAmount,
3090
+ isOrderSynced: this.store.isOrderSynced
3091
+ });
3092
+
3093
+ // 检查是否所有支付项都带有 voucher_id
3094
+ allPaymentsHaveVoucherId = this.store.currentOrder.payment && this.store.currentOrder.payment.length > 0 && this.store.currentOrder.payment.every(function (item) {
3095
+ return item.status !== 'voided' && item.voucher_id;
3096
+ });
3097
+ console.log('[Checkout] 支付项voucher_id检查:', {
3098
+ paymentCount: ((_this$store$currentOr14 = this.store.currentOrder.payment) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.length) || 0,
3099
+ allHaveVoucherId: allPaymentsHaveVoucherId,
3100
+ paymentItems: (_this$store$currentOr15 = this.store.currentOrder.payment) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.map(function (p) {
3101
+ return {
3102
+ uuid: p.uuid,
3103
+ code: p.code,
3104
+ amount: p.amount,
3105
+ voucher_id: p.voucher_id,
3106
+ status: p.status
3107
+ };
3108
+ })
3109
+ });
3110
+
3111
+ // 如果支付完成但订单未同步,需要判断是否同步
3112
+ if (this.store.isOrderSynced) {
3113
+ _context40.next = 19;
3114
+ break;
3115
+ }
3116
+ if (!allPaymentsHaveVoucherId) {
3117
+ _context40.next = 16;
3118
+ break;
3119
+ }
3120
+ console.log('[Checkout] 所有支付项均为代金券类型,跳过订单同步');
3121
+ _context40.next = 19;
3122
+ break;
3123
+ case 16:
3124
+ console.log('[Checkout] 支付完成但订单未同步,开始同步订单到后端...');
3125
+ _context40.next = 19;
3126
+ return this.syncOrderToBackend();
3127
+ case 19:
3128
+ _context40.next = 21;
3129
+ return this.core.effects.emit(CheckoutHooks.OnOrderPaymentCompleted, {
3130
+ orderUuid: this.store.currentOrder.uuid,
3131
+ orderId: this.store.currentOrder.order_id,
3132
+ totalAmount: totalAmount,
3133
+ paidAmount: paidAmount,
3134
+ remainingAmount: remainingAmount,
3135
+ timestamp: Date.now()
3136
+ });
3137
+ case 21:
3138
+ _context40.next = 26;
3139
+ break;
3140
+ case 23:
3141
+ _context40.prev = 23;
3142
+ _context40.t0 = _context40["catch"](0);
3143
+ console.error('[Checkout] 检查订单支付完成状态失败:', _context40.t0);
3144
+ case 26:
3145
+ case "end":
3146
+ return _context40.stop();
3147
+ }
3148
+ }, _callee40, this, [[0, 23]]);
3149
+ }));
3150
+ function checkOrderPaymentCompletion() {
3151
+ return _checkOrderPaymentCompletion.apply(this, arguments);
3152
+ }
3153
+ return checkOrderPaymentCompletion;
3154
+ }()
3155
+ /**
3156
+ * 判断支付方式是否需要同步订单到后端
3157
+ *
3158
+ * 现金支付(CASHMANUAL)和自定义支付不需要同步,其他支付方式需要同步
3159
+ *
3160
+ * @param paymentCode 支付方式代码
3161
+ * @param paymentType 支付方式类型
3162
+ * @returns 是否需要同步订单
3163
+ */
3164
+ )
3165
+ }, {
3166
+ key: "shouldSyncOrderForPayment",
3167
+ value: function shouldSyncOrderForPayment(paymentCode, paymentType) {
3168
+ var codeUpper = (paymentCode === null || paymentCode === void 0 ? void 0 : paymentCode.toUpperCase()) || '';
3169
+ var typeUpper = (paymentType === null || paymentType === void 0 ? void 0 : paymentType.toUpperCase()) || '';
3170
+
3171
+ // 现金支付不需要同步 - 支持多种现金支付识别方式
3172
+ var cashIdentifiers = ['CASHMANUAL', 'CASH', 'MANUAL'];
3173
+ if (cashIdentifiers.some(function (id) {
3174
+ return codeUpper.includes(id) || typeUpper.includes(id);
3175
+ })) {
3176
+ return false;
3177
+ }
3178
+
3179
+ // 标准现金支付代码检查
3180
+ if (paymentCode === PaymentMethodType.Cash || paymentType === PaymentMethodType.Cash) {
3181
+ return false;
3182
+ }
3183
+
3184
+ // 自定义支付不需要同步
3185
+ if (codeUpper.includes('CUSTOM') || typeUpper.includes('CUSTOM')) {
3186
+ return false;
3187
+ }
3188
+
3189
+ // 其他支付方式都需要同步
3190
+ return true;
3191
+ }
3192
+
3193
+ /**
3194
+ * 同步订单到后端
3195
+ *
3196
+ * 调用后端 /order/checkout 接口创建真实订单
3197
+ */
3198
+ /**
3199
+ * 判断订单ID是否为本地生成的虚拟ID
3200
+ *
3201
+ * @param orderId 订单ID
3202
+ * @returns true 表示是虚拟ID,false 表示是真实的后端ID
3203
+ */
3204
+ }, {
3205
+ key: "isVirtualOrderId",
3206
+ value: function isVirtualOrderId(orderId) {
3207
+ return orderId.startsWith('local_order_');
1530
3208
  }
1531
3209
 
3210
+ /**
3211
+ * 同步订单到后端并返回真实订单ID
3212
+ *
3213
+ * @param isManual 是否为手动同步,默认为 false
3214
+ * @param customPaymentItems 自定义支付项列表,如果提供则使用此列表而不是从数据库获取
3215
+ * @returns 后端返回的真实订单ID
3216
+ */
3217
+ }, {
3218
+ key: "syncOrderToBackendWithReturn",
3219
+ value: (function () {
3220
+ var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
3221
+ var _this$store$currentCu2, _this$store$currentOr16, _this$store$currentOr17;
3222
+ var isManual,
3223
+ customPaymentItems,
3224
+ syncType,
3225
+ currentOrderId,
3226
+ hasRealOrderId,
3227
+ isUpdateOperation,
3228
+ reason,
3229
+ operation,
3230
+ paymentItems,
3231
+ orderParams,
3232
+ checkoutResponse,
3233
+ realOrderId,
3234
+ _data3,
3235
+ extractedOrderId,
3236
+ updatedOrder,
3237
+ beforeManualUpdate,
3238
+ finalOrderId,
3239
+ finalIsVirtual,
3240
+ _args41 = arguments;
3241
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3242
+ while (1) switch (_context41.prev = _context41.next) {
3243
+ case 0:
3244
+ isManual = _args41.length > 0 && _args41[0] !== undefined ? _args41[0] : false;
3245
+ customPaymentItems = _args41.length > 1 ? _args41[1] : undefined;
3246
+ if (!(!this.store.localOrderData || !this.store.currentOrder)) {
3247
+ _context41.next = 4;
3248
+ break;
3249
+ }
3250
+ throw new Error('缺少必要的订单数据,无法同步到后端');
3251
+ case 4:
3252
+ syncType = isManual ? '手动' : '自动'; // 判断是创建订单还是更新订单
3253
+ currentOrderId = this.store.currentOrder.order_id;
3254
+ hasRealOrderId = currentOrderId && !this.isVirtualOrderId(currentOrderId); // 更准确的判断:优先考虑同步状态
3255
+ // 1. 如果订单已经同步过,无论订单ID是什么,都应该是更新操作(防止ID被意外重置)
3256
+ // 2. 如果订单未同步但有真实订单ID,也认为是更新操作
3257
+ // 3. 其他情况都是创建操作
3258
+ isUpdateOperation = false;
3259
+ reason = '';
3260
+ if (this.store.isOrderSynced) {
3261
+ isUpdateOperation = true;
3262
+ reason = '订单已同步过';
3263
+ } else if (hasRealOrderId) {
3264
+ isUpdateOperation = true;
3265
+ reason = '有真实订单ID';
3266
+ } else {
3267
+ isUpdateOperation = false;
3268
+ reason = '既未同步也无真实ID';
3269
+ }
3270
+ operation = isUpdateOperation ? '更新' : '创建';
3271
+ console.log('[Checkout] 操作类型判断详情:', {
3272
+ currentOrderId: currentOrderId,
3273
+ hasRealOrderId: hasRealOrderId,
3274
+ isOrderSynced: this.store.isOrderSynced,
3275
+ isManual: isManual,
3276
+ reason: reason,
3277
+ finalDecision: operation
3278
+ });
3279
+ console.log("[Checkout] \u5F00\u59CB".concat(syncType).concat(operation, "\u8BA2\u5355\u5230\u540E\u7AEF..."), {
3280
+ currentOrderId: currentOrderId,
3281
+ isVirtualId: this.isVirtualOrderId(currentOrderId || ''),
3282
+ operation: operation,
3283
+ orderUuid: this.store.currentOrder.uuid,
3284
+ isOrderSynced: this.store.isOrderSynced
3285
+ });
3286
+
3287
+ // 获取当前订单的支付项
3288
+ _context41.t0 = customPaymentItems;
3289
+ if (_context41.t0) {
3290
+ _context41.next = 18;
3291
+ break;
3292
+ }
3293
+ _context41.next = 17;
3294
+ return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
3295
+ case 17:
3296
+ _context41.t0 = _context41.sent;
3297
+ case 18:
3298
+ paymentItems = _context41.t0;
3299
+ console.log('[Checkout] 获取到支付项:', {
3300
+ count: paymentItems.length,
3301
+ isCustomFiltered: !!customPaymentItems,
3302
+ methods: paymentItems.map(function (p) {
3303
+ return p.code;
3304
+ }),
3305
+ totalAmount: paymentItems.reduce(function (sum, p) {
3306
+ return sum + parseFloat(p.amount);
3307
+ }, 0).toFixed(2),
3308
+ paymentDetails: paymentItems.map(function (p) {
3309
+ var _p$metadata;
3310
+ return {
3311
+ uuid: p.uuid,
3312
+ code: p.code,
3313
+ amount: p.amount,
3314
+ uniquePaymentNumber: (_p$metadata = p.metadata) === null || _p$metadata === void 0 ? void 0 : _p$metadata.unique_payment_number,
3315
+ voucherId: p.voucher_id
3316
+ };
3317
+ })
3318
+ });
3319
+
3320
+ // 构造订单参数,直接使用 localOrderData 中已处理好的数据
3321
+ orderParams = _objectSpread(_objectSpread({}, this.store.localOrderData), {}, {
3322
+ type: this.store.localOrderData.type,
3323
+ platform: this.store.localOrderData.platform,
3324
+ payments: paymentItems,
3325
+ // 添加支付项
3326
+ customer_id: (_this$store$currentCu2 = this.store.currentCustomer) === null || _this$store$currentCu2 === void 0 ? void 0 : _this$store$currentCu2.customer_id,
3327
+ // 添加客户ID
3328
+ is_price_include_tax: this.otherParams.is_price_include_tax,
3329
+ // core 有
3330
+ tax_title: this.otherParams.tax_title,
3331
+ // core 没有
3332
+ tax_rate: this.otherParams.tax_rate,
3333
+ // core 有
3334
+ tax_country_code: this.otherParams.tax_country_code,
3335
+ // core 没有
3336
+ currency_code: this.otherParams.currency_code,
3337
+ currency_symbol: this.otherParams.currency_symbol,
3338
+ currency_format: this.otherParams.currency_format,
3339
+ is_deposit: ((_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.is_deposit) || 0,
3340
+ deposit_amount: ((_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.deposit_amount) || '0.00',
3341
+ // surcharge_fee: this.otherParams.surcharge_fee,
3342
+ // surcharges: ,
3343
+ note: this.store.localOrderData.shop_note
3344
+ // deposit_amount:
3345
+ }); // 如果是更新操作,需要在参数中包含真实的订单ID
3346
+
3347
+ if (isUpdateOperation) {
3348
+ // 如果当前订单ID是虚拟ID,但订单已同步过,可能存在数据不一致的问题
3349
+ if (this.isVirtualOrderId(currentOrderId)) {
3350
+ console.error('[Checkout] 数据不一致警告:更新操作但订单ID仍为虚拟ID!', {
3351
+ currentOrderId: currentOrderId,
3352
+ isOrderSynced: this.store.isOrderSynced,
3353
+ reason: reason,
3354
+ orderUuid: this.store.currentOrder.uuid
3355
+ });
3356
+
3357
+ // 🔧 尝试数据修复:先不包含order_id,让后端创建
3358
+ // 这样至少能保证功能正常,后续会正确设置真实订单ID
3359
+ console.log('[Checkout] 尝试数据修复:暂时不包含order_id,让后端处理');
3360
+ console.log('[Checkout] 注意:这次调用将作为创建操作处理,但后续会修复数据一致性');
3361
+ } else {
3362
+ orderParams.order_id = currentOrderId;
3363
+ console.log("[Checkout] \u66F4\u65B0\u8BA2\u5355\u64CD\u4F5C\uFF0C\u5305\u542B\u8BA2\u5355ID: ".concat(currentOrderId));
3364
+ }
3365
+ } else {
3366
+ console.log('[Checkout] 创建新订单操作');
3367
+ }
3368
+
3369
+ // 调用 Order 模块的专用 createOrderByCheckout 方法
3370
+ _context41.next = 24;
3371
+ return this.order.createOrderByCheckout(orderParams);
3372
+ case 24:
3373
+ checkoutResponse = _context41.sent;
3374
+ console.log('[Checkout] 后端返回的响应数据:', {
3375
+ status: checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.status,
3376
+ code: checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.code,
3377
+ message: checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.message,
3378
+ data: checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.data
3379
+ });
3380
+ if (!isUpdateOperation) {
3381
+ _context41.next = 31;
3382
+ break;
3383
+ }
3384
+ // 更新操作:使用现有的订单ID
3385
+ realOrderId = currentOrderId;
3386
+ console.log("[Checkout] \u8BA2\u5355\u66F4\u65B0\u6210\u529F\uFF0C\u8BA2\u5355ID: ".concat(realOrderId));
3387
+ _context41.next = 52;
3388
+ break;
3389
+ case 31:
3390
+ // 创建操作:从响应中提取新的订单ID
3391
+ extractedOrderId = checkoutResponse === null || checkoutResponse === void 0 || (_data3 = checkoutResponse.data) === null || _data3 === void 0 ? void 0 : _data3.order_id; // 如果data.order_id不存在,尝试直接从根级获取
3392
+ if (!extractedOrderId) {
3393
+ extractedOrderId = checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.order_id;
3394
+ }
3395
+
3396
+ // 确保转换为字符串类型
3397
+ if (extractedOrderId !== undefined && extractedOrderId !== null) {
3398
+ extractedOrderId = String(extractedOrderId);
3399
+ }
3400
+ if (extractedOrderId) {
3401
+ _context41.next = 36;
3402
+ break;
3403
+ }
3404
+ throw new Error('后端返回的订单信息中未包含订单ID');
3405
+ case 36:
3406
+ realOrderId = extractedOrderId;
3407
+ console.log('[Checkout] 订单创建成功,真实订单ID:', realOrderId);
3408
+
3409
+ // 替换虚拟订单ID为真实订单ID
3410
+ console.log('[Checkout] 准备替换订单ID:', {
3411
+ orderUuid: this.store.currentOrder.uuid,
3412
+ oldOrderId: this.store.currentOrder.order_id,
3413
+ newOrderId: realOrderId
3414
+ });
3415
+ _context41.prev = 39;
3416
+ _context41.next = 42;
3417
+ return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, realOrderId);
3418
+ case 42:
3419
+ updatedOrder = _context41.sent;
3420
+ console.log('[Checkout] Payment模块替换订单ID结果:', {
3421
+ wasSuccessful: !!updatedOrder,
3422
+ returnedOrderId: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.order_id,
3423
+ expectedOrderId: realOrderId
3424
+ });
3425
+ if (updatedOrder) {
3426
+ console.log('[Checkout] Payment模块返回的更新后订单:', {
3427
+ uuid: updatedOrder.uuid,
3428
+ orderId: updatedOrder.order_id,
3429
+ totalAmount: updatedOrder.total_amount
3430
+ });
3431
+ this.store.currentOrder = updatedOrder;
3432
+ console.log('[Checkout] 订单ID替换成功,当前订单ID:', this.store.currentOrder.order_id);
3433
+ } else {
3434
+ console.error('[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换');
3435
+
3436
+ // 如果替换失败,手动更新订单ID
3437
+ beforeManualUpdate = this.store.currentOrder.order_id;
3438
+ this.store.currentOrder.order_id = realOrderId;
3439
+ console.log('[Checkout] 手动设置订单ID:', {
3440
+ 替换前: beforeManualUpdate,
3441
+ 替换后: this.store.currentOrder.order_id,
3442
+ 目标ID: realOrderId
3443
+ });
3444
+ }
3445
+ _context41.next = 52;
3446
+ break;
3447
+ case 47:
3448
+ _context41.prev = 47;
3449
+ _context41.t1 = _context41["catch"](39);
3450
+ console.error('[Checkout] 调用Payment模块替换订单ID时发生错误:', _context41.t1);
3451
+
3452
+ // 发生错误时也进行手动替换
3453
+ this.store.currentOrder.order_id = realOrderId;
3454
+ console.log('[Checkout] 错误恢复:手动设置订单ID:', realOrderId);
3455
+ case 52:
3456
+ // 标记订单已同步
3457
+ this.store.isOrderSynced = true;
3458
+
3459
+ // 触发订单同步完成事件
3460
+ _context41.next = 55;
3461
+ return this.core.effects.emit(CheckoutHooks.OnOrderSynced, {
3462
+ orderUuid: this.store.currentOrder.uuid,
3463
+ realOrderId: realOrderId,
3464
+ virtualOrderId: this.store.currentOrder.order_id,
3465
+ timestamp: Date.now(),
3466
+ isManual: isManual
3467
+ });
3468
+ case 55:
3469
+ // 验证最终状态
3470
+ finalOrderId = this.store.currentOrder.order_id;
3471
+ finalIsVirtual = this.isVirtualOrderId(finalOrderId || '');
3472
+ console.log("[Checkout] ".concat(syncType).concat(operation, "\u8BA2\u5355\u5230\u540E\u7AEF\u5B8C\u6210"), {
3473
+ 返回的订单ID: realOrderId,
3474
+ 当前存储的订单ID: finalOrderId,
3475
+ 是否还是虚拟ID: finalIsVirtual,
3476
+ 是否同步: this.store.isOrderSynced
3477
+ });
3478
+
3479
+ // 如果最终状态不正确,发出警告
3480
+ if (finalIsVirtual && !isUpdateOperation) {
3481
+ console.warn('[Checkout] 警告:订单创建后,当前订单ID仍然是虚拟ID,可能存在问题');
3482
+ }
3483
+
3484
+ // 返回真实订单ID
3485
+ return _context41.abrupt("return", realOrderId);
3486
+ case 60:
3487
+ case "end":
3488
+ return _context41.stop();
3489
+ }
3490
+ }, _callee41, this, [[39, 47]]);
3491
+ }));
3492
+ function syncOrderToBackendWithReturn() {
3493
+ return _syncOrderToBackendWithReturn.apply(this, arguments);
3494
+ }
3495
+ return syncOrderToBackendWithReturn;
3496
+ }())
3497
+ }, {
3498
+ key: "syncOrderToBackend",
3499
+ value: function () {
3500
+ var _syncOrderToBackend = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42() {
3501
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3502
+ while (1) switch (_context42.prev = _context42.next) {
3503
+ case 0:
3504
+ _context42.prev = 0;
3505
+ _context42.next = 3;
3506
+ return this.syncOrderToBackendWithReturn(false);
3507
+ case 3:
3508
+ _context42.next = 10;
3509
+ break;
3510
+ case 5:
3511
+ _context42.prev = 5;
3512
+ _context42.t0 = _context42["catch"](0);
3513
+ console.error('[Checkout] 同步订单到后端失败:', _context42.t0);
3514
+ _context42.next = 10;
3515
+ return this.handleError(new Error("\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context42.t0 instanceof Error ? _context42.t0.message : String(_context42.t0))), CheckoutErrorType.OrderCreationFailed);
3516
+ case 10:
3517
+ case "end":
3518
+ return _context42.stop();
3519
+ }
3520
+ }, _callee42, this, [[0, 5]]);
3521
+ }));
3522
+ function syncOrderToBackend() {
3523
+ return _syncOrderToBackend.apply(this, arguments);
3524
+ }
3525
+ return syncOrderToBackend;
3526
+ }()
1532
3527
  /**
1533
3528
  * 获取状态消息
1534
3529
  */
@@ -1559,32 +3554,63 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1559
3554
  return '';
1560
3555
  }
1561
3556
  }
3557
+ }, {
3558
+ key: "setOtherParams",
3559
+ value: function () {
3560
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
3561
+ var _ref3,
3562
+ _ref3$cover,
3563
+ cover,
3564
+ _args43 = arguments;
3565
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3566
+ while (1) switch (_context43.prev = _context43.next) {
3567
+ case 0:
3568
+ _ref3 = _args43.length > 1 && _args43[1] !== undefined ? _args43[1] : {}, _ref3$cover = _ref3.cover, cover = _ref3$cover === void 0 ? false : _ref3$cover;
3569
+ if (cover) {
3570
+ this.otherParams = params;
3571
+ } else {
3572
+ this.otherParams = _objectSpread(_objectSpread({}, this.otherParams), params);
3573
+ }
3574
+ case 2:
3575
+ case "end":
3576
+ return _context43.stop();
3577
+ }
3578
+ }, _callee43, this);
3579
+ }));
3580
+ function setOtherParams(_x28) {
3581
+ return _setOtherParams.apply(this, arguments);
3582
+ }
3583
+ return setOtherParams;
3584
+ }()
1562
3585
  }, {
1563
3586
  key: "destroy",
1564
3587
  value: function () {
1565
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
1566
- var _this$store$order, _this$store$order$des, _this$store$payment, _this$store$payment$d;
1567
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
1568
- while (1) switch (_context26.prev = _context26.next) {
3588
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44() {
3589
+ var _this$order, _this$order$destroy, _this$payment, _this$payment$destroy;
3590
+ return _regeneratorRuntime().wrap(function _callee44$(_context44) {
3591
+ while (1) switch (_context44.prev = _context44.next) {
1569
3592
  case 0:
3593
+ // 清理钱包模块的所有缓存数据
3594
+ this.payment.wallet.clearAllCache();
3595
+
1570
3596
  // 清理事件监听
1571
3597
  this.core.effects.offByModuleDestroy(this.name);
1572
3598
 
1573
3599
  // 销毁子模块
1574
- _context26.next = 3;
1575
- return (_this$store$order = this.store.order) === null || _this$store$order === void 0 || (_this$store$order$des = _this$store$order.destroy) === null || _this$store$order$des === void 0 ? void 0 : _this$store$order$des.call(_this$store$order);
1576
- case 3:
1577
- _context26.next = 5;
1578
- return (_this$store$payment = this.store.payment) === null || _this$store$payment === void 0 || (_this$store$payment$d = _this$store$payment.destroy) === null || _this$store$payment$d === void 0 ? void 0 : _this$store$payment$d.call(_this$store$payment);
1579
- case 5:
3600
+ _context44.next = 4;
3601
+ 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);
3602
+ case 4:
3603
+ _context44.next = 6;
3604
+ 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);
3605
+ case 6:
1580
3606
  // 取消注册模块
1581
3607
  this.core.unregisterModule(this);
1582
3608
  console.log('[Checkout] 已销毁');
1583
- case 7:
3609
+ case 8:
1584
3610
  case "end":
1585
- return _context26.stop();
3611
+ return _context44.stop();
1586
3612
  }
1587
- }, _callee26, this);
3613
+ }, _callee44, this);
1588
3614
  }));
1589
3615
  function destroy() {
1590
3616
  return _destroy.apply(this, arguments);