@pisell/pisellos 0.10.8 → 0.10.9

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 (98) hide show
  1. package/dist/core/index.js +0 -1
  2. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
  3. package/dist/model/strategy/adapter/dataVariant/evaluator.js +287 -101
  4. package/dist/model/strategy/adapter/dataVariant/type.d.ts +25 -0
  5. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  6. package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -2
  7. package/dist/model/strategy/adapter/walletPass/type.d.ts +5 -0
  8. package/dist/model/strategy/adapter/walletPass/utils.js +57 -26
  9. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +7 -3
  10. package/dist/modules/BookingContext/utils/productExtend.js +5 -9
  11. package/dist/modules/BookingContext/utils/timeSlices.js +24 -3
  12. package/dist/modules/Customer/index.d.ts +4 -0
  13. package/dist/modules/Customer/index.js +91 -59
  14. package/dist/modules/Customer/types.d.ts +2 -0
  15. package/dist/modules/Discount/index.d.ts +2 -0
  16. package/dist/modules/Discount/index.js +38 -5
  17. package/dist/modules/Discount/types.d.ts +11 -0
  18. package/dist/modules/Order/index.d.ts +20 -1
  19. package/dist/modules/Order/index.js +976 -730
  20. package/dist/modules/Order/types.d.ts +6 -1
  21. package/dist/modules/Order/utils/virtualSettlement.d.ts +56 -0
  22. package/dist/modules/Order/utils/virtualSettlement.js +271 -0
  23. package/dist/modules/Order/utils.js +89 -48
  24. package/dist/modules/Payment/types.d.ts +2 -0
  25. package/dist/modules/Payment/utils.js +4 -1
  26. package/dist/modules/Payment/walletpass.d.ts +11 -0
  27. package/dist/modules/Payment/walletpass.js +235 -60
  28. package/dist/modules/Product/types.d.ts +23 -0
  29. package/dist/modules/ProductList/index.d.ts +15 -2
  30. package/dist/modules/ProductList/index.js +92 -13
  31. package/dist/modules/SalesSummary/index.d.ts +1 -0
  32. package/dist/modules/SalesSummary/index.js +4 -3
  33. package/dist/modules/SalesSummary/types.d.ts +1 -0
  34. package/dist/modules/SalesSummary/utils.d.ts +1 -0
  35. package/dist/modules/SalesSummary/utils.js +21 -1
  36. package/dist/server/index.d.ts +9 -0
  37. package/dist/server/index.js +90 -58
  38. package/dist/server/modules/order/index.d.ts +1 -0
  39. package/dist/server/modules/order/index.js +252 -94
  40. package/dist/server/utils/small-ticket.js +2 -1
  41. package/dist/solution/BaseSales/index.d.ts +26 -2
  42. package/dist/solution/BaseSales/index.js +1310 -931
  43. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  44. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +78 -12
  45. package/dist/solution/BookingByStep/index.d.ts +3 -3
  46. package/dist/solution/BookingTicket/index.d.ts +5 -1
  47. package/dist/solution/BookingTicket/index.js +221 -159
  48. package/dist/solution/BookingTicket/utils/addProductDecision.js +2 -1
  49. package/dist/solution/ScanOrder/index.js +25 -64
  50. package/lib/core/index.js +0 -1
  51. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
  52. package/lib/model/strategy/adapter/dataVariant/evaluator.js +170 -7
  53. package/lib/model/strategy/adapter/dataVariant/type.d.ts +25 -0
  54. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
  55. package/lib/model/strategy/adapter/walletPass/type.d.ts +5 -0
  56. package/lib/model/strategy/adapter/walletPass/utils.js +62 -11
  57. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +3 -0
  58. package/lib/modules/BookingContext/utils/productExtend.js +4 -3
  59. package/lib/modules/BookingContext/utils/timeSlices.js +18 -3
  60. package/lib/modules/Customer/index.d.ts +4 -0
  61. package/lib/modules/Customer/index.js +11 -0
  62. package/lib/modules/Customer/types.d.ts +2 -0
  63. package/lib/modules/Discount/index.d.ts +2 -0
  64. package/lib/modules/Discount/index.js +37 -3
  65. package/lib/modules/Discount/types.d.ts +11 -0
  66. package/lib/modules/Order/index.d.ts +20 -1
  67. package/lib/modules/Order/index.js +393 -128
  68. package/lib/modules/Order/types.d.ts +6 -1
  69. package/lib/modules/Order/utils/virtualSettlement.d.ts +56 -0
  70. package/lib/modules/Order/utils/virtualSettlement.js +300 -0
  71. package/lib/modules/Order/utils.js +65 -21
  72. package/lib/modules/Payment/types.d.ts +2 -0
  73. package/lib/modules/Payment/utils.js +5 -1
  74. package/lib/modules/Payment/walletpass.d.ts +11 -0
  75. package/lib/modules/Payment/walletpass.js +198 -17
  76. package/lib/modules/Product/types.d.ts +23 -0
  77. package/lib/modules/ProductList/index.d.ts +15 -2
  78. package/lib/modules/ProductList/index.js +85 -3
  79. package/lib/modules/SalesSummary/index.d.ts +1 -0
  80. package/lib/modules/SalesSummary/index.js +10 -2
  81. package/lib/modules/SalesSummary/types.d.ts +1 -0
  82. package/lib/modules/SalesSummary/utils.d.ts +1 -0
  83. package/lib/modules/SalesSummary/utils.js +25 -1
  84. package/lib/server/index.d.ts +9 -0
  85. package/lib/server/index.js +54 -14
  86. package/lib/server/modules/order/index.d.ts +1 -0
  87. package/lib/server/modules/order/index.js +66 -2
  88. package/lib/server/utils/small-ticket.js +1 -1
  89. package/lib/solution/BaseSales/index.d.ts +26 -2
  90. package/lib/solution/BaseSales/index.js +261 -23
  91. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  92. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +61 -11
  93. package/lib/solution/BookingByStep/index.d.ts +3 -3
  94. package/lib/solution/BookingTicket/index.d.ts +5 -1
  95. package/lib/solution/BookingTicket/index.js +30 -2
  96. package/lib/solution/BookingTicket/utils/addProductDecision.js +2 -1
  97. package/lib/solution/ScanOrder/index.js +17 -54
  98. package/package.json +1 -1
@@ -43,6 +43,7 @@ import { hasManualProductDiscountFlag, syncManualProductDiscountProductNum } fro
43
43
  import { expandHydratedProductsForDiscountCollection, restoreHydratedBundleDiscounts } from "./utils/bundleDiscountHydration";
44
44
  import { getOrderCollectionPersistentId, getOrderCollectionUid, normalizeOrderCollections, repairDuplicateProductLineIdentities as repairDuplicateOrderProductLineIdentities, setOrderCollectionUid } from "./utils/orderCollectionIdentity";
45
45
  import { consolidateDiscountFreeProductLines, ensureUniqueProductLineUids } from "./utils/discountProductLineIdentity";
46
+ import { applyTempOrderSettlementState, getSelectedSettlementSnapshot, getSettlementKey, getTempOrderSettlementKey, getTempOrderSettlementSnapshot, isVirtualSettlementOrder, normalizeVirtualSettlementOrderProduct, normalizeVirtualSettlementProducts, OrderSettlementConflictError, releaseTempOrderSettlementState, VirtualCurrencyAssetNotFoundError, VirtualCurrencyBalanceError } from "./utils/virtualSettlement";
46
47
  import { DiscountModule } from "../Discount";
47
48
  import { RulesModule } from "../Rules";
48
49
  import { UnavailableReason } from "../Rules/types";
@@ -339,6 +340,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
339
340
  this.store.tempOrder = null;
340
341
  this.store.summary = createEmptySummary();
341
342
  this.store.availableWalletIds = [];
343
+ this.store.virtualCurrencyList = [];
342
344
  this.store.lastOrderInfo = undefined;
343
345
  this.store.syncState = undefined;
344
346
  this.store.discountList = [];
@@ -351,6 +353,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
351
353
  if (!Array.isArray(this.store.availableWalletIds)) {
352
354
  this.store.availableWalletIds = [];
353
355
  }
356
+ if (!Array.isArray(this.store.virtualCurrencyList)) {
357
+ this.store.virtualCurrencyList = [];
358
+ }
354
359
  this.request = this.core.getPlugin('request');
355
360
  appPlugin = this.core.getPlugin('app');
356
361
  if (!appPlugin) {
@@ -366,7 +371,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
366
371
  this.otherParams = otherParams;
367
372
  this.registerDiscountModules(options);
368
373
  this.logInfo('OrderModule initialized successfully');
369
- case 20:
374
+ case 21:
370
375
  case "end":
371
376
  return _context.stop();
372
377
  }
@@ -559,6 +564,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
559
564
  with_wallet_pass_holder: 1,
560
565
  with_available_wallet_flag: 1,
561
566
  with_available_wallet_pass_flag: 1,
567
+ with_virtual_currency: 1,
562
568
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
563
569
  }, orderId ? {
564
570
  order_id: orderId
@@ -567,8 +573,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
567
573
  prepareConfigResult = _context3.sent;
568
574
  discountList = prepareConfigResult === null || prepareConfigResult === void 0 ? void 0 : prepareConfigResult.discountList;
569
575
  this.store.availableWalletIds = (prepareConfigResult === null || prepareConfigResult === void 0 ? void 0 : prepareConfigResult.availableWalletIds) || [];
576
+ this.store.virtualCurrencyList = (prepareConfigResult === null || prepareConfigResult === void 0 ? void 0 : prepareConfigResult.virtualCurrencyList) || [];
570
577
  if (!discountList) {
571
- _context3.next = 18;
578
+ _context3.next = 19;
572
579
  break;
573
580
  }
574
581
  currentDiscountList = ((_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 ? void 0 : _this$store$discount2.getDiscountList()) || [];
@@ -589,17 +596,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
589
596
  return true;
590
597
  });
591
598
  mergedDiscountList = [].concat(_toConsumableArray(currentEditDiscounts), _toConsumableArray(currentScanDiscounts), _toConsumableArray(runtimeDiscounts));
592
- _context3.next = 16;
599
+ _context3.next = 17;
593
600
  return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.setOriginalDiscountList(mergedDiscountList);
594
- case 16:
595
- _context3.next = 18;
601
+ case 17:
602
+ _context3.next = 19;
596
603
  return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.setDiscountList(mergedDiscountList);
597
- case 18:
604
+ case 19:
598
605
  if (params.apply !== false && (_this$store$tempOrder2 = this.store.tempOrder) !== null && _this$store$tempOrder2 !== void 0 && (_this$store$tempOrder2 = _this$store$tempOrder2.products) !== null && _this$store$tempOrder2 !== void 0 && _this$store$tempOrder2.length) {
599
606
  this.applyDiscount();
600
607
  }
601
608
  return _context3.abrupt("return", this.getDiscountList());
602
- case 20:
609
+ case 21:
603
610
  case "end":
604
611
  return _context3.stop();
605
612
  }
@@ -621,6 +628,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
621
628
  value: function getAvailableWalletIds() {
622
629
  return Array.isArray(this.store.availableWalletIds) ? _toConsumableArray(this.store.availableWalletIds) : [];
623
630
  }
631
+ }, {
632
+ key: "getVirtualCurrencyList",
633
+ value: function getVirtualCurrencyList() {
634
+ return cloneDeep(this.store.virtualCurrencyList || []);
635
+ }
624
636
  }, {
625
637
  key: "syncScannedDiscountsToOriginalDiscountList",
626
638
  value: function () {
@@ -713,26 +725,39 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
713
725
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
714
726
  while (1) switch (_context6.prev = _context6.next) {
715
727
  case 0:
716
- _context6.next = 2;
728
+ if (!this.isActiveVirtualSettlementOrder(this.store.tempOrder)) {
729
+ _context6.next = 2;
730
+ break;
731
+ }
732
+ return _context6.abrupt("return", {
733
+ type: 'clientCalc',
734
+ isAvailable: false,
735
+ isAccepted: false,
736
+ discountList: [],
737
+ scannedDiscountList: [],
738
+ unavailableReason: UnavailableReason.ProductNotApplicable
739
+ });
740
+ case 2:
741
+ _context6.next = 4;
717
742
  return (_this$store$discount11 = this.store.discount) === null || _this$store$discount11 === void 0 ? void 0 : _this$store$discount11.batchSearch(code, {
718
743
  customerId: customerId
719
744
  });
720
- case 2:
745
+ case 4:
721
746
  _context6.t0 = _context6.sent;
722
747
  if (_context6.t0) {
723
- _context6.next = 5;
748
+ _context6.next = 7;
724
749
  break;
725
750
  }
726
751
  _context6.t0 = {
727
752
  discountList: [],
728
753
  unavailableReasonKey: null
729
754
  };
730
- case 5:
755
+ case 7:
731
756
  resultDiscountWithReason = _context6.t0;
732
757
  resultDiscountList = resultDiscountWithReason.discountList, unavailableReasonKey = resultDiscountWithReason.unavailableReasonKey;
733
758
  rulesModule = this.store.rules;
734
759
  if (rulesModule) {
735
- _context6.next = 10;
760
+ _context6.next = 12;
736
761
  break;
737
762
  }
738
763
  return _context6.abrupt("return", {
@@ -743,9 +768,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
743
768
  scannedDiscountList: resultDiscountList,
744
769
  unavailableReason: UnavailableReason.Unknown
745
770
  });
746
- case 10:
771
+ case 12:
747
772
  if (resultDiscountList.length) {
748
- _context6.next = 12;
773
+ _context6.next = 14;
749
774
  break;
750
775
  }
751
776
  return _context6.abrupt("return", {
@@ -756,7 +781,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
756
781
  scannedDiscountList: resultDiscountList,
757
782
  unavailableReasonKey: unavailableReasonKey
758
783
  });
759
- case 12:
784
+ case 14:
760
785
  withScanList = resultDiscountList.map(function (item) {
761
786
  return _objectSpread(_objectSpread({}, item), {}, {
762
787
  isScan: true
@@ -770,12 +795,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
770
795
  return m.id === n.id;
771
796
  });
772
797
  }))) {
773
- _context6.next = 18;
798
+ _context6.next = 20;
774
799
  break;
775
800
  }
776
- _context6.next = 17;
801
+ _context6.next = 19;
777
802
  return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
778
- case 17:
803
+ case 19:
779
804
  return _context6.abrupt("return", {
780
805
  type: 'clientCalc',
781
806
  isAvailable: true,
@@ -783,7 +808,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
783
808
  discountList: this.getDiscountList(),
784
809
  scannedDiscountList: resultDiscountList
785
810
  });
786
- case 18:
811
+ case 20:
787
812
  tempOrder = this.store.tempOrder;
788
813
  holders = (tempOrder === null || tempOrder === void 0 || (_tempOrder$holder = tempOrder.holder) === null || _tempOrder$holder === void 0 ? void 0 : _tempOrder$holder.form_record) || [];
789
814
  _ref12 = rulesModule.isDiscountListAvailable({
@@ -804,32 +829,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
804
829
  retainedDiscountList = evaluatedDiscountList ? markScannedDiscounts(evaluatedDiscountList, withScanList) : normalizedNewDiscountList;
805
830
  resolvedDiscountList = normalizedNewDiscountList || this.getDiscountList();
806
831
  if (!(isAvailable && normalizedNewDiscountList)) {
807
- _context6.next = 34;
832
+ _context6.next = 36;
808
833
  break;
809
834
  }
810
- _context6.next = 28;
835
+ _context6.next = 30;
811
836
  return (_this$store$discount12 = this.store.discount) === null || _this$store$discount12 === void 0 ? void 0 : _this$store$discount12.setDiscountList(normalizedNewDiscountList);
812
- case 28:
837
+ case 30:
813
838
  this.applyDiscount();
814
- _context6.next = 31;
839
+ _context6.next = 33;
815
840
  return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
816
- case 31:
841
+ case 33:
817
842
  resolvedDiscountList = this.getDiscountList();
818
- _context6.next = 40;
843
+ _context6.next = 42;
819
844
  break;
820
- case 34:
845
+ case 36:
821
846
  if (!(shouldRetainForLater && retainedDiscountList)) {
822
- _context6.next = 40;
847
+ _context6.next = 42;
823
848
  break;
824
849
  }
825
- _context6.next = 37;
826
- return (_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.setDiscountList(retainedDiscountList);
827
- case 37:
828
850
  _context6.next = 39;
829
- return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
851
+ return (_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.setDiscountList(retainedDiscountList);
830
852
  case 39:
853
+ _context6.next = 41;
854
+ return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
855
+ case 41:
831
856
  resolvedDiscountList = this.getDiscountList();
832
- case 40:
857
+ case 42:
833
858
  return _context6.abrupt("return", {
834
859
  type: 'clientCalc',
835
860
  isAvailable: isAvailable || false,
@@ -838,7 +863,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
838
863
  scannedDiscountList: resultDiscountList,
839
864
  unavailableReason: unavailableReason
840
865
  });
841
- case 41:
866
+ case 43:
842
867
  case "end":
843
868
  return _context6.stop();
844
869
  }
@@ -852,7 +877,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
852
877
  }, {
853
878
  key: "applyDiscount",
854
879
  value: function applyDiscount(options) {
855
- var _this$store$discount14,
880
+ var _this$store$discount16,
856
881
  _this$store$summary2,
857
882
  _this2 = this;
858
883
  var tempOrder = this.store.tempOrder;
@@ -860,9 +885,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
860
885
  // 也需要让 Rules.calcDiscount 把 DiscountModule 的 isSelected / isAvailable /
861
886
  // appliedProductDetails / savedAmount 复位。
862
887
  if (!tempOrder) return;
888
+ if (this.isActiveVirtualSettlementOrder(tempOrder)) {
889
+ var _this$store$discount14, _this$store$discount15;
890
+ tempOrder.products = normalizeVirtualSettlementProducts(tempOrder.products);
891
+ tempOrder.discount_list = [];
892
+ tempOrder.shop_discount = '0.00';
893
+ void ((_this$store$discount14 = this.store.discount) === null || _this$store$discount14 === void 0 ? void 0 : _this$store$discount14.setDiscountList([]));
894
+ void ((_this$store$discount15 = this.store.discount) === null || _this$store$discount15 === void 0 ? void 0 : _this$store$discount15.setOriginalDiscountList([]));
895
+ return;
896
+ }
863
897
  this.syncLinkedBookingHoldersToProducts(tempOrder);
864
898
  delete tempOrder.discount_list;
865
- var discountList = ((_this$store$discount14 = this.store.discount) === null || _this$store$discount14 === void 0 ? void 0 : _this$store$discount14.getDiscountList()) || [];
899
+ var discountList = ((_this$store$discount16 = this.store.discount) === null || _this$store$discount16 === void 0 ? void 0 : _this$store$discount16.getDiscountList()) || [];
866
900
  var shouldSkipDiscountCalculation = this.shouldSkipDiscountCalculation(tempOrder);
867
901
  if (shouldSkipDiscountCalculation) return;
868
902
  var rulesModule = this.store.rules;
@@ -896,9 +930,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
896
930
  consolidateDiscountFreeProductLines(tempOrder);
897
931
  }
898
932
  if (result !== null && result !== void 0 && result.discountList) {
899
- var _this$store$discount15;
933
+ var _this$store$discount17;
900
934
  OrderModule.populateSavedAmounts(result.productList || tempOrder.products, result.discountList);
901
- (_this$store$discount15 = this.store.discount) === null || _this$store$discount15 === void 0 || _this$store$discount15.setDiscountList(result.discountList);
935
+ (_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 || _this$store$discount17.setDiscountList(result.discountList);
902
936
  }
903
937
  this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(function (product) {
904
938
  return _this2.productHasCustomerBoundDiscount(product);
@@ -987,15 +1021,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
987
1021
  }
988
1022
  return _context9.abrupt("return");
989
1023
  case 7:
990
- strategyConfigs = (_this$promotionEvalua = (_this$promotionEvalua2 = this.promotionEvaluator).getStrategyConfigs) === null || _this$promotionEvalua === void 0 ? void 0 : _this$promotionEvalua.call(_this$promotionEvalua2);
991
- if (!(Array.isArray(strategyConfigs) && strategyConfigs.length === 0)) {
1024
+ if (!this.isActiveVirtualSettlementOrder(tempOrder)) {
992
1025
  _context9.next = 10;
993
1026
  break;
994
1027
  }
1028
+ tempOrder.products = normalizeVirtualSettlementProducts(tempOrder.products);
995
1029
  return _context9.abrupt("return");
996
1030
  case 10:
1031
+ strategyConfigs = (_this$promotionEvalua = (_this$promotionEvalua2 = this.promotionEvaluator).getStrategyConfigs) === null || _this$promotionEvalua === void 0 ? void 0 : _this$promotionEvalua.call(_this$promotionEvalua2);
1032
+ if (!(Array.isArray(strategyConfigs) && strategyConfigs.length === 0)) {
1033
+ _context9.next = 13;
1034
+ break;
1035
+ }
1036
+ return _context9.abrupt("return");
1037
+ case 13:
997
1038
  this.isApplyingPromotion = true;
998
- _context9.prev = 11;
1039
+ _context9.prev = 14;
999
1040
  result = processCartPromotion(tempOrder.products, this.promotionEvaluator); // step 1: toRemove —— 直接过滤
1000
1041
  if (result.giftActions.toRemove.length > 0) {
1001
1042
  removeSet = new Set(result.giftActions.toRemove.map(String));
@@ -1007,16 +1048,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1007
1048
 
1008
1049
  // step 2: toReduce —— 调整数量
1009
1050
  _iterator3 = _createForOfIteratorHelper(result.giftActions.toReduce);
1010
- _context9.prev = 15;
1051
+ _context9.prev = 18;
1011
1052
  _iterator3.s();
1012
- case 17:
1053
+ case 20:
1013
1054
  if ((_step3 = _iterator3.n()).done) {
1014
- _context9.next = 37;
1055
+ _context9.next = 40;
1015
1056
  break;
1016
1057
  }
1017
1058
  reduce = _step3.value;
1018
1059
  _iterator6 = _createForOfIteratorHelper(reduce.items);
1019
- _context9.prev = 20;
1060
+ _context9.prev = 23;
1020
1061
  _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
1021
1062
  var item, product;
1022
1063
  return _regeneratorRuntime().wrap(function _loop2$(_context8) {
@@ -1036,47 +1077,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1036
1077
  }, _loop2);
1037
1078
  });
1038
1079
  _iterator6.s();
1039
- case 23:
1080
+ case 26:
1040
1081
  if ((_step6 = _iterator6.n()).done) {
1041
- _context9.next = 27;
1082
+ _context9.next = 30;
1042
1083
  break;
1043
1084
  }
1044
- return _context9.delegateYield(_loop2(), "t0", 25);
1045
- case 25:
1046
- _context9.next = 23;
1085
+ return _context9.delegateYield(_loop2(), "t0", 28);
1086
+ case 28:
1087
+ _context9.next = 26;
1047
1088
  break;
1048
- case 27:
1049
- _context9.next = 32;
1089
+ case 30:
1090
+ _context9.next = 35;
1050
1091
  break;
1051
- case 29:
1052
- _context9.prev = 29;
1053
- _context9.t1 = _context9["catch"](20);
1054
- _iterator6.e(_context9.t1);
1055
1092
  case 32:
1056
1093
  _context9.prev = 32;
1057
- _iterator6.f();
1058
- return _context9.finish(32);
1094
+ _context9.t1 = _context9["catch"](23);
1095
+ _iterator6.e(_context9.t1);
1059
1096
  case 35:
1060
- _context9.next = 17;
1097
+ _context9.prev = 35;
1098
+ _iterator6.f();
1099
+ return _context9.finish(35);
1100
+ case 38:
1101
+ _context9.next = 20;
1061
1102
  break;
1062
- case 37:
1063
- _context9.next = 42;
1103
+ case 40:
1104
+ _context9.next = 45;
1064
1105
  break;
1065
- case 39:
1066
- _context9.prev = 39;
1067
- _context9.t2 = _context9["catch"](15);
1068
- _iterator3.e(_context9.t2);
1069
1106
  case 42:
1070
1107
  _context9.prev = 42;
1071
- _iterator3.f();
1072
- return _context9.finish(42);
1108
+ _context9.t2 = _context9["catch"](18);
1109
+ _iterator3.e(_context9.t2);
1073
1110
  case 45:
1111
+ _context9.prev = 45;
1112
+ _iterator3.f();
1113
+ return _context9.finish(45);
1114
+ case 48:
1074
1115
  if (!(result.giftActions.toAdd.length > 0)) {
1075
- _context9.next = 68;
1116
+ _context9.next = 71;
1076
1117
  break;
1077
1118
  }
1078
1119
  if (this.giftSelectResolver) {
1079
- _context9.next = 50;
1120
+ _context9.next = 53;
1080
1121
  break;
1081
1122
  }
1082
1123
  if (result.giftActions.toAdd.some(function (g) {
@@ -1087,11 +1128,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1087
1128
  } else {
1088
1129
  console.warn('[OrderModule] giftSelectResolver not set, skip applying single-option gifts', result.giftActions.toAdd);
1089
1130
  }
1090
- _context9.next = 68;
1131
+ _context9.next = 71;
1091
1132
  break;
1092
- case 50:
1133
+ case 53:
1093
1134
  _iterator4 = _createForOfIteratorHelper(result.giftActions.toAdd);
1094
- _context9.prev = 51;
1135
+ _context9.prev = 54;
1095
1136
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
1096
1137
  var addAction, _sameStrategy$metadat, sameStrategy, giftResult, giftProducts, giftBookings, _iterator5, _step5, _step5$value, index, gp, booking, linked;
1097
1138
  return _regeneratorRuntime().wrap(function _loop$(_context7) {
@@ -1189,33 +1230,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1189
1230
  }, _loop, null, [[6, 39], [14, 31, 34, 37]]);
1190
1231
  });
1191
1232
  _iterator4.s();
1192
- case 54:
1233
+ case 57:
1193
1234
  if ((_step4 = _iterator4.n()).done) {
1194
- _context9.next = 60;
1235
+ _context9.next = 63;
1195
1236
  break;
1196
1237
  }
1197
- return _context9.delegateYield(_loop(), "t3", 56);
1198
- case 56:
1238
+ return _context9.delegateYield(_loop(), "t3", 59);
1239
+ case 59:
1199
1240
  if (!_context9.t3) {
1200
- _context9.next = 58;
1241
+ _context9.next = 61;
1201
1242
  break;
1202
1243
  }
1203
- return _context9.abrupt("continue", 58);
1204
- case 58:
1205
- _context9.next = 54;
1244
+ return _context9.abrupt("continue", 61);
1245
+ case 61:
1246
+ _context9.next = 57;
1206
1247
  break;
1207
- case 60:
1208
- _context9.next = 65;
1248
+ case 63:
1249
+ _context9.next = 68;
1209
1250
  break;
1210
- case 62:
1211
- _context9.prev = 62;
1212
- _context9.t4 = _context9["catch"](51);
1213
- _iterator4.e(_context9.t4);
1214
1251
  case 65:
1215
1252
  _context9.prev = 65;
1216
- _iterator4.f();
1217
- return _context9.finish(65);
1253
+ _context9.t4 = _context9["catch"](54);
1254
+ _iterator4.e(_context9.t4);
1218
1255
  case 68:
1256
+ _context9.prev = 68;
1257
+ _iterator4.f();
1258
+ return _context9.finish(68);
1259
+ case 71:
1219
1260
  tempOrder.products = result.products;
1220
1261
  this.lastUnfulfilledPromotions = result.unfulfilledPromotions;
1221
1262
  this.lastGiftActions = result.giftActions;
@@ -1233,21 +1274,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1233
1274
  products: tempOrder.products
1234
1275
  };
1235
1276
  this.effectsEmit('onPromotionApplied', payload);
1236
- _context9.next = 78;
1277
+ _context9.next = 81;
1237
1278
  break;
1238
- case 75:
1239
- _context9.prev = 75;
1240
- _context9.t5 = _context9["catch"](11);
1241
- console.error('[OrderModule] applyPromotion failed', _context9.t5);
1242
1279
  case 78:
1243
1280
  _context9.prev = 78;
1244
- this.isApplyingPromotion = false;
1245
- return _context9.finish(78);
1281
+ _context9.t5 = _context9["catch"](14);
1282
+ console.error('[OrderModule] applyPromotion failed', _context9.t5);
1246
1283
  case 81:
1284
+ _context9.prev = 81;
1285
+ this.isApplyingPromotion = false;
1286
+ return _context9.finish(81);
1287
+ case 84:
1247
1288
  case "end":
1248
1289
  return _context9.stop();
1249
1290
  }
1250
- }, _callee7, this, [[11, 75, 78, 81], [15, 39, 42, 45], [20, 29, 32, 35], [51, 62, 65, 68]]);
1291
+ }, _callee7, this, [[14, 78, 81, 84], [18, 42, 45, 48], [23, 32, 35, 38], [54, 65, 68, 71]]);
1251
1292
  }));
1252
1293
  function applyPromotion() {
1253
1294
  return _applyPromotion.apply(this, arguments);
@@ -1632,7 +1673,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1632
1673
  paidAmount: netPaidAmount
1633
1674
  });
1634
1675
  var isOrderFullyPaid = orderExpectedAmount.lte(0) ? true : netPaidAmount.gte(orderExpectedAmount);
1635
- var paymentStage = this.isDepositOrder(tempOrder, depositAmount) && !isDepositFullyPaid ? 'deposit' : 'normal';
1676
+ var paymentStage = this.isDepositOrder(tempOrder, depositAmount) && !isDepositFullyPaid && !this.hasPaidNormalPayment(paymentList) ? 'deposit' : 'normal';
1636
1677
  return {
1637
1678
  isFullyPaid: isOrderFullyPaid,
1638
1679
  isOrderFullyPaid: isOrderFullyPaid,
@@ -1654,12 +1695,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1654
1695
  return sum.plus(_this6.calculatePaymentGapAmount(paymentRecord));
1655
1696
  }, new Decimal(0));
1656
1697
  }
1698
+ }, {
1699
+ key: "hasPaidNormalPayment",
1700
+ value: function hasPaidNormalPayment(payments) {
1701
+ return (payments || []).some(function (payment) {
1702
+ var paymentRecord = payment;
1703
+ if (!isPaidPaymentRecord(paymentRecord)) return false;
1704
+ return paymentRecord.order_payment_type !== 'deposit' && paymentRecord.type !== 'deposit';
1705
+ });
1706
+ }
1657
1707
  }, {
1658
1708
  key: "resolveNextOrderPaymentType",
1659
1709
  value: function resolveNextOrderPaymentType(tempOrder) {
1660
1710
  var depositAmount = new Decimal(tempOrder.deposit_amount || '0.00');
1661
1711
  if (!this.isDepositOrder(tempOrder, depositAmount)) return 'normal';
1662
1712
  if (depositAmount.lte(0)) return 'normal';
1713
+ if (this.hasPaidNormalPayment(tempOrder.payments || [])) return 'normal';
1663
1714
  var depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1664
1715
  return depositPaidAmount.lt(depositAmount) ? 'deposit' : 'normal';
1665
1716
  }
@@ -1987,10 +2038,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1987
2038
  value: function calculateSummaryAmountGap(params) {
1988
2039
  var tempOrder = params.tempOrder,
1989
2040
  summary = params.summary,
1990
- orderPaidAmount = params.orderPaidAmount;
2041
+ orderPaidAmount = params.orderPaidAmount,
2042
+ payments = params.payments;
1991
2043
  var refundAmount = this.getSummaryRefundAmount(summary);
1992
2044
  var netOrderPaidAmount = Decimal.max(orderPaidAmount.minus(refundAmount), 0);
1993
- var targetAmount = this.calculatePaymentTargetAmount(tempOrder, summary, netOrderPaidAmount);
2045
+ var targetAmount = this.calculatePaymentTargetAmount(tempOrder, summary, netOrderPaidAmount, payments);
1994
2046
  return targetAmount.minus(netOrderPaidAmount).toFixed(2);
1995
2047
  }
1996
2048
  }, {
@@ -2002,10 +2054,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2002
2054
  key: "calculatePaymentTargetAmount",
2003
2055
  value: function calculatePaymentTargetAmount(tempOrder, summary) {
2004
2056
  var paidAmount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Decimal(0);
2057
+ var payments = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : tempOrder.payments || [];
2005
2058
  var depositAmount = this.getDepositAmount(tempOrder, summary);
2006
2059
  if (!this.isDepositOrder(tempOrder, depositAmount)) {
2007
2060
  return this.getOrderExpectedAmount(summary);
2008
2061
  }
2062
+ if (this.hasPaidNormalPayment(payments)) {
2063
+ return this.getOrderExpectedAmount(summary);
2064
+ }
2009
2065
  if (this.isDepositCovered({
2010
2066
  tempOrder: tempOrder,
2011
2067
  summary: summary,
@@ -2258,17 +2314,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2258
2314
  }, {
2259
2315
  key: "isSnapshotPayableAmountUnchanged",
2260
2316
  value: function isSnapshotPayableAmountUnchanged(tempOrder, snapshot, snapshotSummary) {
2261
- var currentPaidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
2317
+ var currentPayments = tempOrder.payments || [];
2318
+ var currentPaidPaymentSummary = this.calculatePaidPaymentSummary(currentPayments);
2262
2319
  var currentAmountGap = this.calculateSummaryAmountGap({
2263
2320
  tempOrder: tempOrder,
2264
2321
  summary: snapshotSummary,
2265
- orderPaidAmount: currentPaidPaymentSummary.gapPaidAmount
2322
+ orderPaidAmount: currentPaidPaymentSummary.gapPaidAmount,
2323
+ payments: currentPayments
2266
2324
  });
2267
- var snapshotPaidPaymentSummary = this.calculatePaidPaymentSummary(Array.isArray(snapshot.payments) ? snapshot.payments : []);
2325
+ var snapshotPayments = Array.isArray(snapshot.payments) ? snapshot.payments : [];
2326
+ var snapshotPaidPaymentSummary = this.calculatePaidPaymentSummary(snapshotPayments);
2268
2327
  var snapshotAmountGap = this.calculateSummaryAmountGap({
2269
2328
  tempOrder: tempOrder,
2270
2329
  summary: snapshotSummary,
2271
- orderPaidAmount: snapshotPaidPaymentSummary.gapPaidAmount
2330
+ orderPaidAmount: snapshotPaidPaymentSummary.gapPaidAmount,
2331
+ payments: snapshotPayments
2272
2332
  });
2273
2333
  return currentAmountGap === snapshotAmountGap;
2274
2334
  }
@@ -2302,6 +2362,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2302
2362
  }
2303
2363
  var isPayableAmountUnchanged = this.isSnapshotPayableAmountUnchanged(tempOrder, snapshot, summary);
2304
2364
  if (!isPayableAmountUnchanged) return null;
2365
+ var currentPaidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
2366
+ summary.amount_gap = this.calculateSummaryAmountGap({
2367
+ tempOrder: tempOrder,
2368
+ summary: summary,
2369
+ orderPaidAmount: currentPaidPaymentSummary.gapPaidAmount
2370
+ });
2305
2371
  if (Array.isArray(snapshot.products)) {
2306
2372
  tempOrder.products = cloneDeep(snapshot.products);
2307
2373
  }
@@ -2428,7 +2494,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2428
2494
  }, {
2429
2495
  key: "restoreOrder",
2430
2496
  value: function restoreOrder() {
2431
- var _this$store$discount16, _this$store$discount17;
2497
+ var _this$store$discount18, _this$store$discount19;
2432
2498
  this.logInfo('restoreOrder start', {});
2433
2499
  this.sessionStorageRestoreRecord = null;
2434
2500
  var freshTempOrder = this.createDefaultTempOrderInstance();
@@ -2437,8 +2503,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2437
2503
  this.store.summary = createEmptySummary();
2438
2504
  this.store.lastOrderInfo = undefined;
2439
2505
  this.store.syncState = undefined;
2440
- void ((_this$store$discount16 = this.store.discount) === null || _this$store$discount16 === void 0 ? void 0 : _this$store$discount16.setOriginalDiscountList([]));
2441
- void ((_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 ? void 0 : _this$store$discount17.setDiscountList([]));
2506
+ void ((_this$store$discount18 = this.store.discount) === null || _this$store$discount18 === void 0 ? void 0 : _this$store$discount18.setOriginalDiscountList([]));
2507
+ void ((_this$store$discount19 = this.store.discount) === null || _this$store$discount19 === void 0 ? void 0 : _this$store$discount19.setDiscountList([]));
2442
2508
  this.persistTempOrder();
2443
2509
  return freshTempOrder;
2444
2510
  }
@@ -2643,8 +2709,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2643
2709
  value: function sanitizeTempOrderProducts(tempOrder) {
2644
2710
  var _this15 = this;
2645
2711
  tempOrder.products = (tempOrder.products || []).map(function (product) {
2646
- return _this15.sanitizeOrderProductForTempOrder(product);
2712
+ return _this15.sanitizeOrderProductForTempOrder(_this15.normalizeVirtualSettlementProductIfEnabled(product));
2647
2713
  });
2714
+ this.syncTempOrderSettlementState(tempOrder);
2648
2715
  ensureUniqueProductLineUids(tempOrder);
2649
2716
  }
2650
2717
  }, {
@@ -3042,7 +3109,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3042
3109
  return salesSummary.getSummary(_objectSpread({
3043
3110
  products: summaryProducts,
3044
3111
  isPriceIncludeTax: tempOrder.is_price_include_tax,
3045
- shopDiscount: tempOrder.shop_discount
3112
+ shopDiscount: tempOrder.shop_discount,
3113
+ virtualSettlementMode: this.shouldUseVirtualSettlementSummary(tempOrder)
3046
3114
  }, (_this$otherParams2 = this.otherParams) !== null && _this$otherParams2 !== void 0 && _this$otherParams2.channel ? {
3047
3115
  channel: this.otherParams.channel
3048
3116
  } : {}));
@@ -3278,11 +3346,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3278
3346
  }, {
3279
3347
  key: "shouldSkipDiscountCalculation",
3280
3348
  value: function shouldSkipDiscountCalculation(tempOrder) {
3281
- var _this$store$discount18,
3282
- _this$store$discount19,
3349
+ var _this$store$discount20,
3350
+ _this$store$discount21,
3283
3351
  _this20 = this;
3284
3352
  if (this.hasActiveCustomerBoundDiscount) return false;
3285
- var discountList = ((_this$store$discount18 = this.store.discount) === null || _this$store$discount18 === void 0 || (_this$store$discount19 = _this$store$discount18.getDiscountList) === null || _this$store$discount19 === void 0 ? void 0 : _this$store$discount19.call(_this$store$discount18)) || [];
3353
+ var discountList = ((_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 || (_this$store$discount21 = _this$store$discount20.getDiscountList) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.call(_this$store$discount20)) || [];
3286
3354
  if (discountList.length > 0) return false;
3287
3355
  return !(tempOrder.products || []).some(function (product) {
3288
3356
  return _this20.productHasCustomerBoundDiscount(product);
@@ -3404,6 +3472,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3404
3472
  var nextCustomerId = (_tempOrder$customer_i5 = tempOrder.customer_id) !== null && _tempOrder$customer_i5 !== void 0 ? _tempOrder$customer_i5 : null;
3405
3473
  if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
3406
3474
  this.store.availableWalletIds = [];
3475
+ this.store.virtualCurrencyList = [];
3407
3476
  clearTempOrderHolderAssignments(tempOrder);
3408
3477
  this.clearCustomerBoundDiscounts(tempOrder);
3409
3478
  this.applyDiscount();
@@ -3449,6 +3518,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3449
3518
  tempOrder.customer = null;
3450
3519
  if (tempOrder._extend) delete tempOrder._extend.customerSnapshot;
3451
3520
  this.store.availableWalletIds = [];
3521
+ this.store.virtualCurrencyList = [];
3452
3522
  this.clearCustomerBoundDiscounts(tempOrder);
3453
3523
  this.applyDiscount();
3454
3524
  this.persistTempOrder();
@@ -3869,52 +3939,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3869
3939
  }
3870
3940
  return updateVoucherOrderPaymentsAsync;
3871
3941
  }()
3942
+ }, {
3943
+ key: "normalizeShouldMergeProductResult",
3944
+ value: function normalizeShouldMergeProductResult(result) {
3945
+ if (typeof result === 'boolean') return result;
3946
+ if (result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean') {
3947
+ return result.shouldMerge;
3948
+ }
3949
+ return true;
3950
+ }
3872
3951
  }, {
3873
3952
  key: "shouldMergeProductToOrder",
3874
- value: function () {
3875
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
3876
- var _this$orderHooks;
3877
- var onBeforeMergeProductToOrder, result;
3878
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3879
- while (1) switch (_context20.prev = _context20.next) {
3880
- case 0:
3881
- onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
3882
- if (onBeforeMergeProductToOrder) {
3883
- _context20.next = 3;
3884
- break;
3885
- }
3886
- return _context20.abrupt("return", true);
3887
- case 3:
3888
- _context20.next = 5;
3889
- return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
3890
- defaultShouldMerge: true
3891
- }));
3892
- case 5:
3893
- result = _context20.sent;
3894
- if (!(typeof result === 'boolean')) {
3895
- _context20.next = 8;
3896
- break;
3897
- }
3898
- return _context20.abrupt("return", result);
3899
- case 8:
3900
- if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
3901
- _context20.next = 10;
3902
- break;
3903
- }
3904
- return _context20.abrupt("return", result.shouldMerge);
3905
- case 10:
3906
- return _context20.abrupt("return", true);
3907
- case 11:
3908
- case "end":
3909
- return _context20.stop();
3910
- }
3911
- }, _callee18, this);
3953
+ value: function shouldMergeProductToOrder(params) {
3954
+ var _this$orderHooks,
3955
+ _this26 = this;
3956
+ var onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
3957
+ if (!onBeforeMergeProductToOrder) return true;
3958
+ var result = onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
3959
+ defaultShouldMerge: true
3912
3960
  }));
3913
- function shouldMergeProductToOrder(_x19) {
3914
- return _shouldMergeProductToOrder.apply(this, arguments);
3961
+ if (result && _typeof(result) === 'object' && typeof result.then === 'function') {
3962
+ return Promise.resolve(result).then(function (resolved) {
3963
+ return _this26.normalizeShouldMergeProductResult(resolved);
3964
+ });
3915
3965
  }
3916
- return shouldMergeProductToOrder;
3917
- }()
3966
+ return this.normalizeShouldMergeProductResult(result);
3967
+ }
3918
3968
  }, {
3919
3969
  key: "hasOrderProductLineNote",
3920
3970
  value: function hasOrderProductLineNote(product) {
@@ -3934,6 +3984,99 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3934
3984
  var bookingUid = (_product$booking_uid = product === null || product === void 0 ? void 0 : product.booking_uid) !== null && _product$booking_uid !== void 0 ? _product$booking_uid : product === null || product === void 0 || (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.booking_uid;
3935
3985
  return bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '';
3936
3986
  }
3987
+ }, {
3988
+ key: "isMultiCurrencySettlementEnabled",
3989
+ value: function isMultiCurrencySettlementEnabled() {
3990
+ var _this$otherParams3;
3991
+ return ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.enableMultiCurrencySettlement) === true;
3992
+ }
3993
+ }, {
3994
+ key: "isActiveVirtualSettlementOrder",
3995
+ value: function isActiveVirtualSettlementOrder(tempOrder) {
3996
+ return this.isMultiCurrencySettlementEnabled() && isVirtualSettlementOrder(tempOrder);
3997
+ }
3998
+ }, {
3999
+ key: "shouldUseVirtualSettlementSummary",
4000
+ value: function shouldUseVirtualSettlementSummary(tempOrder) {
4001
+ var _tempOrder$metadata;
4002
+ return this.isActiveVirtualSettlementOrder(tempOrder) || (tempOrder === null || tempOrder === void 0 || (_tempOrder$metadata = tempOrder.metadata) === null || _tempOrder$metadata === void 0 || (_tempOrder$metadata = _tempOrder$metadata.currency_settlement_config) === null || _tempOrder$metadata === void 0 ? void 0 : _tempOrder$metadata.settlement_type) === 'virtual_currency';
4003
+ }
4004
+ }, {
4005
+ key: "normalizeVirtualSettlementProductIfEnabled",
4006
+ value: function normalizeVirtualSettlementProductIfEnabled(product) {
4007
+ return this.isMultiCurrencySettlementEnabled() ? normalizeVirtualSettlementOrderProduct(product) : product;
4008
+ }
4009
+ }, {
4010
+ key: "assertAndLockProductSettlement",
4011
+ value: function assertAndLockProductSettlement(tempOrder, product) {
4012
+ var _ref60, _ref61, _product$selling_pric;
4013
+ if (!this.isMultiCurrencySettlementEnabled()) return;
4014
+ var currentKey = getTempOrderSettlementKey(tempOrder);
4015
+ var incomingKey = getSettlementKey(getSelectedSettlementSnapshot(product)) || 'legal_currency';
4016
+ if (currentKey && currentKey !== incomingKey) {
4017
+ throw new OrderSettlementConflictError(currentKey, incomingKey);
4018
+ }
4019
+ var snapshot = getSelectedSettlementSnapshot(product);
4020
+ if ((snapshot === null || snapshot === void 0 ? void 0 : snapshot.settlement_type) === 'virtual_currency' && tempOrder.customer_id && Number(tempOrder.customer_id) !== 1) {
4021
+ var currencyProductId = Number(snapshot.currency_product_id);
4022
+ var asset = (this.store.virtualCurrencyList || []).find(function (item) {
4023
+ return Number(item === null || item === void 0 ? void 0 : item.product_id) === currencyProductId;
4024
+ });
4025
+ if (!asset) {
4026
+ throw new VirtualCurrencyAssetNotFoundError(currencyProductId);
4027
+ }
4028
+ var existedAmount = tempOrder.products.reduce(function (sum, item) {
4029
+ return sum.plus(new Decimal(item.selling_price || 0).times(item.num || 1));
4030
+ }, new Decimal(0));
4031
+ var requiredAmount = existedAmount.plus(new Decimal(snapshot.price || 0).times(product.num || 1));
4032
+ var balance = new Decimal(asset.balance || 0);
4033
+ if (balance.lt(requiredAmount)) {
4034
+ throw new VirtualCurrencyBalanceError(balance.toFixed(2), requiredAmount.toFixed(2));
4035
+ }
4036
+ }
4037
+ applyTempOrderSettlementState(tempOrder, snapshot || {
4038
+ settlement_type: 'legal_currency',
4039
+ price: (_ref60 = (_ref61 = (_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : product.original_price) !== null && _ref61 !== void 0 ? _ref61 : product.payment_price) !== null && _ref60 !== void 0 ? _ref60 : 0,
4040
+ unit_label: tempOrder.currency_code,
4041
+ symbol: tempOrder.currency_symbol,
4042
+ amount_format: tempOrder.currency_format
4043
+ });
4044
+ }
4045
+ }, {
4046
+ key: "syncTempOrderSettlementState",
4047
+ value: function syncTempOrderSettlementState(tempOrder) {
4048
+ if (!this.isMultiCurrencySettlementEnabled()) return;
4049
+ tempOrder.metadata = tempOrder.metadata || {};
4050
+ if (!tempOrder.products.length) {
4051
+ releaseTempOrderSettlementState(tempOrder);
4052
+ return;
4053
+ }
4054
+ var snapshot = getTempOrderSettlementSnapshot(tempOrder);
4055
+ if (snapshot) {
4056
+ applyTempOrderSettlementState(tempOrder, snapshot);
4057
+ return;
4058
+ }
4059
+ tempOrder.metadata.cart_settlement_key = 'legal_currency';
4060
+ }
4061
+ }, {
4062
+ key: "prepareVirtualSettlementTempOrder",
4063
+ value: function prepareVirtualSettlementTempOrder(tempOrder) {
4064
+ if (!this.isMultiCurrencySettlementEnabled()) return;
4065
+ this.syncTempOrderSettlementState(tempOrder);
4066
+ if (!this.isActiveVirtualSettlementOrder(tempOrder)) return;
4067
+ tempOrder.products = normalizeVirtualSettlementProducts(tempOrder.products);
4068
+ tempOrder.discount_list = [];
4069
+ tempOrder.shop_discount = '0.00';
4070
+ tempOrder.surcharge_fee = '0.00';
4071
+ tempOrder.surcharges = [];
4072
+ var virtualOrder = tempOrder;
4073
+ virtualOrder.discount_amount = '0.00';
4074
+ virtualOrder.product_tax_fee = '0.00';
4075
+ virtualOrder.tax_fee = '0.00';
4076
+ virtualOrder.shipping_fee = '0.00';
4077
+ virtualOrder.shipping_tax_fee = '0.00';
4078
+ virtualOrder.tip_fee = '0.00';
4079
+ }
3937
4080
 
3938
4081
  // ─── TempOrder: 商品 CRUD ───
3939
4082
 
@@ -3946,42 +4089,45 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3946
4089
  }, {
3947
4090
  key: "finalizeProductOrderMutation",
3948
4091
  value: function () {
3949
- var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(tempOrder, options) {
3950
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3951
- while (1) switch (_context21.prev = _context21.next) {
4092
+ var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(tempOrder, options) {
4093
+ var isVirtualSettlement;
4094
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
4095
+ while (1) switch (_context20.prev = _context20.next) {
3952
4096
  case 0:
3953
4097
  this.syncTempOrderHolderFromBookings(tempOrder);
3954
- if (options !== null && options !== void 0 && options.skipEditDiscountConfigRefresh) {
3955
- _context21.next = 4;
4098
+ this.prepareVirtualSettlementTempOrder(tempOrder);
4099
+ isVirtualSettlement = this.isActiveVirtualSettlementOrder(tempOrder);
4100
+ if (!(!(options !== null && options !== void 0 && options.skipEditDiscountConfigRefresh) && !isVirtualSettlement)) {
4101
+ _context20.next = 6;
3956
4102
  break;
3957
4103
  }
3958
- _context21.next = 4;
4104
+ _context20.next = 6;
3959
4105
  return this.ensureEditDiscountConfigForProductChange(tempOrder);
3960
- case 4:
3961
- if (options !== null && options !== void 0 && options.skipDiscountRecalculation) {
3962
- _context21.next = 7;
4106
+ case 6:
4107
+ if (!(!(options !== null && options !== void 0 && options.skipDiscountRecalculation) && !isVirtualSettlement)) {
4108
+ _context20.next = 9;
3963
4109
  break;
3964
4110
  }
3965
- _context21.next = 7;
4111
+ _context20.next = 9;
3966
4112
  return this.applyPromotion();
3967
- case 7:
3968
- if (!(options !== null && options !== void 0 && options.skipDiscountRecalculation)) {
4113
+ case 9:
4114
+ if (!(options !== null && options !== void 0 && options.skipDiscountRecalculation) && !isVirtualSettlement) {
3969
4115
  this.applyDiscount();
3970
4116
  }
3971
4117
  this.sanitizeTempOrderProducts(tempOrder);
3972
- _context21.next = 11;
4118
+ _context20.next = 13;
3973
4119
  return this.recalculateSummary({
3974
4120
  createIfMissing: true
3975
4121
  });
3976
- case 11:
4122
+ case 13:
3977
4123
  this.persistTempOrder();
3978
- case 12:
4124
+ case 14:
3979
4125
  case "end":
3980
- return _context21.stop();
4126
+ return _context20.stop();
3981
4127
  }
3982
- }, _callee19, this);
4128
+ }, _callee18, this);
3983
4129
  }));
3984
- function finalizeProductOrderMutation(_x20, _x21) {
4130
+ function finalizeProductOrderMutation(_x19, _x20) {
3985
4131
  return _finalizeProductOrderMutation.apply(this, arguments);
3986
4132
  }
3987
4133
  return finalizeProductOrderMutation;
@@ -3991,149 +4137,136 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3991
4137
  * 带 booking 且 num>1 时由 `addProductToOrder` 拆成多次本方法调用(每次 num=1)。
3992
4138
  *
3993
4139
  * @example
3994
- * await this.appendProductLineToTempOrder(tempOrder, { product_id: 1, num: 1 }, booking);
4140
+ * const pending = this.appendProductLineToTempOrder(
4141
+ * tempOrder,
4142
+ * { product_id: 1, num: 1 },
4143
+ * booking,
4144
+ * );
4145
+ * if (pending) await pending;
3995
4146
  */
3996
4147
  }, {
3997
4148
  key: "appendProductLineToTempOrder",
3998
- value: (function () {
3999
- var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(tempOrder, product, booking, options) {
4000
- var _normalizedIncoming$p,
4001
- _normalizedIncoming$p2,
4002
- _booking_uid,
4003
- _metadata,
4004
- _productToAdd$metadat,
4005
- _origin,
4006
- _this26 = this;
4007
- var linked, productToAdd, incomingFingerprint, normalizedIncoming, isWeighingProduct, netWeight, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingManualProductDiscount, hasIncomingBookingUid, isIncomingCustomItem, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, insertAtIndex, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, mergedProduct;
4008
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4009
- while (1) switch (_context22.prev = _context22.next) {
4010
- case 0:
4011
- linked = booking ? this.createLinkedProductAndBooking({
4012
- product: product,
4013
- booking: booking
4014
- }) : null;
4015
- productToAdd = (linked === null || linked === void 0 ? void 0 : linked.product) || product;
4016
- incomingFingerprint = buildProductLineFingerprint(getProductSkuOptions(productToAdd), productToAdd.product_bundle);
4017
- normalizedIncoming = mergeOrderProductDisplayFields(productToAdd, normalizeOrderProduct(productToAdd));
4018
- isWeighingProduct = Number(((_normalizedIncoming$p = normalizedIncoming.product_sku) === null || _normalizedIncoming$p === void 0 ? void 0 : _normalizedIncoming$p.open_sold_weight) || 0) === 1;
4019
- netWeight = Number((_normalizedIncoming$p2 = normalizedIncoming.product_sku) === null || _normalizedIncoming$p2 === void 0 ? void 0 : _normalizedIncoming$p2.net_weight);
4020
- if (!(isWeighingProduct && (!Number.isFinite(netWeight) || netWeight <= 0))) {
4021
- _context22.next = 8;
4022
- break;
4023
- }
4024
- throw new Error('[Order] 称重商品净重必须大于 0');
4025
- case 8:
4026
- incomingBookingUid = (_booking_uid = productToAdd.booking_uid) !== null && _booking_uid !== void 0 ? _booking_uid : (_metadata = productToAdd.metadata) === null || _metadata === void 0 ? void 0 : _metadata.booking_uid;
4027
- if (incomingBookingUid !== undefined && incomingBookingUid !== null && String(incomingBookingUid) !== '') {
4028
- normalizedIncoming.booking_uid = String(incomingBookingUid);
4029
- normalizedIncoming.metadata = _objectSpread(_objectSpread({}, normalizedIncoming.metadata || {}), {}, {
4030
- booking_uid: String(incomingBookingUid)
4031
- });
4032
- }
4033
- normalizedIncoming.discount_list = normalizeOrderProductDiscountList(normalizedIncoming.discount_list);
4034
- hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
4035
- hasIncomingProductNote = this.hasOrderProductLineNote(normalizedIncoming);
4036
- hasIncomingManualProductDiscount = isManualProductDiscountProduct(normalizedIncoming);
4037
- hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
4038
- isIncomingCustomItem = ((_productToAdd$metadat = productToAdd.metadata) === null || _productToAdd$metadat === void 0 || (_productToAdd$metadat = _productToAdd$metadat.origin) === null || _productToAdd$metadat === void 0 ? void 0 : _productToAdd$metadat.isCustomItem) === true || ((_origin = productToAdd._origin) === null || _origin === void 0 ? void 0 : _origin.isCustomItem) === true;
4039
- shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingManualProductDiscount || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
4040
- matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
4041
- var _item$metadata3;
4042
- if (_this26.hasGoodPassDiscount(item)) return false;
4043
- if (_this26.hasOrderProductLineNote(item)) return false;
4044
- if (isManualProductDiscountProduct(item)) return false;
4045
- if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
4046
- if ((_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.is_edit_for_runtime) return false;
4047
- if (item.product_id !== productToAdd.product_id) return false;
4048
- if (item.product_variant_id !== productToAdd.product_variant_id) return false;
4049
- var existedFingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
4050
- return existedFingerprint === incomingFingerprint;
4051
- });
4052
- matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
4053
- existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
4054
- if (!matchedProduct) {
4055
- _context22.next = 26;
4056
- break;
4057
- }
4058
- _context22.next = 23;
4059
- return this.shouldMergeProductToOrder({
4060
- incomingProduct: productToAdd,
4061
- normalizedIncoming: normalizedIncoming,
4062
- matchedProduct: matchedProduct,
4063
- matchedIndex: matchedIndex,
4064
- incomingFingerprint: incomingFingerprint,
4065
- existedFingerprint: existedFingerprint,
4066
- tempOrder: tempOrder,
4067
- booking: booking
4068
- });
4069
- case 23:
4070
- _context22.t0 = _context22.sent;
4071
- _context22.next = 27;
4072
- break;
4073
- case 26:
4074
- _context22.t0 = false;
4075
- case 27:
4076
- shouldMerge = _context22.t0;
4077
- if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
4078
- this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
4079
- if (linked) {
4080
- normalizedIncoming.booking_uid = linked.bookingUid;
4081
- normalizedIncoming.metadata = _objectSpread(_objectSpread({}, normalizedIncoming.metadata || {}), {}, {
4082
- booking_uid: linked.bookingUid
4083
- });
4084
- }
4085
- insertAtIndex = options === null || options === void 0 ? void 0 : options.insertAtIndex;
4086
- if (Number.isInteger(insertAtIndex) && Number(insertAtIndex) >= 0 && Number(insertAtIndex) < tempOrder.products.length) {
4087
- tempOrder.products = [].concat(_toConsumableArray(tempOrder.products.slice(0, insertAtIndex)), [normalizedIncoming], _toConsumableArray(tempOrder.products.slice(insertAtIndex)));
4088
- } else {
4089
- tempOrder.products = [].concat(_toConsumableArray(tempOrder.products), [normalizedIncoming]);
4090
- }
4091
- } else {
4092
- targetProduct = matchedProduct;
4093
- targetUid = (_targetProduct$metada = targetProduct.metadata) === null || _targetProduct$metada === void 0 ? void 0 : _targetProduct$metada.unique_identification_number;
4094
- normalizedProduct = mergeOrderProductDisplayFields(targetProduct, normalizeOrderProduct(_objectSpread(_objectSpread({}, productToAdd), {}, {
4095
- metadata: _objectSpread(_objectSpread({}, productToAdd.metadata || {}), {}, {
4096
- unique_identification_number: targetUid
4097
- })
4098
- })));
4099
- normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4100
- nextNum = getSafeProductNum(targetProduct.num + normalizedProduct.num);
4101
- tempOrder.products[matchedIndex] = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), normalizedProduct), {}, {
4102
- discount_list: normalizedProduct.discount_list,
4103
- metadata: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.metadata || {}), normalizedProduct.metadata || {}), {}, {
4104
- unique_identification_number: targetUid
4105
- }),
4106
- product_sku: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.product_sku || {
4107
- option: []
4108
- }), normalizedProduct.product_sku || {
4109
- option: []
4110
- }), {}, {
4111
- option: getProductSkuOptions(normalizedProduct)
4112
- }),
4113
- note: targetProduct.note,
4114
- order_detail_id: targetProduct.order_detail_id,
4115
- num: nextNum
4116
- });
4117
- this.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4118
- if (matchedIndex !== tempOrder.products.length - 1) {
4119
- mergedProduct = tempOrder.products[matchedIndex];
4120
- tempOrder.products = [].concat(_toConsumableArray(tempOrder.products.slice(0, matchedIndex)), _toConsumableArray(tempOrder.products.slice(matchedIndex + 1)), [mergedProduct]);
4121
- }
4122
- }
4123
- if (linked) {
4124
- tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
4125
- }
4126
- case 30:
4127
- case "end":
4128
- return _context22.stop();
4149
+ value: function appendProductLineToTempOrder(tempOrder, product, booking, options) {
4150
+ var _normalizedIncoming$p,
4151
+ _normalizedIncoming$p2,
4152
+ _booking_uid,
4153
+ _metadata,
4154
+ _productToAdd$metadat,
4155
+ _origin,
4156
+ _this27 = this;
4157
+ var linked = booking ? this.createLinkedProductAndBooking({
4158
+ product: product,
4159
+ booking: booking
4160
+ }) : null;
4161
+ var productToAdd = (linked === null || linked === void 0 ? void 0 : linked.product) || product;
4162
+ this.assertAndLockProductSettlement(tempOrder, productToAdd);
4163
+ var incomingFingerprint = buildProductLineFingerprint(getProductSkuOptions(productToAdd), productToAdd.product_bundle);
4164
+ var normalizedIncoming = this.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(productToAdd, normalizeOrderProduct(productToAdd)));
4165
+ var isWeighingProduct = Number(((_normalizedIncoming$p = normalizedIncoming.product_sku) === null || _normalizedIncoming$p === void 0 ? void 0 : _normalizedIncoming$p.open_sold_weight) || 0) === 1;
4166
+ var netWeight = Number((_normalizedIncoming$p2 = normalizedIncoming.product_sku) === null || _normalizedIncoming$p2 === void 0 ? void 0 : _normalizedIncoming$p2.net_weight);
4167
+ if (isWeighingProduct && (!Number.isFinite(netWeight) || netWeight <= 0)) {
4168
+ throw new Error('[Order] 称重商品净重必须大于 0');
4169
+ }
4170
+ var incomingBookingUid = (_booking_uid = productToAdd.booking_uid) !== null && _booking_uid !== void 0 ? _booking_uid : (_metadata = productToAdd.metadata) === null || _metadata === void 0 ? void 0 : _metadata.booking_uid;
4171
+ if (incomingBookingUid !== undefined && incomingBookingUid !== null && String(incomingBookingUid) !== '') {
4172
+ normalizedIncoming.booking_uid = String(incomingBookingUid);
4173
+ normalizedIncoming.metadata = _objectSpread(_objectSpread({}, normalizedIncoming.metadata || {}), {}, {
4174
+ booking_uid: String(incomingBookingUid)
4175
+ });
4176
+ }
4177
+ normalizedIncoming.discount_list = normalizeOrderProductDiscountList(normalizedIncoming.discount_list);
4178
+ var hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
4179
+ var hasIncomingProductNote = this.hasOrderProductLineNote(normalizedIncoming);
4180
+ var hasIncomingManualProductDiscount = isManualProductDiscountProduct(normalizedIncoming);
4181
+ var hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
4182
+ var isIncomingCustomItem = ((_productToAdd$metadat = productToAdd.metadata) === null || _productToAdd$metadat === void 0 || (_productToAdd$metadat = _productToAdd$metadat.origin) === null || _productToAdd$metadat === void 0 ? void 0 : _productToAdd$metadat.isCustomItem) === true || ((_origin = productToAdd._origin) === null || _origin === void 0 ? void 0 : _origin.isCustomItem) === true;
4183
+ var shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingManualProductDiscount || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
4184
+ var matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
4185
+ var _item$metadata3;
4186
+ if (_this27.hasGoodPassDiscount(item)) return false;
4187
+ if (_this27.hasOrderProductLineNote(item)) return false;
4188
+ if (isManualProductDiscountProduct(item)) return false;
4189
+ if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
4190
+ if ((_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.is_edit_for_runtime) return false;
4191
+ if (item.product_id !== productToAdd.product_id) return false;
4192
+ if (item.product_variant_id !== productToAdd.product_variant_id) return false;
4193
+ var existedFingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
4194
+ return existedFingerprint === incomingFingerprint;
4195
+ });
4196
+ var matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
4197
+ var existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
4198
+ var commitProductLine = function commitProductLine(shouldMerge) {
4199
+ if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
4200
+ _this27.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
4201
+ if (linked) {
4202
+ normalizedIncoming.booking_uid = linked.bookingUid;
4203
+ normalizedIncoming.metadata = _objectSpread(_objectSpread({}, normalizedIncoming.metadata || {}), {}, {
4204
+ booking_uid: linked.bookingUid
4205
+ });
4129
4206
  }
4130
- }, _callee20, this);
4131
- }));
4132
- function appendProductLineToTempOrder(_x22, _x23, _x24, _x25) {
4133
- return _appendProductLineToTempOrder.apply(this, arguments);
4207
+ var insertAtIndex = options === null || options === void 0 ? void 0 : options.insertAtIndex;
4208
+ if (Number.isInteger(insertAtIndex) && Number(insertAtIndex) >= 0 && Number(insertAtIndex) < tempOrder.products.length) {
4209
+ tempOrder.products = [].concat(_toConsumableArray(tempOrder.products.slice(0, insertAtIndex)), [normalizedIncoming], _toConsumableArray(tempOrder.products.slice(insertAtIndex)));
4210
+ } else {
4211
+ tempOrder.products = [].concat(_toConsumableArray(tempOrder.products), [normalizedIncoming]);
4212
+ }
4213
+ } else {
4214
+ var _targetProduct$metada;
4215
+ var targetProduct = matchedProduct;
4216
+ var targetUid = (_targetProduct$metada = targetProduct.metadata) === null || _targetProduct$metada === void 0 ? void 0 : _targetProduct$metada.unique_identification_number;
4217
+ var normalizedProduct = _this27.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(targetProduct, normalizeOrderProduct(_objectSpread(_objectSpread({}, productToAdd), {}, {
4218
+ metadata: _objectSpread(_objectSpread({}, productToAdd.metadata || {}), {}, {
4219
+ unique_identification_number: targetUid
4220
+ })
4221
+ }))));
4222
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4223
+ var nextNum = getSafeProductNum(targetProduct.num + normalizedProduct.num);
4224
+ tempOrder.products[matchedIndex] = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), normalizedProduct), {}, {
4225
+ discount_list: normalizedProduct.discount_list,
4226
+ metadata: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.metadata || {}), normalizedProduct.metadata || {}), {}, {
4227
+ unique_identification_number: targetUid
4228
+ }),
4229
+ product_sku: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.product_sku || {
4230
+ option: []
4231
+ }), normalizedProduct.product_sku || {
4232
+ option: []
4233
+ }), {}, {
4234
+ option: getProductSkuOptions(normalizedProduct)
4235
+ }),
4236
+ note: targetProduct.note,
4237
+ order_detail_id: targetProduct.order_detail_id,
4238
+ num: nextNum
4239
+ });
4240
+ _this27.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4241
+ if (matchedIndex !== tempOrder.products.length - 1) {
4242
+ var mergedProduct = tempOrder.products[matchedIndex];
4243
+ tempOrder.products = [].concat(_toConsumableArray(tempOrder.products.slice(0, matchedIndex)), _toConsumableArray(tempOrder.products.slice(matchedIndex + 1)), [mergedProduct]);
4244
+ }
4245
+ }
4246
+ if (linked) {
4247
+ tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
4248
+ }
4249
+ };
4250
+ if (!matchedProduct) {
4251
+ commitProductLine(false);
4252
+ return;
4134
4253
  }
4135
- return appendProductLineToTempOrder;
4136
- }()
4254
+ var shouldMerge = this.shouldMergeProductToOrder({
4255
+ incomingProduct: productToAdd,
4256
+ normalizedIncoming: normalizedIncoming,
4257
+ matchedProduct: matchedProduct,
4258
+ matchedIndex: matchedIndex,
4259
+ incomingFingerprint: incomingFingerprint,
4260
+ existedFingerprint: existedFingerprint,
4261
+ tempOrder: tempOrder,
4262
+ booking: booking
4263
+ });
4264
+ if (shouldMerge && _typeof(shouldMerge) === 'object' && typeof shouldMerge.then === 'function') {
4265
+ return Promise.resolve(shouldMerge).then(commitProductLine);
4266
+ }
4267
+ commitProductLine(shouldMerge);
4268
+ }
4269
+
4137
4270
  /**
4138
4271
  * 添加商品行。带 booking 时强制独立行;num>1 时拆成多条 num=1 的 product+booking(对齐 BookingByStep / ticketBooking addService)。
4139
4272
  *
@@ -4141,14 +4274,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4141
4274
  * await order.addProductToOrder({ product_id: 1, num: 3 }, { start_time: '10:00' });
4142
4275
  * // → tempOrder.products 新增 3 行,每行 num=1,bookings 3 条
4143
4276
  */
4144
- )
4145
4277
  }, {
4146
4278
  key: "addProductToOrder",
4147
4279
  value: (function () {
4148
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(product, booking, options) {
4149
- var tempOrder, insertAfterProductUid, anchorIndex, insertAtIndex, _ref60, _productRecord$num, productRecord, splitCount, i, singleLine;
4150
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4151
- while (1) switch (_context23.prev = _context23.next) {
4280
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(product, booking, options) {
4281
+ var tempOrder, insertAfterProductUid, anchorIndex, insertAtIndex, _ref62, _productRecord$num, productRecord, splitCount, i, singleLine, _appendResult, appendResult;
4282
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
4283
+ while (1) switch (_context21.prev = _context21.next) {
4152
4284
  case 0:
4153
4285
  tempOrder = this.ensureTempOrder();
4154
4286
  insertAfterProductUid = options === null || options === void 0 ? void 0 : options.insertAfterProductUid;
@@ -4159,60 +4291,70 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4159
4291
  }) : -1;
4160
4292
  insertAtIndex = anchorIndex >= 0 ? anchorIndex + 1 : undefined;
4161
4293
  if (!booking) {
4162
- _context23.next = 22;
4294
+ _context21.next = 24;
4163
4295
  break;
4164
4296
  }
4165
4297
  productRecord = product;
4166
- splitCount = getSafeProductNum((_ref60 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref60 !== void 0 ? _ref60 : 1);
4298
+ splitCount = getSafeProductNum((_ref62 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref62 !== void 0 ? _ref62 : 1);
4167
4299
  if (!(splitCount > 1)) {
4168
- _context23.next = 22;
4300
+ _context21.next = 24;
4169
4301
  break;
4170
4302
  }
4171
4303
  i = 0;
4172
4304
  case 9:
4173
4305
  if (!(i < splitCount)) {
4174
- _context23.next = 19;
4306
+ _context21.next = 21;
4175
4307
  break;
4176
4308
  }
4177
4309
  singleLine = cloneDeep(productRecord);
4178
4310
  singleLine.num = 1;
4179
4311
  delete singleLine.product_quantity;
4180
- _context23.next = 15;
4181
- return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking), {
4312
+ _appendResult = this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking), {
4182
4313
  insertAtIndex: insertAtIndex
4183
4314
  });
4184
- case 15:
4315
+ if (!_appendResult) {
4316
+ _context21.next = 17;
4317
+ break;
4318
+ }
4319
+ _context21.next = 17;
4320
+ return _appendResult;
4321
+ case 17:
4185
4322
  if (insertAtIndex !== undefined) insertAtIndex += 1;
4186
- case 16:
4323
+ case 18:
4187
4324
  i += 1;
4188
- _context23.next = 9;
4325
+ _context21.next = 9;
4189
4326
  break;
4190
- case 19:
4191
- _context23.next = 21;
4192
- return this.finalizeProductOrderMutation(tempOrder);
4193
4327
  case 21:
4194
- return _context23.abrupt("return", tempOrder.products);
4195
- case 22:
4196
- _context23.next = 24;
4197
- return this.appendProductLineToTempOrder(tempOrder, product, booking, {
4328
+ _context21.next = 23;
4329
+ return this.finalizeProductOrderMutation(tempOrder);
4330
+ case 23:
4331
+ return _context21.abrupt("return", tempOrder.products);
4332
+ case 24:
4333
+ appendResult = this.appendProductLineToTempOrder(tempOrder, product, booking, {
4198
4334
  insertAtIndex: insertAtIndex
4199
4335
  });
4200
- case 24:
4201
- _context23.next = 26;
4336
+ if (!appendResult) {
4337
+ _context21.next = 28;
4338
+ break;
4339
+ }
4340
+ _context21.next = 28;
4341
+ return appendResult;
4342
+ case 28:
4343
+ _context21.next = 30;
4202
4344
  return this.finalizeProductOrderMutation(tempOrder);
4203
- case 26:
4345
+ case 30:
4204
4346
  this.logInfo('addProductToOrder success', {
4205
4347
  product_id: product.product_id,
4206
4348
  with_booking: !!booking
4207
4349
  });
4208
- return _context23.abrupt("return", tempOrder.products);
4209
- case 28:
4350
+ return _context21.abrupt("return", tempOrder.products);
4351
+ case 32:
4210
4352
  case "end":
4211
- return _context23.stop();
4353
+ return _context21.stop();
4212
4354
  }
4213
- }, _callee21, this);
4355
+ }, _callee19, this);
4214
4356
  }));
4215
- function addProductToOrder(_x26, _x27, _x28) {
4357
+ function addProductToOrder(_x21, _x22, _x23) {
4216
4358
  return _addProductToOrder.apply(this, arguments);
4217
4359
  }
4218
4360
  return addProductToOrder;
@@ -4230,93 +4372,103 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4230
4372
  }, {
4231
4373
  key: "addProductsToOrder",
4232
4374
  value: (function () {
4233
- var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(items, options) {
4234
- var tempOrder, _iterator20, _step20, item, product, booking, _ref61, _productRecord$num2, productRecord, splitCount, i, singleLine;
4235
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4236
- while (1) switch (_context24.prev = _context24.next) {
4375
+ var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(items, options) {
4376
+ var tempOrder, _iterator20, _step20, item, product, booking, _ref63, _productRecord$num2, productRecord, splitCount, i, singleLine, _appendResult2, appendResult;
4377
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4378
+ while (1) switch (_context22.prev = _context22.next) {
4237
4379
  case 0:
4238
4380
  tempOrder = this.ensureTempOrder();
4239
4381
  if (!(!Array.isArray(items) || items.length === 0)) {
4240
- _context24.next = 3;
4382
+ _context22.next = 3;
4241
4383
  break;
4242
4384
  }
4243
- return _context24.abrupt("return", tempOrder.products);
4385
+ return _context22.abrupt("return", tempOrder.products);
4244
4386
  case 3:
4245
4387
  _iterator20 = _createForOfIteratorHelper(items || []);
4246
- _context24.prev = 4;
4388
+ _context22.prev = 4;
4247
4389
  _iterator20.s();
4248
4390
  case 6:
4249
4391
  if ((_step20 = _iterator20.n()).done) {
4250
- _context24.next = 30;
4392
+ _context22.next = 34;
4251
4393
  break;
4252
4394
  }
4253
4395
  item = _step20.value;
4254
4396
  product = item.product, booking = item.booking;
4255
4397
  if (product) {
4256
- _context24.next = 11;
4398
+ _context22.next = 11;
4257
4399
  break;
4258
4400
  }
4259
- return _context24.abrupt("continue", 28);
4401
+ return _context22.abrupt("continue", 32);
4260
4402
  case 11:
4261
4403
  if (!booking) {
4262
- _context24.next = 26;
4404
+ _context22.next = 28;
4263
4405
  break;
4264
4406
  }
4265
4407
  productRecord = product;
4266
- splitCount = getSafeProductNum((_ref61 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 1);
4408
+ splitCount = getSafeProductNum((_ref63 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref63 !== void 0 ? _ref63 : 1);
4267
4409
  if (!(splitCount > 1)) {
4268
- _context24.next = 26;
4410
+ _context22.next = 28;
4269
4411
  break;
4270
4412
  }
4271
4413
  i = 0;
4272
4414
  case 16:
4273
4415
  if (!(i < splitCount)) {
4274
- _context24.next = 25;
4416
+ _context22.next = 27;
4275
4417
  break;
4276
4418
  }
4277
4419
  singleLine = cloneDeep(productRecord);
4278
4420
  singleLine.num = 1;
4279
4421
  delete singleLine.product_quantity;
4280
- _context24.next = 22;
4281
- return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
4282
- case 22:
4422
+ _appendResult2 = this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
4423
+ if (!_appendResult2) {
4424
+ _context22.next = 24;
4425
+ break;
4426
+ }
4427
+ _context22.next = 24;
4428
+ return _appendResult2;
4429
+ case 24:
4283
4430
  i += 1;
4284
- _context24.next = 16;
4431
+ _context22.next = 16;
4285
4432
  break;
4286
- case 25:
4287
- return _context24.abrupt("continue", 28);
4288
- case 26:
4289
- _context24.next = 28;
4290
- return this.appendProductLineToTempOrder(tempOrder, product, booking);
4433
+ case 27:
4434
+ return _context22.abrupt("continue", 32);
4291
4435
  case 28:
4292
- _context24.next = 6;
4436
+ appendResult = this.appendProductLineToTempOrder(tempOrder, product, booking);
4437
+ if (!appendResult) {
4438
+ _context22.next = 32;
4439
+ break;
4440
+ }
4441
+ _context22.next = 32;
4442
+ return appendResult;
4443
+ case 32:
4444
+ _context22.next = 6;
4293
4445
  break;
4294
- case 30:
4295
- _context24.next = 35;
4446
+ case 34:
4447
+ _context22.next = 39;
4296
4448
  break;
4297
- case 32:
4298
- _context24.prev = 32;
4299
- _context24.t0 = _context24["catch"](4);
4300
- _iterator20.e(_context24.t0);
4301
- case 35:
4302
- _context24.prev = 35;
4449
+ case 36:
4450
+ _context22.prev = 36;
4451
+ _context22.t0 = _context22["catch"](4);
4452
+ _iterator20.e(_context22.t0);
4453
+ case 39:
4454
+ _context22.prev = 39;
4303
4455
  _iterator20.f();
4304
- return _context24.finish(35);
4305
- case 38:
4306
- _context24.next = 40;
4456
+ return _context22.finish(39);
4457
+ case 42:
4458
+ _context22.next = 44;
4307
4459
  return this.finalizeProductOrderMutation(tempOrder, options);
4308
- case 40:
4460
+ case 44:
4309
4461
  this.logInfo('addProductsToOrder success', {
4310
4462
  itemsCount: items.length
4311
4463
  });
4312
- return _context24.abrupt("return", tempOrder.products);
4313
- case 42:
4464
+ return _context22.abrupt("return", tempOrder.products);
4465
+ case 46:
4314
4466
  case "end":
4315
- return _context24.stop();
4467
+ return _context22.stop();
4316
4468
  }
4317
- }, _callee22, this, [[4, 32, 35, 38]]);
4469
+ }, _callee20, this, [[4, 36, 39, 42]]);
4318
4470
  }));
4319
- function addProductsToOrder(_x29, _x30) {
4471
+ function addProductsToOrder(_x24, _x25) {
4320
4472
  return _addProductsToOrder.apply(this, arguments);
4321
4473
  }
4322
4474
  return addProductsToOrder;
@@ -4343,24 +4495,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4343
4495
  }, {
4344
4496
  key: "getBundleRuntimeIdentity",
4345
4497
  value: function getBundleRuntimeIdentity(bundle) {
4346
- var _ref62, _bundle$bundle_id2, _ref63, _bundle$bundle_group_2, _ref64, _ref65, _bundle$bundle_produc3, _ref66, _bundle$bundle_varian3;
4498
+ var _ref64, _bundle$bundle_id2, _ref65, _bundle$bundle_group_2, _ref66, _ref67, _bundle$bundle_produc3, _ref68, _bundle$bundle_varian3;
4347
4499
  if (!bundle || _typeof(bundle) !== 'object') return '';
4348
- return [(_ref62 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref62 !== void 0 ? _ref62 : '', (_ref63 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref63 !== void 0 ? _ref63 : '', (_ref64 = (_ref65 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref65 !== void 0 ? _ref65 : bundle.product_id) !== null && _ref64 !== void 0 ? _ref64 : '', (_ref66 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref66 !== void 0 ? _ref66 : 0].join('|');
4500
+ return [(_ref64 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref64 !== void 0 ? _ref64 : '', (_ref65 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref65 !== void 0 ? _ref65 : '', (_ref66 = (_ref67 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref67 !== void 0 ? _ref67 : bundle.product_id) !== null && _ref66 !== void 0 ? _ref66 : '', (_ref68 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref68 !== void 0 ? _ref68 : 0].join('|');
4349
4501
  }
4350
4502
  }, {
4351
4503
  key: "preservePersistedBundlePriceFields",
4352
4504
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
4353
- var _this27 = this;
4505
+ var _this28 = this;
4354
4506
  if (!Array.isArray(nextBundles)) return nextBundles;
4355
4507
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
4356
4508
  var previousByIdentity = new Map();
4357
4509
  previousBundles.forEach(function (bundle) {
4358
- var identity = _this27.getBundleRuntimeIdentity(bundle);
4510
+ var identity = _this28.getBundleRuntimeIdentity(bundle);
4359
4511
  if (identity) previousByIdentity.set(identity, bundle);
4360
4512
  });
4361
4513
  return nextBundles.map(function (bundle, index) {
4362
4514
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
4363
- var previous = previousByIdentity.get(_this27.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4515
+ var previous = previousByIdentity.get(_this28.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4364
4516
  if (!previous || _typeof(previous) !== 'object') return bundle;
4365
4517
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), (bundle.cover === undefined || bundle.cover === null || bundle.cover === '') && previous.cover !== undefined && previous.cover !== null && previous.cover !== '' ? {
4366
4518
  cover: previous.cover
@@ -4496,13 +4648,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4496
4648
  delete nextProduct.metadata.main_product_original_price;
4497
4649
  delete nextProduct.metadata.price_schema_version;
4498
4650
  } else if (callerChangesLineConfiguration && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
4499
- var _ref67, _targetProduct$metada10, _targetProduct$metada11, _ref68, _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
4651
+ var _ref69, _targetProduct$metada10, _targetProduct$metada11, _ref70, _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
4500
4652
  // 仅 option / bundle 变化时,保留历史 source 和主商品折扣金额,
4501
4653
  // 但必须让 original 与 selling 一起随新的 option 金额移动。
4502
4654
  var previousOptionSum = sumOptionUnitPrice(getProductSkuOptions(targetProduct));
4503
4655
  var nextOptionSum = sumOptionUnitPrice(getProductSkuOptions(nextProduct));
4504
- var _previousMainOriginal = new Decimal(Number((_ref67 = (_targetProduct$metada10 = (_targetProduct$metada11 = targetProduct.metadata) === null || _targetProduct$metada11 === void 0 ? void 0 : _targetProduct$metada11.main_product_original_price) !== null && _targetProduct$metada10 !== void 0 ? _targetProduct$metada10 : targetProduct.original_price) !== null && _ref67 !== void 0 ? _ref67 : 0) || 0);
4505
- var _previousMainSelling = new Decimal(Number((_ref68 = (_targetProduct$metada12 = (_targetProduct$metada13 = targetProduct.metadata) === null || _targetProduct$metada13 === void 0 ? void 0 : _targetProduct$metada13.main_product_selling_price) !== null && _targetProduct$metada12 !== void 0 ? _targetProduct$metada12 : targetProduct.selling_price) !== null && _ref68 !== void 0 ? _ref68 : _previousMainOriginal.toNumber()) || 0);
4656
+ var _previousMainOriginal = new Decimal(Number((_ref69 = (_targetProduct$metada10 = (_targetProduct$metada11 = targetProduct.metadata) === null || _targetProduct$metada11 === void 0 ? void 0 : _targetProduct$metada11.main_product_original_price) !== null && _targetProduct$metada10 !== void 0 ? _targetProduct$metada10 : targetProduct.original_price) !== null && _ref69 !== void 0 ? _ref69 : 0) || 0);
4657
+ var _previousMainSelling = new Decimal(Number((_ref70 = (_targetProduct$metada12 = (_targetProduct$metada13 = targetProduct.metadata) === null || _targetProduct$metada13 === void 0 ? void 0 : _targetProduct$metada13.main_product_selling_price) !== null && _targetProduct$metada12 !== void 0 ? _targetProduct$metada12 : targetProduct.selling_price) !== null && _ref70 !== void 0 ? _ref70 : _previousMainOriginal.toNumber()) || 0);
4506
4658
  var _preservedDiscount = _previousMainOriginal.minus(_previousMainSelling);
4507
4659
  var previousSource = ((_targetProduct$metada14 = targetProduct.metadata) === null || _targetProduct$metada14 === void 0 ? void 0 : _targetProduct$metada14.source_product_price) != null ? new Decimal(Number(targetProduct.metadata.source_product_price) || 0) : _previousMainOriginal.minus(previousOptionSum);
4508
4660
  var _nextMainOriginal = previousSource.plus(nextOptionSum);
@@ -4522,7 +4674,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4522
4674
  }
4523
4675
  // normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
4524
4676
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
4525
- var normalizedProduct = mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct));
4677
+ var normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct)));
4526
4678
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4527
4679
  var preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata = nextProduct.metadata) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada15 = targetProduct.metadata) === null || _targetProduct$metada15 === void 0 ? void 0 : _targetProduct$metada15.booking_uid);
4528
4680
  if (!booking && preservedBookingUid) {
@@ -4561,21 +4713,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4561
4713
  }, {
4562
4714
  key: "updateOrderProduct",
4563
4715
  value: function () {
4564
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
4716
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
4565
4717
  var tempOrder, updatedProductUid;
4566
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4567
- while (1) switch (_context25.prev = _context25.next) {
4718
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4719
+ while (1) switch (_context23.prev = _context23.next) {
4568
4720
  case 0:
4569
4721
  tempOrder = this.ensureTempOrder();
4570
4722
  updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
4571
- _context25.next = 4;
4723
+ _context23.next = 4;
4572
4724
  return this.applyPromotion();
4573
4725
  case 4:
4574
4726
  this.applyDiscount({
4575
4727
  reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
4576
4728
  });
4577
4729
  this.sanitizeTempOrderProducts(tempOrder);
4578
- _context25.next = 8;
4730
+ _context23.next = 8;
4579
4731
  return this.recalculateSummary({
4580
4732
  createIfMissing: true
4581
4733
  });
@@ -4584,14 +4736,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4584
4736
  this.logInfo('updateOrderProduct success', {
4585
4737
  params: params
4586
4738
  });
4587
- return _context25.abrupt("return", tempOrder.products);
4739
+ return _context23.abrupt("return", tempOrder.products);
4588
4740
  case 11:
4589
4741
  case "end":
4590
- return _context25.stop();
4742
+ return _context23.stop();
4591
4743
  }
4592
- }, _callee23, this);
4744
+ }, _callee21, this);
4593
4745
  }));
4594
- function updateOrderProduct(_x31) {
4746
+ function updateOrderProduct(_x26) {
4595
4747
  return _updateOrderProduct.apply(this, arguments);
4596
4748
  }
4597
4749
  return updateOrderProduct;
@@ -4599,28 +4751,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4599
4751
  }, {
4600
4752
  key: "updateOrderProducts",
4601
4753
  value: function () {
4602
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(paramsList) {
4603
- var _this28 = this;
4754
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(paramsList) {
4755
+ var _this29 = this;
4604
4756
  var tempOrder, reapplyBookingDiscountProductUids;
4605
- return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4606
- while (1) switch (_context26.prev = _context26.next) {
4757
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4758
+ while (1) switch (_context24.prev = _context24.next) {
4607
4759
  case 0:
4608
4760
  tempOrder = this.ensureTempOrder();
4609
4761
  if (paramsList.length) {
4610
- _context26.next = 3;
4762
+ _context24.next = 3;
4611
4763
  break;
4612
4764
  }
4613
- return _context26.abrupt("return", tempOrder.products);
4765
+ return _context24.abrupt("return", tempOrder.products);
4614
4766
  case 3:
4615
4767
  reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
4616
- var updatedProductUid = _this28.applyOrderProductUpdateToTempOrder(tempOrder, params);
4768
+ var updatedProductUid = _this29.applyOrderProductUpdateToTempOrder(tempOrder, params);
4617
4769
  // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
4618
4770
  if (params.allow_booking_discount_reapply && updatedProductUid) {
4619
4771
  acc.push(String(updatedProductUid));
4620
4772
  }
4621
4773
  return acc;
4622
4774
  }, []);
4623
- _context26.next = 6;
4775
+ _context24.next = 6;
4624
4776
  return this.finalizeAfterProductsMutation(tempOrder, {
4625
4777
  reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
4626
4778
  });
@@ -4628,14 +4780,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4628
4780
  this.logInfo('updateOrderProduct success', {
4629
4781
  paramsList: paramsList
4630
4782
  });
4631
- return _context26.abrupt("return", tempOrder.products);
4783
+ return _context24.abrupt("return", tempOrder.products);
4632
4784
  case 8:
4633
4785
  case "end":
4634
- return _context26.stop();
4786
+ return _context24.stop();
4635
4787
  }
4636
- }, _callee24, this);
4788
+ }, _callee22, this);
4637
4789
  }));
4638
- function updateOrderProducts(_x32) {
4790
+ function updateOrderProducts(_x27) {
4639
4791
  return _updateOrderProducts.apply(this, arguments);
4640
4792
  }
4641
4793
  return updateOrderProducts;
@@ -4643,11 +4795,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4643
4795
  }, {
4644
4796
  key: "updateOrderProductQuantity",
4645
4797
  value: function () {
4646
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
4798
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
4647
4799
  var _targetProduct$metada17;
4648
- var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
4649
- return _regeneratorRuntime().wrap(function _callee25$(_context27) {
4650
- while (1) switch (_context27.prev = _context27.next) {
4800
+ var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct, settlementSnapshot, currencyProductId, asset, requiredAmount, balance;
4801
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4802
+ while (1) switch (_context25.prev = _context25.next) {
4651
4803
  case 0:
4652
4804
  product_id = params.product_id, product_variant_id = params.product_variant_id, num = params.num, unique_identification_number = params.unique_identification_number, identity_key = params.identity_key, product_sku = params.product_sku, product_bundle = params.product_bundle;
4653
4805
  tempOrder = this.ensureTempOrder();
@@ -4677,42 +4829,75 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4677
4829
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
4678
4830
  }
4679
4831
  if (!(productIndex === -1)) {
4680
- _context27.next = 13;
4832
+ _context25.next = 13;
4681
4833
  break;
4682
4834
  }
4683
4835
  throw new Error('[Order] 目标商品不存在,无法更新数量');
4684
4836
  case 13:
4685
4837
  targetProduct = tempOrder.products[productIndex];
4686
- normalizedProduct = normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
4838
+ normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
4687
4839
  num: getSafeProductNum(num),
4688
4840
  metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
4689
4841
  unique_identification_number: ((_targetProduct$metada17 = targetProduct.metadata) === null || _targetProduct$metada17 === void 0 ? void 0 : _targetProduct$metada17.unique_identification_number) || unique_identification_number
4690
4842
  })
4691
- }));
4843
+ })));
4692
4844
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4845
+ settlementSnapshot = getSelectedSettlementSnapshot(normalizedProduct);
4846
+ if (!(this.isMultiCurrencySettlementEnabled() && (settlementSnapshot === null || settlementSnapshot === void 0 ? void 0 : settlementSnapshot.settlement_type) === 'virtual_currency' && tempOrder.customer_id && Number(tempOrder.customer_id) !== 1)) {
4847
+ _context25.next = 26;
4848
+ break;
4849
+ }
4850
+ currencyProductId = Number(settlementSnapshot.currency_product_id);
4851
+ asset = (this.store.virtualCurrencyList || []).find(function (item) {
4852
+ return Number(item === null || item === void 0 ? void 0 : item.product_id) === currencyProductId;
4853
+ });
4854
+ if (asset) {
4855
+ _context25.next = 22;
4856
+ break;
4857
+ }
4858
+ throw new VirtualCurrencyAssetNotFoundError(currencyProductId);
4859
+ case 22:
4860
+ requiredAmount = tempOrder.products.reduce(function (sum, item, index) {
4861
+ var current = index === productIndex ? normalizedProduct : item;
4862
+ var currentSnapshot = getSelectedSettlementSnapshot(current);
4863
+ return sum.plus(new Decimal((currentSnapshot === null || currentSnapshot === void 0 ? void 0 : currentSnapshot.price) || current.selling_price || 0).times(current.num || 1));
4864
+ }, new Decimal(0));
4865
+ balance = new Decimal(asset.balance || 0);
4866
+ if (!balance.lt(requiredAmount)) {
4867
+ _context25.next = 26;
4868
+ break;
4869
+ }
4870
+ throw new VirtualCurrencyBalanceError(balance.toFixed(2), requiredAmount.toFixed(2));
4871
+ case 26:
4693
4872
  tempOrder.products[productIndex] = normalizedProduct;
4694
- _context27.next = 19;
4873
+ this.prepareVirtualSettlementTempOrder(tempOrder);
4874
+ if (this.isActiveVirtualSettlementOrder(tempOrder)) {
4875
+ _context25.next = 32;
4876
+ break;
4877
+ }
4878
+ _context25.next = 31;
4695
4879
  return this.applyPromotion();
4696
- case 19:
4880
+ case 31:
4697
4881
  this.applyDiscount();
4882
+ case 32:
4698
4883
  this.sanitizeTempOrderProducts(tempOrder);
4699
- _context27.next = 23;
4884
+ _context25.next = 35;
4700
4885
  return this.recalculateSummary({
4701
4886
  createIfMissing: true
4702
4887
  });
4703
- case 23:
4888
+ case 35:
4704
4889
  this.persistTempOrder();
4705
4890
  this.logInfo('updateOrderProductQuantity success', {
4706
4891
  params: params
4707
4892
  });
4708
- return _context27.abrupt("return", tempOrder.products);
4709
- case 26:
4893
+ return _context25.abrupt("return", tempOrder.products);
4894
+ case 38:
4710
4895
  case "end":
4711
- return _context27.stop();
4896
+ return _context25.stop();
4712
4897
  }
4713
- }, _callee25, this);
4898
+ }, _callee23, this);
4714
4899
  }));
4715
- function updateOrderProductQuantity(_x33) {
4900
+ function updateOrderProductQuantity(_x28) {
4716
4901
  return _updateOrderProductQuantity.apply(this, arguments);
4717
4902
  }
4718
4903
  return updateOrderProductQuantity;
@@ -4753,19 +4938,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4753
4938
  }, {
4754
4939
  key: "finalizeAfterProductsMutation",
4755
4940
  value: (function () {
4756
- var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(tempOrder, options) {
4757
- return _regeneratorRuntime().wrap(function _callee26$(_context28) {
4758
- while (1) switch (_context28.prev = _context28.next) {
4941
+ var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(tempOrder, options) {
4942
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4943
+ while (1) switch (_context26.prev = _context26.next) {
4759
4944
  case 0:
4760
4945
  this.syncTempOrderHolderFromBookings(tempOrder);
4761
- _context28.next = 3;
4946
+ _context26.next = 3;
4762
4947
  return this.applyPromotion();
4763
4948
  case 3:
4764
4949
  this.applyDiscount({
4765
4950
  reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
4766
4951
  });
4767
4952
  this.sanitizeTempOrderProducts(tempOrder);
4768
- _context28.next = 7;
4953
+ _context26.next = 7;
4769
4954
  return this.recalculateSummary({
4770
4955
  createIfMissing: true
4771
4956
  });
@@ -4773,11 +4958,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4773
4958
  this.persistTempOrder();
4774
4959
  case 8:
4775
4960
  case "end":
4776
- return _context28.stop();
4961
+ return _context26.stop();
4777
4962
  }
4778
- }, _callee26, this);
4963
+ }, _callee24, this);
4779
4964
  }));
4780
- function finalizeAfterProductsMutation(_x34, _x35) {
4965
+ function finalizeAfterProductsMutation(_x29, _x30) {
4781
4966
  return _finalizeAfterProductsMutation.apply(this, arguments);
4782
4967
  }
4783
4968
  return finalizeAfterProductsMutation;
@@ -4792,19 +4977,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4792
4977
  }, {
4793
4978
  key: "removeProductsFromOrder",
4794
4979
  value: (function () {
4795
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(identities, options) {
4796
- var _this29 = this;
4980
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(identities, options) {
4981
+ var _this30 = this;
4797
4982
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, preserveDisplayPosition, anchorIndex, productsAfterAnchor, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3, remainingProductIndex, remainingProduct, nextProduct, productsWithoutRemaining, nextProductIndex;
4798
- return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4799
- while (1) switch (_context30.prev = _context30.next) {
4983
+ return _regeneratorRuntime().wrap(function _callee25$(_context28) {
4984
+ while (1) switch (_context28.prev = _context28.next) {
4800
4985
  case 0:
4801
4986
  tempOrder = this.ensureTempOrder();
4802
4987
  this.repairDuplicateProductLineIdentities(tempOrder);
4803
4988
  if (identities.length) {
4804
- _context30.next = 4;
4989
+ _context28.next = 4;
4805
4990
  break;
4806
4991
  }
4807
- return _context30.abrupt("return", tempOrder.products);
4992
+ return _context28.abrupt("return", tempOrder.products);
4808
4993
  case 4:
4809
4994
  productsBeforeRemove = tempOrder.products || [];
4810
4995
  bookingsBeforeRemove = tempOrder.bookings || [];
@@ -4834,29 +5019,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4834
5019
  }
4835
5020
  linkedBookingUidsToRemove = new Set();
4836
5021
  _iterator21 = _createForOfIteratorHelper(matchedProducts);
4837
- _context30.prev = 15;
5022
+ _context28.prev = 15;
4838
5023
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
4839
5024
  var _metadata11, _metadata12, _metadata13, _metadata14;
4840
5025
  var product, productUid, productBookingUid, isAddTimeProduct;
4841
- return _regeneratorRuntime().wrap(function _loop3$(_context29) {
4842
- while (1) switch (_context29.prev = _context29.next) {
5026
+ return _regeneratorRuntime().wrap(function _loop3$(_context27) {
5027
+ while (1) switch (_context27.prev = _context27.next) {
4843
5028
  case 0:
4844
5029
  product = _step21.value;
4845
5030
  productUid = (product === null || product === void 0 || (_metadata11 = product.metadata) === null || _metadata11 === void 0 ? void 0 : _metadata11.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
4846
5031
  productBookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_metadata12 = product.metadata) === null || _metadata12 === void 0 ? void 0 : _metadata12.booking_uid);
4847
5032
  isAddTimeProduct = (product === null || product === void 0 || (_metadata13 = product.metadata) === null || _metadata13 === void 0 ? void 0 : _metadata13.product_add_schedule_time) !== undefined && (product === null || product === void 0 || (_metadata14 = product.metadata) === null || _metadata14 === void 0 ? void 0 : _metadata14.product_add_schedule_time) !== null;
4848
5033
  if (!isAddTimeProduct) {
4849
- _context29.next = 6;
5034
+ _context27.next = 6;
4850
5035
  break;
4851
5036
  }
4852
- return _context29.abrupt("return", 1);
5037
+ return _context27.abrupt("return", 1);
4853
5038
  case 6:
4854
5039
  if (productBookingUid !== undefined && productBookingUid !== null && productBookingUid !== '') {
4855
5040
  linkedBookingUidsToRemove.add(String(productBookingUid));
4856
5041
  }
4857
5042
  if (productUid !== undefined && productUid !== null && productUid !== '') {
4858
5043
  bookingsBeforeRemove.forEach(function (booking) {
4859
- var bookingUid = _this29.getBookingUniqueIdentificationNumber(booking);
5044
+ var bookingUid = _this30.getBookingUniqueIdentificationNumber(booking);
4860
5045
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
4861
5046
  linkedBookingUidsToRemove.add(bookingUid);
4862
5047
  }
@@ -4864,37 +5049,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4864
5049
  }
4865
5050
  case 8:
4866
5051
  case "end":
4867
- return _context29.stop();
5052
+ return _context27.stop();
4868
5053
  }
4869
5054
  }, _loop3);
4870
5055
  });
4871
5056
  _iterator21.s();
4872
5057
  case 18:
4873
5058
  if ((_step21 = _iterator21.n()).done) {
4874
- _context30.next = 24;
5059
+ _context28.next = 24;
4875
5060
  break;
4876
5061
  }
4877
- return _context30.delegateYield(_loop3(), "t0", 20);
5062
+ return _context28.delegateYield(_loop3(), "t0", 20);
4878
5063
  case 20:
4879
- if (!_context30.t0) {
4880
- _context30.next = 22;
5064
+ if (!_context28.t0) {
5065
+ _context28.next = 22;
4881
5066
  break;
4882
5067
  }
4883
- return _context30.abrupt("continue", 22);
5068
+ return _context28.abrupt("continue", 22);
4884
5069
  case 22:
4885
- _context30.next = 18;
5070
+ _context28.next = 18;
4886
5071
  break;
4887
5072
  case 24:
4888
- _context30.next = 29;
5073
+ _context28.next = 29;
4889
5074
  break;
4890
5075
  case 26:
4891
- _context30.prev = 26;
4892
- _context30.t1 = _context30["catch"](15);
4893
- _iterator21.e(_context30.t1);
5076
+ _context28.prev = 26;
5077
+ _context28.t1 = _context28["catch"](15);
5078
+ _iterator21.e(_context28.t1);
4894
5079
  case 29:
4895
- _context30.prev = 29;
5080
+ _context28.prev = 29;
4896
5081
  _iterator21.f();
4897
- return _context30.finish(29);
5082
+ return _context28.finish(29);
4898
5083
  case 32:
4899
5084
  if (linkedBookingUidsToRemove.size > 0) {
4900
5085
  // 删除主预约商品时,同步移除挂在同一 booking_uid 下的加时商品,避免残留孤儿行。
@@ -4921,20 +5106,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4921
5106
  tempOrder.products = nextProductIndex >= 0 ? [].concat(_toConsumableArray(productsWithoutRemaining.slice(0, nextProductIndex)), [remainingProduct], _toConsumableArray(productsWithoutRemaining.slice(nextProductIndex))) : [].concat(_toConsumableArray(productsWithoutRemaining), [remainingProduct]);
4922
5107
  }
4923
5108
  }
4924
- _context30.next = 36;
5109
+ _context28.next = 36;
4925
5110
  return this.finalizeAfterProductsMutation(tempOrder);
4926
5111
  case 36:
4927
5112
  this.logInfo('removeProductsFromOrder success', {
4928
5113
  identities: identities
4929
5114
  });
4930
- return _context30.abrupt("return", tempOrder.products);
5115
+ return _context28.abrupt("return", tempOrder.products);
4931
5116
  case 38:
4932
5117
  case "end":
4933
- return _context30.stop();
5118
+ return _context28.stop();
4934
5119
  }
4935
- }, _callee27, this, [[15, 26, 29, 32]]);
5120
+ }, _callee25, this, [[15, 26, 29, 32]]);
4936
5121
  }));
4937
- function removeProductsFromOrder(_x36, _x37) {
5122
+ function removeProductsFromOrder(_x31, _x32) {
4938
5123
  return _removeProductsFromOrder.apply(this, arguments);
4939
5124
  }
4940
5125
  return removeProductsFromOrder;
@@ -4942,18 +5127,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4942
5127
  }, {
4943
5128
  key: "removeProductFromOrder",
4944
5129
  value: function () {
4945
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(identity, options) {
4946
- return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4947
- while (1) switch (_context31.prev = _context31.next) {
5130
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(identity, options) {
5131
+ return _regeneratorRuntime().wrap(function _callee26$(_context29) {
5132
+ while (1) switch (_context29.prev = _context29.next) {
4948
5133
  case 0:
4949
- return _context31.abrupt("return", this.removeProductsFromOrder([identity], options));
5134
+ return _context29.abrupt("return", this.removeProductsFromOrder([identity], options));
4950
5135
  case 1:
4951
5136
  case "end":
4952
- return _context31.stop();
5137
+ return _context29.stop();
4953
5138
  }
4954
- }, _callee28, this);
5139
+ }, _callee26, this);
4955
5140
  }));
4956
- function removeProductFromOrder(_x38, _x39) {
5141
+ function removeProductFromOrder(_x33, _x34) {
4957
5142
  return _removeProductFromOrder.apply(this, arguments);
4958
5143
  }
4959
5144
  return removeProductFromOrder;
@@ -4965,65 +5150,122 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4965
5150
  }, {
4966
5151
  key: "clearOrderCartLines",
4967
5152
  value: (function () {
4968
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
5153
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
4969
5154
  var tempOrder;
4970
- return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4971
- while (1) switch (_context32.prev = _context32.next) {
5155
+ return _regeneratorRuntime().wrap(function _callee27$(_context30) {
5156
+ while (1) switch (_context30.prev = _context30.next) {
4972
5157
  case 0:
4973
5158
  tempOrder = this.ensureTempOrder();
4974
5159
  tempOrder.products = [];
4975
5160
  tempOrder.bookings = [];
5161
+ releaseTempOrderSettlementState(tempOrder);
4976
5162
  this.syncTempOrderHolderFromBookings(tempOrder);
4977
5163
  if (tempOrder._extend && _typeof(tempOrder._extend) === 'object') {
4978
5164
  tempOrder._extend = _objectSpread(_objectSpread({}, tempOrder._extend), {}, {
4979
5165
  productsByUid: {}
4980
5166
  });
4981
5167
  }
4982
- _context32.next = 7;
5168
+ _context30.next = 8;
4983
5169
  return this.applyPromotion();
4984
- case 7:
5170
+ case 8:
4985
5171
  this.applyDiscount();
4986
5172
  this.sanitizeTempOrderProducts(tempOrder);
4987
- _context32.next = 11;
5173
+ _context30.next = 12;
4988
5174
  return this.recalculateSummary({
4989
5175
  createIfMissing: true
4990
5176
  });
4991
- case 11:
5177
+ case 12:
4992
5178
  this.persistTempOrder();
4993
5179
  this.logInfo('clearOrderCartLines success', {});
4994
- return _context32.abrupt("return", tempOrder);
4995
- case 14:
5180
+ return _context30.abrupt("return", tempOrder);
5181
+ case 15:
4996
5182
  case "end":
4997
- return _context32.stop();
5183
+ return _context30.stop();
4998
5184
  }
4999
- }, _callee29, this);
5185
+ }, _callee27, this);
5000
5186
  }));
5001
5187
  function clearOrderCartLines() {
5002
5188
  return _clearOrderCartLines.apply(this, arguments);
5003
5189
  }
5004
5190
  return clearOrderCartLines;
5191
+ }()
5192
+ /**
5193
+ * 切换购物车结算单位时清理所有会影响新币种的订单状态,但保留当前客户。
5194
+ */
5195
+ )
5196
+ }, {
5197
+ key: "clearOrderForSettlementSwitch",
5198
+ value: (function () {
5199
+ var _clearOrderForSettlementSwitch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
5200
+ var _this$store$discount22, _this$store$discount23;
5201
+ var tempOrder;
5202
+ return _regeneratorRuntime().wrap(function _callee28$(_context31) {
5203
+ while (1) switch (_context31.prev = _context31.next) {
5204
+ case 0:
5205
+ tempOrder = this.ensureTempOrder();
5206
+ tempOrder.products = [];
5207
+ tempOrder.bookings = [];
5208
+ tempOrder.discount_list = [];
5209
+ tempOrder.payments = [];
5210
+ tempOrder.refunds = [];
5211
+ tempOrder.shop_discount = '0.00';
5212
+ tempOrder.surcharges = [];
5213
+ releaseTempOrderSettlementState(tempOrder);
5214
+ this.syncTempOrderHolderFromBookings(tempOrder);
5215
+ if (tempOrder._extend && _typeof(tempOrder._extend) === 'object') {
5216
+ tempOrder._extend = _objectSpread(_objectSpread({}, tempOrder._extend), {}, {
5217
+ productsByUid: {}
5218
+ });
5219
+ }
5220
+ _context31.next = 13;
5221
+ return (_this$store$discount22 = this.store.discount) === null || _this$store$discount22 === void 0 ? void 0 : _this$store$discount22.setDiscountList([]);
5222
+ case 13:
5223
+ _context31.next = 15;
5224
+ return (_this$store$discount23 = this.store.discount) === null || _this$store$discount23 === void 0 ? void 0 : _this$store$discount23.setOriginalDiscountList([]);
5225
+ case 15:
5226
+ this.hasActiveCustomerBoundDiscount = false;
5227
+ this.lastUnfulfilledPromotions = [];
5228
+ this.lastGiftActions = null;
5229
+ _context31.next = 20;
5230
+ return this.recalculateSummary({
5231
+ createIfMissing: true
5232
+ });
5233
+ case 20:
5234
+ this.persistTempOrder();
5235
+ this.logInfo('clearOrderForSettlementSwitch success', {});
5236
+ return _context31.abrupt("return", tempOrder);
5237
+ case 23:
5238
+ case "end":
5239
+ return _context31.stop();
5240
+ }
5241
+ }, _callee28, this);
5242
+ }));
5243
+ function clearOrderForSettlementSwitch() {
5244
+ return _clearOrderForSettlementSwitch.apply(this, arguments);
5245
+ }
5246
+ return clearOrderForSettlementSwitch;
5005
5247
  }() // ─── TempOrder: 提交 ───
5006
5248
  )
5007
5249
  }, {
5008
5250
  key: "buildCurrentSubmitPayloadForLocalPrint",
5009
5251
  value: function buildCurrentSubmitPayloadForLocalPrint(params) {
5010
- var _params$cacheId, _this$otherParams3, _ref69, _params$businessCode, _this$otherParams4, _this$otherParams5;
5252
+ var _params$cacheId, _this$otherParams4, _ref71, _params$businessCode, _this$otherParams5, _this$otherParams6;
5011
5253
  var tempOrder = this.ensureTempOrder();
5012
5254
  this.persistTempOrder();
5013
5255
  var payload = buildSubmitPayload({
5014
5256
  tempOrder: tempOrder,
5015
5257
  cacheId: (_params$cacheId = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId !== void 0 ? _params$cacheId : this.cacheId,
5016
- platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.platform),
5017
- businessCode: (_ref69 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.businessCode) !== null && _ref69 !== void 0 ? _ref69 : (_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.business_code,
5258
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.platform),
5259
+ businessCode: (_ref71 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.businessCode) !== null && _ref71 !== void 0 ? _ref71 : (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.business_code,
5018
5260
  channel: params === null || params === void 0 ? void 0 : params.channel,
5019
5261
  type: params === null || params === void 0 ? void 0 : params.type,
5020
5262
  summary: this.store.summary || createEmptySummary(),
5021
5263
  enhance: function enhance(nextPayload) {
5022
- var _ref70, _tempOrder$order_numb, _ref71, _tempOrder$shop_order, _ref72, _tempOrder$shop_full_;
5264
+ var _ref72, _tempOrder$order_numb, _ref73, _tempOrder$shop_order, _ref74, _tempOrder$shop_full_;
5023
5265
  return _objectSpread(_objectSpread({}, nextPayload), {}, {
5024
- order_number: (_ref70 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref70 !== void 0 ? _ref70 : null,
5025
- shop_order_number: (_ref71 = (_tempOrder$shop_order = tempOrder.shop_order_number) !== null && _tempOrder$shop_order !== void 0 ? _tempOrder$shop_order : nextPayload.shop_order_number) !== null && _ref71 !== void 0 ? _ref71 : null,
5026
- shop_full_order_number: (_ref72 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref72 !== void 0 ? _ref72 : null,
5266
+ order_number: (_ref72 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref72 !== void 0 ? _ref72 : null,
5267
+ shop_order_number: (_ref73 = (_tempOrder$shop_order = tempOrder.shop_order_number) !== null && _tempOrder$shop_order !== void 0 ? _tempOrder$shop_order : nextPayload.shop_order_number) !== null && _ref73 !== void 0 ? _ref73 : null,
5268
+ shop_full_order_number: (_ref74 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref74 !== void 0 ? _ref74 : null,
5027
5269
  small_ticket_data_flag: 1
5028
5270
  });
5029
5271
  }
@@ -5034,17 +5276,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5034
5276
  }, {
5035
5277
  key: "applyLocalPrintOrderNumbers",
5036
5278
  value: function () {
5037
- var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order) {
5279
+ var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(order) {
5038
5280
  var tempOrder, shopOrderNumber, shopFullOrderNumber;
5039
- return _regeneratorRuntime().wrap(function _callee30$(_context33) {
5040
- while (1) switch (_context33.prev = _context33.next) {
5281
+ return _regeneratorRuntime().wrap(function _callee29$(_context32) {
5282
+ while (1) switch (_context32.prev = _context32.next) {
5041
5283
  case 0:
5042
5284
  tempOrder = this.ensureTempOrder();
5043
5285
  if (!(!order || _typeof(order) !== 'object')) {
5044
- _context33.next = 3;
5286
+ _context32.next = 3;
5045
5287
  break;
5046
5288
  }
5047
- return _context33.abrupt("return", tempOrder);
5289
+ return _context32.abrupt("return", tempOrder);
5048
5290
  case 3:
5049
5291
  shopOrderNumber = order.shop_order_number;
5050
5292
  shopFullOrderNumber = order.shop_full_order_number;
@@ -5055,17 +5297,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5055
5297
  tempOrder.shop_full_order_number = String(shopFullOrderNumber);
5056
5298
  }
5057
5299
  this.persistTempOrder();
5058
- _context33.next = 10;
5300
+ _context32.next = 10;
5059
5301
  return this.saveDraft();
5060
5302
  case 10:
5061
- return _context33.abrupt("return", tempOrder);
5303
+ return _context32.abrupt("return", tempOrder);
5062
5304
  case 11:
5063
5305
  case "end":
5064
- return _context33.stop();
5306
+ return _context32.stop();
5065
5307
  }
5066
- }, _callee30, this);
5308
+ }, _callee29, this);
5067
5309
  }));
5068
- function applyLocalPrintOrderNumbers(_x40) {
5310
+ function applyLocalPrintOrderNumbers(_x35) {
5069
5311
  return _applyLocalPrintOrderNumbers.apply(this, arguments);
5070
5312
  }
5071
5313
  return applyLocalPrintOrderNumbers;
@@ -5073,42 +5315,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5073
5315
  }, {
5074
5316
  key: "saveTempOrderAsDraft",
5075
5317
  value: function () {
5076
- var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
5077
- var _params$cacheId2, _this$otherParams6, _this$otherParams7, _this$otherParams8, _params$type, _this$otherParams9, _payload$products;
5318
+ var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
5319
+ var _params$cacheId2, _this$otherParams7, _this$otherParams8, _this$otherParams9, _params$type, _this$otherParams10, _payload$products;
5078
5320
  var tempOrder, latestSummary, payload;
5079
- return _regeneratorRuntime().wrap(function _callee31$(_context34) {
5080
- while (1) switch (_context34.prev = _context34.next) {
5321
+ return _regeneratorRuntime().wrap(function _callee30$(_context33) {
5322
+ while (1) switch (_context33.prev = _context33.next) {
5081
5323
  case 0:
5082
5324
  tempOrder = this.ensureTempOrder();
5083
5325
  this.ensureExternalSaleNumber(tempOrder);
5084
5326
  this.persistTempOrder();
5085
- _context34.next = 5;
5327
+ _context33.next = 5;
5086
5328
  return this.recalculateSummary({
5087
5329
  createIfMissing: true
5088
5330
  });
5089
5331
  case 5:
5090
- _context34.t1 = _context34.sent;
5091
- if (_context34.t1) {
5092
- _context34.next = 8;
5332
+ _context33.t1 = _context33.sent;
5333
+ if (_context33.t1) {
5334
+ _context33.next = 8;
5093
5335
  break;
5094
5336
  }
5095
- _context34.t1 = this.store.summary;
5337
+ _context33.t1 = this.store.summary;
5096
5338
  case 8:
5097
- _context34.t0 = _context34.t1;
5098
- if (_context34.t0) {
5099
- _context34.next = 11;
5339
+ _context33.t0 = _context33.t1;
5340
+ if (_context33.t0) {
5341
+ _context33.next = 11;
5100
5342
  break;
5101
5343
  }
5102
- _context34.t0 = createEmptySummary();
5344
+ _context33.t0 = createEmptySummary();
5103
5345
  case 11:
5104
- latestSummary = _context34.t0;
5346
+ latestSummary = _context33.t0;
5105
5347
  payload = buildSubmitPayload({
5106
5348
  tempOrder: tempOrder,
5107
5349
  cacheId: (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId,
5108
- platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
5109
- businessCode: (params === null || params === void 0 ? void 0 : params.businessCode) || ((_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) || ((_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code) || tempOrder.business_code,
5350
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.platform),
5351
+ businessCode: (params === null || params === void 0 ? void 0 : params.businessCode) || ((_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.businessCode) || ((_this$otherParams9 = this.otherParams) === null || _this$otherParams9 === void 0 ? void 0 : _this$otherParams9.business_code) || tempOrder.business_code,
5110
5352
  channel: params === null || params === void 0 ? void 0 : params.channel,
5111
- type: (_params$type = params === null || params === void 0 ? void 0 : params.type) !== null && _params$type !== void 0 ? _params$type : (_this$otherParams9 = this.otherParams) === null || _this$otherParams9 === void 0 ? void 0 : _this$otherParams9.type,
5353
+ type: (_params$type = params === null || params === void 0 ? void 0 : params.type) !== null && _params$type !== void 0 ? _params$type : (_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.type,
5112
5354
  summary: latestSummary,
5113
5355
  enhance: params === null || params === void 0 ? void 0 : params.enhancePayload
5114
5356
  });
@@ -5122,17 +5364,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5122
5364
  externalSaleNumber: payload.external_sale_number,
5123
5365
  productsCount: ((_payload$products = payload.products) === null || _payload$products === void 0 ? void 0 : _payload$products.length) || 0
5124
5366
  });
5125
- return _context34.abrupt("return", this.request.post('/order/sales/draft', payload, {
5367
+ return _context33.abrupt("return", this.request.post('/order/sales/draft', payload, {
5126
5368
  osServer: true,
5127
5369
  customToast: function customToast() {}
5128
5370
  }));
5129
5371
  case 18:
5130
5372
  case "end":
5131
- return _context34.stop();
5373
+ return _context33.stop();
5132
5374
  }
5133
- }, _callee31, this);
5375
+ }, _callee30, this);
5134
5376
  }));
5135
- function saveTempOrderAsDraft(_x41) {
5377
+ function saveTempOrderAsDraft(_x36) {
5136
5378
  return _saveTempOrderAsDraft.apply(this, arguments);
5137
5379
  }
5138
5380
  return saveTempOrderAsDraft;
@@ -5146,18 +5388,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5146
5388
  }, {
5147
5389
  key: "submitTempOrder",
5148
5390
  value: (function () {
5149
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
5150
- return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5151
- while (1) switch (_context35.prev = _context35.next) {
5391
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
5392
+ return _regeneratorRuntime().wrap(function _callee31$(_context34) {
5393
+ while (1) switch (_context34.prev = _context34.next) {
5152
5394
  case 0:
5153
- return _context35.abrupt("return", this.runSubmitTempOrder(params));
5395
+ return _context34.abrupt("return", this.runSubmitTempOrder(params));
5154
5396
  case 1:
5155
5397
  case "end":
5156
- return _context35.stop();
5398
+ return _context34.stop();
5157
5399
  }
5158
- }, _callee32, this);
5400
+ }, _callee31, this);
5159
5401
  }));
5160
- function submitTempOrder(_x42) {
5402
+ function submitTempOrder(_x37) {
5161
5403
  return _submitTempOrder.apply(this, arguments);
5162
5404
  }
5163
5405
  return submitTempOrder;
@@ -5165,20 +5407,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5165
5407
  }, {
5166
5408
  key: "submitTempOrderAsync",
5167
5409
  value: function () {
5168
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
5169
- return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5170
- while (1) switch (_context36.prev = _context36.next) {
5410
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
5411
+ return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5412
+ while (1) switch (_context35.prev = _context35.next) {
5171
5413
  case 0:
5172
- return _context36.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
5414
+ return _context35.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
5173
5415
  syncMode: true
5174
5416
  })));
5175
5417
  case 1:
5176
5418
  case "end":
5177
- return _context36.stop();
5419
+ return _context35.stop();
5178
5420
  }
5179
- }, _callee33, this);
5421
+ }, _callee32, this);
5180
5422
  }));
5181
- function submitTempOrderAsync(_x43) {
5423
+ function submitTempOrderAsync(_x38) {
5182
5424
  return _submitTempOrderAsync.apply(this, arguments);
5183
5425
  }
5184
5426
  return submitTempOrderAsync;
@@ -5186,13 +5428,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5186
5428
  }, {
5187
5429
  key: "runSubmitTempOrder",
5188
5430
  value: function () {
5189
- var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5190
- var _params$cacheId3, _this$otherParams10, _ref73, _ref74, _submitSnapshot$busin, _this$otherParams11, _this$otherParams12, _submitSnapshot$type;
5431
+ var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
5432
+ var _params$cacheId3, _this$otherParams11, _ref75, _ref76, _submitSnapshot$busin, _this$otherParams12, _this$otherParams13, _submitSnapshot$type;
5191
5433
  var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
5192
- return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5193
- while (1) switch (_context37.prev = _context37.next) {
5434
+ return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5435
+ while (1) switch (_context36.prev = _context36.next) {
5194
5436
  case 0:
5195
5437
  tempOrder = this.ensureTempOrder();
5438
+ this.prepareVirtualSettlementTempOrder(tempOrder);
5196
5439
  shouldConfirmPendingVoucherPayments = (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== false;
5197
5440
  hasPaymentOverride = (params === null || params === void 0 ? void 0 : params.payments) !== undefined;
5198
5441
  preparedPaymentOverride = hasPaymentOverride ? this.prepareVoucherPaymentsForSubmit((params === null || params === void 0 ? void 0 : params.payments) || [], shouldConfirmPendingVoucherPayments) : undefined;
@@ -5210,26 +5453,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5210
5453
  }
5211
5454
  }
5212
5455
  this.persistTempOrder();
5213
- _context37.next = 8;
5456
+ _context36.next = 9;
5214
5457
  return this.recalculateSummary({
5215
5458
  createIfMissing: true
5216
5459
  });
5217
- case 8:
5218
- _context37.t1 = _context37.sent;
5219
- if (_context37.t1) {
5220
- _context37.next = 11;
5460
+ case 9:
5461
+ _context36.t1 = _context36.sent;
5462
+ if (_context36.t1) {
5463
+ _context36.next = 12;
5221
5464
  break;
5222
5465
  }
5223
- _context37.t1 = this.store.summary;
5224
- case 11:
5225
- _context37.t0 = _context37.t1;
5226
- if (_context37.t0) {
5227
- _context37.next = 14;
5466
+ _context36.t1 = this.store.summary;
5467
+ case 12:
5468
+ _context36.t0 = _context36.t1;
5469
+ if (_context36.t0) {
5470
+ _context36.next = 15;
5228
5471
  break;
5229
5472
  }
5230
- _context37.t0 = createEmptySummary();
5231
- case 14:
5232
- latestSummary = _context37.t0;
5473
+ _context36.t0 = createEmptySummary();
5474
+ case 15:
5475
+ latestSummary = _context36.t0;
5233
5476
  effectiveCacheId = (_params$cacheId3 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId3 !== void 0 ? _params$cacheId3 : this.cacheId;
5234
5477
  hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
5235
5478
  hasSmallTicketDataFlagOverride = (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined;
@@ -5248,8 +5491,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5248
5491
  payload = buildSubmitPayload({
5249
5492
  tempOrder: tempOrder,
5250
5493
  cacheId: effectiveCacheId,
5251
- platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform),
5252
- businessCode: (_ref73 = (_ref74 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref74 !== void 0 ? _ref74 : (_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) !== null && _ref73 !== void 0 ? _ref73 : (_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.business_code,
5494
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.platform),
5495
+ businessCode: (_ref75 = (_ref76 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref76 !== void 0 ? _ref76 : (_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.businessCode) !== null && _ref75 !== void 0 ? _ref75 : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.business_code,
5253
5496
  channel: params === null || params === void 0 ? void 0 : params.channel,
5254
5497
  type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
5255
5498
  summary: latestSummary,
@@ -5264,10 +5507,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5264
5507
  if (!payload.created_at) {
5265
5508
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
5266
5509
  }
5267
- _context37.next = 26;
5510
+ _context36.next = 27;
5268
5511
  return this.saveDraft();
5269
- case 26:
5270
- _context37.prev = 26;
5512
+ case 27:
5513
+ _context36.prev = 27;
5271
5514
  this.logInfo('submitTempOrder calling sales checkout', {
5272
5515
  orderId: payload.order_id,
5273
5516
  externalSaleNumber: payload.external_sale_number,
@@ -5277,44 +5520,44 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5277
5520
  smallTicketDataFlag: payload.small_ticket_data_flag,
5278
5521
  syncMode: payload.sync_mode
5279
5522
  });
5280
- _context37.next = 30;
5523
+ _context36.next = 31;
5281
5524
  return this.submitSalesOrder({
5282
5525
  query: payload
5283
5526
  });
5284
- case 30:
5285
- result = _context37.sent;
5286
- _context37.next = 43;
5527
+ case 31:
5528
+ result = _context36.sent;
5529
+ _context36.next = 44;
5287
5530
  break;
5288
- case 33:
5289
- _context37.prev = 33;
5290
- _context37.t2 = _context37["catch"](26);
5291
- backendErrorResponse = this.extractSubmitErrorResponse(_context37.t2);
5531
+ case 34:
5532
+ _context36.prev = 34;
5533
+ _context36.t2 = _context36["catch"](27);
5534
+ backendErrorResponse = this.extractSubmitErrorResponse(_context36.t2);
5292
5535
  if (!backendErrorResponse) {
5293
- _context37.next = 40;
5536
+ _context36.next = 41;
5294
5537
  break;
5295
5538
  }
5296
5539
  this.store.syncState = 'failed';
5297
5540
  this.logSubmitBackendRejected(backendErrorResponse, payload);
5298
- return _context37.abrupt("return", backendErrorResponse);
5299
- case 40:
5541
+ return _context36.abrupt("return", backendErrorResponse);
5542
+ case 41:
5300
5543
  this.store.syncState = 'failed';
5301
5544
  this.logError('submitTempOrder failed', {
5302
- error: _context37.t2 instanceof Error ? _context37.t2.message : String(_context37.t2),
5545
+ error: _context36.t2 instanceof Error ? _context36.t2.message : String(_context36.t2),
5303
5546
  orderId: payload.order_id,
5304
5547
  externalSaleNumber: payload.external_sale_number,
5305
5548
  paymentStatus: payload.payment_status,
5306
5549
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
5307
5550
  });
5308
- throw _context37.t2;
5309
- case 43:
5551
+ throw _context36.t2;
5552
+ case 44:
5310
5553
  if (!this.isSubmitResponseRejected(result)) {
5311
- _context37.next = 47;
5554
+ _context36.next = 48;
5312
5555
  break;
5313
5556
  }
5314
5557
  this.store.syncState = 'failed';
5315
5558
  this.logSubmitBackendRejected(result, payload);
5316
- return _context37.abrupt("return", result);
5317
- case 47:
5559
+ return _context36.abrupt("return", result);
5560
+ case 48:
5318
5561
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
5319
5562
  this.logInfo('runSubmitTempOrder: 提交成功', {
5320
5563
  submittedOrderId: submittedOrderId,
@@ -5324,31 +5567,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5324
5567
  })
5325
5568
  });
5326
5569
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
5327
- _context37.next = 56;
5570
+ _context36.next = 57;
5328
5571
  break;
5329
5572
  }
5330
5573
  tempOrder.order_id = submittedOrderId;
5331
5574
  resultRecord = result;
5332
- _context37.next = 54;
5575
+ _context36.next = 55;
5333
5576
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
5334
- case 54:
5335
- _context37.next = 57;
5577
+ case 55:
5578
+ _context36.next = 58;
5336
5579
  break;
5337
- case 56:
5580
+ case 57:
5338
5581
  if (this.isLocalPendingSubmitResult(result)) {
5339
5582
  this.store.syncState = 'local';
5340
5583
  } else {
5341
5584
  this.store.syncState = 'submitted';
5342
5585
  }
5343
- case 57:
5344
- return _context37.abrupt("return", result);
5345
5586
  case 58:
5587
+ return _context36.abrupt("return", result);
5588
+ case 59:
5346
5589
  case "end":
5347
- return _context37.stop();
5590
+ return _context36.stop();
5348
5591
  }
5349
- }, _callee34, this, [[26, 33]]);
5592
+ }, _callee33, this, [[27, 34]]);
5350
5593
  }));
5351
- function runSubmitTempOrder(_x44) {
5594
+ function runSubmitTempOrder(_x39) {
5352
5595
  return _runSubmitTempOrder.apply(this, arguments);
5353
5596
  }
5354
5597
  return runSubmitTempOrder;
@@ -5356,10 +5599,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5356
5599
  }, {
5357
5600
  key: "markLocalOrderSynced",
5358
5601
  value: function () {
5359
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(orderId, remoteOrder) {
5602
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(orderId, remoteOrder) {
5360
5603
  var tempOrder;
5361
- return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5362
- while (1) switch (_context38.prev = _context38.next) {
5604
+ return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5605
+ while (1) switch (_context37.prev = _context37.next) {
5363
5606
  case 0:
5364
5607
  tempOrder = this.ensureTempOrder();
5365
5608
  tempOrder.order_id = orderId;
@@ -5367,15 +5610,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5367
5610
  this.store.lastOrderInfo = remoteOrder;
5368
5611
  this.store.syncState = 'submitted';
5369
5612
  this.persistTempOrder();
5370
- _context38.next = 8;
5613
+ _context37.next = 8;
5371
5614
  return this.saveDraft();
5372
5615
  case 8:
5373
5616
  case "end":
5374
- return _context38.stop();
5617
+ return _context37.stop();
5375
5618
  }
5376
- }, _callee35, this);
5619
+ }, _callee34, this);
5377
5620
  }));
5378
- function markLocalOrderSynced(_x45, _x46) {
5621
+ function markLocalOrderSynced(_x40, _x41) {
5379
5622
  return _markLocalOrderSynced.apply(this, arguments);
5380
5623
  }
5381
5624
  return markLocalOrderSynced;
@@ -5418,10 +5661,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5418
5661
  value: function extractSubmitErrorResponse(error) {
5419
5662
  var _error$response,
5420
5663
  _error$response2,
5421
- _this30 = this;
5664
+ _this31 = this;
5422
5665
  var candidates = [error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data, error === null || error === void 0 ? void 0 : error.data, error === null || error === void 0 || (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.body, error === null || error === void 0 ? void 0 : error.body];
5423
5666
  return candidates.find(function (candidate) {
5424
- return _this30.isSubmitErrorResponse(candidate);
5667
+ return _this31.isSubmitErrorResponse(candidate);
5425
5668
  }) || null;
5426
5669
  }
5427
5670
  }, {
@@ -5448,33 +5691,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5448
5691
  }, {
5449
5692
  key: "syncPaymentsToOrder",
5450
5693
  value: function () {
5451
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5452
- var _this31 = this,
5694
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
5695
+ var _this32 = this,
5453
5696
  _params$confirmPendin;
5454
5697
  var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitParams, submitResult;
5455
- return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5456
- while (1) switch (_context39.prev = _context39.next) {
5698
+ return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5699
+ while (1) switch (_context38.prev = _context38.next) {
5457
5700
  case 0:
5458
5701
  tempOrder = this.ensureTempOrder();
5459
5702
  needsPaymentNumber = (params.payments || []).some(function (payment) {
5460
5703
  return String(payment.payment_number || '').trim() === '';
5461
5704
  });
5462
5705
  if (!needsPaymentNumber) {
5463
- _context39.next = 8;
5706
+ _context38.next = 8;
5464
5707
  break;
5465
5708
  }
5466
- _context39.next = 5;
5709
+ _context38.next = 5;
5467
5710
  return this.getPaymentNumberDevicePrefixAsync();
5468
5711
  case 5:
5469
- _context39.t0 = _context39.sent;
5470
- _context39.next = 9;
5712
+ _context38.t0 = _context38.sent;
5713
+ _context38.next = 9;
5471
5714
  break;
5472
5715
  case 8:
5473
- _context39.t0 = 'LOCAL';
5716
+ _context38.t0 = 'LOCAL';
5474
5717
  case 9:
5475
- devicePrefix = _context39.t0;
5718
+ devicePrefix = _context38.t0;
5476
5719
  mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
5477
- return _this31.normalizePaymentSource(payment, {
5720
+ return _this32.normalizePaymentSource(payment, {
5478
5721
  defaultPaid: false,
5479
5722
  devicePrefix: devicePrefix
5480
5723
  });
@@ -5487,20 +5730,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5487
5730
  tempOrder.payments = effectivePayments;
5488
5731
  tempOrder.payment_status = paymentStatus;
5489
5732
  this.persistTempOrder();
5490
- _context39.next = 21;
5733
+ _context38.next = 21;
5491
5734
  return this.saveDraft();
5492
5735
  case 21:
5493
5736
  if (params.submitWhenPaid) {
5494
- _context39.next = 23;
5737
+ _context38.next = 23;
5495
5738
  break;
5496
5739
  }
5497
- return _context39.abrupt("return", completion);
5740
+ return _context38.abrupt("return", completion);
5498
5741
  case 23:
5499
5742
  if (!(this.store.syncState === 'submitting')) {
5500
- _context39.next = 25;
5743
+ _context38.next = 25;
5501
5744
  break;
5502
5745
  }
5503
- return _context39.abrupt("return", completion);
5746
+ return _context38.abrupt("return", completion);
5504
5747
  case 25:
5505
5748
  this.store.syncState = 'submitting';
5506
5749
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
@@ -5519,32 +5762,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5519
5762
  }
5520
5763
  };
5521
5764
  if (!(params.checkoutSyncTaskEnabled === false)) {
5522
- _context39.next = 34;
5765
+ _context38.next = 34;
5523
5766
  break;
5524
5767
  }
5525
- _context39.next = 31;
5768
+ _context38.next = 31;
5526
5769
  return this.submitTempOrderAsync(submitParams);
5527
5770
  case 31:
5528
- _context39.t1 = _context39.sent;
5529
- _context39.next = 37;
5771
+ _context38.t1 = _context38.sent;
5772
+ _context38.next = 37;
5530
5773
  break;
5531
5774
  case 34:
5532
- _context39.next = 36;
5775
+ _context38.next = 36;
5533
5776
  return this.submitTempOrder(submitParams);
5534
5777
  case 36:
5535
- _context39.t1 = _context39.sent;
5778
+ _context38.t1 = _context38.sent;
5536
5779
  case 37:
5537
- submitResult = _context39.t1;
5538
- return _context39.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5780
+ submitResult = _context38.t1;
5781
+ return _context38.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5539
5782
  submitResult: submitResult
5540
5783
  }));
5541
5784
  case 39:
5542
5785
  case "end":
5543
- return _context39.stop();
5786
+ return _context38.stop();
5544
5787
  }
5545
- }, _callee36, this);
5788
+ }, _callee35, this);
5546
5789
  }));
5547
- function syncPaymentsToOrder(_x47) {
5790
+ function syncPaymentsToOrder(_x42) {
5548
5791
  return _syncPaymentsToOrder.apply(this, arguments);
5549
5792
  }
5550
5793
  return syncPaymentsToOrder;
@@ -5552,7 +5795,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5552
5795
  }, {
5553
5796
  key: "createOrder",
5554
5797
  value: function createOrder(params) {
5555
- var _this32 = this;
5798
+ var _this33 = this;
5556
5799
  var order = _objectSpread({
5557
5800
  type: (params === null || params === void 0 ? void 0 : params.type) || 'appointment_booking',
5558
5801
  // 要从外面拿,virtual
@@ -5584,7 +5827,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5584
5827
 
5585
5828
  // 为预约补齐 holder 信息
5586
5829
  if (params !== null && params !== void 0 && (_params$extraData = params.extraData) !== null && _params$extraData !== void 0 && _params$extraData.is_add_holder_info) {
5587
- ensureCartItemOriginHolder(item, _this32.window);
5830
+ ensureCartItemOriginHolder(item, _this33.window);
5588
5831
  }
5589
5832
 
5590
5833
  // 购物车是否为普通商品
@@ -5641,11 +5884,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5641
5884
  }, {
5642
5885
  key: "submitOrder",
5643
5886
  value: function () {
5644
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(order) {
5887
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(order) {
5645
5888
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
5646
5889
  var url, query, fetchUrl, params;
5647
- return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5648
- while (1) switch (_context40.prev = _context40.next) {
5890
+ return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5891
+ while (1) switch (_context39.prev = _context39.next) {
5649
5892
  case 0:
5650
5893
  this.logInfo('submitOrder called', {
5651
5894
  url: order.url,
@@ -5665,14 +5908,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5665
5908
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
5666
5909
  scheduleDate: params.schedule_date
5667
5910
  });
5668
- return _context40.abrupt("return", this.request.post(fetchUrl, params));
5911
+ return _context39.abrupt("return", this.request.post(fetchUrl, params));
5669
5912
  case 6:
5670
5913
  case "end":
5671
- return _context40.stop();
5914
+ return _context39.stop();
5672
5915
  }
5673
- }, _callee37, this);
5916
+ }, _callee36, this);
5674
5917
  }));
5675
- function submitOrder(_x48) {
5918
+ function submitOrder(_x43) {
5676
5919
  return _submitOrder.apply(this, arguments);
5677
5920
  }
5678
5921
  return submitOrder;
@@ -5680,13 +5923,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5680
5923
  }, {
5681
5924
  key: "cancelOrder",
5682
5925
  value: function () {
5683
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5926
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
5684
5927
  var payload;
5685
- return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5686
- while (1) switch (_context41.prev = _context41.next) {
5928
+ return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5929
+ while (1) switch (_context40.prev = _context40.next) {
5687
5930
  case 0:
5688
5931
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
5689
- _context41.next = 2;
5932
+ _context40.next = 2;
5690
5933
  break;
5691
5934
  }
5692
5935
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -5702,16 +5945,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5702
5945
  method: 'PUT',
5703
5946
  orderIdsCount: params.order_ids.length
5704
5947
  });
5705
- return _context41.abrupt("return", this.request.put('/order/update-status', payload, {
5948
+ return _context40.abrupt("return", this.request.put('/order/update-status', payload, {
5706
5949
  isShopApi: true
5707
5950
  }));
5708
5951
  case 5:
5709
5952
  case "end":
5710
- return _context41.stop();
5953
+ return _context40.stop();
5711
5954
  }
5712
- }, _callee38, this);
5955
+ }, _callee37, this);
5713
5956
  }));
5714
- function cancelOrder(_x49) {
5957
+ function cancelOrder(_x44) {
5715
5958
  return _cancelOrder.apply(this, arguments);
5716
5959
  }
5717
5960
  return cancelOrder;
@@ -5719,19 +5962,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5719
5962
  }, {
5720
5963
  key: "changeBookingStatus",
5721
5964
  value: function () {
5722
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5965
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5723
5966
  var url, payload;
5724
- return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5725
- while (1) switch (_context42.prev = _context42.next) {
5967
+ return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5968
+ while (1) switch (_context41.prev = _context41.next) {
5726
5969
  case 0:
5727
5970
  if (params.booking_id) {
5728
- _context42.next = 2;
5971
+ _context41.next = 2;
5729
5972
  break;
5730
5973
  }
5731
5974
  throw new Error('变更预约状态失败:booking_id 不能为空');
5732
5975
  case 2:
5733
5976
  if (params.appointment_status) {
5734
- _context42.next = 4;
5977
+ _context41.next = 4;
5735
5978
  break;
5736
5979
  }
5737
5980
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -5746,16 +5989,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5746
5989
  bookingId: params.booking_id,
5747
5990
  appointmentStatus: params.appointment_status
5748
5991
  });
5749
- return _context42.abrupt("return", this.request.put(url, payload, {
5992
+ return _context41.abrupt("return", this.request.put(url, payload, {
5750
5993
  isShopApi: true
5751
5994
  }));
5752
5995
  case 8:
5753
5996
  case "end":
5754
- return _context42.stop();
5997
+ return _context41.stop();
5755
5998
  }
5756
- }, _callee39, this);
5999
+ }, _callee38, this);
5757
6000
  }));
5758
- function changeBookingStatus(_x50) {
6001
+ function changeBookingStatus(_x45) {
5759
6002
  return _changeBookingStatus.apply(this, arguments);
5760
6003
  }
5761
6004
  return changeBookingStatus;
@@ -5773,11 +6016,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5773
6016
  }, {
5774
6017
  key: "createOrderByCheckout",
5775
6018
  value: (function () {
5776
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
6019
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5777
6020
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
5778
6021
  var onlineStorePaymentCodeList, _orderData$payments, _orderData$bookings, _orderData$relation_p, _orderData$payments2, _orderData$payments3, _orderData$bookings2, _orderData$relation_p2, _orderData$payments4, _orderData$payments5, _response$data, orderData, response;
5779
- return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5780
- while (1) switch (_context43.prev = _context43.next) {
6022
+ return _regeneratorRuntime().wrap(function _callee39$(_context42) {
6023
+ while (1) switch (_context42.prev = _context42.next) {
5781
6024
  case 0:
5782
6025
  // 过滤掉由在线店铺下单的 payment 支付数据
5783
6026
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -5811,7 +6054,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5811
6054
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
5812
6055
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
5813
6056
  });
5814
- _context43.prev = 4;
6057
+ _context42.prev = 4;
5815
6058
  // 构建订单数据,设置默认值并允许 params 覆盖
5816
6059
  orderData = _objectSpread({
5817
6060
  sales_channel: 'my_pisel',
@@ -5873,13 +6116,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5873
6116
  hasOrderId: !!orderData.order_id,
5874
6117
  smallTicketDataFlag: orderData.small_ticket_data_flag
5875
6118
  });
5876
- _context43.next = 12;
6119
+ _context42.next = 12;
5877
6120
  return this.request.post('/order/checkout', orderData, {
5878
6121
  osServer: true,
5879
6122
  customToast: function customToast() {}
5880
6123
  });
5881
6124
  case 12:
5882
- response = _context43.sent;
6125
+ response = _context42.sent;
5883
6126
  this.logInfo('Order API called successfully', {
5884
6127
  response: response
5885
6128
  });
@@ -5887,22 +6130,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5887
6130
  success: !!response,
5888
6131
  hasOrderId: !!(response !== null && response !== void 0 && (_response$data = response.data) !== null && _response$data !== void 0 && _response$data.order_id || response !== null && response !== void 0 && response.order_id)
5889
6132
  });
5890
- return _context43.abrupt("return", response);
6133
+ return _context42.abrupt("return", response);
5891
6134
  case 18:
5892
- _context43.prev = 18;
5893
- _context43.t0 = _context43["catch"](4);
5894
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context43.t0);
6135
+ _context42.prev = 18;
6136
+ _context42.t0 = _context42["catch"](4);
6137
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context42.t0);
5895
6138
  this.logInfo('Order API called failed', {
5896
- error: _context43.t0 instanceof Error ? _context43.t0.message : String(_context43.t0)
6139
+ error: _context42.t0 instanceof Error ? _context42.t0.message : String(_context42.t0)
5897
6140
  });
5898
- throw _context43.t0;
6141
+ throw _context42.t0;
5899
6142
  case 23:
5900
6143
  case "end":
5901
- return _context43.stop();
6144
+ return _context42.stop();
5902
6145
  }
5903
- }, _callee40, this, [[4, 18]]);
6146
+ }, _callee39, this, [[4, 18]]);
5904
6147
  }));
5905
- function createOrderByCheckout(_x51) {
6148
+ function createOrderByCheckout(_x46) {
5906
6149
  return _createOrderByCheckout.apply(this, arguments);
5907
6150
  }
5908
6151
  return createOrderByCheckout;
@@ -5910,24 +6153,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5910
6153
  }, {
5911
6154
  key: "submitSalesOrder",
5912
6155
  value: function () {
5913
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
6156
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
5914
6157
  var url, query, fetchUrl;
5915
- return _regeneratorRuntime().wrap(function _callee41$(_context44) {
5916
- while (1) switch (_context44.prev = _context44.next) {
6158
+ return _regeneratorRuntime().wrap(function _callee40$(_context43) {
6159
+ while (1) switch (_context43.prev = _context43.next) {
5917
6160
  case 0:
5918
6161
  url = params.url, query = params.query;
5919
6162
  fetchUrl = url || '/order/sales/checkout';
5920
- return _context44.abrupt("return", this.request.post(fetchUrl, query, {
6163
+ return _context43.abrupt("return", this.request.post(fetchUrl, query, {
5921
6164
  osServer: true,
5922
6165
  customToast: function customToast() {}
5923
6166
  }));
5924
6167
  case 3:
5925
6168
  case "end":
5926
- return _context44.stop();
6169
+ return _context43.stop();
5927
6170
  }
5928
- }, _callee41, this);
6171
+ }, _callee40, this);
5929
6172
  }));
5930
- function submitSalesOrder(_x52) {
6173
+ function submitSalesOrder(_x47) {
5931
6174
  return _submitSalesOrder.apply(this, arguments);
5932
6175
  }
5933
6176
  return submitSalesOrder;
@@ -5941,37 +6184,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5941
6184
  }, {
5942
6185
  key: "sendCustomerPayLink",
5943
6186
  value: (function () {
5944
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
6187
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
5945
6188
  var _params$emails;
5946
6189
  var orderIds;
5947
- return _regeneratorRuntime().wrap(function _callee42$(_context45) {
5948
- while (1) switch (_context45.prev = _context45.next) {
6190
+ return _regeneratorRuntime().wrap(function _callee41$(_context44) {
6191
+ while (1) switch (_context44.prev = _context44.next) {
5949
6192
  case 0:
5950
6193
  orderIds = params.order_ids || params.orderIds || [];
5951
6194
  if (orderIds.length) {
5952
- _context45.next = 3;
6195
+ _context44.next = 3;
5953
6196
  break;
5954
6197
  }
5955
6198
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
5956
6199
  case 3:
5957
6200
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
5958
- _context45.next = 5;
6201
+ _context44.next = 5;
5959
6202
  break;
5960
6203
  }
5961
6204
  throw new Error('发送支付链接需要至少一个邮箱');
5962
6205
  case 5:
5963
- return _context45.abrupt("return", this.request.post('/order/batch-email', {
6206
+ return _context44.abrupt("return", this.request.post('/order/batch-email', {
5964
6207
  order_ids: orderIds,
5965
6208
  notify_action: params.notify_action || 'order_payment_reminder',
5966
6209
  emails: params.emails
5967
6210
  }));
5968
6211
  case 6:
5969
6212
  case "end":
5970
- return _context45.stop();
6213
+ return _context44.stop();
5971
6214
  }
5972
- }, _callee42, this);
6215
+ }, _callee41, this);
5973
6216
  }));
5974
- function sendCustomerPayLink(_x53) {
6217
+ function sendCustomerPayLink(_x48) {
5975
6218
  return _sendCustomerPayLink.apply(this, arguments);
5976
6219
  }
5977
6220
  return sendCustomerPayLink;
@@ -5979,14 +6222,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5979
6222
  }, {
5980
6223
  key: "getSalesOrderByLookup",
5981
6224
  value: function () {
5982
- var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
6225
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
5983
6226
  var lookup, res;
5984
- return _regeneratorRuntime().wrap(function _callee43$(_context46) {
5985
- while (1) switch (_context46.prev = _context46.next) {
6227
+ return _regeneratorRuntime().wrap(function _callee42$(_context45) {
6228
+ while (1) switch (_context45.prev = _context45.next) {
5986
6229
  case 0:
5987
6230
  lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
5988
6231
  if (lookup) {
5989
- _context46.next = 3;
6232
+ _context45.next = 3;
5990
6233
  break;
5991
6234
  }
5992
6235
  throw new Error('加载销售详情需要 lookup');
@@ -5995,7 +6238,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5995
6238
  if (lookup.startsWith('LOCAL_')) {
5996
6239
  params.forceRemote = false;
5997
6240
  }
5998
- _context46.next = 6;
6241
+ _context45.next = 6;
5999
6242
  return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
6000
6243
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info', 'refunds']
6001
6244
  }, params.forceRemote ? {
@@ -6004,18 +6247,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6004
6247
  osServer: true
6005
6248
  });
6006
6249
  case 6:
6007
- res = _context46.sent;
6250
+ res = _context45.sent;
6008
6251
  if (res.code === 200) {
6009
6252
  this.store.lastOrderInfo = res.data;
6010
6253
  }
6011
- return _context46.abrupt("return", res);
6254
+ return _context45.abrupt("return", res);
6012
6255
  case 9:
6013
6256
  case "end":
6014
- return _context46.stop();
6257
+ return _context45.stop();
6015
6258
  }
6016
- }, _callee43, this);
6259
+ }, _callee42, this);
6017
6260
  }));
6018
- function getSalesOrderByLookup(_x54) {
6261
+ function getSalesOrderByLookup(_x49) {
6019
6262
  return _getSalesOrderByLookup.apply(this, arguments);
6020
6263
  }
6021
6264
  return getSalesOrderByLookup;
@@ -6029,11 +6272,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6029
6272
  }, {
6030
6273
  key: "hydrateTempOrderFromRecord",
6031
6274
  value: (function () {
6032
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(record, options) {
6033
- var _sourceRaw$_extend, _this$store$discount22;
6034
- var sourceRaw, duplicateProductIdentityRepair, duplicateIdentityReadySource, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, isSessionStorageHydrate, nextTempOrder, _this$store$discount20, _this$store$discount21, restoredSessionDiscounts, nextExtend, sourceLastOrderInfo, isDraftOrder, syntheticIdentityOptions, rawSummary, summarySurcharges, hadSyntheticDraftOrderId, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount23, _this$store$discount24;
6035
- return _regeneratorRuntime().wrap(function _callee44$(_context47) {
6036
- while (1) switch (_context47.prev = _context47.next) {
6275
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(record, options) {
6276
+ var _sourceRaw$_extend, _this$store$discount26;
6277
+ var sourceRaw, duplicateProductIdentityRepair, duplicateIdentityReadySource, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, isSessionStorageHydrate, nextTempOrder, _this$store$discount24, _this$store$discount25, restoredSessionDiscounts, nextExtend, sourceLastOrderInfo, isDraftOrder, syntheticIdentityOptions, rawSummary, summarySurcharges, hadSyntheticDraftOrderId, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount27, _this$store$discount28;
6278
+ return _regeneratorRuntime().wrap(function _callee43$(_context46) {
6279
+ while (1) switch (_context46.prev = _context46.next) {
6037
6280
  case 0:
6038
6281
  sourceRaw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
6039
6282
  duplicateProductIdentityRepair = repairDuplicateOrderProductLineIdentities(Array.isArray(sourceRaw.products) ? sourceRaw.products : [], (_sourceRaw$_extend = sourceRaw._extend) === null || _sourceRaw$_extend === void 0 ? void 0 : _sourceRaw$_extend.productsByUid);
@@ -6071,7 +6314,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6071
6314
  });
6072
6315
  this.store.tempOrder = nextTempOrder;
6073
6316
  if (!isSessionStorageHydrate) {
6074
- _context47.next = 29;
6317
+ _context46.next = 29;
6075
6318
  break;
6076
6319
  }
6077
6320
  // 会话快照是未提交购物车,不应获得编辑订单的 saved/edit 标记与服务端基线。
@@ -6087,23 +6330,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6087
6330
  nextTempOrder.discount_list = restoredSessionDiscounts;
6088
6331
  this.store.summary = createEmptySummary();
6089
6332
  this.store.lastOrderInfo = undefined;
6090
- _context47.next = 22;
6091
- return (_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 ? void 0 : _this$store$discount20.setOriginalDiscountList(cloneDeep(restoredSessionDiscounts));
6333
+ _context46.next = 22;
6334
+ return (_this$store$discount24 = this.store.discount) === null || _this$store$discount24 === void 0 ? void 0 : _this$store$discount24.setOriginalDiscountList(cloneDeep(restoredSessionDiscounts));
6092
6335
  case 22:
6093
- _context47.next = 24;
6094
- return (_this$store$discount21 = this.store.discount) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.setDiscountList(cloneDeep(restoredSessionDiscounts));
6336
+ _context46.next = 24;
6337
+ return (_this$store$discount25 = this.store.discount) === null || _this$store$discount25 === void 0 ? void 0 : _this$store$discount25.setDiscountList(cloneDeep(restoredSessionDiscounts));
6095
6338
  case 24:
6096
6339
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
6097
- _context47.next = 27;
6340
+ _context46.next = 27;
6098
6341
  break;
6099
6342
  }
6100
- _context47.next = 27;
6343
+ _context46.next = 27;
6101
6344
  return this.recalculateSummary({
6102
6345
  createIfMissing: false
6103
6346
  });
6104
6347
  case 27:
6105
6348
  this.persistTempOrder();
6106
- return _context47.abrupt("return", nextTempOrder);
6349
+ return _context46.abrupt("return", nextTempOrder);
6107
6350
  case 29:
6108
6351
  // Server list compatibility may synthesize order_id from external_sale_number; tempOrder must not.
6109
6352
  sourceLastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
@@ -6136,7 +6379,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6136
6379
  this.store.syncState = 'local';
6137
6380
  }
6138
6381
  hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
6139
- currentDiscounts = typeof ((_this$store$discount22 = this.store.discount) === null || _this$store$discount22 === void 0 ? void 0 : _this$store$discount22.getDiscountList) === 'function' ? this.store.discount.getDiscountList() || [] : [];
6382
+ currentDiscounts = typeof ((_this$store$discount26 = this.store.discount) === null || _this$store$discount26 === void 0 ? void 0 : _this$store$discount26.getDiscountList) === 'function' ? this.store.discount.getDiscountList() || [] : [];
6140
6383
  currentScanDiscounts = currentDiscounts.filter(function (discount) {
6141
6384
  return discount === null || discount === void 0 ? void 0 : discount.isScan;
6142
6385
  });
@@ -6149,34 +6392,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6149
6392
  nextDiscounts = [].concat(_toConsumableArray(hydratedEditDiscounts), _toConsumableArray(retainedScanDiscounts));
6150
6393
  shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
6151
6394
  if (shouldSkipEmptyDiscountSync) {
6152
- _context47.next = 52;
6395
+ _context46.next = 52;
6153
6396
  break;
6154
6397
  }
6155
6398
  OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
6156
- _context47.next = 50;
6157
- return (_this$store$discount23 = this.store.discount) === null || _this$store$discount23 === void 0 ? void 0 : _this$store$discount23.setOriginalDiscountList(nextDiscounts);
6399
+ _context46.next = 50;
6400
+ return (_this$store$discount27 = this.store.discount) === null || _this$store$discount27 === void 0 ? void 0 : _this$store$discount27.setOriginalDiscountList(nextDiscounts);
6158
6401
  case 50:
6159
- _context47.next = 52;
6160
- return (_this$store$discount24 = this.store.discount) === null || _this$store$discount24 === void 0 ? void 0 : _this$store$discount24.setDiscountList(nextDiscounts);
6402
+ _context46.next = 52;
6403
+ return (_this$store$discount28 = this.store.discount) === null || _this$store$discount28 === void 0 ? void 0 : _this$store$discount28.setDiscountList(nextDiscounts);
6161
6404
  case 52:
6162
6405
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
6163
- _context47.next = 55;
6406
+ _context46.next = 55;
6164
6407
  break;
6165
6408
  }
6166
- _context47.next = 55;
6409
+ _context46.next = 55;
6167
6410
  return this.recalculateSummary({
6168
6411
  createIfMissing: false
6169
6412
  });
6170
6413
  case 55:
6171
6414
  this.persistTempOrder();
6172
- return _context47.abrupt("return", nextTempOrder);
6415
+ return _context46.abrupt("return", nextTempOrder);
6173
6416
  case 57:
6174
6417
  case "end":
6175
- return _context47.stop();
6418
+ return _context46.stop();
6176
6419
  }
6177
- }, _callee44, this);
6420
+ }, _callee43, this);
6178
6421
  }));
6179
- function hydrateTempOrderFromRecord(_x55, _x56) {
6422
+ function hydrateTempOrderFromRecord(_x50, _x51) {
6180
6423
  return _hydrateTempOrderFromRecord.apply(this, arguments);
6181
6424
  }
6182
6425
  return hydrateTempOrderFromRecord;
@@ -6290,7 +6533,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6290
6533
  }, {
6291
6534
  key: "normalizeTempOrderForRuntime",
6292
6535
  value: function normalizeTempOrderForRuntime(raw, options) {
6293
- var _this33 = this;
6536
+ var _this34 = this;
6294
6537
  var runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
6295
6538
  var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), runtimeRaw || {});
6296
6539
  // ES 列表详情使用 id 表示订单主键;OS 详情态统一依赖 order_id 驱动操作按钮。
@@ -6314,12 +6557,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6314
6557
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
6315
6558
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
6316
6559
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
6317
- return _this33.normalizeHydratedOrderProduct(p, {
6560
+ return _this34.normalizeHydratedOrderProduct(p, {
6318
6561
  makeEditMark: options === null || options === void 0 ? void 0 : options.makeEditMark
6319
6562
  });
6320
6563
  }) : [];
6321
6564
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
6322
- var booking = _this33.normalizeHydratedBookingHolder(b || {});
6565
+ var booking = _this34.normalizeHydratedBookingHolder(b || {});
6323
6566
  return _objectSpread(_objectSpread({}, booking), {}, {
6324
6567
  is_all: normalizeBookingIsAll(booking),
6325
6568
  sub_type: normalizeBookingSubType(booking)
@@ -6349,7 +6592,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6349
6592
  _step24;
6350
6593
  try {
6351
6594
  for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
6352
- var _product$metadata9, _ref75, _ref76, _existed$origin, _rawProduct$metadata;
6595
+ var _product$metadata9, _ref77, _ref78, _existed$origin, _rawProduct$metadata;
6353
6596
  var _step24$value = _slicedToArray(_step24.value, 2),
6354
6597
  index = _step24$value[0],
6355
6598
  product = _step24$value[1];
@@ -6357,7 +6600,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6357
6600
  if (!uid) continue;
6358
6601
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
6359
6602
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
6360
- var origin = (_ref75 = (_ref76 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref76 !== void 0 ? _ref76 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref75 !== void 0 ? _ref75 : rawProduct;
6603
+ var origin = (_ref77 = (_ref78 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref78 !== void 0 ? _ref78 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref77 !== void 0 ? _ref77 : rawProduct;
6361
6604
  var originSnapshot = cloneDeep(origin);
6362
6605
  var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
6363
6606
  if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
@@ -6486,10 +6729,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6486
6729
  }, {
6487
6730
  key: "normalizeHydratedProductOptionItem",
6488
6731
  value: function normalizeHydratedProductOptionItem(optionItem) {
6489
- var _ref77, _optionItem$num, _ref78, _optionItem$add_price;
6490
- var rawNum = (_ref77 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref77 !== void 0 ? _ref77 : 1;
6732
+ var _ref79, _optionItem$num, _ref80, _optionItem$add_price;
6733
+ var rawNum = (_ref79 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref79 !== void 0 ? _ref79 : 1;
6491
6734
  var parsedNum = Number(rawNum);
6492
- var rawPrice = (_ref78 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref78 !== void 0 ? _ref78 : 0;
6735
+ var rawPrice = (_ref80 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref80 !== void 0 ? _ref80 : 0;
6493
6736
  var parsedPrice = Number(rawPrice);
6494
6737
  var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
6495
6738
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -6506,7 +6749,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6506
6749
  }, {
6507
6750
  key: "normalizeHydratedOrderProduct",
6508
6751
  value: function normalizeHydratedOrderProduct(product, options) {
6509
- var _this34 = this;
6752
+ var _this35 = this;
6510
6753
  var row = _objectSpread({}, product || {});
6511
6754
  if (row.num === undefined && row.product_quantity !== undefined) {
6512
6755
  row.num = row.product_quantity;
@@ -6514,12 +6757,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6514
6757
  var productSku = ensureProductSku(row);
6515
6758
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
6516
6759
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
6517
- return _this34.normalizeHydratedProductOptionItem(optionItem || {});
6760
+ return _this35.normalizeHydratedProductOptionItem(optionItem || {});
6518
6761
  }))
6519
6762
  });
6520
6763
  delete row["product_".concat('option', "_item")];
6521
6764
  if (!Array.isArray(row.product_bundle)) row.product_bundle = [];
6522
- if (!row.metadata || _typeof(row.metadata) !== 'object') row.metadata = {};
6765
+ row.metadata = row.metadata && _typeof(row.metadata) === 'object' ? _objectSpread({}, row.metadata) : {};
6766
+ // bundle_edit 只描述当前编辑会话中的套餐修改状态,不能从本地缓存或详情响应带入新会话。
6767
+ delete row.bundle_edit;
6768
+ delete row.metadata.bundle_edit;
6523
6769
  if (row.booking_uid && !row.metadata.booking_uid) {
6524
6770
  row.metadata.booking_uid = row.booking_uid;
6525
6771
  }
@@ -6540,7 +6786,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6540
6786
  });
6541
6787
  if (result.metadata) delete result.metadata.price_schema_version;
6542
6788
  var restored = restoreHydratedBundleDiscounts(result, normalizeOrderProductDiscountList);
6543
- return this.sanitizeOrderProductForTempOrder(restored);
6789
+ return this.sanitizeOrderProductForTempOrder(this.normalizeVirtualSettlementProductIfEnabled(restored));
6544
6790
  }
6545
6791
  }, {
6546
6792
  key: "getLastOrderInfo",
@@ -6551,27 +6797,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6551
6797
  }, {
6552
6798
  key: "getOrderInfo",
6553
6799
  value: function () {
6554
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(order_id) {
6800
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(order_id) {
6555
6801
  var res;
6556
- return _regeneratorRuntime().wrap(function _callee45$(_context48) {
6557
- while (1) switch (_context48.prev = _context48.next) {
6802
+ return _regeneratorRuntime().wrap(function _callee44$(_context47) {
6803
+ while (1) switch (_context47.prev = _context47.next) {
6558
6804
  case 0:
6559
- _context48.next = 2;
6805
+ _context47.next = 2;
6560
6806
  return this.request.get("/order/sales/".concat(order_id), {
6561
6807
  with: ['products', 'bookings']
6562
6808
  }, {
6563
6809
  osServer: true
6564
6810
  });
6565
6811
  case 2:
6566
- res = _context48.sent;
6567
- return _context48.abrupt("return", res);
6812
+ res = _context47.sent;
6813
+ return _context47.abrupt("return", res);
6568
6814
  case 4:
6569
6815
  case "end":
6570
- return _context48.stop();
6816
+ return _context47.stop();
6571
6817
  }
6572
- }, _callee45, this);
6818
+ }, _callee44, this);
6573
6819
  }));
6574
- function getOrderInfo(_x57) {
6820
+ function getOrderInfo(_x52) {
6575
6821
  return _getOrderInfo.apply(this, arguments);
6576
6822
  }
6577
6823
  return getOrderInfo;