@pisell/pisellos 0.0.230 → 0.0.232

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 +93 -1
  3. package/dist/modules/Order/types.d.ts +45 -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 +254 -2
  23. package/dist/solution/Checkout/index.js +2472 -320
  24. package/dist/solution/Checkout/types.d.ts +207 -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 +65 -1
  28. package/lib/modules/Order/types.d.ts +45 -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 +254 -2
  47. package/lib/solution/Checkout/index.js +1361 -39
  48. package/lib/solution/Checkout/types.d.ts +207 -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,
@@ -890,43 +987,52 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
890
987
  }
891
988
  return refreshPaymentMethodsAsync;
892
989
  }()
990
+ /**
991
+ * 获取订单原始数据
992
+ */
993
+ )
994
+ }, {
995
+ key: "getOrderOriginalData",
996
+ value: function getOrderOriginalData() {
997
+ var _this$store$currentOr4;
998
+ return (_this$store$currentOr4 = this.store.currentOrder) === null || _this$store$currentOr4 === void 0 ? void 0 : _this$store$currentOr4.order_info;
999
+ }
1000
+
893
1001
  /**
894
1002
  * 获取当前订单基础信息
895
1003
  *
896
1004
  * 返回当前订单的基础信息,包括订单状态、金额、支付状态等
897
1005
  */
898
- )
899
1006
  }, {
900
1007
  key: "getCurrentOrderInfo",
901
1008
  value: function getCurrentOrderInfo() {
902
1009
  try {
903
- var _localOrderData$platf;
904
1010
  var _this$store = this.store,
905
- currentOrder = _this$store.currentOrder,
1011
+ _currentOrder = _this$store.currentOrder,
906
1012
  status = _this$store.status,
907
1013
  step = _this$store.step,
908
1014
  cartItems = _this$store.cartItems,
909
1015
  localOrderData = _this$store.localOrderData;
910
- if (!currentOrder) {
1016
+ if (!_currentOrder) {
911
1017
  console.log('[Checkout] 当前没有活跃订单');
912
1018
  return null;
913
1019
  }
914
1020
 
915
1021
  // 从本地订单数据或订单信息中提取基础信息
916
- var orderInfo = currentOrder.order_info || {};
1022
+ var orderInfo = _currentOrder.order_info || {};
917
1023
  var createdAt = orderInfo.created_at || new Date().toISOString();
918
1024
  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';
1025
+ var platform = (localOrderData === null || localOrderData === void 0 ? void 0 : localOrderData.platform) || orderInfo.platform || 'pc';
920
1026
  var result = {
921
- uuid: currentOrder.uuid,
922
- orderId: currentOrder.order_id,
1027
+ uuid: _currentOrder.uuid,
1028
+ orderId: _currentOrder.order_id,
923
1029
  status: status,
924
1030
  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,
1031
+ totalAmount: _currentOrder.total_amount,
1032
+ remainingAmount: _currentOrder.expect_amount,
1033
+ paymentStatus: _currentOrder.payment_status,
1034
+ isDeposit: Boolean(_currentOrder.is_deposit),
1035
+ depositAmount: _currentOrder.deposit_amount,
930
1036
  orderType: orderType,
931
1037
  platform: platform,
932
1038
  createdAt: createdAt,
@@ -947,16 +1053,90 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
947
1053
  }
948
1054
  }
949
1055
 
1056
+ /**
1057
+ * 获取当前订单的支付项
1058
+ *
1059
+ * 返回当前订单的所有支付项,包括活跃和已撤销的支付项
1060
+ */
1061
+ }, {
1062
+ key: "getCurrentOrderPaymentItemsAsync",
1063
+ value: (function () {
1064
+ var _getCurrentOrderPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1065
+ var _currentOrder2, paymentItems;
1066
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1067
+ while (1) switch (_context15.prev = _context15.next) {
1068
+ case 0:
1069
+ _context15.prev = 0;
1070
+ _currentOrder2 = this.store.currentOrder;
1071
+ if (_currentOrder2) {
1072
+ _context15.next = 5;
1073
+ break;
1074
+ }
1075
+ console.log('[Checkout] 当前没有活跃订单,无法获取支付项');
1076
+ return _context15.abrupt("return", []);
1077
+ case 5:
1078
+ console.log('[Checkout] 获取当前订单支付项:', {
1079
+ orderUuid: _currentOrder2.uuid,
1080
+ orderId: _currentOrder2.order_id
1081
+ });
1082
+
1083
+ // 调用Payment模块获取支付项
1084
+ _context15.next = 8;
1085
+ return this.payment.getPaymentItemsAsync(_currentOrder2.uuid);
1086
+ case 8:
1087
+ paymentItems = _context15.sent;
1088
+ console.log('[Checkout] 成功获取支付项:', {
1089
+ orderUuid: _currentOrder2.uuid,
1090
+ paymentItemCount: paymentItems.length,
1091
+ activeItems: paymentItems.filter(function (item) {
1092
+ return item.status !== 'voided';
1093
+ }).length,
1094
+ voidedItems: paymentItems.filter(function (item) {
1095
+ return item.status === 'voided';
1096
+ }).length,
1097
+ totalPaidAmount: paymentItems.filter(function (item) {
1098
+ return item.status !== 'voided';
1099
+ }).reduce(function (sum, item) {
1100
+ return sum + parseFloat(item.amount || '0');
1101
+ }, 0).toFixed(2),
1102
+ paymentMethods: paymentItems.map(function (item) {
1103
+ return {
1104
+ uuid: item.uuid,
1105
+ code: item.code,
1106
+ amount: item.amount,
1107
+ status: item.status,
1108
+ voucher_id: item.voucher_id
1109
+ };
1110
+ })
1111
+ });
1112
+ return _context15.abrupt("return", paymentItems);
1113
+ case 13:
1114
+ _context15.prev = 13;
1115
+ _context15.t0 = _context15["catch"](0);
1116
+ console.error('[Checkout] 获取当前订单支付项失败:', _context15.t0);
1117
+ return _context15.abrupt("return", []);
1118
+ case 17:
1119
+ case "end":
1120
+ return _context15.stop();
1121
+ }
1122
+ }, _callee15, this, [[0, 13]]);
1123
+ }));
1124
+ function getCurrentOrderPaymentItemsAsync() {
1125
+ return _getCurrentOrderPaymentItemsAsync.apply(this, arguments);
1126
+ }
1127
+ return getCurrentOrderPaymentItemsAsync;
1128
+ }()
950
1129
  /**
951
1130
  * 验证结账前置条件
952
1131
  */
1132
+ )
953
1133
  }, {
954
1134
  key: "validateCheckoutAsync",
955
1135
  value: (function () {
956
- var _validateCheckoutAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1136
+ var _validateCheckoutAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
957
1137
  var errors;
958
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
959
- while (1) switch (_context15.prev = _context15.next) {
1138
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1139
+ while (1) switch (_context16.prev = _context16.next) {
960
1140
  case 0:
961
1141
  errors = []; // 验证购物车
962
1142
  if (!this.store.cartItems || this.store.cartItems.length === 0) {
@@ -972,15 +1152,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
972
1152
  if (this.store.status === CheckoutStatus.Error) {
973
1153
  errors.push('结账流程存在错误');
974
1154
  }
975
- return _context15.abrupt("return", {
1155
+ return _context16.abrupt("return", {
976
1156
  valid: errors.length === 0,
977
1157
  errors: errors
978
1158
  });
979
1159
  case 5:
980
1160
  case "end":
981
- return _context15.stop();
1161
+ return _context16.stop();
982
1162
  }
983
- }, _callee15, this);
1163
+ }, _callee16, this);
984
1164
  }));
985
1165
  function validateCheckoutAsync() {
986
1166
  return _validateCheckoutAsync.apply(this, arguments);
@@ -994,53 +1174,44 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
994
1174
  }, {
995
1175
  key: "retryFailedOperationAsync",
996
1176
  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) {
1177
+ var _retryFailedOperationAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1178
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1179
+ while (1) switch (_context17.prev = _context17.next) {
1000
1180
  case 0:
1001
- _context16.prev = 0;
1181
+ _context17.prev = 0;
1002
1182
  if (!(this.store.status === CheckoutStatus.Error && this.store.lastError)) {
1003
- _context16.next = 14;
1183
+ _context17.next = 10;
1004
1184
  break;
1005
1185
  }
1006
- _context16.t0 = this.store.lastError.type;
1007
- _context16.next = _context16.t0 === CheckoutErrorType.OrderCreationFailed ? 5 : _context16.t0 === CheckoutErrorType.PaymentFailed ? 9 : 13;
1186
+ _context17.t0 = this.store.lastError.type;
1187
+ _context17.next = _context17.t0 === CheckoutErrorType.OrderCreationFailed ? 5 : 9;
1008
1188
  break;
1009
1189
  case 5:
1010
1190
  if (!(this.store.cartItems.length > 0)) {
1011
- _context16.next = 8;
1191
+ _context17.next = 8;
1012
1192
  break;
1013
1193
  }
1014
- _context16.next = 8;
1194
+ _context17.next = 8;
1015
1195
  return this.createOrderAsync({
1016
1196
  cartItems: this.store.cartItems
1017
1197
  });
1018
1198
  case 8:
1019
- return _context16.abrupt("break", 14);
1199
+ return _context17.abrupt("break", 10);
1020
1200
  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
1201
  console.warn('[Checkout] 无法重试此类型的错误:', this.store.lastError.type);
1031
- case 14:
1032
- _context16.next = 20;
1202
+ case 10:
1203
+ _context17.next = 16;
1033
1204
  break;
1205
+ case 12:
1206
+ _context17.prev = 12;
1207
+ _context17.t1 = _context17["catch"](0);
1208
+ _context17.next = 16;
1209
+ return this.handleError(_context17.t1, CheckoutErrorType.UnknownError);
1034
1210
  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
1211
  case "end":
1041
- return _context16.stop();
1212
+ return _context17.stop();
1042
1213
  }
1043
- }, _callee16, this, [[0, 16]]);
1214
+ }, _callee17, this, [[0, 12]]);
1044
1215
  }));
1045
1216
  function retryFailedOperationAsync() {
1046
1217
  return _retryFailedOperationAsync.apply(this, arguments);
@@ -1069,7 +1240,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1069
1240
  }, {
1070
1241
  key: "getOrderModule",
1071
1242
  value: function getOrderModule() {
1072
- return this.store.order;
1243
+ return this.order;
1073
1244
  }
1074
1245
 
1075
1246
  /**
@@ -1078,7 +1249,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1078
1249
  }, {
1079
1250
  key: "getPaymentModule",
1080
1251
  value: function getPaymentModule() {
1081
- return this.store.payment;
1252
+ return this.payment;
1082
1253
  }
1083
1254
 
1084
1255
  /**
@@ -1092,32 +1263,32 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1092
1263
  }, {
1093
1264
  key: "replaceLocalOrderIdAsync",
1094
1265
  value: (function () {
1095
- var _replaceLocalOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(newOrderId) {
1266
+ var _replaceLocalOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(newOrderId) {
1096
1267
  var updatedOrder;
1097
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1098
- while (1) switch (_context17.prev = _context17.next) {
1268
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1269
+ while (1) switch (_context18.prev = _context18.next) {
1099
1270
  case 0:
1100
- _context17.prev = 0;
1271
+ _context18.prev = 0;
1101
1272
  if (this.store.currentOrder) {
1102
- _context17.next = 4;
1273
+ _context18.next = 4;
1103
1274
  break;
1104
1275
  }
1105
1276
  console.warn('[Checkout] 没有当前订单,无法替换订单ID');
1106
- return _context17.abrupt("return", null);
1277
+ return _context18.abrupt("return", null);
1107
1278
  case 4:
1108
- _context17.next = 6;
1109
- return this.store.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, newOrderId);
1279
+ _context18.next = 6;
1280
+ return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, newOrderId);
1110
1281
  case 6:
1111
- updatedOrder = _context17.sent;
1282
+ updatedOrder = _context18.sent;
1112
1283
  if (!updatedOrder) {
1113
- _context17.next = 12;
1284
+ _context18.next = 15;
1114
1285
  break;
1115
1286
  }
1116
1287
  // 更新当前订单引用
1117
1288
  this.store.currentOrder = updatedOrder;
1118
1289
 
1119
1290
  // 触发订单更新事件
1120
- _context17.next = 11;
1291
+ _context18.next = 11;
1121
1292
  return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
1122
1293
  order: updatedOrder,
1123
1294
  timestamp: Date.now()
@@ -1127,21 +1298,28 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1127
1298
  uuid: updatedOrder.uuid,
1128
1299
  newOrderId: updatedOrder.id
1129
1300
  });
1130
- case 12:
1131
- return _context17.abrupt("return", updatedOrder);
1301
+
1302
+ // 标记订单已同步(替换ID意味着订单已在后端创建)
1303
+ this.store.isOrderSynced = true;
1304
+
1305
+ // 订单ID替换后更新 stateAmount
1306
+ _context18.next = 15;
1307
+ return this.updateStateAmountToRemaining();
1132
1308
  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:
1309
+ return _context18.abrupt("return", updatedOrder);
1310
+ case 18:
1311
+ _context18.prev = 18;
1312
+ _context18.t0 = _context18["catch"](0);
1313
+ console.error('[Checkout] 替换订单ID失败:', _context18.t0);
1314
+ _context18.next = 23;
1315
+ return this.handleError(_context18.t0, CheckoutErrorType.UnknownError);
1316
+ case 23:
1317
+ return _context18.abrupt("return", null);
1318
+ case 24:
1141
1319
  case "end":
1142
- return _context17.stop();
1320
+ return _context18.stop();
1143
1321
  }
1144
- }, _callee17, this, [[0, 15]]);
1322
+ }, _callee18, this, [[0, 18]]);
1145
1323
  }));
1146
1324
  function replaceLocalOrderIdAsync(_x11) {
1147
1325
  return _replaceLocalOrderIdAsync.apply(this, arguments);
@@ -1149,138 +1327,1361 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1149
1327
  return replaceLocalOrderIdAsync;
1150
1328
  }()
1151
1329
  /**
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
- * 设置步骤
1330
+ * 设置自定义支付金额
1331
+ *
1332
+ * 允许UI自定义本次支付的金额,通常用于部分支付或调整支付金额场景
1333
+ *
1334
+ * @param amount 自定义支付金额,必须是有效的数字字符串
1184
1335
  */
1185
1336
  )
1186
1337
  }, {
1187
- key: "setStep",
1338
+ key: "setStateAmountAsync",
1188
1339
  value: (function () {
1189
- var _setStep = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(step) {
1190
- var oldStep;
1340
+ var _setStateAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(amount) {
1341
+ var numAmount, oldAmount, formattedAmount, errorMessage;
1191
1342
  return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1192
1343
  while (1) switch (_context19.prev = _context19.next) {
1193
1344
  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,
1345
+ _context19.prev = 0;
1346
+ // 验证金额格式
1347
+ numAmount = parseFloat(amount);
1348
+ if (!(isNaN(numAmount) || numAmount < 0)) {
1349
+ _context19.next = 4;
1350
+ break;
1351
+ }
1352
+ throw new Error("\u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: ".concat(amount));
1353
+ case 4:
1354
+ oldAmount = this.store.stateAmount;
1355
+ formattedAmount = numAmount.toFixed(2); // 如果金额没有变化,直接返回
1356
+ if (!(oldAmount === formattedAmount)) {
1357
+ _context19.next = 8;
1358
+ break;
1359
+ }
1360
+ return _context19.abrupt("return");
1361
+ case 8:
1362
+ // 更新状态
1363
+ this.store.stateAmount = formattedAmount;
1364
+
1365
+ // 触发金额变更事件
1366
+ _context19.next = 11;
1367
+ return this.core.effects.emit(CheckoutHooks.OnStateAmountChanged, {
1368
+ oldAmount: oldAmount,
1369
+ newAmount: formattedAmount,
1200
1370
  timestamp: Date.now()
1201
1371
  });
1202
- case 4:
1372
+ case 11:
1373
+ console.log('[Checkout] 自定义支付金额已更新:', {
1374
+ oldAmount: oldAmount,
1375
+ newAmount: formattedAmount
1376
+ });
1377
+ _context19.next = 21;
1378
+ break;
1379
+ case 14:
1380
+ _context19.prev = 14;
1381
+ _context19.t0 = _context19["catch"](0);
1382
+ errorMessage = _context19.t0 instanceof Error ? _context19.t0.message : '设置支付金额失败';
1383
+ console.error('[Checkout] 设置自定义支付金额失败:', errorMessage);
1384
+ _context19.next = 20;
1385
+ return this.handleError(new Error(errorMessage), CheckoutErrorType.ValidationFailed);
1386
+ case 20:
1387
+ throw _context19.t0;
1388
+ case 21:
1203
1389
  case "end":
1204
1390
  return _context19.stop();
1205
1391
  }
1206
- }, _callee19, this);
1392
+ }, _callee19, this, [[0, 14]]);
1207
1393
  }));
1208
- function setStep(_x13) {
1209
- return _setStep.apply(this, arguments);
1394
+ function setStateAmountAsync(_x12) {
1395
+ return _setStateAmountAsync.apply(this, arguments);
1210
1396
  }
1211
- return setStep;
1397
+ return setStateAmountAsync;
1212
1398
  }()
1213
1399
  /**
1214
- * 处理错误
1400
+ * 获取当前自定义支付金额
1401
+ *
1402
+ * @returns 当前设置的自定义支付金额
1215
1403
  */
1216
1404
  )
1217
1405
  }, {
1218
- key: "handleError",
1406
+ key: "getStateAmount",
1407
+ value: function getStateAmount() {
1408
+ return this.store.stateAmount;
1409
+ }
1410
+
1411
+ /**
1412
+ * 刷新 stateAmount 为当前剩余未支付金额
1413
+ *
1414
+ * UI 可以调用此方法来主动刷新支付金额状态
1415
+ */
1416
+ }, {
1417
+ key: "refreshStateAmountAsync",
1219
1418
  value: (function () {
1220
- var _handleError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(error, type) {
1221
- var checkoutError;
1419
+ var _refreshStateAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1222
1420
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1223
1421
  while (1) switch (_context20.prev = _context20.next) {
1224
1422
  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:
1423
+ _context20.next = 2;
1424
+ return this.updateStateAmountToRemaining();
1425
+ case 2:
1242
1426
  case "end":
1243
1427
  return _context20.stop();
1244
1428
  }
1245
1429
  }, _callee20, this);
1246
1430
  }));
1247
- function handleError(_x14, _x15) {
1248
- return _handleError.apply(this, arguments);
1431
+ function refreshStateAmountAsync() {
1432
+ return _refreshStateAmountAsync.apply(this, arguments);
1249
1433
  }
1250
- return handleError;
1434
+ return refreshStateAmountAsync;
1251
1435
  }()
1252
1436
  /**
1253
- * 处理支付成功
1437
+ * 获取购物车小计数据
1438
+ *
1439
+ * 返回当前结账流程中的购物车小计项数据,包含各种费用明细
1440
+ *
1441
+ * @returns 购物车小计数据数组,如果没有则返回 null
1254
1442
  */
1255
1443
  )
1256
1444
  }, {
1257
- key: "handlePaymentSuccess",
1258
- value: (function () {
1259
- var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(data) {
1260
- var _this$store$currentOr4;
1261
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1262
- while (1) switch (_context21.prev = _context21.next) {
1263
- case 0:
1264
- _context21.next = 2;
1265
- return this.setStatus(CheckoutStatus.PaymentCompleted);
1266
- case 2:
1267
- _context21.next = 4;
1268
- return this.core.effects.emit(CheckoutHooks.OnPaymentSuccess, {
1269
- orderUuid: data.orderUuid,
1270
- paymentMethodCode: '',
1271
- amount: ((_this$store$currentOr4 = this.store.currentOrder) === null || _this$store$currentOr4 === void 0 ? void 0 : _this$store$currentOr4.total_amount) || '0',
1272
- timestamp: data.timestamp
1273
- });
1274
- case 4:
1275
- _context21.next = 6;
1276
- return this.completeCheckoutAsync();
1445
+ key: "getCartSummary",
1446
+ value: function getCartSummary() {
1447
+ if (!this.store.cartSummary || this.store.cartSummary.length === 0) {
1448
+ console.warn('[Checkout] 没有可用的购物车小计数据');
1449
+ return null;
1450
+ }
1451
+ console.log('[Checkout] 获取购物车小计数据:', {
1452
+ itemCount: this.store.cartSummary.length,
1453
+ items: this.store.cartSummary.map(function (item) {
1454
+ return {
1455
+ key: item.key,
1456
+ value: item.value,
1457
+ label: item.label
1458
+ };
1459
+ })
1460
+ });
1461
+ return _toConsumableArray(this.store.cartSummary); // 返回副本,避免外部修改
1462
+ }
1463
+
1464
+ /**
1465
+ * 获取提取的金额详细信息
1466
+ *
1467
+ * 从当前的购物车小计数据中提取结构化的金额信息
1468
+ *
1469
+ * @returns 提取的金额信息对象,如果没有小计数据则返回 null
1470
+ */
1471
+ }, {
1472
+ key: "getExtractedAmountInfo",
1473
+ value: function getExtractedAmountInfo() {
1474
+ if (!this.store.cartSummary || this.store.cartSummary.length === 0) {
1475
+ console.warn('[Checkout] 没有可用的购物车小计数据,无法提取金额信息');
1476
+ return null;
1477
+ }
1478
+ var extractedInfo = this.extractAmountFromCartSummary(this.store.cartSummary);
1479
+ console.log('[Checkout] 获取提取的金额信息:', extractedInfo);
1480
+ return extractedInfo;
1481
+ }
1482
+
1483
+ /**
1484
+ * 获取支付方式列表
1485
+ *
1486
+ * 直接调用 Payment 模块的 getPayMethodListAsync 方法
1487
+ *
1488
+ * @returns 支付方式列表
1489
+ */
1490
+ }, {
1491
+ key: "getPaymentMethodsAsync",
1492
+ value: (function () {
1493
+ var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1494
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1495
+ while (1) switch (_context21.prev = _context21.next) {
1496
+ case 0:
1497
+ _context21.next = 2;
1498
+ return this.payment.getPayMethodListAsync();
1499
+ case 2:
1500
+ return _context21.abrupt("return", _context21.sent);
1501
+ case 3:
1502
+ case "end":
1503
+ return _context21.stop();
1504
+ }
1505
+ }, _callee21, this);
1506
+ }));
1507
+ function getPaymentMethodsAsync() {
1508
+ return _getPaymentMethodsAsync.apply(this, arguments);
1509
+ }
1510
+ return getPaymentMethodsAsync;
1511
+ }()
1512
+ /**
1513
+ * 为当前订单添加支付项
1514
+ *
1515
+ * 向当前活跃订单添加一个支付项,支付项包含支付方式信息和金额
1516
+ *
1517
+ * @param paymentItem 支付项数据
1518
+ * @throws 当前没有活跃订单时抛出错误
1519
+ */
1520
+ )
1521
+ }, {
1522
+ key: "addPaymentItemAsync",
1523
+ value: (function () {
1524
+ var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(paymentItem) {
1525
+ var currentOrderId, isCurrentOrderReal, updatedOrder, needsOrderSync;
1526
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1527
+ while (1) switch (_context22.prev = _context22.next) {
1528
+ case 0:
1529
+ _context22.prev = 0;
1530
+ if (this.store.currentOrder) {
1531
+ _context22.next = 3;
1532
+ break;
1533
+ }
1534
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法添加支付项');
1535
+ case 3:
1536
+ console.log('[Checkout] 为当前订单添加支付项:', {
1537
+ orderUuid: this.store.currentOrder.uuid,
1538
+ paymentItem: {
1539
+ code: paymentItem.code,
1540
+ name: paymentItem.name,
1541
+ type: paymentItem.type,
1542
+ amount: paymentItem.amount,
1543
+ service_charge: paymentItem.service_charge
1544
+ }
1545
+ });
1546
+
1547
+ // 添加支付项到订单
1548
+ _context22.next = 6;
1549
+ return this.payment.addPaymentItemAsync(this.store.currentOrder.uuid, paymentItem);
1550
+ case 6:
1551
+ console.log('[Checkout] 支付项添加成功');
1552
+
1553
+ // 重新从Payment模块获取最新的订单数据,确保支付项同步
1554
+ currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1555
+ isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
1556
+ console.log('[Checkout] 准备同步订单数据:', {
1557
+ 当前订单ID: currentOrderId,
1558
+ 是否为真实ID: isCurrentOrderReal
1559
+ });
1560
+ _context22.next = 12;
1561
+ return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1562
+ case 12:
1563
+ updatedOrder = _context22.sent;
1564
+ if (updatedOrder) {
1565
+ // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
1566
+ if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
1567
+ console.warn('[Checkout] 检测到订单ID回退,保护真实订单ID:', {
1568
+ 当前真实ID: currentOrderId,
1569
+ 获取到的虚拟ID: updatedOrder.order_id
1570
+ });
1571
+ updatedOrder.order_id = currentOrderId; // 恢复真实的订单ID
1572
+ }
1573
+ this.store.currentOrder = updatedOrder;
1574
+ console.log('[Checkout] 订单数据已同步:', {
1575
+ 支付项数量: updatedOrder.payment.length,
1576
+ 最终订单ID: updatedOrder.order_id,
1577
+ 是否为虚拟ID: this.isVirtualOrderId(updatedOrder.order_id)
1578
+ });
1579
+ }
1580
+
1581
+ // 检查是否需要同步订单到后端
1582
+ needsOrderSync = this.shouldSyncOrderForPayment(paymentItem.code, paymentItem.type);
1583
+ console.log('[Checkout] 支付项同步检查:', {
1584
+ paymentCode: paymentItem.code,
1585
+ paymentType: paymentItem.type,
1586
+ paymentAmount: paymentItem.amount,
1587
+ expectedCashCode: PaymentMethodType.Cash,
1588
+ needsOrderSync: needsOrderSync,
1589
+ isOrderSynced: this.store.isOrderSynced
1590
+ });
1591
+ if (!needsOrderSync) {
1592
+ _context22.next = 21;
1593
+ break;
1594
+ }
1595
+ console.log('[Checkout] 检测到非现金/自定义支付,开始同步订单到后端...', {
1596
+ 同步前订单ID: this.store.currentOrder.order_id,
1597
+ 是否为虚拟ID: this.isVirtualOrderId(this.store.currentOrder.order_id),
1598
+ 订单同步状态: this.store.isOrderSynced,
1599
+ 订单UUID: this.store.currentOrder.uuid
1600
+ });
1601
+ _context22.next = 20;
1602
+ return this.syncOrderToBackend();
1603
+ case 20:
1604
+ console.log('[Checkout] addPaymentItemAsync 中的同步完成:', {
1605
+ 同步后订单ID: this.store.currentOrder.order_id,
1606
+ 是否为虚拟ID: this.isVirtualOrderId(this.store.currentOrder.order_id),
1607
+ 订单同步状态: this.store.isOrderSynced
1608
+ });
1609
+ case 21:
1610
+ _context22.next = 23;
1611
+ return this.updateStateAmountToRemaining();
1612
+ case 23:
1613
+ _context22.next = 25;
1614
+ return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1615
+ orderUuid: this.store.currentOrder.uuid,
1616
+ paymentMethodCode: paymentItem.code,
1617
+ amount: String(paymentItem.amount),
1618
+ timestamp: Date.now()
1619
+ });
1620
+ case 25:
1621
+ _context22.next = 33;
1622
+ break;
1623
+ case 27:
1624
+ _context22.prev = 27;
1625
+ _context22.t0 = _context22["catch"](0);
1626
+ console.error('[Checkout] 添加支付项失败:', _context22.t0);
1627
+ _context22.next = 32;
1628
+ return this.handleError(_context22.t0, CheckoutErrorType.PaymentFailed);
1629
+ case 32:
1630
+ throw _context22.t0;
1631
+ case 33:
1632
+ case "end":
1633
+ return _context22.stop();
1634
+ }
1635
+ }, _callee22, this, [[0, 27]]);
1636
+ }));
1637
+ function addPaymentItemAsync(_x13) {
1638
+ return _addPaymentItemAsync.apply(this, arguments);
1639
+ }
1640
+ return addPaymentItemAsync;
1641
+ }()
1642
+ /**
1643
+ * 删除当前订单的支付项
1644
+ *
1645
+ * 从当前活跃订单中删除指定的支付项,支付项将被标记为已撤销状态
1646
+ *
1647
+ * @param paymentUuid 要删除的支付项UUID
1648
+ * @throws 当前没有活跃订单时抛出错误
1649
+ * @throws 支付项不存在时抛出错误
1650
+ */
1651
+ )
1652
+ }, {
1653
+ key: "deletePaymentItemAsync",
1654
+ value: (function () {
1655
+ var _deletePaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(paymentUuid) {
1656
+ var paymentItem, currentOrderId, isCurrentOrderReal, updatedOrder;
1657
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1658
+ while (1) switch (_context23.prev = _context23.next) {
1659
+ case 0:
1660
+ _context23.prev = 0;
1661
+ if (this.store.currentOrder) {
1662
+ _context23.next = 3;
1663
+ break;
1664
+ }
1665
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, '当前没有活跃订单,无法删除支付项');
1666
+ case 3:
1667
+ console.log('[Checkout] 开始删除支付项:', {
1668
+ orderUuid: this.store.currentOrder.uuid,
1669
+ paymentUuid: paymentUuid
1670
+ });
1671
+
1672
+ // 验证支付项是否存在
1673
+ paymentItem = this.store.currentOrder.payment.find(function (p) {
1674
+ return p.uuid === paymentUuid;
1675
+ });
1676
+ if (paymentItem) {
1677
+ _context23.next = 7;
1678
+ break;
1679
+ }
1680
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u652F\u4ED8\u9879\u4E0D\u5B58\u5728: ".concat(paymentUuid));
1681
+ case 7:
1682
+ console.log('[Checkout] 找到要删除的支付项:', {
1683
+ uuid: paymentItem.uuid,
1684
+ code: paymentItem.code,
1685
+ amount: paymentItem.amount,
1686
+ status: paymentItem.status
1687
+ });
1688
+
1689
+ // 调用 Payment 模块删除支付项
1690
+ _context23.next = 10;
1691
+ return this.payment.deletePaymentAsync(this.store.currentOrder.uuid, paymentUuid);
1692
+ case 10:
1693
+ console.log('[Checkout] Payment模块删除完成');
1694
+
1695
+ // 重新从Payment模块获取最新的订单数据,确保支付项同步
1696
+ currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1697
+ isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
1698
+ _context23.next = 15;
1699
+ return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1700
+ case 15:
1701
+ updatedOrder = _context23.sent;
1702
+ if (updatedOrder) {
1703
+ // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
1704
+ if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
1705
+ console.warn('[Checkout] deletePaymentItemAsync: 检测到订单ID回退,保护真实订单ID:', {
1706
+ 当前真实ID: currentOrderId,
1707
+ 获取到的虚拟ID: updatedOrder.order_id
1708
+ });
1709
+ updatedOrder.order_id = currentOrderId; // 恢复真实的订单ID
1710
+ }
1711
+ this.store.currentOrder = updatedOrder;
1712
+ console.log('[Checkout] 订单数据已同步,当前支付项数量:', updatedOrder.payment.length);
1713
+ }
1714
+
1715
+ // 更新 stateAmount 为剩余未支付金额
1716
+ _context23.next = 19;
1717
+ return this.updateStateAmountToRemaining();
1718
+ case 19:
1719
+ _context23.next = 21;
1720
+ return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1721
+ orderUuid: this.store.currentOrder.uuid,
1722
+ paymentMethodCode: paymentItem.code,
1723
+ amount: "-".concat(paymentItem.amount),
1724
+ // 负数表示删除
1725
+ timestamp: Date.now()
1726
+ });
1727
+ case 21:
1728
+ console.log('[Checkout] 支付项删除成功');
1729
+ _context23.next = 30;
1730
+ break;
1731
+ case 24:
1732
+ _context23.prev = 24;
1733
+ _context23.t0 = _context23["catch"](0);
1734
+ console.error('[Checkout] 删除支付项失败:', _context23.t0);
1735
+ _context23.next = 29;
1736
+ return this.handleError(_context23.t0, CheckoutErrorType.PaymentFailed);
1737
+ case 29:
1738
+ throw _context23.t0;
1739
+ case 30:
1740
+ case "end":
1741
+ return _context23.stop();
1742
+ }
1743
+ }, _callee23, this, [[0, 24]]);
1744
+ }));
1745
+ function deletePaymentItemAsync(_x14) {
1746
+ return _deletePaymentItemAsync.apply(this, arguments);
1747
+ }
1748
+ return deletePaymentItemAsync;
1749
+ }()
1750
+ /**
1751
+ * 批量更新当前订单的代金券支付项(覆盖更新)
1752
+ *
1753
+ * 删除所有现有的代金券支付项,然后添加新的代金券支付项。
1754
+ * 这是一个覆盖式更新操作,确保代金券支付项的一致性。
1755
+ *
1756
+ * @param voucherPaymentItems 新的代金券支付项列表,每个都必须包含 voucher_id
1757
+ * @throws 当前没有活跃订单时抛出错误
1758
+ * @throws 支付项缺少 voucher_id 时抛出错误
1759
+ */
1760
+ )
1761
+ }, {
1762
+ key: "updateVoucherPaymentItemsAsync",
1763
+ value: (function () {
1764
+ var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(voucherPaymentItems) {
1765
+ var _iterator, _step, item, currentOrderId, isCurrentOrderReal, updatedOrder, voucherItems;
1766
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1767
+ while (1) switch (_context24.prev = _context24.next) {
1768
+ case 0:
1769
+ _context24.prev = 0;
1770
+ if (this.store.currentOrder) {
1771
+ _context24.next = 3;
1772
+ break;
1773
+ }
1774
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, '当前没有活跃订单,无法更新代金券支付项');
1775
+ case 3:
1776
+ console.log('[Checkout] 开始批量更新代金券支付项:', {
1777
+ orderUuid: this.store.currentOrder.uuid,
1778
+ newVoucherCount: voucherPaymentItems.length,
1779
+ voucherPaymentItems: voucherPaymentItems
1780
+ });
1781
+
1782
+ // 验证所有支付项都包含 voucher_id
1783
+ _iterator = _createForOfIteratorHelper(voucherPaymentItems);
1784
+ _context24.prev = 5;
1785
+ _iterator.s();
1786
+ case 7:
1787
+ if ((_step = _iterator.n()).done) {
1788
+ _context24.next = 13;
1789
+ break;
1790
+ }
1791
+ item = _step.value;
1792
+ if (item.voucher_id) {
1793
+ _context24.next = 11;
1794
+ break;
1795
+ }
1796
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u7F3A\u5C11 voucher_id: ".concat(JSON.stringify(item)));
1797
+ case 11:
1798
+ _context24.next = 7;
1799
+ break;
1800
+ case 13:
1801
+ _context24.next = 18;
1802
+ break;
1803
+ case 15:
1804
+ _context24.prev = 15;
1805
+ _context24.t0 = _context24["catch"](5);
1806
+ _iterator.e(_context24.t0);
1807
+ case 18:
1808
+ _context24.prev = 18;
1809
+ _iterator.f();
1810
+ return _context24.finish(18);
1811
+ case 21:
1812
+ _context24.next = 23;
1813
+ return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItems);
1814
+ case 23:
1815
+ console.log('[Checkout] Payment模块批量更新完成');
1816
+
1817
+ // 重新从Payment模块获取最新的订单数据,确保支付项同步
1818
+ currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1819
+ isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
1820
+ _context24.next = 28;
1821
+ return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1822
+ case 28:
1823
+ updatedOrder = _context24.sent;
1824
+ if (updatedOrder) {
1825
+ // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
1826
+ if (isCurrentOrderReal && this.isVirtualOrderId(updatedOrder.order_id)) {
1827
+ console.warn('[Checkout] updateVoucherPaymentItemsAsync: 检测到订单ID回退,保护真实订单ID:', {
1828
+ 当前真实ID: currentOrderId,
1829
+ 获取到的虚拟ID: updatedOrder.order_id
1830
+ });
1831
+ updatedOrder.order_id = currentOrderId; // 恢复真实的订单ID
1832
+ }
1833
+ this.store.currentOrder = updatedOrder;
1834
+ console.log('[Checkout] 订单数据已同步,当前支付项数量:', updatedOrder.payment.length);
1835
+
1836
+ // 打印更新后的代金券支付项
1837
+ voucherItems = updatedOrder.payment.filter(function (payment) {
1838
+ return payment.voucher_id && payment.status !== 'voided';
1839
+ });
1840
+ console.log('[Checkout] 更新后的代金券支付项:', {
1841
+ voucherCount: voucherItems.length,
1842
+ items: voucherItems.map(function (item) {
1843
+ return {
1844
+ uuid: item.uuid,
1845
+ code: item.code,
1846
+ amount: item.amount,
1847
+ voucher_id: item.voucher_id
1848
+ };
1849
+ })
1850
+ });
1851
+ }
1852
+
1853
+ // 更新 stateAmount 为剩余未支付金额
1854
+ _context24.next = 32;
1855
+ return this.updateStateAmountToRemaining();
1856
+ case 32:
1857
+ _context24.next = 34;
1858
+ return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1859
+ orderUuid: this.store.currentOrder.uuid,
1860
+ paymentMethodCode: 'VOUCHER_BATCH',
1861
+ amount: voucherPaymentItems.reduce(function (sum, item) {
1862
+ return sum + parseFloat(String(item.amount));
1863
+ }, 0).toFixed(2),
1864
+ timestamp: Date.now()
1865
+ });
1866
+ case 34:
1867
+ console.log('[Checkout] 代金券支付项批量更新成功');
1868
+ _context24.next = 43;
1869
+ break;
1870
+ case 37:
1871
+ _context24.prev = 37;
1872
+ _context24.t1 = _context24["catch"](0);
1873
+ console.error('[Checkout] 批量更新代金券支付项失败:', _context24.t1);
1874
+ _context24.next = 42;
1875
+ return this.handleError(_context24.t1, CheckoutErrorType.PaymentFailed);
1876
+ case 42:
1877
+ throw _context24.t1;
1878
+ case 43:
1879
+ case "end":
1880
+ return _context24.stop();
1881
+ }
1882
+ }, _callee24, this, [[0, 37], [5, 15, 18, 21]]);
1883
+ }));
1884
+ function updateVoucherPaymentItemsAsync(_x15) {
1885
+ return _updateVoucherPaymentItemsAsync.apply(this, arguments);
1886
+ }
1887
+ return updateVoucherPaymentItemsAsync;
1888
+ }()
1889
+ /**
1890
+ * 修改当前订单的定金状态
1891
+ *
1892
+ * 更新当前订单的 is_deposit 字段,用于标识订单是否为定金订单
1893
+ *
1894
+ * @param isDeposit 定金状态 (1: 定金订单, 0: 全款订单)
1895
+ * @throws 当前没有活跃订单时抛出错误
1896
+ */
1897
+ )
1898
+ }, {
1899
+ key: "updateOrderDepositStatusAsync",
1900
+ value: (function () {
1901
+ var _updateOrderDepositStatusAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(isDeposit) {
1902
+ var newDepositValue, oldDepositValue, updateParams;
1903
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1904
+ while (1) switch (_context25.prev = _context25.next) {
1905
+ case 0:
1906
+ _context25.prev = 0;
1907
+ if (!(isDeposit !== 0 && isDeposit !== 1)) {
1908
+ _context25.next = 3;
1909
+ break;
1910
+ }
1911
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, 'isDeposit 参数只能是 0(全款订单)或 1(定金订单)');
1912
+ case 3:
1913
+ if (this.store.currentOrder) {
1914
+ _context25.next = 5;
1915
+ break;
1916
+ }
1917
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法修改定金状态');
1918
+ case 5:
1919
+ newDepositValue = isDeposit;
1920
+ oldDepositValue = this.store.currentOrder.is_deposit; // 如果状态没有变化,直接返回
1921
+ if (!(oldDepositValue === newDepositValue)) {
1922
+ _context25.next = 10;
1923
+ break;
1924
+ }
1925
+ console.log('[Checkout] 定金状态无变化,跳过更新');
1926
+ return _context25.abrupt("return");
1927
+ case 10:
1928
+ console.log('[Checkout] 更新订单定金状态:', {
1929
+ orderUuid: this.store.currentOrder.uuid,
1930
+ orderId: this.store.currentOrder.order_id,
1931
+ oldIsDeposit: oldDepositValue,
1932
+ newIsDeposit: newDepositValue
1933
+ });
1934
+
1935
+ // 准备更新参数
1936
+ updateParams = {
1937
+ is_deposit: newDepositValue
1938
+ }; // 如果从定金改为全款,可以清空定金金额
1939
+ if (isDeposit === 0 && this.store.currentOrder.deposit_amount !== '0.00') {
1940
+ updateParams.deposit_amount = '0.00';
1941
+ console.log('[Checkout] 订单从定金改为全款,清空定金金额');
1942
+ }
1943
+
1944
+ // 调用 Payment 模块更新订单
1945
+ _context25.next = 15;
1946
+ return this.payment.updateOrderAsync(this.store.currentOrder.uuid, updateParams);
1947
+ case 15:
1948
+ // 更新本地缓存的订单对象
1949
+ this.store.currentOrder = _objectSpread(_objectSpread({}, this.store.currentOrder), updateParams);
1950
+
1951
+ // 同时更新本地订单数据(如果存在)
1952
+ if (this.store.localOrderData) {
1953
+ this.store.localOrderData.is_deposit = newDepositValue;
1954
+ }
1955
+
1956
+ // 触发订单更新事件
1957
+ _context25.next = 19;
1958
+ return this.core.effects.emit(CheckoutHooks.OnOrderCreated, {
1959
+ order: this.store.currentOrder,
1960
+ timestamp: Date.now()
1961
+ });
1962
+ case 19:
1963
+ console.log('[Checkout] 订单定金状态更新成功:', {
1964
+ isDeposit: newDepositValue,
1965
+ depositAmount: this.store.currentOrder.deposit_amount
1966
+ });
1967
+ _context25.next = 28;
1968
+ break;
1969
+ case 22:
1970
+ _context25.prev = 22;
1971
+ _context25.t0 = _context25["catch"](0);
1972
+ console.error('[Checkout] 更新订单定金状态失败:', _context25.t0);
1973
+ _context25.next = 27;
1974
+ return this.handleError(_context25.t0, CheckoutErrorType.ValidationFailed);
1975
+ case 27:
1976
+ throw _context25.t0;
1977
+ case 28:
1978
+ case "end":
1979
+ return _context25.stop();
1980
+ }
1981
+ }, _callee25, this, [[0, 22]]);
1982
+ }));
1983
+ function updateOrderDepositStatusAsync(_x16) {
1984
+ return _updateOrderDepositStatusAsync.apply(this, arguments);
1985
+ }
1986
+ return updateOrderDepositStatusAsync;
1987
+ }()
1988
+ /**
1989
+ * 更新当前订单的客户信息
1990
+ *
1991
+ * 更新当前订单关联的客户信息,用于标识订单的所属客户
1992
+ *
1993
+ * @param customer 客户信息 (customer_id 和/或 customer_name)
1994
+ * @throws 当前没有活跃订单时抛出错误
1995
+ */
1996
+ )
1997
+ }, {
1998
+ key: "updateOrderCustomerAsync",
1999
+ value: (function () {
2000
+ var _updateOrderCustomerAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(customer) {
2001
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2002
+ while (1) switch (_context26.prev = _context26.next) {
2003
+ case 0:
2004
+ _context26.prev = 0;
2005
+ if (this.store.currentOrder) {
2006
+ _context26.next = 3;
2007
+ break;
2008
+ }
2009
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法更新客户信息');
2010
+ case 3:
2011
+ console.log('[Checkout] 更新订单客户信息:', {
2012
+ orderUuid: this.store.currentOrder.uuid,
2013
+ oldCustomer: this.store.currentCustomer,
2014
+ newCustomer: customer
2015
+ });
2016
+
2017
+ // 更新客户信息
2018
+ this.store.currentCustomer = {
2019
+ customer_id: customer.customer_id,
2020
+ customer_name: customer.customer_name
2021
+ };
2022
+
2023
+ // 同时更新本地订单数据中的客户信息(如果存在)
2024
+ if (this.store.localOrderData) {
2025
+ this.store.localOrderData.customer_id = customer.customer_id;
2026
+ this.store.localOrderData.customer_name = customer.customer_name;
2027
+ }
2028
+ console.log('[Checkout] 订单客户信息更新成功:', this.store.currentCustomer);
2029
+ _context26.next = 15;
2030
+ break;
2031
+ case 9:
2032
+ _context26.prev = 9;
2033
+ _context26.t0 = _context26["catch"](0);
2034
+ console.error('[Checkout] 更新订单客户信息失败:', _context26.t0);
2035
+ _context26.next = 14;
2036
+ return this.handleError(_context26.t0, CheckoutErrorType.ValidationFailed);
2037
+ case 14:
2038
+ throw _context26.t0;
2039
+ case 15:
2040
+ case "end":
2041
+ return _context26.stop();
2042
+ }
2043
+ }, _callee26, this, [[0, 9]]);
2044
+ }));
2045
+ function updateOrderCustomerAsync(_x17) {
2046
+ return _updateOrderCustomerAsync.apply(this, arguments);
2047
+ }
2048
+ return updateOrderCustomerAsync;
2049
+ }()
2050
+ /**
2051
+ * 获取当前订单的客户信息
2052
+ *
2053
+ * @returns 当前客户信息,如果没有则返回 null
2054
+ */
2055
+ )
2056
+ }, {
2057
+ key: "getCurrentCustomer",
2058
+ value: function getCurrentCustomer() {
2059
+ return this.store.currentCustomer || null;
2060
+ }
2061
+
2062
+ /**
2063
+ * 检查订单是否需要手动同步
2064
+ *
2065
+ * 返回订单是否为纯代金券支付且待付金额<=0但未同步的状态
2066
+ */
2067
+ }, {
2068
+ key: "needsManualSync",
2069
+ value: function needsManualSync() {
2070
+ try {
2071
+ var _this$store$currentOr5;
2072
+ // 检查基础条件
2073
+ if (!this.store.currentOrder || this.store.isOrderSynced) {
2074
+ return false;
2075
+ }
2076
+
2077
+ // 检查是否支付完成(剩余金额<=0)
2078
+ var remainingAmount = this.calculateRemainingAmount();
2079
+ var remainingValue = parseFloat(remainingAmount);
2080
+ if (remainingValue > 0) {
2081
+ return false;
2082
+ }
2083
+
2084
+ // 检查是否所有支付项都带有 voucher_id
2085
+ var allPaymentsHaveVoucherId = this.store.currentOrder.payment && this.store.currentOrder.payment.length > 0 && this.store.currentOrder.payment.every(function (item) {
2086
+ return item.status !== 'voided' && item.voucher_id;
2087
+ });
2088
+ console.log('[Checkout] needsManualSync 检查结果:', {
2089
+ orderUuid: this.store.currentOrder.uuid,
2090
+ isOrderSynced: this.store.isOrderSynced,
2091
+ remainingAmount: remainingAmount,
2092
+ hasPayments: ((_this$store$currentOr5 = this.store.currentOrder.payment) === null || _this$store$currentOr5 === void 0 ? void 0 : _this$store$currentOr5.length) > 0,
2093
+ allPaymentsHaveVoucherId: allPaymentsHaveVoucherId,
2094
+ needsManualSync: allPaymentsHaveVoucherId
2095
+ });
2096
+ return allPaymentsHaveVoucherId;
2097
+ } catch (error) {
2098
+ console.error('[Checkout] needsManualSync 检查失败:', error);
2099
+ return false;
2100
+ }
2101
+ }
2102
+
2103
+ /**
2104
+ * 手动同步订单到后端
2105
+ *
2106
+ * 用于强制同步订单到后端,特别适用于纯代金券支付完成的订单
2107
+ */
2108
+ }, {
2109
+ key: "manualSyncOrderAsync",
2110
+ value: (function () {
2111
+ var _manualSyncOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
2112
+ var orderUuid, oldOrderId, realOrderId, finalOrderId, finalIsVirtual, _this$store$currentOr6, errorMessage;
2113
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2114
+ while (1) switch (_context27.prev = _context27.next) {
2115
+ case 0:
2116
+ _context27.prev = 0;
2117
+ if (this.store.currentOrder) {
2118
+ _context27.next = 3;
2119
+ break;
2120
+ }
2121
+ return _context27.abrupt("return", {
2122
+ success: false,
2123
+ message: '当前没有活跃订单,无法同步'
2124
+ });
2125
+ case 3:
2126
+ orderUuid = this.store.currentOrder.uuid;
2127
+ oldOrderId = this.store.currentOrder.order_id; // 检查订单是否已经同步
2128
+ if (this.store.isOrderSynced) {
2129
+ console.log('[Checkout] 订单已同步过,将执行更新操作');
2130
+ }
2131
+ console.log('[Checkout] 开始手动同步订单到后端:', {
2132
+ orderUuid: orderUuid,
2133
+ orderId: oldOrderId,
2134
+ totalAmount: this.store.currentOrder.total_amount,
2135
+ remainingAmount: this.calculateRemainingAmount()
2136
+ });
2137
+
2138
+ // 强制同步订单到后端,并获取真实订单ID
2139
+ _context27.next = 9;
2140
+ return this.syncOrderToBackendWithReturn(true);
2141
+ case 9:
2142
+ realOrderId = _context27.sent;
2143
+ console.log('[Checkout] 手动同步订单完成:', {
2144
+ orderUuid: orderUuid,
2145
+ oldOrderId: oldOrderId,
2146
+ realOrderId: realOrderId,
2147
+ isOrderSynced: this.store.isOrderSynced
2148
+ });
2149
+
2150
+ // 🔍 关键验证:检查最终状态是否正确
2151
+ finalOrderId = this.store.currentOrder.order_id;
2152
+ finalIsVirtual = this.isVirtualOrderId(finalOrderId);
2153
+ console.log('[Checkout] manualSyncOrderAsync 最终状态验证:', {
2154
+ 返回的订单ID: realOrderId,
2155
+ 存储的订单ID: finalOrderId,
2156
+ 存储的ID是否虚拟: finalIsVirtual,
2157
+ 是否一致: realOrderId === finalOrderId,
2158
+ 同步状态: this.store.isOrderSynced
2159
+ });
2160
+ if (finalIsVirtual) {
2161
+ console.error('[Checkout] 严重警告:手动同步完成后订单ID仍为虚拟ID!');
2162
+ }
2163
+ if (realOrderId !== finalOrderId) {
2164
+ console.error('[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!');
2165
+ }
2166
+ return _context27.abrupt("return", {
2167
+ success: true,
2168
+ message: '订单同步成功',
2169
+ orderId: realOrderId,
2170
+ // 直接返回从后端获取的真实订单ID
2171
+ orderUuid: orderUuid
2172
+ });
2173
+ case 19:
2174
+ _context27.prev = 19;
2175
+ _context27.t0 = _context27["catch"](0);
2176
+ console.error('[Checkout] 手动同步订单失败:', _context27.t0);
2177
+ errorMessage = _context27.t0 instanceof Error ? _context27.t0.message : '同步失败';
2178
+ return _context27.abrupt("return", {
2179
+ success: false,
2180
+ message: "\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(errorMessage),
2181
+ orderUuid: (_this$store$currentOr6 = this.store.currentOrder) === null || _this$store$currentOr6 === void 0 ? void 0 : _this$store$currentOr6.uuid
2182
+ });
2183
+ case 24:
2184
+ case "end":
2185
+ return _context27.stop();
2186
+ }
2187
+ }, _callee27, this, [[0, 19]]);
2188
+ }));
2189
+ function manualSyncOrderAsync() {
2190
+ return _manualSyncOrderAsync.apply(this, arguments);
2191
+ }
2192
+ return manualSyncOrderAsync;
2193
+ }()
2194
+ /**
2195
+ * 获取当前订单备注
2196
+ *
2197
+ * @returns 当前订单的备注内容,如果没有则返回空字符串
2198
+ */
2199
+ )
2200
+ }, {
2201
+ key: "getOrderNote",
2202
+ value: function getOrderNote() {
2203
+ if (!this.store.localOrderData) {
2204
+ console.log('[Checkout] 没有本地订单数据,无法获取备注');
2205
+ return '';
2206
+ }
2207
+ return this.store.localOrderData.shop_note || '';
2208
+ }
2209
+
2210
+ /**
2211
+ * 获取当前订单ID
2212
+ *
2213
+ * @returns 当前订单的ID,如果没有订单则返回null
2214
+ */
2215
+ }, {
2216
+ key: "getCurrentOrderId",
2217
+ value: function getCurrentOrderId() {
2218
+ if (!this.store.currentOrder) {
2219
+ return null;
2220
+ }
2221
+ return this.store.currentOrder.order_id;
2222
+ }
2223
+
2224
+ /**
2225
+ * 保存订单并稍后支付
2226
+ *
2227
+ * 将当前订单保存到后端,但排除代金券类支付项(voucher_id),
2228
+ * 适用于用户想要保存订单但稍后完成支付的场景
2229
+ */
2230
+ }, {
2231
+ key: "saveForLaterPaymentAsync",
2232
+ value: (function () {
2233
+ var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2234
+ var orderUuid, currentOrderId, allPaymentItems, filteredPaymentItems, voucherItems, realOrderId, finalOrderId, _this$store$currentOr7, errorMessage;
2235
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2236
+ while (1) switch (_context28.prev = _context28.next) {
2237
+ case 0:
2238
+ _context28.prev = 0;
2239
+ if (this.store.currentOrder) {
2240
+ _context28.next = 3;
2241
+ break;
2242
+ }
2243
+ return _context28.abrupt("return", {
2244
+ success: false,
2245
+ message: '当前没有活跃订单,无法保存'
2246
+ });
2247
+ case 3:
2248
+ orderUuid = this.store.currentOrder.uuid;
2249
+ currentOrderId = this.store.currentOrder.order_id;
2250
+ console.log('[Checkout] 开始保存订单并稍后支付:', {
2251
+ orderUuid: orderUuid,
2252
+ orderId: currentOrderId,
2253
+ totalAmount: this.store.currentOrder.total_amount
2254
+ });
2255
+
2256
+ // 获取当前订单的所有支付项
2257
+ _context28.next = 8;
2258
+ return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
2259
+ case 8:
2260
+ allPaymentItems = _context28.sent;
2261
+ // 过滤掉带有 voucher_id 的支付项(代金券类支付项)
2262
+ filteredPaymentItems = allPaymentItems.filter(function (payment) {
2263
+ return !payment.voucher_id || payment.voucher_id.trim() === '';
2264
+ }); // 记录过滤结果
2265
+ voucherItems = allPaymentItems.filter(function (payment) {
2266
+ return payment.voucher_id && payment.voucher_id.trim() !== '';
2267
+ });
2268
+ console.log('[Checkout] 支付项过滤结果:', {
2269
+ 总支付项: allPaymentItems.length,
2270
+ 过滤后支付项: filteredPaymentItems.length,
2271
+ 被过滤的代金券项: voucherItems.length,
2272
+ 代金券详情: voucherItems.map(function (item) {
2273
+ return {
2274
+ uuid: item.uuid,
2275
+ code: item.code,
2276
+ amount: item.amount,
2277
+ voucherId: item.voucher_id
2278
+ };
2279
+ }),
2280
+ 保留的支付项: filteredPaymentItems.map(function (item) {
2281
+ return {
2282
+ uuid: item.uuid,
2283
+ code: item.code,
2284
+ amount: item.amount
2285
+ };
2286
+ })
2287
+ });
2288
+
2289
+ // 调用同步方法,传入过滤后的支付项
2290
+ _context28.next = 14;
2291
+ return this.syncOrderToBackendWithReturn(false, filteredPaymentItems);
2292
+ case 14:
2293
+ realOrderId = _context28.sent;
2294
+ console.log('[Checkout] 保存订单完成:', {
2295
+ orderUuid: orderUuid,
2296
+ oldOrderId: currentOrderId,
2297
+ realOrderId: realOrderId,
2298
+ isOrderSynced: this.store.isOrderSynced,
2299
+ filteredPaymentsCount: filteredPaymentItems.length
2300
+ });
2301
+
2302
+ // 验证最终状态
2303
+ finalOrderId = this.store.currentOrder.order_id;
2304
+ console.log('[Checkout] saveForLaterPaymentAsync 最终状态验证:', {
2305
+ 返回的订单ID: realOrderId,
2306
+ 存储的订单ID: finalOrderId,
2307
+ 是否一致: realOrderId === finalOrderId,
2308
+ 同步状态: this.store.isOrderSynced
2309
+ });
2310
+ return _context28.abrupt("return", {
2311
+ success: true,
2312
+ message: '订单保存成功,可稍后继续支付',
2313
+ orderId: realOrderId,
2314
+ orderUuid: orderUuid
2315
+ });
2316
+ case 21:
2317
+ _context28.prev = 21;
2318
+ _context28.t0 = _context28["catch"](0);
2319
+ console.error('[Checkout] 保存订单失败:', _context28.t0);
2320
+ errorMessage = _context28.t0 instanceof Error ? _context28.t0.message : '保存失败';
2321
+ return _context28.abrupt("return", {
2322
+ success: false,
2323
+ message: "\u8BA2\u5355\u4FDD\u5B58\u5931\u8D25: ".concat(errorMessage),
2324
+ orderUuid: (_this$store$currentOr7 = this.store.currentOrder) === null || _this$store$currentOr7 === void 0 ? void 0 : _this$store$currentOr7.uuid
2325
+ });
2326
+ case 26:
2327
+ case "end":
2328
+ return _context28.stop();
2329
+ }
2330
+ }, _callee28, this, [[0, 21]]);
2331
+ }));
2332
+ function saveForLaterPaymentAsync() {
2333
+ return _saveForLaterPaymentAsync.apply(this, arguments);
2334
+ }
2335
+ return saveForLaterPaymentAsync;
2336
+ }()
2337
+ /**
2338
+ * 获取当前商店折扣金额
2339
+ *
2340
+ * @returns 当前的商店折扣金额,如果没有则返回0
2341
+ */
2342
+ )
2343
+ }, {
2344
+ key: "getShopDiscount",
2345
+ value: function getShopDiscount() {
2346
+ var _this$store$localOrde;
2347
+ // 优先从 localOrderData 中获取
2348
+ if (((_this$store$localOrde = this.store.localOrderData) === null || _this$store$localOrde === void 0 ? void 0 : _this$store$localOrde.shop_discount) !== undefined) {
2349
+ return this.store.localOrderData.shop_discount;
2350
+ }
2351
+
2352
+ // 从 cartSummary 中查找 shop_discount 项
2353
+ if (this.store.cartSummary) {
2354
+ var shopDiscountItem = this.store.cartSummary.find(function (item) {
2355
+ return item.key === 'shop_discount';
2356
+ });
2357
+ if (shopDiscountItem) {
2358
+ return shopDiscountItem.value;
2359
+ }
2360
+ }
2361
+ return 0;
2362
+ }
2363
+
2364
+ /**
2365
+ * 更新订单商店折扣
2366
+ *
2367
+ * 同时更新cartSummary和localOrderData中的shop_discount值
2368
+ *
2369
+ * @param discountAmount 商店折扣金额
2370
+ */
2371
+ }, {
2372
+ key: "updateShopDiscountAsync",
2373
+ value: (function () {
2374
+ var _updateShopDiscountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(discountAmount) {
2375
+ var _this$store$currentOr8, _this$store$currentOr9, oldDiscount, shopDiscountItem, updatedAmountInfo;
2376
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2377
+ while (1) switch (_context29.prev = _context29.next) {
2378
+ case 0:
2379
+ _context29.prev = 0;
2380
+ oldDiscount = this.getShopDiscount();
2381
+ console.log('[Checkout] 更新商店折扣:', {
2382
+ orderUuid: (_this$store$currentOr8 = this.store.currentOrder) === null || _this$store$currentOr8 === void 0 ? void 0 : _this$store$currentOr8.uuid,
2383
+ oldDiscount: oldDiscount,
2384
+ newDiscount: discountAmount
2385
+ });
2386
+
2387
+ // 1. 更新 cartSummary 中的 shop_discount 项
2388
+ if (this.store.cartSummary) {
2389
+ shopDiscountItem = this.store.cartSummary.find(function (item) {
2390
+ return item.key === 'shop_discount';
2391
+ });
2392
+ if (shopDiscountItem) {
2393
+ shopDiscountItem.value = discountAmount;
2394
+ console.log('[Checkout] cartSummary 中的商店折扣已更新');
2395
+ } else {
2396
+ // 如果不存在,创建一个新的商店折扣项
2397
+ this.store.cartSummary.push({
2398
+ key: 'shop_discount',
2399
+ value: discountAmount,
2400
+ hidden: true,
2401
+ label: 'Shop Discount'
2402
+ });
2403
+ console.log('[Checkout] cartSummary 中已添加新的商店折扣项');
2404
+ }
2405
+ }
2406
+
2407
+ // 2. 更新 localOrderData 中的 shop_discount
2408
+ if (this.store.localOrderData) {
2409
+ this.store.localOrderData.shop_discount = discountAmount;
2410
+ console.log('[Checkout] localOrderData 中的商店折扣已更新');
2411
+ } else {
2412
+ console.warn('[Checkout] localOrderData 不存在,无法更新商店折扣');
2413
+ }
2414
+
2415
+ // 3. 如果有当前订单,可能需要重新计算订单金额
2416
+ if (this.store.currentOrder && this.store.cartSummary) {
2417
+ // 重新提取金额信息
2418
+ updatedAmountInfo = this.extractAmountFromCartSummary(this.store.cartSummary);
2419
+ console.log('[Checkout] 重新计算订单金额:', updatedAmountInfo);
2420
+
2421
+ // 更新订单的总金额等信息
2422
+ this.store.currentOrder.total_amount = updatedAmountInfo.totalAmount;
2423
+ this.store.currentOrder.expect_amount = updatedAmountInfo.totalAmount;
2424
+ }
2425
+
2426
+ // 4. 更新 stateAmount 为剩余未支付金额
2427
+ _context29.next = 8;
2428
+ return this.updateStateAmountToRemaining();
2429
+ case 8:
2430
+ _context29.next = 10;
2431
+ return this.core.effects.emit(CheckoutHooks.OnShopDiscountChanged, {
2432
+ orderUuid: (_this$store$currentOr9 = this.store.currentOrder) === null || _this$store$currentOr9 === void 0 ? void 0 : _this$store$currentOr9.uuid,
2433
+ oldDiscount: oldDiscount,
2434
+ newDiscount: discountAmount,
2435
+ timestamp: Date.now()
2436
+ });
2437
+ case 10:
2438
+ console.log('[Checkout] 商店折扣更新成功:', {
2439
+ oldDiscount: oldDiscount,
2440
+ newDiscount: discountAmount
2441
+ });
2442
+ _context29.next = 19;
2443
+ break;
2444
+ case 13:
2445
+ _context29.prev = 13;
2446
+ _context29.t0 = _context29["catch"](0);
2447
+ console.error('[Checkout] 更新商店折扣失败:', _context29.t0);
2448
+ _context29.next = 18;
2449
+ return this.handleError(_context29.t0, CheckoutErrorType.ValidationFailed);
2450
+ case 18:
2451
+ throw _context29.t0;
2452
+ case 19:
2453
+ case "end":
2454
+ return _context29.stop();
2455
+ }
2456
+ }, _callee29, this, [[0, 13]]);
2457
+ }));
2458
+ function updateShopDiscountAsync(_x18) {
2459
+ return _updateShopDiscountAsync.apply(this, arguments);
2460
+ }
2461
+ return updateShopDiscountAsync;
2462
+ }()
2463
+ /**
2464
+ * 更新订单备注
2465
+ *
2466
+ * @param note 订单备注内容
2467
+ */
2468
+ )
2469
+ }, {
2470
+ key: "updateOrderNoteAsync",
2471
+ value: (function () {
2472
+ var _updateOrderNoteAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(note) {
2473
+ var _this$store$currentOr10, _this$store$currentOr11, oldNote, orderInPayment;
2474
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2475
+ while (1) switch (_context30.prev = _context30.next) {
2476
+ case 0:
2477
+ _context30.prev = 0;
2478
+ if (this.store.localOrderData) {
2479
+ _context30.next = 3;
2480
+ break;
2481
+ }
2482
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, '没有本地订单数据,无法更新备注');
2483
+ case 3:
2484
+ console.log('[Checkout] 更新订单备注:', {
2485
+ orderUuid: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.uuid,
2486
+ oldNote: this.store.localOrderData.shop_note,
2487
+ newNote: note
2488
+ });
2489
+
2490
+ // 更新备注
2491
+ oldNote = this.store.localOrderData.shop_note;
2492
+ this.store.localOrderData.shop_note = note;
2493
+
2494
+ // 如果有当前订单,也同步到Payment模块中的订单数据
2495
+ if (!this.store.currentOrder) {
2496
+ _context30.next = 17;
2497
+ break;
2498
+ }
2499
+ _context30.prev = 7;
2500
+ _context30.next = 10;
2501
+ return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
2502
+ case 10:
2503
+ orderInPayment = _context30.sent;
2504
+ if (orderInPayment && orderInPayment.note !== undefined) {
2505
+ // 使用Payment模块的更新方法(如果有的话)
2506
+ // 这里可能需要根据Payment模块的实际API来调整
2507
+ console.log('[Checkout] 同步备注到Payment模块的订单数据中');
2508
+ }
2509
+ _context30.next = 17;
2510
+ break;
2511
+ case 14:
2512
+ _context30.prev = 14;
2513
+ _context30.t0 = _context30["catch"](7);
2514
+ console.warn('[Checkout] 同步备注到Payment模块失败,但本地更新成功:', _context30.t0);
2515
+ case 17:
2516
+ _context30.next = 19;
2517
+ return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
2518
+ orderUuid: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.uuid,
2519
+ oldNote: oldNote,
2520
+ newNote: note,
2521
+ timestamp: Date.now()
2522
+ });
2523
+ case 19:
2524
+ console.log('[Checkout] 订单备注更新成功:', {
2525
+ oldNote: oldNote,
2526
+ newNote: note
2527
+ });
2528
+ _context30.next = 28;
2529
+ break;
2530
+ case 22:
2531
+ _context30.prev = 22;
2532
+ _context30.t1 = _context30["catch"](0);
2533
+ console.error('[Checkout] 更新订单备注失败:', _context30.t1);
2534
+ _context30.next = 27;
2535
+ return this.handleError(_context30.t1, CheckoutErrorType.ValidationFailed);
2536
+ case 27:
2537
+ throw _context30.t1;
2538
+ case 28:
2539
+ case "end":
2540
+ return _context30.stop();
2541
+ }
2542
+ }, _callee30, this, [[0, 22], [7, 14]]);
2543
+ }));
2544
+ function updateOrderNoteAsync(_x19) {
2545
+ return _updateOrderNoteAsync.apply(this, arguments);
2546
+ }
2547
+ return updateOrderNoteAsync;
2548
+ }()
2549
+ /**
2550
+ * 设置状态
2551
+ */
2552
+ )
2553
+ }, {
2554
+ key: "setStatus",
2555
+ value: (function () {
2556
+ var _setStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(status) {
2557
+ var oldStatus;
2558
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2559
+ while (1) switch (_context31.prev = _context31.next) {
2560
+ case 0:
2561
+ oldStatus = this.store.status;
2562
+ this.store.status = status;
2563
+ _context31.next = 4;
2564
+ return this.core.effects.emit(CheckoutHooks.OnStatusChanged, {
2565
+ oldStatus: oldStatus,
2566
+ newStatus: status,
2567
+ timestamp: Date.now()
2568
+ });
2569
+ case 4:
2570
+ case "end":
2571
+ return _context31.stop();
2572
+ }
2573
+ }, _callee31, this);
2574
+ }));
2575
+ function setStatus(_x20) {
2576
+ return _setStatus.apply(this, arguments);
2577
+ }
2578
+ return setStatus;
2579
+ }()
2580
+ /**
2581
+ * 设置步骤
2582
+ */
2583
+ )
2584
+ }, {
2585
+ key: "setStep",
2586
+ value: (function () {
2587
+ var _setStep = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(step) {
2588
+ var oldStep;
2589
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2590
+ while (1) switch (_context32.prev = _context32.next) {
2591
+ case 0:
2592
+ oldStep = this.store.step;
2593
+ this.store.step = step;
2594
+ _context32.next = 4;
2595
+ return this.core.effects.emit(CheckoutHooks.OnStepChanged, {
2596
+ oldStep: oldStep,
2597
+ newStep: step,
2598
+ timestamp: Date.now()
2599
+ });
2600
+ case 4:
2601
+ case "end":
2602
+ return _context32.stop();
2603
+ }
2604
+ }, _callee32, this);
2605
+ }));
2606
+ function setStep(_x21) {
2607
+ return _setStep.apply(this, arguments);
2608
+ }
2609
+ return setStep;
2610
+ }()
2611
+ /**
2612
+ * 处理错误
2613
+ */
2614
+ )
2615
+ }, {
2616
+ key: "handleError",
2617
+ value: (function () {
2618
+ var _handleError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(error, type) {
2619
+ var checkoutError;
2620
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2621
+ while (1) switch (_context33.prev = _context33.next) {
2622
+ case 0:
2623
+ checkoutError = error instanceof Error && 'type' in error ? error : createCheckoutError(type, error.message, error);
2624
+ this.store.lastError = checkoutError;
2625
+ _context33.next = 4;
2626
+ return this.setStatus(CheckoutStatus.Error);
2627
+ case 4:
2628
+ _context33.next = 6;
2629
+ return this.core.effects.emit(CheckoutHooks.OnError, {
2630
+ error: checkoutError,
2631
+ context: {
2632
+ status: this.store.status,
2633
+ step: this.store.step
2634
+ },
2635
+ timestamp: Date.now()
2636
+ });
1277
2637
  case 6:
2638
+ console.error('[Checkout] 错误:', checkoutError);
2639
+ case 7:
1278
2640
  case "end":
1279
- return _context21.stop();
2641
+ return _context33.stop();
1280
2642
  }
1281
- }, _callee21, this);
2643
+ }, _callee33, this);
2644
+ }));
2645
+ function handleError(_x22, _x23) {
2646
+ return _handleError.apply(this, arguments);
2647
+ }
2648
+ return handleError;
2649
+ }()
2650
+ /**
2651
+ * 处理支付成功
2652
+ */
2653
+ )
2654
+ }, {
2655
+ key: "handlePaymentSuccess",
2656
+ value: (function () {
2657
+ var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(data) {
2658
+ var _this$store$currentOr12;
2659
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2660
+ while (1) switch (_context34.prev = _context34.next) {
2661
+ case 0:
2662
+ _context34.next = 2;
2663
+ return this.setStatus(CheckoutStatus.PaymentCompleted);
2664
+ case 2:
2665
+ _context34.next = 4;
2666
+ return this.updateStateAmountToRemaining();
2667
+ case 4:
2668
+ _context34.next = 6;
2669
+ return this.core.effects.emit(CheckoutHooks.OnPaymentSuccess, {
2670
+ orderUuid: data.orderUuid,
2671
+ paymentMethodCode: '',
2672
+ amount: ((_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.total_amount) || '0',
2673
+ timestamp: data.timestamp
2674
+ });
2675
+ case 6:
2676
+ _context34.next = 8;
2677
+ return this.completeCheckoutAsync();
2678
+ case 8:
2679
+ case "end":
2680
+ return _context34.stop();
2681
+ }
2682
+ }, _callee34, this);
1282
2683
  }));
1283
- function handlePaymentSuccess(_x16) {
2684
+ function handlePaymentSuccess(_x24) {
1284
2685
  return _handlePaymentSuccess.apply(this, arguments);
1285
2686
  }
1286
2687
  return handlePaymentSuccess;
@@ -1292,30 +2693,30 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1292
2693
  }, {
1293
2694
  key: "handlePaymentError",
1294
2695
  value: (function () {
1295
- var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(data) {
1296
- var _this$store$currentOr5;
2696
+ var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(data) {
2697
+ var _this$store$currentOr13;
1297
2698
  var error;
1298
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1299
- while (1) switch (_context22.prev = _context22.next) {
2699
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2700
+ while (1) switch (_context35.prev = _context35.next) {
1300
2701
  case 0:
1301
2702
  error = createCheckoutError(CheckoutErrorType.PaymentFailed, data.error || '支付同步失败');
1302
- _context22.next = 3;
2703
+ _context35.next = 3;
1303
2704
  return this.handleError(error instanceof Error ? error : new Error(String(error)), CheckoutErrorType.PaymentFailed);
1304
2705
  case 3:
1305
- _context22.next = 5;
2706
+ _context35.next = 5;
1306
2707
  return this.core.effects.emit(CheckoutHooks.OnPaymentFailed, {
1307
2708
  orderUuid: data.orderUuid,
1308
2709
  paymentMethodCode: '',
1309
- amount: ((_this$store$currentOr5 = this.store.currentOrder) === null || _this$store$currentOr5 === void 0 ? void 0 : _this$store$currentOr5.total_amount) || '0',
2710
+ amount: ((_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.total_amount) || '0',
1310
2711
  timestamp: data.timestamp
1311
2712
  });
1312
2713
  case 5:
1313
2714
  case "end":
1314
- return _context22.stop();
2715
+ return _context35.stop();
1315
2716
  }
1316
- }, _callee22, this);
2717
+ }, _callee35, this);
1317
2718
  }));
1318
- function handlePaymentError(_x17) {
2719
+ function handlePaymentError(_x25) {
1319
2720
  return _handlePaymentError.apply(this, arguments);
1320
2721
  }
1321
2722
  return handlePaymentError;
@@ -1327,18 +2728,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1327
2728
  }, {
1328
2729
  key: "validateCheckoutParams",
1329
2730
  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) {
2731
+ var _validateCheckoutParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
2732
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
2733
+ while (1) switch (_context36.prev = _context36.next) {
1333
2734
  case 0:
1334
- return _context23.abrupt("return", validateCheckoutData(params));
2735
+ return _context36.abrupt("return", validateCheckoutData(params));
1335
2736
  case 1:
1336
2737
  case "end":
1337
- return _context23.stop();
2738
+ return _context36.stop();
1338
2739
  }
1339
- }, _callee23);
2740
+ }, _callee36);
1340
2741
  }));
1341
- function validateCheckoutParams(_x18) {
2742
+ function validateCheckoutParams(_x26) {
1342
2743
  return _validateCheckoutParams.apply(this, arguments);
1343
2744
  }
1344
2745
  return validateCheckoutParams;
@@ -1350,10 +2751,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1350
2751
  }, {
1351
2752
  key: "validateLocalOrderData",
1352
2753
  value: (function () {
1353
- var _validateLocalOrderData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orderData) {
2754
+ var _validateLocalOrderData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(orderData) {
1354
2755
  var errors;
1355
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1356
- while (1) switch (_context24.prev = _context24.next) {
2756
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
2757
+ while (1) switch (_context37.prev = _context37.next) {
1357
2758
  case 0:
1358
2759
  errors = []; // 验证基本字段
1359
2760
  if (!orderData.type) {
@@ -1380,17 +2781,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1380
2781
  }
1381
2782
  });
1382
2783
  }
1383
- return _context24.abrupt("return", {
2784
+ return _context37.abrupt("return", {
1384
2785
  valid: errors.length === 0,
1385
2786
  errors: errors
1386
2787
  });
1387
2788
  case 6:
1388
2789
  case "end":
1389
- return _context24.stop();
2790
+ return _context37.stop();
1390
2791
  }
1391
- }, _callee24);
2792
+ }, _callee37);
1392
2793
  }));
1393
- function validateLocalOrderData(_x19) {
2794
+ function validateLocalOrderData(_x27) {
1394
2795
  return _validateLocalOrderData.apply(this, arguments);
1395
2796
  }
1396
2797
  return validateLocalOrderData;
@@ -1407,6 +2808,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1407
2808
  return "local_order_".concat(timestamp, "_").concat(random);
1408
2809
  }
1409
2810
 
2811
+ /**
2812
+ * 格式化日期时间为 YYYY-MM-DD hh:mm:ss 格式
2813
+ *
2814
+ * @param date 要格式化的日期对象
2815
+ * @returns 格式化后的日期时间字符串
2816
+ */
2817
+ }, {
2818
+ key: "formatDateTime",
2819
+ value: function formatDateTime(date) {
2820
+ var year = date.getFullYear();
2821
+ var month = String(date.getMonth() + 1).padStart(2, '0');
2822
+ var day = String(date.getDate()).padStart(2, '0');
2823
+ var hours = String(date.getHours()).padStart(2, '0');
2824
+ var minutes = String(date.getMinutes()).padStart(2, '0');
2825
+ var seconds = String(date.getSeconds()).padStart(2, '0');
2826
+ return "".concat(year, "-").concat(month, "-").concat(day, " ").concat(hours, ":").concat(minutes, ":").concat(seconds);
2827
+ }
2828
+
1410
2829
  /**
1411
2830
  * 从购物车小计数据中提取金额信息
1412
2831
  */
@@ -1470,31 +2889,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1470
2889
  }, {
1471
2890
  key: "preloadPaymentMethods",
1472
2891
  value: (function () {
1473
- var _preloadPaymentMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2892
+ var _preloadPaymentMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38() {
1474
2893
  var methods;
1475
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1476
- while (1) switch (_context25.prev = _context25.next) {
2894
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
2895
+ while (1) switch (_context38.prev = _context38.next) {
1477
2896
  case 0:
1478
- _context25.prev = 0;
2897
+ _context38.prev = 0;
1479
2898
  console.log('[Checkout] 预加载支付方式...');
1480
- _context25.next = 4;
1481
- return this.store.payment.getPayMethodListAsync();
2899
+ _context38.next = 4;
2900
+ return this.payment.getPayMethodListAsync();
1482
2901
  case 4:
1483
- methods = _context25.sent;
2902
+ methods = _context38.sent;
1484
2903
  this.store.paymentMethods = methods;
1485
2904
  console.log("[Checkout] \u9884\u52A0\u8F7D\u5B8C\u6210\uFF0C\u5171 ".concat(methods.length, " \u79CD\u652F\u4ED8\u65B9\u5F0F"));
1486
- _context25.next = 13;
2905
+ _context38.next = 13;
1487
2906
  break;
1488
2907
  case 9:
1489
- _context25.prev = 9;
1490
- _context25.t0 = _context25["catch"](0);
1491
- console.error('[Checkout] 预加载支付方式失败:', _context25.t0);
2908
+ _context38.prev = 9;
2909
+ _context38.t0 = _context38["catch"](0);
2910
+ console.error('[Checkout] 预加载支付方式失败:', _context38.t0);
1492
2911
  this.store.paymentMethods = [];
1493
2912
  case 13:
1494
2913
  case "end":
1495
- return _context25.stop();
2914
+ return _context38.stop();
1496
2915
  }
1497
- }, _callee25, this, [[0, 9]]);
2916
+ }, _callee38, this, [[0, 9]]);
1498
2917
  }));
1499
2918
  function preloadPaymentMethods() {
1500
2919
  return _preloadPaymentMethods.apply(this, arguments);
@@ -1522,13 +2941,600 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1522
2941
  }, {
1523
2942
  key: "calculatePaidAmount",
1524
2943
  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);
2944
+ if (!this.store.currentOrder) {
2945
+ console.log('[Checkout] calculatePaidAmount: 没有当前订单');
2946
+ return '0.00';
2947
+ }
2948
+ var payments = this.store.currentOrder.payment || [];
2949
+ console.log('[Checkout] calculatePaidAmount: 支付项详情:', {
2950
+ paymentCount: payments.length,
2951
+ payments: payments.map(function (p) {
2952
+ return {
2953
+ uuid: p.uuid,
2954
+ amount: p.amount,
2955
+ code: p.code,
2956
+ status: p.status
2957
+ };
2958
+ })
2959
+ });
2960
+ var paidAmount = payments.filter(function (payment) {
2961
+ return payment.status !== 'voided';
2962
+ }) // 只计算未撤销的支付项
2963
+ .reduce(function (sum, payment) {
2964
+ var amount = parseFloat(payment.amount || '0');
2965
+ console.log("[Checkout] \u8BA1\u7B97\u652F\u4ED8\u9879: ".concat(payment.code, " = ").concat(amount));
2966
+ return sum + amount;
1528
2967
  }, 0);
1529
- return paidAmount.toFixed(2);
2968
+ var result = paidAmount.toFixed(2);
2969
+ console.log('[Checkout] calculatePaidAmount: 计算结果 =', result);
2970
+ return result;
2971
+ }
2972
+
2973
+ /**
2974
+ * 计算剩余未支付金额
2975
+ */
2976
+ }, {
2977
+ key: "calculateRemainingAmount",
2978
+ value: function calculateRemainingAmount() {
2979
+ if (!this.store.currentOrder) {
2980
+ console.log('[Checkout] calculateRemainingAmount: 没有当前订单');
2981
+ return '0.00';
2982
+ }
2983
+ var totalAmount = parseFloat(this.store.currentOrder.total_amount || '0');
2984
+ var paidAmount = parseFloat(this.calculatePaidAmount());
2985
+ var remainingAmount = totalAmount - paidAmount;
2986
+ var result = Math.max(0, remainingAmount).toFixed(2);
2987
+ console.log('[Checkout] calculateRemainingAmount: 计算详情:', {
2988
+ orderUuid: this.store.currentOrder.uuid,
2989
+ totalAmount: totalAmount.toFixed(2),
2990
+ paidAmount: paidAmount.toFixed(2),
2991
+ calculatedRemaining: remainingAmount.toFixed(2),
2992
+ finalResult: result
2993
+ });
2994
+ return result;
2995
+ }
2996
+
2997
+ /**
2998
+ * 更新 stateAmount 为当前剩余未支付金额
2999
+ */
3000
+ }, {
3001
+ key: "updateStateAmountToRemaining",
3002
+ value: (function () {
3003
+ var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
3004
+ var _this$store$currentOr14, remainingAmount, currentStateAmount;
3005
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3006
+ while (1) switch (_context39.prev = _context39.next) {
3007
+ case 0:
3008
+ _context39.prev = 0;
3009
+ remainingAmount = this.calculateRemainingAmount();
3010
+ currentStateAmount = this.store.stateAmount;
3011
+ console.log('[Checkout] updateStateAmountToRemaining: 状态检查:', {
3012
+ calculatedRemainingAmount: remainingAmount,
3013
+ currentStateAmount: currentStateAmount,
3014
+ needsUpdate: remainingAmount !== currentStateAmount,
3015
+ orderUuid: (_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.uuid
3016
+ });
3017
+
3018
+ // 只有当剩余金额与当前 stateAmount 不同时才更新
3019
+ if (!(remainingAmount !== currentStateAmount)) {
3020
+ _context39.next = 11;
3021
+ break;
3022
+ }
3023
+ this.store.stateAmount = remainingAmount;
3024
+
3025
+ // 发出 stateAmount 变更事件
3026
+ _context39.next = 8;
3027
+ return this.core.effects.emit(CheckoutHooks.OnStateAmountChanged, {
3028
+ oldAmount: currentStateAmount,
3029
+ newAmount: remainingAmount,
3030
+ timestamp: Date.now()
3031
+ });
3032
+ case 8:
3033
+ console.log('[Checkout] stateAmount 已自动更新为剩余金额:', {
3034
+ oldAmount: currentStateAmount,
3035
+ newAmount: remainingAmount
3036
+ });
3037
+ _context39.next = 12;
3038
+ break;
3039
+ case 11:
3040
+ console.log('[Checkout] stateAmount 无需更新,当前值已是最新:', {
3041
+ stateAmount: currentStateAmount,
3042
+ remainingAmount: remainingAmount
3043
+ });
3044
+ case 12:
3045
+ _context39.next = 14;
3046
+ return this.checkOrderPaymentCompletion();
3047
+ case 14:
3048
+ _context39.next = 19;
3049
+ break;
3050
+ case 16:
3051
+ _context39.prev = 16;
3052
+ _context39.t0 = _context39["catch"](0);
3053
+ console.error('[Checkout] 更新 stateAmount 为剩余金额失败:', _context39.t0);
3054
+ case 19:
3055
+ case "end":
3056
+ return _context39.stop();
3057
+ }
3058
+ }, _callee39, this, [[0, 16]]);
3059
+ }));
3060
+ function updateStateAmountToRemaining() {
3061
+ return _updateStateAmountToRemaining.apply(this, arguments);
3062
+ }
3063
+ return updateStateAmountToRemaining;
3064
+ }()
3065
+ /**
3066
+ * 检查订单支付是否完成
3067
+ *
3068
+ * 当剩余待付款金额 <= 0 时,触发订单支付完成事件
3069
+ */
3070
+ )
3071
+ }, {
3072
+ key: "checkOrderPaymentCompletion",
3073
+ value: (function () {
3074
+ var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40() {
3075
+ var remainingAmount, remainingValue, _this$store$currentOr15, _this$store$currentOr16, totalAmount, paidAmount, allPaymentsHaveVoucherId;
3076
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3077
+ while (1) switch (_context40.prev = _context40.next) {
3078
+ case 0:
3079
+ _context40.prev = 0;
3080
+ if (this.store.currentOrder) {
3081
+ _context40.next = 3;
3082
+ break;
3083
+ }
3084
+ return _context40.abrupt("return");
3085
+ case 3:
3086
+ remainingAmount = this.calculateRemainingAmount();
3087
+ remainingValue = parseFloat(remainingAmount); // 当剩余金额小于等于0时,认为订单已完成支付
3088
+ if (!(remainingValue <= 0)) {
3089
+ _context40.next = 21;
3090
+ break;
3091
+ }
3092
+ totalAmount = this.store.currentOrder.total_amount;
3093
+ paidAmount = this.calculatePaidAmount();
3094
+ console.log('[Checkout] 检测到订单支付完成:', {
3095
+ orderUuid: this.store.currentOrder.uuid,
3096
+ orderId: this.store.currentOrder.order_id,
3097
+ totalAmount: totalAmount,
3098
+ paidAmount: paidAmount,
3099
+ remainingAmount: remainingAmount,
3100
+ isOrderSynced: this.store.isOrderSynced
3101
+ });
3102
+
3103
+ // 检查是否所有支付项都带有 voucher_id
3104
+ allPaymentsHaveVoucherId = this.store.currentOrder.payment && this.store.currentOrder.payment.length > 0 && this.store.currentOrder.payment.every(function (item) {
3105
+ return item.status !== 'voided' && item.voucher_id;
3106
+ });
3107
+ console.log('[Checkout] 支付项voucher_id检查:', {
3108
+ paymentCount: ((_this$store$currentOr15 = this.store.currentOrder.payment) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.length) || 0,
3109
+ allHaveVoucherId: allPaymentsHaveVoucherId,
3110
+ paymentItems: (_this$store$currentOr16 = this.store.currentOrder.payment) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.map(function (p) {
3111
+ return {
3112
+ uuid: p.uuid,
3113
+ code: p.code,
3114
+ amount: p.amount,
3115
+ voucher_id: p.voucher_id,
3116
+ status: p.status
3117
+ };
3118
+ })
3119
+ });
3120
+
3121
+ // 如果支付完成但订单未同步,需要判断是否同步
3122
+ if (this.store.isOrderSynced) {
3123
+ _context40.next = 19;
3124
+ break;
3125
+ }
3126
+ if (!allPaymentsHaveVoucherId) {
3127
+ _context40.next = 16;
3128
+ break;
3129
+ }
3130
+ console.log('[Checkout] 所有支付项均为代金券类型,跳过订单同步');
3131
+ _context40.next = 19;
3132
+ break;
3133
+ case 16:
3134
+ console.log('[Checkout] 支付完成但订单未同步,开始同步订单到后端...');
3135
+ _context40.next = 19;
3136
+ return this.syncOrderToBackend();
3137
+ case 19:
3138
+ _context40.next = 21;
3139
+ return this.core.effects.emit(CheckoutHooks.OnOrderPaymentCompleted, {
3140
+ orderUuid: this.store.currentOrder.uuid,
3141
+ orderId: this.store.currentOrder.order_id,
3142
+ totalAmount: totalAmount,
3143
+ paidAmount: paidAmount,
3144
+ remainingAmount: remainingAmount,
3145
+ timestamp: Date.now()
3146
+ });
3147
+ case 21:
3148
+ _context40.next = 26;
3149
+ break;
3150
+ case 23:
3151
+ _context40.prev = 23;
3152
+ _context40.t0 = _context40["catch"](0);
3153
+ console.error('[Checkout] 检查订单支付完成状态失败:', _context40.t0);
3154
+ case 26:
3155
+ case "end":
3156
+ return _context40.stop();
3157
+ }
3158
+ }, _callee40, this, [[0, 23]]);
3159
+ }));
3160
+ function checkOrderPaymentCompletion() {
3161
+ return _checkOrderPaymentCompletion.apply(this, arguments);
3162
+ }
3163
+ return checkOrderPaymentCompletion;
3164
+ }()
3165
+ /**
3166
+ * 判断支付方式是否需要同步订单到后端
3167
+ *
3168
+ * 现金支付(CASHMANUAL)和自定义支付不需要同步,其他支付方式需要同步
3169
+ *
3170
+ * @param paymentCode 支付方式代码
3171
+ * @param paymentType 支付方式类型
3172
+ * @returns 是否需要同步订单
3173
+ */
3174
+ )
3175
+ }, {
3176
+ key: "shouldSyncOrderForPayment",
3177
+ value: function shouldSyncOrderForPayment(paymentCode, paymentType) {
3178
+ var codeUpper = (paymentCode === null || paymentCode === void 0 ? void 0 : paymentCode.toUpperCase()) || '';
3179
+ var typeUpper = (paymentType === null || paymentType === void 0 ? void 0 : paymentType.toUpperCase()) || '';
3180
+
3181
+ // 现金支付不需要同步 - 支持多种现金支付识别方式
3182
+ var cashIdentifiers = ['CASHMANUAL', 'CASH', 'MANUAL'];
3183
+ if (cashIdentifiers.some(function (id) {
3184
+ return codeUpper.includes(id) || typeUpper.includes(id);
3185
+ })) {
3186
+ return false;
3187
+ }
3188
+
3189
+ // 标准现金支付代码检查
3190
+ if (paymentCode === PaymentMethodType.Cash || paymentType === PaymentMethodType.Cash) {
3191
+ return false;
3192
+ }
3193
+
3194
+ // 自定义支付不需要同步
3195
+ if (codeUpper.includes('CUSTOM') || typeUpper.includes('CUSTOM')) {
3196
+ return false;
3197
+ }
3198
+
3199
+ // 其他支付方式都需要同步
3200
+ return true;
3201
+ }
3202
+
3203
+ /**
3204
+ * 同步订单到后端
3205
+ *
3206
+ * 调用后端 /order/checkout 接口创建真实订单
3207
+ */
3208
+ /**
3209
+ * 判断订单ID是否为本地生成的虚拟ID
3210
+ *
3211
+ * @param orderId 订单ID
3212
+ * @returns true 表示是虚拟ID,false 表示是真实的后端ID
3213
+ */
3214
+ }, {
3215
+ key: "isVirtualOrderId",
3216
+ value: function isVirtualOrderId(orderId) {
3217
+ return orderId.startsWith('local_order_');
1530
3218
  }
1531
3219
 
3220
+ /**
3221
+ * 同步订单到后端并返回真实订单ID
3222
+ *
3223
+ * @param isManual 是否为手动同步,默认为 false
3224
+ * @param customPaymentItems 自定义支付项列表,如果提供则使用此列表而不是从数据库获取
3225
+ * @returns 后端返回的真实订单ID
3226
+ */
3227
+ }, {
3228
+ key: "syncOrderToBackendWithReturn",
3229
+ value: (function () {
3230
+ var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
3231
+ var _this$store$currentCu2, _this$store$currentOr17, _this$store$currentOr18;
3232
+ var isManual,
3233
+ customPaymentItems,
3234
+ syncType,
3235
+ currentOrderId,
3236
+ hasRealOrderId,
3237
+ isUpdateOperation,
3238
+ reason,
3239
+ operation,
3240
+ paymentItems,
3241
+ orderParams,
3242
+ checkoutResponse,
3243
+ realOrderId,
3244
+ _data3,
3245
+ extractedOrderId,
3246
+ updatedOrder,
3247
+ beforeManualUpdate,
3248
+ finalOrderId,
3249
+ finalIsVirtual,
3250
+ _args41 = arguments;
3251
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3252
+ while (1) switch (_context41.prev = _context41.next) {
3253
+ case 0:
3254
+ isManual = _args41.length > 0 && _args41[0] !== undefined ? _args41[0] : false;
3255
+ customPaymentItems = _args41.length > 1 ? _args41[1] : undefined;
3256
+ if (!(!this.store.localOrderData || !this.store.currentOrder)) {
3257
+ _context41.next = 4;
3258
+ break;
3259
+ }
3260
+ throw new Error('缺少必要的订单数据,无法同步到后端');
3261
+ case 4:
3262
+ syncType = isManual ? '手动' : '自动'; // 判断是创建订单还是更新订单
3263
+ currentOrderId = this.store.currentOrder.order_id;
3264
+ hasRealOrderId = currentOrderId && !this.isVirtualOrderId(currentOrderId); // 更准确的判断:优先考虑同步状态
3265
+ // 1. 如果订单已经同步过,无论订单ID是什么,都应该是更新操作(防止ID被意外重置)
3266
+ // 2. 如果订单未同步但有真实订单ID,也认为是更新操作
3267
+ // 3. 其他情况都是创建操作
3268
+ isUpdateOperation = false;
3269
+ reason = '';
3270
+ if (this.store.isOrderSynced) {
3271
+ isUpdateOperation = true;
3272
+ reason = '订单已同步过';
3273
+ } else if (hasRealOrderId) {
3274
+ isUpdateOperation = true;
3275
+ reason = '有真实订单ID';
3276
+ } else {
3277
+ isUpdateOperation = false;
3278
+ reason = '既未同步也无真实ID';
3279
+ }
3280
+ operation = isUpdateOperation ? '更新' : '创建';
3281
+ console.log('[Checkout] 操作类型判断详情:', {
3282
+ currentOrderId: currentOrderId,
3283
+ hasRealOrderId: hasRealOrderId,
3284
+ isOrderSynced: this.store.isOrderSynced,
3285
+ isManual: isManual,
3286
+ reason: reason,
3287
+ finalDecision: operation
3288
+ });
3289
+ console.log("[Checkout] \u5F00\u59CB".concat(syncType).concat(operation, "\u8BA2\u5355\u5230\u540E\u7AEF..."), {
3290
+ currentOrderId: currentOrderId,
3291
+ isVirtualId: this.isVirtualOrderId(currentOrderId || ''),
3292
+ operation: operation,
3293
+ orderUuid: this.store.currentOrder.uuid,
3294
+ isOrderSynced: this.store.isOrderSynced
3295
+ });
3296
+
3297
+ // 获取当前订单的支付项
3298
+ _context41.t0 = customPaymentItems;
3299
+ if (_context41.t0) {
3300
+ _context41.next = 18;
3301
+ break;
3302
+ }
3303
+ _context41.next = 17;
3304
+ return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
3305
+ case 17:
3306
+ _context41.t0 = _context41.sent;
3307
+ case 18:
3308
+ paymentItems = _context41.t0;
3309
+ console.log('[Checkout] 获取到支付项:', {
3310
+ count: paymentItems.length,
3311
+ isCustomFiltered: !!customPaymentItems,
3312
+ methods: paymentItems.map(function (p) {
3313
+ return p.code;
3314
+ }),
3315
+ totalAmount: paymentItems.reduce(function (sum, p) {
3316
+ return sum + parseFloat(p.amount);
3317
+ }, 0).toFixed(2),
3318
+ paymentDetails: paymentItems.map(function (p) {
3319
+ var _p$metadata;
3320
+ return {
3321
+ uuid: p.uuid,
3322
+ code: p.code,
3323
+ amount: p.amount,
3324
+ uniquePaymentNumber: (_p$metadata = p.metadata) === null || _p$metadata === void 0 ? void 0 : _p$metadata.unique_payment_number,
3325
+ voucherId: p.voucher_id
3326
+ };
3327
+ })
3328
+ });
3329
+
3330
+ // 构造订单参数,直接使用 localOrderData 中已处理好的数据
3331
+ orderParams = _objectSpread(_objectSpread({}, this.store.localOrderData), {}, {
3332
+ type: this.store.localOrderData.type,
3333
+ platform: this.store.localOrderData.platform,
3334
+ payments: paymentItems,
3335
+ // 添加支付项
3336
+ customer_id: (_this$store$currentCu2 = this.store.currentCustomer) === null || _this$store$currentCu2 === void 0 ? void 0 : _this$store$currentCu2.customer_id,
3337
+ // 添加客户ID
3338
+ is_price_include_tax: this.otherParams.is_price_include_tax,
3339
+ // core 有
3340
+ tax_title: this.otherParams.tax_title,
3341
+ // core 没有
3342
+ tax_rate: this.otherParams.tax_rate,
3343
+ // core 有
3344
+ tax_country_code: this.otherParams.tax_country_code,
3345
+ // core 没有
3346
+ currency_code: this.otherParams.currency_code,
3347
+ currency_symbol: this.otherParams.currency_symbol,
3348
+ currency_format: this.otherParams.currency_format,
3349
+ is_deposit: ((_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.is_deposit) || 0,
3350
+ deposit_amount: ((_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.deposit_amount) || '0.00',
3351
+ // surcharge_fee: this.otherParams.surcharge_fee,
3352
+ // surcharges: ,
3353
+ note: this.store.localOrderData.shop_note
3354
+ // deposit_amount:
3355
+ }); // 如果是更新操作,需要在参数中包含真实的订单ID
3356
+
3357
+ if (isUpdateOperation) {
3358
+ // 如果当前订单ID是虚拟ID,但订单已同步过,可能存在数据不一致的问题
3359
+ if (this.isVirtualOrderId(currentOrderId)) {
3360
+ console.error('[Checkout] 数据不一致警告:更新操作但订单ID仍为虚拟ID!', {
3361
+ currentOrderId: currentOrderId,
3362
+ isOrderSynced: this.store.isOrderSynced,
3363
+ reason: reason,
3364
+ orderUuid: this.store.currentOrder.uuid
3365
+ });
3366
+
3367
+ // 🔧 尝试数据修复:先不包含order_id,让后端创建
3368
+ // 这样至少能保证功能正常,后续会正确设置真实订单ID
3369
+ console.log('[Checkout] 尝试数据修复:暂时不包含order_id,让后端处理');
3370
+ console.log('[Checkout] 注意:这次调用将作为创建操作处理,但后续会修复数据一致性');
3371
+ } else {
3372
+ orderParams.order_id = currentOrderId;
3373
+ console.log("[Checkout] \u66F4\u65B0\u8BA2\u5355\u64CD\u4F5C\uFF0C\u5305\u542B\u8BA2\u5355ID: ".concat(currentOrderId));
3374
+ }
3375
+ } else {
3376
+ console.log('[Checkout] 创建新订单操作');
3377
+ }
3378
+
3379
+ // 调用 Order 模块的专用 createOrderByCheckout 方法
3380
+ _context41.next = 24;
3381
+ return this.order.createOrderByCheckout(orderParams);
3382
+ case 24:
3383
+ checkoutResponse = _context41.sent;
3384
+ console.log('[Checkout] 后端返回的响应数据:', {
3385
+ status: checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.status,
3386
+ code: checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.code,
3387
+ message: checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.message,
3388
+ data: checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.data
3389
+ });
3390
+ if (!isUpdateOperation) {
3391
+ _context41.next = 31;
3392
+ break;
3393
+ }
3394
+ // 更新操作:使用现有的订单ID
3395
+ realOrderId = currentOrderId;
3396
+ console.log("[Checkout] \u8BA2\u5355\u66F4\u65B0\u6210\u529F\uFF0C\u8BA2\u5355ID: ".concat(realOrderId));
3397
+ _context41.next = 52;
3398
+ break;
3399
+ case 31:
3400
+ // 创建操作:从响应中提取新的订单ID
3401
+ extractedOrderId = checkoutResponse === null || checkoutResponse === void 0 || (_data3 = checkoutResponse.data) === null || _data3 === void 0 ? void 0 : _data3.order_id; // 如果data.order_id不存在,尝试直接从根级获取
3402
+ if (!extractedOrderId) {
3403
+ extractedOrderId = checkoutResponse === null || checkoutResponse === void 0 ? void 0 : checkoutResponse.order_id;
3404
+ }
3405
+
3406
+ // 确保转换为字符串类型
3407
+ if (extractedOrderId !== undefined && extractedOrderId !== null) {
3408
+ extractedOrderId = String(extractedOrderId);
3409
+ }
3410
+ if (extractedOrderId) {
3411
+ _context41.next = 36;
3412
+ break;
3413
+ }
3414
+ throw new Error('后端返回的订单信息中未包含订单ID');
3415
+ case 36:
3416
+ realOrderId = extractedOrderId;
3417
+ console.log('[Checkout] 订单创建成功,真实订单ID:', realOrderId);
3418
+
3419
+ // 替换虚拟订单ID为真实订单ID
3420
+ console.log('[Checkout] 准备替换订单ID:', {
3421
+ orderUuid: this.store.currentOrder.uuid,
3422
+ oldOrderId: this.store.currentOrder.order_id,
3423
+ newOrderId: realOrderId
3424
+ });
3425
+ _context41.prev = 39;
3426
+ _context41.next = 42;
3427
+ return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, realOrderId);
3428
+ case 42:
3429
+ updatedOrder = _context41.sent;
3430
+ console.log('[Checkout] Payment模块替换订单ID结果:', {
3431
+ wasSuccessful: !!updatedOrder,
3432
+ returnedOrderId: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.order_id,
3433
+ expectedOrderId: realOrderId
3434
+ });
3435
+ if (updatedOrder) {
3436
+ console.log('[Checkout] Payment模块返回的更新后订单:', {
3437
+ uuid: updatedOrder.uuid,
3438
+ orderId: updatedOrder.order_id,
3439
+ totalAmount: updatedOrder.total_amount
3440
+ });
3441
+ this.store.currentOrder = updatedOrder;
3442
+ console.log('[Checkout] 订单ID替换成功,当前订单ID:', this.store.currentOrder.order_id);
3443
+ } else {
3444
+ console.error('[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换');
3445
+
3446
+ // 如果替换失败,手动更新订单ID
3447
+ beforeManualUpdate = this.store.currentOrder.order_id;
3448
+ this.store.currentOrder.order_id = realOrderId;
3449
+ console.log('[Checkout] 手动设置订单ID:', {
3450
+ 替换前: beforeManualUpdate,
3451
+ 替换后: this.store.currentOrder.order_id,
3452
+ 目标ID: realOrderId
3453
+ });
3454
+ }
3455
+ _context41.next = 52;
3456
+ break;
3457
+ case 47:
3458
+ _context41.prev = 47;
3459
+ _context41.t1 = _context41["catch"](39);
3460
+ console.error('[Checkout] 调用Payment模块替换订单ID时发生错误:', _context41.t1);
3461
+
3462
+ // 发生错误时也进行手动替换
3463
+ this.store.currentOrder.order_id = realOrderId;
3464
+ console.log('[Checkout] 错误恢复:手动设置订单ID:', realOrderId);
3465
+ case 52:
3466
+ // 标记订单已同步
3467
+ this.store.isOrderSynced = true;
3468
+
3469
+ // 触发订单同步完成事件
3470
+ _context41.next = 55;
3471
+ return this.core.effects.emit(CheckoutHooks.OnOrderSynced, {
3472
+ orderUuid: this.store.currentOrder.uuid,
3473
+ realOrderId: realOrderId,
3474
+ virtualOrderId: this.store.currentOrder.order_id,
3475
+ timestamp: Date.now(),
3476
+ isManual: isManual,
3477
+ response: checkoutResponse
3478
+ });
3479
+ case 55:
3480
+ // 验证最终状态
3481
+ finalOrderId = this.store.currentOrder.order_id;
3482
+ finalIsVirtual = this.isVirtualOrderId(finalOrderId || '');
3483
+ console.log("[Checkout] ".concat(syncType).concat(operation, "\u8BA2\u5355\u5230\u540E\u7AEF\u5B8C\u6210"), {
3484
+ 返回的订单ID: realOrderId,
3485
+ 当前存储的订单ID: finalOrderId,
3486
+ 是否还是虚拟ID: finalIsVirtual,
3487
+ 是否同步: this.store.isOrderSynced
3488
+ });
3489
+
3490
+ // 如果最终状态不正确,发出警告
3491
+ if (finalIsVirtual && !isUpdateOperation) {
3492
+ console.warn('[Checkout] 警告:订单创建后,当前订单ID仍然是虚拟ID,可能存在问题');
3493
+ }
3494
+
3495
+ // 返回真实订单ID
3496
+ return _context41.abrupt("return", realOrderId);
3497
+ case 60:
3498
+ case "end":
3499
+ return _context41.stop();
3500
+ }
3501
+ }, _callee41, this, [[39, 47]]);
3502
+ }));
3503
+ function syncOrderToBackendWithReturn() {
3504
+ return _syncOrderToBackendWithReturn.apply(this, arguments);
3505
+ }
3506
+ return syncOrderToBackendWithReturn;
3507
+ }())
3508
+ }, {
3509
+ key: "syncOrderToBackend",
3510
+ value: function () {
3511
+ var _syncOrderToBackend = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42() {
3512
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3513
+ while (1) switch (_context42.prev = _context42.next) {
3514
+ case 0:
3515
+ _context42.prev = 0;
3516
+ _context42.next = 3;
3517
+ return this.syncOrderToBackendWithReturn(false);
3518
+ case 3:
3519
+ _context42.next = 10;
3520
+ break;
3521
+ case 5:
3522
+ _context42.prev = 5;
3523
+ _context42.t0 = _context42["catch"](0);
3524
+ console.error('[Checkout] 同步订单到后端失败:', _context42.t0);
3525
+ _context42.next = 10;
3526
+ return this.handleError(new Error("\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context42.t0 instanceof Error ? _context42.t0.message : String(_context42.t0))), CheckoutErrorType.OrderCreationFailed);
3527
+ case 10:
3528
+ case "end":
3529
+ return _context42.stop();
3530
+ }
3531
+ }, _callee42, this, [[0, 5]]);
3532
+ }));
3533
+ function syncOrderToBackend() {
3534
+ return _syncOrderToBackend.apply(this, arguments);
3535
+ }
3536
+ return syncOrderToBackend;
3537
+ }()
1532
3538
  /**
1533
3539
  * 获取状态消息
1534
3540
  */
@@ -1559,32 +3565,178 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1559
3565
  return '';
1560
3566
  }
1561
3567
  }
3568
+ }, {
3569
+ key: "setOtherParams",
3570
+ value: function () {
3571
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
3572
+ var _ref3,
3573
+ _ref3$cover,
3574
+ cover,
3575
+ _args43 = arguments;
3576
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3577
+ while (1) switch (_context43.prev = _context43.next) {
3578
+ case 0:
3579
+ _ref3 = _args43.length > 1 && _args43[1] !== undefined ? _args43[1] : {}, _ref3$cover = _ref3.cover, cover = _ref3$cover === void 0 ? false : _ref3$cover;
3580
+ if (cover) {
3581
+ this.otherParams = params;
3582
+ } else {
3583
+ this.otherParams = _objectSpread(_objectSpread({}, this.otherParams), params);
3584
+ }
3585
+ case 2:
3586
+ case "end":
3587
+ return _context43.stop();
3588
+ }
3589
+ }, _callee43, this);
3590
+ }));
3591
+ function setOtherParams(_x28) {
3592
+ return _setOtherParams.apply(this, arguments);
3593
+ }
3594
+ return setOtherParams;
3595
+ }()
3596
+ /**
3597
+ * 通过订单ID编辑订单备注
3598
+ *
3599
+ * 用于修改已同步到后端的订单备注,通常在支付成功后的弹窗中使用
3600
+ *
3601
+ * @param orderId 后端订单ID
3602
+ * @param note 新的订单备注
3603
+ * @returns 修改结果
3604
+ */
3605
+ }, {
3606
+ key: "editOrderNoteByOrderIdAsync",
3607
+ value: (function () {
3608
+ var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(orderId, note) {
3609
+ var response, previousNote, errorMessage, _errorMessage;
3610
+ return _regeneratorRuntime().wrap(function _callee44$(_context44) {
3611
+ while (1) switch (_context44.prev = _context44.next) {
3612
+ case 0:
3613
+ _context44.prev = 0;
3614
+ console.log('[Checkout] 开始编辑订单备注:', {
3615
+ orderId: orderId,
3616
+ note: note,
3617
+ noteLength: note.length
3618
+ });
3619
+
3620
+ // 参数验证
3621
+ if (orderId) {
3622
+ _context44.next = 4;
3623
+ break;
3624
+ }
3625
+ return _context44.abrupt("return", {
3626
+ success: false,
3627
+ message: '订单ID不能为空',
3628
+ orderId: orderId
3629
+ });
3630
+ case 4:
3631
+ _context44.next = 6;
3632
+ return this.request.put("/shop/order/order/".concat(orderId, "/note"), {
3633
+ note: note
3634
+ });
3635
+ case 6:
3636
+ response = _context44.sent;
3637
+ console.log('[Checkout] 订单备注编辑响应:', {
3638
+ orderId: orderId,
3639
+ status: response.status,
3640
+ message: response.message,
3641
+ response: response
3642
+ });
3643
+
3644
+ // 检查响应状态
3645
+ if (!(response.status === true || response.status === 200)) {
3646
+ _context44.next = 19;
3647
+ break;
3648
+ }
3649
+ console.log("[Checkout] \u8BA2\u5355 ".concat(orderId, " \u5907\u6CE8\u4FEE\u6539\u6210\u529F"));
3650
+
3651
+ // 如果当前订单就是被修改的订单,同时更新本地状态
3652
+ if (!(this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId)))) {
3653
+ _context44.next = 16;
3654
+ break;
3655
+ }
3656
+ console.log('[Checkout] 更新本地订单备注状态');
3657
+
3658
+ // 获取修改前的备注用于事件
3659
+ previousNote = this.getOrderNote(); // 更新本地订单数据中的备注
3660
+ if (this.store.localOrderData) {
3661
+ this.store.localOrderData.shop_note = note;
3662
+ }
3663
+
3664
+ // 触发订单备注变更事件
3665
+ _context44.next = 16;
3666
+ return this.core.effects.emit(CheckoutHooks.OnOrderNoteChanged, {
3667
+ orderUuid: this.store.currentOrder.uuid,
3668
+ oldNote: previousNote,
3669
+ newNote: note,
3670
+ timestamp: Date.now()
3671
+ });
3672
+ case 16:
3673
+ return _context44.abrupt("return", {
3674
+ success: true,
3675
+ message: response.message || '订单备注修改成功',
3676
+ orderId: orderId
3677
+ });
3678
+ case 19:
3679
+ // API返回失败状态
3680
+ errorMessage = response.message || '订单备注修改失败';
3681
+ console.error("[Checkout] \u8BA2\u5355 ".concat(orderId, " \u5907\u6CE8\u4FEE\u6539\u5931\u8D25:"), errorMessage);
3682
+ return _context44.abrupt("return", {
3683
+ success: false,
3684
+ message: errorMessage,
3685
+ orderId: orderId
3686
+ });
3687
+ case 22:
3688
+ _context44.next = 29;
3689
+ break;
3690
+ case 24:
3691
+ _context44.prev = 24;
3692
+ _context44.t0 = _context44["catch"](0);
3693
+ console.error('[Checkout] 编辑订单备注失败:', _context44.t0);
3694
+ _errorMessage = _context44.t0 instanceof Error ? _context44.t0.message : '网络错误或服务器异常';
3695
+ return _context44.abrupt("return", {
3696
+ success: false,
3697
+ message: "\u7F16\u8F91\u8BA2\u5355\u5907\u6CE8\u5931\u8D25: ".concat(_errorMessage),
3698
+ orderId: orderId
3699
+ });
3700
+ case 29:
3701
+ case "end":
3702
+ return _context44.stop();
3703
+ }
3704
+ }, _callee44, this, [[0, 24]]);
3705
+ }));
3706
+ function editOrderNoteByOrderIdAsync(_x29, _x30) {
3707
+ return _editOrderNoteByOrderIdAsync.apply(this, arguments);
3708
+ }
3709
+ return editOrderNoteByOrderIdAsync;
3710
+ }())
1562
3711
  }, {
1563
3712
  key: "destroy",
1564
3713
  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) {
3714
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45() {
3715
+ var _this$order, _this$order$destroy, _this$payment, _this$payment$destroy;
3716
+ return _regeneratorRuntime().wrap(function _callee45$(_context45) {
3717
+ while (1) switch (_context45.prev = _context45.next) {
1569
3718
  case 0:
3719
+ // 清理钱包模块的所有缓存数据
3720
+ this.payment.wallet.clearAllCache();
3721
+
1570
3722
  // 清理事件监听
1571
3723
  this.core.effects.offByModuleDestroy(this.name);
1572
3724
 
1573
3725
  // 销毁子模块
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:
3726
+ _context45.next = 4;
3727
+ 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);
3728
+ case 4:
3729
+ _context45.next = 6;
3730
+ 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);
3731
+ case 6:
1580
3732
  // 取消注册模块
1581
3733
  this.core.unregisterModule(this);
1582
3734
  console.log('[Checkout] 已销毁');
1583
- case 7:
3735
+ case 8:
1584
3736
  case "end":
1585
- return _context26.stop();
3737
+ return _context45.stop();
1586
3738
  }
1587
- }, _callee26, this);
3739
+ }, _callee45, this);
1588
3740
  }));
1589
3741
  function destroy() {
1590
3742
  return _destroy.apply(this, arguments);