@pisell/pisellos 2.3.38 → 2.3.39

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 (225) hide show
  1. package/dist/core/index.d.ts +0 -2
  2. package/dist/core/index.js +0 -7
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  4. package/dist/model/strategy/adapter/promotion/adapter.js +0 -23
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +6 -279
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +0 -86
  8. package/dist/model/strategy/adapter/promotion/examples.js +0 -99
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/type.d.ts +2 -90
  11. package/dist/model/strategy/adapter/promotion/type.js +0 -45
  12. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +3 -5
  13. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +3 -6
  14. package/dist/modules/Discount/index.d.ts +1 -0
  15. package/dist/modules/Discount/index.js +40 -11
  16. package/dist/modules/Discount/types.d.ts +1 -0
  17. package/dist/modules/Holder/index.d.ts +48 -0
  18. package/dist/modules/Holder/index.js +640 -0
  19. package/dist/modules/Holder/types.d.ts +123 -0
  20. package/dist/modules/Holder/types.js +1 -0
  21. package/dist/modules/Holder/utils.d.ts +13 -0
  22. package/dist/modules/Holder/utils.js +34 -0
  23. package/dist/modules/OpenData/index.d.ts +0 -2
  24. package/dist/modules/OpenData/index.js +2 -10
  25. package/dist/modules/Order/index.d.ts +11 -28
  26. package/dist/modules/Order/index.js +509 -750
  27. package/dist/modules/Order/types.d.ts +10 -33
  28. package/dist/modules/Order/utils/orderCollectionIdentity.js +2 -7
  29. package/dist/modules/Order/utils.d.ts +10 -0
  30. package/dist/modules/Order/utils.js +41 -13
  31. package/dist/modules/Payment/index.d.ts +0 -2
  32. package/dist/modules/Payment/index.js +50 -79
  33. package/dist/modules/Payment/types.d.ts +28 -99
  34. package/dist/modules/Payment/types.js +3 -20
  35. package/dist/modules/Payment/walletpass.d.ts +1 -25
  36. package/dist/modules/Payment/walletpass.js +157 -707
  37. package/dist/modules/Product/types.d.ts +1 -0
  38. package/dist/modules/ProductList/index.js +33 -14
  39. package/dist/modules/Quotation/index.d.ts +1 -1
  40. package/dist/modules/Quotation/index.js +2 -2
  41. package/dist/modules/ResourcePlanner/index.d.ts +24 -0
  42. package/dist/modules/ResourcePlanner/index.js +181 -0
  43. package/dist/modules/ResourcePlanner/planner.d.ts +14 -0
  44. package/dist/modules/ResourcePlanner/planner.js +1069 -0
  45. package/dist/modules/ResourcePlanner/types.d.ts +227 -0
  46. package/dist/modules/ResourcePlanner/types.js +1 -0
  47. package/dist/modules/Rules/index.d.ts +0 -1
  48. package/dist/modules/Rules/index.js +96 -89
  49. package/dist/modules/SalesSummary/index.js +12 -13
  50. package/dist/modules/ScanOrderLogger/index.d.ts +2 -0
  51. package/dist/modules/ScanOrderLogger/index.js +15 -2
  52. package/dist/modules/ScanOrderLogger/providers/feishu.js +45 -27
  53. package/dist/modules/ScanOrderLogger/types.d.ts +1 -0
  54. package/dist/modules/Schedule/index.d.ts +3 -1
  55. package/dist/modules/Schedule/index.js +21 -16
  56. package/dist/modules/Summary/utils.js +38 -13
  57. package/dist/modules/index.d.ts +2 -0
  58. package/dist/modules/index.js +3 -1
  59. package/dist/plugins/window.d.ts +1 -0
  60. package/dist/server/index.d.ts +14 -16
  61. package/dist/server/index.js +1148 -1930
  62. package/dist/server/modules/order/index.d.ts +4 -54
  63. package/dist/server/modules/order/index.js +695 -1595
  64. package/dist/server/modules/order/types.d.ts +3 -11
  65. package/dist/server/modules/order/types.js +1 -1
  66. package/dist/solution/BaseSales/index.d.ts +20 -109
  67. package/dist/solution/BaseSales/index.js +481 -1797
  68. package/dist/solution/BaseSales/types.d.ts +0 -52
  69. package/dist/solution/BaseSales/types.js +1 -2
  70. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  71. package/dist/solution/BaseSales/utils/cartPromotion.js +31 -90
  72. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  73. package/dist/solution/BookingByStep/index.d.ts +17 -2
  74. package/dist/solution/BookingByStep/index.js +294 -215
  75. package/dist/solution/BookingByStep/types.d.ts +2 -1
  76. package/dist/solution/BookingByStep/types.js +3 -1
  77. package/dist/solution/BookingByStep/utils/capacity.js +17 -1
  78. package/dist/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  79. package/dist/solution/BookingByStep/utils/timeslots.js +19 -12
  80. package/dist/solution/BookingTicket/index.d.ts +3 -7
  81. package/dist/solution/BookingTicket/index.js +49 -132
  82. package/dist/solution/BookingTicket/utils/addProductDecision.js +0 -6
  83. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -8
  84. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +82 -172
  85. package/dist/solution/Sales/index.d.ts +0 -1
  86. package/dist/solution/Sales/index.js +2 -10
  87. package/dist/solution/ScanOrder/index.d.ts +26 -14
  88. package/dist/solution/ScanOrder/index.js +1148 -756
  89. package/dist/solution/ScanOrder/types.d.ts +21 -1
  90. package/dist/solution/ScanOrder/utils.d.ts +8 -0
  91. package/dist/solution/ScanOrder/utils.js +66 -25
  92. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  93. package/dist/solution/ShopDiscount/index.js +125 -87
  94. package/dist/solution/UnifiedBookingSales/index.d.ts +183 -0
  95. package/dist/solution/UnifiedBookingSales/index.js +1871 -0
  96. package/dist/solution/UnifiedBookingSales/types.d.ts +143 -0
  97. package/dist/solution/UnifiedBookingSales/types.js +11 -0
  98. package/dist/solution/VenueBooking/index.d.ts +39 -11
  99. package/dist/solution/VenueBooking/index.js +1176 -860
  100. package/dist/solution/VenueBooking/types.d.ts +3 -0
  101. package/dist/solution/VenueBooking/utils/resource.js +1 -0
  102. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -4
  103. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -5
  104. package/dist/solution/index.d.ts +1 -0
  105. package/dist/solution/index.js +2 -1
  106. package/dist/types/index.d.ts +1 -1
  107. package/lib/core/index.d.ts +0 -2
  108. package/lib/core/index.js +0 -4
  109. package/lib/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  110. package/lib/model/strategy/adapter/promotion/adapter.js +0 -20
  111. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  112. package/lib/model/strategy/adapter/promotion/evaluator.js +0 -235
  113. package/lib/model/strategy/adapter/promotion/examples.d.ts +0 -86
  114. package/lib/model/strategy/adapter/promotion/examples.js +0 -91
  115. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  116. package/lib/model/strategy/adapter/promotion/index.js +0 -51
  117. package/lib/model/strategy/adapter/promotion/type.d.ts +2 -90
  118. package/lib/model/strategy/adapter/promotion/type.js +0 -2
  119. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +1 -2
  120. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +1 -2
  121. package/lib/modules/Discount/index.d.ts +1 -0
  122. package/lib/modules/Discount/index.js +9 -0
  123. package/lib/modules/Discount/types.d.ts +1 -0
  124. package/lib/modules/Holder/index.d.ts +48 -0
  125. package/lib/modules/Holder/index.js +402 -0
  126. package/lib/modules/Holder/types.d.ts +123 -0
  127. package/lib/modules/Holder/types.js +17 -0
  128. package/lib/modules/Holder/utils.d.ts +13 -0
  129. package/lib/modules/Holder/utils.js +71 -0
  130. package/lib/modules/OpenData/index.d.ts +0 -2
  131. package/lib/modules/OpenData/index.js +1 -6
  132. package/lib/modules/Order/index.d.ts +11 -28
  133. package/lib/modules/Order/index.js +86 -196
  134. package/lib/modules/Order/types.d.ts +10 -33
  135. package/lib/modules/Order/utils/orderCollectionIdentity.js +0 -3
  136. package/lib/modules/Order/utils.d.ts +10 -0
  137. package/lib/modules/Order/utils.js +40 -16
  138. package/lib/modules/Payment/index.d.ts +0 -2
  139. package/lib/modules/Payment/index.js +13 -34
  140. package/lib/modules/Payment/types.d.ts +28 -99
  141. package/lib/modules/Payment/types.js +3 -4
  142. package/lib/modules/Payment/walletpass.d.ts +1 -25
  143. package/lib/modules/Payment/walletpass.js +21 -470
  144. package/lib/modules/Product/types.d.ts +1 -0
  145. package/lib/modules/ProductList/index.js +40 -31
  146. package/lib/modules/Quotation/index.d.ts +1 -1
  147. package/lib/modules/Quotation/index.js +2 -2
  148. package/lib/modules/ResourcePlanner/index.d.ts +24 -0
  149. package/lib/modules/ResourcePlanner/index.js +148 -0
  150. package/lib/modules/ResourcePlanner/planner.d.ts +14 -0
  151. package/lib/modules/ResourcePlanner/planner.js +933 -0
  152. package/lib/modules/ResourcePlanner/types.d.ts +227 -0
  153. package/lib/modules/ResourcePlanner/types.js +17 -0
  154. package/lib/modules/Rules/index.d.ts +0 -1
  155. package/lib/modules/Rules/index.js +40 -47
  156. package/lib/modules/SalesSummary/index.js +6 -7
  157. package/lib/modules/ScanOrderLogger/index.d.ts +2 -0
  158. package/lib/modules/ScanOrderLogger/index.js +13 -1
  159. package/lib/modules/ScanOrderLogger/providers/feishu.js +15 -6
  160. package/lib/modules/ScanOrderLogger/types.d.ts +1 -0
  161. package/lib/modules/Schedule/index.d.ts +3 -1
  162. package/lib/modules/Schedule/index.js +10 -8
  163. package/lib/modules/Summary/utils.js +21 -1
  164. package/lib/modules/index.d.ts +2 -0
  165. package/lib/modules/index.js +5 -1
  166. package/lib/plugins/window.d.ts +1 -0
  167. package/lib/server/index.d.ts +14 -16
  168. package/lib/server/index.js +83 -675
  169. package/lib/server/modules/order/index.d.ts +4 -54
  170. package/lib/server/modules/order/index.js +66 -679
  171. package/lib/server/modules/order/types.d.ts +3 -11
  172. package/lib/solution/BaseSales/index.d.ts +20 -109
  173. package/lib/solution/BaseSales/index.js +70 -881
  174. package/lib/solution/BaseSales/types.d.ts +0 -52
  175. package/lib/solution/BaseSales/types.js +1 -2
  176. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  177. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -63
  178. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  179. package/lib/solution/BookingByStep/index.d.ts +17 -2
  180. package/lib/solution/BookingByStep/index.js +60 -18
  181. package/lib/solution/BookingByStep/types.d.ts +2 -1
  182. package/lib/solution/BookingByStep/types.js +5 -0
  183. package/lib/solution/BookingByStep/utils/capacity.js +20 -1
  184. package/lib/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  185. package/lib/solution/BookingByStep/utils/timeslots.js +19 -11
  186. package/lib/solution/BookingTicket/index.d.ts +3 -7
  187. package/lib/solution/BookingTicket/index.js +9 -62
  188. package/lib/solution/BookingTicket/utils/addProductDecision.js +0 -4
  189. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -8
  190. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +4 -36
  191. package/lib/solution/Sales/index.d.ts +0 -1
  192. package/lib/solution/Sales/index.js +3 -5
  193. package/lib/solution/ScanOrder/index.d.ts +26 -14
  194. package/lib/solution/ScanOrder/index.js +449 -190
  195. package/lib/solution/ScanOrder/types.d.ts +21 -1
  196. package/lib/solution/ScanOrder/utils.d.ts +8 -0
  197. package/lib/solution/ScanOrder/utils.js +31 -0
  198. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  199. package/lib/solution/ShopDiscount/index.js +14 -0
  200. package/lib/solution/UnifiedBookingSales/index.d.ts +183 -0
  201. package/lib/solution/UnifiedBookingSales/index.js +1076 -0
  202. package/lib/solution/UnifiedBookingSales/types.d.ts +143 -0
  203. package/lib/solution/UnifiedBookingSales/types.js +33 -0
  204. package/lib/solution/VenueBooking/index.d.ts +39 -11
  205. package/lib/solution/VenueBooking/index.js +328 -123
  206. package/lib/solution/VenueBooking/types.d.ts +3 -0
  207. package/lib/solution/VenueBooking/utils/resource.js +1 -0
  208. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -4
  209. package/lib/solution/VenueBooking/utils/slotMerge.js +6 -4
  210. package/lib/solution/index.d.ts +1 -0
  211. package/lib/solution/index.js +3 -1
  212. package/lib/types/index.d.ts +1 -1
  213. package/package.json +1 -1
  214. package/dist/modules/Order/payment-utils.d.ts +0 -26
  215. package/dist/modules/Order/payment-utils.js +0 -225
  216. package/dist/solution/BookingTicket/utils/weighingProductSku.d.ts +0 -5
  217. package/dist/solution/BookingTicket/utils/weighingProductSku.js +0 -45
  218. package/dist/utils/payment-number.d.ts +0 -9
  219. package/dist/utils/payment-number.js +0 -69
  220. package/lib/modules/Order/payment-utils.d.ts +0 -26
  221. package/lib/modules/Order/payment-utils.js +0 -224
  222. package/lib/solution/BookingTicket/utils/weighingProductSku.d.ts +0 -5
  223. package/lib/solution/BookingTicket/utils/weighingProductSku.js +0 -63
  224. package/lib/utils/payment-number.d.ts +0 -9
  225. package/lib/utils/payment-number.js +0 -64
@@ -28,8 +28,6 @@ declare class PisellOSCore implements PisellCore {
28
28
  getModule<T extends Module>(name: string): T | null;
29
29
  getModuleExports<T = any>(name: string): T | null;
30
30
  hasModule(name: string): boolean;
31
- /** 返回当前已注册模块名,供宿主在切换店铺等生命周期中定向清理运行态。 */
32
- getModuleNames(): string[];
33
31
  destroy(): Promise<void>;
34
32
  setContext(ctx: Partial<BusinessContext>): void;
35
33
  /**
@@ -300,13 +300,6 @@ var PisellOSCore = /*#__PURE__*/function () {
300
300
  return this.modules.has(name);
301
301
  }
302
302
 
303
- /** 返回当前已注册模块名,供宿主在切换店铺等生命周期中定向清理运行态。 */
304
- }, {
305
- key: "getModuleNames",
306
- value: function getModuleNames() {
307
- return Array.from(this.modules.keys());
308
- }
309
-
310
303
  // 销毁方法
311
304
  }, {
312
305
  key: "destroy",
@@ -48,10 +48,6 @@ export declare class PromotionAdapter implements BusinessAdapter {
48
48
  * 解析 买X送Y Action
49
49
  */
50
50
  private parseBuyXGetYFreeAction;
51
- /**
52
- * 解析 商品奖励 Action
53
- */
54
- private parseItemRewardAction;
55
51
  /**
56
52
  * 获取适用的商品列表
57
53
  *
@@ -162,8 +162,6 @@ export var PromotionAdapter = /*#__PURE__*/function () {
162
162
  return this.parseXItemsForYPriceAction(action);
163
163
  case PROMOTION_ACTION_TYPES.BUY_X_GET_Y_FREE:
164
164
  return this.parseBuyXGetYFreeAction(action);
165
- case PROMOTION_ACTION_TYPES.ITEM_REWARD:
166
- return this.parseItemRewardAction(action);
167
165
  default:
168
166
  return undefined;
169
167
  }
@@ -206,27 +204,6 @@ export var PromotionAdapter = /*#__PURE__*/function () {
206
204
  };
207
205
  }
208
206
 
209
- /**
210
- * 解析 商品奖励 Action
211
- */
212
- }, {
213
- key: "parseItemRewardAction",
214
- value: function parseItemRewardAction(action) {
215
- var value = action.value || {};
216
- var config = action.config || {};
217
- return {
218
- type: PROMOTION_ACTION_TYPES.ITEM_REWARD,
219
- rewardMethod: value.rewardMethod || 'free',
220
- rewardValue: Number(value.rewardValue || 0),
221
- quantityRule: value.quantityRule || 'per_condition_quantity',
222
- triggerQuantity: Number(value.triggerQuantity || 1),
223
- rewardQuantity: Number(value.rewardQuantity || 1),
224
- maxRewardQuantity: value.maxRewardQuantity === undefined || value.maxRewardQuantity === null ? undefined : Number(value.maxRewardQuantity),
225
- rewardTargets: Array.isArray(config.rewardTargets) ? config.rewardTargets : [],
226
- targetSelection: config.targetSelection || 'consumer_best'
227
- };
228
- }
229
-
230
207
  /**
231
208
  * 获取适用的商品列表
232
209
  *
@@ -169,21 +169,6 @@ export declare class PromotionEvaluator {
169
169
  * 支持 bundle 子商品的数量计算(主商品数量 × 子商品数量)
170
170
  */
171
171
  private processBuyXGetYFree;
172
- /**
173
- * 处理 商品奖励 促销
174
- *
175
- * 1. 使用 group.products 统计触发条件商品数量
176
- * 2. 按 quantityRule 计算最多奖励的目标商品数量
177
- * 3. 在全购物车商品中筛选 rewardTargets
178
- * 4. 按消费者最优(可节省金额从高到低)选择目标单位
179
- * 5. 对目标商品拆分并写入 finalPrice,触发商品本身不改价
180
- */
181
- private processItemReward;
182
- private normalizePositiveInteger;
183
- private getAvailablePromotionQuantity;
184
- private buildItemRewardTargetUnits;
185
- private resolveItemRewardFinalPrice;
186
- private resolveItemRewardLimit;
187
172
  /**
188
173
  * 获取未参与任何促销的商品
189
174
  */
@@ -209,8 +194,6 @@ export declare class PromotionEvaluator {
209
194
  * 检查商品是否在策略的适用范围内
210
195
  */
211
196
  private isProductInStrategy;
212
- private shouldSkipStrategyForProduct;
213
- private hasActionType;
214
197
  /**
215
198
  * 查找商品匹配规则
216
199
  */
@@ -178,10 +178,6 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
178
178
  try {
179
179
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
180
180
  var config = _step2.value;
181
- if (this.shouldSkipStrategyForProduct(product, config)) {
182
- continue;
183
- }
184
-
185
181
  // 1. 先用 getProductMatchInfo 检查商品是否在策略的适用范围内(包含 bundle 子商品检查)
186
182
  var matchInfo = this.getProductMatchInfo(product, config);
187
183
  if (!matchInfo.isMatch) {
@@ -404,12 +400,6 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
404
400
  if (_result.giftInfo) {
405
401
  gifts.push(_result.giftInfo);
406
402
  }
407
- } else if (actionType === PROMOTION_ACTION_TYPES.ITEM_REWARD) {
408
- // 商品奖励处理:条件商品触发,目标商品行享优惠,不自动新增商品
409
- var _result2 = this.processItemReward(group, processedQuantityMap, products, matchedBundleIndexMap);
410
- pricedProducts.push.apply(pricedProducts, _toConsumableArray(_result2.products));
411
- totalOriginalAmount = totalOriginalAmount.plus(_result2.originalAmount);
412
- totalFinalAmount = totalFinalAmount.plus(_result2.finalAmount);
413
403
  }
414
404
  }
415
405
 
@@ -540,9 +530,6 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
540
530
  try {
541
531
  for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
542
532
  var config = _step8.value;
543
- if (_this3.shouldSkipStrategyForProduct(product, config)) {
544
- continue;
545
- }
546
533
  var contextProduct = product;
547
534
  if (!matchVariant) {
548
535
  // 只匹配 product_id,忽略 product_variant_id
@@ -640,9 +627,6 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
640
627
  } else if (actionType === 'X_ITEMS_FOR_Y_PRICE') {
641
628
  var _detail = actionDetail;
642
629
  requiredQuantity = _detail.x || 0;
643
- } else if (actionType === 'ITEM_REWARD') {
644
- var _detail2 = actionDetail;
645
- requiredQuantity = _detail2.triggerQuantity || 1;
646
630
  }
647
631
 
648
632
  // 获取可参与商品列表
@@ -1120,248 +1104,6 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
1120
1104
  };
1121
1105
  }
1122
1106
 
1123
- /**
1124
- * 处理 商品奖励 促销
1125
- *
1126
- * 1. 使用 group.products 统计触发条件商品数量
1127
- * 2. 按 quantityRule 计算最多奖励的目标商品数量
1128
- * 3. 在全购物车商品中筛选 rewardTargets
1129
- * 4. 按消费者最优(可节省金额从高到低)选择目标单位
1130
- * 5. 对目标商品拆分并写入 finalPrice,触发商品本身不改价
1131
- */
1132
- }, {
1133
- key: "processItemReward",
1134
- value: function processItemReward(group, processedQuantityMap, allProducts, matchedBundleIndexMap) {
1135
- var _this4 = this;
1136
- var strategyId = group.strategyId,
1137
- strategyMetadata = group.strategyMetadata,
1138
- actionDetail = group.actionDetail,
1139
- triggerProducts = group.products;
1140
- var detail = actionDetail;
1141
- var triggerQuantity = this.normalizePositiveInteger(detail.triggerQuantity, 1);
1142
- var rewardQuantity = this.normalizePositiveInteger(detail.rewardQuantity, 1);
1143
- var conditionQuantity = this.getAvailablePromotionQuantity(triggerProducts, processedQuantityMap, matchedBundleIndexMap);
1144
- if (conditionQuantity < triggerQuantity) {
1145
- return {
1146
- products: [],
1147
- originalAmount: 0,
1148
- finalAmount: 0
1149
- };
1150
- }
1151
- var targetProducts = allProducts.filter(function (product) {
1152
- return _this4.isProductMatch(product, detail.rewardTargets || []);
1153
- });
1154
- var targetUnitCandidates = this.buildItemRewardTargetUnits(targetProducts, processedQuantityMap, detail);
1155
- if (targetUnitCandidates.length === 0) {
1156
- return {
1157
- products: [],
1158
- originalAmount: 0,
1159
- finalAmount: 0
1160
- };
1161
- }
1162
- var rewardLimit = this.resolveItemRewardLimit(detail, conditionQuantity, triggerQuantity, rewardQuantity, targetUnitCandidates.length);
1163
- if (rewardLimit <= 0) {
1164
- return {
1165
- products: [],
1166
- originalAmount: 0,
1167
- finalAmount: 0
1168
- };
1169
- }
1170
- var selectedUnits = _toConsumableArray(targetUnitCandidates).sort(function (a, b) {
1171
- var discountDiff = b.discountAmount.minus(a.discountAmount).toNumber();
1172
- if (discountDiff !== 0) return discountDiff;
1173
- return b.originalPrice.minus(a.originalPrice).toNumber();
1174
- }).slice(0, rewardLimit);
1175
- var selectedByProductId = new Map();
1176
- var _iterator18 = _createForOfIteratorHelper(selectedUnits),
1177
- _step18;
1178
- try {
1179
- for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
1180
- var unit = _step18.value;
1181
- var existing = selectedByProductId.get(unit.product.id);
1182
- if (existing) {
1183
- existing.quantity += 1;
1184
- } else {
1185
- selectedByProductId.set(unit.product.id, {
1186
- quantity: 1,
1187
- finalPrice: unit.finalPrice,
1188
- originalPrice: unit.originalPrice
1189
- });
1190
- }
1191
- }
1192
- } catch (err) {
1193
- _iterator18.e(err);
1194
- } finally {
1195
- _iterator18.f();
1196
- }
1197
- var result = [];
1198
- var originalAmount = new Decimal(0);
1199
- var finalAmount = new Decimal(0);
1200
- var _iterator19 = _createForOfIteratorHelper(targetProducts),
1201
- _step19;
1202
- try {
1203
- for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
1204
- var product = _step19.value;
1205
- var key = this.getProductKey(product);
1206
- var processedQty = processedQuantityMap.get(key) || 0;
1207
- var availableQty = product.quantity - processedQty;
1208
- if (availableQty <= 0) continue;
1209
- var selected = selectedByProductId.get(product.id);
1210
- var selectedQty = (selected === null || selected === void 0 ? void 0 : selected.quantity) || 0;
1211
- var remainingQty = availableQty - selectedQty;
1212
- if (selectedQty <= 0) continue;
1213
- if (selectedQty > 0) {
1214
- result.push(_objectSpread(_objectSpread({}, product), {}, {
1215
- id: selectedQty === availableQty ? product.id : this.generateRandomId(),
1216
- originalId: product.id,
1217
- quantity: selectedQty,
1218
- finalPrice: this.formatPrice(selected.finalPrice),
1219
- strategyId: strategyId,
1220
- strategyMetadata: strategyMetadata,
1221
- inPromotion: true,
1222
- isSplit: selectedQty !== product.quantity
1223
- }));
1224
- originalAmount = originalAmount.plus(selected.originalPrice.mul(selectedQty));
1225
- finalAmount = finalAmount.plus(selected.finalPrice.mul(selectedQty));
1226
- }
1227
- if (remainingQty > 0) {
1228
- result.push(_objectSpread(_objectSpread({}, product), {}, {
1229
- quantity: remainingQty,
1230
- finalPrice: this.formatPrice(product.price),
1231
- strategyId: undefined,
1232
- strategyMetadata: undefined,
1233
- inPromotion: false,
1234
- isSplit: selectedQty > 0
1235
- }));
1236
- var remainingAmount = new Decimal(product.price).mul(remainingQty);
1237
- originalAmount = originalAmount.plus(remainingAmount);
1238
- finalAmount = finalAmount.plus(remainingAmount);
1239
- }
1240
- processedQuantityMap.set(key, processedQty + availableQty);
1241
- }
1242
- } catch (err) {
1243
- _iterator19.e(err);
1244
- } finally {
1245
- _iterator19.f();
1246
- }
1247
- return {
1248
- products: result,
1249
- originalAmount: originalAmount.toNumber(),
1250
- finalAmount: finalAmount.toNumber()
1251
- };
1252
- }
1253
- }, {
1254
- key: "normalizePositiveInteger",
1255
- value: function normalizePositiveInteger(value, fallback) {
1256
- var n = Math.floor(Number(value));
1257
- return Number.isFinite(n) && n > 0 ? n : fallback;
1258
- }
1259
- }, {
1260
- key: "getAvailablePromotionQuantity",
1261
- value: function getAvailablePromotionQuantity(products, processedQuantityMap, matchedBundleIndexMap) {
1262
- var total = 0;
1263
- var _iterator20 = _createForOfIteratorHelper(products),
1264
- _step20;
1265
- try {
1266
- for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
1267
- var product = _step20.value;
1268
- var key = this.getProductKey(product);
1269
- var processedQty = processedQuantityMap.get(key) || 0;
1270
- var availableQty = product.quantity - processedQty;
1271
- if (availableQty <= 0) continue;
1272
- var matchedBundleIndex = matchedBundleIndexMap === null || matchedBundleIndexMap === void 0 ? void 0 : matchedBundleIndexMap.get(product.id);
1273
- if (matchedBundleIndex !== undefined && product.bundle) {
1274
- var bundleItem = product.bundle[matchedBundleIndex];
1275
- total += availableQty * ((bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.quantity) || 1);
1276
- } else {
1277
- total += availableQty;
1278
- }
1279
- }
1280
- } catch (err) {
1281
- _iterator20.e(err);
1282
- } finally {
1283
- _iterator20.f();
1284
- }
1285
- return total;
1286
- }
1287
- }, {
1288
- key: "buildItemRewardTargetUnits",
1289
- value: function buildItemRewardTargetUnits(products, processedQuantityMap, detail) {
1290
- var units = [];
1291
- var _iterator21 = _createForOfIteratorHelper(products),
1292
- _step21;
1293
- try {
1294
- for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
1295
- var product = _step21.value;
1296
- var key = this.getProductKey(product);
1297
- var processedQty = processedQuantityMap.get(key) || 0;
1298
- var availableQty = product.quantity - processedQty;
1299
- if (availableQty <= 0) continue;
1300
- var originalPrice = new Decimal(product.price || 0);
1301
- var finalPrice = this.resolveItemRewardFinalPrice(originalPrice, detail);
1302
- var discountAmount = originalPrice.minus(finalPrice);
1303
- if (discountAmount.lte(0)) continue;
1304
- for (var i = 0; i < availableQty; i++) {
1305
- units.push({
1306
- product: product,
1307
- originalPrice: originalPrice,
1308
- finalPrice: finalPrice,
1309
- discountAmount: discountAmount
1310
- });
1311
- }
1312
- }
1313
- } catch (err) {
1314
- _iterator21.e(err);
1315
- } finally {
1316
- _iterator21.f();
1317
- }
1318
- return units;
1319
- }
1320
- }, {
1321
- key: "resolveItemRewardFinalPrice",
1322
- value: function resolveItemRewardFinalPrice(originalPrice, detail) {
1323
- var rewardValue = new Decimal(Number(detail.rewardValue) || 0);
1324
- var finalPrice;
1325
- switch (detail.rewardMethod) {
1326
- case 'percent_off':
1327
- {
1328
- var percent = Decimal.min(100, Decimal.max(0, rewardValue));
1329
- finalPrice = originalPrice.mul(new Decimal(100).minus(percent)).div(100);
1330
- break;
1331
- }
1332
- case 'amount_off':
1333
- finalPrice = originalPrice.minus(Decimal.max(0, rewardValue));
1334
- break;
1335
- case 'fixed_price':
1336
- finalPrice = Decimal.max(0, rewardValue);
1337
- break;
1338
- case 'free':
1339
- default:
1340
- finalPrice = new Decimal(0);
1341
- break;
1342
- }
1343
- return Decimal.max(0, Decimal.min(originalPrice, finalPrice)).toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
1344
- }
1345
- }, {
1346
- key: "resolveItemRewardLimit",
1347
- value: function resolveItemRewardLimit(detail, conditionQuantity, triggerQuantity, rewardQuantity, targetUnitCount) {
1348
- var _detail$maxRewardQuan;
1349
- var limit = 0;
1350
- switch (detail.quantityRule) {
1351
- case 'all_targets':
1352
- limit = targetUnitCount;
1353
- break;
1354
- case 'max_per_order':
1355
- limit = this.normalizePositiveInteger((_detail$maxRewardQuan = detail.maxRewardQuantity) !== null && _detail$maxRewardQuan !== void 0 ? _detail$maxRewardQuan : detail.rewardQuantity, rewardQuantity);
1356
- break;
1357
- case 'per_condition_quantity':
1358
- default:
1359
- limit = Math.floor(conditionQuantity / triggerQuantity) * rewardQuantity;
1360
- break;
1361
- }
1362
- return Math.min(Math.max(0, limit), targetUnitCount);
1363
- }
1364
-
1365
1107
  /**
1366
1108
  * 获取未参与任何促销的商品
1367
1109
  */
@@ -1369,11 +1111,11 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
1369
1111
  key: "getRemainingProducts",
1370
1112
  value: function getRemainingProducts(allProducts, processedQuantityMap) {
1371
1113
  var result = [];
1372
- var _iterator22 = _createForOfIteratorHelper(allProducts),
1373
- _step22;
1114
+ var _iterator18 = _createForOfIteratorHelper(allProducts),
1115
+ _step18;
1374
1116
  try {
1375
- for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
1376
- var product = _step22.value;
1117
+ for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
1118
+ var product = _step18.value;
1377
1119
  var key = this.getProductKey(product);
1378
1120
  var processedQty = processedQuantityMap.get(key) || 0;
1379
1121
  var remainingQty = product.quantity - processedQty;
@@ -1388,9 +1130,9 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
1388
1130
  }
1389
1131
  }
1390
1132
  } catch (err) {
1391
- _iterator22.e(err);
1133
+ _iterator18.e(err);
1392
1134
  } finally {
1393
- _iterator22.f();
1135
+ _iterator18.f();
1394
1136
  }
1395
1137
  return result;
1396
1138
  }
@@ -1468,23 +1210,8 @@ export var PromotionEvaluator = /*#__PURE__*/function () {
1468
1210
  }, {
1469
1211
  key: "isProductInStrategy",
1470
1212
  value: function isProductInStrategy(product, config) {
1471
- if (this.shouldSkipStrategyForProduct(product, config)) {
1472
- return false;
1473
- }
1474
1213
  return this.getProductMatchInfo(product, config).isMatch;
1475
1214
  }
1476
- }, {
1477
- key: "shouldSkipStrategyForProduct",
1478
- value: function shouldSkipStrategyForProduct(product, config) {
1479
- return Boolean(product._promotionOnlyForItemReward) && !this.hasActionType(config, PROMOTION_ACTION_TYPES.ITEM_REWARD);
1480
- }
1481
- }, {
1482
- key: "hasActionType",
1483
- value: function hasActionType(config, actionType) {
1484
- return (config.actions || []).some(function (action) {
1485
- return (action === null || action === void 0 ? void 0 : action.type) === actionType;
1486
- });
1487
- }
1488
1215
 
1489
1216
  /**
1490
1217
  * 查找商品匹配规则
@@ -136,89 +136,3 @@ export declare const BUY_X_GET_Y_FREE_STRATEGY: {
136
136
  };
137
137
  }[];
138
138
  };
139
- /**
140
- * ITEM_REWARD 策略配置示例:儿童票触发婴儿票免费
141
- *
142
- * 业务规则:
143
- * - 条件商品:儿童票(conditions.rules.productIdAndVariantId)
144
- * - 奖励商品:购物车/订单内已经存在的婴儿票(actions[0].config.rewardTargets)
145
- * - 本 action 不自动新增婴儿票;每次购物车变更后由统一促销链路重算
146
- *
147
- * 字段说明:
148
- * - type: "ITEM_REWARD" 表示商品奖励 action
149
- * - target: "product" 表示本期只奖励商品行
150
- * - config.rewardTargets: 奖励对象数组,支持 { product_id, product_variant_id }
151
- * - config.targetSelection: "consumer_best" 表示目标商品超额时选择节省金额最高的商品
152
- * - value.rewardMethod:
153
- * - "free": 目标商品最终价为 0
154
- * - "percent_off": 百分比折扣,rewardValue 为 0-100
155
- * - "amount_off": 每个目标商品固定减免 rewardValue
156
- * - "fixed_price": 目标商品最终单价为 rewardValue
157
- * - value.quantityRule:
158
- * - "per_condition_quantity": 每满足 triggerQuantity 个条件商品,奖励 rewardQuantity 个目标商品
159
- * - "all_targets": 满足条件后奖励全部目标商品
160
- * - "max_per_order": 满足条件后每单最多奖励 maxRewardQuantity 个目标商品
161
- */
162
- export declare const ITEM_REWARD_STRATEGY: {
163
- metadata: {
164
- id: string;
165
- name: {
166
- en: string;
167
- 'zh-CN': string;
168
- 'zh-HK': string;
169
- };
170
- type: string;
171
- custom: {
172
- display: {
173
- product_card: {
174
- text: {
175
- en: string;
176
- 'zh-CN': string;
177
- 'zh-HK': string;
178
- };
179
- type: string;
180
- };
181
- };
182
- };
183
- };
184
- conditions: {
185
- operator: string;
186
- rules: ({
187
- type: string;
188
- field: string;
189
- value: string;
190
- operator: string;
191
- } | {
192
- type: string;
193
- field: string;
194
- value: {
195
- product_id: number;
196
- product_variant_id: number;
197
- }[];
198
- operator: string;
199
- })[];
200
- actionIds: string[];
201
- };
202
- actions: {
203
- id: string;
204
- type: string;
205
- value: {
206
- rewardMethod: string;
207
- rewardValue: number;
208
- quantityRule: string;
209
- triggerQuantity: number;
210
- rewardQuantity: number;
211
- maxRewardQuantity: number;
212
- };
213
- valueType: string;
214
- target: string;
215
- priority: number;
216
- config: {
217
- rewardTargets: {
218
- product_id: number;
219
- product_variant_id: number;
220
- }[];
221
- targetSelection: string;
222
- };
223
- }[];
224
- };
@@ -163,103 +163,4 @@ export var BUY_X_GET_Y_FREE_STRATEGY = {
163
163
  }]
164
164
  }
165
165
  }]
166
- };
167
-
168
- /**
169
- * ITEM_REWARD 策略配置示例:儿童票触发婴儿票免费
170
- *
171
- * 业务规则:
172
- * - 条件商品:儿童票(conditions.rules.productIdAndVariantId)
173
- * - 奖励商品:购物车/订单内已经存在的婴儿票(actions[0].config.rewardTargets)
174
- * - 本 action 不自动新增婴儿票;每次购物车变更后由统一促销链路重算
175
- *
176
- * 字段说明:
177
- * - type: "ITEM_REWARD" 表示商品奖励 action
178
- * - target: "product" 表示本期只奖励商品行
179
- * - config.rewardTargets: 奖励对象数组,支持 { product_id, product_variant_id }
180
- * - config.targetSelection: "consumer_best" 表示目标商品超额时选择节省金额最高的商品
181
- * - value.rewardMethod:
182
- * - "free": 目标商品最终价为 0
183
- * - "percent_off": 百分比折扣,rewardValue 为 0-100
184
- * - "amount_off": 每个目标商品固定减免 rewardValue
185
- * - "fixed_price": 目标商品最终单价为 rewardValue
186
- * - value.quantityRule:
187
- * - "per_condition_quantity": 每满足 triggerQuantity 个条件商品,奖励 rewardQuantity 个目标商品
188
- * - "all_targets": 满足条件后奖励全部目标商品
189
- * - "max_per_order": 满足条件后每单最多奖励 maxRewardQuantity 个目标商品
190
- */
191
- export var ITEM_REWARD_STRATEGY = {
192
- metadata: {
193
- id: 'STRATEGY_003',
194
- name: {
195
- en: 'Infant ticket free with child ticket',
196
- 'zh-CN': '儿童票触发婴儿票免费',
197
- 'zh-HK': '兒童票觸發嬰兒票免費'
198
- },
199
- type: 'promotion',
200
- custom: {
201
- display: {
202
- product_card: {
203
- text: {
204
- en: 'Infant ticket free',
205
- 'zh-CN': '婴儿票免费',
206
- 'zh-HK': '嬰兒票免費'
207
- },
208
- type: 'tag'
209
- }
210
- }
211
- }
212
- },
213
- conditions: {
214
- operator: 'and',
215
- rules: [{
216
- type: 'operator',
217
- field: 'currentDateTime',
218
- value: '2023-01-01 00:00:00',
219
- operator: '>='
220
- }, {
221
- type: 'operator',
222
- field: 'currentDateTime',
223
- value: '2030-01-01 00:00:00',
224
- operator: '<='
225
- }, {
226
- type: 'operator',
227
- field: 'productIdAndVariantId',
228
- value: [{
229
- product_id: 1001,
230
- // 条件商品:儿童票
231
- product_variant_id: 0 // 0 = 匹配任意变体
232
- }],
233
- operator: 'product_match'
234
- }],
235
- actionIds: ['1']
236
- },
237
- actions: [{
238
- id: '1',
239
- type: 'ITEM_REWARD',
240
- value: {
241
- rewardMethod: 'free',
242
- // free | percent_off | amount_off | fixed_price
243
- rewardValue: 0,
244
- // free 可省略;其他 rewardMethod 使用
245
- quantityRule: 'per_condition_quantity',
246
- // per_condition_quantity | all_targets | max_per_order
247
- triggerQuantity: 1,
248
- // N:每满足 N 个条件商品
249
- rewardQuantity: 1,
250
- // Y:奖励 Y 个目标商品
251
- maxRewardQuantity: 1 // max_per_order 使用;本例保留为配置示意
252
- },
253
- valueType: 'object',
254
- target: 'product',
255
- priority: 1,
256
- config: {
257
- rewardTargets: [{
258
- product_id: 2001,
259
- // 奖励对象:婴儿票
260
- product_variant_id: 0 // 0 = 匹配任意变体
261
- }],
262
- targetSelection: 'consumer_best' // consumer_best = 按可节省金额从高到低选择
263
- }
264
- }]
265
166
  };
@@ -1,4 +1,4 @@
1
1
  export { PromotionEvaluator } from './evaluator';
2
2
  export { PromotionAdapter } from './adapter';
3
3
  export { default } from './adapter';
4
- export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, ITEM_REWARD_STRATEGY, } from './examples';
4
+ export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, } from './examples';