@pisell/pisellos 2.1.168 → 2.1.170

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 (75) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +3 -0
  3. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
  4. package/dist/model/strategy/adapter/dataVariant/adapter.js +167 -0
  5. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
  6. package/dist/model/strategy/adapter/dataVariant/evaluator.js +867 -0
  7. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  8. package/dist/model/strategy/adapter/dataVariant/examples.js +277 -0
  9. package/dist/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  10. package/dist/model/strategy/adapter/dataVariant/index.js +4 -0
  11. package/dist/model/strategy/adapter/dataVariant/type.d.ts +149 -0
  12. package/dist/model/strategy/adapter/dataVariant/type.js +54 -0
  13. package/dist/model/strategy/adapter/index.d.ts +4 -0
  14. package/dist/model/strategy/adapter/index.js +5 -1
  15. package/dist/modules/Discount/index.d.ts +5 -2
  16. package/dist/modules/Discount/index.js +21 -1
  17. package/dist/modules/Discount/types.d.ts +4 -0
  18. package/dist/modules/Order/index.d.ts +1 -0
  19. package/dist/modules/Order/index.js +18 -6
  20. package/dist/modules/Order/types.d.ts +2 -0
  21. package/dist/modules/ProductList/index.d.ts +3 -1
  22. package/dist/modules/ProductList/index.js +22 -11
  23. package/dist/modules/Schedule/getDateIsInSchedule.js +5 -0
  24. package/dist/solution/ScanOrder/index.js +1 -1
  25. package/dist/solution/ShopDiscount/index.js +16 -15
  26. package/dist/solution/VenueBooking/index.d.ts +49 -3
  27. package/dist/solution/VenueBooking/index.js +537 -287
  28. package/dist/solution/VenueBooking/types.d.ts +3 -1
  29. package/dist/solution/VenueBooking/types.js +1 -0
  30. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  31. package/dist/solution/VenueBooking/utils/dateSummary.js +12 -25
  32. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -6
  33. package/dist/solution/VenueBooking/utils/slotMerge.js +3 -9
  34. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +71 -0
  35. package/dist/solution/VenueBooking/utils/smartPricing.js +302 -0
  36. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +2 -0
  37. package/dist/solution/VenueBooking/utils/timeSlot.js +9 -4
  38. package/lib/index.d.ts +1 -0
  39. package/lib/index.js +3 -0
  40. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
  41. package/lib/model/strategy/adapter/dataVariant/adapter.js +149 -0
  42. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
  43. package/lib/model/strategy/adapter/dataVariant/evaluator.js +666 -0
  44. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  45. package/lib/model/strategy/adapter/dataVariant/examples.js +293 -0
  46. package/lib/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  47. package/lib/model/strategy/adapter/dataVariant/index.js +38 -0
  48. package/lib/model/strategy/adapter/dataVariant/type.d.ts +149 -0
  49. package/lib/model/strategy/adapter/dataVariant/type.js +31 -0
  50. package/lib/model/strategy/adapter/index.d.ts +4 -0
  51. package/lib/model/strategy/adapter/index.js +13 -2
  52. package/lib/modules/Discount/index.d.ts +5 -2
  53. package/lib/modules/Discount/index.js +11 -1
  54. package/lib/modules/Discount/types.d.ts +4 -0
  55. package/lib/modules/Order/index.d.ts +1 -0
  56. package/lib/modules/Order/index.js +11 -1
  57. package/lib/modules/Order/types.d.ts +2 -0
  58. package/lib/modules/ProductList/index.d.ts +3 -1
  59. package/lib/modules/ProductList/index.js +45 -39
  60. package/lib/modules/Schedule/getDateIsInSchedule.js +4 -0
  61. package/lib/solution/ScanOrder/index.js +1 -1
  62. package/lib/solution/ShopDiscount/index.js +3 -2
  63. package/lib/solution/VenueBooking/index.d.ts +49 -3
  64. package/lib/solution/VenueBooking/index.js +362 -113
  65. package/lib/solution/VenueBooking/types.d.ts +3 -1
  66. package/lib/solution/VenueBooking/types.js +1 -0
  67. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  68. package/lib/solution/VenueBooking/utils/dateSummary.js +5 -10
  69. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -6
  70. package/lib/solution/VenueBooking/utils/slotMerge.js +3 -4
  71. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +71 -0
  72. package/lib/solution/VenueBooking/utils/smartPricing.js +225 -0
  73. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +2 -0
  74. package/lib/solution/VenueBooking/utils/timeSlot.js +7 -3
  75. package/package.json +1 -1
@@ -6,7 +6,9 @@ export declare enum VenueBookingHooks {
6
6
  onDestroy = "venueBooking:onDestroy",
7
7
  onRetryInit = "venueBooking:onRetryInit",
8
8
  onRefresh = "venueBooking:onRefresh",
9
- onCartValidationChanged = "venueBooking:onCartValidationChanged"
9
+ onCartValidationChanged = "venueBooking:onCartValidationChanged",
10
+ /** 登录客户的智能定价、营销配置与订单汇总已完成刷新 */
11
+ onSmartPricingUpdated = "venueBooking:onSmartPricingUpdated"
10
12
  }
11
13
  export type VenueBookingStatus = 'idle' | 'initializing' | 'ready' | 'error';
12
14
  export interface VenueBookingEntryContext {
@@ -4,6 +4,7 @@ export var VenueBookingHooks = /*#__PURE__*/function (VenueBookingHooks) {
4
4
  VenueBookingHooks["onRetryInit"] = "venueBooking:onRetryInit";
5
5
  VenueBookingHooks["onRefresh"] = "venueBooking:onRefresh";
6
6
  VenueBookingHooks["onCartValidationChanged"] = "venueBooking:onCartValidationChanged";
7
+ VenueBookingHooks["onSmartPricingUpdated"] = "venueBooking:onSmartPricingUpdated";
7
8
  return VenueBookingHooks;
8
9
  }({});
9
10
 
@@ -1,11 +1,11 @@
1
1
  import type { VenueBookingSlotConfig, VenueResourceRawData, VenueDateSummaryItem, ResourceProductMapping } from '../types';
2
- import type { QuotationModule } from '../../../modules/Quotation';
3
2
  export declare function buildDateRangeSummary(params: {
4
3
  startDate: string;
5
4
  endDate: string;
6
5
  config: VenueBookingSlotConfig;
7
6
  rawResources: VenueResourceRawData[];
8
7
  resourceProductMap: Map<number | string, ResourceProductMapping[]>;
9
- quotationModule?: QuotationModule;
10
8
  resolveConfig?: (date: string) => VenueBookingSlotConfig;
9
+ /** 按日期构建 slot 智能定价 Map */
10
+ buildSlotPriceMap?: (date: string, config: VenueBookingSlotConfig, productIds: number[]) => Map<string, string | null>;
11
11
  }): VenueDateSummaryItem[];
@@ -6,41 +6,31 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
6
6
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
7
  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; }
8
8
  import dayjs from 'dayjs';
9
- import { buildTimeSlotGrid, generateTimeLabels } from "./timeSlot";
9
+ import { buildTimeSlotGrid } from "./timeSlot";
10
10
  export function buildDateRangeSummary(params) {
11
11
  var startDate = params.startDate,
12
12
  endDate = params.endDate,
13
13
  config = params.config,
14
14
  rawResources = params.rawResources,
15
15
  resourceProductMap = params.resourceProductMap,
16
- quotationModule = params.quotationModule,
17
- resolveConfig = params.resolveConfig;
16
+ resolveConfig = params.resolveConfig,
17
+ buildSlotPriceMap = params.buildSlotPriceMap;
18
18
  var result = [];
19
- var productIds = quotationModule ? _toConsumableArray(new Set(_toConsumableArray(resourceProductMap.values()).flat().map(function (m) {
19
+ var productIds = buildSlotPriceMap ? _toConsumableArray(new Set(_toConsumableArray(resourceProductMap.values()).flat().map(function (m) {
20
20
  return m.productId;
21
21
  }))) : [];
22
22
  var cursor = dayjs(startDate);
23
23
  var end = dayjs(endDate);
24
- var _loop = function _loop() {
25
- var date = cursor.format('YYYY-MM-DD');
26
- var effectiveConfig = (resolveConfig === null || resolveConfig === void 0 ? void 0 : resolveConfig(date)) || config;
27
- var quotationPriceMap;
28
- if (quotationModule && productIds.length) {
29
- var timeLabels = generateTimeLabels(effectiveConfig);
30
- var timePoints = timeLabels.map(function (label) {
31
- return "".concat(date, " ").concat(label);
32
- });
33
- quotationPriceMap = quotationModule.buildProductPriceMap({
34
- productIds: productIds,
35
- timePoints: timePoints
36
- });
37
- }
24
+ while (!cursor.isAfter(end)) {
25
+ var _date = cursor.format('YYYY-MM-DD');
26
+ var effectiveConfig = (resolveConfig === null || resolveConfig === void 0 ? void 0 : resolveConfig(_date)) || config;
27
+ var slotPriceMap = buildSlotPriceMap && productIds.length ? buildSlotPriceMap(_date, effectiveConfig, productIds) : undefined;
38
28
  var grid = buildTimeSlotGrid({
39
- date: date,
29
+ date: _date,
40
30
  config: effectiveConfig,
41
31
  rawResources: rawResources,
42
32
  resourceProductMap: resourceProductMap,
43
- quotationPriceMap: quotationPriceMap
33
+ slotPriceMap: slotPriceMap
44
34
  });
45
35
  var totalSlots = 0;
46
36
  var availableSlots = 0;
@@ -78,7 +68,7 @@ export function buildDateRangeSummary(params) {
78
68
  } finally {
79
69
  _iterator.f();
80
70
  }
81
- var status;
71
+ var status = void 0;
82
72
  if (totalSlots === 0) {
83
73
  status = 'unavailable';
84
74
  } else if (availableSlots === 0) {
@@ -89,16 +79,13 @@ export function buildDateRangeSummary(params) {
89
79
  status = 'available';
90
80
  }
91
81
  result.push({
92
- date: date,
82
+ date: _date,
93
83
  status: status,
94
84
  startingPrice: lowestPrice !== null ? lowestPrice.toFixed(2) : null,
95
85
  totalSlots: totalSlots,
96
86
  availableSlots: availableSlots
97
87
  });
98
88
  cursor = cursor.add(1, 'day');
99
- };
100
- while (!cursor.isAfter(end)) {
101
- _loop();
102
89
  }
103
90
  return result;
104
91
  }
@@ -5,12 +5,6 @@ export declare function mergeConsecutiveSlots(slots: VenueSlotSelection[]): Merg
5
5
  export declare function buildPriceBreakdown(params: {
6
6
  group: MergedSlotGroup;
7
7
  productId: number;
8
- quotation?: {
9
- getQuotationShelfId: (p: {
10
- productId: number;
11
- datetime: string;
12
- }) => number;
13
- };
14
8
  }): PriceBreakdownEntry[];
15
9
  export interface BuildVenueBookingParams {
16
10
  group: MergedSlotGroup;
@@ -51,9 +51,7 @@ export function mergeConsecutiveSlots(slots) {
51
51
  return groups;
52
52
  }
53
53
  export function buildPriceBreakdown(params) {
54
- var group = params.group,
55
- productId = params.productId,
56
- quotation = params.quotation;
54
+ var group = params.group;
57
55
  if (!group.slots.length) return [];
58
56
  var entries = [];
59
57
  var _iterator = _createForOfIteratorHelper(group.slots),
@@ -62,14 +60,10 @@ export function buildPriceBreakdown(params) {
62
60
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
63
61
  var slot = _step.value;
64
62
  var unitPrice = Number(slot.price || '0');
65
- var shelfId = quotation ? quotation.getQuotationShelfId({
66
- productId: productId,
67
- datetime: slot.startTime
68
- }) : 0;
69
63
  var startHm = dayjs(slot.startTime, 'YYYY-MM-DD HH:mm').format('YYYY-MM-DD HH:mm');
70
64
  var endHm = dayjs(slot.endTime, 'YYYY-MM-DD HH:mm').format('YYYY-MM-DD HH:mm');
71
65
  var last = entries[entries.length - 1];
72
- if (last && last.unit_price === unitPrice && last.quotation_shelf_id === shelfId && last.end_time === startHm) {
66
+ if (last && last.unit_price === unitPrice && last.quotation_shelf_id === 0 && last.end_time === startHm) {
73
67
  last.end_time = endHm;
74
68
  last.quantity += 1;
75
69
  } else {
@@ -77,7 +71,7 @@ export function buildPriceBreakdown(params) {
77
71
  start_time: startHm,
78
72
  end_time: endHm,
79
73
  unit_price: unitPrice,
80
- quotation_shelf_id: shelfId,
74
+ quotation_shelf_id: 0,
81
75
  quantity: 1
82
76
  });
83
77
  }
@@ -0,0 +1,71 @@
1
+ import type { ProductData } from '../../../modules/Product/types';
2
+ import type { ScheduleItem } from '../../../modules/Schedule/types';
3
+ import type { DataVariantBusinessData, DataVariantMenu, DataVariantProduct } from '../../../model/strategy/adapter/dataVariant/type';
4
+ import type { DataVariantEvaluator } from '../../../model/strategy/adapter/dataVariant/evaluator';
5
+ import type { StrategyConfig } from '../../../model/strategy/type';
6
+ import type { VenueBookingSlotConfig } from '../types';
7
+ /** VenueBooking 智能定价运行时上下文 */
8
+ export interface VenueBookingSmartPricingContext {
9
+ evaluator?: DataVariantEvaluator | null;
10
+ scheduleList?: ScheduleItem[];
11
+ menuList?: DataVariantMenu[];
12
+ customerId?: number | string;
13
+ availableWalletIds?: Array<number | string>;
14
+ channel?: string;
15
+ businessCode?: string;
16
+ orderType?: string;
17
+ strategy_context?: Record<string, any>;
18
+ strategyConfigs?: StrategyConfig[];
19
+ debugLog?: (title: string, payload?: Record<string, any>) => void;
20
+ }
21
+ /** 从商品上读取展示/算价用的 price 字段 */
22
+ export declare function extractProductPrice(product: DataVariantProduct): string | null;
23
+ /** 组装 DataVariant 评估入参,对齐 OS Server buildProductFormatterContext 语义 */
24
+ export declare function buildDataVariantBusinessData(products: ProductData[], context: VenueBookingSmartPricingContext, scheduleDateTime: string): DataVariantBusinessData;
25
+ /**
26
+ * 对商品列表执行一次智能定价格式化(loadProducts 后使用)。
27
+ * evaluator 未注入时原样返回并打 warning。
28
+ */
29
+ export declare function formatProductsWithDataVariant(products: ProductData[], context: VenueBookingSmartPricingContext, scheduleDateTime?: string): ProductData[];
30
+ /**
31
+ * 根据 schedule_time_points 与营业开始时间,构造当天需要评估的 datetime 列表(升序)。
32
+ * 跨日营业时,早于营业开始小时的时间点归到次日。
33
+ */
34
+ export declare function buildEvaluationDatetimes(params: {
35
+ date: string;
36
+ config: VenueBookingSlotConfig;
37
+ scheduleTimePoints: string[];
38
+ }): string[];
39
+ /** 找到 slot 时间所属分段的评估 datetime(max(evalDt <= slotDt)) */
40
+ export declare function findSegmentEvalDatetime(slotDatetime: string, evalDatetimes: string[]): string;
41
+ /** 将 slot 标签转为与 timeSlot 网格一致的 slotStart 字符串 */
42
+ export declare function buildSlotStartDatetime(date: string, label: string, config: VenueBookingSlotConfig): string;
43
+ /**
44
+ * 按 schedule 分段批量 resolveProducts,输出与 quotation 相同 key 格式的 slot 价格 Map。
45
+ * key: `${productId}:${slotStart}`,value: price | null
46
+ */
47
+ export declare function buildSlotPriceMapByScheduleSegments(params: {
48
+ products: ProductData[];
49
+ productIds: number[];
50
+ date: string;
51
+ timeLabels: string[];
52
+ config: VenueBookingSlotConfig;
53
+ context: VenueBookingSmartPricingContext;
54
+ }): Map<string, string | null>;
55
+ /**
56
+ * 指定商品在某一 datetime 的智能定价(addon / 单点重算用)。
57
+ */
58
+ export declare function getPriceForProductAtDatetime(params: {
59
+ products: ProductData[];
60
+ context: VenueBookingSmartPricingContext;
61
+ productId: number;
62
+ datetime: string;
63
+ fallbackPrice?: string;
64
+ }): string;
65
+ /** 从 slot 价格 Map 读取单价,找不到则回退 fallback */
66
+ export declare function getSlotPriceFromMap(params: {
67
+ slotPriceMap: Map<string, string | null>;
68
+ productId: number;
69
+ slotStartTime: string;
70
+ fallbackPrice?: string;
71
+ }): string;
@@ -0,0 +1,302 @@
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
+ 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
+ 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
+ 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; }
8
+ import dayjs from 'dayjs';
9
+ import { isBusinessHoursCrossDay } from "./timeSlot";
10
+
11
+ /** VenueBooking 智能定价运行时上下文 */
12
+
13
+ /** 从商品上读取展示/算价用的 price 字段 */
14
+ export function extractProductPrice(product) {
15
+ var _product$price;
16
+ var price = (_product$price = product === null || product === void 0 ? void 0 : product.price) !== null && _product$price !== void 0 ? _product$price : product === null || product === void 0 ? void 0 : product.selling_price;
17
+ if (price == null || price === '') return null;
18
+ return String(price);
19
+ }
20
+
21
+ /** 组装 DataVariant 评估入参,对齐 OS Server buildProductFormatterContext 语义 */
22
+ export function buildDataVariantBusinessData(products, context, scheduleDateTime) {
23
+ var _ref, _context$availableWal, _context$channel, _ref2, _context$orderType, _ref3, _context$businessCode;
24
+ var strategyContext = context.strategy_context || {};
25
+ return {
26
+ products: products,
27
+ strategyConfigs: context.strategyConfigs,
28
+ scheduleDateTime: scheduleDateTime,
29
+ scheduleList: context.scheduleList || [],
30
+ menuList: context.menuList || [],
31
+ customerId: context.customerId,
32
+ availableWalletIds: (_ref = (_context$availableWal = context.availableWalletIds) !== null && _context$availableWal !== void 0 ? _context$availableWal : strategyContext.available_wallet_ids) !== null && _ref !== void 0 ? _ref : strategyContext.availableWalletIds,
33
+ channel: (_context$channel = context.channel) !== null && _context$channel !== void 0 ? _context$channel : strategyContext.channel,
34
+ orderType: (_ref2 = (_context$orderType = context.orderType) !== null && _context$orderType !== void 0 ? _context$orderType : strategyContext.orderType) !== null && _ref2 !== void 0 ? _ref2 : strategyContext.order_type,
35
+ 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
38
+ };
39
+ }
40
+
41
+ /**
42
+ * 对商品列表执行一次智能定价格式化(loadProducts 后使用)。
43
+ * evaluator 未注入时原样返回并打 warning。
44
+ */
45
+ export function formatProductsWithDataVariant(products, context, scheduleDateTime) {
46
+ var _context$debugLog, _context$debugLog2, _result$globalEffecti, _result$globalEffecti2;
47
+ var evaluator = context.evaluator;
48
+ if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
49
+ console.warn('[VenueBooking][smartPricing] dataVariantEvaluator 未注入,跳过智能定价格式化');
50
+ return products;
51
+ }
52
+ var resolvedAt = scheduleDateTime || dayjs().format('YYYY-MM-DD HH:mm:ss');
53
+ 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
+ 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
+ return Array.isArray(result === null || result === void 0 ? void 0 : result.products) ? result.products : products;
84
+ }
85
+
86
+ /**
87
+ * 根据 schedule_time_points 与营业开始时间,构造当天需要评估的 datetime 列表(升序)。
88
+ * 跨日营业时,早于营业开始小时的时间点归到次日。
89
+ */
90
+ export function buildEvaluationDatetimes(params) {
91
+ var date = params.date,
92
+ config = params.config,
93
+ scheduleTimePoints = params.scheduleTimePoints;
94
+ var crossDay = isBusinessHoursCrossDay(config);
95
+ var businessStartHour = Number(config.businessStartTime.split(':')[0]);
96
+ var evalSet = new Set();
97
+ evalSet.add("".concat(date, " ").concat(config.businessStartTime));
98
+ var _iterator = _createForOfIteratorHelper(scheduleTimePoints),
99
+ _step;
100
+ try {
101
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
102
+ var timePoint = _step.value;
103
+ var hour = Number(timePoint.split(':')[0]);
104
+ var pointDate = crossDay && hour < businessStartHour ? dayjs(date).add(1, 'day').format('YYYY-MM-DD') : date;
105
+ evalSet.add("".concat(pointDate, " ").concat(timePoint));
106
+ }
107
+ } catch (err) {
108
+ _iterator.e(err);
109
+ } finally {
110
+ _iterator.f();
111
+ }
112
+ return Array.from(evalSet).sort(function (a, b) {
113
+ var aMs = dayjs(a, ['YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD HH:mm']).valueOf();
114
+ var bMs = dayjs(b, ['YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD HH:mm']).valueOf();
115
+ return aMs - bMs;
116
+ });
117
+ }
118
+
119
+ /** 找到 slot 时间所属分段的评估 datetime(max(evalDt <= slotDt)) */
120
+ export function findSegmentEvalDatetime(slotDatetime, evalDatetimes) {
121
+ if (!evalDatetimes.length) return slotDatetime;
122
+ var slotMs = dayjs(slotDatetime, ['YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD HH:mm']).valueOf();
123
+ var chosen = evalDatetimes[0];
124
+ var _iterator2 = _createForOfIteratorHelper(evalDatetimes),
125
+ _step2;
126
+ try {
127
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
128
+ var evalDt = _step2.value;
129
+ var evalMs = dayjs(evalDt, ['YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD HH:mm']).valueOf();
130
+ if (evalMs <= slotMs) {
131
+ chosen = evalDt;
132
+ } else {
133
+ break;
134
+ }
135
+ }
136
+ } catch (err) {
137
+ _iterator2.e(err);
138
+ } finally {
139
+ _iterator2.f();
140
+ }
141
+ return chosen;
142
+ }
143
+
144
+ /** 将 slot 标签转为与 timeSlot 网格一致的 slotStart 字符串 */
145
+ export function buildSlotStartDatetime(date, label, config) {
146
+ var crossDay = isBusinessHoursCrossDay(config);
147
+ var businessStartHour = Number(config.businessStartTime.split(':')[0]);
148
+ var hour = Number(label.split(':')[0]);
149
+ var slotDate = crossDay && hour < businessStartHour ? dayjs(date).add(1, 'day').format('YYYY-MM-DD') : date;
150
+ return dayjs("".concat(slotDate, " ").concat(label)).format('YYYY-MM-DD HH:mm');
151
+ }
152
+
153
+ /**
154
+ * 按 schedule 分段批量 resolveProducts,输出与 quotation 相同 key 格式的 slot 价格 Map。
155
+ * key: `${productId}:${slotStart}`,value: price | null
156
+ */
157
+ export function buildSlotPriceMapByScheduleSegments(params) {
158
+ var _context$debugLog3, _context$debugLog4;
159
+ var products = params.products,
160
+ productIds = params.productIds,
161
+ date = params.date,
162
+ timeLabels = params.timeLabels,
163
+ config = params.config,
164
+ context = params.context;
165
+ var map = new Map();
166
+ if (!productIds.length || !timeLabels.length) return map;
167
+ var evaluator = context.evaluator;
168
+ if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
169
+ return map;
170
+ }
171
+ var strategyConfigs = context.strategyConfigs || (typeof evaluator.getStrategyConfigs === 'function' ? evaluator.getStrategyConfigs() : []);
172
+ var scheduleTimePoints = typeof evaluator.buildScheduleTimePoints === 'function' ? evaluator.buildScheduleTimePoints(strategyConfigs, context.scheduleList || []) : [];
173
+ var evalDatetimes = buildEvaluationDatetimes({
174
+ date: date,
175
+ config: config,
176
+ scheduleTimePoints: scheduleTimePoints
177
+ });
178
+ 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
+ var _iterator3 = _createForOfIteratorHelper(evalDatetimes),
187
+ _step3;
188
+ try {
189
+ var _loop = function _loop() {
190
+ var _context$debugLog5;
191
+ var evalDt = _step3.value;
192
+ var resolved = formatProductsWithDataVariant(products, context, evalDt);
193
+ var priceByProductId = new Map();
194
+ var _iterator5 = _createForOfIteratorHelper(resolved),
195
+ _step5;
196
+ try {
197
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
198
+ var product = _step5.value;
199
+ var productId = Number(product.id);
200
+ if (!Number.isFinite(productId)) continue;
201
+ priceByProductId.set(productId, extractProductPrice(product));
202
+ }
203
+ } catch (err) {
204
+ _iterator5.e(err);
205
+ } finally {
206
+ _iterator5.f();
207
+ }
208
+ 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
+ }
224
+ } catch (err) {
225
+ _iterator3.e(err);
226
+ } finally {
227
+ _iterator3.f();
228
+ }
229
+ var _iterator4 = _createForOfIteratorHelper(timeLabels),
230
+ _step4;
231
+ try {
232
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
233
+ var label = _step4.value;
234
+ var slotStart = buildSlotStartDatetime(date, label, config);
235
+ var segmentEvalDt = findSegmentEvalDatetime(slotStart, evalDatetimes);
236
+ var priceByProductId = priceCache.get(segmentEvalDt);
237
+ var _iterator6 = _createForOfIteratorHelper(productIds),
238
+ _step6;
239
+ try {
240
+ 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;
245
+ if (price !== null) {
246
+ map.set(key, price);
247
+ }
248
+ }
249
+ } catch (err) {
250
+ _iterator6.e(err);
251
+ } finally {
252
+ _iterator6.f();
253
+ }
254
+ }
255
+ } catch (err) {
256
+ _iterator4.e(err);
257
+ } finally {
258
+ _iterator4.f();
259
+ }
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
+ return map;
273
+ }
274
+
275
+ /**
276
+ * 指定商品在某一 datetime 的智能定价(addon / 单点重算用)。
277
+ */
278
+ export function getPriceForProductAtDatetime(params) {
279
+ var _ref6, _extractProductPrice;
280
+ var products = params.products,
281
+ context = params.context,
282
+ productId = params.productId,
283
+ datetime = params.datetime,
284
+ fallbackPrice = params.fallbackPrice;
285
+ var resolved = formatProductsWithDataVariant(products, context, datetime);
286
+ var product = resolved.find(function (item) {
287
+ return Number(item.id) === Number(productId);
288
+ });
289
+ return (_ref6 = (_extractProductPrice = extractProductPrice(product || {})) !== null && _extractProductPrice !== void 0 ? _extractProductPrice : fallbackPrice) !== null && _ref6 !== void 0 ? _ref6 : '0.00';
290
+ }
291
+
292
+ /** 从 slot 价格 Map 读取单价,找不到则回退 fallback */
293
+ export function getSlotPriceFromMap(params) {
294
+ var slotPriceMap = params.slotPriceMap,
295
+ productId = params.productId,
296
+ slotStartTime = params.slotStartTime,
297
+ fallbackPrice = params.fallbackPrice;
298
+ var key = "".concat(productId, ":").concat(slotStartTime);
299
+ var mapped = slotPriceMap.get(key);
300
+ if (mapped != null) return mapped;
301
+ return fallbackPrice !== null && fallbackPrice !== void 0 ? fallbackPrice : '0.00';
302
+ }
@@ -27,6 +27,8 @@ export declare function buildTimeSlotGrid(params: {
27
27
  config: VenueBookingSlotConfig;
28
28
  rawResources: VenueResourceRawData[];
29
29
  resourceProductMap: Map<number | string, ResourceProductMapping[]>;
30
+ /** @deprecated 使用 slotPriceMap */
30
31
  quotationPriceMap?: Map<string, string | null>;
32
+ slotPriceMap?: Map<string, string | null>;
31
33
  }): VenueTimeSlotGrid;
32
34
  export {};
@@ -230,6 +230,7 @@ function buildProductSlots(params) {
230
230
  now = params.now,
231
231
  crossDay = params.crossDay,
232
232
  quotationPriceMap = params.quotationPriceMap,
233
+ slotPriceMap = params.slotPriceMap,
233
234
  childRawResources = params.childRawResources,
234
235
  childTimesCache = params.childTimesCache,
235
236
  childEventsCache = params.childEventsCache,
@@ -239,7 +240,7 @@ function buildProductSlots(params) {
239
240
  _step7;
240
241
  try {
241
242
  for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
242
- var _quotationPriceMap$ge;
243
+ var _resolvedPriceMap$get;
243
244
  var label = _step7.value;
244
245
  var _label$split$map = label.split(':').map(Number),
245
246
  _label$split$map2 = _slicedToArray(_label$split$map, 1),
@@ -298,11 +299,12 @@ function buildProductSlots(params) {
298
299
  }
299
300
  var isBookable = status === 'available' || status === 'partially_occupied';
300
301
  var slotStartStr = slotStart.format('YYYY-MM-DD HH:mm');
302
+ var resolvedPriceMap = slotPriceMap !== null && slotPriceMap !== void 0 ? slotPriceMap : quotationPriceMap;
301
303
  slots.push({
302
304
  startTime: slotStartStr,
303
305
  endTime: slotEnd.format('YYYY-MM-DD HH:mm'),
304
306
  status: status,
305
- price: isBookable ? (_quotationPriceMap$ge = quotationPriceMap === null || quotationPriceMap === void 0 ? void 0 : quotationPriceMap.get("".concat(mapping.productId, ":").concat(slotStartStr))) !== null && _quotationPriceMap$ge !== void 0 ? _quotationPriceMap$ge : mapping.price : null,
307
+ price: isBookable ? (_resolvedPriceMap$get = resolvedPriceMap === null || resolvedPriceMap === void 0 ? void 0 : resolvedPriceMap.get("".concat(mapping.productId, ":").concat(slotStartStr))) !== null && _resolvedPriceMap$get !== void 0 ? _resolvedPriceMap$get : mapping.price : null,
306
308
  resourceId: resource.resourceId,
307
309
  resourceFormId: resource.formId,
308
310
  capacity: status === 'past' || status === 'unavailable' ? null : resCapacity,
@@ -322,7 +324,9 @@ export function buildTimeSlotGrid(params) {
322
324
  config = params.config,
323
325
  rawResources = params.rawResources,
324
326
  resourceProductMap = params.resourceProductMap,
325
- quotationPriceMap = params.quotationPriceMap;
327
+ quotationPriceMap = params.quotationPriceMap,
328
+ slotPriceMap = params.slotPriceMap;
329
+ var resolvedPriceMap = slotPriceMap !== null && slotPriceMap !== void 0 ? slotPriceMap : quotationPriceMap;
326
330
  var timeLabels = generateTimeLabels(config);
327
331
  var now = dayjs();
328
332
  var crossDay = isBusinessHoursCrossDay(config);
@@ -377,7 +381,8 @@ export function buildTimeSlotGrid(params) {
377
381
  resCapacity: resCapacity,
378
382
  now: now,
379
383
  crossDay: crossDay,
380
- quotationPriceMap: quotationPriceMap,
384
+ quotationPriceMap: resolvedPriceMap,
385
+ slotPriceMap: resolvedPriceMap,
381
386
  childRawResources: childRawResources,
382
387
  childTimesCache: childTimesCache,
383
388
  childEventsCache: childEventsCache,
package/lib/index.d.ts CHANGED
@@ -7,5 +7,6 @@ export * from './modules';
7
7
  export * from './plugins';
8
8
  export * from './solution';
9
9
  export { PisellOSCore } from './core';
10
+ export { DataVariantEvaluator } from './model/strategy/adapter/dataVariant/evaluator';
10
11
  import PisellOSCore from './core';
11
12
  export default PisellOSCore;
package/lib/index.js CHANGED
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
+ DataVariantEvaluator: () => import_evaluator.DataVariantEvaluator,
33
34
  PisellOSCore: () => import_core.PisellOSCore,
34
35
  default: () => src_default
35
36
  });
@@ -39,10 +40,12 @@ __reExport(src_exports, require("./modules"), module.exports);
39
40
  __reExport(src_exports, require("./plugins"), module.exports);
40
41
  __reExport(src_exports, require("./solution"), module.exports);
41
42
  var import_core = require("./core");
43
+ var import_evaluator = require("./model/strategy/adapter/dataVariant/evaluator");
42
44
  var import_core2 = __toESM(require("./core"));
43
45
  var src_default = import_core2.default;
44
46
  // Annotate the CommonJS export names for ESM import in node:
45
47
  0 && (module.exports = {
48
+ DataVariantEvaluator,
46
49
  PisellOSCore,
47
50
  ...require("./types"),
48
51
  ...require("./modules"),