@pisell/pisellos 2.3.132 → 2.3.134

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 (27) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/Order/index.d.ts +1 -1
  3. package/dist/solution/BookingByStep/index.d.ts +1 -1
  4. package/dist/solution/VenueBooking/index.d.ts +15 -2
  5. package/dist/solution/VenueBooking/index.js +1036 -760
  6. package/dist/solution/VenueBooking/types.d.ts +2 -1
  7. package/dist/solution/VenueBooking/types.js +1 -0
  8. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  9. package/dist/solution/VenueBooking/utils/dateSummary.js +7 -4
  10. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +71 -0
  11. package/dist/solution/VenueBooking/utils/smartPricing.js +273 -0
  12. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +1 -0
  13. package/dist/solution/VenueBooking/utils/timeSlot.js +6 -3
  14. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  15. package/lib/modules/Order/index.d.ts +1 -1
  16. package/lib/solution/BookingByStep/index.d.ts +1 -1
  17. package/lib/solution/VenueBooking/index.d.ts +15 -2
  18. package/lib/solution/VenueBooking/index.js +234 -88
  19. package/lib/solution/VenueBooking/types.d.ts +2 -1
  20. package/lib/solution/VenueBooking/types.js +1 -0
  21. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  22. package/lib/solution/VenueBooking/utils/dateSummary.js +7 -4
  23. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +71 -0
  24. package/lib/solution/VenueBooking/utils/smartPricing.js +224 -0
  25. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +1 -0
  26. package/lib/solution/VenueBooking/utils/timeSlot.js +5 -2
  27. package/package.json +1 -1
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.buildDataVariantBusinessData = buildDataVariantBusinessData;
7
+ exports.buildEvaluationDatetimes = buildEvaluationDatetimes;
8
+ exports.buildSlotPriceMapByScheduleSegments = buildSlotPriceMapByScheduleSegments;
9
+ exports.buildSlotStartDatetime = buildSlotStartDatetime;
10
+ exports.extractProductPrice = extractProductPrice;
11
+ exports.findSegmentEvalDatetime = findSegmentEvalDatetime;
12
+ exports.formatProductsWithDataVariant = formatProductsWithDataVariant;
13
+ exports.getPriceForProductAtDatetime = getPriceForProductAtDatetime;
14
+ exports.getSlotPriceFromMap = getSlotPriceFromMap;
15
+ var _dayjs = _interopRequireDefault(require("dayjs"));
16
+ var _timeSlot = require("./timeSlot");
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ /** VenueBooking 智能定价运行时上下文 */
19
+
20
+ /** 从商品上读取展示/算价用的 price 字段 */
21
+ function extractProductPrice(product) {
22
+ const price = product?.price ?? product?.selling_price;
23
+ if (price == null || price === '') return null;
24
+ return String(price);
25
+ }
26
+
27
+ /** 组装 DataVariant 评估入参,对齐 OS Server buildProductFormatterContext 语义 */
28
+ function buildDataVariantBusinessData(products, context, scheduleDateTime) {
29
+ const strategyContext = context.strategy_context || {};
30
+ return {
31
+ products: products,
32
+ strategyConfigs: context.strategyConfigs,
33
+ scheduleDateTime,
34
+ scheduleList: context.scheduleList || [],
35
+ menuList: context.menuList || [],
36
+ customerId: context.customerId,
37
+ availableWalletIds: context.availableWalletIds ?? strategyContext.available_wallet_ids ?? strategyContext.availableWalletIds,
38
+ channel: context.channel ?? strategyContext.channel,
39
+ orderType: context.orderType ?? strategyContext.orderType ?? strategyContext.order_type,
40
+ businessCode: context.businessCode ?? strategyContext.business_code ?? strategyContext.businessCode,
41
+ custom: strategyContext
42
+ };
43
+ }
44
+
45
+ /**
46
+ * 对商品列表执行一次智能定价格式化(loadProducts 后使用)。
47
+ * evaluator 未注入时原样返回并打 warning。
48
+ */
49
+ function formatProductsWithDataVariant(products, context, scheduleDateTime) {
50
+ const evaluator = context.evaluator;
51
+ if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
52
+ console.warn('[VenueBooking][smartPricing] dataVariantEvaluator 未注入,跳过智能定价格式化');
53
+ return products;
54
+ }
55
+
56
+ // 日程包含结束边界,向后偏移一秒评估,避免前一时段的定价规则覆盖当前时段。
57
+ // 仅调整规则匹配时间,预约时间和分段缓存 key 仍保留原值。
58
+ const resolvedAt = (0, _dayjs.default)(scheduleDateTime || undefined).add(1, 'second').format('YYYY-MM-DD HH:mm:ss');
59
+ // 接口的命中 ID 对应商品查询时刻,不能用于另一个预约时段/客户。
60
+ // 仅处理本次评估副本,保留目录中的原始数据。
61
+ const pricingProducts = products.map(product => {
62
+ const metadata = {
63
+ ...product.metadata
64
+ };
65
+ const hasResolvedVariants = Array.isArray(metadata.data_variant_ids);
66
+ delete metadata.data_variant_ids;
67
+ return {
68
+ ...product,
69
+ price: hasResolvedVariants ? product.base_price ?? product.price : product.price,
70
+ metadata
71
+ };
72
+ });
73
+ const businessData = buildDataVariantBusinessData(pricingProducts, context, resolvedAt);
74
+ const result = evaluator.resolveProducts(businessData);
75
+ return Array.isArray(result?.products) ? result.products : products;
76
+ }
77
+
78
+ /**
79
+ * 根据 schedule_time_points 与营业开始时间,构造当天需要评估的 datetime 列表(升序)。
80
+ * 跨日营业时,早于营业开始小时的时间点归到次日。
81
+ */
82
+ function buildEvaluationDatetimes(params) {
83
+ const {
84
+ date,
85
+ config,
86
+ scheduleTimePoints
87
+ } = params;
88
+ const crossDay = (0, _timeSlot.isBusinessHoursCrossDay)(config);
89
+ const businessStartHour = Number(config.businessStartTime.split(':')[0]);
90
+ const evalSet = new Set();
91
+ evalSet.add(`${date} ${config.businessStartTime}`);
92
+ if (crossDay) {
93
+ // 即使规则没有显式 00:00 时间点,日期/星期变化也可能切换适用规则。
94
+ evalSet.add(`${(0, _dayjs.default)(date).add(1, 'day').format('YYYY-MM-DD')} 00:00`);
95
+ }
96
+ for (const timePoint of scheduleTimePoints) {
97
+ const hour = Number(timePoint.split(':')[0]);
98
+ const pointDate = crossDay && hour < businessStartHour ? (0, _dayjs.default)(date).add(1, 'day').format('YYYY-MM-DD') : date;
99
+ evalSet.add(`${pointDate} ${timePoint}`);
100
+ }
101
+ return Array.from(evalSet).sort((a, b) => {
102
+ const aMs = (0, _dayjs.default)(a, ['YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD HH:mm']).valueOf();
103
+ const bMs = (0, _dayjs.default)(b, ['YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD HH:mm']).valueOf();
104
+ return aMs - bMs;
105
+ });
106
+ }
107
+
108
+ /** 找到 slot 时间所属分段的评估 datetime(max(evalDt <= slotDt)) */
109
+ function findSegmentEvalDatetime(slotDatetime, evalDatetimes) {
110
+ if (!evalDatetimes.length) return slotDatetime;
111
+ const slotMs = (0, _dayjs.default)(slotDatetime, ['YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD HH:mm']).valueOf();
112
+ let chosen = evalDatetimes[0];
113
+ for (const evalDt of evalDatetimes) {
114
+ const evalMs = (0, _dayjs.default)(evalDt, ['YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD HH:mm']).valueOf();
115
+ if (evalMs <= slotMs) {
116
+ chosen = evalDt;
117
+ } else {
118
+ break;
119
+ }
120
+ }
121
+ return chosen;
122
+ }
123
+
124
+ /** 将 slot 标签转为与 timeSlot 网格一致的 slotStart 字符串 */
125
+ function buildSlotStartDatetime(date, label, config) {
126
+ const crossDay = (0, _timeSlot.isBusinessHoursCrossDay)(config);
127
+ const businessStartHour = Number(config.businessStartTime.split(':')[0]);
128
+ const hour = Number(label.split(':')[0]);
129
+ const slotDate = crossDay && hour < businessStartHour ? (0, _dayjs.default)(date).add(1, 'day').format('YYYY-MM-DD') : date;
130
+ return (0, _dayjs.default)(`${slotDate} ${label}`).format('YYYY-MM-DD HH:mm');
131
+ }
132
+
133
+ /**
134
+ * 按 schedule 分段批量 resolveProducts,输出与 quotation 相同 key 格式的 slot 价格 Map。
135
+ * key: `${productId}:${slotStart}`,value: price | null
136
+ */
137
+ function buildSlotPriceMapByScheduleSegments(params) {
138
+ const {
139
+ products,
140
+ productIds,
141
+ date,
142
+ timeLabels,
143
+ config,
144
+ context
145
+ } = params;
146
+ const map = new Map();
147
+ if (!productIds.length || !timeLabels.length) return map;
148
+ const evaluator = context.evaluator;
149
+ if (!evaluator || typeof evaluator.resolveProducts !== 'function') return map;
150
+ const strategyConfigs = context.strategyConfigs || (typeof evaluator.getStrategyConfigs === 'function' ? evaluator.getStrategyConfigs() : []);
151
+ const scheduleTimePoints = typeof evaluator.buildScheduleTimePoints === 'function' ? evaluator.buildScheduleTimePoints(strategyConfigs, context.scheduleList || []) : [];
152
+ const evalDatetimes = buildEvaluationDatetimes({
153
+ date,
154
+ config,
155
+ scheduleTimePoints
156
+ });
157
+ const priceCache = new Map();
158
+ for (const evalDt of evalDatetimes) {
159
+ const resolved = formatProductsWithDataVariant(products, context, evalDt);
160
+ const priceByProductId = new Map();
161
+ for (const product of resolved) {
162
+ const productId = Number(product.id);
163
+ if (!Number.isFinite(productId)) continue;
164
+ priceByProductId.set(productId, extractProductPrice(product));
165
+ }
166
+ priceCache.set(evalDt, priceByProductId);
167
+ }
168
+ for (const label of timeLabels) {
169
+ const slotStart = buildSlotStartDatetime(date, label, config);
170
+ const segmentEvalDt = findSegmentEvalDatetime(slotStart, evalDatetimes);
171
+ const priceByProductId = priceCache.get(segmentEvalDt);
172
+ for (const productId of productIds) {
173
+ const key = `${productId}:${slotStart}`;
174
+ const price = priceByProductId?.get(productId) ?? null;
175
+ if (price !== null) {
176
+ map.set(key, price);
177
+ }
178
+ }
179
+ }
180
+ return map;
181
+ }
182
+
183
+ /**
184
+ * 指定商品在某一 datetime 的智能定价(addon / 单点重算用)。
185
+ */
186
+ function getPriceForProductAtDatetime(params) {
187
+ const {
188
+ products,
189
+ context,
190
+ productId,
191
+ variantId,
192
+ datetime,
193
+ fallbackPrice
194
+ } = params;
195
+ const selectedProducts = products.filter(product => Number(product.id) === Number(productId)).map(product => {
196
+ if (!variantId) return product;
197
+ const variant = product.variant?.find(item => Number(item.id) === Number(variantId));
198
+ if (!variant) return product;
199
+ return {
200
+ ...product,
201
+ product_variant_id: variantId,
202
+ variant_id: variantId,
203
+ price: variant.price ?? variant.base_price ?? product.price,
204
+ base_price: variant.base_price ?? variant.price ?? product.base_price
205
+ };
206
+ });
207
+ const resolved = formatProductsWithDataVariant(selectedProducts, context, datetime);
208
+ const product = resolved.find(item => Number(item.id) === Number(productId));
209
+ return extractProductPrice(product || {}) ?? fallbackPrice ?? '0.00';
210
+ }
211
+
212
+ /** 从 slot 价格 Map 读取单价,找不到则回退 fallback */
213
+ function getSlotPriceFromMap(params) {
214
+ const {
215
+ slotPriceMap,
216
+ productId,
217
+ slotStartTime,
218
+ fallbackPrice
219
+ } = params;
220
+ const key = `${productId}:${slotStartTime}`;
221
+ const mapped = slotPriceMap.get(key);
222
+ if (mapped != null) return mapped;
223
+ return fallbackPrice ?? '0.00';
224
+ }
@@ -28,5 +28,6 @@ export declare function buildTimeSlotGrid(params: {
28
28
  rawResources: VenueResourceRawData[];
29
29
  resourceProductMap: Map<number | string, ResourceProductMapping[]>;
30
30
  quotationPriceMap?: Map<string, string | null>;
31
+ slotPriceMap?: Map<string, string | null>;
31
32
  }): VenueTimeSlotGrid;
32
33
  export {};
@@ -166,6 +166,7 @@ function buildProductSlots(params) {
166
166
  now,
167
167
  crossDay,
168
168
  quotationPriceMap,
169
+ slotPriceMap,
169
170
  childRawResources,
170
171
  childTimesCache,
171
172
  childEventsCache,
@@ -230,7 +231,7 @@ function buildProductSlots(params) {
230
231
  startTime: slotStartStr,
231
232
  endTime: slotEnd.format('YYYY-MM-DD HH:mm'),
232
233
  status,
233
- price: isBookable ? quotationPriceMap?.get(`${mapping.productId}:${slotStartStr}`) ?? mapping.price : null,
234
+ price: isBookable ? (slotPriceMap ?? quotationPriceMap)?.get(`${mapping.productId}:${slotStartStr}`) ?? mapping.price : null,
234
235
  resourceId: resource.resourceId,
235
236
  resourceFormId: resource.formId,
236
237
  capacity: status === 'past' || status === 'unavailable' ? null : resCapacity,
@@ -246,7 +247,8 @@ function buildTimeSlotGrid(params) {
246
247
  config,
247
248
  rawResources,
248
249
  resourceProductMap,
249
- quotationPriceMap
250
+ quotationPriceMap,
251
+ slotPriceMap
250
252
  } = params;
251
253
  const timeLabels = generateTimeLabels(config);
252
254
  const now = (0, _dayjs.default)();
@@ -279,6 +281,7 @@ function buildTimeSlotGrid(params) {
279
281
  now,
280
282
  crossDay,
281
283
  quotationPriceMap,
284
+ slotPriceMap,
282
285
  childRawResources,
283
286
  childTimesCache,
284
287
  childEventsCache,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.132",
4
+ "version": "2.3.134",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",