@pisell/pisellos 0.0.556 → 0.0.558

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 (68) 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 +49 -0
  4. package/dist/model/strategy/adapter/dataVariant/adapter.js +152 -0
  5. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +87 -0
  6. package/dist/model/strategy/adapter/dataVariant/evaluator.js +755 -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 +146 -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/Order/index.d.ts +1 -1
  16. package/dist/modules/Product/index.d.ts +1 -1
  17. package/dist/modules/ProductList/index.d.ts +2 -1
  18. package/dist/modules/ProductList/index.js +21 -11
  19. package/dist/solution/BookingByStep/index.d.ts +2 -2
  20. package/dist/solution/ScanOrder/index.d.ts +2 -1
  21. package/dist/solution/ScanOrder/index.js +137 -117
  22. package/dist/solution/ScanOrder/utils.d.ts +5 -0
  23. package/dist/solution/ScanOrder/utils.js +55 -23
  24. package/dist/solution/VenueBooking/index.d.ts +22 -3
  25. package/dist/solution/VenueBooking/index.js +259 -166
  26. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  27. package/dist/solution/VenueBooking/utils/dateSummary.js +12 -25
  28. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -6
  29. package/dist/solution/VenueBooking/utils/slotMerge.js +3 -9
  30. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +69 -0
  31. package/dist/solution/VenueBooking/utils/smartPricing.js +233 -0
  32. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +2 -0
  33. package/dist/solution/VenueBooking/utils/timeSlot.js +9 -4
  34. package/lib/index.d.ts +1 -0
  35. package/lib/index.js +3 -0
  36. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +49 -0
  37. package/lib/model/strategy/adapter/dataVariant/adapter.js +139 -0
  38. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +87 -0
  39. package/lib/model/strategy/adapter/dataVariant/evaluator.js +564 -0
  40. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  41. package/lib/model/strategy/adapter/dataVariant/examples.js +293 -0
  42. package/lib/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  43. package/lib/model/strategy/adapter/dataVariant/index.js +38 -0
  44. package/lib/model/strategy/adapter/dataVariant/type.d.ts +146 -0
  45. package/lib/model/strategy/adapter/dataVariant/type.js +31 -0
  46. package/lib/model/strategy/adapter/index.d.ts +4 -0
  47. package/lib/model/strategy/adapter/index.js +13 -2
  48. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  49. package/lib/modules/Order/index.d.ts +1 -1
  50. package/lib/modules/Product/index.d.ts +1 -1
  51. package/lib/modules/ProductList/index.d.ts +2 -1
  52. package/lib/modules/ProductList/index.js +45 -40
  53. package/lib/solution/BookingByStep/index.d.ts +2 -2
  54. package/lib/solution/ScanOrder/index.d.ts +2 -1
  55. package/lib/solution/ScanOrder/index.js +29 -18
  56. package/lib/solution/ScanOrder/utils.d.ts +5 -0
  57. package/lib/solution/ScanOrder/utils.js +23 -0
  58. package/lib/solution/VenueBooking/index.d.ts +22 -3
  59. package/lib/solution/VenueBooking/index.js +151 -63
  60. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  61. package/lib/solution/VenueBooking/utils/dateSummary.js +5 -10
  62. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -6
  63. package/lib/solution/VenueBooking/utils/slotMerge.js +3 -4
  64. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +69 -0
  65. package/lib/solution/VenueBooking/utils/smartPricing.js +180 -0
  66. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +2 -0
  67. package/lib/solution/VenueBooking/utils/timeSlot.js +7 -3
  68. package/package.json +1 -1
@@ -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
+ channel: context.channel ?? strategyContext.channel,
61
+ orderType: context.orderType ?? strategyContext.orderType ?? strategyContext.order_type,
62
+ businessCode: context.businessCode ?? strategyContext.business_code ?? strategyContext.businessCode,
63
+ custom: strategyContext
64
+ };
65
+ }
66
+ function formatProductsWithDataVariant(products, context, scheduleDateTime) {
67
+ const evaluator = context.evaluator;
68
+ if (!evaluator || typeof evaluator.resolveProducts !== "function") {
69
+ console.warn("[VenueBooking][smartPricing] dataVariantEvaluator 未注入,跳过智能定价格式化");
70
+ return products;
71
+ }
72
+ const resolvedAt = scheduleDateTime || (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
73
+ const businessData = buildDataVariantBusinessData(products, context, resolvedAt);
74
+ console.log(businessData, "businessData");
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": "0.0.556",
4
+ "version": "0.0.558",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",