@pisell/pisellos 2.1.170 → 2.1.171

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.
@@ -16,7 +16,6 @@ export interface VenueBookingSmartPricingContext {
16
16
  orderType?: string;
17
17
  strategy_context?: Record<string, any>;
18
18
  strategyConfigs?: StrategyConfig[];
19
- debugLog?: (title: string, payload?: Record<string, any>) => void;
20
19
  }
21
20
  /** 从商品上读取展示/算价用的 price 字段 */
22
21
  export declare function extractProductPrice(product: DataVariantProduct): string | null;
@@ -1,7 +1,3 @@
1
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
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."); }
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; } }
4
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
5
1
  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; } } }; }
6
2
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
7
3
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
@@ -33,8 +29,7 @@ export function buildDataVariantBusinessData(products, context, scheduleDateTime
33
29
  channel: (_context$channel = context.channel) !== null && _context$channel !== void 0 ? _context$channel : strategyContext.channel,
34
30
  orderType: (_ref2 = (_context$orderType = context.orderType) !== null && _context$orderType !== void 0 ? _context$orderType : strategyContext.orderType) !== null && _ref2 !== void 0 ? _ref2 : strategyContext.order_type,
35
31
  businessCode: (_ref3 = (_context$businessCode = context.businessCode) !== null && _context$businessCode !== void 0 ? _context$businessCode : strategyContext.business_code) !== null && _ref3 !== void 0 ? _ref3 : strategyContext.businessCode,
36
- custom: strategyContext,
37
- debugLog: context === null || context === void 0 ? void 0 : context.debugLog
32
+ custom: strategyContext
38
33
  };
39
34
  }
40
35
 
@@ -43,7 +38,6 @@ export function buildDataVariantBusinessData(products, context, scheduleDateTime
43
38
  * evaluator 未注入时原样返回并打 warning。
44
39
  */
45
40
  export function formatProductsWithDataVariant(products, context, scheduleDateTime) {
46
- var _context$debugLog, _context$debugLog2, _result$globalEffecti, _result$globalEffecti2;
47
41
  var evaluator = context.evaluator;
48
42
  if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
49
43
  console.warn('[VenueBooking][smartPricing] dataVariantEvaluator 未注入,跳过智能定价格式化');
@@ -51,35 +45,7 @@ export function formatProductsWithDataVariant(products, context, scheduleDateTim
51
45
  }
52
46
  var resolvedAt = scheduleDateTime || dayjs().format('YYYY-MM-DD HH:mm:ss');
53
47
  var businessData = buildDataVariantBusinessData(products, context, resolvedAt);
54
- (_context$debugLog = context.debugLog) === null || _context$debugLog === void 0 || _context$debugLog.call(context, '[VenueBooking][smartPricing] formatProducts input', {
55
- scheduleDateTime: resolvedAt,
56
- customerId: businessData.customerId,
57
- availableWalletIds: businessData.availableWalletIds,
58
- channel: businessData.channel,
59
- businessCode: businessData.businessCode,
60
- orderType: businessData.orderType,
61
- productCount: products.length,
62
- products: products.map(function (product) {
63
- var _product$id;
64
- return {
65
- productId: (_product$id = product === null || product === void 0 ? void 0 : product.id) !== null && _product$id !== void 0 ? _product$id : product === null || product === void 0 ? void 0 : product.product_id,
66
- price: product === null || product === void 0 ? void 0 : product.price,
67
- sellingPrice: product === null || product === void 0 ? void 0 : product.selling_price,
68
- dataVariants: Array.isArray(product === null || product === void 0 ? void 0 : product.data_variants) ? product.data_variants.map(function (variant) {
69
- return {
70
- dataVariantRuleId: variant === null || variant === void 0 ? void 0 : variant.data_variant_rule_id,
71
- data: variant === null || variant === void 0 ? void 0 : variant.data
72
- };
73
- }) : []
74
- };
75
- })
76
- });
77
48
  var result = evaluator.resolveProducts(businessData);
78
- (_context$debugLog2 = context.debugLog) === null || _context$debugLog2 === void 0 || _context$debugLog2.call(context, '[VenueBooking][smartPricing] formatProducts output', {
79
- scheduleDateTime: resolvedAt,
80
- effectiveRuleIds: Array.from((result === null || result === void 0 || (_result$globalEffecti = result.globalEffectiveRuleMap) === null || _result$globalEffecti === void 0 || (_result$globalEffecti2 = _result$globalEffecti.keys) === null || _result$globalEffecti2 === void 0 ? void 0 : _result$globalEffecti2.call(_result$globalEffecti)) || []),
81
- resultProducts: (result === null || result === void 0 ? void 0 : result.products) || []
82
- });
83
49
  return Array.isArray(result === null || result === void 0 ? void 0 : result.products) ? result.products : products;
84
50
  }
85
51
 
@@ -155,7 +121,6 @@ export function buildSlotStartDatetime(date, label, config) {
155
121
  * key: `${productId}:${slotStart}`,value: price | null
156
122
  */
157
123
  export function buildSlotPriceMapByScheduleSegments(params) {
158
- var _context$debugLog3, _context$debugLog4;
159
124
  var products = params.products,
160
125
  productIds = params.productIds,
161
126
  date = params.date,
@@ -176,18 +141,10 @@ export function buildSlotPriceMapByScheduleSegments(params) {
176
141
  scheduleTimePoints: scheduleTimePoints
177
142
  });
178
143
  var priceCache = new Map();
179
- (_context$debugLog3 = context.debugLog) === null || _context$debugLog3 === void 0 || _context$debugLog3.call(context, '[VenueBooking][smartPricing] slot price evaluation started', {
180
- date: date,
181
- productIds: productIds,
182
- scheduleTimePoints: scheduleTimePoints,
183
- evalDatetimes: evalDatetimes,
184
- timeLabels: timeLabels
185
- });
186
144
  var _iterator3 = _createForOfIteratorHelper(evalDatetimes),
187
145
  _step3;
188
146
  try {
189
- var _loop = function _loop() {
190
- var _context$debugLog5;
147
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
191
148
  var evalDt = _step3.value;
192
149
  var resolved = formatProductsWithDataVariant(products, context, evalDt);
193
150
  var priceByProductId = new Map();
@@ -206,20 +163,6 @@ export function buildSlotPriceMapByScheduleSegments(params) {
206
163
  _iterator5.f();
207
164
  }
208
165
  priceCache.set(evalDt, priceByProductId);
209
- (_context$debugLog5 = context.debugLog) === null || _context$debugLog5 === void 0 || _context$debugLog5.call(context, '[VenueBooking][smartPricing] slot segment prices resolved', {
210
- date: date,
211
- evalDatetime: evalDt,
212
- prices: productIds.map(function (productId) {
213
- var _priceByProductId$get;
214
- return {
215
- productId: productId,
216
- price: (_priceByProductId$get = priceByProductId.get(productId)) !== null && _priceByProductId$get !== void 0 ? _priceByProductId$get : null
217
- };
218
- })
219
- });
220
- };
221
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
222
- _loop();
223
166
  }
224
167
  } catch (err) {
225
168
  _iterator3.e(err);
@@ -233,15 +176,15 @@ export function buildSlotPriceMapByScheduleSegments(params) {
233
176
  var label = _step4.value;
234
177
  var slotStart = buildSlotStartDatetime(date, label, config);
235
178
  var segmentEvalDt = findSegmentEvalDatetime(slotStart, evalDatetimes);
236
- var priceByProductId = priceCache.get(segmentEvalDt);
179
+ var _priceByProductId = priceCache.get(segmentEvalDt);
237
180
  var _iterator6 = _createForOfIteratorHelper(productIds),
238
181
  _step6;
239
182
  try {
240
183
  for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
241
- var _priceByProductId$get2;
242
- var productId = _step6.value;
243
- var key = "".concat(productId, ":").concat(slotStart);
244
- var price = (_priceByProductId$get2 = priceByProductId === null || priceByProductId === void 0 ? void 0 : priceByProductId.get(productId)) !== null && _priceByProductId$get2 !== void 0 ? _priceByProductId$get2 : null;
184
+ var _priceByProductId$get;
185
+ var _productId = _step6.value;
186
+ var key = "".concat(_productId, ":").concat(slotStart);
187
+ var price = (_priceByProductId$get = _priceByProductId === null || _priceByProductId === void 0 ? void 0 : _priceByProductId.get(_productId)) !== null && _priceByProductId$get !== void 0 ? _priceByProductId$get : null;
245
188
  if (price !== null) {
246
189
  map.set(key, price);
247
190
  }
@@ -257,18 +200,6 @@ export function buildSlotPriceMapByScheduleSegments(params) {
257
200
  } finally {
258
201
  _iterator4.f();
259
202
  }
260
- (_context$debugLog4 = context.debugLog) === null || _context$debugLog4 === void 0 || _context$debugLog4.call(context, '[VenueBooking][smartPricing] slot price map completed', {
261
- date: date,
262
- entries: Array.from(map.entries()).map(function (_ref4) {
263
- var _ref5 = _slicedToArray(_ref4, 2),
264
- key = _ref5[0],
265
- price = _ref5[1];
266
- return {
267
- key: key,
268
- price: price
269
- };
270
- })
271
- });
272
203
  return map;
273
204
  }
274
205
 
@@ -276,7 +207,7 @@ export function buildSlotPriceMapByScheduleSegments(params) {
276
207
  * 指定商品在某一 datetime 的智能定价(addon / 单点重算用)。
277
208
  */
278
209
  export function getPriceForProductAtDatetime(params) {
279
- var _ref6, _extractProductPrice;
210
+ var _ref4, _extractProductPrice;
280
211
  var products = params.products,
281
212
  context = params.context,
282
213
  productId = params.productId,
@@ -286,7 +217,7 @@ export function getPriceForProductAtDatetime(params) {
286
217
  var product = resolved.find(function (item) {
287
218
  return Number(item.id) === Number(productId);
288
219
  });
289
- return (_ref6 = (_extractProductPrice = extractProductPrice(product || {})) !== null && _extractProductPrice !== void 0 ? _extractProductPrice : fallbackPrice) !== null && _ref6 !== void 0 ? _ref6 : '0.00';
220
+ return (_ref4 = (_extractProductPrice = extractProductPrice(product || {})) !== null && _extractProductPrice !== void 0 ? _extractProductPrice : fallbackPrice) !== null && _ref4 !== void 0 ? _ref4 : '0.00';
290
221
  }
291
222
 
292
223
  /** 从 slot 价格 Map 读取单价,找不到则回退 fallback */
@@ -46,7 +46,6 @@ var DataVariantEvaluator = class {
46
46
  * 先执行全局预计算,再只针对商品自身 data_variants 引用到的规则做商品级判断。
47
47
  */
48
48
  resolveProducts(businessData) {
49
- var _a;
50
49
  const strategyConfigs = businessData.strategyConfigs ? this.normalizeStrategyConfigs(businessData.strategyConfigs) : this.strategyConfigs;
51
50
  const menuScopeMap = this.buildMenuScopeMap(businessData.menuList || []);
52
51
  const scheduleTimePoints = this.buildScheduleTimePoints(
@@ -58,14 +57,12 @@ var DataVariantEvaluator = class {
58
57
  businessData,
59
58
  menuScopeMap
60
59
  );
61
- const productDiagnostics = businessData.debugLog ? [] : void 0;
62
60
  const products = businessData.products.map((product) => {
63
61
  const resolvedProduct = this.resolveProduct(
64
62
  product,
65
63
  businessData,
66
64
  globalEffectiveRuleMap,
67
- menuScopeMap,
68
- productDiagnostics
65
+ menuScopeMap
69
66
  );
70
67
  return this.resolveProductBundleItems(
71
68
  resolvedProduct,
@@ -74,32 +71,6 @@ var DataVariantEvaluator = class {
74
71
  menuScopeMap
75
72
  );
76
73
  });
77
- (_a = businessData == null ? void 0 : businessData.debugLog) == null ? void 0 : _a.call(businessData, "[VenueBooking][smartPricing] evaluator result", {
78
- scheduleDateTime: businessData.scheduleDateTime,
79
- strategyConfigs: strategyConfigs.map((config) => {
80
- var _a2, _b, _c, _d;
81
- return {
82
- ruleId: String((_a2 = config == null ? void 0 : config.metadata) == null ? void 0 : _a2.id),
83
- name: (_b = config == null ? void 0 : config.metadata) == null ? void 0 : _b.name,
84
- status: (_d = (_c = config == null ? void 0 : config.metadata) == null ? void 0 : _c.custom) == null ? void 0 : _d.status,
85
- priority: this.getStrategyPriority(config),
86
- conditions: config == null ? void 0 : config.conditions
87
- };
88
- }),
89
- globalRuleResults: rawResults.map((result) => {
90
- var _a2, _b, _c, _d;
91
- return {
92
- ruleId: String((_b = (_a2 = result == null ? void 0 : result.config) == null ? void 0 : _a2.metadata) == null ? void 0 : _b.id),
93
- name: (_d = (_c = result == null ? void 0 : result.config) == null ? void 0 : _c.metadata) == null ? void 0 : _d.name,
94
- applicable: result == null ? void 0 : result.applicable,
95
- code: result == null ? void 0 : result.code,
96
- message: result == null ? void 0 : result.message,
97
- matched: result == null ? void 0 : result.matched
98
- };
99
- }),
100
- effectiveRuleIds: Array.from(globalEffectiveRuleMap.keys()),
101
- productDiagnostics: productDiagnostics || []
102
- });
103
74
  return {
104
75
  products,
105
76
  globalEffectiveRuleMap,
@@ -206,57 +177,20 @@ var DataVariantEvaluator = class {
206
177
  }
207
178
  return { globalEffectiveRuleMap, rawResults };
208
179
  }
209
- resolveProduct(product, businessData, globalEffectiveRuleMap, menuScopeMap, diagnostics) {
210
- var _a, _b;
180
+ resolveProduct(product, businessData, globalEffectiveRuleMap, menuScopeMap) {
211
181
  const dataVariants = this.getProductDataVariants(product);
212
- const productId = (product == null ? void 0 : product.id) ?? (product == null ? void 0 : product.product_id);
213
- if (!dataVariants.length) {
214
- diagnostics == null ? void 0 : diagnostics.push({
215
- productId,
216
- originalPrice: (product == null ? void 0 : product.price) ?? (product == null ? void 0 : product.selling_price),
217
- finalPrice: (product == null ? void 0 : product.price) ?? (product == null ? void 0 : product.selling_price),
218
- reason: "product has no data_variants",
219
- variants: []
220
- });
182
+ if (!dataVariants.length)
221
183
  return product;
222
- }
223
184
  const matchedVariants = [];
224
- const variantDiagnostics = [];
225
185
  for (const variant of dataVariants) {
226
- const ruleId = String(variant.data_variant_rule_id);
227
186
  const rule = globalEffectiveRuleMap.get(
228
- ruleId
187
+ String(variant.data_variant_rule_id)
229
188
  );
230
- if (!rule) {
231
- variantDiagnostics.push({
232
- ruleId,
233
- variantData: variant.data || {},
234
- globalRuleEffective: false,
235
- productRulesMatched: false,
236
- reason: "referenced rule is missing or its global conditions did not match"
237
- });
189
+ if (!rule)
238
190
  continue;
239
- }
240
- const productRulesMatched = this.evaluateProductRules(rule, product, businessData, menuScopeMap);
241
- if (!productRulesMatched) {
242
- variantDiagnostics.push({
243
- ruleId,
244
- variantData: variant.data || {},
245
- globalRuleEffective: true,
246
- productRulesMatched: false,
247
- productRules: rule.productRules,
248
- reason: "product-level conditions did not match"
249
- });
191
+ if (!this.evaluateProductRules(rule, product, businessData, menuScopeMap)) {
250
192
  continue;
251
193
  }
252
- variantDiagnostics.push({
253
- ruleId,
254
- variantData: variant.data || {},
255
- globalRuleEffective: true,
256
- productRulesMatched: true,
257
- priority: rule.priority,
258
- reason: "variant matched and will be merged into the product"
259
- });
260
194
  matchedVariants.push({
261
195
  ruleId: rule.ruleId,
262
196
  priority: rule.priority,
@@ -264,26 +198,9 @@ var DataVariantEvaluator = class {
264
198
  variant
265
199
  });
266
200
  }
267
- if (!matchedVariants.length) {
268
- diagnostics == null ? void 0 : diagnostics.push({
269
- productId,
270
- originalPrice: (product == null ? void 0 : product.price) ?? (product == null ? void 0 : product.selling_price),
271
- finalPrice: (product == null ? void 0 : product.price) ?? (product == null ? void 0 : product.selling_price),
272
- reason: "no data_variant matched",
273
- variants: variantDiagnostics
274
- });
201
+ if (!matchedVariants.length)
275
202
  return product;
276
- }
277
- const resolvedProduct = this.mergeMatchedVariants(product, matchedVariants);
278
- diagnostics == null ? void 0 : diagnostics.push({
279
- productId,
280
- originalPrice: (product == null ? void 0 : product.price) ?? (product == null ? void 0 : product.selling_price),
281
- finalPrice: (resolvedProduct == null ? void 0 : resolvedProduct.price) ?? (resolvedProduct == null ? void 0 : resolvedProduct.selling_price),
282
- appliedRuleIds: ((_a = resolvedProduct == null ? void 0 : resolvedProduct._dataVariant) == null ? void 0 : _a.appliedRuleIds) || [],
283
- appliedFields: ((_b = resolvedProduct == null ? void 0 : resolvedProduct._dataVariant) == null ? void 0 : _b.appliedFields) || [],
284
- variants: variantDiagnostics
285
- });
286
- return resolvedProduct;
203
+ return this.mergeMatchedVariants(product, matchedVariants);
287
204
  }
288
205
  /**
289
206
  * 解析套餐子商品上的 Data Variant 覆盖。
@@ -105,7 +105,6 @@ export interface DataVariantBusinessData {
105
105
  /** 当前客户可用 wallet/pass id 合并列表,对应策略条件 field: available_wallet_ids */
106
106
  availableWalletIds?: Array<number | string>;
107
107
  custom?: Record<string, any>;
108
- debugLog?: (title: string, payload?: Record<string, any>) => void;
109
108
  }
110
109
  /**
111
110
  * 全局预计算后的规则信息。
@@ -310,7 +310,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
310
310
  date: string;
311
311
  status: string;
312
312
  week: string;
313
- weekNum: 0 | 2 | 1 | 5 | 4 | 3 | 6;
313
+ weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
314
314
  }[]>;
315
315
  submitTimeSlot(timeSlots: TimeSliceItem): void;
316
316
  private getScheduleDataByIds;
@@ -62,6 +62,8 @@ export declare class VenueBookingImpl extends BaseModule implements Module {
62
62
  private logPricingDiagnostics;
63
63
  private isPricingDiagnosticsEnabled;
64
64
  private getAvailableWalletIdsForDiagnostics;
65
+ private getOrderPricingSnapshotForDiagnostics;
66
+ private getCatalogPricingSnapshotForDiagnostics;
65
67
  private logMethodStart;
66
68
  private logMethodSuccess;
67
69
  private logMethodError;
@@ -181,6 +183,14 @@ export declare class VenueBookingImpl extends BaseModule implements Module {
181
183
  onCustomerLogin(params: {
182
184
  customerId: number;
183
185
  }): Promise<void>;
186
+ /**
187
+ * 接收 pisell2 VenueBooking 登录链路诊断日志。
188
+ * 实际是否上报仍由 OS 内部 cacheId 白名单统一控制。
189
+ */
190
+ logPricingDiagnosticsFromClient(params: {
191
+ title: string;
192
+ payload?: Record<string, any>;
193
+ }): void;
184
194
  private recalculateOrderPricesFromSmartPricing;
185
195
  /**
186
196
  * DataVariant 重算价格后,同步刷新订单展示、Rules 与 Summary 共用的价格口径。