@pisell/pisellos 2.2.262 → 2.2.264

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 (131) hide show
  1. package/dist/model/strategy/adapter/index.d.ts +0 -4
  2. package/dist/model/strategy/adapter/index.js +1 -5
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  4. package/dist/model/strategy/adapter/promotion/adapter.js +23 -0
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +279 -6
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +86 -0
  8. package/dist/model/strategy/adapter/promotion/examples.js +99 -0
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
  11. package/dist/model/strategy/adapter/promotion/type.js +45 -0
  12. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +10 -16
  13. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +1 -2
  14. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  15. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +1 -32
  16. package/dist/modules/Discount/index.d.ts +2 -5
  17. package/dist/modules/Discount/index.js +7 -30
  18. package/dist/modules/Discount/types.d.ts +0 -4
  19. package/dist/modules/Order/index.d.ts +2 -14
  20. package/dist/modules/Order/index.js +736 -1035
  21. package/dist/modules/Order/types.d.ts +0 -16
  22. package/dist/modules/Order/utils.d.ts +3 -4
  23. package/dist/modules/Order/utils.js +61 -54
  24. package/dist/modules/Product/types.d.ts +0 -22
  25. package/dist/modules/ProductList/index.d.ts +1 -1
  26. package/dist/modules/ProductList/index.js +2 -4
  27. package/dist/modules/ProductList/types.d.ts +0 -2
  28. package/dist/modules/Rules/index.d.ts +9 -2
  29. package/dist/modules/Rules/index.js +43 -69
  30. package/dist/modules/Rules/types.d.ts +1 -10
  31. package/dist/server/index.d.ts +0 -55
  32. package/dist/server/index.js +742 -1161
  33. package/dist/server/modules/order/index.d.ts +4 -10
  34. package/dist/server/modules/order/index.js +399 -404
  35. package/dist/server/modules/order/types.d.ts +0 -4
  36. package/dist/server/modules/products/index.d.ts +8 -31
  37. package/dist/server/modules/products/index.js +390 -549
  38. package/dist/server/modules/products/types.d.ts +0 -18
  39. package/dist/solution/BaseSales/index.d.ts +1 -21
  40. package/dist/solution/BaseSales/index.js +789 -1136
  41. package/dist/solution/BaseSales/types.d.ts +1 -6
  42. package/dist/solution/BaseSales/types.js +1 -1
  43. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  44. package/dist/solution/BaseSales/utils/cartPromotion.js +97 -50
  45. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
  46. package/dist/solution/BaseSales/utils/parseSalesResponse.js +8 -6
  47. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -14
  48. package/dist/solution/BookingByStep/index.d.ts +1 -1
  49. package/dist/solution/BookingTicket/index.js +25 -59
  50. package/dist/solution/BookingTicket/types.d.ts +0 -2
  51. package/dist/solution/ScanOrder/index.js +31 -20
  52. package/dist/solution/ShopDiscount/index.js +14 -15
  53. package/dist/solution/VenueBooking/index.js +30 -19
  54. package/lib/model/strategy/adapter/index.d.ts +0 -4
  55. package/lib/model/strategy/adapter/index.js +2 -13
  56. package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  57. package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
  58. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  59. package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
  60. package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
  61. package/lib/model/strategy/adapter/promotion/examples.js +91 -0
  62. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  63. package/lib/model/strategy/adapter/promotion/index.js +51 -0
  64. package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
  65. package/lib/model/strategy/adapter/promotion/type.js +2 -0
  66. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -5
  67. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -1
  68. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  69. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +2 -23
  70. package/lib/modules/Discount/index.d.ts +2 -5
  71. package/lib/modules/Discount/index.js +3 -23
  72. package/lib/modules/Discount/types.d.ts +0 -4
  73. package/lib/modules/Order/index.d.ts +2 -14
  74. package/lib/modules/Order/index.js +60 -326
  75. package/lib/modules/Order/types.d.ts +0 -16
  76. package/lib/modules/Order/utils.d.ts +3 -4
  77. package/lib/modules/Order/utils.js +23 -22
  78. package/lib/modules/Product/types.d.ts +0 -22
  79. package/lib/modules/ProductList/index.d.ts +1 -1
  80. package/lib/modules/ProductList/index.js +2 -4
  81. package/lib/modules/ProductList/types.d.ts +0 -2
  82. package/lib/modules/Rules/index.d.ts +9 -2
  83. package/lib/modules/Rules/index.js +29 -61
  84. package/lib/modules/Rules/types.d.ts +1 -10
  85. package/lib/server/index.d.ts +0 -55
  86. package/lib/server/index.js +31 -327
  87. package/lib/server/modules/order/index.d.ts +4 -10
  88. package/lib/server/modules/order/index.js +139 -198
  89. package/lib/server/modules/order/types.d.ts +0 -4
  90. package/lib/server/modules/products/index.d.ts +8 -31
  91. package/lib/server/modules/products/index.js +35 -134
  92. package/lib/server/modules/products/types.d.ts +0 -18
  93. package/lib/solution/BaseSales/index.d.ts +1 -21
  94. package/lib/solution/BaseSales/index.js +72 -313
  95. package/lib/solution/BaseSales/types.d.ts +1 -6
  96. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  97. package/lib/solution/BaseSales/utils/cartPromotion.js +64 -25
  98. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
  99. package/lib/solution/BaseSales/utils/parseSalesResponse.js +5 -4
  100. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +0 -8
  101. package/lib/solution/BookingByStep/index.d.ts +1 -1
  102. package/lib/solution/BookingTicket/index.js +8 -33
  103. package/lib/solution/BookingTicket/types.d.ts +0 -2
  104. package/lib/solution/ScanOrder/index.js +8 -0
  105. package/lib/solution/ShopDiscount/index.js +1 -2
  106. package/lib/solution/VenueBooking/index.js +8 -0
  107. package/package.json +1 -1
  108. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
  109. package/dist/model/strategy/adapter/dataVariant/adapter.js +0 -167
  110. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
  111. package/dist/model/strategy/adapter/dataVariant/evaluator.js +0 -780
  112. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  113. package/dist/model/strategy/adapter/dataVariant/examples.js +0 -277
  114. package/dist/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  115. package/dist/model/strategy/adapter/dataVariant/index.js +0 -4
  116. package/dist/model/strategy/adapter/dataVariant/type.d.ts +0 -148
  117. package/dist/model/strategy/adapter/dataVariant/type.js +0 -54
  118. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +0 -53
  119. package/dist/modules/Order/utils/orderCollectionIdentity.js +0 -405
  120. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
  121. package/lib/model/strategy/adapter/dataVariant/adapter.js +0 -149
  122. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
  123. package/lib/model/strategy/adapter/dataVariant/evaluator.js +0 -583
  124. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  125. package/lib/model/strategy/adapter/dataVariant/examples.js +0 -293
  126. package/lib/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  127. package/lib/model/strategy/adapter/dataVariant/index.js +0 -38
  128. package/lib/model/strategy/adapter/dataVariant/type.d.ts +0 -148
  129. package/lib/model/strategy/adapter/dataVariant/type.js +0 -31
  130. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +0 -53
  131. package/lib/modules/Order/utils/orderCollectionIdentity.js +0 -415
@@ -77,19 +77,43 @@ function getOrderProductOriginalPriceForPromotion(product) {
77
77
  }
78
78
  return getOrderProductBasePrice(product);
79
79
  }
80
- function updatePromotionDiscountList(item, promotionDiscount) {
80
+ var X_ITEMS_FOR_Y_PRICE = "X_ITEMS_FOR_Y_PRICE";
81
+ var ITEM_REWARD = "ITEM_REWARD";
82
+ function isItemRewardPromotionDiscountItem(item) {
83
+ var _a, _b;
84
+ return (item == null ? void 0 : item.type) === "product" && ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.source) === "promotion" && ((_b = item == null ? void 0 : item.metadata) == null ? void 0 : _b.actionType) === ITEM_REWARD;
85
+ }
86
+ function isManagedPromotionDiscountItem(item) {
87
+ if ((item == null ? void 0 : item.type) === "promotion")
88
+ return true;
89
+ return isItemRewardPromotionDiscountItem(item);
90
+ }
91
+ function wasInPromotionBeforeEvaluation(item) {
92
+ var _a, _b;
93
+ if (((_b = (_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a._promotion) == null ? void 0 : _b.inPromotion) === true)
94
+ return true;
95
+ return Array.isArray(item == null ? void 0 : item.discount_list) && item.discount_list.some(isItemRewardPromotionDiscountItem);
96
+ }
97
+ function updatePromotionDiscountList(item, promotionDiscount, options) {
81
98
  let discountList = Array.isArray(item.discount_list) ? [...item.discount_list] : [];
82
- discountList = discountList.filter((d) => (d == null ? void 0 : d.type) !== "promotion");
99
+ discountList = discountList.filter((d) => !isManagedPromotionDiscountItem(d));
83
100
  if (promotionDiscount) {
101
+ const discountType = (options == null ? void 0 : options.discountType) || "promotion";
84
102
  discountList.push({
85
- type: "promotion",
103
+ type: discountType,
86
104
  amount: promotionDiscount.amount,
87
105
  discount: {
88
106
  original_amount: promotionDiscount.original_amount,
89
107
  fixed_amount: promotionDiscount.fixed_amount,
90
108
  title: promotionDiscount.title,
91
109
  resource_id: ""
92
- }
110
+ },
111
+ ...discountType === "product" ? {
112
+ metadata: {
113
+ source: "promotion",
114
+ actionType: (options == null ? void 0 : options.actionType) || ITEM_REWARD
115
+ }
116
+ } : {}
93
117
  });
94
118
  }
95
119
  if (discountList.length > 0) {
@@ -98,7 +122,15 @@ function updatePromotionDiscountList(item, promotionDiscount) {
98
122
  delete item.discount_list;
99
123
  }
100
124
  }
101
- var X_ITEMS_FOR_Y_PRICE = "X_ITEMS_FOR_Y_PRICE";
125
+ function evaluatorHasActionType(evaluator, actionType) {
126
+ var _a;
127
+ const configs = (_a = evaluator == null ? void 0 : evaluator.getStrategyConfigs) == null ? void 0 : _a.call(evaluator);
128
+ if (!Array.isArray(configs))
129
+ return false;
130
+ return configs.some(
131
+ (config) => ((config == null ? void 0 : config.actions) || []).some((action) => (action == null ? void 0 : action.type) === actionType)
132
+ );
133
+ }
102
134
  function applyPromoUnitPriceToLine(item, input) {
103
135
  const metadata = item.metadata || (item.metadata = {});
104
136
  const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(item)).toNumber();
@@ -125,6 +157,9 @@ function applyPromoUnitPriceToLine(item, input) {
125
157
  amount: discountAmount,
126
158
  original_amount: catalogSource,
127
159
  fixed_amount: discountAmount
160
+ }, {
161
+ actionType: input.actionType,
162
+ discountType: input.actionType === ITEM_REWARD ? "product" : "promotion"
128
163
  });
129
164
  } else {
130
165
  updatePromotionDiscountList(item, null);
@@ -179,7 +214,6 @@ function mergeIdenticalPromotionCartLines(products) {
179
214
  promotion.finalPrice ?? ((_c = line.metadata) == null ? void 0 : _c.main_product_selling_price) ?? ""
180
215
  );
181
216
  const noteSignature = getProductLineNoteSignature(line);
182
- const lineMergeBoundary = getPromotionLineMergeBoundary(line);
183
217
  const bookingUid = (line == null ? void 0 : line.booking_uid) ?? ((_d = line == null ? void 0 : line.metadata) == null ? void 0 : _d.booking_uid);
184
218
  const orderDetailId = (line == null ? void 0 : line.order_detail_id) ?? (line == null ? void 0 : line.orderDetailId);
185
219
  const mergeKey = [
@@ -187,7 +221,6 @@ function mergeIdenticalPromotionCartLines(products) {
187
221
  line.product_variant_id ?? 0,
188
222
  fingerprint,
189
223
  noteSignature,
190
- lineMergeBoundary,
191
224
  bookingUid ? String(bookingUid) : "",
192
225
  orderDetailId !== void 0 && orderDetailId !== null && orderDetailId !== "" ? String(orderDetailId) : "",
193
226
  promotion.strategyId,
@@ -331,12 +364,6 @@ function getProductLineNoteSignature(product) {
331
364
  const uid = getOrderProductUid(product);
332
365
  return uid ? `note:${uid}` : `note:${normalizedNote}`;
333
366
  }
334
- function getPromotionLineMergeBoundary(product) {
335
- var _a;
336
- if (((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.is_edit_for_runtime) !== true)
337
- return "";
338
- return `edit:${getOrderProductUid(product)}`;
339
- }
340
367
  function isPersistedGeneratedVoucher(product) {
341
368
  const orderDetailId = (product == null ? void 0 : product.order_detail_id) ?? (product == null ? void 0 : product.orderDetailId);
342
369
  if (orderDetailId === void 0 || orderDetailId === null || orderDetailId === "") {
@@ -364,7 +391,6 @@ function buildConsolidateKeyForPromotion(item) {
364
391
  item.product_bundle
365
392
  );
366
393
  const noteSignature = getProductLineNoteSignature(item);
367
- const lineMergeBoundary = getPromotionLineMergeBoundary(item);
368
394
  const bookingUid = (item == null ? void 0 : item.booking_uid) ?? ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.booking_uid);
369
395
  const orderDetailId = (item == null ? void 0 : item.order_detail_id) ?? (item == null ? void 0 : item.orderDetailId);
370
396
  if (orderDetailId !== void 0 && orderDetailId !== null && orderDetailId !== "") {
@@ -373,7 +399,6 @@ function buildConsolidateKeyForPromotion(item) {
373
399
  item.product_variant_id ?? 0,
374
400
  fingerprint,
375
401
  noteSignature,
376
- lineMergeBoundary,
377
402
  String(orderDetailId)
378
403
  ].join("#");
379
404
  }
@@ -383,7 +408,6 @@ function buildConsolidateKeyForPromotion(item) {
383
408
  item.product_variant_id ?? 0,
384
409
  fingerprint,
385
410
  noteSignature,
386
- lineMergeBoundary,
387
411
  String(bookingUid)
388
412
  ].join("#");
389
413
  }
@@ -391,19 +415,17 @@ function buildConsolidateKeyForPromotion(item) {
391
415
  item.product_id,
392
416
  item.product_variant_id ?? 0,
393
417
  fingerprint,
394
- noteSignature,
395
- lineMergeBoundary
418
+ noteSignature
396
419
  ].join("#");
397
420
  }
398
421
  function consolidateMainProductsForPromotion(entries) {
399
- var _a, _b;
400
422
  if (!Array.isArray(entries) || entries.length <= 1) {
401
423
  return [...entries || []];
402
424
  }
403
425
  const groups = /* @__PURE__ */ new Map();
404
426
  for (const { item, originalListIndex } of entries) {
405
427
  const key = buildConsolidateKeyForPromotion(item);
406
- const wasInPromotion = ((_b = (_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a._promotion) == null ? void 0 : _b.inPromotion) === true;
428
+ const wasInPromotion = wasInPromotionBeforeEvaluation(item);
407
429
  const existing = groups.get(key);
408
430
  if (!existing) {
409
431
  const mergedItem = (0, import_lodash_es.cloneDeep)(item);
@@ -469,6 +491,9 @@ function splitXItemsPromoLinesByGroup(lines, strategyActionMap) {
469
491
  function generateNumericId() {
470
492
  return Math.floor(Math.random() * 1e9) + Date.now();
471
493
  }
494
+ function isBookingEditProductLine(product) {
495
+ return (product == null ? void 0 : product.booking_id) !== void 0 && (product == null ? void 0 : product.booking_id) !== null && product.booking_id !== 0 && product.booking_id !== "0";
496
+ }
472
497
  function convertToPromotionProduct(product, index) {
473
498
  const metadata = (product == null ? void 0 : product.metadata) || {};
474
499
  const numericId = generateNumericId();
@@ -481,6 +506,7 @@ function convertToPromotionProduct(product, index) {
481
506
  price: getOrderProductOriginalPriceForPromotion(product),
482
507
  quantity: Number((product == null ? void 0 : product.num) ?? 1) || 1,
483
508
  bundle: getProductBundleForEvaluator(product),
509
+ _promotionOnlyForItemReward: isBookingEditProductLine(product),
484
510
  _originalItem: originalItem,
485
511
  _originalId: getOrderProductUid(product),
486
512
  _originalIndex: index
@@ -582,6 +608,9 @@ function resolveStrategyRequiredQuantity(matched) {
582
608
  if (matched.actionType === "BUY_X_GET_Y_FREE") {
583
609
  return Number(detail.buyQuantity) || 1;
584
610
  }
611
+ if (matched.actionType === "ITEM_REWARD") {
612
+ return Number(detail.triggerQuantity) || 1;
613
+ }
585
614
  return 1;
586
615
  }
587
616
  function resolveStrategyEligibleProducts(matched) {
@@ -692,6 +721,10 @@ function processCartPromotion(list, evaluator, options) {
692
721
  };
693
722
  if (!list || list.length === 0 || !evaluator)
694
723
  return empty;
724
+ const shouldIncludeEditProductsForItemReward = evaluatorHasActionType(
725
+ evaluator,
726
+ ITEM_REWARD
727
+ );
695
728
  const mainProductsWithIndex = [];
696
729
  const existingGiftsWithIndex = [];
697
730
  const editProductsWithIndex = [];
@@ -702,8 +735,12 @@ function processCartPromotion(list, evaluator, options) {
702
735
  editProductsWithIndex.push({ item, originalListIndex: i });
703
736
  } else if (giftInfo) {
704
737
  existingGiftsWithIndex.push({ item, originalListIndex: i });
705
- } else if ((item == null ? void 0 : item.booking_id) !== void 0 && (item == null ? void 0 : item.booking_id) !== null && item.booking_id !== 0 && item.booking_id !== "0") {
706
- editProductsWithIndex.push({ item, originalListIndex: i });
738
+ } else if (isBookingEditProductLine(item)) {
739
+ if (shouldIncludeEditProductsForItemReward) {
740
+ mainProductsWithIndex.push({ item, originalListIndex: i });
741
+ } else {
742
+ editProductsWithIndex.push({ item, originalListIndex: i });
743
+ }
707
744
  } else {
708
745
  mainProductsWithIndex.push({ item, originalListIndex: i });
709
746
  }
@@ -746,7 +783,8 @@ function processCartPromotion(list, evaluator, options) {
746
783
  name: ((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.product_name) || (item == null ? void 0 : item.title) || "",
747
784
  price: getOrderProductBasePrice(item),
748
785
  quantity: Number((item == null ? void 0 : item.num) ?? 1) || 1,
749
- bundle: getProductBundleForEvaluator(item)
786
+ bundle: getProductBundleForEvaluator(item),
787
+ _promotionOnlyForItemReward: isBookingEditProductLine(item)
750
788
  };
751
789
  });
752
790
  for (let i = 0; i < consolidatedMainProductsWithIndex.length; i++) {
@@ -815,7 +853,7 @@ function processCartPromotion(list, evaluator, options) {
815
853
  const metadata = newItem.metadata || {};
816
854
  const sourceCartNum = (0, import_utils2.getSafeProductNum)(originalItem.num);
817
855
  newItem._sourceCartNum = sourceCartNum;
818
- const wasInPromotion = ((_a = metadata._promotion) == null ? void 0 : _a.inPromotion) === true || originalItem._wasInPromotionBeforeConsolidate === true;
856
+ const wasInPromotion = wasInPromotionBeforeEvaluation(originalItem) || originalItem._wasInPromotionBeforeConsolidate === true;
819
857
  delete metadata._promotion;
820
858
  if (Array.isArray(newItem.product_bundle)) {
821
859
  for (const b of newItem.product_bundle) {
@@ -832,7 +870,8 @@ function processCartPromotion(list, evaluator, options) {
832
870
  applyPromoUnitPriceToLine(newItem, {
833
871
  promoUnitPrice,
834
872
  originalBasePrice,
835
- strategyTitle: (_b = priced.strategyMetadata) == null ? void 0 : _b.name
873
+ strategyTitle: (_a = priced.strategyMetadata) == null ? void 0 : _a.name,
874
+ actionType: priced.strategyId ? (_b = strategyActionMap.get(priced.strategyId)) == null ? void 0 : _b.actionType : void 0
836
875
  });
837
876
  } else {
838
877
  const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(newItem)).toNumber();
@@ -2,7 +2,7 @@
2
2
  * 把 `/order/sales/{id}` 响应(OrderData)解析为 ISalesDetail。
3
3
  *
4
4
  * - 纯函数:不依赖任何运行时模块/插件,便于单测与 view-model 适配
5
- * - products 保留 tempOrder / 后端详情原字段,仅规范化集合身份并浅拷贝,避免丢失 product_sku 等协议字段
5
+ * - products 保留 tempOrder / 后端详情原字段,仅做浅拷贝,避免丢失 product_sku 等协议字段
6
6
  * - bookings 平铺保留服务端原顺序,同时输出 byProductUid 反查表与 rootBooking
7
7
  * - header 收敛"非数组顶层字段",便于 ticketBooking view-model 直接消费
8
8
  *
@@ -130,7 +130,7 @@ export interface ISalesDetail {
130
130
  customer: ISalesDetailCustomer | null;
131
131
  /** 服务端 summary(仅输出) */
132
132
  summary: Record<string, any>;
133
- /** 规范化后的响应快照,方便 UI 兜底使用 */
133
+ /** 原始响应快照,方便 UI 兜底使用 */
134
134
  raw: Record<string, any>;
135
135
  }
136
136
  /**
@@ -138,7 +138,7 @@ export interface ISalesDetail {
138
138
  *
139
139
  * 注意:
140
140
  * - 入参允许是 `{ data: OrderData }` 或直接 `OrderData`,自动识别。
141
- * - products/bookings/payments 在此补齐集合身份;其余 runtime 字段由 OrderModule hydrate 负责。
141
+ * - products 保留原字段;字段补齐由 OrderModule hydrate 负责。
142
142
  * - 不做远程请求;不修改入参;返回新对象。
143
143
  */
144
144
  export declare function parseSalesResponse(input: Record<string, any> | null | undefined): ISalesDetail;
@@ -22,7 +22,6 @@ __export(parseSalesResponse_exports, {
22
22
  parseSalesResponse: () => parseSalesResponse
23
23
  });
24
24
  module.exports = __toCommonJS(parseSalesResponse_exports);
25
- var import_orderCollectionIdentity = require("../../../modules/Order/utils/orderCollectionIdentity");
26
25
  var HEADER_KEYS = [
27
26
  "order_id",
28
27
  "order_number",
@@ -122,12 +121,14 @@ function indexBookingsByProductUid(bookings) {
122
121
  return result;
123
122
  }
124
123
  function parseSalesResponse(input) {
125
- const sourceRaw = input && typeof input === "object" && input.data && input.order_id == null ? input.data : input || {};
126
- const raw = (0, import_orderCollectionIdentity.normalizeOrderCollections)(sourceRaw).order;
124
+ const raw = input && typeof input === "object" && input.data && input.order_id == null ? input.data : input || {};
127
125
  const productsRaw = Array.isArray(raw == null ? void 0 : raw.products) ? raw.products : [];
128
- const products = productsRaw.map((p) => {
126
+ const products = productsRaw.map((p, index) => {
129
127
  const row = { ...p || {} };
130
128
  const metadata = row.metadata && typeof row.metadata === "object" ? { ...row.metadata } : {};
129
+ if (!metadata.unique_identification_number) {
130
+ metadata.unique_identification_number = `sales-product-${row.product_id ?? "unknown"}-${row.product_variant_id ?? 0}-${index}`;
131
+ }
131
132
  delete metadata.price_schema_version;
132
133
  delete row.identity_key;
133
134
  return { ...row, metadata };
@@ -50,12 +50,6 @@ function toPriceString(value, fallback = "0.00") {
50
50
  return fallback;
51
51
  return parsedValue.toFixed(2);
52
52
  }
53
- function isBlankValue(value) {
54
- return value === void 0 || value === null || typeof value === "string" && value.trim() === "";
55
- }
56
- function firstNonBlank(...values) {
57
- return values.find((value) => !isBlankValue(value));
58
- }
59
53
  function normalizeOptionItems(optionItems) {
60
54
  if (!Array.isArray(optionItems))
61
55
  return [];
@@ -204,7 +198,6 @@ function transformBaseProductToOrderProduct(params) {
204
198
  main_product_selling_price: mainProductSellingPrice,
205
199
  main_product_original_price: mainProductOriginalPrice,
206
200
  price_schema_version: 2,
207
- holder_config: sourceProduct == null ? void 0 : sourceProduct.holder_config,
208
201
  ...hasPriceOverride ? {
209
202
  price_override: String(payload.price_override),
210
203
  is_manual_discount: 1
@@ -243,7 +236,6 @@ function transformBaseProductToOrderProduct(params) {
243
236
  metadata,
244
237
  note: payload.note != null ? String(payload.note) : "",
245
238
  product_title: productTitle,
246
- product_cover: firstNonBlank(matchedVariant == null ? void 0 : matchedVariant.cover, sourceProduct == null ? void 0 : sourceProduct.cover),
247
239
  _origin: {
248
240
  ...sourceProduct || {},
249
241
  callbackData: payload
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 2 | 1 | 6 | 4 | 3 | 5;
314
+ weekNum: 0 | 2 | 1 | 5 | 3 | 4 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -341,28 +341,15 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
341
341
  if (!this.store.order)
342
342
  throw new Error("order 模块未初始化");
343
343
  const raw = await this.store.order.scanCode(code, customerId);
344
- const scannedList = raw.scannedDiscountList || [];
345
- const extractedCustomerId = this.getDiscountCustomerId(scannedList);
346
- const hasOrderCustomer = Boolean(this.store.order.getOrderCustomer());
347
- if (!hasOrderCustomer && extractedCustomerId) {
348
- await this.hydrateOrderCustomerFromScanDiscounts(scannedList);
349
- }
350
344
  if (raw.isAvailable) {
345
+ await this.hydrateOrderCustomerFromScanDiscounts(raw.scannedDiscountList || []);
351
346
  await this.store.order.recalculateSummary({ createIfMissing: true });
352
347
  this.store.order.persistTempOrder();
353
- const tempOrder = this.store.order.ensureTempOrder();
354
- await this.effectsEmit("onDiscountApplied", {
355
- productList: tempOrder.products || [],
356
- discountList: this.store.order.getDiscountList(),
357
- selectedDiscountList: tempOrder.discount_list || [],
358
- tempOrder
359
- });
360
348
  }
361
349
  return {
362
350
  isAvailable: raw.isAvailable,
363
351
  type: raw.type,
364
- unavailableReason: raw.unavailableReason,
365
- scannedDiscountList: raw.scannedDiscountList
352
+ unavailableReason: raw.unavailableReason
366
353
  };
367
354
  }
368
355
  async hydrateOrderCustomerFromScanDiscounts(discounts) {
@@ -379,13 +366,11 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
379
366
  this.setOrderCustomer(customer);
380
367
  }
381
368
  getDiscountCustomerId(discounts) {
382
- for (const item of discounts) {
383
- const topLevelId = Number(item.customer_id);
384
- if (Number.isFinite(topLevelId) && topLevelId > 0) {
385
- return topLevelId;
386
- }
387
- }
388
- return null;
369
+ const discount = discounts.find((item) => item.customer_id != null);
370
+ const customerId = Number(discount == null ? void 0 : discount.customer_id);
371
+ if (!Number.isFinite(customerId) || customerId <= 0)
372
+ return null;
373
+ return customerId;
389
374
  }
390
375
  async resolveCustomerByDiscountCustomerId(customerId) {
391
376
  var _a;
@@ -877,17 +862,7 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
877
862
  void ((_a = discountModule == null ? void 0 : discountModule.setOriginalDiscountList) == null ? void 0 : _a.call(discountModule, []));
878
863
  void ((_b = discountModule == null ? void 0 : discountModule.setDiscountList) == null ? void 0 : _b.call(discountModule, []));
879
864
  this.store.order.applyDiscount();
880
- void this.store.order.recalculateSummary({ createIfMissing: true }).then(() => {
881
- var _a2;
882
- const tempOrder = this.store.order.ensureTempOrder();
883
- this.store.order.persistTempOrder();
884
- return this.effectsEmit("onDiscountApplied", {
885
- productList: tempOrder.products || [],
886
- discountList: ((_a2 = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _a2.call(discountModule)) || [],
887
- selectedDiscountList: tempOrder.discount_list || [],
888
- tempOrder
889
- });
890
- }).catch((error) => {
865
+ void this.store.order.recalculateSummary({ createIfMissing: true }).then(() => this.store.order.persistTempOrder()).catch((error) => {
891
866
  console.error("Failed to recalculate summary after clearing customer:", error);
892
867
  });
893
868
  this.core.effects.emit(`${this.name}:onOrderCustomerChange`, null);
@@ -83,8 +83,6 @@ export interface ILoadProductsParams {
83
83
  extension_type?: string[];
84
84
  /** 商品发布状态 */
85
85
  status?: string;
86
- /** 智能定价条件上下文,仅影响策略命中,不参与商品集合筛选 */
87
- strategy_context?: Record<string, any>;
88
86
  }
89
87
  /**
90
88
  * 加载商品详情的参数
@@ -48,6 +48,10 @@ var import_utils2 = require("../../modules/Order/utils");
48
48
  var import_dayjs = __toESM(require("dayjs"));
49
49
  var import_itemRule = require("../../model/strategy/adapter/itemRule");
50
50
  __reExport(ScanOrder_exports, require("./types"), module.exports);
51
+ function isItemRewardProductDiscount(discount) {
52
+ var _a, _b;
53
+ return (discount == null ? void 0 : discount.type) === "product" && ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.source) === "promotion" && ((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.actionType) === "ITEM_REWARD";
54
+ }
51
55
  var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
52
56
  constructor(name, version) {
53
57
  super(name, version);
@@ -742,6 +746,10 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
742
746
  for (const product of tempOrder.products) {
743
747
  if ((_c = product._origin) == null ? void 0 : _c.isManualDiscount)
744
748
  continue;
749
+ if ((product.discount_list || []).some(isItemRewardProductDiscount)) {
750
+ product.discount_list = (product.discount_list || []).filter(isItemRewardProductDiscount);
751
+ continue;
752
+ }
745
753
  product.discount_list = (product.discount_list || []).filter((pd) => {
746
754
  var _a2;
747
755
  const rid = ((_a2 = pd.discount) == null ? void 0 : _a2.resource_id) ?? pd.id;
@@ -505,7 +505,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
505
505
  try {
506
506
  const orderId = this.store.orderId;
507
507
  const customerId = params.customerId || ((_a = this.getCustomer()) == null ? void 0 : _a.id);
508
- const prepareConfigResult = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
508
+ const goodPassList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
509
509
  customer_id: customerId,
510
510
  action: orderId ? "edit" : "create",
511
511
  with_good_pass: 1,
@@ -514,7 +514,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
514
514
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
515
515
  ...orderId ? { order_id: orderId } : {}
516
516
  }));
517
- const goodPassList = (prepareConfigResult == null ? void 0 : prepareConfigResult.discountList) || [];
518
517
  const scanDiscount = (_c = this.getDiscountList()) == null ? void 0 : _c.filter(
519
518
  (item) => item.isScan
520
519
  );
@@ -65,6 +65,10 @@ var OPEN_DATA_SECTION_CODES = [
65
65
  "workflow",
66
66
  "checkout"
67
67
  ];
68
+ function isItemRewardProductDiscount(discount) {
69
+ var _a, _b;
70
+ return (discount == null ? void 0 : discount.type) === "product" && ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.source) === "promotion" && ((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.actionType) === "ITEM_REWARD";
71
+ }
68
72
  function cloneCustomDepositData(customDepositData) {
69
73
  if (!customDepositData || typeof customDepositData !== "object")
70
74
  return void 0;
@@ -1339,6 +1343,10 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
1339
1343
  for (const product of tempOrder.products) {
1340
1344
  if ((_c = product._origin) == null ? void 0 : _c.isManualDiscount)
1341
1345
  continue;
1346
+ if ((product.discount_list || []).some(isItemRewardProductDiscount)) {
1347
+ product.discount_list = (product.discount_list || []).filter(isItemRewardProductDiscount);
1348
+ continue;
1349
+ }
1342
1350
  product.discount_list = (product.discount_list || []).filter((pd) => {
1343
1351
  var _a2;
1344
1352
  const rid = ((_a2 = pd.discount) == null ? void 0 : _a2.resource_id) ?? pd.id;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.262",
4
+ "version": "2.2.264",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -1,50 +0,0 @@
1
- import type { EvaluationResult, RuntimeContext } from '../../type';
2
- import type { BusinessAdapter } from '../type';
3
- import type { DataVariantBusinessData, DataVariantProduct } from './type';
4
- /**
5
- * Data Variant 适配器。
6
- *
7
- * 负责把智能定价运行态数据转换为 StrategyEngine 能识别的 attributes。
8
- */
9
- export declare class DataVariantAdapter implements BusinessAdapter {
10
- name: string;
11
- version: string;
12
- /**
13
- * 准备批量全局上下文。
14
- *
15
- * 这里只放不依赖单个商品的字段,用于预计算 schedule/channel/orderType 等条件。
16
- */
17
- prepareContext(businessData: DataVariantBusinessData): RuntimeContext;
18
- /**
19
- * 准备全局预计算上下文。
20
- */
21
- prepareGlobalContext(businessData: DataVariantBusinessData): RuntimeContext;
22
- /**
23
- * 准备单商品上下文。
24
- *
25
- * 商品级条件只在当前商品 data_variants 引用到对应规则后才评估。
26
- */
27
- prepareProductContext(businessData: DataVariantBusinessData, product: DataVariantProduct): RuntimeContext;
28
- transformResult(result: EvaluationResult): EvaluationResult;
29
- formatConfig(result: EvaluationResult, businessData?: DataVariantBusinessData): {
30
- result: EvaluationResult;
31
- businessData?: DataVariantBusinessData;
32
- };
33
- /**
34
- * 构建 menu_match 使用的轻量商品对象。
35
- *
36
- * collection_ids 来自商品 collection 字段,避免 operator 读取复杂商品对象。
37
- */
38
- buildProductValue(product: DataVariantProduct): {
39
- id: number;
40
- product_variant_id: number;
41
- collection_ids: number[];
42
- };
43
- private toNumber;
44
- /**
45
- * 归一化客户 id:无效值返回 undefined,有效值统一为 number。
46
- */
47
- private normalizeCustomerId;
48
- private normalizeNumberArray;
49
- }
50
- export default DataVariantAdapter;