@pisell/pisellos 0.10.7 → 0.10.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/core/index.js +0 -1
  2. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
  3. package/dist/model/strategy/adapter/dataVariant/evaluator.js +287 -101
  4. package/dist/model/strategy/adapter/dataVariant/type.d.ts +25 -0
  5. package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -2
  6. package/dist/model/strategy/adapter/walletPass/type.d.ts +5 -0
  7. package/dist/model/strategy/adapter/walletPass/utils.js +57 -26
  8. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +18 -12
  9. package/dist/modules/BookingContext/utils/productExtend.js +5 -9
  10. package/dist/modules/BookingContext/utils/timeSlices.js +24 -3
  11. package/dist/modules/Customer/index.d.ts +4 -0
  12. package/dist/modules/Customer/index.js +91 -59
  13. package/dist/modules/Customer/types.d.ts +2 -0
  14. package/dist/modules/Discount/index.d.ts +2 -0
  15. package/dist/modules/Discount/index.js +38 -5
  16. package/dist/modules/Discount/types.d.ts +11 -0
  17. package/dist/modules/Order/index.d.ts +32 -6
  18. package/dist/modules/Order/index.js +1165 -819
  19. package/dist/modules/Order/types.d.ts +32 -4
  20. package/dist/modules/Order/types.js +11 -0
  21. package/dist/modules/Order/utils/discountProductLineIdentity.d.ts +45 -0
  22. package/dist/modules/Order/utils/discountProductLineIdentity.js +227 -0
  23. package/dist/modules/Order/utils/virtualSettlement.d.ts +56 -0
  24. package/dist/modules/Order/utils/virtualSettlement.js +271 -0
  25. package/dist/modules/Order/utils.js +89 -48
  26. package/dist/modules/Payment/types.d.ts +2 -0
  27. package/dist/modules/Payment/utils.js +4 -1
  28. package/dist/modules/Payment/walletpass.d.ts +11 -0
  29. package/dist/modules/Payment/walletpass.js +235 -60
  30. package/dist/modules/Product/types.d.ts +23 -0
  31. package/dist/modules/ProductList/index.d.ts +15 -2
  32. package/dist/modules/ProductList/index.js +92 -13
  33. package/dist/modules/Rules/index.js +125 -52
  34. package/dist/modules/SalesSummary/index.d.ts +1 -0
  35. package/dist/modules/SalesSummary/index.js +4 -3
  36. package/dist/modules/SalesSummary/types.d.ts +1 -0
  37. package/dist/modules/SalesSummary/utils.d.ts +1 -0
  38. package/dist/modules/SalesSummary/utils.js +28 -2
  39. package/dist/server/index.d.ts +15 -0
  40. package/dist/server/index.js +894 -781
  41. package/dist/server/modules/order/index.d.ts +2 -0
  42. package/dist/server/modules/order/index.js +261 -96
  43. package/dist/server/modules/order/types.d.ts +1 -1
  44. package/dist/server/utils/small-ticket.js +2 -1
  45. package/dist/solution/BaseSales/index.d.ts +41 -7
  46. package/dist/solution/BaseSales/index.js +1405 -974
  47. package/dist/solution/BaseSales/utils/cartPromotion.js +26 -3
  48. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  49. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +79 -13
  50. package/dist/solution/BaseSales/utils.js +31 -20
  51. package/dist/solution/BookingByStep/index.d.ts +3 -3
  52. package/dist/solution/BookingTicket/index.d.ts +5 -1
  53. package/dist/solution/BookingTicket/index.js +221 -162
  54. package/dist/solution/BookingTicket/types.d.ts +3 -0
  55. package/dist/solution/BookingTicket/utils/addProductDecision.js +2 -1
  56. package/dist/solution/BookingTicket/utils/cartView.js +44 -32
  57. package/dist/solution/Sales/index.d.ts +1 -0
  58. package/dist/solution/Sales/index.js +16 -2
  59. package/dist/solution/ScanOrder/index.js +25 -64
  60. package/dist/solution/ScanOrder/utils.js +31 -20
  61. package/dist/solution/UnifiedBookingSales/index.d.ts +5 -4
  62. package/dist/solution/UnifiedBookingSales/index.js +51 -39
  63. package/lib/core/index.js +0 -1
  64. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
  65. package/lib/model/strategy/adapter/dataVariant/evaluator.js +170 -7
  66. package/lib/model/strategy/adapter/dataVariant/type.d.ts +25 -0
  67. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
  68. package/lib/model/strategy/adapter/walletPass/type.d.ts +5 -0
  69. package/lib/model/strategy/adapter/walletPass/utils.js +62 -11
  70. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +6 -1
  71. package/lib/modules/BookingContext/utils/productExtend.js +4 -3
  72. package/lib/modules/BookingContext/utils/timeSlices.js +18 -3
  73. package/lib/modules/Customer/index.d.ts +4 -0
  74. package/lib/modules/Customer/index.js +11 -0
  75. package/lib/modules/Customer/types.d.ts +2 -0
  76. package/lib/modules/Discount/index.d.ts +2 -0
  77. package/lib/modules/Discount/index.js +37 -3
  78. package/lib/modules/Discount/types.d.ts +11 -0
  79. package/lib/modules/Order/index.d.ts +32 -6
  80. package/lib/modules/Order/index.js +518 -148
  81. package/lib/modules/Order/types.d.ts +32 -4
  82. package/lib/modules/Order/utils/discountProductLineIdentity.d.ts +45 -0
  83. package/lib/modules/Order/utils/discountProductLineIdentity.js +170 -0
  84. package/lib/modules/Order/utils/virtualSettlement.d.ts +56 -0
  85. package/lib/modules/Order/utils/virtualSettlement.js +300 -0
  86. package/lib/modules/Order/utils.js +65 -21
  87. package/lib/modules/Payment/types.d.ts +2 -0
  88. package/lib/modules/Payment/utils.js +5 -1
  89. package/lib/modules/Payment/walletpass.d.ts +11 -0
  90. package/lib/modules/Payment/walletpass.js +198 -17
  91. package/lib/modules/Product/types.d.ts +23 -0
  92. package/lib/modules/ProductList/index.d.ts +15 -2
  93. package/lib/modules/ProductList/index.js +85 -3
  94. package/lib/modules/Rules/index.js +100 -20
  95. package/lib/modules/SalesSummary/index.d.ts +1 -0
  96. package/lib/modules/SalesSummary/index.js +10 -2
  97. package/lib/modules/SalesSummary/types.d.ts +1 -0
  98. package/lib/modules/SalesSummary/utils.d.ts +1 -0
  99. package/lib/modules/SalesSummary/utils.js +30 -2
  100. package/lib/server/index.d.ts +15 -0
  101. package/lib/server/index.js +105 -14
  102. package/lib/server/modules/order/index.d.ts +2 -0
  103. package/lib/server/modules/order/index.js +75 -5
  104. package/lib/server/modules/order/types.d.ts +1 -1
  105. package/lib/server/utils/small-ticket.js +1 -1
  106. package/lib/solution/BaseSales/index.d.ts +41 -7
  107. package/lib/solution/BaseSales/index.js +325 -39
  108. package/lib/solution/BaseSales/utils/cartPromotion.js +26 -2
  109. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  110. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +62 -12
  111. package/lib/solution/BaseSales/utils.js +29 -18
  112. package/lib/solution/BookingByStep/index.d.ts +3 -3
  113. package/lib/solution/BookingTicket/index.d.ts +5 -1
  114. package/lib/solution/BookingTicket/index.js +31 -6
  115. package/lib/solution/BookingTicket/types.d.ts +3 -0
  116. package/lib/solution/BookingTicket/utils/addProductDecision.js +2 -1
  117. package/lib/solution/BookingTicket/utils/cartView.js +43 -30
  118. package/lib/solution/Sales/index.d.ts +1 -0
  119. package/lib/solution/Sales/index.js +15 -3
  120. package/lib/solution/ScanOrder/index.js +17 -54
  121. package/lib/solution/ScanOrder/utils.js +29 -18
  122. package/lib/solution/UnifiedBookingSales/index.d.ts +5 -4
  123. package/lib/solution/UnifiedBookingSales/index.js +35 -26
  124. package/package.json +1 -1
@@ -1,4 +1,3 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
2
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
3
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
@@ -7,6 +6,7 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableTo
7
6
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
7
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
9
8
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
9
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
10
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
11
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
12
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
@@ -24,7 +24,7 @@ import { DataVariantAdapter } from "./adapter";
24
24
  /**
25
25
  * Data Variant 评估器。
26
26
  *
27
- * 当前阶段只提供策略模型能力和示例验证,不接入 ProductList 业务链路。
27
+ * OS Server 商品路由开启时由 ProductsModule 调用;路由关闭时由 ProductList 在远端响应后调用。
28
28
  */
29
29
  export var DataVariantEvaluator = /*#__PURE__*/function () {
30
30
  function DataVariantEvaluator() {
@@ -51,7 +51,7 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
51
51
  /**
52
52
  * 批量解析商品 Data Variant。
53
53
  *
54
- * 先执行全局预计算,再只针对商品自身 data_variants 引用到的规则做商品级判断。
54
+ * 优先使用商品 metadata.data_variant_ids;缺少权威命中结果时才执行本地策略判断。
55
55
  */
56
56
  }, {
57
57
  key: "resolveProducts",
@@ -60,9 +60,17 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
60
60
  var strategyConfigs = businessData.strategyConfigs ? this.normalizeStrategyConfigs(businessData.strategyConfigs) : this.strategyConfigs;
61
61
  var menuScopeMap = this.buildMenuScopeMap(businessData.menuList || []);
62
62
  var scheduleTimePoints = this.buildScheduleTimePoints(strategyConfigs, businessData.scheduleList || []);
63
- var _this$buildGlobalEffe = this.buildGlobalEffectiveRuleMap(strategyConfigs, businessData, menuScopeMap),
64
- globalEffectiveRuleMap = _this$buildGlobalEffe.globalEffectiveRuleMap,
65
- rawResults = _this$buildGlobalEffe.rawResults;
63
+ // metadata.data_variant_ids 存在时,接口已经完成规则计算;只有仍有商品缺少
64
+ // 该权威结果时才初始化本地策略引擎,避免 OS/接口与客户端重复评估。
65
+ var shouldEvaluateStrategies = businessData.products.some(function (product) {
66
+ return _this.requiresLocalStrategyEvaluation(product);
67
+ });
68
+ var _ref = shouldEvaluateStrategies ? this.buildGlobalEffectiveRuleMap(strategyConfigs, businessData, menuScopeMap) : {
69
+ globalEffectiveRuleMap: new Map(),
70
+ rawResults: []
71
+ },
72
+ globalEffectiveRuleMap = _ref.globalEffectiveRuleMap,
73
+ rawResults = _ref.rawResults;
66
74
  var products = businessData.products.map(function (product) {
67
75
  var resolvedProduct = _this.resolveProduct(product, businessData, globalEffectiveRuleMap, menuScopeMap);
68
76
  // 套餐子商品也可能携带 data_variants,需在同一策略上下文内继续评估并写回 bundle_item。
@@ -180,6 +188,69 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
180
188
  });
181
189
  return this.extractTimePointsFromSchedules(matchedSchedules);
182
190
  }
191
+
192
+ /**
193
+ * 判断商品(含套餐子商品)是否仍需要本地执行策略条件。
194
+ * metadata.data_variant_ids 只要是数组,即使为空,也表示接口已经给出权威命中结果。
195
+ */
196
+ }, {
197
+ key: "requiresLocalStrategyEvaluation",
198
+ value: function requiresLocalStrategyEvaluation(product) {
199
+ var _this2 = this;
200
+ var dataVariants = this.getProductDataVariants(product);
201
+ var hasConditionalVariant = dataVariants.some(function (variant) {
202
+ return Number(variant.data_variant_rule_id) !== 0;
203
+ });
204
+ if (hasConditionalVariant && this.getAuthoritativeVariantPriorities(product) === null) {
205
+ return true;
206
+ }
207
+ var bundleGroups = Array.isArray(product.bundle_group) ? product.bundle_group : [];
208
+ return bundleGroups.some(function (group) {
209
+ var bundleItems = Array.isArray(group === null || group === void 0 ? void 0 : group.bundle_item) ? group.bundle_item : [];
210
+ return bundleItems.some(function (item) {
211
+ return _this2.requiresLocalStrategyEvaluation(_this2.toBundleItemDataVariantProduct(item));
212
+ });
213
+ });
214
+ }
215
+
216
+ /**
217
+ * 将接口返回的高 -> 低优先级 Variant ID 转成数值优先级。
218
+ * 返回 null 表示接口没有提供该字段;空 Map 表示已计算但没有任何命中。
219
+ */
220
+ }, {
221
+ key: "getAuthoritativeVariantPriorities",
222
+ value: function getAuthoritativeVariantPriorities(product) {
223
+ var _product$metadata;
224
+ var rawIds = product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.data_variant_ids;
225
+ if (!Array.isArray(rawIds)) return null;
226
+ var orderedIds = [];
227
+ var seen = new Set();
228
+ var _iterator4 = _createForOfIteratorHelper(rawIds),
229
+ _step4;
230
+ try {
231
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
232
+ var rawId = _step4.value;
233
+ var id = this.normalizeDataVariantId(rawId);
234
+ if (id === null || seen.has(id)) continue;
235
+ seen.add(id);
236
+ orderedIds.push(id);
237
+ }
238
+ } catch (err) {
239
+ _iterator4.e(err);
240
+ } finally {
241
+ _iterator4.f();
242
+ }
243
+ return new Map(orderedIds.map(function (id, index) {
244
+ return [id, orderedIds.length - index];
245
+ }));
246
+ }
247
+ }, {
248
+ key: "normalizeDataVariantId",
249
+ value: function normalizeDataVariantId(value) {
250
+ if (value === undefined || value === null) return null;
251
+ var normalized = String(value).trim();
252
+ return normalized || null;
253
+ }
183
254
  }, {
184
255
  key: "buildGlobalEffectiveRuleMap",
185
256
  value: function buildGlobalEffectiveRuleMap(strategyConfigs, businessData, menuScopeMap) {
@@ -187,11 +258,11 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
187
258
  var rawResults = [];
188
259
  var engine = this.createEngine(businessData, menuScopeMap);
189
260
  var context = this.adapter.prepareGlobalContext(businessData);
190
- var _iterator4 = _createForOfIteratorHelper(strategyConfigs),
191
- _step4;
261
+ var _iterator5 = _createForOfIteratorHelper(strategyConfigs),
262
+ _step5;
192
263
  try {
193
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
194
- var config = _step4.value;
264
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
265
+ var config = _step5.value;
195
266
  if (!this.isStrategyActive(config)) continue;
196
267
  var _this$splitStrategyCo = this.splitStrategyConfig(config),
197
268
  globalConfig = _this$splitStrategyCo.globalConfig,
@@ -208,9 +279,9 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
208
279
  });
209
280
  }
210
281
  } catch (err) {
211
- _iterator4.e(err);
282
+ _iterator5.e(err);
212
283
  } finally {
213
- _iterator4.f();
284
+ _iterator5.f();
214
285
  }
215
286
  return {
216
287
  globalEffectiveRuleMap: globalEffectiveRuleMap,
@@ -223,11 +294,28 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
223
294
  var dataVariants = this.getProductDataVariants(product);
224
295
  if (!dataVariants.length) return product;
225
296
  var matchedVariants = [];
226
- var _iterator5 = _createForOfIteratorHelper(dataVariants),
227
- _step5;
297
+ var authoritativeVariantPriorities = this.getAuthoritativeVariantPriorities(product);
298
+ var settlementVariants = dataVariants.filter(function (variant) {
299
+ return variant.business_type === 'multi_currency_settlement' && variant.status === 'enable';
300
+ });
301
+ var _iterator6 = _createForOfIteratorHelper(dataVariants),
302
+ _step6;
228
303
  try {
229
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
230
- var variant = _step5.value;
304
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
305
+ var variant = _step6.value;
306
+ if (variant.business_type === 'multi_currency_settlement') continue;
307
+ if (authoritativeVariantPriorities !== null) {
308
+ var variantId = this.normalizeDataVariantId(variant.id);
309
+ var priority = variantId === null ? undefined : authoritativeVariantPriorities.get(variantId);
310
+ if (priority === undefined) continue;
311
+ matchedVariants.push({
312
+ ruleId: String(variant.data_variant_rule_id),
313
+ priority: priority,
314
+ data: variant.data || {},
315
+ variant: variant
316
+ });
317
+ continue;
318
+ }
231
319
  var rule = globalEffectiveRuleMap.get(String(variant.data_variant_rule_id));
232
320
  if (!rule) continue;
233
321
  if (!this.evaluateProductRules(rule, product, businessData, menuScopeMap)) {
@@ -241,12 +329,103 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
241
329
  });
242
330
  }
243
331
  } catch (err) {
244
- _iterator5.e(err);
332
+ _iterator6.e(err);
245
333
  } finally {
246
- _iterator5.f();
334
+ _iterator6.f();
247
335
  }
248
- if (!matchedVariants.length) return product;
249
- return this.mergeMatchedVariants(product, matchedVariants);
336
+ var resolvedProduct = matchedVariants.length ? this.mergeMatchedVariants(product, matchedVariants) : product;
337
+ var availableSettlementOptions = this.resolveSettlementOptions(settlementVariants, product, businessData, globalEffectiveRuleMap, menuScopeMap, authoritativeVariantPriorities);
338
+ if (!settlementVariants.length) return resolvedProduct;
339
+ return _objectSpread(_objectSpread({}, resolvedProduct), {}, {
340
+ available_settlement_options: availableSettlementOptions
341
+ });
342
+ }
343
+
344
+ /**
345
+ * 多货币 Data Variant 只生成候选列表,不参与商品字段覆盖。
346
+ * rule_id=0 是无条件默认价;同币种命中的条件价优先于默认价。
347
+ */
348
+ }, {
349
+ key: "resolveSettlementOptions",
350
+ value: function resolveSettlementOptions(variants, product, businessData, globalEffectiveRuleMap, menuScopeMap, authoritativeVariantPriorities) {
351
+ var _this3 = this;
352
+ if (!variants.length) return [];
353
+ var candidates = variants.flatMap(function (variant) {
354
+ var _variant$data, _variant$id, _variant$data$price, _variant$data2;
355
+ var settlement = (_variant$data = variant.data) === null || _variant$data === void 0 ? void 0 : _variant$data.multi_currency_settlement;
356
+ if (!settlement || _typeof(settlement) !== 'object') return [];
357
+ var ruleId = String(variant.data_variant_rule_id);
358
+ var isDefault = Number(variant.data_variant_rule_id) === 0;
359
+ var rule = isDefault ? undefined : globalEffectiveRuleMap.get(ruleId);
360
+ var variantId = _this3.normalizeDataVariantId(variant.id);
361
+ var authoritativePriority = variantId === null ? undefined : authoritativeVariantPriorities === null || authoritativeVariantPriorities === void 0 ? void 0 : authoritativeVariantPriorities.get(variantId);
362
+ var available;
363
+ var priority;
364
+ if (isDefault) {
365
+ // rule 0 是无条件默认候选,不依赖接口命中 ID 或本地策略引擎。
366
+ available = true;
367
+ priority = Number.NEGATIVE_INFINITY;
368
+ } else if (authoritativeVariantPriorities !== null) {
369
+ var _ref2;
370
+ // 数组存在(包括 [])即表示接口已经算过规则,不再在客户端二次判断。
371
+ available = authoritativePriority !== undefined;
372
+ priority = (_ref2 = authoritativePriority !== null && authoritativePriority !== void 0 ? authoritativePriority : rule === null || rule === void 0 ? void 0 : rule.priority) !== null && _ref2 !== void 0 ? _ref2 : Number.NEGATIVE_INFINITY;
373
+ } else {
374
+ var _rule$priority;
375
+ available = Boolean(rule && _this3.evaluateProductRules(rule, product, businessData, menuScopeMap));
376
+ priority = (_rule$priority = rule === null || rule === void 0 ? void 0 : rule.priority) !== null && _rule$priority !== void 0 ? _rule$priority : Number.NEGATIVE_INFINITY;
377
+ }
378
+ var settlementType = String(settlement.settlement_type || '');
379
+ var currencyProductId = _this3.toNumber(settlement.currency_product_id);
380
+ var settlementKey = settlementType === 'virtual_currency' ? "virtual_currency:".concat(currencyProductId || '') : settlementType || "variant:".concat((_variant$id = variant.id) !== null && _variant$id !== void 0 ? _variant$id : ruleId);
381
+ return [{
382
+ key: settlementKey,
383
+ priority: priority,
384
+ isDefault: isDefault,
385
+ option: _objectSpread(_objectSpread(_objectSpread({}, settlement), {}, {
386
+ settlement_type: settlementType
387
+ }, currencyProductId ? {
388
+ currency_product_id: currencyProductId
389
+ } : {}), {}, {
390
+ price: String((_variant$data$price = (_variant$data2 = variant.data) === null || _variant$data2 === void 0 ? void 0 : _variant$data2.price) !== null && _variant$data$price !== void 0 ? _variant$data$price : '0'),
391
+ data_variant_id: variant.id,
392
+ data_variant_rule_id: variant.data_variant_rule_id,
393
+ available: available,
394
+ disabled_reason: available ? '' : String(settlement.disabled_reason || 'Not available for this purchase.')
395
+ })
396
+ }];
397
+ });
398
+ var grouped = new Map();
399
+ var _iterator7 = _createForOfIteratorHelper(candidates),
400
+ _step7;
401
+ try {
402
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
403
+ var candidate = _step7.value;
404
+ var group = grouped.get(candidate.key) || [];
405
+ group.push(candidate);
406
+ grouped.set(candidate.key, group);
407
+ }
408
+ } catch (err) {
409
+ _iterator7.e(err);
410
+ } finally {
411
+ _iterator7.f();
412
+ }
413
+ return Array.from(grouped.values()).map(function (group) {
414
+ var matchedConditional = group.filter(function (candidate) {
415
+ return !candidate.isDefault && candidate.option.available;
416
+ }).sort(function (a, b) {
417
+ return b.priority - a.priority;
418
+ })[0];
419
+ var defaultCandidate = group.find(function (candidate) {
420
+ return candidate.isDefault;
421
+ });
422
+ var unavailableCandidate = _toConsumableArray(group).filter(function (candidate) {
423
+ return !candidate.option.available;
424
+ }).sort(function (a, b) {
425
+ return b.priority - a.priority;
426
+ })[0];
427
+ return (matchedConditional || defaultCandidate || unavailableCandidate).option;
428
+ });
250
429
  }
251
430
 
252
431
  /**
@@ -257,7 +436,7 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
257
436
  }, {
258
437
  key: "resolveProductBundleItems",
259
438
  value: function resolveProductBundleItems(product, businessData, globalEffectiveRuleMap, menuScopeMap) {
260
- var _this2 = this;
439
+ var _this4 = this;
261
440
  var bundleGroups = product.bundle_group;
262
441
  if (!Array.isArray(bundleGroups) || bundleGroups.length === 0) {
263
442
  return product;
@@ -269,7 +448,7 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
269
448
  }
270
449
  return _objectSpread(_objectSpread({}, group), {}, {
271
450
  bundle_item: bundleItems.map(function (item) {
272
- return _this2.resolveBundleItem(item, businessData, globalEffectiveRuleMap, menuScopeMap);
451
+ return _this4.resolveBundleItem(item, businessData, globalEffectiveRuleMap, menuScopeMap);
273
452
  })
274
453
  });
275
454
  });
@@ -298,16 +477,17 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
298
477
  }, {
299
478
  key: "toBundleItemDataVariantProduct",
300
479
  value: function toBundleItemDataVariantProduct(item) {
301
- var _item$bundle_product_, _ref, _ref2, _item$bundle_variant_;
480
+ var _item$bundle_product_, _ref3, _ref4, _item$bundle_variant_;
302
481
  var productId = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item.product_id;
303
- var variantId = (_ref = (_ref2 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref2 !== void 0 ? _ref2 : item.product_variant_id) !== null && _ref !== void 0 ? _ref : 0;
482
+ var variantId = (_ref3 = (_ref4 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref4 !== void 0 ? _ref4 : item.product_variant_id) !== null && _ref3 !== void 0 ? _ref3 : 0;
304
483
  return {
305
484
  id: productId,
306
485
  product_id: productId,
307
486
  product_variant_id: variantId,
308
487
  variant_id: variantId,
309
488
  collection: item.collection,
310
- data_variants: item.data_variants
489
+ data_variants: item.data_variants,
490
+ metadata: item.metadata
311
491
  };
312
492
  }
313
493
 
@@ -323,19 +503,19 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
323
503
  return originalItem;
324
504
  }
325
505
  var result = _objectSpread({}, originalItem);
326
- var _iterator6 = _createForOfIteratorHelper(appliedInfo.appliedFields),
327
- _step6;
506
+ var _iterator8 = _createForOfIteratorHelper(appliedInfo.appliedFields),
507
+ _step8;
328
508
  try {
329
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
330
- var field = _step6.value;
509
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
510
+ var field = _step8.value;
331
511
  if (resolvedItem[field] !== undefined) {
332
512
  result[field] = resolvedItem[field];
333
513
  }
334
514
  }
335
515
  } catch (err) {
336
- _iterator6.e(err);
516
+ _iterator8.e(err);
337
517
  } finally {
338
- _iterator6.f();
518
+ _iterator8.f();
339
519
  }
340
520
  result._dataVariant = appliedInfo;
341
521
  return result;
@@ -375,11 +555,11 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
375
555
  productRules: this.flattenConditionRules(conditions)
376
556
  };
377
557
  }
378
- var _iterator7 = _createForOfIteratorHelper(conditions.rules),
379
- _step7;
558
+ var _iterator9 = _createForOfIteratorHelper(conditions.rules),
559
+ _step9;
380
560
  try {
381
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
382
- var rule = _step7.value;
561
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
562
+ var rule = _step9.value;
383
563
  if (this.isConditionGroup(rule)) {
384
564
  productRules.push.apply(productRules, _toConsumableArray(this.flattenConditionRules(rule)));
385
565
  continue;
@@ -391,9 +571,9 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
391
571
  }
392
572
  }
393
573
  } catch (err) {
394
- _iterator7.e(err);
574
+ _iterator9.e(err);
395
575
  } finally {
396
- _iterator7.f();
576
+ _iterator9.f();
397
577
  }
398
578
  return {
399
579
  globalConfig: _objectSpread(_objectSpread({}, config), {}, {
@@ -409,16 +589,16 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
409
589
  }, {
410
590
  key: "createEngine",
411
591
  value: function createEngine(businessData, menuScopeMap) {
412
- var _this3 = this;
592
+ var _this5 = this;
413
593
  var operatorHandlers = {
414
594
  schedule_match: function schedule_match(fieldValue, compareValue) {
415
- return _this3.evaluateScheduleMatch(fieldValue, compareValue, businessData.scheduleList || []);
595
+ return _this5.evaluateScheduleMatch(fieldValue, compareValue, businessData.scheduleList || []);
416
596
  },
417
597
  menu_match: function menu_match(fieldValue, compareValue) {
418
- return _this3.evaluateMenuMatch(fieldValue, compareValue, menuScopeMap);
598
+ return _this5.evaluateMenuMatch(fieldValue, compareValue, menuScopeMap);
419
599
  },
420
600
  array_intersects: function array_intersects(fieldValue, compareValue) {
421
- return _this3.evaluateArrayIntersects(fieldValue, compareValue);
601
+ return _this5.evaluateArrayIntersects(fieldValue, compareValue);
422
602
  }
423
603
  };
424
604
  return new StrategyEngine({
@@ -444,19 +624,19 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
444
624
  value: function evaluateMenuMatch(fieldValue, compareValue, menuScopeMap) {
445
625
  var menuIds = this.normalizeNumberArray(compareValue);
446
626
  if (!menuIds.length) return true;
447
- var _iterator8 = _createForOfIteratorHelper(menuIds),
448
- _step8;
627
+ var _iterator10 = _createForOfIteratorHelper(menuIds),
628
+ _step10;
449
629
  try {
450
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
451
- var menuId = _step8.value;
630
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
631
+ var menuId = _step10.value;
452
632
  var scope = menuScopeMap.get(menuId);
453
633
  if (!scope) continue;
454
634
  if (this.isProductInMenuScope(fieldValue, scope)) return true;
455
635
  }
456
636
  } catch (err) {
457
- _iterator8.e(err);
637
+ _iterator10.e(err);
458
638
  } finally {
459
- _iterator8.f();
639
+ _iterator10.f();
460
640
  }
461
641
  return false;
462
642
  }
@@ -475,55 +655,55 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
475
655
  key: "collectScheduleIdsFromStrategies",
476
656
  value: function collectScheduleIdsFromStrategies(strategyConfigs) {
477
657
  var scheduleIds = new Set();
478
- var _iterator9 = _createForOfIteratorHelper(strategyConfigs),
479
- _step9;
658
+ var _iterator11 = _createForOfIteratorHelper(strategyConfigs),
659
+ _step11;
480
660
  try {
481
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
482
- var config = _step9.value;
661
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
662
+ var config = _step11.value;
483
663
  if (!this.isStrategyActive(config)) continue;
484
664
  var rules = this.flattenConditionRules(config.conditions);
485
- var _iterator10 = _createForOfIteratorHelper(rules),
486
- _step10;
665
+ var _iterator12 = _createForOfIteratorHelper(rules),
666
+ _step12;
487
667
  try {
488
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
489
- var rule = _step10.value;
668
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
669
+ var rule = _step12.value;
490
670
  if (rule.operator !== 'schedule_match') continue;
491
- var _iterator11 = _createForOfIteratorHelper(this.normalizeNumberArray(rule.value)),
492
- _step11;
671
+ var _iterator13 = _createForOfIteratorHelper(this.normalizeNumberArray(rule.value)),
672
+ _step13;
493
673
  try {
494
- for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
495
- var scheduleId = _step11.value;
674
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
675
+ var scheduleId = _step13.value;
496
676
  scheduleIds.add(scheduleId);
497
677
  }
498
678
  } catch (err) {
499
- _iterator11.e(err);
679
+ _iterator13.e(err);
500
680
  } finally {
501
- _iterator11.f();
681
+ _iterator13.f();
502
682
  }
503
683
  }
504
684
  } catch (err) {
505
- _iterator10.e(err);
685
+ _iterator12.e(err);
506
686
  } finally {
507
- _iterator10.f();
687
+ _iterator12.f();
508
688
  }
509
689
  }
510
690
  } catch (err) {
511
- _iterator9.e(err);
691
+ _iterator11.e(err);
512
692
  } finally {
513
- _iterator9.f();
693
+ _iterator11.f();
514
694
  }
515
695
  return Array.from(scheduleIds);
516
696
  }
517
697
  }, {
518
698
  key: "extractTimePointsFromSchedules",
519
699
  value: function extractTimePointsFromSchedules(schedules) {
520
- var _this4 = this;
700
+ var _this6 = this;
521
701
  var timePoints = new Set();
522
- var _iterator12 = _createForOfIteratorHelper(schedules),
523
- _step12;
702
+ var _iterator14 = _createForOfIteratorHelper(schedules),
703
+ _step14;
524
704
  try {
525
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
526
- var schedule = _step12.value;
705
+ for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
706
+ var schedule = _step14.value;
527
707
  switch (schedule.type) {
528
708
  case 'standard':
529
709
  {
@@ -534,36 +714,36 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
534
714
  case 'time-slots':
535
715
  {
536
716
  var slots = Array.isArray(schedule.time_slot) ? schedule.time_slot : [];
537
- var _iterator13 = _createForOfIteratorHelper(slots),
538
- _step13;
717
+ var _iterator15 = _createForOfIteratorHelper(slots),
718
+ _step15;
539
719
  try {
540
- for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
541
- var slot = _step13.value;
720
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
721
+ var slot = _step15.value;
542
722
  this.addRawTimePoint(timePoints, slot.start_time);
543
723
  this.addRawTimePoint(timePoints, slot.end_time);
544
724
  }
545
725
  } catch (err) {
546
- _iterator13.e(err);
726
+ _iterator15.e(err);
547
727
  } finally {
548
- _iterator13.f();
728
+ _iterator15.f();
549
729
  }
550
730
  break;
551
731
  }
552
732
  case 'designation':
553
733
  {
554
734
  var designations = Array.isArray(schedule.designation) ? schedule.designation : schedule.designation ? [schedule.designation] : [];
555
- var _iterator14 = _createForOfIteratorHelper(designations),
556
- _step14;
735
+ var _iterator16 = _createForOfIteratorHelper(designations),
736
+ _step16;
557
737
  try {
558
- for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
559
- var designation = _step14.value;
738
+ for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
739
+ var designation = _step16.value;
560
740
  this.addRawTimePoint(timePoints, designation.start_time);
561
741
  this.addRawTimePoint(timePoints, designation.end_time);
562
742
  }
563
743
  } catch (err) {
564
- _iterator14.e(err);
744
+ _iterator16.e(err);
565
745
  } finally {
566
- _iterator14.f();
746
+ _iterator16.f();
567
747
  }
568
748
  break;
569
749
  }
@@ -572,12 +752,12 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
572
752
  }
573
753
  }
574
754
  } catch (err) {
575
- _iterator12.e(err);
755
+ _iterator14.e(err);
576
756
  } finally {
577
- _iterator12.f();
757
+ _iterator14.f();
578
758
  }
579
759
  return Array.from(timePoints).sort(function (a, b) {
580
- return _this4.timeToMinutes(a) - _this4.timeToMinutes(b);
760
+ return _this6.timeToMinutes(a) - _this6.timeToMinutes(b);
581
761
  });
582
762
  }
583
763
  }, {
@@ -624,14 +804,14 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
624
804
  key: "isProductInMenuScope",
625
805
  value: function isProductInMenuScope(product, scope) {
626
806
  var _product$id,
627
- _this5 = this;
807
+ _this7 = this;
628
808
  if (scope.isAllProducts) return true;
629
809
  if (!product || _typeof(product) !== 'object') return false;
630
810
  var productId = this.toNumber((_product$id = product.id) !== null && _product$id !== void 0 ? _product$id : product.product_id);
631
811
  var variantId = this.toNumber(product.product_variant_id);
632
812
  var productKey = this.buildProductKey(productId, variantId);
633
813
  var collectionIds = Array.isArray(product.collection_ids) ? product.collection_ids.map(function (id) {
634
- return _this5.toNumber(id);
814
+ return _this7.toNumber(id);
635
815
  }) : [];
636
816
  return collectionIds.some(function (id) {
637
817
  return scope.collectionIds.has(id);
@@ -640,6 +820,7 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
640
820
  }, {
641
821
  key: "mergeMatchedVariants",
642
822
  value: function mergeMatchedVariants(product, matchedVariants) {
823
+ var _this8 = this;
643
824
  var original = _objectSpread({}, product);
644
825
  var sortedVariants = _toConsumableArray(matchedVariants).sort(function (a, b) {
645
826
  if (a.priority !== b.priority) return a.priority - b.priority;
@@ -648,11 +829,11 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
648
829
  var result = _objectSpread({}, product);
649
830
  var appliedRuleIds = [];
650
831
  var appliedFields = new Set();
651
- var _iterator15 = _createForOfIteratorHelper(sortedVariants),
652
- _step15;
832
+ var _iterator17 = _createForOfIteratorHelper(sortedVariants),
833
+ _step17;
653
834
  try {
654
- for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
655
- var matched = _step15.value;
835
+ for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
836
+ var matched = _step17.value;
656
837
  for (var _i = 0, _Object$entries = Object.entries(matched.data); _i < _Object$entries.length; _i++) {
657
838
  var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
658
839
  key = _Object$entries$_i[0],
@@ -664,12 +845,17 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
664
845
  appliedRuleIds.push(matched.ruleId);
665
846
  }
666
847
  } catch (err) {
667
- _iterator15.e(err);
848
+ _iterator17.e(err);
668
849
  } finally {
669
- _iterator15.f();
850
+ _iterator17.f();
670
851
  }
671
852
  result._dataVariant = {
672
853
  appliedRuleIds: appliedRuleIds,
854
+ appliedVariantIds: Array.from(new Set(_toConsumableArray(sortedVariants).reverse().map(function (matched) {
855
+ return _this8.normalizeDataVariantId(matched.variant.id);
856
+ }).filter(function (id) {
857
+ return id !== null;
858
+ }))),
673
859
  appliedFields: Array.from(appliedFields),
674
860
  original: original
675
861
  };
@@ -718,11 +904,11 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
718
904
  key: "flattenConditionRules",
719
905
  value: function flattenConditionRules(group) {
720
906
  var rules = [];
721
- var _iterator16 = _createForOfIteratorHelper(group.rules),
722
- _step16;
907
+ var _iterator18 = _createForOfIteratorHelper(group.rules),
908
+ _step18;
723
909
  try {
724
- for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
725
- var rule = _step16.value;
910
+ for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
911
+ var rule = _step18.value;
726
912
  if (this.isConditionGroup(rule)) {
727
913
  rules.push.apply(rules, _toConsumableArray(this.flattenConditionRules(rule)));
728
914
  } else {
@@ -730,9 +916,9 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
730
916
  }
731
917
  }
732
918
  } catch (err) {
733
- _iterator16.e(err);
919
+ _iterator18.e(err);
734
920
  } finally {
735
- _iterator16.f();
921
+ _iterator18.f();
736
922
  }
737
923
  return rules;
738
924
  }
@@ -744,10 +930,10 @@ export var DataVariantEvaluator = /*#__PURE__*/function () {
744
930
  }, {
745
931
  key: "normalizeNumberArray",
746
932
  value: function normalizeNumberArray(value) {
747
- var _this6 = this;
933
+ var _this9 = this;
748
934
  if (!Array.isArray(value)) return [];
749
935
  return value.map(function (item) {
750
- return _this6.toNumber(item);
936
+ return _this9.toNumber(item);
751
937
  }).filter(function (item) {
752
938
  return item > 0;
753
939
  });