@pisell/pisellos 0.10.7 → 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 (124) 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/walletPass/evaluator.js +0 -2
  6. package/dist/model/strategy/adapter/walletPass/type.d.ts +5 -0
  7. package/dist/model/strategy/adapter/walletPass/utils.js +57 -26
  8. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +18 -12
  9. package/dist/modules/BookingContext/utils/productExtend.js +5 -9
  10. package/dist/modules/BookingContext/utils/timeSlices.js +24 -3
  11. package/dist/modules/Customer/index.d.ts +4 -0
  12. package/dist/modules/Customer/index.js +91 -59
  13. package/dist/modules/Customer/types.d.ts +2 -0
  14. package/dist/modules/Discount/index.d.ts +2 -0
  15. package/dist/modules/Discount/index.js +38 -5
  16. package/dist/modules/Discount/types.d.ts +11 -0
  17. package/dist/modules/Order/index.d.ts +32 -6
  18. package/dist/modules/Order/index.js +1165 -819
  19. package/dist/modules/Order/types.d.ts +32 -4
  20. package/dist/modules/Order/types.js +11 -0
  21. package/dist/modules/Order/utils/discountProductLineIdentity.d.ts +45 -0
  22. package/dist/modules/Order/utils/discountProductLineIdentity.js +227 -0
  23. package/dist/modules/Order/utils/virtualSettlement.d.ts +56 -0
  24. package/dist/modules/Order/utils/virtualSettlement.js +271 -0
  25. package/dist/modules/Order/utils.js +89 -48
  26. package/dist/modules/Payment/types.d.ts +2 -0
  27. package/dist/modules/Payment/utils.js +4 -1
  28. package/dist/modules/Payment/walletpass.d.ts +11 -0
  29. package/dist/modules/Payment/walletpass.js +235 -60
  30. package/dist/modules/Product/types.d.ts +23 -0
  31. package/dist/modules/ProductList/index.d.ts +15 -2
  32. package/dist/modules/ProductList/index.js +92 -13
  33. package/dist/modules/Rules/index.js +125 -52
  34. package/dist/modules/SalesSummary/index.d.ts +1 -0
  35. package/dist/modules/SalesSummary/index.js +4 -3
  36. package/dist/modules/SalesSummary/types.d.ts +1 -0
  37. package/dist/modules/SalesSummary/utils.d.ts +1 -0
  38. package/dist/modules/SalesSummary/utils.js +28 -2
  39. package/dist/server/index.d.ts +15 -0
  40. package/dist/server/index.js +894 -781
  41. package/dist/server/modules/order/index.d.ts +2 -0
  42. package/dist/server/modules/order/index.js +261 -96
  43. package/dist/server/modules/order/types.d.ts +1 -1
  44. package/dist/server/utils/small-ticket.js +2 -1
  45. package/dist/solution/BaseSales/index.d.ts +41 -7
  46. package/dist/solution/BaseSales/index.js +1405 -974
  47. package/dist/solution/BaseSales/utils/cartPromotion.js +26 -3
  48. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  49. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +79 -13
  50. package/dist/solution/BaseSales/utils.js +31 -20
  51. package/dist/solution/BookingByStep/index.d.ts +3 -3
  52. package/dist/solution/BookingTicket/index.d.ts +5 -1
  53. package/dist/solution/BookingTicket/index.js +221 -162
  54. package/dist/solution/BookingTicket/types.d.ts +3 -0
  55. package/dist/solution/BookingTicket/utils/addProductDecision.js +2 -1
  56. package/dist/solution/BookingTicket/utils/cartView.js +44 -32
  57. package/dist/solution/Sales/index.d.ts +1 -0
  58. package/dist/solution/Sales/index.js +16 -2
  59. package/dist/solution/ScanOrder/index.js +25 -64
  60. package/dist/solution/ScanOrder/utils.js +31 -20
  61. package/dist/solution/UnifiedBookingSales/index.d.ts +5 -4
  62. package/dist/solution/UnifiedBookingSales/index.js +51 -39
  63. package/lib/core/index.js +0 -1
  64. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
  65. package/lib/model/strategy/adapter/dataVariant/evaluator.js +170 -7
  66. package/lib/model/strategy/adapter/dataVariant/type.d.ts +25 -0
  67. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
  68. package/lib/model/strategy/adapter/walletPass/type.d.ts +5 -0
  69. package/lib/model/strategy/adapter/walletPass/utils.js +62 -11
  70. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +6 -1
  71. package/lib/modules/BookingContext/utils/productExtend.js +4 -3
  72. package/lib/modules/BookingContext/utils/timeSlices.js +18 -3
  73. package/lib/modules/Customer/index.d.ts +4 -0
  74. package/lib/modules/Customer/index.js +11 -0
  75. package/lib/modules/Customer/types.d.ts +2 -0
  76. package/lib/modules/Discount/index.d.ts +2 -0
  77. package/lib/modules/Discount/index.js +37 -3
  78. package/lib/modules/Discount/types.d.ts +11 -0
  79. package/lib/modules/Order/index.d.ts +32 -6
  80. package/lib/modules/Order/index.js +518 -148
  81. package/lib/modules/Order/types.d.ts +32 -4
  82. package/lib/modules/Order/utils/discountProductLineIdentity.d.ts +45 -0
  83. package/lib/modules/Order/utils/discountProductLineIdentity.js +170 -0
  84. package/lib/modules/Order/utils/virtualSettlement.d.ts +56 -0
  85. package/lib/modules/Order/utils/virtualSettlement.js +300 -0
  86. package/lib/modules/Order/utils.js +65 -21
  87. package/lib/modules/Payment/types.d.ts +2 -0
  88. package/lib/modules/Payment/utils.js +5 -1
  89. package/lib/modules/Payment/walletpass.d.ts +11 -0
  90. package/lib/modules/Payment/walletpass.js +198 -17
  91. package/lib/modules/Product/types.d.ts +23 -0
  92. package/lib/modules/ProductList/index.d.ts +15 -2
  93. package/lib/modules/ProductList/index.js +85 -3
  94. package/lib/modules/Rules/index.js +100 -20
  95. package/lib/modules/SalesSummary/index.d.ts +1 -0
  96. package/lib/modules/SalesSummary/index.js +10 -2
  97. package/lib/modules/SalesSummary/types.d.ts +1 -0
  98. package/lib/modules/SalesSummary/utils.d.ts +1 -0
  99. package/lib/modules/SalesSummary/utils.js +30 -2
  100. package/lib/server/index.d.ts +15 -0
  101. package/lib/server/index.js +105 -14
  102. package/lib/server/modules/order/index.d.ts +2 -0
  103. package/lib/server/modules/order/index.js +75 -5
  104. package/lib/server/modules/order/types.d.ts +1 -1
  105. package/lib/server/utils/small-ticket.js +1 -1
  106. package/lib/solution/BaseSales/index.d.ts +41 -7
  107. package/lib/solution/BaseSales/index.js +325 -39
  108. package/lib/solution/BaseSales/utils/cartPromotion.js +26 -2
  109. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  110. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +62 -12
  111. package/lib/solution/BaseSales/utils.js +29 -18
  112. package/lib/solution/BookingByStep/index.d.ts +3 -3
  113. package/lib/solution/BookingTicket/index.d.ts +5 -1
  114. package/lib/solution/BookingTicket/index.js +31 -6
  115. package/lib/solution/BookingTicket/types.d.ts +3 -0
  116. package/lib/solution/BookingTicket/utils/addProductDecision.js +2 -1
  117. package/lib/solution/BookingTicket/utils/cartView.js +43 -30
  118. package/lib/solution/Sales/index.d.ts +1 -0
  119. package/lib/solution/Sales/index.js +15 -3
  120. package/lib/solution/ScanOrder/index.js +17 -54
  121. package/lib/solution/ScanOrder/utils.js +29 -18
  122. package/lib/solution/UnifiedBookingSales/index.d.ts +5 -4
  123. package/lib/solution/UnifiedBookingSales/index.js +35 -26
  124. package/package.json +1 -1
@@ -39,9 +39,11 @@ import { ensureOrderPaymentNumber, mergeOrderPaymentRecord, resolveOrderPaymentI
39
39
  import { resolvePaymentNumberDevicePrefix, resolvePaymentNumberDevicePrefixFromDeviceId } from "../../utils/payment-number";
40
40
  import { processCartPromotion, appendPromotionTags as _appendPromotionTags, getOrderProductUid as getPromotionUid } from "../../solution/BaseSales/utils/cartPromotion";
41
41
  import { buildProductLineFingerprint, getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
42
- import { syncManualProductDiscountProductNum } from "./utils/manualProductDiscount";
42
+ import { hasManualProductDiscountFlag, syncManualProductDiscountProductNum } from "./utils/manualProductDiscount";
43
43
  import { expandHydratedProductsForDiscountCollection, restoreHydratedBundleDiscounts } from "./utils/bundleDiscountHydration";
44
44
  import { getOrderCollectionPersistentId, getOrderCollectionUid, normalizeOrderCollections, repairDuplicateProductLineIdentities as repairDuplicateOrderProductLineIdentities, setOrderCollectionUid } from "./utils/orderCollectionIdentity";
45
+ import { consolidateDiscountFreeProductLines, ensureUniqueProductLineUids } from "./utils/discountProductLineIdentity";
46
+ import { applyTempOrderSettlementState, getSelectedSettlementSnapshot, getSettlementKey, getTempOrderSettlementKey, getTempOrderSettlementSnapshot, isVirtualSettlementOrder, normalizeVirtualSettlementOrderProduct, normalizeVirtualSettlementProducts, OrderSettlementConflictError, releaseTempOrderSettlementState, VirtualCurrencyAssetNotFoundError, VirtualCurrencyBalanceError } from "./utils/virtualSettlement";
45
47
  import { DiscountModule } from "../Discount";
46
48
  import { RulesModule } from "../Rules";
47
49
  import { UnavailableReason } from "../Rules/types";
@@ -63,8 +65,7 @@ function isSameDiscountList(left, right) {
63
65
  return JSON.stringify(normalizeDiscountListSignature(left)) === JSON.stringify(normalizeDiscountListSignature(right));
64
66
  }
65
67
  function isManualProductDiscountProduct(product) {
66
- var _product$metadata, _product$metadata2;
67
- return (product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.is_manual_discount) === true || (product === null || product === void 0 || (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.is_manual_discount) === 1 || ((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (item) {
68
+ return hasManualProductDiscountFlag(product === null || product === void 0 ? void 0 : product.metadata) || ((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (item) {
68
69
  return (item === null || item === void 0 ? void 0 : item.type) === 'product';
69
70
  });
70
71
  }
@@ -163,7 +164,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
163
164
  _step2;
164
165
  try {
165
166
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
166
- var _item$type2, _ref, _ref2, _item$discount$resour, _item$discount, _item$discount$title, _item$discount2, _item$amount, _ref3, _item$discount$origin, _item$discount3, _ref4, _ref5, _item$metadata$num, _item$metadata, _ref6, _ref7, _item$metadata$num2, _item$metadata2, _ref8, _item$discount$discou, _item$discount4, _ref9, _item$discount$origin2, _item$discount5, _item$amount2, _item$amount3, _product$product_id, _product$is_charge_ta, _ref10, _product$original_pri, _ref11, _item$discount$discou2, _item$discount6, _item$discount$discou3, _item$discount7;
167
+ var _item$type2, _ref, _ref2, _item$discount$resour, _item$discount, _item$discount$title, _item$discount2, _item$discount3, _item$discount$fixed_, _item$discount4, _item$discount5, _item$amount, _ref3, _item$discount$origin, _item$discount6, _ref4, _ref5, _item$metadata$num, _item$metadata, _ref6, _ref7, _item$metadata$num2, _item$metadata2, _ref8, _item$discount$discou, _item$discount7, _item$amount2, _item$amount3, _product$product_id, _product$is_charge_ta, _ref9, _product$original_pri, _ref10, _item$discount$discou2, _item$discount8, _item$discount$discou3, _item$discount9;
167
168
  var item = _step2.value;
168
169
  var type = (_item$type2 = item === null || item === void 0 ? void 0 : item.type) !== null && _item$type2 !== void 0 ? _item$type2 : item === null || item === void 0 ? void 0 : item.tag;
169
170
  if (!type || type === 'product') continue;
@@ -174,12 +175,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
174
175
  var key = Number.isFinite(id) ? id : String(resourceId);
175
176
  var title = (_item$discount$title = item === null || item === void 0 || (_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.title) !== null && _item$discount$title !== void 0 ? _item$discount$title : {};
176
177
  var amount = Number((item === null || item === void 0 ? void 0 : item.amount) || 0);
178
+ var discountCardType = item === null || item === void 0 || (_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.discount_card_type;
179
+ var parValue = isDiscountCard ? discountCardType === 'fixed_amount' ? (_item$discount$fixed_ = item === null || item === void 0 || (_item$discount4 = item.discount) === null || _item$discount4 === void 0 ? void 0 : _item$discount4.fixed_amount) !== null && _item$discount$fixed_ !== void 0 ? _item$discount$fixed_ : item === null || item === void 0 ? void 0 : item.amount : item === null || item === void 0 || (_item$discount5 = item.discount) === null || _item$discount5 === void 0 ? void 0 : _item$discount5.percent : '0';
177
180
  var detail = {
178
181
  amount: String((_item$amount = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount !== void 0 ? _item$amount : '0'),
179
182
  type: type,
180
183
  resource_id: key,
181
184
  title: title,
182
- original_amount: String((_ref3 = (_item$discount$origin = item === null || item === void 0 || (_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.original_amount) !== null && _item$discount$origin !== void 0 ? _item$discount$origin : item === null || item === void 0 ? void 0 : item.amount) !== null && _ref3 !== void 0 ? _ref3 : '0'),
185
+ original_amount: String((_ref3 = (_item$discount$origin = item === null || item === void 0 || (_item$discount6 = item.discount) === null || _item$discount6 === void 0 ? void 0 : _item$discount6.original_amount) !== null && _item$discount$origin !== void 0 ? _item$discount$origin : item === null || item === void 0 ? void 0 : item.amount) !== null && _ref3 !== void 0 ? _ref3 : '0'),
183
186
  num: Number((_ref4 = (_ref5 = (_item$metadata$num = item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.num) !== null && _item$metadata$num !== void 0 ? _item$metadata$num : product === null || product === void 0 ? void 0 : product.num) !== null && _ref5 !== void 0 ? _ref5 : product === null || product === void 0 ? void 0 : product.product_quantity) !== null && _ref4 !== void 0 ? _ref4 : 1) || 1,
184
187
  metadata: item === null || item === void 0 ? void 0 : item.metadata,
185
188
  discount: item === null || item === void 0 ? void 0 : item.discount,
@@ -209,9 +212,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
209
212
  encoded: '',
210
213
  code: '',
211
214
  tag: type,
212
- product_id: (_ref8 = (_item$discount$discou = item === null || item === void 0 || (_item$discount4 = item.discount) === null || _item$discount4 === void 0 ? void 0 : _item$discount4.discount_product_id) !== null && _item$discount$discou !== void 0 ? _item$discount$discou : product === null || product === void 0 ? void 0 : product.product_id) !== null && _ref8 !== void 0 ? _ref8 : 0,
215
+ product_id: (_ref8 = (_item$discount$discou = item === null || item === void 0 || (_item$discount7 = item.discount) === null || _item$discount7 === void 0 ? void 0 : _item$discount7.discount_product_id) !== null && _item$discount$discou !== void 0 ? _item$discount$discou : product === null || product === void 0 ? void 0 : product.product_id) !== null && _ref8 !== void 0 ? _ref8 : 0,
213
216
  relation_type: '',
214
- par_value: String((_ref9 = (_item$discount$origin2 = item === null || item === void 0 || (_item$discount5 = item.discount) === null || _item$discount5 === void 0 ? void 0 : _item$discount5.original_amount) !== null && _item$discount$origin2 !== void 0 ? _item$discount$origin2 : item === null || item === void 0 ? void 0 : item.amount) !== null && _ref9 !== void 0 ? _ref9 : '0'),
217
+ par_value: String(parValue !== null && parValue !== void 0 ? parValue : '0'),
215
218
  used_par_value: String((_item$amount2 = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount2 !== void 0 ? _item$amount2 : '0'),
216
219
  limit_status: 'enable',
217
220
  limited_relation_product_data: {
@@ -230,7 +233,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
230
233
  id: (_product$product_id = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : 0,
231
234
  title: '',
232
235
  is_charge_tax: (_product$is_charge_ta = product === null || product === void 0 ? void 0 : product.is_charge_tax) !== null && _product$is_charge_ta !== void 0 ? _product$is_charge_ta : 0,
233
- base_price: String((_ref10 = (_product$original_pri = product === null || product === void 0 ? void 0 : product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : product === null || product === void 0 ? void 0 : product.selling_price) !== null && _ref10 !== void 0 ? _ref10 : '0')
236
+ base_price: String((_ref9 = (_product$original_pri = product === null || product === void 0 ? void 0 : product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : product === null || product === void 0 ? void 0 : product.selling_price) !== null && _ref9 !== void 0 ? _ref9 : '0')
234
237
  },
235
238
  type: type,
236
239
  resource_id: key,
@@ -242,8 +245,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
242
245
  amount: amount,
243
246
  discount: _objectSpread(_objectSpread({}, (item === null || item === void 0 ? void 0 : item.discount) || {}), {}, {
244
247
  resource_id: key,
245
- discount_product_id: (_ref11 = (_item$discount$discou2 = item === null || item === void 0 || (_item$discount6 = item.discount) === null || _item$discount6 === void 0 ? void 0 : _item$discount6.discount_product_id) !== null && _item$discount$discou2 !== void 0 ? _item$discount$discou2 : product === null || product === void 0 ? void 0 : product.product_id) !== null && _ref11 !== void 0 ? _ref11 : 0,
246
- discount_calculation_mode: (_item$discount$discou3 = item === null || item === void 0 || (_item$discount7 = item.discount) === null || _item$discount7 === void 0 ? void 0 : _item$discount7.discount_calculation_mode) !== null && _item$discount$discou3 !== void 0 ? _item$discount$discou3 : 'item_level'
248
+ discount_product_id: (_ref10 = (_item$discount$discou2 = item === null || item === void 0 || (_item$discount8 = item.discount) === null || _item$discount8 === void 0 ? void 0 : _item$discount8.discount_product_id) !== null && _item$discount$discou2 !== void 0 ? _item$discount$discou2 : product === null || product === void 0 ? void 0 : product.product_id) !== null && _ref10 !== void 0 ? _ref10 : 0,
249
+ discount_calculation_mode: (_item$discount$discou3 = item === null || item === void 0 || (_item$discount9 = item.discount) === null || _item$discount9 === void 0 ? void 0 : _item$discount9.discount_calculation_mode) !== null && _item$discount$discou3 !== void 0 ? _item$discount$discou3 : 'item_level'
247
250
  }),
248
251
  applicableProductDetails: [detail],
249
252
  appliedProductDetails: [detail]
@@ -271,7 +274,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
271
274
  key: "applyProductDiscountPrices",
272
275
  value: function applyProductDiscountPrices(products) {
273
276
  return (products || []).map(function (product) {
274
- var _product$metadata$sou, _product$metadata3, _product$metadata4, _product$original_pri2;
277
+ var _product$metadata$sou, _product$metadata, _product$metadata2, _product$original_pri2;
275
278
  if (isManualProductDiscountProduct(product)) return product;
276
279
  var discountItems = Array.isArray(product.discount_list) ? product.discount_list : [];
277
280
  var hasOnlyPersistedDiscountSnapshots = product.order_detail_id !== undefined && product.order_detail_id !== null && discountItems.length > 0 && discountItems.every(function (discount) {
@@ -282,7 +285,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
282
285
  }
283
286
  var totalPerUnitDiscount = resolveEffectivePerUnitDiscount(product);
284
287
  var optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
285
- var sourcePrice = (_product$metadata$sou = (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : '0';
288
+ var sourcePrice = (_product$metadata$sou = (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : '0';
286
289
  var newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
287
290
  var newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
288
291
  if (product.metadata) {
@@ -291,10 +294,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
291
294
  }
292
295
  if (Array.isArray(product.product_bundle)) {
293
296
  product.product_bundle = product.product_bundle.map(function (bundle) {
294
- var _ref12, _bundle$original_pric;
297
+ var _ref11, _bundle$original_pric;
295
298
  var hasBundleDiscount = Array.isArray(bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) && bundle.discount_list.length > 0;
296
299
  if (hasBundleDiscount) return bundle;
297
- var restoredPrice = (_ref12 = (_bundle$original_pric = bundle === null || bundle === void 0 ? void 0 : bundle.original_price) !== null && _bundle$original_pric !== void 0 ? _bundle$original_pric : bundle === null || bundle === void 0 ? void 0 : bundle.product_price) !== null && _ref12 !== void 0 ? _ref12 : bundle === null || bundle === void 0 ? void 0 : bundle.price;
300
+ var restoredPrice = (_ref11 = (_bundle$original_pric = bundle === null || bundle === void 0 ? void 0 : bundle.original_price) !== null && _bundle$original_pric !== void 0 ? _bundle$original_pric : bundle === null || bundle === void 0 ? void 0 : bundle.product_price) !== null && _ref11 !== void 0 ? _ref11 : bundle === null || bundle === void 0 ? void 0 : bundle.price;
298
301
  if (restoredPrice === undefined || restoredPrice === null || restoredPrice === '') return bundle;
299
302
  return _objectSpread(_objectSpread({}, bundle), {}, {
300
303
  price: restoredPrice,
@@ -337,6 +340,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
337
340
  this.store.tempOrder = null;
338
341
  this.store.summary = createEmptySummary();
339
342
  this.store.availableWalletIds = [];
343
+ this.store.virtualCurrencyList = [];
340
344
  this.store.lastOrderInfo = undefined;
341
345
  this.store.syncState = undefined;
342
346
  this.store.discountList = [];
@@ -349,6 +353,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
349
353
  if (!Array.isArray(this.store.availableWalletIds)) {
350
354
  this.store.availableWalletIds = [];
351
355
  }
356
+ if (!Array.isArray(this.store.virtualCurrencyList)) {
357
+ this.store.virtualCurrencyList = [];
358
+ }
352
359
  this.request = this.core.getPlugin('request');
353
360
  appPlugin = this.core.getPlugin('app');
354
361
  if (!appPlugin) {
@@ -364,7 +371,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
364
371
  this.otherParams = otherParams;
365
372
  this.registerDiscountModules(options);
366
373
  this.logInfo('OrderModule initialized successfully');
367
- case 20:
374
+ case 21:
368
375
  case "end":
369
376
  return _context.stop();
370
377
  }
@@ -557,6 +564,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
557
564
  with_wallet_pass_holder: 1,
558
565
  with_available_wallet_flag: 1,
559
566
  with_available_wallet_pass_flag: 1,
567
+ with_virtual_currency: 1,
560
568
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
561
569
  }, orderId ? {
562
570
  order_id: orderId
@@ -565,8 +573,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
565
573
  prepareConfigResult = _context3.sent;
566
574
  discountList = prepareConfigResult === null || prepareConfigResult === void 0 ? void 0 : prepareConfigResult.discountList;
567
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) || [];
568
577
  if (!discountList) {
569
- _context3.next = 18;
578
+ _context3.next = 19;
570
579
  break;
571
580
  }
572
581
  currentDiscountList = ((_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 ? void 0 : _this$store$discount2.getDiscountList()) || [];
@@ -587,17 +596,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
587
596
  return true;
588
597
  });
589
598
  mergedDiscountList = [].concat(_toConsumableArray(currentEditDiscounts), _toConsumableArray(currentScanDiscounts), _toConsumableArray(runtimeDiscounts));
590
- _context3.next = 16;
599
+ _context3.next = 17;
591
600
  return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.setOriginalDiscountList(mergedDiscountList);
592
- case 16:
593
- _context3.next = 18;
601
+ case 17:
602
+ _context3.next = 19;
594
603
  return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.setDiscountList(mergedDiscountList);
595
- case 18:
604
+ case 19:
596
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) {
597
606
  this.applyDiscount();
598
607
  }
599
608
  return _context3.abrupt("return", this.getDiscountList());
600
- case 20:
609
+ case 21:
601
610
  case "end":
602
611
  return _context3.stop();
603
612
  }
@@ -619,6 +628,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
619
628
  value: function getAvailableWalletIds() {
620
629
  return Array.isArray(this.store.availableWalletIds) ? _toConsumableArray(this.store.availableWalletIds) : [];
621
630
  }
631
+ }, {
632
+ key: "getVirtualCurrencyList",
633
+ value: function getVirtualCurrencyList() {
634
+ return cloneDeep(this.store.virtualCurrencyList || []);
635
+ }
622
636
  }, {
623
637
  key: "syncScannedDiscountsToOriginalDiscountList",
624
638
  value: function () {
@@ -707,30 +721,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
707
721
  value: function () {
708
722
  var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(code, customerId) {
709
723
  var _this$store$discount11, _tempOrder$holder, _this$store$summary;
710
- var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref13, isAvailable, newDiscountList, evaluatedDiscountList, unavailableReason, shouldRetainForLater, normalizedNewDiscountList, retainedDiscountList, resolvedDiscountList, _this$store$discount12, _this$store$discount13;
724
+ var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref12, isAvailable, newDiscountList, evaluatedDiscountList, unavailableReason, shouldRetainForLater, normalizedNewDiscountList, retainedDiscountList, resolvedDiscountList, _this$store$discount12, _this$store$discount13;
711
725
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
712
726
  while (1) switch (_context6.prev = _context6.next) {
713
727
  case 0:
714
- _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;
715
742
  return (_this$store$discount11 = this.store.discount) === null || _this$store$discount11 === void 0 ? void 0 : _this$store$discount11.batchSearch(code, {
716
743
  customerId: customerId
717
744
  });
718
- case 2:
745
+ case 4:
719
746
  _context6.t0 = _context6.sent;
720
747
  if (_context6.t0) {
721
- _context6.next = 5;
748
+ _context6.next = 7;
722
749
  break;
723
750
  }
724
751
  _context6.t0 = {
725
752
  discountList: [],
726
753
  unavailableReasonKey: null
727
754
  };
728
- case 5:
755
+ case 7:
729
756
  resultDiscountWithReason = _context6.t0;
730
757
  resultDiscountList = resultDiscountWithReason.discountList, unavailableReasonKey = resultDiscountWithReason.unavailableReasonKey;
731
758
  rulesModule = this.store.rules;
732
759
  if (rulesModule) {
733
- _context6.next = 10;
760
+ _context6.next = 12;
734
761
  break;
735
762
  }
736
763
  return _context6.abrupt("return", {
@@ -741,9 +768,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
741
768
  scannedDiscountList: resultDiscountList,
742
769
  unavailableReason: UnavailableReason.Unknown
743
770
  });
744
- case 10:
771
+ case 12:
745
772
  if (resultDiscountList.length) {
746
- _context6.next = 12;
773
+ _context6.next = 14;
747
774
  break;
748
775
  }
749
776
  return _context6.abrupt("return", {
@@ -754,7 +781,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
754
781
  scannedDiscountList: resultDiscountList,
755
782
  unavailableReasonKey: unavailableReasonKey
756
783
  });
757
- case 12:
784
+ case 14:
758
785
  withScanList = resultDiscountList.map(function (item) {
759
786
  return _objectSpread(_objectSpread({}, item), {}, {
760
787
  isScan: true
@@ -768,12 +795,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
768
795
  return m.id === n.id;
769
796
  });
770
797
  }))) {
771
- _context6.next = 18;
798
+ _context6.next = 20;
772
799
  break;
773
800
  }
774
- _context6.next = 17;
801
+ _context6.next = 19;
775
802
  return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
776
- case 17:
803
+ case 19:
777
804
  return _context6.abrupt("return", {
778
805
  type: 'clientCalc',
779
806
  isAvailable: true,
@@ -781,10 +808,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
781
808
  discountList: this.getDiscountList(),
782
809
  scannedDiscountList: resultDiscountList
783
810
  });
784
- case 18:
811
+ case 20:
785
812
  tempOrder = this.store.tempOrder;
786
813
  holders = (tempOrder === null || tempOrder === void 0 || (_tempOrder$holder = tempOrder.holder) === null || _tempOrder$holder === void 0 ? void 0 : _tempOrder$holder.form_record) || [];
787
- _ref13 = rulesModule.isDiscountListAvailable({
814
+ _ref12 = rulesModule.isDiscountListAvailable({
788
815
  productList: (tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.products) || [],
789
816
  oldDiscountList: this.getDiscountList(),
790
817
  newDiscountList: withScanList,
@@ -796,38 +823,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
796
823
  }) || {
797
824
  isAvailable: false,
798
825
  discountList: this.getDiscountList()
799
- }, isAvailable = _ref13.isAvailable, newDiscountList = _ref13.discountList, evaluatedDiscountList = _ref13.evaluatedDiscountList, unavailableReason = _ref13.unavailableReason;
826
+ }, isAvailable = _ref12.isAvailable, newDiscountList = _ref12.discountList, evaluatedDiscountList = _ref12.evaluatedDiscountList, unavailableReason = _ref12.unavailableReason;
800
827
  shouldRetainForLater = !isAvailable && unavailableReason === UnavailableReason.ProductNotApplicable && withScanList.some(isCustomerPromotionDiscount);
801
828
  normalizedNewDiscountList = newDiscountList ? markScannedDiscounts(newDiscountList, withScanList) : undefined;
802
829
  retainedDiscountList = evaluatedDiscountList ? markScannedDiscounts(evaluatedDiscountList, withScanList) : normalizedNewDiscountList;
803
830
  resolvedDiscountList = normalizedNewDiscountList || this.getDiscountList();
804
831
  if (!(isAvailable && normalizedNewDiscountList)) {
805
- _context6.next = 34;
832
+ _context6.next = 36;
806
833
  break;
807
834
  }
808
- _context6.next = 28;
835
+ _context6.next = 30;
809
836
  return (_this$store$discount12 = this.store.discount) === null || _this$store$discount12 === void 0 ? void 0 : _this$store$discount12.setDiscountList(normalizedNewDiscountList);
810
- case 28:
837
+ case 30:
811
838
  this.applyDiscount();
812
- _context6.next = 31;
839
+ _context6.next = 33;
813
840
  return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
814
- case 31:
841
+ case 33:
815
842
  resolvedDiscountList = this.getDiscountList();
816
- _context6.next = 40;
843
+ _context6.next = 42;
817
844
  break;
818
- case 34:
845
+ case 36:
819
846
  if (!(shouldRetainForLater && retainedDiscountList)) {
820
- _context6.next = 40;
847
+ _context6.next = 42;
821
848
  break;
822
849
  }
823
- _context6.next = 37;
824
- return (_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.setDiscountList(retainedDiscountList);
825
- case 37:
826
850
  _context6.next = 39;
827
- 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);
828
852
  case 39:
853
+ _context6.next = 41;
854
+ return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
855
+ case 41:
829
856
  resolvedDiscountList = this.getDiscountList();
830
- case 40:
857
+ case 42:
831
858
  return _context6.abrupt("return", {
832
859
  type: 'clientCalc',
833
860
  isAvailable: isAvailable || false,
@@ -836,7 +863,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
836
863
  scannedDiscountList: resultDiscountList,
837
864
  unavailableReason: unavailableReason
838
865
  });
839
- case 41:
866
+ case 43:
840
867
  case "end":
841
868
  return _context6.stop();
842
869
  }
@@ -850,7 +877,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
850
877
  }, {
851
878
  key: "applyDiscount",
852
879
  value: function applyDiscount(options) {
853
- var _this$store$discount14,
880
+ var _this$store$discount16,
854
881
  _this$store$summary2,
855
882
  _this2 = this;
856
883
  var tempOrder = this.store.tempOrder;
@@ -858,9 +885,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
858
885
  // 也需要让 Rules.calcDiscount 把 DiscountModule 的 isSelected / isAvailable /
859
886
  // appliedProductDetails / savedAmount 复位。
860
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
+ }
861
897
  this.syncLinkedBookingHoldersToProducts(tempOrder);
862
898
  delete tempOrder.discount_list;
863
- 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()) || [];
864
900
  var shouldSkipDiscountCalculation = this.shouldSkipDiscountCalculation(tempOrder);
865
901
  if (shouldSkipDiscountCalculation) return;
866
902
  var rulesModule = this.store.rules;
@@ -879,9 +915,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
879
915
  if (result !== null && result !== void 0 && result.productList) {
880
916
  var previousProductsByUid = indexOrderProductsByUid(tempOrder.products);
881
917
  tempOrder.products = this.applyProductDiscountPrices((result.productList || []).map(function (product, index) {
882
- var _ref14;
918
+ var _ref13;
883
919
  var uid = getOrderProductLineUid(product);
884
- var previous = (_ref14 = uid ? previousProductsByUid.get(uid) : undefined) !== null && _ref14 !== void 0 ? _ref14 : previousProductsByUid.get("__index__:".concat(index));
920
+ var previous = (_ref13 = uid ? previousProductsByUid.get(uid) : undefined) !== null && _ref13 !== void 0 ? _ref13 : previousProductsByUid.get("__index__:".concat(index));
885
921
  if (isManualProductDiscountProduct(previous)) {
886
922
  return previous;
887
923
  }
@@ -890,12 +926,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
890
926
  discount_list: normalizeOrderProductDiscountList(syncManualProductDiscountProductNum(mergedProduct.discount_list, mergedProduct.num))
891
927
  });
892
928
  }));
893
- this.repairDuplicateProductLineIdentities(tempOrder);
929
+ ensureUniqueProductLineUids(tempOrder);
930
+ consolidateDiscountFreeProductLines(tempOrder);
894
931
  }
895
932
  if (result !== null && result !== void 0 && result.discountList) {
896
- var _this$store$discount15;
933
+ var _this$store$discount17;
897
934
  OrderModule.populateSavedAmounts(result.productList || tempOrder.products, result.discountList);
898
- (_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);
899
936
  }
900
937
  this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(function (product) {
901
938
  return _this2.productHasCustomerBoundDiscount(product);
@@ -984,15 +1021,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
984
1021
  }
985
1022
  return _context9.abrupt("return");
986
1023
  case 7:
987
- strategyConfigs = (_this$promotionEvalua = (_this$promotionEvalua2 = this.promotionEvaluator).getStrategyConfigs) === null || _this$promotionEvalua === void 0 ? void 0 : _this$promotionEvalua.call(_this$promotionEvalua2);
988
- if (!(Array.isArray(strategyConfigs) && strategyConfigs.length === 0)) {
1024
+ if (!this.isActiveVirtualSettlementOrder(tempOrder)) {
989
1025
  _context9.next = 10;
990
1026
  break;
991
1027
  }
1028
+ tempOrder.products = normalizeVirtualSettlementProducts(tempOrder.products);
992
1029
  return _context9.abrupt("return");
993
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:
994
1038
  this.isApplyingPromotion = true;
995
- _context9.prev = 11;
1039
+ _context9.prev = 14;
996
1040
  result = processCartPromotion(tempOrder.products, this.promotionEvaluator); // step 1: toRemove —— 直接过滤
997
1041
  if (result.giftActions.toRemove.length > 0) {
998
1042
  removeSet = new Set(result.giftActions.toRemove.map(String));
@@ -1004,16 +1048,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1004
1048
 
1005
1049
  // step 2: toReduce —— 调整数量
1006
1050
  _iterator3 = _createForOfIteratorHelper(result.giftActions.toReduce);
1007
- _context9.prev = 15;
1051
+ _context9.prev = 18;
1008
1052
  _iterator3.s();
1009
- case 17:
1053
+ case 20:
1010
1054
  if ((_step3 = _iterator3.n()).done) {
1011
- _context9.next = 37;
1055
+ _context9.next = 40;
1012
1056
  break;
1013
1057
  }
1014
1058
  reduce = _step3.value;
1015
1059
  _iterator6 = _createForOfIteratorHelper(reduce.items);
1016
- _context9.prev = 20;
1060
+ _context9.prev = 23;
1017
1061
  _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
1018
1062
  var item, product;
1019
1063
  return _regeneratorRuntime().wrap(function _loop2$(_context8) {
@@ -1033,47 +1077,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1033
1077
  }, _loop2);
1034
1078
  });
1035
1079
  _iterator6.s();
1036
- case 23:
1080
+ case 26:
1037
1081
  if ((_step6 = _iterator6.n()).done) {
1038
- _context9.next = 27;
1082
+ _context9.next = 30;
1039
1083
  break;
1040
1084
  }
1041
- return _context9.delegateYield(_loop2(), "t0", 25);
1042
- case 25:
1043
- _context9.next = 23;
1085
+ return _context9.delegateYield(_loop2(), "t0", 28);
1086
+ case 28:
1087
+ _context9.next = 26;
1044
1088
  break;
1045
- case 27:
1046
- _context9.next = 32;
1089
+ case 30:
1090
+ _context9.next = 35;
1047
1091
  break;
1048
- case 29:
1049
- _context9.prev = 29;
1050
- _context9.t1 = _context9["catch"](20);
1051
- _iterator6.e(_context9.t1);
1052
1092
  case 32:
1053
1093
  _context9.prev = 32;
1054
- _iterator6.f();
1055
- return _context9.finish(32);
1094
+ _context9.t1 = _context9["catch"](23);
1095
+ _iterator6.e(_context9.t1);
1056
1096
  case 35:
1057
- _context9.next = 17;
1097
+ _context9.prev = 35;
1098
+ _iterator6.f();
1099
+ return _context9.finish(35);
1100
+ case 38:
1101
+ _context9.next = 20;
1058
1102
  break;
1059
- case 37:
1060
- _context9.next = 42;
1103
+ case 40:
1104
+ _context9.next = 45;
1061
1105
  break;
1062
- case 39:
1063
- _context9.prev = 39;
1064
- _context9.t2 = _context9["catch"](15);
1065
- _iterator3.e(_context9.t2);
1066
1106
  case 42:
1067
1107
  _context9.prev = 42;
1068
- _iterator3.f();
1069
- return _context9.finish(42);
1108
+ _context9.t2 = _context9["catch"](18);
1109
+ _iterator3.e(_context9.t2);
1070
1110
  case 45:
1111
+ _context9.prev = 45;
1112
+ _iterator3.f();
1113
+ return _context9.finish(45);
1114
+ case 48:
1071
1115
  if (!(result.giftActions.toAdd.length > 0)) {
1072
- _context9.next = 68;
1116
+ _context9.next = 71;
1073
1117
  break;
1074
1118
  }
1075
1119
  if (this.giftSelectResolver) {
1076
- _context9.next = 50;
1120
+ _context9.next = 53;
1077
1121
  break;
1078
1122
  }
1079
1123
  if (result.giftActions.toAdd.some(function (g) {
@@ -1084,11 +1128,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1084
1128
  } else {
1085
1129
  console.warn('[OrderModule] giftSelectResolver not set, skip applying single-option gifts', result.giftActions.toAdd);
1086
1130
  }
1087
- _context9.next = 68;
1131
+ _context9.next = 71;
1088
1132
  break;
1089
- case 50:
1133
+ case 53:
1090
1134
  _iterator4 = _createForOfIteratorHelper(result.giftActions.toAdd);
1091
- _context9.prev = 51;
1135
+ _context9.prev = 54;
1092
1136
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
1093
1137
  var addAction, _sameStrategy$metadat, sameStrategy, giftResult, giftProducts, giftBookings, _iterator5, _step5, _step5$value, index, gp, booking, linked;
1094
1138
  return _regeneratorRuntime().wrap(function _loop$(_context7) {
@@ -1186,33 +1230,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1186
1230
  }, _loop, null, [[6, 39], [14, 31, 34, 37]]);
1187
1231
  });
1188
1232
  _iterator4.s();
1189
- case 54:
1233
+ case 57:
1190
1234
  if ((_step4 = _iterator4.n()).done) {
1191
- _context9.next = 60;
1235
+ _context9.next = 63;
1192
1236
  break;
1193
1237
  }
1194
- return _context9.delegateYield(_loop(), "t3", 56);
1195
- case 56:
1238
+ return _context9.delegateYield(_loop(), "t3", 59);
1239
+ case 59:
1196
1240
  if (!_context9.t3) {
1197
- _context9.next = 58;
1241
+ _context9.next = 61;
1198
1242
  break;
1199
1243
  }
1200
- return _context9.abrupt("continue", 58);
1201
- case 58:
1202
- _context9.next = 54;
1244
+ return _context9.abrupt("continue", 61);
1245
+ case 61:
1246
+ _context9.next = 57;
1203
1247
  break;
1204
- case 60:
1205
- _context9.next = 65;
1248
+ case 63:
1249
+ _context9.next = 68;
1206
1250
  break;
1207
- case 62:
1208
- _context9.prev = 62;
1209
- _context9.t4 = _context9["catch"](51);
1210
- _iterator4.e(_context9.t4);
1211
1251
  case 65:
1212
1252
  _context9.prev = 65;
1213
- _iterator4.f();
1214
- return _context9.finish(65);
1253
+ _context9.t4 = _context9["catch"](54);
1254
+ _iterator4.e(_context9.t4);
1215
1255
  case 68:
1256
+ _context9.prev = 68;
1257
+ _iterator4.f();
1258
+ return _context9.finish(68);
1259
+ case 71:
1216
1260
  tempOrder.products = result.products;
1217
1261
  this.lastUnfulfilledPromotions = result.unfulfilledPromotions;
1218
1262
  this.lastGiftActions = result.giftActions;
@@ -1230,21 +1274,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1230
1274
  products: tempOrder.products
1231
1275
  };
1232
1276
  this.effectsEmit('onPromotionApplied', payload);
1233
- _context9.next = 78;
1277
+ _context9.next = 81;
1234
1278
  break;
1235
- case 75:
1236
- _context9.prev = 75;
1237
- _context9.t5 = _context9["catch"](11);
1238
- console.error('[OrderModule] applyPromotion failed', _context9.t5);
1239
1279
  case 78:
1240
1280
  _context9.prev = 78;
1241
- this.isApplyingPromotion = false;
1242
- return _context9.finish(78);
1281
+ _context9.t5 = _context9["catch"](14);
1282
+ console.error('[OrderModule] applyPromotion failed', _context9.t5);
1243
1283
  case 81:
1284
+ _context9.prev = 81;
1285
+ this.isApplyingPromotion = false;
1286
+ return _context9.finish(81);
1287
+ case 84:
1244
1288
  case "end":
1245
1289
  return _context9.stop();
1246
1290
  }
1247
- }, _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]]);
1248
1292
  }));
1249
1293
  function applyPromotion() {
1250
1294
  return _applyPromotion.apply(this, arguments);
@@ -1310,6 +1354,53 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1310
1354
  cacheKey: ['tempOrder']
1311
1355
  });
1312
1356
  }
1357
+
1358
+ /**
1359
+ * 终止当前模块实例的 sessionStorage 订单恢复会话。
1360
+ *
1361
+ * 支付跳转等终态场景需要同时删除当前 cacheId 的 tempOrder 快照,并关闭
1362
+ * 本实例后续异步任务的再次写入;新模块实例初始化时会按 otherParams 重新启用。
1363
+ */
1364
+ }, {
1365
+ key: "clearSessionStoragePersistedTempOrder",
1366
+ value: function clearSessionStoragePersistedTempOrder() {
1367
+ var _this$window;
1368
+ this.sessionStorageRestoreRecord = null;
1369
+ if (!this.sessionStoragePersistEnabled) return;
1370
+ this.sessionStoragePersistEnabled = false;
1371
+ if (!this.cacheId || !this.fatherModule || !((_this$window = this.window) !== null && _this$window !== void 0 && _this$window.sessionStorage)) {
1372
+ return;
1373
+ }
1374
+ var sessionStorage = this.window.sessionStorage;
1375
+ var rawCacheData = sessionStorage.getItem(this.fatherModule);
1376
+ if (!rawCacheData) return;
1377
+ var parsedCacheData;
1378
+ try {
1379
+ parsedCacheData = JSON.parse(rawCacheData);
1380
+ } catch (_unused2) {
1381
+ return;
1382
+ }
1383
+ if (!parsedCacheData || _typeof(parsedCacheData) !== 'object' || Array.isArray(parsedCacheData)) {
1384
+ return;
1385
+ }
1386
+ var cacheRoot = parsedCacheData;
1387
+ var cacheBucket = cacheRoot[this.cacheId];
1388
+ if (!cacheBucket || _typeof(cacheBucket) !== 'object' || Array.isArray(cacheBucket)) {
1389
+ return;
1390
+ }
1391
+ var moduleBucket = cacheBucket[this.name];
1392
+ if (!moduleBucket || _typeof(moduleBucket) !== 'object' || Array.isArray(moduleBucket)) {
1393
+ return;
1394
+ }
1395
+ delete moduleBucket.tempOrder;
1396
+ if (Object.keys(moduleBucket).length === 0) {
1397
+ delete cacheBucket[this.name];
1398
+ }
1399
+ if (Object.keys(cacheBucket).length === 0) {
1400
+ delete cacheRoot[this.cacheId];
1401
+ }
1402
+ sessionStorage.setItem(this.fatherModule, JSON.stringify(cacheRoot));
1403
+ }
1313
1404
  }, {
1314
1405
  key: "consumeSessionStorageRestore",
1315
1406
  value: function consumeSessionStorageRestore() {
@@ -1436,15 +1527,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1436
1527
  }, {
1437
1528
  key: "extractOrderIdFromSubmitResult",
1438
1529
  value: function extractOrderIdFromSubmitResult(result) {
1439
- var _ref15, _ref16, _ref17, _result$data$order_id, _result$data, _result$data2;
1440
- return (_ref15 = (_ref16 = (_ref17 = (_result$data$order_id = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.order_id) !== null && _result$data$order_id !== void 0 ? _result$data$order_id : result === null || result === void 0 ? void 0 : result.order_id) !== null && _ref17 !== void 0 ? _ref17 : result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.id) !== null && _ref16 !== void 0 ? _ref16 : result === null || result === void 0 ? void 0 : result.id) !== null && _ref15 !== void 0 ? _ref15 : null;
1530
+ var _ref14, _ref15, _ref16, _result$data$order_id, _result$data, _result$data2;
1531
+ return (_ref14 = (_ref15 = (_ref16 = (_result$data$order_id = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.order_id) !== null && _result$data$order_id !== void 0 ? _result$data$order_id : result === null || result === void 0 ? void 0 : result.order_id) !== null && _ref16 !== void 0 ? _ref16 : result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.id) !== null && _ref15 !== void 0 ? _ref15 : result === null || result === void 0 ? void 0 : result.id) !== null && _ref14 !== void 0 ? _ref14 : null;
1441
1532
  }
1442
1533
  }, {
1443
1534
  key: "calculatePaymentEffectiveAmount",
1444
1535
  value: function calculatePaymentEffectiveAmount(payment) {
1445
- var _ref18, _payment$origin_amoun;
1536
+ var _ref17, _payment$origin_amoun;
1446
1537
  var amount = new Decimal(payment.amount || 0);
1447
- var originAmount = new Decimal((_ref18 = (_payment$origin_amoun = payment.origin_amount) !== null && _payment$origin_amoun !== void 0 ? _payment$origin_amoun : payment.amount) !== null && _ref18 !== void 0 ? _ref18 : 0);
1538
+ var originAmount = new Decimal((_ref17 = (_payment$origin_amoun = payment.origin_amount) !== null && _payment$origin_amoun !== void 0 ? _payment$origin_amoun : payment.amount) !== null && _ref17 !== void 0 ? _ref17 : 0);
1448
1539
  var serviceFee = new Decimal(payment.service_fee || 0);
1449
1540
  // TODO: 后端允许 amount 表示顾客实际支付总额后,移除这个兼容分支。
1450
1541
  var effectiveAmount = serviceFee.gt(0) && amount.eq(originAmount) ? amount.plus(serviceFee) : amount;
@@ -1582,7 +1673,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1582
1673
  paidAmount: netPaidAmount
1583
1674
  });
1584
1675
  var isOrderFullyPaid = orderExpectedAmount.lte(0) ? true : netPaidAmount.gte(orderExpectedAmount);
1585
- var paymentStage = this.isDepositOrder(tempOrder, depositAmount) && !isDepositFullyPaid ? 'deposit' : 'normal';
1676
+ var paymentStage = this.isDepositOrder(tempOrder, depositAmount) && !isDepositFullyPaid && !this.hasPaidNormalPayment(paymentList) ? 'deposit' : 'normal';
1586
1677
  return {
1587
1678
  isFullyPaid: isOrderFullyPaid,
1588
1679
  isOrderFullyPaid: isOrderFullyPaid,
@@ -1604,12 +1695,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1604
1695
  return sum.plus(_this6.calculatePaymentGapAmount(paymentRecord));
1605
1696
  }, new Decimal(0));
1606
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
+ }
1607
1707
  }, {
1608
1708
  key: "resolveNextOrderPaymentType",
1609
1709
  value: function resolveNextOrderPaymentType(tempOrder) {
1610
1710
  var depositAmount = new Decimal(tempOrder.deposit_amount || '0.00');
1611
1711
  if (!this.isDepositOrder(tempOrder, depositAmount)) return 'normal';
1612
1712
  if (depositAmount.lte(0)) return 'normal';
1713
+ if (this.hasPaidNormalPayment(tempOrder.payments || [])) return 'normal';
1613
1714
  var depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1614
1715
  return depositPaidAmount.lt(depositAmount) ? 'deposit' : 'normal';
1615
1716
  }
@@ -1644,12 +1745,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1644
1745
  }, {
1645
1746
  key: "normalizePaymentSource",
1646
1747
  value: function normalizePaymentSource(payment, options) {
1647
- var _ref19, _paymentRecord$origin;
1748
+ var _ref18, _paymentRecord$origin;
1648
1749
  var paymentRecord = payment;
1649
1750
  var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
1650
1751
  var normalized = ensureOrderPaymentNumber(_objectSpread(_objectSpread({}, paymentRecord), {}, {
1651
1752
  metadata: metadata,
1652
- origin_amount: (_ref19 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref19 !== void 0 ? _ref19 : '0.00'
1753
+ origin_amount: (_ref18 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref18 !== void 0 ? _ref18 : '0.00'
1653
1754
  }), (options === null || options === void 0 ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(), createUuidV4);
1654
1755
  if (paymentRecord.status !== undefined) {
1655
1756
  normalized.status = paymentRecord.status;
@@ -1937,10 +2038,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1937
2038
  value: function calculateSummaryAmountGap(params) {
1938
2039
  var tempOrder = params.tempOrder,
1939
2040
  summary = params.summary,
1940
- orderPaidAmount = params.orderPaidAmount;
2041
+ orderPaidAmount = params.orderPaidAmount,
2042
+ payments = params.payments;
1941
2043
  var refundAmount = this.getSummaryRefundAmount(summary);
1942
2044
  var netOrderPaidAmount = Decimal.max(orderPaidAmount.minus(refundAmount), 0);
1943
- var targetAmount = this.calculatePaymentTargetAmount(tempOrder, summary, netOrderPaidAmount);
2045
+ var targetAmount = this.calculatePaymentTargetAmount(tempOrder, summary, netOrderPaidAmount, payments);
1944
2046
  return targetAmount.minus(netOrderPaidAmount).toFixed(2);
1945
2047
  }
1946
2048
  }, {
@@ -1952,10 +2054,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1952
2054
  key: "calculatePaymentTargetAmount",
1953
2055
  value: function calculatePaymentTargetAmount(tempOrder, summary) {
1954
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 || [];
1955
2058
  var depositAmount = this.getDepositAmount(tempOrder, summary);
1956
2059
  if (!this.isDepositOrder(tempOrder, depositAmount)) {
1957
2060
  return this.getOrderExpectedAmount(summary);
1958
2061
  }
2062
+ if (this.hasPaidNormalPayment(payments)) {
2063
+ return this.getOrderExpectedAmount(summary);
2064
+ }
1959
2065
  if (this.isDepositCovered({
1960
2066
  tempOrder: tempOrder,
1961
2067
  summary: summary,
@@ -1972,7 +2078,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1972
2078
  try {
1973
2079
  var parsed = new Decimal(String(value || 0));
1974
2080
  return parsed.toFixed(4);
1975
- } catch (_unused2) {
2081
+ } catch (_unused3) {
1976
2082
  return String(value);
1977
2083
  }
1978
2084
  }
@@ -2000,7 +2106,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2000
2106
  _product$payment_pric,
2001
2107
  _sku$code,
2002
2108
  _sku$barcode,
2003
- _ref20,
2109
+ _ref19,
2004
2110
  _sku$variant_id,
2005
2111
  _this11 = this;
2006
2112
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
@@ -2027,24 +2133,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2027
2133
  product_sku: this.normalizeFingerprintValue({
2028
2134
  code: (_sku$code = sku.code) !== null && _sku$code !== void 0 ? _sku$code : '',
2029
2135
  barcode: (_sku$barcode = sku.barcode) !== null && _sku$barcode !== void 0 ? _sku$barcode : '',
2030
- variant_id: (_ref20 = (_sku$variant_id = sku.variant_id) !== null && _sku$variant_id !== void 0 ? _sku$variant_id : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref20 !== void 0 ? _ref20 : 0,
2136
+ variant_id: (_ref19 = (_sku$variant_id = sku.variant_id) !== null && _sku$variant_id !== void 0 ? _sku$variant_id : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref19 !== void 0 ? _ref19 : 0,
2031
2137
  variant: sku.variant || [],
2032
2138
  option: getProductSkuOptions(product || {}).map(function (option) {
2033
- var _ref21, _option$id, _option$option_group_, _ref22, _option$option_group_2, _option$num, _option$add_price;
2139
+ var _ref20, _option$id, _option$option_group_, _ref21, _option$option_group_2, _option$num, _option$add_price;
2034
2140
  return {
2035
- id: (_ref21 = (_option$id = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id !== void 0 ? _option$id : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref21 !== void 0 ? _ref21 : null,
2141
+ id: (_ref20 = (_option$id = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id !== void 0 ? _option$id : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref20 !== void 0 ? _ref20 : null,
2036
2142
  option_group_id: (_option$option_group_ = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : null,
2037
- option_group_item_id: (_ref22 = (_option$option_group_2 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref22 !== void 0 ? _ref22 : null,
2143
+ option_group_item_id: (_ref21 = (_option$option_group_2 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref21 !== void 0 ? _ref21 : null,
2038
2144
  num: Number((_option$num = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num !== void 0 ? _option$num : 1) || 1,
2039
2145
  add_price: _this11.normalizeFingerprintMoney((_option$add_price = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price !== void 0 ? _option$add_price : option === null || option === void 0 ? void 0 : option.price)
2040
2146
  };
2041
2147
  })
2042
2148
  }),
2043
2149
  product_bundle: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.product_bundle) || []).map(function (bundle) {
2044
- var _ref23, _ref24, _bundle$bundle_produc, _ref25, _bundle$bundle_varian, _bundle$num, _bundle$price_type, _bundle$price_type_ex;
2150
+ var _ref22, _ref23, _bundle$bundle_produc, _ref24, _bundle$bundle_varian, _bundle$num, _bundle$price_type, _bundle$price_type_ex;
2045
2151
  return {
2046
- bundle_product_id: (_ref23 = (_ref24 = (_bundle$bundle_produc = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref24 !== void 0 ? _ref24 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref23 !== void 0 ? _ref23 : null,
2047
- bundle_variant_id: (_ref25 = (_bundle$bundle_varian = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref25 !== void 0 ? _ref25 : 0,
2152
+ bundle_product_id: (_ref22 = (_ref23 = (_bundle$bundle_produc = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref23 !== void 0 ? _ref23 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref22 !== void 0 ? _ref22 : null,
2153
+ bundle_variant_id: (_ref24 = (_bundle$bundle_varian = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref24 !== void 0 ? _ref24 : 0,
2048
2154
  num: getSafeProductNum((_bundle$num = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle === null || bundle === void 0 ? void 0 : bundle.quantity),
2049
2155
  price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
2050
2156
  bundle_selling_price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
@@ -2053,10 +2159,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2053
2159
  };
2054
2160
  })),
2055
2161
  discount_list: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
2056
- var _ref26, _discount$type2, _ref27, _ref28, _discount$discount_id, _discount$discount;
2162
+ var _ref25, _discount$type2, _ref26, _ref27, _discount$discount_id, _discount$discount;
2057
2163
  return {
2058
- type: (_ref26 = (_discount$type2 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type2 !== void 0 ? _discount$type2 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref26 !== void 0 ? _ref26 : '',
2059
- discount_id: (_ref27 = (_ref28 = (_discount$discount_id = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id !== void 0 ? _discount$discount_id : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref28 !== void 0 ? _ref28 : discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _ref27 !== void 0 ? _ref27 : null,
2164
+ type: (_ref25 = (_discount$type2 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type2 !== void 0 ? _discount$type2 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref25 !== void 0 ? _ref25 : '',
2165
+ discount_id: (_ref26 = (_ref27 = (_discount$discount_id = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id !== void 0 ? _discount$discount_id : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref27 !== void 0 ? _ref27 : discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _ref26 !== void 0 ? _ref26 : null,
2060
2166
  amount: _this11.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2061
2167
  };
2062
2168
  }))
@@ -2080,14 +2186,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2080
2186
  var _product$product_id3,
2081
2187
  _product$product_vari2,
2082
2188
  _product$num2,
2083
- _ref29,
2189
+ _ref28,
2084
2190
  _metadata$unique_iden,
2085
2191
  _metadata$price_overr,
2086
2192
  _metadata$is_manual_d,
2087
2193
  _metadata$product_dis,
2088
2194
  _sku$code2,
2089
2195
  _sku$barcode2,
2090
- _ref30,
2196
+ _ref29,
2091
2197
  _sku$variant_id2,
2092
2198
  _this13 = this;
2093
2199
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
@@ -2103,7 +2209,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2103
2209
  extension_type: extensionType,
2104
2210
  num: getSafeProductNum((_product$num2 = product === null || product === void 0 ? void 0 : product.num) !== null && _product$num2 !== void 0 ? _product$num2 : product === null || product === void 0 ? void 0 : product.product_quantity),
2105
2211
  metadata: {
2106
- unique_identification_number: (_ref29 = (_metadata$unique_iden = metadata.unique_identification_number) !== null && _metadata$unique_iden !== void 0 ? _metadata$unique_iden : product === null || product === void 0 ? void 0 : product.unique_identification_number) !== null && _ref29 !== void 0 ? _ref29 : '',
2212
+ unique_identification_number: (_ref28 = (_metadata$unique_iden = metadata.unique_identification_number) !== null && _metadata$unique_iden !== void 0 ? _metadata$unique_iden : product === null || product === void 0 ? void 0 : product.unique_identification_number) !== null && _ref28 !== void 0 ? _ref28 : '',
2107
2213
  price_override: (_metadata$price_overr = metadata.price_override) !== null && _metadata$price_overr !== void 0 ? _metadata$price_overr : '',
2108
2214
  is_manual_discount: (_metadata$is_manual_d = metadata.is_manual_discount) !== null && _metadata$is_manual_d !== void 0 ? _metadata$is_manual_d : '',
2109
2215
  product_discount_reason: (_metadata$product_dis = metadata.product_discount_reason) !== null && _metadata$product_dis !== void 0 ? _metadata$product_dis : ''
@@ -2111,35 +2217,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2111
2217
  product_sku: this.normalizeFingerprintValue({
2112
2218
  code: (_sku$code2 = sku.code) !== null && _sku$code2 !== void 0 ? _sku$code2 : '',
2113
2219
  barcode: (_sku$barcode2 = sku.barcode) !== null && _sku$barcode2 !== void 0 ? _sku$barcode2 : '',
2114
- variant_id: (_ref30 = (_sku$variant_id2 = sku.variant_id) !== null && _sku$variant_id2 !== void 0 ? _sku$variant_id2 : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref30 !== void 0 ? _ref30 : 0,
2220
+ variant_id: (_ref29 = (_sku$variant_id2 = sku.variant_id) !== null && _sku$variant_id2 !== void 0 ? _sku$variant_id2 : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref29 !== void 0 ? _ref29 : 0,
2115
2221
  variant: sku.variant || [],
2116
2222
  option: getProductSkuOptions(product || {}).map(function (option) {
2117
- var _ref31, _option$id2, _option$option_group_3, _ref32, _option$option_group_4, _option$num2, _option$add_price2;
2223
+ var _ref30, _option$id2, _option$option_group_3, _ref31, _option$option_group_4, _option$num2, _option$add_price2;
2118
2224
  return {
2119
- id: (_ref31 = (_option$id2 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id2 !== void 0 ? _option$id2 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref31 !== void 0 ? _ref31 : null,
2225
+ id: (_ref30 = (_option$id2 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id2 !== void 0 ? _option$id2 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref30 !== void 0 ? _ref30 : null,
2120
2226
  option_group_id: (_option$option_group_3 = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_3 !== void 0 ? _option$option_group_3 : null,
2121
- option_group_item_id: (_ref32 = (_option$option_group_4 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_4 !== void 0 ? _option$option_group_4 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref32 !== void 0 ? _ref32 : null,
2227
+ option_group_item_id: (_ref31 = (_option$option_group_4 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_4 !== void 0 ? _option$option_group_4 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref31 !== void 0 ? _ref31 : null,
2122
2228
  num: Number((_option$num2 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1) || 1,
2123
2229
  add_price: _this13.normalizeFingerprintMoney((_option$add_price2 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price2 !== void 0 ? _option$add_price2 : option === null || option === void 0 ? void 0 : option.price)
2124
2230
  };
2125
2231
  })
2126
2232
  }),
2127
2233
  product_bundle: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.product_bundle) || []).map(function (bundle) {
2128
- var _ref33, _bundle$bundle_id, _ref34, _bundle$bundle_group_, _ref35, _ref36, _bundle$bundle_produc2, _ref37, _bundle$bundle_varian2, _bundle$num2, _bundle$price_type2, _bundle$price_type_ex2;
2234
+ var _ref32, _bundle$bundle_id, _ref33, _bundle$bundle_group_, _ref34, _ref35, _bundle$bundle_produc2, _ref36, _bundle$bundle_varian2, _bundle$num2, _bundle$price_type2, _bundle$price_type_ex2;
2129
2235
  return {
2130
- bundle_id: (_ref33 = (_bundle$bundle_id = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle === null || bundle === void 0 ? void 0 : bundle.id) !== null && _ref33 !== void 0 ? _ref33 : null,
2131
- bundle_group_id: (_ref34 = (_bundle$bundle_group_ = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle === null || bundle === void 0 ? void 0 : bundle.group_id) !== null && _ref34 !== void 0 ? _ref34 : null,
2132
- bundle_product_id: (_ref35 = (_ref36 = (_bundle$bundle_produc2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref36 !== void 0 ? _ref36 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref35 !== void 0 ? _ref35 : null,
2133
- bundle_variant_id: (_ref37 = (_bundle$bundle_varian2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian2 !== void 0 ? _bundle$bundle_varian2 : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref37 !== void 0 ? _ref37 : 0,
2236
+ bundle_id: (_ref32 = (_bundle$bundle_id = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle === null || bundle === void 0 ? void 0 : bundle.id) !== null && _ref32 !== void 0 ? _ref32 : null,
2237
+ bundle_group_id: (_ref33 = (_bundle$bundle_group_ = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle === null || bundle === void 0 ? void 0 : bundle.group_id) !== null && _ref33 !== void 0 ? _ref33 : null,
2238
+ bundle_product_id: (_ref34 = (_ref35 = (_bundle$bundle_produc2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref35 !== void 0 ? _ref35 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref34 !== void 0 ? _ref34 : null,
2239
+ bundle_variant_id: (_ref36 = (_bundle$bundle_varian2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian2 !== void 0 ? _bundle$bundle_varian2 : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref36 !== void 0 ? _ref36 : 0,
2134
2240
  num: getSafeProductNum((_bundle$num2 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num2 !== void 0 ? _bundle$num2 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity),
2135
2241
  price_type: (_bundle$price_type2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type2 !== void 0 ? _bundle$price_type2 : '',
2136
2242
  price_type_ext: (_bundle$price_type_ex2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type_ext) !== null && _bundle$price_type_ex2 !== void 0 ? _bundle$price_type_ex2 : '',
2137
2243
  option: _this13.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2138
- var _ref38, _option$id3, _option$option_group_5, _ref39, _option$option_group_6, _option$num3, _option$add_price3;
2244
+ var _ref37, _option$id3, _option$option_group_5, _ref38, _option$option_group_6, _option$num3, _option$add_price3;
2139
2245
  return {
2140
- id: (_ref38 = (_option$id3 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id3 !== void 0 ? _option$id3 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref38 !== void 0 ? _ref38 : null,
2246
+ id: (_ref37 = (_option$id3 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id3 !== void 0 ? _option$id3 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref37 !== void 0 ? _ref37 : null,
2141
2247
  option_group_id: (_option$option_group_5 = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_5 !== void 0 ? _option$option_group_5 : null,
2142
- option_group_item_id: (_ref39 = (_option$option_group_6 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_6 !== void 0 ? _option$option_group_6 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref39 !== void 0 ? _ref39 : null,
2248
+ option_group_item_id: (_ref38 = (_option$option_group_6 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_6 !== void 0 ? _option$option_group_6 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref38 !== void 0 ? _ref38 : null,
2143
2249
  num: Number((_option$num3 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num3 !== void 0 ? _option$num3 : 1) || 1,
2144
2250
  add_price: _this13.normalizeFingerprintMoney((_option$add_price3 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price3 !== void 0 ? _option$add_price3 : option === null || option === void 0 ? void 0 : option.price)
2145
2251
  };
@@ -2147,10 +2253,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2147
2253
  };
2148
2254
  })),
2149
2255
  discount_list: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
2150
- var _ref40, _discount$type4, _ref41, _ref42, _discount$discount_id2, _discount$discount2;
2256
+ var _ref39, _discount$type4, _ref40, _ref41, _discount$discount_id2, _discount$discount2;
2151
2257
  return {
2152
- type: (_ref40 = (_discount$type4 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type4 !== void 0 ? _discount$type4 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref40 !== void 0 ? _ref40 : '',
2153
- discount_id: (_ref41 = (_ref42 = (_discount$discount_id2 = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id2 !== void 0 ? _discount$discount_id2 : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref42 !== void 0 ? _ref42 : discount === null || discount === void 0 || (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) !== null && _ref41 !== void 0 ? _ref41 : null,
2258
+ type: (_ref39 = (_discount$type4 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type4 !== void 0 ? _discount$type4 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref39 !== void 0 ? _ref39 : '',
2259
+ discount_id: (_ref40 = (_ref41 = (_discount$discount_id2 = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id2 !== void 0 ? _discount$discount_id2 : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref41 !== void 0 ? _ref41 : discount === null || discount === void 0 || (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) !== null && _ref40 !== void 0 ? _ref40 : null,
2154
2260
  amount: _this13.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2155
2261
  };
2156
2262
  }))
@@ -2208,17 +2314,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2208
2314
  }, {
2209
2315
  key: "isSnapshotPayableAmountUnchanged",
2210
2316
  value: function isSnapshotPayableAmountUnchanged(tempOrder, snapshot, snapshotSummary) {
2211
- var currentPaidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
2317
+ var currentPayments = tempOrder.payments || [];
2318
+ var currentPaidPaymentSummary = this.calculatePaidPaymentSummary(currentPayments);
2212
2319
  var currentAmountGap = this.calculateSummaryAmountGap({
2213
2320
  tempOrder: tempOrder,
2214
2321
  summary: snapshotSummary,
2215
- orderPaidAmount: currentPaidPaymentSummary.gapPaidAmount
2322
+ orderPaidAmount: currentPaidPaymentSummary.gapPaidAmount,
2323
+ payments: currentPayments
2216
2324
  });
2217
- 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);
2218
2327
  var snapshotAmountGap = this.calculateSummaryAmountGap({
2219
2328
  tempOrder: tempOrder,
2220
2329
  summary: snapshotSummary,
2221
- orderPaidAmount: snapshotPaidPaymentSummary.gapPaidAmount
2330
+ orderPaidAmount: snapshotPaidPaymentSummary.gapPaidAmount,
2331
+ payments: snapshotPayments
2222
2332
  });
2223
2333
  return currentAmountGap === snapshotAmountGap;
2224
2334
  }
@@ -2252,6 +2362,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2252
2362
  }
2253
2363
  var isPayableAmountUnchanged = this.isSnapshotPayableAmountUnchanged(tempOrder, snapshot, summary);
2254
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
+ });
2255
2371
  if (Array.isArray(snapshot.products)) {
2256
2372
  tempOrder.products = cloneDeep(snapshot.products);
2257
2373
  }
@@ -2378,7 +2494,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2378
2494
  }, {
2379
2495
  key: "restoreOrder",
2380
2496
  value: function restoreOrder() {
2381
- var _this$store$discount16, _this$store$discount17;
2497
+ var _this$store$discount18, _this$store$discount19;
2382
2498
  this.logInfo('restoreOrder start', {});
2383
2499
  this.sessionStorageRestoreRecord = null;
2384
2500
  var freshTempOrder = this.createDefaultTempOrderInstance();
@@ -2387,8 +2503,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2387
2503
  this.store.summary = createEmptySummary();
2388
2504
  this.store.lastOrderInfo = undefined;
2389
2505
  this.store.syncState = undefined;
2390
- void ((_this$store$discount16 = this.store.discount) === null || _this$store$discount16 === void 0 ? void 0 : _this$store$discount16.setOriginalDiscountList([]));
2391
- 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([]));
2392
2508
  this.persistTempOrder();
2393
2509
  return freshTempOrder;
2394
2510
  }
@@ -2455,11 +2571,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2455
2571
  }, {
2456
2572
  key: "getOrderIdentity",
2457
2573
  value: function getOrderIdentity() {
2458
- var _ref43, _ref44, _tempOrder$order_id, _tempOrder$_extend6;
2574
+ var _ref42, _ref43, _tempOrder$order_id, _tempOrder$_extend6;
2459
2575
  var tempOrder = this.store.tempOrder;
2460
2576
  if (!tempOrder) return null;
2461
2577
  var lastOrderInfo = this.store.lastOrderInfo || {};
2462
- var orderId = (_ref43 = (_ref44 = (_tempOrder$order_id = tempOrder.order_id) !== null && _tempOrder$order_id !== void 0 ? _tempOrder$order_id : lastOrderInfo.order_id) !== null && _ref44 !== void 0 ? _ref44 : lastOrderInfo.id) !== null && _ref43 !== void 0 ? _ref43 : null;
2578
+ var orderId = (_ref42 = (_ref43 = (_tempOrder$order_id = tempOrder.order_id) !== null && _tempOrder$order_id !== void 0 ? _tempOrder$order_id : lastOrderInfo.order_id) !== null && _ref43 !== void 0 ? _ref43 : lastOrderInfo.id) !== null && _ref42 !== void 0 ? _ref42 : null;
2463
2579
  return {
2464
2580
  localId: this.cacheId || ((_tempOrder$_extend6 = tempOrder._extend) === null || _tempOrder$_extend6 === void 0 ? void 0 : _tempOrder$_extend6.localId),
2465
2581
  orderId: orderId,
@@ -2593,8 +2709,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2593
2709
  value: function sanitizeTempOrderProducts(tempOrder) {
2594
2710
  var _this15 = this;
2595
2711
  tempOrder.products = (tempOrder.products || []).map(function (product) {
2596
- return _this15.sanitizeOrderProductForTempOrder(product);
2712
+ return _this15.sanitizeOrderProductForTempOrder(_this15.normalizeVirtualSettlementProductIfEnabled(product));
2597
2713
  });
2714
+ this.syncTempOrderSettlementState(tempOrder);
2715
+ ensureUniqueProductLineUids(tempOrder);
2598
2716
  }
2599
2717
  }, {
2600
2718
  key: "ensureExtend",
@@ -2627,11 +2745,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2627
2745
  }, {
2628
2746
  key: "captureProductRuntime",
2629
2747
  value: function captureProductRuntime(tempOrder, rawProduct, normalizedProduct, existedUid) {
2630
- var _extend$productsByUid, _ref45, _rawProduct$_origin;
2748
+ var _extend$productsByUid, _ref44, _rawProduct$_origin;
2631
2749
  var uid = existedUid || this.getProductUid(normalizedProduct);
2632
2750
  var extend = this.ensureExtend(tempOrder);
2633
2751
  var existed = ((_extend$productsByUid = extend.productsByUid) === null || _extend$productsByUid === void 0 ? void 0 : _extend$productsByUid[uid]) || {};
2634
- var origin = (_ref45 = (_rawProduct$_origin = rawProduct._origin) !== null && _rawProduct$_origin !== void 0 ? _rawProduct$_origin : normalizedProduct._origin) !== null && _ref45 !== void 0 ? _ref45 : existed.origin;
2752
+ var origin = (_ref44 = (_rawProduct$_origin = rawProduct._origin) !== null && _rawProduct$_origin !== void 0 ? _rawProduct$_origin : normalizedProduct._origin) !== null && _ref44 !== void 0 ? _ref44 : existed.origin;
2635
2753
  extend.productsByUid[uid] = _objectSpread(_objectSpread({}, existed), origin !== undefined ? {
2636
2754
  origin: origin
2637
2755
  } : {});
@@ -2730,10 +2848,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2730
2848
  }
2731
2849
  });
2732
2850
  products.forEach(function (product) {
2733
- var _product$metadata5, _product$metadata6;
2851
+ var _product$metadata3, _product$metadata4;
2734
2852
  if (!product || _typeof(product) !== 'object') return;
2735
- var productUid = ((_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number) || product.unique_identification_number;
2736
- var bookingUid = product.booking_uid || ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
2853
+ var productUid = ((_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.unique_identification_number) || product.unique_identification_number;
2854
+ var bookingUid = product.booking_uid || ((_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.booking_uid);
2737
2855
  var linkedBooking = (productUid !== undefined && productUid !== null && String(productUid) !== '' ? bookingByProductUid.get(String(productUid)) : undefined) || (bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '' ? bookingByBookingUid.get(String(bookingUid)) : undefined);
2738
2856
  if (linkedBooking) {
2739
2857
  _this16.setProductHolderFromBooking(product, linkedBooking);
@@ -2774,7 +2892,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2774
2892
  }, {
2775
2893
  key: "buildTempOrderHolderFromBookings",
2776
2894
  value: function buildTempOrderHolderFromBookings(tempOrder) {
2777
- var _baseHolder$customer_, _baseHolder, _ref46, _baseHolder$form_id, _baseHolder2, _tempOrder$holder2, _baseHolder3, _this$otherParams;
2895
+ var _baseHolder$customer_, _baseHolder, _ref45, _baseHolder$form_id, _baseHolder2, _tempOrder$holder2, _baseHolder3, _this$otherParams;
2778
2896
  var holderRecords = [];
2779
2897
  var holderNames = [];
2780
2898
  var baseHolder = null;
@@ -2821,7 +2939,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2821
2939
  }
2822
2940
  var nextHolder = {
2823
2941
  customer_id: (_baseHolder$customer_ = (_baseHolder = baseHolder) === null || _baseHolder === void 0 ? void 0 : _baseHolder.customer_id) !== null && _baseHolder$customer_ !== void 0 ? _baseHolder$customer_ : tempOrder.customer_id,
2824
- form_id: (_ref46 = (_baseHolder$form_id = (_baseHolder2 = baseHolder) === null || _baseHolder2 === void 0 ? void 0 : _baseHolder2.form_id) !== null && _baseHolder$form_id !== void 0 ? _baseHolder$form_id : (_tempOrder$holder2 = tempOrder.holder) === null || _tempOrder$holder2 === void 0 ? void 0 : _tempOrder$holder2.form_id) !== null && _ref46 !== void 0 ? _ref46 : 0,
2942
+ form_id: (_ref45 = (_baseHolder$form_id = (_baseHolder2 = baseHolder) === null || _baseHolder2 === void 0 ? void 0 : _baseHolder2.form_id) !== null && _baseHolder$form_id !== void 0 ? _baseHolder$form_id : (_tempOrder$holder2 = tempOrder.holder) === null || _tempOrder$holder2 === void 0 ? void 0 : _tempOrder$holder2.form_id) !== null && _ref45 !== void 0 ? _ref45 : 0,
2825
2943
  form_record: holderRecords
2826
2944
  };
2827
2945
  if (holderNames.length) {
@@ -2872,11 +2990,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2872
2990
  }, {
2873
2991
  key: "removeLinkedBookingsForProduct",
2874
2992
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
2875
- var _product$metadata7,
2876
- _product$metadata8,
2993
+ var _product$metadata5,
2994
+ _product$metadata6,
2877
2995
  _this18 = this;
2878
- var productUid = (product === null || product === void 0 || (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
2879
- var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.booking_uid);
2996
+ var productUid = (product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
2997
+ var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
2880
2998
  if (!productUid && !bookingUid) return;
2881
2999
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
2882
3000
  var currentBookingUid = _this18.getBookingUniqueIdentificationNumber(booking);
@@ -2926,7 +3044,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2926
3044
  key: "recalculateSummary",
2927
3045
  value: function () {
2928
3046
  var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(options) {
2929
- var _this$otherParams2, _ref47, _salesSummaryResult$e;
3047
+ var _this$otherParams2, _ref46, _salesSummaryResult$e;
2930
3048
  var tempOrder, originalSnapshot, hasShopDiscountChanged, shouldReuseOriginalSnapshot, snapshotSummary, shouldFullRecalculateFromSnapshot, summaryProducts, salesSummary, existedSummary, totalRefundAmount, paidPaymentSummary, emptyBaseSummary, emptySummaryBase, emptySummaryWithDeposit, emptySummary, salesSummaryResult, roundingAmount, payServiceChargeAmount, hasSalesSummaryAmount, expectAmount, amountPaymentPatch, normalizedExpectAmountPatch, summaryForGap, summary;
2931
3049
  return _regeneratorRuntime().wrap(function _callee12$(_context14) {
2932
3050
  while (1) switch (_context14.prev = _context14.next) {
@@ -2991,7 +3109,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2991
3109
  return salesSummary.getSummary(_objectSpread({
2992
3110
  products: summaryProducts,
2993
3111
  isPriceIncludeTax: tempOrder.is_price_include_tax,
2994
- shopDiscount: tempOrder.shop_discount
3112
+ shopDiscount: tempOrder.shop_discount,
3113
+ virtualSettlementMode: this.shouldUseVirtualSettlementSummary(tempOrder)
2995
3114
  }, (_this$otherParams2 = this.otherParams) !== null && _this$otherParams2 !== void 0 && _this$otherParams2.channel ? {
2996
3115
  channel: this.otherParams.channel
2997
3116
  } : {}));
@@ -3004,7 +3123,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3004
3123
  roundingAmount = paidPaymentSummary.roundingAmount;
3005
3124
  payServiceChargeAmount = paidPaymentSummary.payServiceChargeAmount;
3006
3125
  hasSalesSummaryAmount = salesSummaryResult.expect_amount !== undefined || salesSummaryResult.total_amount !== undefined;
3007
- expectAmount = hasSalesSummaryAmount ? new Decimal((_ref47 = (_salesSummaryResult$e = salesSummaryResult.expect_amount) !== null && _salesSummaryResult$e !== void 0 ? _salesSummaryResult$e : salesSummaryResult.total_amount) !== null && _ref47 !== void 0 ? _ref47 : 0) : null;
3126
+ expectAmount = hasSalesSummaryAmount ? new Decimal((_ref46 = (_salesSummaryResult$e = salesSummaryResult.expect_amount) !== null && _salesSummaryResult$e !== void 0 ? _salesSummaryResult$e : salesSummaryResult.total_amount) !== null && _ref46 !== void 0 ? _ref46 : 0) : null;
3008
3127
  amountPaymentPatch = hasSalesSummaryAmount || !roundingAmount.eq(0) || !payServiceChargeAmount.eq(0) ? _objectSpread({
3009
3128
  rounding_amount: roundingAmount.toFixed(2)
3010
3129
  }, expectAmount ? {
@@ -3182,17 +3301,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3182
3301
  }, {
3183
3302
  key: "buildTempOrderCustomer",
3184
3303
  value: function buildTempOrderCustomer(params) {
3185
- var _ref48, _ref49, _ref50, _source$name, _ref51, _ref52, _ref53, _source$customer_name, _source$id, _source$customer_id, _ref54, _source$country_calli, _source$phone, _source$email;
3304
+ var _ref47, _ref48, _ref49, _source$name, _ref50, _ref51, _ref52, _source$customer_name, _source$id, _source$customer_id, _ref53, _source$country_calli, _source$phone, _source$email;
3186
3305
  if (!params.customerId) return null;
3187
3306
  var source = params.source ? cloneDeep(params.source) : {};
3188
- var name = (_ref48 = (_ref49 = (_ref50 = (_source$name = source.name) !== null && _source$name !== void 0 ? _source$name : source.display_name) !== null && _ref50 !== void 0 ? _ref50 : source.customerName) !== null && _ref49 !== void 0 ? _ref49 : source.customer_name) !== null && _ref48 !== void 0 ? _ref48 : params.customerName;
3189
- var customerName = (_ref51 = (_ref52 = (_ref53 = (_source$customer_name = source.customer_name) !== null && _source$customer_name !== void 0 ? _source$customer_name : source.customerName) !== null && _ref53 !== void 0 ? _ref53 : source.display_name) !== null && _ref52 !== void 0 ? _ref52 : source.name) !== null && _ref51 !== void 0 ? _ref51 : params.customerName;
3307
+ var name = (_ref47 = (_ref48 = (_ref49 = (_source$name = source.name) !== null && _source$name !== void 0 ? _source$name : source.display_name) !== null && _ref49 !== void 0 ? _ref49 : source.customerName) !== null && _ref48 !== void 0 ? _ref48 : source.customer_name) !== null && _ref47 !== void 0 ? _ref47 : params.customerName;
3308
+ var customerName = (_ref50 = (_ref51 = (_ref52 = (_source$customer_name = source.customer_name) !== null && _source$customer_name !== void 0 ? _source$customer_name : source.customerName) !== null && _ref52 !== void 0 ? _ref52 : source.display_name) !== null && _ref51 !== void 0 ? _ref51 : source.name) !== null && _ref50 !== void 0 ? _ref50 : params.customerName;
3190
3309
  return _objectSpread(_objectSpread({}, source), {}, {
3191
3310
  id: (_source$id = source.id) !== null && _source$id !== void 0 ? _source$id : params.customerId,
3192
3311
  customer_id: (_source$customer_id = source.customer_id) !== null && _source$customer_id !== void 0 ? _source$customer_id : params.customerId,
3193
3312
  name: String(name || ''),
3194
3313
  customer_name: String(customerName || ''),
3195
- country_calling_code: String((_ref54 = (_source$country_calli = source.country_calling_code) !== null && _source$country_calli !== void 0 ? _source$country_calli : source.countryCallingCode) !== null && _ref54 !== void 0 ? _ref54 : params.countryCallingCode),
3314
+ country_calling_code: String((_ref53 = (_source$country_calli = source.country_calling_code) !== null && _source$country_calli !== void 0 ? _source$country_calli : source.countryCallingCode) !== null && _ref53 !== void 0 ? _ref53 : params.countryCallingCode),
3196
3315
  phone: String((_source$phone = source.phone) !== null && _source$phone !== void 0 ? _source$phone : params.phone),
3197
3316
  email: String((_source$email = source.email) !== null && _source$email !== void 0 ? _source$email : params.email)
3198
3317
  });
@@ -3227,11 +3346,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3227
3346
  }, {
3228
3347
  key: "shouldSkipDiscountCalculation",
3229
3348
  value: function shouldSkipDiscountCalculation(tempOrder) {
3230
- var _this$store$discount18,
3231
- _this$store$discount19,
3349
+ var _this$store$discount20,
3350
+ _this$store$discount21,
3232
3351
  _this20 = this;
3233
3352
  if (this.hasActiveCustomerBoundDiscount) return false;
3234
- 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)) || [];
3235
3354
  if (discountList.length > 0) return false;
3236
3355
  return !(tempOrder.products || []).some(function (product) {
3237
3356
  return _this20.productHasCustomerBoundDiscount(product);
@@ -3296,14 +3415,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3296
3415
  }, {
3297
3416
  key: "updateTempOrderCustomer",
3298
3417
  value: function updateTempOrderCustomer(customer) {
3299
- var _tempOrder$customer_i2, _ref55, _ref56, _customer$customer_id, _ref57, _ref58, _ref59, _customer$customer_na, _ref60, _customer$country_cal, _tempOrder$customer_i3;
3418
+ var _tempOrder$customer_i2, _ref54, _ref55, _customer$customer_id, _ref56, _ref57, _ref58, _customer$customer_na, _ref59, _customer$country_cal, _tempOrder$customer_i3;
3300
3419
  var tempOrder = this.ensureTempOrder();
3301
3420
  var previousCustomerId = (_tempOrder$customer_i2 = tempOrder.customer_id) !== null && _tempOrder$customer_i2 !== void 0 ? _tempOrder$customer_i2 : null;
3302
- var customerId = (_ref55 = (_ref56 = (_customer$customer_id = customer.customer_id) !== null && _customer$customer_id !== void 0 ? _customer$customer_id : customer.customerId) !== null && _ref56 !== void 0 ? _ref56 : customer.id) !== null && _ref55 !== void 0 ? _ref55 : null;
3303
- var customerName = (_ref57 = (_ref58 = (_ref59 = (_customer$customer_na = customer.customer_name) !== null && _customer$customer_na !== void 0 ? _customer$customer_na : customer.customerName) !== null && _ref59 !== void 0 ? _ref59 : customer.display_name) !== null && _ref58 !== void 0 ? _ref58 : customer.name) !== null && _ref57 !== void 0 ? _ref57 : '';
3421
+ var customerId = (_ref54 = (_ref55 = (_customer$customer_id = customer.customer_id) !== null && _customer$customer_id !== void 0 ? _customer$customer_id : customer.customerId) !== null && _ref55 !== void 0 ? _ref55 : customer.id) !== null && _ref54 !== void 0 ? _ref54 : null;
3422
+ var customerName = (_ref56 = (_ref57 = (_ref58 = (_customer$customer_na = customer.customer_name) !== null && _customer$customer_na !== void 0 ? _customer$customer_na : customer.customerName) !== null && _ref58 !== void 0 ? _ref58 : customer.display_name) !== null && _ref57 !== void 0 ? _ref57 : customer.name) !== null && _ref56 !== void 0 ? _ref56 : '';
3304
3423
  tempOrder.customer_id = customerId === null || customerId === undefined || customerId === '' ? null : Number(customerId);
3305
3424
  tempOrder.customer_name = String(customerName || '');
3306
- tempOrder.country_calling_code = String((_ref60 = (_customer$country_cal = customer.country_calling_code) !== null && _customer$country_cal !== void 0 ? _customer$country_cal : customer.countryCallingCode) !== null && _ref60 !== void 0 ? _ref60 : '');
3425
+ tempOrder.country_calling_code = String((_ref59 = (_customer$country_cal = customer.country_calling_code) !== null && _customer$country_cal !== void 0 ? _customer$country_cal : customer.countryCallingCode) !== null && _ref59 !== void 0 ? _ref59 : '');
3307
3426
  tempOrder.phone = String(customer.phone || '');
3308
3427
  tempOrder.email = String(customer.email || '');
3309
3428
  tempOrder.customer = this.buildTempOrderCustomer({
@@ -3353,6 +3472,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3353
3472
  var nextCustomerId = (_tempOrder$customer_i5 = tempOrder.customer_id) !== null && _tempOrder$customer_i5 !== void 0 ? _tempOrder$customer_i5 : null;
3354
3473
  if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
3355
3474
  this.store.availableWalletIds = [];
3475
+ this.store.virtualCurrencyList = [];
3356
3476
  clearTempOrderHolderAssignments(tempOrder);
3357
3477
  this.clearCustomerBoundDiscounts(tempOrder);
3358
3478
  this.applyDiscount();
@@ -3398,7 +3518,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3398
3518
  tempOrder.customer = null;
3399
3519
  if (tempOrder._extend) delete tempOrder._extend.customerSnapshot;
3400
3520
  this.store.availableWalletIds = [];
3521
+ this.store.virtualCurrencyList = [];
3401
3522
  this.clearCustomerBoundDiscounts(tempOrder);
3523
+ this.applyDiscount();
3402
3524
  this.persistTempOrder();
3403
3525
  this.saveDraftInBackground();
3404
3526
  this.core.effects.emit(OrderHooks.OnOrderCustomerChange, null);
@@ -3817,52 +3939,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3817
3939
  }
3818
3940
  return updateVoucherOrderPaymentsAsync;
3819
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
+ }
3820
3951
  }, {
3821
3952
  key: "shouldMergeProductToOrder",
3822
- value: function () {
3823
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
3824
- var _this$orderHooks;
3825
- var onBeforeMergeProductToOrder, result;
3826
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3827
- while (1) switch (_context20.prev = _context20.next) {
3828
- case 0:
3829
- onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
3830
- if (onBeforeMergeProductToOrder) {
3831
- _context20.next = 3;
3832
- break;
3833
- }
3834
- return _context20.abrupt("return", true);
3835
- case 3:
3836
- _context20.next = 5;
3837
- return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
3838
- defaultShouldMerge: true
3839
- }));
3840
- case 5:
3841
- result = _context20.sent;
3842
- if (!(typeof result === 'boolean')) {
3843
- _context20.next = 8;
3844
- break;
3845
- }
3846
- return _context20.abrupt("return", result);
3847
- case 8:
3848
- if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
3849
- _context20.next = 10;
3850
- break;
3851
- }
3852
- return _context20.abrupt("return", result.shouldMerge);
3853
- case 10:
3854
- return _context20.abrupt("return", true);
3855
- case 11:
3856
- case "end":
3857
- return _context20.stop();
3858
- }
3859
- }, _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
3860
3960
  }));
3861
- function shouldMergeProductToOrder(_x19) {
3862
- 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
+ });
3863
3965
  }
3864
- return shouldMergeProductToOrder;
3865
- }()
3966
+ return this.normalizeShouldMergeProductResult(result);
3967
+ }
3866
3968
  }, {
3867
3969
  key: "hasOrderProductLineNote",
3868
3970
  value: function hasOrderProductLineNote(product) {
@@ -3878,10 +3980,103 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3878
3980
  }, {
3879
3981
  key: "hasLinkedBookingUid",
3880
3982
  value: function hasLinkedBookingUid(product) {
3881
- var _product$booking_uid, _product$metadata9;
3882
- 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$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.booking_uid;
3983
+ var _product$booking_uid, _product$metadata7;
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;
3883
3985
  return bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '';
3884
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
+ }
3885
4080
 
3886
4081
  // ─── TempOrder: 商品 CRUD ───
3887
4082
 
@@ -3894,42 +4089,45 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3894
4089
  }, {
3895
4090
  key: "finalizeProductOrderMutation",
3896
4091
  value: function () {
3897
- var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(tempOrder, options) {
3898
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3899
- 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) {
3900
4096
  case 0:
3901
4097
  this.syncTempOrderHolderFromBookings(tempOrder);
3902
- if (options !== null && options !== void 0 && options.skipEditDiscountConfigRefresh) {
3903
- _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;
3904
4102
  break;
3905
4103
  }
3906
- _context21.next = 4;
4104
+ _context20.next = 6;
3907
4105
  return this.ensureEditDiscountConfigForProductChange(tempOrder);
3908
- case 4:
3909
- if (options !== null && options !== void 0 && options.skipDiscountRecalculation) {
3910
- _context21.next = 7;
4106
+ case 6:
4107
+ if (!(!(options !== null && options !== void 0 && options.skipDiscountRecalculation) && !isVirtualSettlement)) {
4108
+ _context20.next = 9;
3911
4109
  break;
3912
4110
  }
3913
- _context21.next = 7;
4111
+ _context20.next = 9;
3914
4112
  return this.applyPromotion();
3915
- case 7:
3916
- if (!(options !== null && options !== void 0 && options.skipDiscountRecalculation)) {
4113
+ case 9:
4114
+ if (!(options !== null && options !== void 0 && options.skipDiscountRecalculation) && !isVirtualSettlement) {
3917
4115
  this.applyDiscount();
3918
4116
  }
3919
4117
  this.sanitizeTempOrderProducts(tempOrder);
3920
- _context21.next = 11;
4118
+ _context20.next = 13;
3921
4119
  return this.recalculateSummary({
3922
4120
  createIfMissing: true
3923
4121
  });
3924
- case 11:
4122
+ case 13:
3925
4123
  this.persistTempOrder();
3926
- case 12:
4124
+ case 14:
3927
4125
  case "end":
3928
- return _context21.stop();
4126
+ return _context20.stop();
3929
4127
  }
3930
- }, _callee19, this);
4128
+ }, _callee18, this);
3931
4129
  }));
3932
- function finalizeProductOrderMutation(_x20, _x21) {
4130
+ function finalizeProductOrderMutation(_x19, _x20) {
3933
4131
  return _finalizeProductOrderMutation.apply(this, arguments);
3934
4132
  }
3935
4133
  return finalizeProductOrderMutation;
@@ -3939,136 +4137,136 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3939
4137
  * 带 booking 且 num>1 时由 `addProductToOrder` 拆成多次本方法调用(每次 num=1)。
3940
4138
  *
3941
4139
  * @example
3942
- * 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;
3943
4146
  */
3944
4147
  }, {
3945
4148
  key: "appendProductLineToTempOrder",
3946
- value: (function () {
3947
- var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(tempOrder, product, booking) {
3948
- var _booking_uid,
3949
- _metadata,
3950
- _this26 = this;
3951
- var linked, productToAdd, incomingFingerprint, normalizedIncoming, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingBookingUid, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList;
3952
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
3953
- while (1) switch (_context22.prev = _context22.next) {
3954
- case 0:
3955
- linked = booking ? this.createLinkedProductAndBooking({
3956
- product: product,
3957
- booking: booking
3958
- }) : null;
3959
- productToAdd = (linked === null || linked === void 0 ? void 0 : linked.product) || product;
3960
- incomingFingerprint = buildProductLineFingerprint(getProductSkuOptions(productToAdd), productToAdd.product_bundle);
3961
- normalizedIncoming = mergeOrderProductDisplayFields(productToAdd, normalizeOrderProduct(productToAdd));
3962
- 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;
3963
- if (incomingBookingUid !== undefined && incomingBookingUid !== null && String(incomingBookingUid) !== '') {
3964
- normalizedIncoming.booking_uid = String(incomingBookingUid);
3965
- normalizedIncoming.metadata = _objectSpread(_objectSpread({}, normalizedIncoming.metadata || {}), {}, {
3966
- booking_uid: String(incomingBookingUid)
3967
- });
3968
- }
3969
- normalizedIncoming.discount_list = normalizeOrderProductDiscountList(normalizedIncoming.discount_list);
3970
- hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
3971
- hasIncomingProductNote = this.hasOrderProductLineNote(normalizedIncoming);
3972
- hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
3973
- shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
3974
- matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
3975
- var _item$metadata3;
3976
- if (_this26.hasGoodPassDiscount(item)) return false;
3977
- if (_this26.hasOrderProductLineNote(item)) return false;
3978
- if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
3979
- if ((_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.is_edit_for_runtime) return false;
3980
- if (item.product_id !== productToAdd.product_id) return false;
3981
- if (item.product_variant_id !== productToAdd.product_variant_id) return false;
3982
- var existedFingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
3983
- return existedFingerprint === incomingFingerprint;
3984
- });
3985
- matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
3986
- existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
3987
- if (!matchedProduct) {
3988
- _context22.next = 20;
3989
- break;
3990
- }
3991
- _context22.next = 17;
3992
- return this.shouldMergeProductToOrder({
3993
- incomingProduct: productToAdd,
3994
- normalizedIncoming: normalizedIncoming,
3995
- matchedProduct: matchedProduct,
3996
- matchedIndex: matchedIndex,
3997
- incomingFingerprint: incomingFingerprint,
3998
- existedFingerprint: existedFingerprint,
3999
- tempOrder: tempOrder,
4000
- booking: booking
4001
- });
4002
- case 17:
4003
- _context22.t0 = _context22.sent;
4004
- _context22.next = 21;
4005
- break;
4006
- case 20:
4007
- _context22.t0 = false;
4008
- case 21:
4009
- shouldMerge = _context22.t0;
4010
- if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
4011
- this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
4012
- if (linked) {
4013
- normalizedIncoming.booking_uid = linked.bookingUid;
4014
- normalizedIncoming.metadata = _objectSpread(_objectSpread({}, normalizedIncoming.metadata || {}), {}, {
4015
- booking_uid: linked.bookingUid
4016
- });
4017
- }
4018
- // tempOrder.products.push(normalizedIncoming);
4019
- tempOrder.products = [].concat(_toConsumableArray(tempOrder.products), [normalizedIncoming]);
4020
- } else {
4021
- targetProduct = matchedProduct;
4022
- targetUid = (_targetProduct$metada = targetProduct.metadata) === null || _targetProduct$metada === void 0 ? void 0 : _targetProduct$metada.unique_identification_number;
4023
- normalizedProduct = mergeOrderProductDisplayFields(targetProduct, normalizeOrderProduct(_objectSpread(_objectSpread({}, productToAdd), {}, {
4024
- metadata: _objectSpread(_objectSpread({}, productToAdd.metadata || {}), {}, {
4025
- unique_identification_number: targetUid
4026
- })
4027
- })));
4028
- normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4029
- nextNum = getSafeProductNum(targetProduct.num + normalizedProduct.num);
4030
- targetIsManualProductDiscount = isManualProductDiscountProduct(targetProduct);
4031
- nextDiscountList = targetIsManualProductDiscount ? normalizeOrderProductDiscountList(syncManualProductDiscountProductNum(targetProduct.discount_list, nextNum)) : normalizedProduct.discount_list;
4032
- tempOrder.products[matchedIndex] = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, targetProduct), normalizedProduct), {}, {
4033
- discount_list: nextDiscountList,
4034
- metadata: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.metadata || {}), normalizedProduct.metadata || {}), {}, {
4035
- unique_identification_number: targetUid
4036
- }),
4037
- product_sku: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.product_sku || {
4038
- option: []
4039
- }), normalizedProduct.product_sku || {
4040
- option: []
4041
- }), {}, {
4042
- option: getProductSkuOptions(normalizedProduct)
4043
- })
4044
- }, targetIsManualProductDiscount ? {
4045
- selling_price: targetProduct.selling_price,
4046
- original_price: targetProduct.original_price,
4047
- payment_price: targetProduct.payment_price,
4048
- metadata: _objectSpread(_objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), targetProduct.metadata || {}), {}, {
4049
- unique_identification_number: targetUid
4050
- })
4051
- } : {}), {}, {
4052
- note: targetProduct.note,
4053
- order_detail_id: targetProduct.order_detail_id,
4054
- num: nextNum
4055
- });
4056
- this.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4057
- }
4058
- if (linked) {
4059
- tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
4060
- }
4061
- case 24:
4062
- case "end":
4063
- 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
+ });
4064
4206
  }
4065
- }, _callee20, this);
4066
- }));
4067
- function appendProductLineToTempOrder(_x22, _x23, _x24) {
4068
- 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;
4069
4253
  }
4070
- return appendProductLineToTempOrder;
4071
- }()
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
+
4072
4270
  /**
4073
4271
  * 添加商品行。带 booking 时强制独立行;num>1 时拆成多条 num=1 的 product+booking(对齐 BookingByStep / ticketBooking addService)。
4074
4272
  *
@@ -4076,65 +4274,87 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4076
4274
  * await order.addProductToOrder({ product_id: 1, num: 3 }, { start_time: '10:00' });
4077
4275
  * // → tempOrder.products 新增 3 行,每行 num=1,bookings 3 条
4078
4276
  */
4079
- )
4080
4277
  }, {
4081
4278
  key: "addProductToOrder",
4082
4279
  value: (function () {
4083
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(product, booking) {
4084
- var tempOrder, _ref61, _productRecord$num, productRecord, splitCount, i, singleLine;
4085
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4086
- 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) {
4087
4284
  case 0:
4088
4285
  tempOrder = this.ensureTempOrder();
4286
+ insertAfterProductUid = options === null || options === void 0 ? void 0 : options.insertAfterProductUid;
4287
+ anchorIndex = booking && insertAfterProductUid ? tempOrder.products.findIndex(function (line) {
4288
+ var _line$metadata;
4289
+ var uid = ((_line$metadata = line.metadata) === null || _line$metadata === void 0 ? void 0 : _line$metadata.unique_identification_number) || line.unique_identification_number;
4290
+ return uid !== undefined && uid !== null && String(uid) === String(insertAfterProductUid);
4291
+ }) : -1;
4292
+ insertAtIndex = anchorIndex >= 0 ? anchorIndex + 1 : undefined;
4089
4293
  if (!booking) {
4090
- _context23.next = 18;
4294
+ _context21.next = 24;
4091
4295
  break;
4092
4296
  }
4093
4297
  productRecord = product;
4094
- splitCount = getSafeProductNum((_ref61 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 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);
4095
4299
  if (!(splitCount > 1)) {
4096
- _context23.next = 18;
4300
+ _context21.next = 24;
4097
4301
  break;
4098
4302
  }
4099
4303
  i = 0;
4100
- case 6:
4304
+ case 9:
4101
4305
  if (!(i < splitCount)) {
4102
- _context23.next = 15;
4306
+ _context21.next = 21;
4103
4307
  break;
4104
4308
  }
4105
4309
  singleLine = cloneDeep(productRecord);
4106
4310
  singleLine.num = 1;
4107
4311
  delete singleLine.product_quantity;
4108
- _context23.next = 12;
4109
- return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
4110
- case 12:
4312
+ _appendResult = this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking), {
4313
+ insertAtIndex: insertAtIndex
4314
+ });
4315
+ if (!_appendResult) {
4316
+ _context21.next = 17;
4317
+ break;
4318
+ }
4319
+ _context21.next = 17;
4320
+ return _appendResult;
4321
+ case 17:
4322
+ if (insertAtIndex !== undefined) insertAtIndex += 1;
4323
+ case 18:
4111
4324
  i += 1;
4112
- _context23.next = 6;
4325
+ _context21.next = 9;
4113
4326
  break;
4114
- case 15:
4115
- _context23.next = 17;
4327
+ case 21:
4328
+ _context21.next = 23;
4116
4329
  return this.finalizeProductOrderMutation(tempOrder);
4117
- case 17:
4118
- return _context23.abrupt("return", tempOrder.products);
4119
- case 18:
4120
- _context23.next = 20;
4121
- return this.appendProductLineToTempOrder(tempOrder, product, booking);
4122
- case 20:
4123
- _context23.next = 22;
4330
+ case 23:
4331
+ return _context21.abrupt("return", tempOrder.products);
4332
+ case 24:
4333
+ appendResult = this.appendProductLineToTempOrder(tempOrder, product, booking, {
4334
+ insertAtIndex: insertAtIndex
4335
+ });
4336
+ if (!appendResult) {
4337
+ _context21.next = 28;
4338
+ break;
4339
+ }
4340
+ _context21.next = 28;
4341
+ return appendResult;
4342
+ case 28:
4343
+ _context21.next = 30;
4124
4344
  return this.finalizeProductOrderMutation(tempOrder);
4125
- case 22:
4345
+ case 30:
4126
4346
  this.logInfo('addProductToOrder success', {
4127
4347
  product_id: product.product_id,
4128
4348
  with_booking: !!booking
4129
4349
  });
4130
- return _context23.abrupt("return", tempOrder.products);
4131
- case 24:
4350
+ return _context21.abrupt("return", tempOrder.products);
4351
+ case 32:
4132
4352
  case "end":
4133
- return _context23.stop();
4353
+ return _context21.stop();
4134
4354
  }
4135
- }, _callee21, this);
4355
+ }, _callee19, this);
4136
4356
  }));
4137
- function addProductToOrder(_x25, _x26) {
4357
+ function addProductToOrder(_x21, _x22, _x23) {
4138
4358
  return _addProductToOrder.apply(this, arguments);
4139
4359
  }
4140
4360
  return addProductToOrder;
@@ -4152,93 +4372,103 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4152
4372
  }, {
4153
4373
  key: "addProductsToOrder",
4154
4374
  value: (function () {
4155
- var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(items, options) {
4156
- var tempOrder, _iterator20, _step20, item, product, booking, _ref62, _productRecord$num2, productRecord, splitCount, i, singleLine;
4157
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4158
- 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) {
4159
4379
  case 0:
4160
4380
  tempOrder = this.ensureTempOrder();
4161
4381
  if (!(!Array.isArray(items) || items.length === 0)) {
4162
- _context24.next = 3;
4382
+ _context22.next = 3;
4163
4383
  break;
4164
4384
  }
4165
- return _context24.abrupt("return", tempOrder.products);
4385
+ return _context22.abrupt("return", tempOrder.products);
4166
4386
  case 3:
4167
4387
  _iterator20 = _createForOfIteratorHelper(items || []);
4168
- _context24.prev = 4;
4388
+ _context22.prev = 4;
4169
4389
  _iterator20.s();
4170
4390
  case 6:
4171
4391
  if ((_step20 = _iterator20.n()).done) {
4172
- _context24.next = 30;
4392
+ _context22.next = 34;
4173
4393
  break;
4174
4394
  }
4175
4395
  item = _step20.value;
4176
4396
  product = item.product, booking = item.booking;
4177
4397
  if (product) {
4178
- _context24.next = 11;
4398
+ _context22.next = 11;
4179
4399
  break;
4180
4400
  }
4181
- return _context24.abrupt("continue", 28);
4401
+ return _context22.abrupt("continue", 32);
4182
4402
  case 11:
4183
4403
  if (!booking) {
4184
- _context24.next = 26;
4404
+ _context22.next = 28;
4185
4405
  break;
4186
4406
  }
4187
4407
  productRecord = product;
4188
- splitCount = getSafeProductNum((_ref62 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref62 !== void 0 ? _ref62 : 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);
4189
4409
  if (!(splitCount > 1)) {
4190
- _context24.next = 26;
4410
+ _context22.next = 28;
4191
4411
  break;
4192
4412
  }
4193
4413
  i = 0;
4194
4414
  case 16:
4195
4415
  if (!(i < splitCount)) {
4196
- _context24.next = 25;
4416
+ _context22.next = 27;
4197
4417
  break;
4198
4418
  }
4199
4419
  singleLine = cloneDeep(productRecord);
4200
4420
  singleLine.num = 1;
4201
4421
  delete singleLine.product_quantity;
4202
- _context24.next = 22;
4203
- return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
4204
- 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:
4205
4430
  i += 1;
4206
- _context24.next = 16;
4431
+ _context22.next = 16;
4207
4432
  break;
4208
- case 25:
4209
- return _context24.abrupt("continue", 28);
4210
- case 26:
4211
- _context24.next = 28;
4212
- return this.appendProductLineToTempOrder(tempOrder, product, booking);
4433
+ case 27:
4434
+ return _context22.abrupt("continue", 32);
4213
4435
  case 28:
4214
- _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;
4215
4445
  break;
4216
- case 30:
4217
- _context24.next = 35;
4446
+ case 34:
4447
+ _context22.next = 39;
4218
4448
  break;
4219
- case 32:
4220
- _context24.prev = 32;
4221
- _context24.t0 = _context24["catch"](4);
4222
- _iterator20.e(_context24.t0);
4223
- case 35:
4224
- _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;
4225
4455
  _iterator20.f();
4226
- return _context24.finish(35);
4227
- case 38:
4228
- _context24.next = 40;
4456
+ return _context22.finish(39);
4457
+ case 42:
4458
+ _context22.next = 44;
4229
4459
  return this.finalizeProductOrderMutation(tempOrder, options);
4230
- case 40:
4460
+ case 44:
4231
4461
  this.logInfo('addProductsToOrder success', {
4232
4462
  itemsCount: items.length
4233
4463
  });
4234
- return _context24.abrupt("return", tempOrder.products);
4235
- case 42:
4464
+ return _context22.abrupt("return", tempOrder.products);
4465
+ case 46:
4236
4466
  case "end":
4237
- return _context24.stop();
4467
+ return _context22.stop();
4238
4468
  }
4239
- }, _callee22, this, [[4, 32, 35, 38]]);
4469
+ }, _callee20, this, [[4, 36, 39, 42]]);
4240
4470
  }));
4241
- function addProductsToOrder(_x27, _x28) {
4471
+ function addProductsToOrder(_x24, _x25) {
4242
4472
  return _addProductsToOrder.apply(this, arguments);
4243
4473
  }
4244
4474
  return addProductsToOrder;
@@ -4265,24 +4495,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4265
4495
  }, {
4266
4496
  key: "getBundleRuntimeIdentity",
4267
4497
  value: function getBundleRuntimeIdentity(bundle) {
4268
- var _ref63, _bundle$bundle_id2, _ref64, _bundle$bundle_group_2, _ref65, _ref66, _bundle$bundle_produc3, _ref67, _bundle$bundle_varian3;
4498
+ var _ref64, _bundle$bundle_id2, _ref65, _bundle$bundle_group_2, _ref66, _ref67, _bundle$bundle_produc3, _ref68, _bundle$bundle_varian3;
4269
4499
  if (!bundle || _typeof(bundle) !== 'object') return '';
4270
- return [(_ref63 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref63 !== void 0 ? _ref63 : '', (_ref64 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref64 !== void 0 ? _ref64 : '', (_ref65 = (_ref66 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref66 !== void 0 ? _ref66 : bundle.product_id) !== null && _ref65 !== void 0 ? _ref65 : '', (_ref67 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref67 !== void 0 ? _ref67 : 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('|');
4271
4501
  }
4272
4502
  }, {
4273
4503
  key: "preservePersistedBundlePriceFields",
4274
4504
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
4275
- var _this27 = this;
4505
+ var _this28 = this;
4276
4506
  if (!Array.isArray(nextBundles)) return nextBundles;
4277
4507
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
4278
4508
  var previousByIdentity = new Map();
4279
4509
  previousBundles.forEach(function (bundle) {
4280
- var identity = _this27.getBundleRuntimeIdentity(bundle);
4510
+ var identity = _this28.getBundleRuntimeIdentity(bundle);
4281
4511
  if (identity) previousByIdentity.set(identity, bundle);
4282
4512
  });
4283
4513
  return nextBundles.map(function (bundle, index) {
4284
4514
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
4285
- var previous = previousByIdentity.get(_this27.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4515
+ var previous = previousByIdentity.get(_this28.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4286
4516
  if (!previous || _typeof(previous) !== 'object') return bundle;
4287
4517
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), (bundle.cover === undefined || bundle.cover === null || bundle.cover === '') && previous.cover !== undefined && previous.cover !== null && previous.cover !== '' ? {
4288
4518
  cover: previous.cover
@@ -4418,13 +4648,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4418
4648
  delete nextProduct.metadata.main_product_original_price;
4419
4649
  delete nextProduct.metadata.price_schema_version;
4420
4650
  } else if (callerChangesLineConfiguration && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
4421
- var _ref68, _targetProduct$metada10, _targetProduct$metada11, _ref69, _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
4651
+ var _ref69, _targetProduct$metada10, _targetProduct$metada11, _ref70, _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
4422
4652
  // 仅 option / bundle 变化时,保留历史 source 和主商品折扣金额,
4423
4653
  // 但必须让 original 与 selling 一起随新的 option 金额移动。
4424
4654
  var previousOptionSum = sumOptionUnitPrice(getProductSkuOptions(targetProduct));
4425
4655
  var nextOptionSum = sumOptionUnitPrice(getProductSkuOptions(nextProduct));
4426
- var _previousMainOriginal = new Decimal(Number((_ref68 = (_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 && _ref68 !== void 0 ? _ref68 : 0) || 0);
4427
- var _previousMainSelling = new Decimal(Number((_ref69 = (_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 && _ref69 !== void 0 ? _ref69 : _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);
4428
4658
  var _preservedDiscount = _previousMainOriginal.minus(_previousMainSelling);
4429
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);
4430
4660
  var _nextMainOriginal = previousSource.plus(nextOptionSum);
@@ -4444,7 +4674,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4444
4674
  }
4445
4675
  // normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
4446
4676
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
4447
- var normalizedProduct = mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct));
4677
+ var normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct)));
4448
4678
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4449
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);
4450
4680
  if (!booking && preservedBookingUid) {
@@ -4483,21 +4713,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4483
4713
  }, {
4484
4714
  key: "updateOrderProduct",
4485
4715
  value: function () {
4486
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
4716
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
4487
4717
  var tempOrder, updatedProductUid;
4488
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4489
- while (1) switch (_context25.prev = _context25.next) {
4718
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4719
+ while (1) switch (_context23.prev = _context23.next) {
4490
4720
  case 0:
4491
4721
  tempOrder = this.ensureTempOrder();
4492
4722
  updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
4493
- _context25.next = 4;
4723
+ _context23.next = 4;
4494
4724
  return this.applyPromotion();
4495
4725
  case 4:
4496
4726
  this.applyDiscount({
4497
4727
  reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
4498
4728
  });
4499
4729
  this.sanitizeTempOrderProducts(tempOrder);
4500
- _context25.next = 8;
4730
+ _context23.next = 8;
4501
4731
  return this.recalculateSummary({
4502
4732
  createIfMissing: true
4503
4733
  });
@@ -4506,14 +4736,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4506
4736
  this.logInfo('updateOrderProduct success', {
4507
4737
  params: params
4508
4738
  });
4509
- return _context25.abrupt("return", tempOrder.products);
4739
+ return _context23.abrupt("return", tempOrder.products);
4510
4740
  case 11:
4511
4741
  case "end":
4512
- return _context25.stop();
4742
+ return _context23.stop();
4513
4743
  }
4514
- }, _callee23, this);
4744
+ }, _callee21, this);
4515
4745
  }));
4516
- function updateOrderProduct(_x29) {
4746
+ function updateOrderProduct(_x26) {
4517
4747
  return _updateOrderProduct.apply(this, arguments);
4518
4748
  }
4519
4749
  return updateOrderProduct;
@@ -4521,28 +4751,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4521
4751
  }, {
4522
4752
  key: "updateOrderProducts",
4523
4753
  value: function () {
4524
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(paramsList) {
4525
- var _this28 = this;
4754
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(paramsList) {
4755
+ var _this29 = this;
4526
4756
  var tempOrder, reapplyBookingDiscountProductUids;
4527
- return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4528
- while (1) switch (_context26.prev = _context26.next) {
4757
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4758
+ while (1) switch (_context24.prev = _context24.next) {
4529
4759
  case 0:
4530
4760
  tempOrder = this.ensureTempOrder();
4531
4761
  if (paramsList.length) {
4532
- _context26.next = 3;
4762
+ _context24.next = 3;
4533
4763
  break;
4534
4764
  }
4535
- return _context26.abrupt("return", tempOrder.products);
4765
+ return _context24.abrupt("return", tempOrder.products);
4536
4766
  case 3:
4537
4767
  reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
4538
- var updatedProductUid = _this28.applyOrderProductUpdateToTempOrder(tempOrder, params);
4768
+ var updatedProductUid = _this29.applyOrderProductUpdateToTempOrder(tempOrder, params);
4539
4769
  // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
4540
4770
  if (params.allow_booking_discount_reapply && updatedProductUid) {
4541
4771
  acc.push(String(updatedProductUid));
4542
4772
  }
4543
4773
  return acc;
4544
4774
  }, []);
4545
- _context26.next = 6;
4775
+ _context24.next = 6;
4546
4776
  return this.finalizeAfterProductsMutation(tempOrder, {
4547
4777
  reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
4548
4778
  });
@@ -4550,14 +4780,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4550
4780
  this.logInfo('updateOrderProduct success', {
4551
4781
  paramsList: paramsList
4552
4782
  });
4553
- return _context26.abrupt("return", tempOrder.products);
4783
+ return _context24.abrupt("return", tempOrder.products);
4554
4784
  case 8:
4555
4785
  case "end":
4556
- return _context26.stop();
4786
+ return _context24.stop();
4557
4787
  }
4558
- }, _callee24, this);
4788
+ }, _callee22, this);
4559
4789
  }));
4560
- function updateOrderProducts(_x30) {
4790
+ function updateOrderProducts(_x27) {
4561
4791
  return _updateOrderProducts.apply(this, arguments);
4562
4792
  }
4563
4793
  return updateOrderProducts;
@@ -4565,11 +4795,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4565
4795
  }, {
4566
4796
  key: "updateOrderProductQuantity",
4567
4797
  value: function () {
4568
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
4798
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
4569
4799
  var _targetProduct$metada17;
4570
- var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
4571
- return _regeneratorRuntime().wrap(function _callee25$(_context27) {
4572
- 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) {
4573
4803
  case 0:
4574
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;
4575
4805
  tempOrder = this.ensureTempOrder();
@@ -4599,42 +4829,75 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4599
4829
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
4600
4830
  }
4601
4831
  if (!(productIndex === -1)) {
4602
- _context27.next = 13;
4832
+ _context25.next = 13;
4603
4833
  break;
4604
4834
  }
4605
4835
  throw new Error('[Order] 目标商品不存在,无法更新数量');
4606
4836
  case 13:
4607
4837
  targetProduct = tempOrder.products[productIndex];
4608
- normalizedProduct = normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
4838
+ normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
4609
4839
  num: getSafeProductNum(num),
4610
4840
  metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
4611
4841
  unique_identification_number: ((_targetProduct$metada17 = targetProduct.metadata) === null || _targetProduct$metada17 === void 0 ? void 0 : _targetProduct$metada17.unique_identification_number) || unique_identification_number
4612
4842
  })
4613
- }));
4843
+ })));
4614
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:
4615
4872
  tempOrder.products[productIndex] = normalizedProduct;
4616
- _context27.next = 19;
4873
+ this.prepareVirtualSettlementTempOrder(tempOrder);
4874
+ if (this.isActiveVirtualSettlementOrder(tempOrder)) {
4875
+ _context25.next = 32;
4876
+ break;
4877
+ }
4878
+ _context25.next = 31;
4617
4879
  return this.applyPromotion();
4618
- case 19:
4880
+ case 31:
4619
4881
  this.applyDiscount();
4882
+ case 32:
4620
4883
  this.sanitizeTempOrderProducts(tempOrder);
4621
- _context27.next = 23;
4884
+ _context25.next = 35;
4622
4885
  return this.recalculateSummary({
4623
4886
  createIfMissing: true
4624
4887
  });
4625
- case 23:
4888
+ case 35:
4626
4889
  this.persistTempOrder();
4627
4890
  this.logInfo('updateOrderProductQuantity success', {
4628
4891
  params: params
4629
4892
  });
4630
- return _context27.abrupt("return", tempOrder.products);
4631
- case 26:
4893
+ return _context25.abrupt("return", tempOrder.products);
4894
+ case 38:
4632
4895
  case "end":
4633
- return _context27.stop();
4896
+ return _context25.stop();
4634
4897
  }
4635
- }, _callee25, this);
4898
+ }, _callee23, this);
4636
4899
  }));
4637
- function updateOrderProductQuantity(_x31) {
4900
+ function updateOrderProductQuantity(_x28) {
4638
4901
  return _updateOrderProductQuantity.apply(this, arguments);
4639
4902
  }
4640
4903
  return updateOrderProductQuantity;
@@ -4675,19 +4938,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4675
4938
  }, {
4676
4939
  key: "finalizeAfterProductsMutation",
4677
4940
  value: (function () {
4678
- var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(tempOrder, options) {
4679
- return _regeneratorRuntime().wrap(function _callee26$(_context28) {
4680
- 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) {
4681
4944
  case 0:
4682
4945
  this.syncTempOrderHolderFromBookings(tempOrder);
4683
- _context28.next = 3;
4946
+ _context26.next = 3;
4684
4947
  return this.applyPromotion();
4685
4948
  case 3:
4686
4949
  this.applyDiscount({
4687
4950
  reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
4688
4951
  });
4689
4952
  this.sanitizeTempOrderProducts(tempOrder);
4690
- _context28.next = 7;
4953
+ _context26.next = 7;
4691
4954
  return this.recalculateSummary({
4692
4955
  createIfMissing: true
4693
4956
  });
@@ -4695,11 +4958,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4695
4958
  this.persistTempOrder();
4696
4959
  case 8:
4697
4960
  case "end":
4698
- return _context28.stop();
4961
+ return _context26.stop();
4699
4962
  }
4700
- }, _callee26, this);
4963
+ }, _callee24, this);
4701
4964
  }));
4702
- function finalizeAfterProductsMutation(_x32, _x33) {
4965
+ function finalizeAfterProductsMutation(_x29, _x30) {
4703
4966
  return _finalizeAfterProductsMutation.apply(this, arguments);
4704
4967
  }
4705
4968
  return finalizeAfterProductsMutation;
@@ -4714,22 +4977,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4714
4977
  }, {
4715
4978
  key: "removeProductsFromOrder",
4716
4979
  value: (function () {
4717
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(identities) {
4718
- var _this29 = this;
4719
- var tempOrder, productsBeforeRemove, bookingsBeforeRemove, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3;
4720
- return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4721
- while (1) switch (_context30.prev = _context30.next) {
4980
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(identities, options) {
4981
+ var _this30 = this;
4982
+ var tempOrder, productsBeforeRemove, bookingsBeforeRemove, preserveDisplayPosition, anchorIndex, productsAfterAnchor, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3, remainingProductIndex, remainingProduct, nextProduct, productsWithoutRemaining, nextProductIndex;
4983
+ return _regeneratorRuntime().wrap(function _callee25$(_context28) {
4984
+ while (1) switch (_context28.prev = _context28.next) {
4722
4985
  case 0:
4723
4986
  tempOrder = this.ensureTempOrder();
4724
4987
  this.repairDuplicateProductLineIdentities(tempOrder);
4725
4988
  if (identities.length) {
4726
- _context30.next = 4;
4989
+ _context28.next = 4;
4727
4990
  break;
4728
4991
  }
4729
- return _context30.abrupt("return", tempOrder.products);
4992
+ return _context28.abrupt("return", tempOrder.products);
4730
4993
  case 4:
4731
4994
  productsBeforeRemove = tempOrder.products || [];
4732
4995
  bookingsBeforeRemove = tempOrder.bookings || [];
4996
+ preserveDisplayPosition = options === null || options === void 0 ? void 0 : options.preserveDisplayPosition;
4997
+ anchorIndex = preserveDisplayPosition ? productsBeforeRemove.findIndex(function (item) {
4998
+ var _item$metadata6;
4999
+ var uid = ((_item$metadata6 = item.metadata) === null || _item$metadata6 === void 0 ? void 0 : _item$metadata6.unique_identification_number) || item.unique_identification_number;
5000
+ return uid !== undefined && uid !== null && String(uid) === String(preserveDisplayPosition.anchorProductUid);
5001
+ }) : -1;
5002
+ productsAfterAnchor = anchorIndex >= 0 ? productsBeforeRemove.slice(anchorIndex + 1) : [];
4733
5003
  matchedProducts = productsBeforeRemove.filter(function (item) {
4734
5004
  return identities.some(function (identity) {
4735
5005
  return isIdentityMatch(item, identity);
@@ -4749,29 +5019,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4749
5019
  }
4750
5020
  linkedBookingUidsToRemove = new Set();
4751
5021
  _iterator21 = _createForOfIteratorHelper(matchedProducts);
4752
- _context30.prev = 12;
5022
+ _context28.prev = 15;
4753
5023
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
4754
5024
  var _metadata11, _metadata12, _metadata13, _metadata14;
4755
5025
  var product, productUid, productBookingUid, isAddTimeProduct;
4756
- return _regeneratorRuntime().wrap(function _loop3$(_context29) {
4757
- while (1) switch (_context29.prev = _context29.next) {
5026
+ return _regeneratorRuntime().wrap(function _loop3$(_context27) {
5027
+ while (1) switch (_context27.prev = _context27.next) {
4758
5028
  case 0:
4759
5029
  product = _step21.value;
4760
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);
4761
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);
4762
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;
4763
5033
  if (!isAddTimeProduct) {
4764
- _context29.next = 6;
5034
+ _context27.next = 6;
4765
5035
  break;
4766
5036
  }
4767
- return _context29.abrupt("return", 1);
5037
+ return _context27.abrupt("return", 1);
4768
5038
  case 6:
4769
5039
  if (productBookingUid !== undefined && productBookingUid !== null && productBookingUid !== '') {
4770
5040
  linkedBookingUidsToRemove.add(String(productBookingUid));
4771
5041
  }
4772
5042
  if (productUid !== undefined && productUid !== null && productUid !== '') {
4773
5043
  bookingsBeforeRemove.forEach(function (booking) {
4774
- var bookingUid = _this29.getBookingUniqueIdentificationNumber(booking);
5044
+ var bookingUid = _this30.getBookingUniqueIdentificationNumber(booking);
4775
5045
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
4776
5046
  linkedBookingUidsToRemove.add(bookingUid);
4777
5047
  }
@@ -4779,61 +5049,77 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4779
5049
  }
4780
5050
  case 8:
4781
5051
  case "end":
4782
- return _context29.stop();
5052
+ return _context27.stop();
4783
5053
  }
4784
5054
  }, _loop3);
4785
5055
  });
4786
5056
  _iterator21.s();
4787
- case 15:
5057
+ case 18:
4788
5058
  if ((_step21 = _iterator21.n()).done) {
4789
- _context30.next = 21;
5059
+ _context28.next = 24;
4790
5060
  break;
4791
5061
  }
4792
- return _context30.delegateYield(_loop3(), "t0", 17);
4793
- case 17:
4794
- if (!_context30.t0) {
4795
- _context30.next = 19;
5062
+ return _context28.delegateYield(_loop3(), "t0", 20);
5063
+ case 20:
5064
+ if (!_context28.t0) {
5065
+ _context28.next = 22;
4796
5066
  break;
4797
5067
  }
4798
- return _context30.abrupt("continue", 19);
4799
- case 19:
4800
- _context30.next = 15;
5068
+ return _context28.abrupt("continue", 22);
5069
+ case 22:
5070
+ _context28.next = 18;
4801
5071
  break;
4802
- case 21:
4803
- _context30.next = 26;
5072
+ case 24:
5073
+ _context28.next = 29;
4804
5074
  break;
4805
- case 23:
4806
- _context30.prev = 23;
4807
- _context30.t1 = _context30["catch"](12);
4808
- _iterator21.e(_context30.t1);
4809
5075
  case 26:
4810
- _context30.prev = 26;
4811
- _iterator21.f();
4812
- return _context30.finish(26);
5076
+ _context28.prev = 26;
5077
+ _context28.t1 = _context28["catch"](15);
5078
+ _iterator21.e(_context28.t1);
4813
5079
  case 29:
5080
+ _context28.prev = 29;
5081
+ _iterator21.f();
5082
+ return _context28.finish(29);
5083
+ case 32:
4814
5084
  if (linkedBookingUidsToRemove.size > 0) {
4815
5085
  // 删除主预约商品时,同步移除挂在同一 booking_uid 下的加时商品,避免残留孤儿行。
4816
5086
  tempOrder.products = (tempOrder.products || []).filter(function (line) {
4817
- var _line$metadata, _line$metadata2, _line$metadata3;
4818
- var lineBookingUid = (line === null || line === void 0 || (_line$metadata = line.metadata) === null || _line$metadata === void 0 ? void 0 : _line$metadata.booking_uid) || (line === null || line === void 0 ? void 0 : line.booking_uid);
4819
- var isAddTimeProduct = (line === null || line === void 0 || (_line$metadata2 = line.metadata) === null || _line$metadata2 === void 0 ? void 0 : _line$metadata2.product_add_schedule_time) !== undefined && (line === null || line === void 0 || (_line$metadata3 = line.metadata) === null || _line$metadata3 === void 0 ? void 0 : _line$metadata3.product_add_schedule_time) !== null;
5087
+ var _line$metadata2, _line$metadata3, _line$metadata4;
5088
+ var lineBookingUid = (line === null || line === void 0 || (_line$metadata2 = line.metadata) === null || _line$metadata2 === void 0 ? void 0 : _line$metadata2.booking_uid) || (line === null || line === void 0 ? void 0 : line.booking_uid);
5089
+ var isAddTimeProduct = (line === null || line === void 0 || (_line$metadata3 = line.metadata) === null || _line$metadata3 === void 0 ? void 0 : _line$metadata3.product_add_schedule_time) !== undefined && (line === null || line === void 0 || (_line$metadata4 = line.metadata) === null || _line$metadata4 === void 0 ? void 0 : _line$metadata4.product_add_schedule_time) !== null;
4820
5090
  return !(isAddTimeProduct && lineBookingUid !== undefined && lineBookingUid !== null && linkedBookingUidsToRemove.has(String(lineBookingUid)));
4821
5091
  });
4822
5092
  }
4823
- _context30.next = 32;
5093
+ if (preserveDisplayPosition && anchorIndex >= 0) {
5094
+ remainingProductIndex = tempOrder.products.findIndex(function (item) {
5095
+ var _item$metadata7;
5096
+ var uid = ((_item$metadata7 = item.metadata) === null || _item$metadata7 === void 0 ? void 0 : _item$metadata7.unique_identification_number) || item.unique_identification_number;
5097
+ return uid !== undefined && uid !== null && String(uid) === String(preserveDisplayPosition.remainingProductUid);
5098
+ });
5099
+ if (remainingProductIndex >= 0) {
5100
+ remainingProduct = tempOrder.products[remainingProductIndex];
5101
+ nextProduct = productsAfterAnchor.find(function (item) {
5102
+ return tempOrder.products.includes(item);
5103
+ });
5104
+ productsWithoutRemaining = [].concat(_toConsumableArray(tempOrder.products.slice(0, remainingProductIndex)), _toConsumableArray(tempOrder.products.slice(remainingProductIndex + 1)));
5105
+ nextProductIndex = nextProduct ? productsWithoutRemaining.indexOf(nextProduct) : -1;
5106
+ tempOrder.products = nextProductIndex >= 0 ? [].concat(_toConsumableArray(productsWithoutRemaining.slice(0, nextProductIndex)), [remainingProduct], _toConsumableArray(productsWithoutRemaining.slice(nextProductIndex))) : [].concat(_toConsumableArray(productsWithoutRemaining), [remainingProduct]);
5107
+ }
5108
+ }
5109
+ _context28.next = 36;
4824
5110
  return this.finalizeAfterProductsMutation(tempOrder);
4825
- case 32:
5111
+ case 36:
4826
5112
  this.logInfo('removeProductsFromOrder success', {
4827
5113
  identities: identities
4828
5114
  });
4829
- return _context30.abrupt("return", tempOrder.products);
4830
- case 34:
5115
+ return _context28.abrupt("return", tempOrder.products);
5116
+ case 38:
4831
5117
  case "end":
4832
- return _context30.stop();
5118
+ return _context28.stop();
4833
5119
  }
4834
- }, _callee27, this, [[12, 23, 26, 29]]);
5120
+ }, _callee25, this, [[15, 26, 29, 32]]);
4835
5121
  }));
4836
- function removeProductsFromOrder(_x34) {
5122
+ function removeProductsFromOrder(_x31, _x32) {
4837
5123
  return _removeProductsFromOrder.apply(this, arguments);
4838
5124
  }
4839
5125
  return removeProductsFromOrder;
@@ -4841,18 +5127,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4841
5127
  }, {
4842
5128
  key: "removeProductFromOrder",
4843
5129
  value: function () {
4844
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(identity) {
4845
- return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4846
- 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) {
4847
5133
  case 0:
4848
- return _context31.abrupt("return", this.removeProductsFromOrder([identity]));
5134
+ return _context29.abrupt("return", this.removeProductsFromOrder([identity], options));
4849
5135
  case 1:
4850
5136
  case "end":
4851
- return _context31.stop();
5137
+ return _context29.stop();
4852
5138
  }
4853
- }, _callee28, this);
5139
+ }, _callee26, this);
4854
5140
  }));
4855
- function removeProductFromOrder(_x35) {
5141
+ function removeProductFromOrder(_x33, _x34) {
4856
5142
  return _removeProductFromOrder.apply(this, arguments);
4857
5143
  }
4858
5144
  return removeProductFromOrder;
@@ -4864,65 +5150,122 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4864
5150
  }, {
4865
5151
  key: "clearOrderCartLines",
4866
5152
  value: (function () {
4867
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
5153
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
4868
5154
  var tempOrder;
4869
- return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4870
- while (1) switch (_context32.prev = _context32.next) {
5155
+ return _regeneratorRuntime().wrap(function _callee27$(_context30) {
5156
+ while (1) switch (_context30.prev = _context30.next) {
4871
5157
  case 0:
4872
5158
  tempOrder = this.ensureTempOrder();
4873
5159
  tempOrder.products = [];
4874
5160
  tempOrder.bookings = [];
5161
+ releaseTempOrderSettlementState(tempOrder);
4875
5162
  this.syncTempOrderHolderFromBookings(tempOrder);
4876
5163
  if (tempOrder._extend && _typeof(tempOrder._extend) === 'object') {
4877
5164
  tempOrder._extend = _objectSpread(_objectSpread({}, tempOrder._extend), {}, {
4878
5165
  productsByUid: {}
4879
5166
  });
4880
5167
  }
4881
- _context32.next = 7;
5168
+ _context30.next = 8;
4882
5169
  return this.applyPromotion();
4883
- case 7:
5170
+ case 8:
4884
5171
  this.applyDiscount();
4885
5172
  this.sanitizeTempOrderProducts(tempOrder);
4886
- _context32.next = 11;
5173
+ _context30.next = 12;
4887
5174
  return this.recalculateSummary({
4888
5175
  createIfMissing: true
4889
5176
  });
4890
- case 11:
5177
+ case 12:
4891
5178
  this.persistTempOrder();
4892
5179
  this.logInfo('clearOrderCartLines success', {});
4893
- return _context32.abrupt("return", tempOrder);
4894
- case 14:
5180
+ return _context30.abrupt("return", tempOrder);
5181
+ case 15:
4895
5182
  case "end":
4896
- return _context32.stop();
5183
+ return _context30.stop();
4897
5184
  }
4898
- }, _callee29, this);
5185
+ }, _callee27, this);
4899
5186
  }));
4900
5187
  function clearOrderCartLines() {
4901
5188
  return _clearOrderCartLines.apply(this, arguments);
4902
5189
  }
4903
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;
4904
5247
  }() // ─── TempOrder: 提交 ───
4905
5248
  )
4906
5249
  }, {
4907
5250
  key: "buildCurrentSubmitPayloadForLocalPrint",
4908
5251
  value: function buildCurrentSubmitPayloadForLocalPrint(params) {
4909
- var _params$cacheId, _this$otherParams3, _ref70, _params$businessCode, _this$otherParams4, _this$otherParams5;
5252
+ var _params$cacheId, _this$otherParams4, _ref71, _params$businessCode, _this$otherParams5, _this$otherParams6;
4910
5253
  var tempOrder = this.ensureTempOrder();
4911
5254
  this.persistTempOrder();
4912
5255
  var payload = buildSubmitPayload({
4913
5256
  tempOrder: tempOrder,
4914
5257
  cacheId: (_params$cacheId = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId !== void 0 ? _params$cacheId : this.cacheId,
4915
- platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.platform),
4916
- businessCode: (_ref70 = (_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 && _ref70 !== void 0 ? _ref70 : (_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,
4917
5260
  channel: params === null || params === void 0 ? void 0 : params.channel,
4918
5261
  type: params === null || params === void 0 ? void 0 : params.type,
4919
5262
  summary: this.store.summary || createEmptySummary(),
4920
5263
  enhance: function enhance(nextPayload) {
4921
- var _ref71, _tempOrder$order_numb, _ref72, _tempOrder$shop_order, _ref73, _tempOrder$shop_full_;
5264
+ var _ref72, _tempOrder$order_numb, _ref73, _tempOrder$shop_order, _ref74, _tempOrder$shop_full_;
4922
5265
  return _objectSpread(_objectSpread({}, nextPayload), {}, {
4923
- order_number: (_ref71 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref71 !== void 0 ? _ref71 : null,
4924
- shop_order_number: (_ref72 = (_tempOrder$shop_order = tempOrder.shop_order_number) !== null && _tempOrder$shop_order !== void 0 ? _tempOrder$shop_order : nextPayload.shop_order_number) !== null && _ref72 !== void 0 ? _ref72 : null,
4925
- shop_full_order_number: (_ref73 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref73 !== void 0 ? _ref73 : 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,
4926
5269
  small_ticket_data_flag: 1
4927
5270
  });
4928
5271
  }
@@ -4933,17 +5276,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4933
5276
  }, {
4934
5277
  key: "applyLocalPrintOrderNumbers",
4935
5278
  value: function () {
4936
- var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order) {
5279
+ var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(order) {
4937
5280
  var tempOrder, shopOrderNumber, shopFullOrderNumber;
4938
- return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4939
- while (1) switch (_context33.prev = _context33.next) {
5281
+ return _regeneratorRuntime().wrap(function _callee29$(_context32) {
5282
+ while (1) switch (_context32.prev = _context32.next) {
4940
5283
  case 0:
4941
5284
  tempOrder = this.ensureTempOrder();
4942
5285
  if (!(!order || _typeof(order) !== 'object')) {
4943
- _context33.next = 3;
5286
+ _context32.next = 3;
4944
5287
  break;
4945
5288
  }
4946
- return _context33.abrupt("return", tempOrder);
5289
+ return _context32.abrupt("return", tempOrder);
4947
5290
  case 3:
4948
5291
  shopOrderNumber = order.shop_order_number;
4949
5292
  shopFullOrderNumber = order.shop_full_order_number;
@@ -4954,17 +5297,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4954
5297
  tempOrder.shop_full_order_number = String(shopFullOrderNumber);
4955
5298
  }
4956
5299
  this.persistTempOrder();
4957
- _context33.next = 10;
5300
+ _context32.next = 10;
4958
5301
  return this.saveDraft();
4959
5302
  case 10:
4960
- return _context33.abrupt("return", tempOrder);
5303
+ return _context32.abrupt("return", tempOrder);
4961
5304
  case 11:
4962
5305
  case "end":
4963
- return _context33.stop();
5306
+ return _context32.stop();
4964
5307
  }
4965
- }, _callee30, this);
5308
+ }, _callee29, this);
4966
5309
  }));
4967
- function applyLocalPrintOrderNumbers(_x36) {
5310
+ function applyLocalPrintOrderNumbers(_x35) {
4968
5311
  return _applyLocalPrintOrderNumbers.apply(this, arguments);
4969
5312
  }
4970
5313
  return applyLocalPrintOrderNumbers;
@@ -4972,42 +5315,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4972
5315
  }, {
4973
5316
  key: "saveTempOrderAsDraft",
4974
5317
  value: function () {
4975
- var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
4976
- 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;
4977
5320
  var tempOrder, latestSummary, payload;
4978
- return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4979
- while (1) switch (_context34.prev = _context34.next) {
5321
+ return _regeneratorRuntime().wrap(function _callee30$(_context33) {
5322
+ while (1) switch (_context33.prev = _context33.next) {
4980
5323
  case 0:
4981
5324
  tempOrder = this.ensureTempOrder();
4982
5325
  this.ensureExternalSaleNumber(tempOrder);
4983
5326
  this.persistTempOrder();
4984
- _context34.next = 5;
5327
+ _context33.next = 5;
4985
5328
  return this.recalculateSummary({
4986
5329
  createIfMissing: true
4987
5330
  });
4988
5331
  case 5:
4989
- _context34.t1 = _context34.sent;
4990
- if (_context34.t1) {
4991
- _context34.next = 8;
5332
+ _context33.t1 = _context33.sent;
5333
+ if (_context33.t1) {
5334
+ _context33.next = 8;
4992
5335
  break;
4993
5336
  }
4994
- _context34.t1 = this.store.summary;
5337
+ _context33.t1 = this.store.summary;
4995
5338
  case 8:
4996
- _context34.t0 = _context34.t1;
4997
- if (_context34.t0) {
4998
- _context34.next = 11;
5339
+ _context33.t0 = _context33.t1;
5340
+ if (_context33.t0) {
5341
+ _context33.next = 11;
4999
5342
  break;
5000
5343
  }
5001
- _context34.t0 = createEmptySummary();
5344
+ _context33.t0 = createEmptySummary();
5002
5345
  case 11:
5003
- latestSummary = _context34.t0;
5346
+ latestSummary = _context33.t0;
5004
5347
  payload = buildSubmitPayload({
5005
5348
  tempOrder: tempOrder,
5006
5349
  cacheId: (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId,
5007
- platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
5008
- 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,
5009
5352
  channel: params === null || params === void 0 ? void 0 : params.channel,
5010
- 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,
5011
5354
  summary: latestSummary,
5012
5355
  enhance: params === null || params === void 0 ? void 0 : params.enhancePayload
5013
5356
  });
@@ -5021,17 +5364,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5021
5364
  externalSaleNumber: payload.external_sale_number,
5022
5365
  productsCount: ((_payload$products = payload.products) === null || _payload$products === void 0 ? void 0 : _payload$products.length) || 0
5023
5366
  });
5024
- return _context34.abrupt("return", this.request.post('/order/sales/draft', payload, {
5367
+ return _context33.abrupt("return", this.request.post('/order/sales/draft', payload, {
5025
5368
  osServer: true,
5026
5369
  customToast: function customToast() {}
5027
5370
  }));
5028
5371
  case 18:
5029
5372
  case "end":
5030
- return _context34.stop();
5373
+ return _context33.stop();
5031
5374
  }
5032
- }, _callee31, this);
5375
+ }, _callee30, this);
5033
5376
  }));
5034
- function saveTempOrderAsDraft(_x37) {
5377
+ function saveTempOrderAsDraft(_x36) {
5035
5378
  return _saveTempOrderAsDraft.apply(this, arguments);
5036
5379
  }
5037
5380
  return saveTempOrderAsDraft;
@@ -5045,18 +5388,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5045
5388
  }, {
5046
5389
  key: "submitTempOrder",
5047
5390
  value: (function () {
5048
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
5049
- return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5050
- 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) {
5051
5394
  case 0:
5052
- return _context35.abrupt("return", this.runSubmitTempOrder(params));
5395
+ return _context34.abrupt("return", this.runSubmitTempOrder(params));
5053
5396
  case 1:
5054
5397
  case "end":
5055
- return _context35.stop();
5398
+ return _context34.stop();
5056
5399
  }
5057
- }, _callee32, this);
5400
+ }, _callee31, this);
5058
5401
  }));
5059
- function submitTempOrder(_x38) {
5402
+ function submitTempOrder(_x37) {
5060
5403
  return _submitTempOrder.apply(this, arguments);
5061
5404
  }
5062
5405
  return submitTempOrder;
@@ -5064,20 +5407,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5064
5407
  }, {
5065
5408
  key: "submitTempOrderAsync",
5066
5409
  value: function () {
5067
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
5068
- return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5069
- 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) {
5070
5413
  case 0:
5071
- return _context36.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
5414
+ return _context35.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
5072
5415
  syncMode: true
5073
5416
  })));
5074
5417
  case 1:
5075
5418
  case "end":
5076
- return _context36.stop();
5419
+ return _context35.stop();
5077
5420
  }
5078
- }, _callee33, this);
5421
+ }, _callee32, this);
5079
5422
  }));
5080
- function submitTempOrderAsync(_x39) {
5423
+ function submitTempOrderAsync(_x38) {
5081
5424
  return _submitTempOrderAsync.apply(this, arguments);
5082
5425
  }
5083
5426
  return submitTempOrderAsync;
@@ -5085,13 +5428,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5085
5428
  }, {
5086
5429
  key: "runSubmitTempOrder",
5087
5430
  value: function () {
5088
- var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5089
- var _params$cacheId3, _this$otherParams10, _ref74, _ref75, _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;
5090
5433
  var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
5091
- return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5092
- while (1) switch (_context37.prev = _context37.next) {
5434
+ return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5435
+ while (1) switch (_context36.prev = _context36.next) {
5093
5436
  case 0:
5094
5437
  tempOrder = this.ensureTempOrder();
5438
+ this.prepareVirtualSettlementTempOrder(tempOrder);
5095
5439
  shouldConfirmPendingVoucherPayments = (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== false;
5096
5440
  hasPaymentOverride = (params === null || params === void 0 ? void 0 : params.payments) !== undefined;
5097
5441
  preparedPaymentOverride = hasPaymentOverride ? this.prepareVoucherPaymentsForSubmit((params === null || params === void 0 ? void 0 : params.payments) || [], shouldConfirmPendingVoucherPayments) : undefined;
@@ -5109,26 +5453,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5109
5453
  }
5110
5454
  }
5111
5455
  this.persistTempOrder();
5112
- _context37.next = 8;
5456
+ _context36.next = 9;
5113
5457
  return this.recalculateSummary({
5114
5458
  createIfMissing: true
5115
5459
  });
5116
- case 8:
5117
- _context37.t1 = _context37.sent;
5118
- if (_context37.t1) {
5119
- _context37.next = 11;
5460
+ case 9:
5461
+ _context36.t1 = _context36.sent;
5462
+ if (_context36.t1) {
5463
+ _context36.next = 12;
5120
5464
  break;
5121
5465
  }
5122
- _context37.t1 = this.store.summary;
5123
- case 11:
5124
- _context37.t0 = _context37.t1;
5125
- if (_context37.t0) {
5126
- _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;
5127
5471
  break;
5128
5472
  }
5129
- _context37.t0 = createEmptySummary();
5130
- case 14:
5131
- latestSummary = _context37.t0;
5473
+ _context36.t0 = createEmptySummary();
5474
+ case 15:
5475
+ latestSummary = _context36.t0;
5132
5476
  effectiveCacheId = (_params$cacheId3 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId3 !== void 0 ? _params$cacheId3 : this.cacheId;
5133
5477
  hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
5134
5478
  hasSmallTicketDataFlagOverride = (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined;
@@ -5147,8 +5491,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5147
5491
  payload = buildSubmitPayload({
5148
5492
  tempOrder: tempOrder,
5149
5493
  cacheId: effectiveCacheId,
5150
- platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform),
5151
- businessCode: (_ref74 = (_ref75 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref75 !== void 0 ? _ref75 : (_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) !== null && _ref74 !== void 0 ? _ref74 : (_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,
5152
5496
  channel: params === null || params === void 0 ? void 0 : params.channel,
5153
5497
  type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
5154
5498
  summary: latestSummary,
@@ -5163,10 +5507,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5163
5507
  if (!payload.created_at) {
5164
5508
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
5165
5509
  }
5166
- _context37.next = 26;
5510
+ _context36.next = 27;
5167
5511
  return this.saveDraft();
5168
- case 26:
5169
- _context37.prev = 26;
5512
+ case 27:
5513
+ _context36.prev = 27;
5170
5514
  this.logInfo('submitTempOrder calling sales checkout', {
5171
5515
  orderId: payload.order_id,
5172
5516
  externalSaleNumber: payload.external_sale_number,
@@ -5176,44 +5520,44 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5176
5520
  smallTicketDataFlag: payload.small_ticket_data_flag,
5177
5521
  syncMode: payload.sync_mode
5178
5522
  });
5179
- _context37.next = 30;
5523
+ _context36.next = 31;
5180
5524
  return this.submitSalesOrder({
5181
5525
  query: payload
5182
5526
  });
5183
- case 30:
5184
- result = _context37.sent;
5185
- _context37.next = 43;
5527
+ case 31:
5528
+ result = _context36.sent;
5529
+ _context36.next = 44;
5186
5530
  break;
5187
- case 33:
5188
- _context37.prev = 33;
5189
- _context37.t2 = _context37["catch"](26);
5190
- backendErrorResponse = this.extractSubmitErrorResponse(_context37.t2);
5531
+ case 34:
5532
+ _context36.prev = 34;
5533
+ _context36.t2 = _context36["catch"](27);
5534
+ backendErrorResponse = this.extractSubmitErrorResponse(_context36.t2);
5191
5535
  if (!backendErrorResponse) {
5192
- _context37.next = 40;
5536
+ _context36.next = 41;
5193
5537
  break;
5194
5538
  }
5195
5539
  this.store.syncState = 'failed';
5196
5540
  this.logSubmitBackendRejected(backendErrorResponse, payload);
5197
- return _context37.abrupt("return", backendErrorResponse);
5198
- case 40:
5541
+ return _context36.abrupt("return", backendErrorResponse);
5542
+ case 41:
5199
5543
  this.store.syncState = 'failed';
5200
5544
  this.logError('submitTempOrder failed', {
5201
- error: _context37.t2 instanceof Error ? _context37.t2.message : String(_context37.t2),
5545
+ error: _context36.t2 instanceof Error ? _context36.t2.message : String(_context36.t2),
5202
5546
  orderId: payload.order_id,
5203
5547
  externalSaleNumber: payload.external_sale_number,
5204
5548
  paymentStatus: payload.payment_status,
5205
5549
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
5206
5550
  });
5207
- throw _context37.t2;
5208
- case 43:
5551
+ throw _context36.t2;
5552
+ case 44:
5209
5553
  if (!this.isSubmitResponseRejected(result)) {
5210
- _context37.next = 47;
5554
+ _context36.next = 48;
5211
5555
  break;
5212
5556
  }
5213
5557
  this.store.syncState = 'failed';
5214
5558
  this.logSubmitBackendRejected(result, payload);
5215
- return _context37.abrupt("return", result);
5216
- case 47:
5559
+ return _context36.abrupt("return", result);
5560
+ case 48:
5217
5561
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
5218
5562
  this.logInfo('runSubmitTempOrder: 提交成功', {
5219
5563
  submittedOrderId: submittedOrderId,
@@ -5223,31 +5567,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5223
5567
  })
5224
5568
  });
5225
5569
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
5226
- _context37.next = 56;
5570
+ _context36.next = 57;
5227
5571
  break;
5228
5572
  }
5229
5573
  tempOrder.order_id = submittedOrderId;
5230
5574
  resultRecord = result;
5231
- _context37.next = 54;
5575
+ _context36.next = 55;
5232
5576
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
5233
- case 54:
5234
- _context37.next = 57;
5577
+ case 55:
5578
+ _context36.next = 58;
5235
5579
  break;
5236
- case 56:
5580
+ case 57:
5237
5581
  if (this.isLocalPendingSubmitResult(result)) {
5238
5582
  this.store.syncState = 'local';
5239
5583
  } else {
5240
5584
  this.store.syncState = 'submitted';
5241
5585
  }
5242
- case 57:
5243
- return _context37.abrupt("return", result);
5244
5586
  case 58:
5587
+ return _context36.abrupt("return", result);
5588
+ case 59:
5245
5589
  case "end":
5246
- return _context37.stop();
5590
+ return _context36.stop();
5247
5591
  }
5248
- }, _callee34, this, [[26, 33]]);
5592
+ }, _callee33, this, [[27, 34]]);
5249
5593
  }));
5250
- function runSubmitTempOrder(_x40) {
5594
+ function runSubmitTempOrder(_x39) {
5251
5595
  return _runSubmitTempOrder.apply(this, arguments);
5252
5596
  }
5253
5597
  return runSubmitTempOrder;
@@ -5255,10 +5599,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5255
5599
  }, {
5256
5600
  key: "markLocalOrderSynced",
5257
5601
  value: function () {
5258
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(orderId, remoteOrder) {
5602
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(orderId, remoteOrder) {
5259
5603
  var tempOrder;
5260
- return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5261
- while (1) switch (_context38.prev = _context38.next) {
5604
+ return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5605
+ while (1) switch (_context37.prev = _context37.next) {
5262
5606
  case 0:
5263
5607
  tempOrder = this.ensureTempOrder();
5264
5608
  tempOrder.order_id = orderId;
@@ -5266,15 +5610,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5266
5610
  this.store.lastOrderInfo = remoteOrder;
5267
5611
  this.store.syncState = 'submitted';
5268
5612
  this.persistTempOrder();
5269
- _context38.next = 8;
5613
+ _context37.next = 8;
5270
5614
  return this.saveDraft();
5271
5615
  case 8:
5272
5616
  case "end":
5273
- return _context38.stop();
5617
+ return _context37.stop();
5274
5618
  }
5275
- }, _callee35, this);
5619
+ }, _callee34, this);
5276
5620
  }));
5277
- function markLocalOrderSynced(_x41, _x42) {
5621
+ function markLocalOrderSynced(_x40, _x41) {
5278
5622
  return _markLocalOrderSynced.apply(this, arguments);
5279
5623
  }
5280
5624
  return markLocalOrderSynced;
@@ -5317,10 +5661,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5317
5661
  value: function extractSubmitErrorResponse(error) {
5318
5662
  var _error$response,
5319
5663
  _error$response2,
5320
- _this30 = this;
5664
+ _this31 = this;
5321
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];
5322
5666
  return candidates.find(function (candidate) {
5323
- return _this30.isSubmitErrorResponse(candidate);
5667
+ return _this31.isSubmitErrorResponse(candidate);
5324
5668
  }) || null;
5325
5669
  }
5326
5670
  }, {
@@ -5347,33 +5691,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5347
5691
  }, {
5348
5692
  key: "syncPaymentsToOrder",
5349
5693
  value: function () {
5350
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5351
- var _this31 = this,
5694
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
5695
+ var _this32 = this,
5352
5696
  _params$confirmPendin;
5353
5697
  var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitParams, submitResult;
5354
- return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5355
- while (1) switch (_context39.prev = _context39.next) {
5698
+ return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5699
+ while (1) switch (_context38.prev = _context38.next) {
5356
5700
  case 0:
5357
5701
  tempOrder = this.ensureTempOrder();
5358
5702
  needsPaymentNumber = (params.payments || []).some(function (payment) {
5359
5703
  return String(payment.payment_number || '').trim() === '';
5360
5704
  });
5361
5705
  if (!needsPaymentNumber) {
5362
- _context39.next = 8;
5706
+ _context38.next = 8;
5363
5707
  break;
5364
5708
  }
5365
- _context39.next = 5;
5709
+ _context38.next = 5;
5366
5710
  return this.getPaymentNumberDevicePrefixAsync();
5367
5711
  case 5:
5368
- _context39.t0 = _context39.sent;
5369
- _context39.next = 9;
5712
+ _context38.t0 = _context38.sent;
5713
+ _context38.next = 9;
5370
5714
  break;
5371
5715
  case 8:
5372
- _context39.t0 = 'LOCAL';
5716
+ _context38.t0 = 'LOCAL';
5373
5717
  case 9:
5374
- devicePrefix = _context39.t0;
5718
+ devicePrefix = _context38.t0;
5375
5719
  mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
5376
- return _this31.normalizePaymentSource(payment, {
5720
+ return _this32.normalizePaymentSource(payment, {
5377
5721
  defaultPaid: false,
5378
5722
  devicePrefix: devicePrefix
5379
5723
  });
@@ -5386,20 +5730,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5386
5730
  tempOrder.payments = effectivePayments;
5387
5731
  tempOrder.payment_status = paymentStatus;
5388
5732
  this.persistTempOrder();
5389
- _context39.next = 21;
5733
+ _context38.next = 21;
5390
5734
  return this.saveDraft();
5391
5735
  case 21:
5392
5736
  if (params.submitWhenPaid) {
5393
- _context39.next = 23;
5737
+ _context38.next = 23;
5394
5738
  break;
5395
5739
  }
5396
- return _context39.abrupt("return", completion);
5740
+ return _context38.abrupt("return", completion);
5397
5741
  case 23:
5398
5742
  if (!(this.store.syncState === 'submitting')) {
5399
- _context39.next = 25;
5743
+ _context38.next = 25;
5400
5744
  break;
5401
5745
  }
5402
- return _context39.abrupt("return", completion);
5746
+ return _context38.abrupt("return", completion);
5403
5747
  case 25:
5404
5748
  this.store.syncState = 'submitting';
5405
5749
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
@@ -5418,32 +5762,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5418
5762
  }
5419
5763
  };
5420
5764
  if (!(params.checkoutSyncTaskEnabled === false)) {
5421
- _context39.next = 34;
5765
+ _context38.next = 34;
5422
5766
  break;
5423
5767
  }
5424
- _context39.next = 31;
5768
+ _context38.next = 31;
5425
5769
  return this.submitTempOrderAsync(submitParams);
5426
5770
  case 31:
5427
- _context39.t1 = _context39.sent;
5428
- _context39.next = 37;
5771
+ _context38.t1 = _context38.sent;
5772
+ _context38.next = 37;
5429
5773
  break;
5430
5774
  case 34:
5431
- _context39.next = 36;
5775
+ _context38.next = 36;
5432
5776
  return this.submitTempOrder(submitParams);
5433
5777
  case 36:
5434
- _context39.t1 = _context39.sent;
5778
+ _context38.t1 = _context38.sent;
5435
5779
  case 37:
5436
- submitResult = _context39.t1;
5437
- return _context39.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5780
+ submitResult = _context38.t1;
5781
+ return _context38.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5438
5782
  submitResult: submitResult
5439
5783
  }));
5440
5784
  case 39:
5441
5785
  case "end":
5442
- return _context39.stop();
5786
+ return _context38.stop();
5443
5787
  }
5444
- }, _callee36, this);
5788
+ }, _callee35, this);
5445
5789
  }));
5446
- function syncPaymentsToOrder(_x43) {
5790
+ function syncPaymentsToOrder(_x42) {
5447
5791
  return _syncPaymentsToOrder.apply(this, arguments);
5448
5792
  }
5449
5793
  return syncPaymentsToOrder;
@@ -5451,7 +5795,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5451
5795
  }, {
5452
5796
  key: "createOrder",
5453
5797
  value: function createOrder(params) {
5454
- var _this32 = this;
5798
+ var _this33 = this;
5455
5799
  var order = _objectSpread({
5456
5800
  type: (params === null || params === void 0 ? void 0 : params.type) || 'appointment_booking',
5457
5801
  // 要从外面拿,virtual
@@ -5483,7 +5827,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5483
5827
 
5484
5828
  // 为预约补齐 holder 信息
5485
5829
  if (params !== null && params !== void 0 && (_params$extraData = params.extraData) !== null && _params$extraData !== void 0 && _params$extraData.is_add_holder_info) {
5486
- ensureCartItemOriginHolder(item, _this32.window);
5830
+ ensureCartItemOriginHolder(item, _this33.window);
5487
5831
  }
5488
5832
 
5489
5833
  // 购物车是否为普通商品
@@ -5540,11 +5884,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5540
5884
  }, {
5541
5885
  key: "submitOrder",
5542
5886
  value: function () {
5543
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(order) {
5887
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(order) {
5544
5888
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
5545
5889
  var url, query, fetchUrl, params;
5546
- return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5547
- while (1) switch (_context40.prev = _context40.next) {
5890
+ return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5891
+ while (1) switch (_context39.prev = _context39.next) {
5548
5892
  case 0:
5549
5893
  this.logInfo('submitOrder called', {
5550
5894
  url: order.url,
@@ -5564,14 +5908,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5564
5908
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
5565
5909
  scheduleDate: params.schedule_date
5566
5910
  });
5567
- return _context40.abrupt("return", this.request.post(fetchUrl, params));
5911
+ return _context39.abrupt("return", this.request.post(fetchUrl, params));
5568
5912
  case 6:
5569
5913
  case "end":
5570
- return _context40.stop();
5914
+ return _context39.stop();
5571
5915
  }
5572
- }, _callee37, this);
5916
+ }, _callee36, this);
5573
5917
  }));
5574
- function submitOrder(_x44) {
5918
+ function submitOrder(_x43) {
5575
5919
  return _submitOrder.apply(this, arguments);
5576
5920
  }
5577
5921
  return submitOrder;
@@ -5579,13 +5923,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5579
5923
  }, {
5580
5924
  key: "cancelOrder",
5581
5925
  value: function () {
5582
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5926
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
5583
5927
  var payload;
5584
- return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5585
- while (1) switch (_context41.prev = _context41.next) {
5928
+ return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5929
+ while (1) switch (_context40.prev = _context40.next) {
5586
5930
  case 0:
5587
5931
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
5588
- _context41.next = 2;
5932
+ _context40.next = 2;
5589
5933
  break;
5590
5934
  }
5591
5935
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -5601,16 +5945,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5601
5945
  method: 'PUT',
5602
5946
  orderIdsCount: params.order_ids.length
5603
5947
  });
5604
- return _context41.abrupt("return", this.request.put('/order/update-status', payload, {
5948
+ return _context40.abrupt("return", this.request.put('/order/update-status', payload, {
5605
5949
  isShopApi: true
5606
5950
  }));
5607
5951
  case 5:
5608
5952
  case "end":
5609
- return _context41.stop();
5953
+ return _context40.stop();
5610
5954
  }
5611
- }, _callee38, this);
5955
+ }, _callee37, this);
5612
5956
  }));
5613
- function cancelOrder(_x45) {
5957
+ function cancelOrder(_x44) {
5614
5958
  return _cancelOrder.apply(this, arguments);
5615
5959
  }
5616
5960
  return cancelOrder;
@@ -5618,19 +5962,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5618
5962
  }, {
5619
5963
  key: "changeBookingStatus",
5620
5964
  value: function () {
5621
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5965
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5622
5966
  var url, payload;
5623
- return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5624
- while (1) switch (_context42.prev = _context42.next) {
5967
+ return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5968
+ while (1) switch (_context41.prev = _context41.next) {
5625
5969
  case 0:
5626
5970
  if (params.booking_id) {
5627
- _context42.next = 2;
5971
+ _context41.next = 2;
5628
5972
  break;
5629
5973
  }
5630
5974
  throw new Error('变更预约状态失败:booking_id 不能为空');
5631
5975
  case 2:
5632
5976
  if (params.appointment_status) {
5633
- _context42.next = 4;
5977
+ _context41.next = 4;
5634
5978
  break;
5635
5979
  }
5636
5980
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -5645,16 +5989,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5645
5989
  bookingId: params.booking_id,
5646
5990
  appointmentStatus: params.appointment_status
5647
5991
  });
5648
- return _context42.abrupt("return", this.request.put(url, payload, {
5992
+ return _context41.abrupt("return", this.request.put(url, payload, {
5649
5993
  isShopApi: true
5650
5994
  }));
5651
5995
  case 8:
5652
5996
  case "end":
5653
- return _context42.stop();
5997
+ return _context41.stop();
5654
5998
  }
5655
- }, _callee39, this);
5999
+ }, _callee38, this);
5656
6000
  }));
5657
- function changeBookingStatus(_x46) {
6001
+ function changeBookingStatus(_x45) {
5658
6002
  return _changeBookingStatus.apply(this, arguments);
5659
6003
  }
5660
6004
  return changeBookingStatus;
@@ -5672,11 +6016,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5672
6016
  }, {
5673
6017
  key: "createOrderByCheckout",
5674
6018
  value: (function () {
5675
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
6019
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5676
6020
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
5677
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;
5678
- return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5679
- while (1) switch (_context43.prev = _context43.next) {
6022
+ return _regeneratorRuntime().wrap(function _callee39$(_context42) {
6023
+ while (1) switch (_context42.prev = _context42.next) {
5680
6024
  case 0:
5681
6025
  // 过滤掉由在线店铺下单的 payment 支付数据
5682
6026
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -5710,7 +6054,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5710
6054
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
5711
6055
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
5712
6056
  });
5713
- _context43.prev = 4;
6057
+ _context42.prev = 4;
5714
6058
  // 构建订单数据,设置默认值并允许 params 覆盖
5715
6059
  orderData = _objectSpread({
5716
6060
  sales_channel: 'my_pisel',
@@ -5772,13 +6116,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5772
6116
  hasOrderId: !!orderData.order_id,
5773
6117
  smallTicketDataFlag: orderData.small_ticket_data_flag
5774
6118
  });
5775
- _context43.next = 12;
6119
+ _context42.next = 12;
5776
6120
  return this.request.post('/order/checkout', orderData, {
5777
6121
  osServer: true,
5778
6122
  customToast: function customToast() {}
5779
6123
  });
5780
6124
  case 12:
5781
- response = _context43.sent;
6125
+ response = _context42.sent;
5782
6126
  this.logInfo('Order API called successfully', {
5783
6127
  response: response
5784
6128
  });
@@ -5786,22 +6130,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5786
6130
  success: !!response,
5787
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)
5788
6132
  });
5789
- return _context43.abrupt("return", response);
6133
+ return _context42.abrupt("return", response);
5790
6134
  case 18:
5791
- _context43.prev = 18;
5792
- _context43.t0 = _context43["catch"](4);
5793
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context43.t0);
6135
+ _context42.prev = 18;
6136
+ _context42.t0 = _context42["catch"](4);
6137
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context42.t0);
5794
6138
  this.logInfo('Order API called failed', {
5795
- error: _context43.t0 instanceof Error ? _context43.t0.message : String(_context43.t0)
6139
+ error: _context42.t0 instanceof Error ? _context42.t0.message : String(_context42.t0)
5796
6140
  });
5797
- throw _context43.t0;
6141
+ throw _context42.t0;
5798
6142
  case 23:
5799
6143
  case "end":
5800
- return _context43.stop();
6144
+ return _context42.stop();
5801
6145
  }
5802
- }, _callee40, this, [[4, 18]]);
6146
+ }, _callee39, this, [[4, 18]]);
5803
6147
  }));
5804
- function createOrderByCheckout(_x47) {
6148
+ function createOrderByCheckout(_x46) {
5805
6149
  return _createOrderByCheckout.apply(this, arguments);
5806
6150
  }
5807
6151
  return createOrderByCheckout;
@@ -5809,24 +6153,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5809
6153
  }, {
5810
6154
  key: "submitSalesOrder",
5811
6155
  value: function () {
5812
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
6156
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
5813
6157
  var url, query, fetchUrl;
5814
- return _regeneratorRuntime().wrap(function _callee41$(_context44) {
5815
- while (1) switch (_context44.prev = _context44.next) {
6158
+ return _regeneratorRuntime().wrap(function _callee40$(_context43) {
6159
+ while (1) switch (_context43.prev = _context43.next) {
5816
6160
  case 0:
5817
6161
  url = params.url, query = params.query;
5818
6162
  fetchUrl = url || '/order/sales/checkout';
5819
- return _context44.abrupt("return", this.request.post(fetchUrl, query, {
6163
+ return _context43.abrupt("return", this.request.post(fetchUrl, query, {
5820
6164
  osServer: true,
5821
6165
  customToast: function customToast() {}
5822
6166
  }));
5823
6167
  case 3:
5824
6168
  case "end":
5825
- return _context44.stop();
6169
+ return _context43.stop();
5826
6170
  }
5827
- }, _callee41, this);
6171
+ }, _callee40, this);
5828
6172
  }));
5829
- function submitSalesOrder(_x48) {
6173
+ function submitSalesOrder(_x47) {
5830
6174
  return _submitSalesOrder.apply(this, arguments);
5831
6175
  }
5832
6176
  return submitSalesOrder;
@@ -5840,37 +6184,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5840
6184
  }, {
5841
6185
  key: "sendCustomerPayLink",
5842
6186
  value: (function () {
5843
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
6187
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
5844
6188
  var _params$emails;
5845
6189
  var orderIds;
5846
- return _regeneratorRuntime().wrap(function _callee42$(_context45) {
5847
- while (1) switch (_context45.prev = _context45.next) {
6190
+ return _regeneratorRuntime().wrap(function _callee41$(_context44) {
6191
+ while (1) switch (_context44.prev = _context44.next) {
5848
6192
  case 0:
5849
6193
  orderIds = params.order_ids || params.orderIds || [];
5850
6194
  if (orderIds.length) {
5851
- _context45.next = 3;
6195
+ _context44.next = 3;
5852
6196
  break;
5853
6197
  }
5854
6198
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
5855
6199
  case 3:
5856
6200
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
5857
- _context45.next = 5;
6201
+ _context44.next = 5;
5858
6202
  break;
5859
6203
  }
5860
6204
  throw new Error('发送支付链接需要至少一个邮箱');
5861
6205
  case 5:
5862
- return _context45.abrupt("return", this.request.post('/order/batch-email', {
6206
+ return _context44.abrupt("return", this.request.post('/order/batch-email', {
5863
6207
  order_ids: orderIds,
5864
6208
  notify_action: params.notify_action || 'order_payment_reminder',
5865
6209
  emails: params.emails
5866
6210
  }));
5867
6211
  case 6:
5868
6212
  case "end":
5869
- return _context45.stop();
6213
+ return _context44.stop();
5870
6214
  }
5871
- }, _callee42, this);
6215
+ }, _callee41, this);
5872
6216
  }));
5873
- function sendCustomerPayLink(_x49) {
6217
+ function sendCustomerPayLink(_x48) {
5874
6218
  return _sendCustomerPayLink.apply(this, arguments);
5875
6219
  }
5876
6220
  return sendCustomerPayLink;
@@ -5878,14 +6222,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5878
6222
  }, {
5879
6223
  key: "getSalesOrderByLookup",
5880
6224
  value: function () {
5881
- var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
6225
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
5882
6226
  var lookup, res;
5883
- return _regeneratorRuntime().wrap(function _callee43$(_context46) {
5884
- while (1) switch (_context46.prev = _context46.next) {
6227
+ return _regeneratorRuntime().wrap(function _callee42$(_context45) {
6228
+ while (1) switch (_context45.prev = _context45.next) {
5885
6229
  case 0:
5886
6230
  lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
5887
6231
  if (lookup) {
5888
- _context46.next = 3;
6232
+ _context45.next = 3;
5889
6233
  break;
5890
6234
  }
5891
6235
  throw new Error('加载销售详情需要 lookup');
@@ -5894,7 +6238,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5894
6238
  if (lookup.startsWith('LOCAL_')) {
5895
6239
  params.forceRemote = false;
5896
6240
  }
5897
- _context46.next = 6;
6241
+ _context45.next = 6;
5898
6242
  return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
5899
6243
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info', 'refunds']
5900
6244
  }, params.forceRemote ? {
@@ -5903,18 +6247,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5903
6247
  osServer: true
5904
6248
  });
5905
6249
  case 6:
5906
- res = _context46.sent;
6250
+ res = _context45.sent;
5907
6251
  if (res.code === 200) {
5908
6252
  this.store.lastOrderInfo = res.data;
5909
6253
  }
5910
- return _context46.abrupt("return", res);
6254
+ return _context45.abrupt("return", res);
5911
6255
  case 9:
5912
6256
  case "end":
5913
- return _context46.stop();
6257
+ return _context45.stop();
5914
6258
  }
5915
- }, _callee43, this);
6259
+ }, _callee42, this);
5916
6260
  }));
5917
- function getSalesOrderByLookup(_x50) {
6261
+ function getSalesOrderByLookup(_x49) {
5918
6262
  return _getSalesOrderByLookup.apply(this, arguments);
5919
6263
  }
5920
6264
  return getSalesOrderByLookup;
@@ -5928,11 +6272,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5928
6272
  }, {
5929
6273
  key: "hydrateTempOrderFromRecord",
5930
6274
  value: (function () {
5931
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(record, options) {
5932
- var _sourceRaw$_extend, _this$store$discount22;
5933
- 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;
5934
- return _regeneratorRuntime().wrap(function _callee44$(_context47) {
5935
- 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) {
5936
6280
  case 0:
5937
6281
  sourceRaw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
5938
6282
  duplicateProductIdentityRepair = repairDuplicateOrderProductLineIdentities(Array.isArray(sourceRaw.products) ? sourceRaw.products : [], (_sourceRaw$_extend = sourceRaw._extend) === null || _sourceRaw$_extend === void 0 ? void 0 : _sourceRaw$_extend.productsByUid);
@@ -5970,7 +6314,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5970
6314
  });
5971
6315
  this.store.tempOrder = nextTempOrder;
5972
6316
  if (!isSessionStorageHydrate) {
5973
- _context47.next = 29;
6317
+ _context46.next = 29;
5974
6318
  break;
5975
6319
  }
5976
6320
  // 会话快照是未提交购物车,不应获得编辑订单的 saved/edit 标记与服务端基线。
@@ -5986,23 +6330,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5986
6330
  nextTempOrder.discount_list = restoredSessionDiscounts;
5987
6331
  this.store.summary = createEmptySummary();
5988
6332
  this.store.lastOrderInfo = undefined;
5989
- _context47.next = 22;
5990
- 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));
5991
6335
  case 22:
5992
- _context47.next = 24;
5993
- 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));
5994
6338
  case 24:
5995
6339
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
5996
- _context47.next = 27;
6340
+ _context46.next = 27;
5997
6341
  break;
5998
6342
  }
5999
- _context47.next = 27;
6343
+ _context46.next = 27;
6000
6344
  return this.recalculateSummary({
6001
6345
  createIfMissing: false
6002
6346
  });
6003
6347
  case 27:
6004
6348
  this.persistTempOrder();
6005
- return _context47.abrupt("return", nextTempOrder);
6349
+ return _context46.abrupt("return", nextTempOrder);
6006
6350
  case 29:
6007
6351
  // Server list compatibility may synthesize order_id from external_sale_number; tempOrder must not.
6008
6352
  sourceLastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
@@ -6035,7 +6379,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6035
6379
  this.store.syncState = 'local';
6036
6380
  }
6037
6381
  hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
6038
- 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() || [] : [];
6039
6383
  currentScanDiscounts = currentDiscounts.filter(function (discount) {
6040
6384
  return discount === null || discount === void 0 ? void 0 : discount.isScan;
6041
6385
  });
@@ -6048,34 +6392,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6048
6392
  nextDiscounts = [].concat(_toConsumableArray(hydratedEditDiscounts), _toConsumableArray(retainedScanDiscounts));
6049
6393
  shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
6050
6394
  if (shouldSkipEmptyDiscountSync) {
6051
- _context47.next = 52;
6395
+ _context46.next = 52;
6052
6396
  break;
6053
6397
  }
6054
6398
  OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
6055
- _context47.next = 50;
6056
- 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);
6057
6401
  case 50:
6058
- _context47.next = 52;
6059
- 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);
6060
6404
  case 52:
6061
6405
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
6062
- _context47.next = 55;
6406
+ _context46.next = 55;
6063
6407
  break;
6064
6408
  }
6065
- _context47.next = 55;
6409
+ _context46.next = 55;
6066
6410
  return this.recalculateSummary({
6067
6411
  createIfMissing: false
6068
6412
  });
6069
6413
  case 55:
6070
6414
  this.persistTempOrder();
6071
- return _context47.abrupt("return", nextTempOrder);
6415
+ return _context46.abrupt("return", nextTempOrder);
6072
6416
  case 57:
6073
6417
  case "end":
6074
- return _context47.stop();
6418
+ return _context46.stop();
6075
6419
  }
6076
- }, _callee44, this);
6420
+ }, _callee43, this);
6077
6421
  }));
6078
- function hydrateTempOrderFromRecord(_x51, _x52) {
6422
+ function hydrateTempOrderFromRecord(_x50, _x51) {
6079
6423
  return _hydrateTempOrderFromRecord.apply(this, arguments);
6080
6424
  }
6081
6425
  return hydrateTempOrderFromRecord;
@@ -6128,10 +6472,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6128
6472
  _step22;
6129
6473
  try {
6130
6474
  for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
6131
- var _product$metadata10;
6475
+ var _product$metadata8;
6132
6476
  var product = _step22.value;
6133
6477
  var productUid = getOrderCollectionUid('product', product);
6134
- var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.booking_uid);
6478
+ var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.booking_uid);
6135
6479
  if (!productUid || bookingUid === undefined || bookingUid === null || bookingUid === '') {
6136
6480
  continue;
6137
6481
  }
@@ -6189,7 +6533,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6189
6533
  }, {
6190
6534
  key: "normalizeTempOrderForRuntime",
6191
6535
  value: function normalizeTempOrderForRuntime(raw, options) {
6192
- var _this33 = this;
6536
+ var _this34 = this;
6193
6537
  var runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
6194
6538
  var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), runtimeRaw || {});
6195
6539
  // ES 列表详情使用 id 表示订单主键;OS 详情态统一依赖 order_id 驱动操作按钮。
@@ -6213,12 +6557,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6213
6557
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
6214
6558
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
6215
6559
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
6216
- return _this33.normalizeHydratedOrderProduct(p, {
6560
+ return _this34.normalizeHydratedOrderProduct(p, {
6217
6561
  makeEditMark: options === null || options === void 0 ? void 0 : options.makeEditMark
6218
6562
  });
6219
6563
  }) : [];
6220
6564
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
6221
- var booking = _this33.normalizeHydratedBookingHolder(b || {});
6565
+ var booking = _this34.normalizeHydratedBookingHolder(b || {});
6222
6566
  return _objectSpread(_objectSpread({}, booking), {}, {
6223
6567
  is_all: normalizeBookingIsAll(booking),
6224
6568
  sub_type: normalizeBookingSubType(booking)
@@ -6248,15 +6592,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6248
6592
  _step24;
6249
6593
  try {
6250
6594
  for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
6251
- var _product$metadata11, _ref76, _ref77, _existed$origin, _rawProduct$metadata;
6595
+ var _product$metadata9, _ref77, _ref78, _existed$origin, _rawProduct$metadata;
6252
6596
  var _step24$value = _slicedToArray(_step24.value, 2),
6253
6597
  index = _step24$value[0],
6254
6598
  product = _step24$value[1];
6255
- var uid = (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.unique_identification_number;
6599
+ var uid = (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.unique_identification_number;
6256
6600
  if (!uid) continue;
6257
6601
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
6258
6602
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
6259
- var origin = (_ref76 = (_ref77 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref77 !== void 0 ? _ref77 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref76 !== void 0 ? _ref76 : 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;
6260
6604
  var originSnapshot = cloneDeep(origin);
6261
6605
  var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
6262
6606
  if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
@@ -6307,8 +6651,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6307
6651
  var bookingUidByProductUid = new Map();
6308
6652
  var productByUid = new Map();
6309
6653
  (tempOrder.products || []).forEach(function (product) {
6310
- var _product$metadata12;
6311
- var productUid = (product === null || product === void 0 || (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6654
+ var _product$metadata10;
6655
+ var productUid = (product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6312
6656
  if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
6313
6657
  productByUid.set(String(productUid), product);
6314
6658
  }
@@ -6329,8 +6673,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6329
6673
  bookingUidByProductUid.set(String(productUid), bookingUid);
6330
6674
  });
6331
6675
  (tempOrder.products || []).forEach(function (product) {
6332
- var _product$metadata13;
6333
- var productUid = (product === null || product === void 0 || (_product$metadata13 = product.metadata) === null || _product$metadata13 === void 0 ? void 0 : _product$metadata13.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6676
+ var _product$metadata11;
6677
+ var productUid = (product === null || product === void 0 || (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6334
6678
  if (productUid === undefined || productUid === null || String(productUid) === '') return;
6335
6679
  var bookingUid = bookingUidByProductUid.get(String(productUid));
6336
6680
  if (!bookingUid) return;
@@ -6385,10 +6729,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6385
6729
  }, {
6386
6730
  key: "normalizeHydratedProductOptionItem",
6387
6731
  value: function normalizeHydratedProductOptionItem(optionItem) {
6388
- var _ref78, _optionItem$num, _ref79, _optionItem$add_price;
6389
- var rawNum = (_ref78 = (_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 && _ref78 !== void 0 ? _ref78 : 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;
6390
6734
  var parsedNum = Number(rawNum);
6391
- var rawPrice = (_ref79 = (_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 && _ref79 !== void 0 ? _ref79 : 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;
6392
6736
  var parsedPrice = Number(rawPrice);
6393
6737
  var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
6394
6738
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -6405,7 +6749,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6405
6749
  }, {
6406
6750
  key: "normalizeHydratedOrderProduct",
6407
6751
  value: function normalizeHydratedOrderProduct(product, options) {
6408
- var _this34 = this;
6752
+ var _this35 = this;
6409
6753
  var row = _objectSpread({}, product || {});
6410
6754
  if (row.num === undefined && row.product_quantity !== undefined) {
6411
6755
  row.num = row.product_quantity;
@@ -6413,12 +6757,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6413
6757
  var productSku = ensureProductSku(row);
6414
6758
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
6415
6759
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
6416
- return _this34.normalizeHydratedProductOptionItem(optionItem || {});
6760
+ return _this35.normalizeHydratedProductOptionItem(optionItem || {});
6417
6761
  }))
6418
6762
  });
6419
6763
  delete row["product_".concat('option', "_item")];
6420
6764
  if (!Array.isArray(row.product_bundle)) row.product_bundle = [];
6421
- 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;
6422
6769
  if (row.booking_uid && !row.metadata.booking_uid) {
6423
6770
  row.metadata.booking_uid = row.booking_uid;
6424
6771
  }
@@ -6439,7 +6786,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6439
6786
  });
6440
6787
  if (result.metadata) delete result.metadata.price_schema_version;
6441
6788
  var restored = restoreHydratedBundleDiscounts(result, normalizeOrderProductDiscountList);
6442
- return this.sanitizeOrderProductForTempOrder(restored);
6789
+ return this.sanitizeOrderProductForTempOrder(this.normalizeVirtualSettlementProductIfEnabled(restored));
6443
6790
  }
6444
6791
  }, {
6445
6792
  key: "getLastOrderInfo",
@@ -6450,27 +6797,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6450
6797
  }, {
6451
6798
  key: "getOrderInfo",
6452
6799
  value: function () {
6453
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(order_id) {
6800
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(order_id) {
6454
6801
  var res;
6455
- return _regeneratorRuntime().wrap(function _callee45$(_context48) {
6456
- while (1) switch (_context48.prev = _context48.next) {
6802
+ return _regeneratorRuntime().wrap(function _callee44$(_context47) {
6803
+ while (1) switch (_context47.prev = _context47.next) {
6457
6804
  case 0:
6458
- _context48.next = 2;
6805
+ _context47.next = 2;
6459
6806
  return this.request.get("/order/sales/".concat(order_id), {
6460
6807
  with: ['products', 'bookings']
6461
6808
  }, {
6462
6809
  osServer: true
6463
6810
  });
6464
6811
  case 2:
6465
- res = _context48.sent;
6466
- return _context48.abrupt("return", res);
6812
+ res = _context47.sent;
6813
+ return _context47.abrupt("return", res);
6467
6814
  case 4:
6468
6815
  case "end":
6469
- return _context48.stop();
6816
+ return _context47.stop();
6470
6817
  }
6471
- }, _callee45, this);
6818
+ }, _callee44, this);
6472
6819
  }));
6473
- function getOrderInfo(_x53) {
6820
+ function getOrderInfo(_x52) {
6474
6821
  return _getOrderInfo.apply(this, arguments);
6475
6822
  }
6476
6823
  return getOrderInfo;
@@ -6529,10 +6876,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6529
6876
  _step29;
6530
6877
  try {
6531
6878
  for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
6532
- var _ref80, _bundle$num3;
6533
6879
  var bundle = _step29.value;
6534
6880
  var isPersistedBundleProduct = isPersistedProduct || Boolean((bundle === null || bundle === void 0 ? void 0 : bundle.order_detail_id) || (bundle === null || bundle === void 0 ? void 0 : bundle.orderDetailId) || (bundle === null || bundle === void 0 ? void 0 : bundle.booking_id));
6535
- var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref80 = (_bundle$num3 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num3 !== void 0 ? _bundle$num3 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref80 !== void 0 ? _ref80 : 1) || 1).toNumber();
6881
+ var bundleQty = Number(qty) || 1;
6536
6882
  var _iterator30 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
6537
6883
  _step30;
6538
6884
  try {