@pisell/pisellos 2.1.165 → 2.1.166

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 (78) 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 +780 -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 +148 -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/model/strategy/adapter/promotion/index.js +0 -9
  16. package/dist/modules/Discount/index.d.ts +5 -2
  17. package/dist/modules/Discount/index.js +21 -1
  18. package/dist/modules/Discount/types.d.ts +4 -0
  19. package/dist/modules/Order/index.d.ts +1 -0
  20. package/dist/modules/Order/index.js +18 -6
  21. package/dist/modules/Order/types.d.ts +2 -0
  22. package/dist/modules/ProductList/index.d.ts +3 -1
  23. package/dist/modules/ProductList/index.js +22 -11
  24. package/dist/modules/Schedule/getDateIsInSchedule.js +5 -0
  25. package/dist/solution/BookingByStep/index.d.ts +2 -2
  26. package/dist/solution/ScanOrder/index.js +1 -1
  27. package/dist/solution/ShopDiscount/index.js +16 -15
  28. package/dist/solution/VenueBooking/index.d.ts +40 -3
  29. package/dist/solution/VenueBooking/index.js +394 -261
  30. package/dist/solution/VenueBooking/types.d.ts +3 -1
  31. package/dist/solution/VenueBooking/types.js +1 -0
  32. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  33. package/dist/solution/VenueBooking/utils/dateSummary.js +12 -25
  34. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -6
  35. package/dist/solution/VenueBooking/utils/slotMerge.js +3 -9
  36. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +70 -0
  37. package/dist/solution/VenueBooking/utils/smartPricing.js +233 -0
  38. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +2 -0
  39. package/dist/solution/VenueBooking/utils/timeSlot.js +9 -4
  40. package/lib/index.d.ts +1 -0
  41. package/lib/index.js +3 -0
  42. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
  43. package/lib/model/strategy/adapter/dataVariant/adapter.js +149 -0
  44. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
  45. package/lib/model/strategy/adapter/dataVariant/evaluator.js +583 -0
  46. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  47. package/lib/model/strategy/adapter/dataVariant/examples.js +293 -0
  48. package/lib/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  49. package/lib/model/strategy/adapter/dataVariant/index.js +38 -0
  50. package/lib/model/strategy/adapter/dataVariant/type.d.ts +148 -0
  51. package/lib/model/strategy/adapter/dataVariant/type.js +31 -0
  52. package/lib/model/strategy/adapter/index.d.ts +4 -0
  53. package/lib/model/strategy/adapter/index.js +13 -2
  54. package/lib/modules/Discount/index.d.ts +5 -2
  55. package/lib/modules/Discount/index.js +11 -1
  56. package/lib/modules/Discount/types.d.ts +4 -0
  57. package/lib/modules/Order/index.d.ts +1 -0
  58. package/lib/modules/Order/index.js +11 -1
  59. package/lib/modules/Order/types.d.ts +2 -0
  60. package/lib/modules/ProductList/index.d.ts +3 -1
  61. package/lib/modules/ProductList/index.js +45 -39
  62. package/lib/modules/Schedule/getDateIsInSchedule.js +4 -0
  63. package/lib/solution/BookingByStep/index.d.ts +2 -2
  64. package/lib/solution/ScanOrder/index.js +1 -1
  65. package/lib/solution/ShopDiscount/index.js +3 -2
  66. package/lib/solution/VenueBooking/index.d.ts +40 -3
  67. package/lib/solution/VenueBooking/index.js +257 -111
  68. package/lib/solution/VenueBooking/types.d.ts +3 -1
  69. package/lib/solution/VenueBooking/types.js +1 -0
  70. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  71. package/lib/solution/VenueBooking/utils/dateSummary.js +5 -10
  72. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -6
  73. package/lib/solution/VenueBooking/utils/slotMerge.js +3 -4
  74. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +70 -0
  75. package/lib/solution/VenueBooking/utils/smartPricing.js +180 -0
  76. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +2 -0
  77. package/lib/solution/VenueBooking/utils/timeSlot.js +7 -3
  78. package/package.json +1 -1
@@ -0,0 +1,70 @@
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
+ }
20
+ /** 从商品上读取展示/算价用的 price 字段 */
21
+ export declare function extractProductPrice(product: DataVariantProduct): string | null;
22
+ /** 组装 DataVariant 评估入参,对齐 OS Server buildProductFormatterContext 语义 */
23
+ export declare function buildDataVariantBusinessData(products: ProductData[], context: VenueBookingSmartPricingContext, scheduleDateTime: string): DataVariantBusinessData;
24
+ /**
25
+ * 对商品列表执行一次智能定价格式化(loadProducts 后使用)。
26
+ * evaluator 未注入时原样返回并打 warning。
27
+ */
28
+ export declare function formatProductsWithDataVariant(products: ProductData[], context: VenueBookingSmartPricingContext, scheduleDateTime?: string): ProductData[];
29
+ /**
30
+ * 根据 schedule_time_points 与营业开始时间,构造当天需要评估的 datetime 列表(升序)。
31
+ * 跨日营业时,早于营业开始小时的时间点归到次日。
32
+ */
33
+ export declare function buildEvaluationDatetimes(params: {
34
+ date: string;
35
+ config: VenueBookingSlotConfig;
36
+ scheduleTimePoints: string[];
37
+ }): string[];
38
+ /** 找到 slot 时间所属分段的评估 datetime(max(evalDt <= slotDt)) */
39
+ export declare function findSegmentEvalDatetime(slotDatetime: string, evalDatetimes: string[]): string;
40
+ /** 将 slot 标签转为与 timeSlot 网格一致的 slotStart 字符串 */
41
+ export declare function buildSlotStartDatetime(date: string, label: string, config: VenueBookingSlotConfig): string;
42
+ /**
43
+ * 按 schedule 分段批量 resolveProducts,输出与 quotation 相同 key 格式的 slot 价格 Map。
44
+ * key: `${productId}:${slotStart}`,value: price | null
45
+ */
46
+ export declare function buildSlotPriceMapByScheduleSegments(params: {
47
+ products: ProductData[];
48
+ productIds: number[];
49
+ date: string;
50
+ timeLabels: string[];
51
+ config: VenueBookingSlotConfig;
52
+ context: VenueBookingSmartPricingContext;
53
+ }): Map<string, string | null>;
54
+ /**
55
+ * 指定商品在某一 datetime 的智能定价(addon / 单点重算用)。
56
+ */
57
+ export declare function getPriceForProductAtDatetime(params: {
58
+ products: ProductData[];
59
+ context: VenueBookingSmartPricingContext;
60
+ productId: number;
61
+ datetime: string;
62
+ fallbackPrice?: string;
63
+ }): string;
64
+ /** 从 slot 价格 Map 读取单价,找不到则回退 fallback */
65
+ export declare function getSlotPriceFromMap(params: {
66
+ slotPriceMap: Map<string, string | null>;
67
+ productId: number;
68
+ slotStartTime: string;
69
+ fallbackPrice?: string;
70
+ }): string;
@@ -0,0 +1,180 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/solution/VenueBooking/utils/smartPricing.ts
30
+ var smartPricing_exports = {};
31
+ __export(smartPricing_exports, {
32
+ buildDataVariantBusinessData: () => buildDataVariantBusinessData,
33
+ buildEvaluationDatetimes: () => buildEvaluationDatetimes,
34
+ buildSlotPriceMapByScheduleSegments: () => buildSlotPriceMapByScheduleSegments,
35
+ buildSlotStartDatetime: () => buildSlotStartDatetime,
36
+ extractProductPrice: () => extractProductPrice,
37
+ findSegmentEvalDatetime: () => findSegmentEvalDatetime,
38
+ formatProductsWithDataVariant: () => formatProductsWithDataVariant,
39
+ getPriceForProductAtDatetime: () => getPriceForProductAtDatetime,
40
+ getSlotPriceFromMap: () => getSlotPriceFromMap
41
+ });
42
+ module.exports = __toCommonJS(smartPricing_exports);
43
+ var import_dayjs = __toESM(require("dayjs"));
44
+ var import_timeSlot = require("./timeSlot");
45
+ function extractProductPrice(product) {
46
+ const price = (product == null ? void 0 : product.price) ?? (product == null ? void 0 : product.selling_price);
47
+ if (price == null || price === "")
48
+ return null;
49
+ return String(price);
50
+ }
51
+ function buildDataVariantBusinessData(products, context, scheduleDateTime) {
52
+ const strategyContext = context.strategy_context || {};
53
+ return {
54
+ products,
55
+ strategyConfigs: context.strategyConfigs,
56
+ scheduleDateTime,
57
+ scheduleList: context.scheduleList || [],
58
+ menuList: context.menuList || [],
59
+ customerId: context.customerId,
60
+ availableWalletIds: context.availableWalletIds ?? strategyContext.available_wallet_ids ?? strategyContext.availableWalletIds,
61
+ channel: context.channel ?? strategyContext.channel,
62
+ orderType: context.orderType ?? strategyContext.orderType ?? strategyContext.order_type,
63
+ businessCode: context.businessCode ?? strategyContext.business_code ?? strategyContext.businessCode,
64
+ custom: strategyContext
65
+ };
66
+ }
67
+ function formatProductsWithDataVariant(products, context, scheduleDateTime) {
68
+ const evaluator = context.evaluator;
69
+ if (!evaluator || typeof evaluator.resolveProducts !== "function") {
70
+ console.warn("[VenueBooking][smartPricing] dataVariantEvaluator 未注入,跳过智能定价格式化");
71
+ return products;
72
+ }
73
+ const resolvedAt = scheduleDateTime || (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
74
+ const businessData = buildDataVariantBusinessData(products, context, resolvedAt);
75
+ const result = evaluator.resolveProducts(businessData);
76
+ return Array.isArray(result == null ? void 0 : result.products) ? result.products : products;
77
+ }
78
+ function buildEvaluationDatetimes(params) {
79
+ const { date, config, scheduleTimePoints } = params;
80
+ const crossDay = (0, import_timeSlot.isBusinessHoursCrossDay)(config);
81
+ const businessStartHour = Number(config.businessStartTime.split(":")[0]);
82
+ const evalSet = /* @__PURE__ */ new Set();
83
+ evalSet.add(`${date} ${config.businessStartTime}`);
84
+ for (const timePoint of scheduleTimePoints) {
85
+ const hour = Number(timePoint.split(":")[0]);
86
+ const pointDate = crossDay && hour < businessStartHour ? (0, import_dayjs.default)(date).add(1, "day").format("YYYY-MM-DD") : date;
87
+ evalSet.add(`${pointDate} ${timePoint}`);
88
+ }
89
+ return Array.from(evalSet).sort((a, b) => {
90
+ const aMs = (0, import_dayjs.default)(a, ["YYYY-MM-DD HH:mm:ss", "YYYY-MM-DD HH:mm"]).valueOf();
91
+ const bMs = (0, import_dayjs.default)(b, ["YYYY-MM-DD HH:mm:ss", "YYYY-MM-DD HH:mm"]).valueOf();
92
+ return aMs - bMs;
93
+ });
94
+ }
95
+ function findSegmentEvalDatetime(slotDatetime, evalDatetimes) {
96
+ if (!evalDatetimes.length)
97
+ return slotDatetime;
98
+ const slotMs = (0, import_dayjs.default)(slotDatetime, ["YYYY-MM-DD HH:mm:ss", "YYYY-MM-DD HH:mm"]).valueOf();
99
+ let chosen = evalDatetimes[0];
100
+ for (const evalDt of evalDatetimes) {
101
+ const evalMs = (0, import_dayjs.default)(evalDt, ["YYYY-MM-DD HH:mm:ss", "YYYY-MM-DD HH:mm"]).valueOf();
102
+ if (evalMs <= slotMs) {
103
+ chosen = evalDt;
104
+ } else {
105
+ break;
106
+ }
107
+ }
108
+ return chosen;
109
+ }
110
+ function buildSlotStartDatetime(date, label, config) {
111
+ const crossDay = (0, import_timeSlot.isBusinessHoursCrossDay)(config);
112
+ const businessStartHour = Number(config.businessStartTime.split(":")[0]);
113
+ const hour = Number(label.split(":")[0]);
114
+ const slotDate = crossDay && hour < businessStartHour ? (0, import_dayjs.default)(date).add(1, "day").format("YYYY-MM-DD") : date;
115
+ return (0, import_dayjs.default)(`${slotDate} ${label}`).format("YYYY-MM-DD HH:mm");
116
+ }
117
+ function buildSlotPriceMapByScheduleSegments(params) {
118
+ const { products, productIds, date, timeLabels, config, context } = params;
119
+ const map = /* @__PURE__ */ new Map();
120
+ if (!productIds.length || !timeLabels.length)
121
+ return map;
122
+ const evaluator = context.evaluator;
123
+ if (!evaluator || typeof evaluator.resolveProducts !== "function") {
124
+ return map;
125
+ }
126
+ const strategyConfigs = context.strategyConfigs || (typeof evaluator.getStrategyConfigs === "function" ? evaluator.getStrategyConfigs() : []);
127
+ const scheduleTimePoints = typeof evaluator.buildScheduleTimePoints === "function" ? evaluator.buildScheduleTimePoints(strategyConfigs, context.scheduleList || []) : [];
128
+ const evalDatetimes = buildEvaluationDatetimes({ date, config, scheduleTimePoints });
129
+ const priceCache = /* @__PURE__ */ new Map();
130
+ for (const evalDt of evalDatetimes) {
131
+ const resolved = formatProductsWithDataVariant(products, context, evalDt);
132
+ const priceByProductId = /* @__PURE__ */ new Map();
133
+ for (const product of resolved) {
134
+ const productId = Number(product.id);
135
+ if (!Number.isFinite(productId))
136
+ continue;
137
+ priceByProductId.set(productId, extractProductPrice(product));
138
+ }
139
+ priceCache.set(evalDt, priceByProductId);
140
+ }
141
+ for (const label of timeLabels) {
142
+ const slotStart = buildSlotStartDatetime(date, label, config);
143
+ const segmentEvalDt = findSegmentEvalDatetime(slotStart, evalDatetimes);
144
+ const priceByProductId = priceCache.get(segmentEvalDt);
145
+ for (const productId of productIds) {
146
+ const key = `${productId}:${slotStart}`;
147
+ const price = (priceByProductId == null ? void 0 : priceByProductId.get(productId)) ?? null;
148
+ if (price !== null) {
149
+ map.set(key, price);
150
+ }
151
+ }
152
+ }
153
+ return map;
154
+ }
155
+ function getPriceForProductAtDatetime(params) {
156
+ const { products, context, productId, datetime, fallbackPrice } = params;
157
+ const resolved = formatProductsWithDataVariant(products, context, datetime);
158
+ const product = resolved.find((item) => Number(item.id) === Number(productId));
159
+ return extractProductPrice(product || {}) ?? fallbackPrice ?? "0.00";
160
+ }
161
+ function getSlotPriceFromMap(params) {
162
+ const { slotPriceMap, productId, slotStartTime, fallbackPrice } = params;
163
+ const key = `${productId}:${slotStartTime}`;
164
+ const mapped = slotPriceMap.get(key);
165
+ if (mapped != null)
166
+ return mapped;
167
+ return fallbackPrice ?? "0.00";
168
+ }
169
+ // Annotate the CommonJS export names for ESM import in node:
170
+ 0 && (module.exports = {
171
+ buildDataVariantBusinessData,
172
+ buildEvaluationDatetimes,
173
+ buildSlotPriceMapByScheduleSegments,
174
+ buildSlotStartDatetime,
175
+ extractProductPrice,
176
+ findSegmentEvalDatetime,
177
+ formatProductsWithDataVariant,
178
+ getPriceForProductAtDatetime,
179
+ getSlotPriceFromMap
180
+ });
@@ -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 {};
@@ -168,6 +168,7 @@ function buildProductSlots(params) {
168
168
  now,
169
169
  crossDay,
170
170
  quotationPriceMap,
171
+ slotPriceMap,
171
172
  childRawResources,
172
173
  childTimesCache,
173
174
  childEventsCache,
@@ -231,11 +232,12 @@ function buildProductSlots(params) {
231
232
  }
232
233
  const isBookable = status === "available" || status === "partially_occupied";
233
234
  const slotStartStr = slotStart.format("YYYY-MM-DD HH:mm");
235
+ const resolvedPriceMap = slotPriceMap ?? quotationPriceMap;
234
236
  slots.push({
235
237
  startTime: slotStartStr,
236
238
  endTime: slotEnd.format("YYYY-MM-DD HH:mm"),
237
239
  status,
238
- price: isBookable ? (quotationPriceMap == null ? void 0 : quotationPriceMap.get(`${mapping.productId}:${slotStartStr}`)) ?? mapping.price : null,
240
+ price: isBookable ? (resolvedPriceMap == null ? void 0 : resolvedPriceMap.get(`${mapping.productId}:${slotStartStr}`)) ?? mapping.price : null,
239
241
  resourceId: resource.resourceId,
240
242
  resourceFormId: resource.formId,
241
243
  capacity: status === "past" || status === "unavailable" ? null : resCapacity,
@@ -246,7 +248,8 @@ function buildProductSlots(params) {
246
248
  return slots;
247
249
  }
248
250
  function buildTimeSlotGrid(params) {
249
- const { date, config, rawResources, resourceProductMap, quotationPriceMap } = params;
251
+ const { date, config, rawResources, resourceProductMap, quotationPriceMap, slotPriceMap } = params;
252
+ const resolvedPriceMap = slotPriceMap ?? quotationPriceMap;
250
253
  const timeLabels = generateTimeLabels(config);
251
254
  const now = (0, import_dayjs.default)();
252
255
  const crossDay = isBusinessHoursCrossDay(config);
@@ -279,7 +282,8 @@ function buildTimeSlotGrid(params) {
279
282
  resCapacity,
280
283
  now,
281
284
  crossDay,
282
- quotationPriceMap,
285
+ quotationPriceMap: resolvedPriceMap,
286
+ slotPriceMap: resolvedPriceMap,
283
287
  childRawResources,
284
288
  childTimesCache,
285
289
  childEventsCache,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.165",
4
+ "version": "2.1.166",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",