@pisell/pisellos 2.2.261 → 2.2.263

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 (134) hide show
  1. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
  2. package/dist/model/strategy/adapter/dataVariant/adapter.js +167 -0
  3. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
  4. package/dist/model/strategy/adapter/dataVariant/evaluator.js +780 -0
  5. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  6. package/dist/model/strategy/adapter/dataVariant/examples.js +277 -0
  7. package/dist/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  8. package/dist/model/strategy/adapter/dataVariant/index.js +4 -0
  9. package/dist/model/strategy/adapter/dataVariant/type.d.ts +148 -0
  10. package/dist/model/strategy/adapter/dataVariant/type.js +54 -0
  11. package/dist/model/strategy/adapter/index.d.ts +4 -0
  12. package/dist/model/strategy/adapter/index.js +5 -1
  13. package/dist/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  14. package/dist/model/strategy/adapter/promotion/adapter.js +0 -23
  15. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  16. package/dist/model/strategy/adapter/promotion/evaluator.js +6 -279
  17. package/dist/model/strategy/adapter/promotion/examples.d.ts +0 -86
  18. package/dist/model/strategy/adapter/promotion/examples.js +0 -99
  19. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  20. package/dist/model/strategy/adapter/promotion/index.js +1 -1
  21. package/dist/model/strategy/adapter/promotion/type.d.ts +2 -90
  22. package/dist/model/strategy/adapter/promotion/type.js +0 -45
  23. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +16 -10
  24. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  25. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  26. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +32 -1
  27. package/dist/modules/Discount/index.d.ts +5 -2
  28. package/dist/modules/Discount/index.js +30 -7
  29. package/dist/modules/Discount/types.d.ts +4 -0
  30. package/dist/modules/Order/index.d.ts +14 -2
  31. package/dist/modules/Order/index.js +1035 -736
  32. package/dist/modules/Order/types.d.ts +16 -0
  33. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  34. package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
  35. package/dist/modules/Order/utils.d.ts +4 -3
  36. package/dist/modules/Order/utils.js +54 -61
  37. package/dist/modules/Product/types.d.ts +22 -0
  38. package/dist/modules/ProductList/index.d.ts +1 -1
  39. package/dist/modules/ProductList/index.js +4 -2
  40. package/dist/modules/ProductList/types.d.ts +2 -0
  41. package/dist/modules/Rules/index.d.ts +2 -9
  42. package/dist/modules/Rules/index.js +69 -43
  43. package/dist/modules/Rules/types.d.ts +10 -1
  44. package/dist/server/index.d.ts +55 -0
  45. package/dist/server/index.js +1173 -753
  46. package/dist/server/modules/order/index.d.ts +10 -4
  47. package/dist/server/modules/order/index.js +404 -399
  48. package/dist/server/modules/order/types.d.ts +4 -0
  49. package/dist/server/modules/products/index.d.ts +31 -8
  50. package/dist/server/modules/products/index.js +549 -390
  51. package/dist/server/modules/products/types.d.ts +18 -0
  52. package/dist/solution/BaseSales/index.d.ts +21 -1
  53. package/dist/solution/BaseSales/index.js +1136 -789
  54. package/dist/solution/BaseSales/types.d.ts +6 -1
  55. package/dist/solution/BaseSales/types.js +1 -1
  56. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  57. package/dist/solution/BaseSales/utils/cartPromotion.js +48 -81
  58. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
  59. package/dist/solution/BaseSales/utils/parseSalesResponse.js +6 -8
  60. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -1
  61. package/dist/solution/BookingByStep/index.d.ts +1 -1
  62. package/dist/solution/BookingTicket/index.d.ts +1 -1
  63. package/dist/solution/BookingTicket/index.js +59 -25
  64. package/dist/solution/BookingTicket/types.d.ts +2 -0
  65. package/dist/solution/ScanOrder/index.js +20 -31
  66. package/dist/solution/ShopDiscount/index.js +15 -14
  67. package/dist/solution/VenueBooking/index.js +19 -30
  68. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
  69. package/lib/model/strategy/adapter/dataVariant/adapter.js +149 -0
  70. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
  71. package/lib/model/strategy/adapter/dataVariant/evaluator.js +583 -0
  72. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  73. package/lib/model/strategy/adapter/dataVariant/examples.js +293 -0
  74. package/lib/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  75. package/lib/model/strategy/adapter/dataVariant/index.js +38 -0
  76. package/lib/model/strategy/adapter/dataVariant/type.d.ts +148 -0
  77. package/lib/model/strategy/adapter/dataVariant/type.js +31 -0
  78. package/lib/model/strategy/adapter/index.d.ts +4 -0
  79. package/lib/model/strategy/adapter/index.js +13 -2
  80. package/lib/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  81. package/lib/model/strategy/adapter/promotion/adapter.js +0 -20
  82. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  83. package/lib/model/strategy/adapter/promotion/evaluator.js +0 -235
  84. package/lib/model/strategy/adapter/promotion/examples.d.ts +0 -86
  85. package/lib/model/strategy/adapter/promotion/examples.js +0 -91
  86. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  87. package/lib/model/strategy/adapter/promotion/index.js +0 -51
  88. package/lib/model/strategy/adapter/promotion/type.d.ts +2 -90
  89. package/lib/model/strategy/adapter/promotion/type.js +0 -2
  90. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -0
  91. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +1 -0
  92. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  93. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +23 -2
  94. package/lib/modules/Discount/index.d.ts +5 -2
  95. package/lib/modules/Discount/index.js +23 -3
  96. package/lib/modules/Discount/types.d.ts +4 -0
  97. package/lib/modules/Order/index.d.ts +14 -2
  98. package/lib/modules/Order/index.js +326 -60
  99. package/lib/modules/Order/types.d.ts +16 -0
  100. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  101. package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
  102. package/lib/modules/Order/utils.d.ts +4 -3
  103. package/lib/modules/Order/utils.js +22 -23
  104. package/lib/modules/Product/types.d.ts +22 -0
  105. package/lib/modules/ProductList/index.d.ts +1 -1
  106. package/lib/modules/ProductList/index.js +4 -2
  107. package/lib/modules/ProductList/types.d.ts +2 -0
  108. package/lib/modules/Rules/index.d.ts +2 -9
  109. package/lib/modules/Rules/index.js +61 -29
  110. package/lib/modules/Rules/types.d.ts +10 -1
  111. package/lib/server/index.d.ts +55 -0
  112. package/lib/server/index.js +332 -34
  113. package/lib/server/modules/order/index.d.ts +10 -4
  114. package/lib/server/modules/order/index.js +198 -139
  115. package/lib/server/modules/order/types.d.ts +4 -0
  116. package/lib/server/modules/products/index.d.ts +31 -8
  117. package/lib/server/modules/products/index.js +134 -35
  118. package/lib/server/modules/products/types.d.ts +18 -0
  119. package/lib/solution/BaseSales/index.d.ts +21 -1
  120. package/lib/solution/BaseSales/index.js +313 -72
  121. package/lib/solution/BaseSales/types.d.ts +6 -1
  122. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  123. package/lib/solution/BaseSales/utils/cartPromotion.js +29 -60
  124. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
  125. package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -5
  126. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -0
  127. package/lib/solution/BookingByStep/index.d.ts +1 -1
  128. package/lib/solution/BookingTicket/index.d.ts +1 -1
  129. package/lib/solution/BookingTicket/index.js +33 -8
  130. package/lib/solution/BookingTicket/types.d.ts +2 -0
  131. package/lib/solution/ScanOrder/index.js +0 -8
  132. package/lib/solution/ShopDiscount/index.js +2 -1
  133. package/lib/solution/VenueBooking/index.js +0 -8
  134. package/package.json +1 -1
@@ -21,6 +21,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
21
21
  import dayjs from "dayjs";
22
22
  import Decimal from 'decimal.js';
23
23
  import { buildProductLineFingerprint, createEmptySummary } from "../../solution/ScanOrder/utils";
24
+ import { createUuidV4 } from "./utils/orderCollectionIdentity";
24
25
  /**
25
26
  * 把"含 option 的主商品单价"与 bundle 合成"单行 composite 单价"。
26
27
  *
@@ -252,8 +253,8 @@ function getOrderProductDeposit(product, runtimeOrigin) {
252
253
  /**
253
254
  * 仅基于 tempOrder.products 重算整单定金。
254
255
  *
255
- * 对齐 Checkout relation_products 分支:商品定金先按商品规则计算,
256
- * 再扣减商品券/折扣卡抵扣金额;tempOrder.bookings 不参与这里的计算。
256
+ * 商品折扣在进入定金计算前已体现在商品行价格字段中,
257
+ * 因此这里只按商品定金规则汇总,不再扣减 discount_list;tempOrder.bookings 不参与这里的计算。
257
258
  */
258
259
  export function calculateOrderProductsDeposit() {
259
260
  var products = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
@@ -273,30 +274,18 @@ export function calculateOrderProductsDeposit() {
273
274
  product.deposit = deposit;
274
275
  if (!(deposit !== null && deposit !== void 0 && deposit.total) || Number(deposit.total) <= 0) continue;
275
276
  total = total.plus(deposit.total);
276
- var _iterator4 = _createForOfIteratorHelper(product.discount_list || []),
277
+ var _iterator4 = _createForOfIteratorHelper(deposit.protocols || []),
277
278
  _step4;
278
279
  try {
279
280
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
280
- var discount = _step4.value;
281
- total = total.minus((discount === null || discount === void 0 ? void 0 : discount.amount) || 0);
281
+ var protocol = _step4.value;
282
+ if (!protocolMap.has(protocol.id)) protocolMap.set(protocol.id, protocol);
282
283
  }
283
284
  } catch (err) {
284
285
  _iterator4.e(err);
285
286
  } finally {
286
287
  _iterator4.f();
287
288
  }
288
- var _iterator5 = _createForOfIteratorHelper(deposit.protocols || []),
289
- _step5;
290
- try {
291
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
292
- var protocol = _step5.value;
293
- if (!protocolMap.has(protocol.id)) protocolMap.set(protocol.id, protocol);
294
- }
295
- } catch (err) {
296
- _iterator5.e(err);
297
- } finally {
298
- _iterator5.f();
299
- }
300
289
  hasDeposit = true;
301
290
  }
302
291
  } catch (err) {
@@ -460,19 +449,19 @@ function resolveSubmitBundleMapId(bundle) {
460
449
  }
461
450
  function collectSubmitProductDiscountList(product) {
462
451
  var submitDiscountList = Array.isArray(product === null || product === void 0 ? void 0 : product.discount_list) ? _toConsumableArray(product.discount_list) : [];
463
- var _iterator6 = _createForOfIteratorHelper((product === null || product === void 0 ? void 0 : product.product_bundle) || []),
464
- _step6;
452
+ var _iterator5 = _createForOfIteratorHelper((product === null || product === void 0 ? void 0 : product.product_bundle) || []),
453
+ _step5;
465
454
  try {
466
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
467
- var bundle = _step6.value;
455
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
456
+ var bundle = _step5.value;
468
457
  if (!bundle || _typeof(bundle) !== 'object') continue;
469
458
  var bundleMapId = resolveSubmitBundleMapId(bundle);
470
459
  var bundleDiscountList = Array.isArray(bundle.discount_list) ? bundle.discount_list : [];
471
- var _iterator7 = _createForOfIteratorHelper(bundleDiscountList),
472
- _step7;
460
+ var _iterator6 = _createForOfIteratorHelper(bundleDiscountList),
461
+ _step6;
473
462
  try {
474
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
475
- var discount = _step7.value;
463
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
464
+ var discount = _step6.value;
476
465
  if (!discount || _typeof(discount) !== 'object') continue;
477
466
  var discountMetadata = discount.metadata && _typeof(discount.metadata) === 'object' ? discount.metadata : {};
478
467
  var discountMapId = discountMetadata.custom_product_bundle_map_id !== undefined && discountMetadata.custom_product_bundle_map_id !== null && discountMetadata.custom_product_bundle_map_id !== '' ? discountMetadata.custom_product_bundle_map_id : bundleMapId;
@@ -483,15 +472,15 @@ function collectSubmitProductDiscountList(product) {
483
472
  } : {}));
484
473
  }
485
474
  } catch (err) {
486
- _iterator7.e(err);
475
+ _iterator6.e(err);
487
476
  } finally {
488
- _iterator7.f();
477
+ _iterator6.f();
489
478
  }
490
479
  }
491
480
  } catch (err) {
492
- _iterator6.e(err);
481
+ _iterator5.e(err);
493
482
  } finally {
494
- _iterator6.f();
483
+ _iterator5.f();
495
484
  }
496
485
  return normalizeOrderProductDiscountList(submitDiscountList);
497
486
  }
@@ -544,8 +533,7 @@ export function resolveEffectivePerUnitDiscount(product) {
544
533
  return sum + Number((discount === null || discount === void 0 ? void 0 : discount.amount) || 0);
545
534
  }, 0);
546
535
  var hasPromoDiscountItem = discountList.some(function (item) {
547
- var _item$metadata, _item$metadata2;
548
- return (item === null || item === void 0 ? void 0 : item.type) === 'promotion' || (item === null || item === void 0 ? void 0 : item.type) === 'product' && (item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.source) === 'promotion' && (item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.actionType) === 'ITEM_REWARD';
536
+ return (item === null || item === void 0 ? void 0 : item.type) === 'promotion';
549
537
  });
550
538
  if (hasPromoDiscountItem) return fromList;
551
539
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
@@ -587,11 +575,14 @@ export function createDefaultOrderRulesHooks() {
587
575
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
588
576
  var current = currentByIdentity.get(getBundleIdentity(bundle));
589
577
  if (!current) return bundle;
578
+ var bundleWithDisplayFields = _objectSpread(_objectSpread({}, bundle), isEmptyOrderProductDisplayValue(bundle.cover) && !isEmptyOrderProductDisplayValue(current.cover) ? {
579
+ cover: current.cover
580
+ } : {});
590
581
  var isProductPriceBundle = ((_bundle$price_type_ex2 = bundle.price_type_ext) !== null && _bundle$price_type_ex2 !== void 0 ? _bundle$price_type_ex2 : current.price_type_ext) === 'product_price';
591
- if (!isProductPriceBundle) return bundle;
582
+ if (!isProductPriceBundle) return bundleWithDisplayFields;
592
583
  var sourcePrice = (_ref18 = (_ref19 = (_current$price = current.price) !== null && _current$price !== void 0 ? _current$price : current.custom_price) !== null && _ref19 !== void 0 ? _ref19 : current.original_price) !== null && _ref18 !== void 0 ? _ref18 : current.bundle_selling_price;
593
584
  var originalPrice = (_ref20 = (_ref21 = (_ref22 = (_current$original_pri = current.original_price) !== null && _current$original_pri !== void 0 ? _current$original_pri : current.product_price) !== null && _ref22 !== void 0 ? _ref22 : current.price) !== null && _ref21 !== void 0 ? _ref21 : current.custom_price) !== null && _ref20 !== void 0 ? _ref20 : sourcePrice;
594
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, bundle), sourcePrice !== undefined ? {
585
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, bundleWithDisplayFields), sourcePrice !== undefined ? {
595
586
  price: sourcePrice
596
587
  } : {}), originalPrice !== undefined ? {
597
588
  original_price: originalPrice
@@ -764,14 +755,7 @@ export var getAllDiscountList = function getAllDiscountList(cartItem) {
764
755
 
765
756
  // ─── 以下为从 ScanOrder/utils.ts 迁入的 Order 专属工具函数 ───
766
757
 
767
- export function createUuidV4() {
768
- var template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
769
- return template.replace(/[xy]/g, function (char) {
770
- var randomValue = Math.floor(Math.random() * 16);
771
- var value = char === 'x' ? randomValue : randomValue & 0x3 | 0x8;
772
- return value.toString(16);
773
- });
774
- }
758
+ export { createUuidV4 };
775
759
  export function isTempOrder(data) {
776
760
  if (!data || _typeof(data) !== 'object') return false;
777
761
  if (!Array.isArray(data.products)) return false;
@@ -864,6 +848,7 @@ function formatSubmitBundleItems(bundle) {
864
848
  bundle_group_id: (_rawBundle$bundle_gro = rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.bundle_group_id) !== null && _rawBundle$bundle_gro !== void 0 ? _rawBundle$bundle_gro : rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.group_id,
865
849
  bundle_id: (_rawBundle$bundle_id = rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.bundle_id) !== null && _rawBundle$bundle_id !== void 0 ? _rawBundle$bundle_id : rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.id,
866
850
  bundle_product_id: (_rawBundle$bundle_pro = rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.bundle_product_id) !== null && _rawBundle$bundle_pro !== void 0 ? _rawBundle$bundle_pro : rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle._bundle_product_id,
851
+ cover: rawBundle.cover,
867
852
  metadata: _objectSpread(_objectSpread(_objectSpread({}, submitMetadata), hasSubmitBundleDiscounts && bundleMapId !== undefined ? {
868
853
  custom_product_bundle_map_id: bundleMapId
869
854
  } : {}), {}, {
@@ -925,6 +910,9 @@ function normalizeSubmitProduct(product) {
925
910
  if (rawMetadata.is_rule !== undefined) {
926
911
  cleanMetadata.is_rule = rawMetadata.is_rule;
927
912
  }
913
+ if (rawMetadata.holder_config !== undefined) {
914
+ cleanMetadata.holder_config = rawMetadata.holder_config;
915
+ }
928
916
  var productSku = _objectSpread(_objectSpread({}, submitProduct.product_sku && _typeof(submitProduct.product_sku) === 'object' ? submitProduct.product_sku : {}), {}, {
929
917
  option: formatSubmitOptionItems((_submitProduct$produc = submitProduct.product_sku) === null || _submitProduct$produc === void 0 ? void 0 : _submitProduct$produc.option)
930
918
  });
@@ -955,19 +943,19 @@ export function normalizeBookingSubType(booking) {
955
943
  export function normalizeSubmitBooking(booking) {
956
944
  var rawMetadata = booking.metadata || {};
957
945
  var cleanMetadata = {};
958
- var _iterator8 = _createForOfIteratorHelper(SUBMIT_BOOKING_METADATA_WHITELIST),
959
- _step8;
946
+ var _iterator7 = _createForOfIteratorHelper(SUBMIT_BOOKING_METADATA_WHITELIST),
947
+ _step7;
960
948
  try {
961
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
962
- var key = _step8.value;
949
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
950
+ var key = _step7.value;
963
951
  if (rawMetadata[key] !== undefined) {
964
952
  cleanMetadata[key] = rawMetadata[key];
965
953
  }
966
954
  }
967
955
  } catch (err) {
968
- _iterator8.e(err);
956
+ _iterator7.e(err);
969
957
  } finally {
970
- _iterator8.f();
958
+ _iterator7.f();
971
959
  }
972
960
  if (cleanMetadata.holder_id === undefined) cleanMetadata.holder_id = null;
973
961
  var bookingRecord = booking;
@@ -1280,25 +1268,25 @@ export function clearTempOrderHolderAssignments(tempOrder) {
1280
1268
  target[key] = null;
1281
1269
  changed = true;
1282
1270
  };
1283
- var _iterator9 = _createForOfIteratorHelper(tempOrder.products || []),
1284
- _step9;
1271
+ var _iterator8 = _createForOfIteratorHelper(tempOrder.products || []),
1272
+ _step8;
1285
1273
  try {
1286
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1287
- var product = _step9.value;
1274
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1275
+ var product = _step8.value;
1288
1276
  if (product.metadata && _typeof(product.metadata) === 'object') {
1289
1277
  resetHolderField(product.metadata);
1290
1278
  }
1291
1279
  }
1292
1280
  } catch (err) {
1293
- _iterator9.e(err);
1281
+ _iterator8.e(err);
1294
1282
  } finally {
1295
- _iterator9.f();
1283
+ _iterator8.f();
1296
1284
  }
1297
- var _iterator10 = _createForOfIteratorHelper(tempOrder.bookings || []),
1298
- _step10;
1285
+ var _iterator9 = _createForOfIteratorHelper(tempOrder.bookings || []),
1286
+ _step9;
1299
1287
  try {
1300
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1301
- var booking = _step10.value;
1288
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1289
+ var booking = _step9.value;
1302
1290
  var bookingRecord = booking;
1303
1291
  if (booking.metadata && _typeof(booking.metadata) === 'object') {
1304
1292
  resetHolderField(booking.metadata);
@@ -1309,9 +1297,9 @@ export function clearTempOrderHolderAssignments(tempOrder) {
1309
1297
  }
1310
1298
  }
1311
1299
  } catch (err) {
1312
- _iterator10.e(err);
1300
+ _iterator9.e(err);
1313
1301
  } finally {
1314
- _iterator10.f();
1302
+ _iterator9.f();
1315
1303
  }
1316
1304
  var productsByUid = (_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.productsByUid;
1317
1305
  if (productsByUid && _typeof(productsByUid) === 'object') {
@@ -1362,11 +1350,16 @@ export function isHolderConfigRequired(holderConfig) {
1362
1350
  return Number(holderConfig.required) === 1;
1363
1351
  }
1364
1352
  export function productRequiresFormSubject(tempOrder, product) {
1353
+ var _tempOrder$products, _orderProduct$metadat;
1354
+ var _orderProduct = tempOrder === null || tempOrder === void 0 || (_tempOrder$products = tempOrder.products) === null || _tempOrder$products === void 0 ? void 0 : _tempOrder$products.find(function (item) {
1355
+ return item.metadata.unique_identification_number === product._id || item.product_id === product.id;
1356
+ });
1365
1357
  var runtimeOrigin = getRuntimeProductOrigin(tempOrder, product);
1366
- return isHolderConfigRequired(product === null || product === void 0 ? void 0 : product.holder_config) || isHolderConfigRequired(runtimeOrigin === null || runtimeOrigin === void 0 ? void 0 : runtimeOrigin.holder_config);
1358
+ return isHolderConfigRequired(_orderProduct === null || _orderProduct === void 0 || (_orderProduct$metadat = _orderProduct.metadata) === null || _orderProduct$metadat === void 0 ? void 0 : _orderProduct$metadat.holder_config) || isHolderConfigRequired(runtimeOrigin === null || runtimeOrigin === void 0 ? void 0 : runtimeOrigin.holder_config) || isHolderConfigRequired(product === null || product === void 0 ? void 0 : product.holder_config);
1367
1359
  }
1368
1360
  export function resolveIsFormSubject(tempOrder, product) {
1369
1361
  var _tempOrder$holder;
1362
+ debugger;
1370
1363
  // 旧版预约维度的 holder 类型仍然生效;新版则从当前商品 holder_config 判断。
1371
1364
  if ((tempOrder === null || tempOrder === void 0 || (_tempOrder$holder = tempOrder.holder) === null || _tempOrder$holder === void 0 ? void 0 : _tempOrder$holder.type) === 'form') return true;
1372
1365
  if (product) return productRequiresFormSubject(tempOrder, product);
@@ -1406,7 +1399,7 @@ export function isEmptyOrderProductDisplayValue(value) {
1406
1399
  */
1407
1400
  export function mergeOrderProductDisplayFields(previous, next) {
1408
1401
  var merged = _objectSpread({}, next);
1409
- var displayFields = ['product_title', 'product_name', 'product_cover', 'cover', 'variant_title', 'product_sku', 'payment_price'];
1402
+ var displayFields = ['product_title', 'product_name', 'product_cover', 'cover', 'product_cover', 'variant_title', 'product_sku', 'payment_price'];
1410
1403
  displayFields.forEach(function (field) {
1411
1404
  if (isEmptyOrderProductDisplayValue(merged[field]) && !isEmptyOrderProductDisplayValue(previous[field])) {
1412
1405
  merged[field] = previous[field];
@@ -9,6 +9,26 @@ export interface ProductCollection {
9
9
  /** 商品集合封面 */
10
10
  cover: string;
11
11
  }
12
+ /**
13
+ * 商品 Data Variant 记录,结构与后端 data_variant 表对齐。
14
+ */
15
+ export interface ProductDataVariant {
16
+ /** 变体记录 id */
17
+ id: number;
18
+ /** 店铺 id */
19
+ shop_id: number;
20
+ /** 所属模块,商品场景固定为 product */
21
+ module: string;
22
+ /** 模块数据 id,商品场景对应 product.id */
23
+ module_data_id: number;
24
+ /** 关联 data_variant_rule.id */
25
+ data_variant_rule_id: number;
26
+ /** 命中策略后覆盖到商品上的字段 */
27
+ data: Record<string, any>;
28
+ created_at: string | null;
29
+ updated_at: string | null;
30
+ deleted_at: string | null;
31
+ }
12
32
  /**
13
33
  * 商品基本信息接口
14
34
  */
@@ -214,6 +234,8 @@ export interface ProductData {
214
234
  bundle_group_count: number;
215
235
  /** 选项组数量 */
216
236
  option_group_count: number;
237
+ /** 智能定价变体列表,/product/query with dataVariants 返回 */
238
+ data_variants?: ProductDataVariant[];
217
239
  /** 服务时长 */
218
240
  service_times?: any;
219
241
  }
@@ -26,7 +26,7 @@ export declare class ProductList extends BaseModule implements Module {
26
26
  * const products = await productList.getAddTimeProducts({ schedule_date: '2026-06-16' });
27
27
  */
28
28
  getAddTimeProducts(params?: ProductListLoadProductsParams): Promise<any>;
29
- loadProducts({ category_ids, product_ids, collection, menu_list_ids, customer_id: paramsCustomerId, with_count, schedule_datetime, schedule_date, cacheId, with_schedule, extension_type, status, }?: ProductListLoadProductsParams, options?: {
29
+ loadProducts({ category_ids, product_ids, collection, menu_list_ids, customer_id: paramsCustomerId, with_count, schedule_datetime, schedule_date, cacheId, with_schedule, extension_type, status, strategy_context, }?: ProductListLoadProductsParams, options?: {
30
30
  callback?: (result: any) => void;
31
31
  subscriberId?: string;
32
32
  }): Promise<any>;
@@ -152,6 +152,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
152
152
  extension_type,
153
153
  _ref$status,
154
154
  status,
155
+ strategy_context,
155
156
  options,
156
157
  userPlugin,
157
158
  customer_id,
@@ -162,7 +163,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
162
163
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
163
164
  while (1) switch (_context4.prev = _context4.next) {
164
165
  case 0:
165
- _ref = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {}, _ref$category_ids = _ref.category_ids, category_ids = _ref$category_ids === void 0 ? [] : _ref$category_ids, _ref$product_ids = _ref.product_ids, product_ids = _ref$product_ids === void 0 ? [] : _ref$product_ids, _ref$collection = _ref.collection, collection = _ref$collection === void 0 ? [] : _ref$collection, _ref$menu_list_ids = _ref.menu_list_ids, menu_list_ids = _ref$menu_list_ids === void 0 ? [] : _ref$menu_list_ids, paramsCustomerId = _ref.customer_id, _ref$with_count = _ref.with_count, with_count = _ref$with_count === void 0 ? [] : _ref$with_count, schedule_datetime = _ref.schedule_datetime, schedule_date = _ref.schedule_date, cacheId = _ref.cacheId, with_schedule = _ref.with_schedule, extension_type = _ref.extension_type, _ref$status = _ref.status, status = _ref$status === void 0 ? 'published' : _ref$status;
166
+ _ref = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {}, _ref$category_ids = _ref.category_ids, category_ids = _ref$category_ids === void 0 ? [] : _ref$category_ids, _ref$product_ids = _ref.product_ids, product_ids = _ref$product_ids === void 0 ? [] : _ref$product_ids, _ref$collection = _ref.collection, collection = _ref$collection === void 0 ? [] : _ref$collection, _ref$menu_list_ids = _ref.menu_list_ids, menu_list_ids = _ref$menu_list_ids === void 0 ? [] : _ref$menu_list_ids, paramsCustomerId = _ref.customer_id, _ref$with_count = _ref.with_count, with_count = _ref$with_count === void 0 ? [] : _ref$with_count, schedule_datetime = _ref.schedule_datetime, schedule_date = _ref.schedule_date, cacheId = _ref.cacheId, with_schedule = _ref.with_schedule, extension_type = _ref.extension_type, _ref$status = _ref.status, status = _ref$status === void 0 ? 'published' : _ref$status, strategy_context = _ref.strategy_context;
166
167
  options = _args4.length > 1 ? _args4[1] : undefined;
167
168
  // // 如果 schedule_ids 为空,则需要尝试从 schedule 模块里获取
168
169
  // if (!schedule_ids?.length) {
@@ -206,7 +207,8 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
206
207
  is_eject: 1,
207
208
  with_schedule: with_schedule,
208
209
  schedule_datetime: schedule_datetime,
209
- extension_type: extension_type
210
+ extension_type: extension_type,
211
+ strategy_context: strategy_context
210
212
  }, {
211
213
  osServer: true,
212
214
  callback: options === null || options === void 0 ? void 0 : options.callback,
@@ -12,6 +12,8 @@ export interface ProductListLoadProductsParams {
12
12
  with_schedule?: number;
13
13
  extension_type?: string[];
14
14
  status?: string;
15
+ /** 智能定价条件上下文,仅影响策略命中,不参与商品集合筛选 */
16
+ strategy_context?: Record<string, any>;
15
17
  }
16
18
  export interface ProductListData {
17
19
  list: ProductData[];
@@ -1,8 +1,7 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { Rules, RulesModuleAPI, DiscountResult, RulesFormSubject, UnavailableReason } from './types';
3
+ import { Rules, RulesModuleAPI, DiscountResult, RulesFormSubject, RulesCalcDiscountOptions, UnavailableReason } from './types';
4
4
  import { Discount } from '../Discount/types';
5
- import { SetDiscountSelectedParams } from '../../solution/ShopDiscount/types';
6
5
  import { WindowPlugin } from '../../plugins';
7
6
  export declare class RulesModule extends BaseModule implements Module, RulesModuleAPI {
8
7
  protected defaultName: string;
@@ -36,7 +35,6 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
36
35
  excludeDiscountListByType(discountList: Discount[], type: string): Discount[];
37
36
  /** 手动改价场景:去掉 promotion,保留 type=product 等行内折扣 */
38
37
  resolveDiscountListForManualOverride(discountList: Discount[]): Discount[];
39
- private isItemRewardProductDiscount;
40
38
  private getUnavailableReason;
41
39
  calcDiscount({ discountList, productList, holders, isFormSubject, orderTotalAmount }: {
42
40
  discountList: Discount[];
@@ -46,12 +44,7 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
46
44
  }[];
47
45
  isFormSubject: RulesFormSubject;
48
46
  orderTotalAmount: number;
49
- }, options?: {
50
- isSelected?: boolean;
51
- discountId?: number;
52
- selectedList?: SetDiscountSelectedParams[];
53
- scan?: boolean;
54
- }): DiscountResult;
47
+ }, options?: RulesCalcDiscountOptions): DiscountResult;
55
48
  /**
56
49
  * 检查优惠是否符合 PackageSubItemUsageRules 配置
57
50
  * @param discount 优惠券
@@ -241,17 +241,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
241
241
  value: function resolveDiscountListForManualOverride(discountList) {
242
242
  return this.excludeDiscountListByType(discountList, 'promotion');
243
243
  }
244
- }, {
245
- key: "isItemRewardProductDiscount",
246
- value: function isItemRewardProductDiscount(product) {
247
- var _product$_promotion;
248
- var discountList = Array.isArray(product === null || product === void 0 ? void 0 : product.discount_list) ? product.discount_list : [];
249
- return (product === null || product === void 0 || (_product$_promotion = product._promotion) === null || _product$_promotion === void 0 ? void 0 : _product$_promotion.actionType) === 'ITEM_REWARD' && discountList.some(function (item) {
250
- var _item$metadata, _item$metadata2;
251
- return (item === null || item === void 0 ? void 0 : item.type) === 'product' && (item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.source) === 'promotion' && (item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.actionType) === 'ITEM_REWARD';
252
- });
253
- }
254
-
255
244
  // 获取券不可用的原因
256
245
  }, {
257
246
  key: "getUnavailableReason",
@@ -346,6 +335,32 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
346
335
  }) && productList.find(function (n) {
347
336
  return !n.booking_id;
348
337
  });
338
+ var reapplyBookingDiscountProductUids = new Set(((options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids) || []).filter(function (uid) {
339
+ return uid !== undefined && uid !== null && uid !== '';
340
+ }).map(String));
341
+ var getOriginProductUid = function getOriginProductUid(originProduct) {
342
+ var _originProduct$metada, _originProduct$metada2;
343
+ var uid = (_originProduct$metada = originProduct === null || originProduct === void 0 || (_originProduct$metada2 = originProduct.metadata) === null || _originProduct$metada2 === void 0 ? void 0 : _originProduct$metada2.unique_identification_number) !== null && _originProduct$metada !== void 0 ? _originProduct$metada : originProduct === null || originProduct === void 0 ? void 0 : originProduct.unique_identification_number;
344
+ if (uid === undefined || uid === null || uid === '') return undefined;
345
+ return String(uid);
346
+ };
347
+ var shouldReapplyBookingDiscount = function shouldReapplyBookingDiscount(originProduct, selectedDiscount) {
348
+ if (!selectedDiscount) return false;
349
+ var uid = getOriginProductUid(originProduct);
350
+ if (!uid || !reapplyBookingDiscountProductUids.has(uid)) return false;
351
+ var discountType = selectedDiscount.tag || selectedDiscount.type;
352
+ return selectedDiscount.isEditMode === true && selectedDiscount.isSelected === true && ['good_pass', 'discount_card', 'product_discount_card'].includes(discountType);
353
+ };
354
+ var resolveReapplyEditModeDiscountPercent = function resolveReapplyEditModeDiscountPercent(originProduct, selectedDiscount) {
355
+ var _discount2;
356
+ if (!shouldReapplyBookingDiscount(originProduct, selectedDiscount)) return undefined;
357
+ var discountType = (selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.tag) || (selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.type);
358
+ if (discountType !== 'discount_card' && discountType !== 'product_discount_card') {
359
+ return undefined;
360
+ }
361
+ var percent = Number((_discount2 = selectedDiscount.discount) === null || _discount2 === void 0 ? void 0 : _discount2.percent);
362
+ return Number.isFinite(percent) ? percent : undefined;
363
+ };
349
364
  var editModeDiscount = [];
350
365
  var addModeDiscount = [];
351
366
  discountList.forEach(function (discount) {
@@ -374,11 +389,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
374
389
  }
375
390
  });
376
391
  }
377
-
378
- // 过滤掉手动取消false的优惠券,但仅用于应用优惠逻辑
379
- var filteredDiscountList = addModeDiscount.filter(function (discount) {
380
- return !discount.isManualSelect;
381
- });
382
392
  var hasDiscountInput = editModeDiscount.length > 0 || addModeDiscount.length > 0 || Boolean(options === null || options === void 0 ? void 0 : options.discountId) || Boolean(options === null || options === void 0 || (_options$selectedList = options.selectedList) === null || _options$selectedList === void 0 ? void 0 : _options$selectedList.length) || Boolean(options === null || options === void 0 ? void 0 : options.scan);
383
393
  if (!hasDiscountInput) {
384
394
  return {
@@ -386,6 +396,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
386
396
  productList: productList
387
397
  };
388
398
  }
399
+ var canUseEditModeDiscountForReapply = function canUseEditModeDiscountForReapply(discount) {
400
+ var discountType = discount.tag || discount.type;
401
+ return reapplyBookingDiscountProductUids.size > 0 && discount.isEditMode === true && discount.isSelected === true && ['good_pass', 'discount_card', 'product_discount_card'].includes(discountType);
402
+ };
403
+
404
+ // 过滤掉手动取消false的优惠券,但仅用于应用优惠逻辑。
405
+ // Change time 重报价需要把已选编辑态折扣卡重新放入候选,再由目标 uid 限定作用范围。
406
+ var filteredDiscountList = [].concat(_toConsumableArray(addModeDiscount.filter(function (discount) {
407
+ return !discount.isManualSelect;
408
+ })), _toConsumableArray(editModeDiscount.filter(canUseEditModeDiscountForReapply)));
389
409
 
390
410
  // 🔥 扁平化商品列表:将 bundle 子商品展开为虚拟商品
391
411
  var flattenProductsWithBundle = function flattenProductsWithBundle(productList) {
@@ -709,9 +729,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
709
729
  startDate: (_flatItem$parentProdu = flatItem.parentProduct) === null || _flatItem$parentProdu === void 0 ? void 0 : _flatItem$parentProdu.startDate
710
730
  };
711
731
  }
712
- if (_this3.isItemRewardProductDiscount(product)) {
713
- return false;
714
- }
715
732
 
716
733
  // 编辑的商品使用了优惠券不可用
717
734
  var isAvailableProduct = flatItem.type === 'main' ? !((_product2 = product) !== null && _product2 !== void 0 && _product2.booking_id && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.length && (_product4 = product) !== null && _product4 !== void 0 && (_product4 = _product4.discount_list) !== null && _product4 !== void 0 && _product4.every(function (d) {
@@ -898,7 +915,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
898
915
  };
899
916
  originProduct = flatItem.originProduct;
900
917
  }
901
- var isItemRewardProductDiscount = _this3.isItemRewardProductDiscount(product);
902
918
  addModeDiscount.forEach(function (discount) {
903
919
  var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config;
904
920
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
@@ -924,7 +940,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
924
940
  var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
925
941
 
926
942
  // 判断优惠券是否适用于该商品
927
- if (isAvailableProduct && !isItemRewardProductDiscount && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config = discount.config) !== null && _discount$config !== void 0 && _discount$config.isAvailable) {
943
+ if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config = discount.config) !== null && _discount$config !== void 0 && _discount$config.isAvailable) {
928
944
  var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
929
945
  // 记录此优惠券适用的商品
930
946
  (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
@@ -1069,10 +1085,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1069
1085
  // 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
1070
1086
  var applicableDiscounts = sortedDiscountList.filter(function (discount) {
1071
1087
  var _product$discount_lis3, _product$discount_lis4;
1072
- if (_this3.isItemRewardProductDiscount(product)) return false;
1073
1088
  // 🔥 检查策略可用性(针对 good_pass 和折扣卡)
1074
1089
  var discountType = discount.tag || discount.type;
1075
- if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
1090
+ var currentOriginUid = getOriginProductUid(originProduct);
1091
+ var isReapplyEditModeDiscountForProduct = discount.isEditMode && reapplyBookingDiscountProductUids.size > 0 && currentOriginUid && reapplyBookingDiscountProductUids.has(String(currentOriginUid)) && discount.isSelected === true;
1092
+ if (discount.isEditMode && reapplyBookingDiscountProductUids.size > 0) {
1093
+ var uid = currentOriginUid;
1094
+ if (!uid || !reapplyBookingDiscountProductUids.has(uid)) return false;
1095
+ if (!discount.isSelected) return false;
1096
+ }
1097
+ if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType) && !isReapplyEditModeDiscountForProduct) {
1076
1098
  var _discount$config2;
1077
1099
  // 如果策略检查后没有config,说明不可用
1078
1100
  if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$config2 = discount.config) !== null && _discount$config2 !== void 0 && _discount$config2.isAvailable)) {
@@ -1150,7 +1172,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1150
1172
 
1151
1173
  // 如果是手动折扣,则不适用优惠券
1152
1174
  var isManualDiscount = false;
1153
- var isItemRewardProductDiscount = false;
1154
1175
  if (flatItem.type === 'main') {
1155
1176
  var _product$discount_lis5, _product$discount_lis6, _product12, _product12$every;
1156
1177
  // 主商品:判断自身是否手动折扣
@@ -1162,8 +1183,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1162
1183
  }) && (!((_product$discount_lis6 = product.discount_list) !== null && _product$discount_lis6 !== void 0 && _product$discount_lis6.length) || ((_product12 = product) === null || _product12 === void 0 || (_product12 = _product12.discount_list) === null || _product12 === void 0 || (_product12$every = _product12.every) === null || _product12$every === void 0 ? void 0 : _product12$every.call(_product12, function (item) {
1163
1184
  return item.type === 'product';
1164
1185
  })));
1165
- isItemRewardProductDiscount = _this3.isItemRewardProductDiscount(product);
1166
- if (product.inPromotion && !isItemRewardProductDiscount) {
1186
+ if (product.inPromotion) {
1167
1187
  isManualDiscount = false;
1168
1188
  }
1169
1189
  } else {
@@ -1273,17 +1293,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1273
1293
  var main_product_selling_price = product.price;
1274
1294
  if ((product.discount_list || []).some(function (item) {
1275
1295
  return item.type === 'promotion';
1276
- }) || isItemRewardProductDiscount || isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
1296
+ }) || isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
1277
1297
  var _product$total, _product$main_product;
1278
1298
  total = (_product$total = product.total) !== null && _product$total !== void 0 ? _product$total : product.origin_total;
1279
1299
  main_product_selling_price = (_product$main_product = product.main_product_selling_price) !== null && _product$main_product !== void 0 ? _product$main_product : main_product_selling_price;
1280
1300
  }
1281
- processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? _objectSpread({
1301
+ processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {
1282
1302
  price: product.price,
1283
- main_product_selling_price: isItemRewardProductDiscount ? main_product_selling_price : product.price
1284
- }, isItemRewardProductDiscount ? {
1285
- total: total
1286
- } : {}) : {
1303
+ main_product_selling_price: product.price
1304
+ } : {
1287
1305
  _id: product._id.split('___')[0] + '___' + index,
1288
1306
  total: total,
1289
1307
  price: product.price,
@@ -1304,7 +1322,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1304
1322
  }
1305
1323
  return;
1306
1324
  }
1307
- if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined' && !(options !== null && options !== void 0 && options.scan) && !isEditModeAddNewProduct) {
1325
+ var shouldReapplyBookingDiscountForProduct = shouldReapplyBookingDiscount(originProduct, selectedDiscount);
1326
+ if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined' && !(options !== null && options !== void 0 && options.scan) && !isEditModeAddNewProduct && !shouldReapplyBookingDiscountForProduct) {
1308
1327
  return;
1309
1328
  }
1310
1329
 
@@ -1345,7 +1364,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1345
1364
  }));
1346
1365
  }
1347
1366
  for (var i = 0; i < splitCount; i++) {
1348
- var _originProduct4, _selectedDiscount$con, _product$options, _product$options2, _selectedDiscount$met, _selectedDiscount$met2;
1367
+ var _originProduct4, _selectedDiscount$con, _product$options, _product$options2, _selectedDiscount$met, _selectedDiscount$met2, _reapplyDiscountPerce;
1349
1368
  // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
1350
1369
  var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
1351
1370
  // 标记优惠券为已使用
@@ -1383,11 +1402,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1383
1402
  var productDiscountDifference = void 0;
1384
1403
  var discountedOptions = product.options;
1385
1404
  var optionDiscountAmount = 0;
1405
+ var reapplyDiscountPercent = void 0;
1386
1406
  if (isOrderLevel && productAllocation) {
1387
1407
  // order_level:使用预计算的分摊金额
1388
1408
  amount = productAllocation.discountAmount;
1389
1409
  productDiscountDifference = productAllocation.difference;
1390
1410
  mainProductSellingPrice = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
1411
+ } else if (resolveReapplyEditModeDiscountPercent(originProduct, _selectedDiscount) !== undefined) {
1412
+ // Change time 重套编辑态折扣卡时,历史 par_value 不是运行时折扣口径,优先使用后端快照里的 percent。
1413
+ var percent = resolveReapplyEditModeDiscountPercent(originProduct, _selectedDiscount);
1414
+ reapplyDiscountPercent = new Decimal(percent).toFixed(2);
1415
+ mainProductSellingPrice = new Decimal(product.price || 0).mul(new Decimal(100).minus(percent)).div(100).toDecimalPlaces(2).toNumber();
1416
+ amount = new Decimal(product.price).minus(mainProductSellingPrice).toNumber();
1391
1417
  } else {
1392
1418
  // item_level 或其他类型:使用原有逻辑
1393
1419
  mainProductSellingPrice = getDiscountAmount(_selectedDiscount, product.price, product.price);
@@ -1420,7 +1446,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1420
1446
  title: _selectedDiscount.format_title,
1421
1447
  original_amount: product.price,
1422
1448
  product_id: originProduct.id || originProduct.product_id,
1423
- percent: _selectedDiscount.par_value,
1449
+ percent: (_reapplyDiscountPerce = reapplyDiscountPercent) !== null && _reapplyDiscountPerce !== void 0 ? _reapplyDiscountPerce : _selectedDiscount.par_value,
1424
1450
  discount_product_id: _selectedDiscount.product_id
1425
1451
  },
1426
1452
  // 前端使用的num数量,为了计算优惠金额
@@ -1724,11 +1750,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1724
1750
  processedItems.forEach(function (item) {
1725
1751
  // 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
1726
1752
  var updatedDiscountList = (item.discount_list || []).map(function (discount) {
1727
- var _item$metadata3;
1753
+ var _item$metadata;
1728
1754
  return _objectSpread(_objectSpread({}, discount), {}, {
1729
1755
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1730
1756
  num: item.num,
1731
- custom_product_bundle_map_id: (_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.custom_product_bundle_map_id
1757
+ custom_product_bundle_map_id: (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.custom_product_bundle_map_id
1732
1758
  })
1733
1759
  // num: item.num, // 使用拆分后的 num
1734
1760
  });
@@ -1747,11 +1773,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1747
1773
  if (item.processed) {
1748
1774
  // 🔥 同样需要更新 discount_list 中的 num
1749
1775
  var _updatedDiscountList = (item.discount_list || []).map(function (discount) {
1750
- var _item$metadata4;
1776
+ var _item$metadata2;
1751
1777
  return _objectSpread(_objectSpread({}, discount), {}, {
1752
1778
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1753
1779
  num: item.num,
1754
- custom_product_bundle_map_id: (_item$metadata4 = item.metadata) === null || _item$metadata4 === void 0 ? void 0 : _item$metadata4.custom_product_bundle_map_id
1780
+ custom_product_bundle_map_id: (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.custom_product_bundle_map_id
1755
1781
  })
1756
1782
  // num: item.num, // 使用当前的 num
1757
1783
  });
@@ -1792,8 +1818,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1792
1818
 
1793
1819
  // 🔥 使用更新后的列表计算折扣金额
1794
1820
  var mainDiscountList = updatedMainDiscountList.filter(function (item) {
1795
- var _item$metadata5;
1796
- return !(item !== null && item !== void 0 && (_item$metadata5 = item.metadata) !== null && _item$metadata5 !== void 0 && _item$metadata5.custom_product_bundle_map_id);
1821
+ var _item$metadata3;
1822
+ return !(item !== null && item !== void 0 && (_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.custom_product_bundle_map_id);
1797
1823
  });
1798
1824
  if (mainDiscountList && mainDiscountList.length > 0) {
1799
1825
  var _Decimal$minus$toNumb, _mainProductData$orig;
@@ -1866,8 +1892,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1866
1892
 
1867
1893
  // 🔥 使用更新后的列表计算折扣金额
1868
1894
  var mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(function (item) {
1869
- var _item$metadata6;
1870
- return !(item !== null && item !== void 0 && (_item$metadata6 = item.metadata) !== null && _item$metadata6 !== void 0 && _item$metadata6.custom_product_bundle_map_id);
1895
+ var _item$metadata4;
1896
+ return !(item !== null && item !== void 0 && (_item$metadata4 = item.metadata) !== null && _item$metadata4 !== void 0 && _item$metadata4.custom_product_bundle_map_id);
1871
1897
  });
1872
1898
  if (mainDiscountListOriginal && mainDiscountListOriginal.length > 0) {
1873
1899
  var _Decimal$minus$toNumb2, _mainProductData$orig2;