@pisell/pisellos 2.1.166 → 2.1.168
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.
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -3
- package/dist/model/strategy/adapter/index.d.ts +0 -4
- package/dist/model/strategy/adapter/index.js +1 -5
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/Cart/utils/changePrice.js +16 -9
- package/dist/modules/Discount/index.d.ts +2 -5
- package/dist/modules/Discount/index.js +1 -21
- package/dist/modules/Discount/types.d.ts +0 -4
- package/dist/modules/Order/index.d.ts +0 -1
- package/dist/modules/Order/index.js +6 -18
- package/dist/modules/Order/types.d.ts +0 -2
- package/dist/modules/ProductList/index.d.ts +1 -3
- package/dist/modules/ProductList/index.js +11 -22
- package/dist/modules/Schedule/getDateIsInSchedule.js +0 -5
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/ScanOrder/index.js +1 -1
- package/dist/solution/ShopDiscount/index.js +15 -16
- package/dist/solution/VenueBooking/index.d.ts +3 -40
- package/dist/solution/VenueBooking/index.js +261 -394
- package/dist/solution/VenueBooking/types.d.ts +1 -3
- package/dist/solution/VenueBooking/types.js +0 -1
- package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
- package/dist/solution/VenueBooking/utils/dateSummary.js +25 -12
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +9 -3
- package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
- package/dist/solution/VenueBooking/utils/timeSlot.js +4 -9
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -3
- package/lib/model/strategy/adapter/index.d.ts +0 -4
- package/lib/model/strategy/adapter/index.js +2 -13
- package/lib/model/strategy/adapter/promotion/index.js +0 -49
- package/lib/modules/Cart/utils/changePrice.js +13 -9
- package/lib/modules/Discount/index.d.ts +2 -5
- package/lib/modules/Discount/index.js +1 -11
- package/lib/modules/Discount/types.d.ts +0 -4
- package/lib/modules/Order/index.d.ts +0 -1
- package/lib/modules/Order/index.js +1 -11
- package/lib/modules/Order/types.d.ts +0 -2
- package/lib/modules/ProductList/index.d.ts +1 -3
- package/lib/modules/ProductList/index.js +39 -45
- package/lib/modules/Schedule/getDateIsInSchedule.js +0 -4
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/ScanOrder/index.js +1 -1
- package/lib/solution/ShopDiscount/index.js +2 -3
- package/lib/solution/VenueBooking/index.d.ts +3 -40
- package/lib/solution/VenueBooking/index.js +111 -257
- package/lib/solution/VenueBooking/types.d.ts +1 -3
- package/lib/solution/VenueBooking/types.js +0 -1
- package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
- package/lib/solution/VenueBooking/utils/dateSummary.js +10 -5
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +4 -3
- package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
- package/lib/solution/VenueBooking/utils/timeSlot.js +3 -7
- package/package.json +1 -1
- package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
- package/dist/model/strategy/adapter/dataVariant/adapter.js +0 -167
- package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
- package/dist/model/strategy/adapter/dataVariant/evaluator.js +0 -780
- package/dist/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
- package/dist/model/strategy/adapter/dataVariant/examples.js +0 -277
- package/dist/model/strategy/adapter/dataVariant/index.d.ts +0 -4
- package/dist/model/strategy/adapter/dataVariant/index.js +0 -4
- package/dist/model/strategy/adapter/dataVariant/type.d.ts +0 -148
- package/dist/model/strategy/adapter/dataVariant/type.js +0 -54
- package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
- package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
- package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
- package/lib/model/strategy/adapter/dataVariant/adapter.js +0 -149
- package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +0 -583
- package/lib/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
- package/lib/model/strategy/adapter/dataVariant/examples.js +0 -293
- package/lib/model/strategy/adapter/dataVariant/index.d.ts +0 -4
- package/lib/model/strategy/adapter/dataVariant/index.js +0 -38
- package/lib/model/strategy/adapter/dataVariant/type.d.ts +0 -148
- package/lib/model/strategy/adapter/dataVariant/type.js +0 -31
- package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
- package/lib/solution/VenueBooking/utils/smartPricing.js +0 -180
|
@@ -1,233 +0,0 @@
|
|
|
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; } } }; }
|
|
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); }
|
|
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; }
|
|
4
|
-
import dayjs from 'dayjs';
|
|
5
|
-
import { isBusinessHoursCrossDay } from "./timeSlot";
|
|
6
|
-
|
|
7
|
-
/** VenueBooking 智能定价运行时上下文 */
|
|
8
|
-
|
|
9
|
-
/** 从商品上读取展示/算价用的 price 字段 */
|
|
10
|
-
export function extractProductPrice(product) {
|
|
11
|
-
var _product$price;
|
|
12
|
-
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;
|
|
13
|
-
if (price == null || price === '') return null;
|
|
14
|
-
return String(price);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** 组装 DataVariant 评估入参,对齐 OS Server buildProductFormatterContext 语义 */
|
|
18
|
-
export function buildDataVariantBusinessData(products, context, scheduleDateTime) {
|
|
19
|
-
var _ref, _context$availableWal, _context$channel, _ref2, _context$orderType, _ref3, _context$businessCode;
|
|
20
|
-
var strategyContext = context.strategy_context || {};
|
|
21
|
-
return {
|
|
22
|
-
products: products,
|
|
23
|
-
strategyConfigs: context.strategyConfigs,
|
|
24
|
-
scheduleDateTime: scheduleDateTime,
|
|
25
|
-
scheduleList: context.scheduleList || [],
|
|
26
|
-
menuList: context.menuList || [],
|
|
27
|
-
customerId: context.customerId,
|
|
28
|
-
availableWalletIds: (_ref = (_context$availableWal = context.availableWalletIds) !== null && _context$availableWal !== void 0 ? _context$availableWal : strategyContext.available_wallet_ids) !== null && _ref !== void 0 ? _ref : strategyContext.availableWalletIds,
|
|
29
|
-
channel: (_context$channel = context.channel) !== null && _context$channel !== void 0 ? _context$channel : strategyContext.channel,
|
|
30
|
-
orderType: (_ref2 = (_context$orderType = context.orderType) !== null && _context$orderType !== void 0 ? _context$orderType : strategyContext.orderType) !== null && _ref2 !== void 0 ? _ref2 : strategyContext.order_type,
|
|
31
|
-
businessCode: (_ref3 = (_context$businessCode = context.businessCode) !== null && _context$businessCode !== void 0 ? _context$businessCode : strategyContext.business_code) !== null && _ref3 !== void 0 ? _ref3 : strategyContext.businessCode,
|
|
32
|
-
custom: strategyContext
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 对商品列表执行一次智能定价格式化(loadProducts 后使用)。
|
|
38
|
-
* evaluator 未注入时原样返回并打 warning。
|
|
39
|
-
*/
|
|
40
|
-
export function formatProductsWithDataVariant(products, context, scheduleDateTime) {
|
|
41
|
-
var evaluator = context.evaluator;
|
|
42
|
-
if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
|
|
43
|
-
console.warn('[VenueBooking][smartPricing] dataVariantEvaluator 未注入,跳过智能定价格式化');
|
|
44
|
-
return products;
|
|
45
|
-
}
|
|
46
|
-
var resolvedAt = scheduleDateTime || dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
47
|
-
var businessData = buildDataVariantBusinessData(products, context, resolvedAt);
|
|
48
|
-
var result = evaluator.resolveProducts(businessData);
|
|
49
|
-
return Array.isArray(result === null || result === void 0 ? void 0 : result.products) ? result.products : products;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* 根据 schedule_time_points 与营业开始时间,构造当天需要评估的 datetime 列表(升序)。
|
|
54
|
-
* 跨日营业时,早于营业开始小时的时间点归到次日。
|
|
55
|
-
*/
|
|
56
|
-
export function buildEvaluationDatetimes(params) {
|
|
57
|
-
var date = params.date,
|
|
58
|
-
config = params.config,
|
|
59
|
-
scheduleTimePoints = params.scheduleTimePoints;
|
|
60
|
-
var crossDay = isBusinessHoursCrossDay(config);
|
|
61
|
-
var businessStartHour = Number(config.businessStartTime.split(':')[0]);
|
|
62
|
-
var evalSet = new Set();
|
|
63
|
-
evalSet.add("".concat(date, " ").concat(config.businessStartTime));
|
|
64
|
-
var _iterator = _createForOfIteratorHelper(scheduleTimePoints),
|
|
65
|
-
_step;
|
|
66
|
-
try {
|
|
67
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
68
|
-
var timePoint = _step.value;
|
|
69
|
-
var hour = Number(timePoint.split(':')[0]);
|
|
70
|
-
var pointDate = crossDay && hour < businessStartHour ? dayjs(date).add(1, 'day').format('YYYY-MM-DD') : date;
|
|
71
|
-
evalSet.add("".concat(pointDate, " ").concat(timePoint));
|
|
72
|
-
}
|
|
73
|
-
} catch (err) {
|
|
74
|
-
_iterator.e(err);
|
|
75
|
-
} finally {
|
|
76
|
-
_iterator.f();
|
|
77
|
-
}
|
|
78
|
-
return Array.from(evalSet).sort(function (a, b) {
|
|
79
|
-
var aMs = dayjs(a, ['YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD HH:mm']).valueOf();
|
|
80
|
-
var bMs = dayjs(b, ['YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD HH:mm']).valueOf();
|
|
81
|
-
return aMs - bMs;
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** 找到 slot 时间所属分段的评估 datetime(max(evalDt <= slotDt)) */
|
|
86
|
-
export function findSegmentEvalDatetime(slotDatetime, evalDatetimes) {
|
|
87
|
-
if (!evalDatetimes.length) return slotDatetime;
|
|
88
|
-
var slotMs = dayjs(slotDatetime, ['YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD HH:mm']).valueOf();
|
|
89
|
-
var chosen = evalDatetimes[0];
|
|
90
|
-
var _iterator2 = _createForOfIteratorHelper(evalDatetimes),
|
|
91
|
-
_step2;
|
|
92
|
-
try {
|
|
93
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
94
|
-
var evalDt = _step2.value;
|
|
95
|
-
var evalMs = dayjs(evalDt, ['YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD HH:mm']).valueOf();
|
|
96
|
-
if (evalMs <= slotMs) {
|
|
97
|
-
chosen = evalDt;
|
|
98
|
-
} else {
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
} catch (err) {
|
|
103
|
-
_iterator2.e(err);
|
|
104
|
-
} finally {
|
|
105
|
-
_iterator2.f();
|
|
106
|
-
}
|
|
107
|
-
return chosen;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** 将 slot 标签转为与 timeSlot 网格一致的 slotStart 字符串 */
|
|
111
|
-
export function buildSlotStartDatetime(date, label, config) {
|
|
112
|
-
var crossDay = isBusinessHoursCrossDay(config);
|
|
113
|
-
var businessStartHour = Number(config.businessStartTime.split(':')[0]);
|
|
114
|
-
var hour = Number(label.split(':')[0]);
|
|
115
|
-
var slotDate = crossDay && hour < businessStartHour ? dayjs(date).add(1, 'day').format('YYYY-MM-DD') : date;
|
|
116
|
-
return dayjs("".concat(slotDate, " ").concat(label)).format('YYYY-MM-DD HH:mm');
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* 按 schedule 分段批量 resolveProducts,输出与 quotation 相同 key 格式的 slot 价格 Map。
|
|
121
|
-
* key: `${productId}:${slotStart}`,value: price | null
|
|
122
|
-
*/
|
|
123
|
-
export function buildSlotPriceMapByScheduleSegments(params) {
|
|
124
|
-
var products = params.products,
|
|
125
|
-
productIds = params.productIds,
|
|
126
|
-
date = params.date,
|
|
127
|
-
timeLabels = params.timeLabels,
|
|
128
|
-
config = params.config,
|
|
129
|
-
context = params.context;
|
|
130
|
-
var map = new Map();
|
|
131
|
-
if (!productIds.length || !timeLabels.length) return map;
|
|
132
|
-
var evaluator = context.evaluator;
|
|
133
|
-
if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
|
|
134
|
-
return map;
|
|
135
|
-
}
|
|
136
|
-
var strategyConfigs = context.strategyConfigs || (typeof evaluator.getStrategyConfigs === 'function' ? evaluator.getStrategyConfigs() : []);
|
|
137
|
-
var scheduleTimePoints = typeof evaluator.buildScheduleTimePoints === 'function' ? evaluator.buildScheduleTimePoints(strategyConfigs, context.scheduleList || []) : [];
|
|
138
|
-
var evalDatetimes = buildEvaluationDatetimes({
|
|
139
|
-
date: date,
|
|
140
|
-
config: config,
|
|
141
|
-
scheduleTimePoints: scheduleTimePoints
|
|
142
|
-
});
|
|
143
|
-
var priceCache = new Map();
|
|
144
|
-
var _iterator3 = _createForOfIteratorHelper(evalDatetimes),
|
|
145
|
-
_step3;
|
|
146
|
-
try {
|
|
147
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
148
|
-
var evalDt = _step3.value;
|
|
149
|
-
var resolved = formatProductsWithDataVariant(products, context, evalDt);
|
|
150
|
-
var priceByProductId = new Map();
|
|
151
|
-
var _iterator5 = _createForOfIteratorHelper(resolved),
|
|
152
|
-
_step5;
|
|
153
|
-
try {
|
|
154
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
155
|
-
var product = _step5.value;
|
|
156
|
-
var productId = Number(product.id);
|
|
157
|
-
if (!Number.isFinite(productId)) continue;
|
|
158
|
-
priceByProductId.set(productId, extractProductPrice(product));
|
|
159
|
-
}
|
|
160
|
-
} catch (err) {
|
|
161
|
-
_iterator5.e(err);
|
|
162
|
-
} finally {
|
|
163
|
-
_iterator5.f();
|
|
164
|
-
}
|
|
165
|
-
priceCache.set(evalDt, priceByProductId);
|
|
166
|
-
}
|
|
167
|
-
} catch (err) {
|
|
168
|
-
_iterator3.e(err);
|
|
169
|
-
} finally {
|
|
170
|
-
_iterator3.f();
|
|
171
|
-
}
|
|
172
|
-
var _iterator4 = _createForOfIteratorHelper(timeLabels),
|
|
173
|
-
_step4;
|
|
174
|
-
try {
|
|
175
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
176
|
-
var label = _step4.value;
|
|
177
|
-
var slotStart = buildSlotStartDatetime(date, label, config);
|
|
178
|
-
var segmentEvalDt = findSegmentEvalDatetime(slotStart, evalDatetimes);
|
|
179
|
-
var _priceByProductId = priceCache.get(segmentEvalDt);
|
|
180
|
-
var _iterator6 = _createForOfIteratorHelper(productIds),
|
|
181
|
-
_step6;
|
|
182
|
-
try {
|
|
183
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
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;
|
|
188
|
-
if (price !== null) {
|
|
189
|
-
map.set(key, price);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
} catch (err) {
|
|
193
|
-
_iterator6.e(err);
|
|
194
|
-
} finally {
|
|
195
|
-
_iterator6.f();
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
} catch (err) {
|
|
199
|
-
_iterator4.e(err);
|
|
200
|
-
} finally {
|
|
201
|
-
_iterator4.f();
|
|
202
|
-
}
|
|
203
|
-
return map;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* 指定商品在某一 datetime 的智能定价(addon / 单点重算用)。
|
|
208
|
-
*/
|
|
209
|
-
export function getPriceForProductAtDatetime(params) {
|
|
210
|
-
var _ref4, _extractProductPrice;
|
|
211
|
-
var products = params.products,
|
|
212
|
-
context = params.context,
|
|
213
|
-
productId = params.productId,
|
|
214
|
-
datetime = params.datetime,
|
|
215
|
-
fallbackPrice = params.fallbackPrice;
|
|
216
|
-
var resolved = formatProductsWithDataVariant(products, context, datetime);
|
|
217
|
-
var product = resolved.find(function (item) {
|
|
218
|
-
return Number(item.id) === Number(productId);
|
|
219
|
-
});
|
|
220
|
-
return (_ref4 = (_extractProductPrice = extractProductPrice(product || {})) !== null && _extractProductPrice !== void 0 ? _extractProductPrice : fallbackPrice) !== null && _ref4 !== void 0 ? _ref4 : '0.00';
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/** 从 slot 价格 Map 读取单价,找不到则回退 fallback */
|
|
224
|
-
export function getSlotPriceFromMap(params) {
|
|
225
|
-
var slotPriceMap = params.slotPriceMap,
|
|
226
|
-
productId = params.productId,
|
|
227
|
-
slotStartTime = params.slotStartTime,
|
|
228
|
-
fallbackPrice = params.fallbackPrice;
|
|
229
|
-
var key = "".concat(productId, ":").concat(slotStartTime);
|
|
230
|
-
var mapped = slotPriceMap.get(key);
|
|
231
|
-
if (mapped != null) return mapped;
|
|
232
|
-
return fallbackPrice !== null && fallbackPrice !== void 0 ? fallbackPrice : '0.00';
|
|
233
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { EvaluationResult, RuntimeContext } from '../../type';
|
|
2
|
-
import type { BusinessAdapter } from '../type';
|
|
3
|
-
import type { DataVariantBusinessData, DataVariantProduct } from './type';
|
|
4
|
-
/**
|
|
5
|
-
* Data Variant 适配器。
|
|
6
|
-
*
|
|
7
|
-
* 负责把智能定价运行态数据转换为 StrategyEngine 能识别的 attributes。
|
|
8
|
-
*/
|
|
9
|
-
export declare class DataVariantAdapter implements BusinessAdapter {
|
|
10
|
-
name: string;
|
|
11
|
-
version: string;
|
|
12
|
-
/**
|
|
13
|
-
* 准备批量全局上下文。
|
|
14
|
-
*
|
|
15
|
-
* 这里只放不依赖单个商品的字段,用于预计算 schedule/channel/orderType 等条件。
|
|
16
|
-
*/
|
|
17
|
-
prepareContext(businessData: DataVariantBusinessData): RuntimeContext;
|
|
18
|
-
/**
|
|
19
|
-
* 准备全局预计算上下文。
|
|
20
|
-
*/
|
|
21
|
-
prepareGlobalContext(businessData: DataVariantBusinessData): RuntimeContext;
|
|
22
|
-
/**
|
|
23
|
-
* 准备单商品上下文。
|
|
24
|
-
*
|
|
25
|
-
* 商品级条件只在当前商品 data_variants 引用到对应规则后才评估。
|
|
26
|
-
*/
|
|
27
|
-
prepareProductContext(businessData: DataVariantBusinessData, product: DataVariantProduct): RuntimeContext;
|
|
28
|
-
transformResult(result: EvaluationResult): EvaluationResult;
|
|
29
|
-
formatConfig(result: EvaluationResult, businessData?: DataVariantBusinessData): {
|
|
30
|
-
result: EvaluationResult;
|
|
31
|
-
businessData?: DataVariantBusinessData;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* 构建 menu_match 使用的轻量商品对象。
|
|
35
|
-
*
|
|
36
|
-
* collection_ids 来自商品 collection 字段,避免 operator 读取复杂商品对象。
|
|
37
|
-
*/
|
|
38
|
-
buildProductValue(product: DataVariantProduct): {
|
|
39
|
-
id: number;
|
|
40
|
-
product_variant_id: number;
|
|
41
|
-
collection_ids: number[];
|
|
42
|
-
};
|
|
43
|
-
private toNumber;
|
|
44
|
-
/**
|
|
45
|
-
* 归一化客户 id:无效值返回 undefined,有效值统一为 number。
|
|
46
|
-
*/
|
|
47
|
-
private normalizeCustomerId;
|
|
48
|
-
private normalizeNumberArray;
|
|
49
|
-
}
|
|
50
|
-
export default DataVariantAdapter;
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// src/model/strategy/adapter/dataVariant/adapter.ts
|
|
20
|
-
var adapter_exports = {};
|
|
21
|
-
__export(adapter_exports, {
|
|
22
|
-
DataVariantAdapter: () => DataVariantAdapter,
|
|
23
|
-
default: () => adapter_default
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(adapter_exports);
|
|
26
|
-
var DataVariantAdapter = class {
|
|
27
|
-
constructor() {
|
|
28
|
-
this.name = "DataVariantAdapter";
|
|
29
|
-
this.version = "1.0.0";
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* 准备批量全局上下文。
|
|
33
|
-
*
|
|
34
|
-
* 这里只放不依赖单个商品的字段,用于预计算 schedule/channel/orderType 等条件。
|
|
35
|
-
*/
|
|
36
|
-
prepareContext(businessData) {
|
|
37
|
-
return this.prepareGlobalContext(businessData);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 准备全局预计算上下文。
|
|
41
|
-
*/
|
|
42
|
-
prepareGlobalContext(businessData) {
|
|
43
|
-
const {
|
|
44
|
-
products,
|
|
45
|
-
scheduleDateTime,
|
|
46
|
-
channel,
|
|
47
|
-
orderType,
|
|
48
|
-
businessCode,
|
|
49
|
-
customerId,
|
|
50
|
-
availableWalletIds,
|
|
51
|
-
custom
|
|
52
|
-
} = businessData;
|
|
53
|
-
const normalizedCustomerId = this.normalizeCustomerId(customerId);
|
|
54
|
-
const normalizedAvailableWalletIds = this.normalizeNumberArray(availableWalletIds ?? (custom == null ? void 0 : custom.available_wallet_ids));
|
|
55
|
-
const resolvedBusinessCode = businessCode || (custom == null ? void 0 : custom.business_code) || (custom == null ? void 0 : custom.businessCode) || "";
|
|
56
|
-
return {
|
|
57
|
-
entities: {
|
|
58
|
-
products
|
|
59
|
-
},
|
|
60
|
-
attributes: {
|
|
61
|
-
...custom,
|
|
62
|
-
schedule: scheduleDateTime || "",
|
|
63
|
-
channel: channel || (custom == null ? void 0 : custom.channel) || "",
|
|
64
|
-
orderType: orderType || (custom == null ? void 0 : custom.orderType) || (custom == null ? void 0 : custom.order_type) || "",
|
|
65
|
-
// snake_case 与策略配置 field 对齐;customerId 保留兼容旧配置
|
|
66
|
-
customer_id: normalizedCustomerId,
|
|
67
|
-
customerId: normalizedCustomerId,
|
|
68
|
-
available_wallet_ids: normalizedAvailableWalletIds,
|
|
69
|
-
availableWalletIds: normalizedAvailableWalletIds,
|
|
70
|
-
business_code: resolvedBusinessCode
|
|
71
|
-
},
|
|
72
|
-
metadata: {
|
|
73
|
-
timestamp: Date.now()
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* 准备单商品上下文。
|
|
79
|
-
*
|
|
80
|
-
* 商品级条件只在当前商品 data_variants 引用到对应规则后才评估。
|
|
81
|
-
*/
|
|
82
|
-
prepareProductContext(businessData, product) {
|
|
83
|
-
const base = this.prepareGlobalContext(businessData);
|
|
84
|
-
const productValue = this.buildProductValue(product);
|
|
85
|
-
return {
|
|
86
|
-
...base,
|
|
87
|
-
entities: {
|
|
88
|
-
...base.entities,
|
|
89
|
-
currentProduct: product
|
|
90
|
-
},
|
|
91
|
-
attributes: {
|
|
92
|
-
...base.attributes,
|
|
93
|
-
product: productValue,
|
|
94
|
-
productIdAndVariantId: {
|
|
95
|
-
product_id: productValue.id,
|
|
96
|
-
product_variant_id: productValue.product_variant_id
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
transformResult(result) {
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
formatConfig(result, businessData) {
|
|
105
|
-
return { result, businessData };
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* 构建 menu_match 使用的轻量商品对象。
|
|
109
|
-
*
|
|
110
|
-
* collection_ids 来自商品 collection 字段,避免 operator 读取复杂商品对象。
|
|
111
|
-
*/
|
|
112
|
-
buildProductValue(product) {
|
|
113
|
-
const productId = this.toNumber(product.id ?? product.product_id);
|
|
114
|
-
const variantId = this.toNumber(
|
|
115
|
-
product.product_variant_id ?? product.variant_id
|
|
116
|
-
);
|
|
117
|
-
const collectionIds = Array.isArray(product.collection) ? product.collection.map((item) => this.toNumber(item == null ? void 0 : item.id)).filter((id) => id > 0) : [];
|
|
118
|
-
return {
|
|
119
|
-
id: productId,
|
|
120
|
-
product_variant_id: variantId,
|
|
121
|
-
collection_ids: collectionIds
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
toNumber(value) {
|
|
125
|
-
const parsed = Number(value);
|
|
126
|
-
return Number.isFinite(parsed) ? parsed : 0;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* 归一化客户 id:无效值返回 undefined,有效值统一为 number。
|
|
130
|
-
*/
|
|
131
|
-
normalizeCustomerId(value) {
|
|
132
|
-
if (value === void 0 || value === null || value === "") {
|
|
133
|
-
return void 0;
|
|
134
|
-
}
|
|
135
|
-
const parsed = Number(value);
|
|
136
|
-
return Number.isFinite(parsed) && parsed > 0 ? parsed : void 0;
|
|
137
|
-
}
|
|
138
|
-
normalizeNumberArray(value) {
|
|
139
|
-
if (!Array.isArray(value))
|
|
140
|
-
return [];
|
|
141
|
-
const ids = value.map((item) => Number(item)).filter((item) => Number.isFinite(item) && item > 0);
|
|
142
|
-
return Array.from(new Set(ids));
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
var adapter_default = DataVariantAdapter;
|
|
146
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
147
|
-
0 && (module.exports = {
|
|
148
|
-
DataVariantAdapter
|
|
149
|
-
});
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import type { ConditionRule, StrategyConfig } from '../../type';
|
|
2
|
-
import type { ConditionScope, DataVariantBusinessData, DataVariantMenu, DataVariantRuleMetadata, MenuScope, ResolvedDataVariantResult } from './type';
|
|
3
|
-
/**
|
|
4
|
-
* Data Variant 评估器。
|
|
5
|
-
*
|
|
6
|
-
* 当前阶段只提供策略模型能力和示例验证,不接入 ProductList 业务链路。
|
|
7
|
-
*/
|
|
8
|
-
export declare class DataVariantEvaluator {
|
|
9
|
-
private adapter;
|
|
10
|
-
private strategyConfigs;
|
|
11
|
-
constructor();
|
|
12
|
-
/**
|
|
13
|
-
* 设置策略配置列表,仅保留 metadata.type === 'data_variant' 的策略。
|
|
14
|
-
*/
|
|
15
|
-
setStrategyConfigs(configs: StrategyConfig[]): void;
|
|
16
|
-
getStrategyConfigs(): StrategyConfig<DataVariantRuleMetadata>[];
|
|
17
|
-
/**
|
|
18
|
-
* 批量解析商品 Data Variant。
|
|
19
|
-
*
|
|
20
|
-
* 先执行全局预计算,再只针对商品自身 data_variants 引用到的规则做商品级判断。
|
|
21
|
-
*/
|
|
22
|
-
resolveProducts(businessData: DataVariantBusinessData): ResolvedDataVariantResult;
|
|
23
|
-
/**
|
|
24
|
-
* 根据 operator/field 判断条件是否依赖当前商品。
|
|
25
|
-
*/
|
|
26
|
-
getConditionScope(rule: ConditionRule): ConditionScope;
|
|
27
|
-
/**
|
|
28
|
-
* 将餐牌 partyroom_package 预构建为 Map/Set 索引。
|
|
29
|
-
*/
|
|
30
|
-
buildMenuScopeMap(menuList: DataVariantMenu[]): Map<number, MenuScope>;
|
|
31
|
-
/**
|
|
32
|
-
* 从当前策略中所有 schedule_match.value 绑定的 schedule_id 提取时间点。
|
|
33
|
-
*
|
|
34
|
-
* 这里不依赖餐牌,只读取策略配置和调用方传入的 scheduleList。
|
|
35
|
-
*/
|
|
36
|
-
buildScheduleTimePoints(strategyConfigs: StrategyConfig<DataVariantRuleMetadata>[], scheduleList: NonNullable<DataVariantBusinessData['scheduleList']>): string[];
|
|
37
|
-
private buildGlobalEffectiveRuleMap;
|
|
38
|
-
private resolveProduct;
|
|
39
|
-
/**
|
|
40
|
-
* 解析套餐子商品上的 Data Variant 覆盖。
|
|
41
|
-
*
|
|
42
|
-
* bundle_item 以 bundle_product_id / bundle_variant_id 作为商品身份参与 product_match 等条件判断。
|
|
43
|
-
*/
|
|
44
|
-
private resolveProductBundleItems;
|
|
45
|
-
/**
|
|
46
|
-
* 将 bundle_item 转为 DataVariantProduct 并评估 data_variants。
|
|
47
|
-
*/
|
|
48
|
-
private resolveBundleItem;
|
|
49
|
-
/**
|
|
50
|
-
* bundle_item 的商品身份映射:bundle_product_id + bundle_variant_id。
|
|
51
|
-
*/
|
|
52
|
-
private toBundleItemDataVariantProduct;
|
|
53
|
-
/**
|
|
54
|
-
* 仅回写命中的字段,避免污染 bundle_item 的结构字段。
|
|
55
|
-
*/
|
|
56
|
-
private mergeBundleItemResolvedData;
|
|
57
|
-
private evaluateProductRules;
|
|
58
|
-
/**
|
|
59
|
-
* 拆分策略条件。
|
|
60
|
-
*
|
|
61
|
-
* 当前 MVP 支持顶层 and 原子条件拆分;复杂条件保守地放到商品级完整判断。
|
|
62
|
-
*/
|
|
63
|
-
private splitStrategyConfig;
|
|
64
|
-
private createEngine;
|
|
65
|
-
private evaluateScheduleMatch;
|
|
66
|
-
private evaluateMenuMatch;
|
|
67
|
-
private evaluateArrayIntersects;
|
|
68
|
-
private collectScheduleIdsFromStrategies;
|
|
69
|
-
private extractTimePointsFromSchedules;
|
|
70
|
-
private addDateTimePoint;
|
|
71
|
-
private addRawTimePoint;
|
|
72
|
-
private extractTimeFromDateTime;
|
|
73
|
-
private normalizeTime;
|
|
74
|
-
private timeToMinutes;
|
|
75
|
-
private isProductInMenuScope;
|
|
76
|
-
private mergeMatchedVariants;
|
|
77
|
-
private getProductDataVariants;
|
|
78
|
-
private normalizeStrategyConfigs;
|
|
79
|
-
private isStrategyActive;
|
|
80
|
-
private getStrategyPriority;
|
|
81
|
-
private createAlwaysTrueConditions;
|
|
82
|
-
private flattenConditionRules;
|
|
83
|
-
private isConditionGroup;
|
|
84
|
-
private normalizeNumberArray;
|
|
85
|
-
private normalizeComparableArray;
|
|
86
|
-
private buildProductKey;
|
|
87
|
-
private toNumber;
|
|
88
|
-
}
|
|
89
|
-
export default DataVariantEvaluator;
|