@pisell/pisellos 2.3.202 → 2.3.204
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/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/ResourcePlanner/planner.js +2 -5
- package/dist/solution/ScanOrder/menuAvailability.js +29 -10
- package/lib/model/strategy/adapter/promotion/index.js +46 -1
- package/lib/modules/ResourcePlanner/planner.js +2 -5
- package/lib/solution/ScanOrder/menuAvailability.js +20 -8
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// 导出评估器
|
|
2
|
+
export { PromotionEvaluator } from "./evaluator";
|
|
3
|
+
|
|
4
|
+
// 导出适配器
|
|
5
|
+
export { PromotionAdapter } from "./adapter";
|
|
6
|
+
export { default } from "./adapter";
|
|
7
|
+
|
|
8
|
+
// 导出策略配置示例常量
|
|
9
|
+
export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, ITEM_REWARD_STRATEGY } from "./examples";
|
|
@@ -175,11 +175,8 @@ function resolveCutOffPolicyIssue(policy) {
|
|
|
175
175
|
return null;
|
|
176
176
|
}
|
|
177
177
|
function addLeadWindow(base, unit, unitType, _timezoneName) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
// Positive day lead times start at midnight; zero days keeps the current-time boundary.
|
|
181
|
-
return Math.trunc(unit) > 0 ? localDateToScalarStart(formatLocalDate(leadDate)) : leadDate;
|
|
182
|
-
}
|
|
178
|
+
// Calendar-day lead times retain the current local hour, minute and second.
|
|
179
|
+
if (unitType === 'days') return addLocalCalendarDays(base, unit);
|
|
183
180
|
if (unitType === 'hours') return addLocalHours(base, unit);
|
|
184
181
|
return addLocalMinutes(base, unit);
|
|
185
182
|
}
|
|
@@ -56,6 +56,10 @@ var productId = function productId(product) {
|
|
|
56
56
|
var _product$product_id;
|
|
57
57
|
return positiveId((_product$product_id = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : product === null || product === void 0 ? void 0 : product.id);
|
|
58
58
|
};
|
|
59
|
+
var isReservationRuleProduct = function isReservationRuleProduct(product) {
|
|
60
|
+
var _product$metadata;
|
|
61
|
+
return (product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.is_rule) === true;
|
|
62
|
+
};
|
|
59
63
|
var fail = function fail() {
|
|
60
64
|
var ids = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
61
65
|
throw new ScanOrderMenuAvailabilityError('SCAN_ORDER_MENU_VALIDATION_FAILED', ids);
|
|
@@ -74,11 +78,14 @@ function readIds(values) {
|
|
|
74
78
|
return _toConsumableArray(new Set(ids));
|
|
75
79
|
}
|
|
76
80
|
function readMenu(record) {
|
|
77
|
-
var
|
|
78
|
-
var
|
|
81
|
+
var _config$filter;
|
|
82
|
+
var config = record.partyroom_package;
|
|
83
|
+
var scope = config === null || config === void 0 ? void 0 : config.type;
|
|
79
84
|
if (!['product_all', 'products', 'product_collection'].includes(scope)) return fail();
|
|
80
|
-
var items =
|
|
85
|
+
var items = config.products;
|
|
81
86
|
if (scope !== 'product_all' && !Array.isArray(items)) return fail();
|
|
87
|
+
var filter = Number((_config$filter = config.filter) !== null && _config$filter !== void 0 ? _config$filter : 0);
|
|
88
|
+
if (scope === 'product_all' && ![0, 1].includes(filter)) return fail();
|
|
82
89
|
return {
|
|
83
90
|
id: positiveId(record.form_record_id),
|
|
84
91
|
scheduleIds: readIds(record.schedule),
|
|
@@ -88,7 +95,10 @@ function readMenu(record) {
|
|
|
88
95
|
})) : [],
|
|
89
96
|
collectionIds: scope === 'product_collection' ? readIds(items.map(function (item) {
|
|
90
97
|
return item.product_collection_id;
|
|
91
|
-
})) : []
|
|
98
|
+
})) : [],
|
|
99
|
+
// The API resolves rule/rule_type into product_ids. For all-products menus
|
|
100
|
+
// these IDs are exclusions, and only apply while filtering is enabled.
|
|
101
|
+
excludedProductIds: scope === 'product_all' && filter === 1 ? readIds(config.product_ids) : []
|
|
92
102
|
};
|
|
93
103
|
}
|
|
94
104
|
function validateSchedule(schedule) {
|
|
@@ -190,7 +200,9 @@ function _prepareScanOrderMenuAvailability() {
|
|
|
190
200
|
while (1) switch (_context.prev = _context.next) {
|
|
191
201
|
case 0:
|
|
192
202
|
request = _ref.request, menuIds = _ref.menuIds, timezone = _ref.timezone, products = _ref.products, _ref$productSources = _ref.productSources, productSources = _ref$productSources === void 0 ? [] : _ref$productSources;
|
|
193
|
-
initialIds = products.
|
|
203
|
+
initialIds = products.filter(function (product) {
|
|
204
|
+
return !isReservationRuleProduct(product);
|
|
205
|
+
}).map(productId).filter(function (id) {
|
|
194
206
|
return id !== undefined;
|
|
195
207
|
});
|
|
196
208
|
_context.prev = 2;
|
|
@@ -287,14 +299,17 @@ function _prepareScanOrderMenuAvailability() {
|
|
|
287
299
|
_step3;
|
|
288
300
|
try {
|
|
289
301
|
var _loop = function _loop() {
|
|
290
|
-
var _product$
|
|
302
|
+
var _product$metadata2;
|
|
291
303
|
var product = _step3.value;
|
|
304
|
+
// Booking rule lines attach the order to a resource; they are not
|
|
305
|
+
// customer menu items, even when a menu explicitly mentions them.
|
|
306
|
+
if (isReservationRuleProduct(product)) return 0; // continue
|
|
292
307
|
var id = productId(product);
|
|
293
308
|
if (!id) return {
|
|
294
309
|
v: fail()
|
|
295
310
|
};
|
|
296
311
|
var matchesDirectly = function matchesDirectly(menu) {
|
|
297
|
-
return menu.scope === 'product_all' || menu.scope === 'products' && menu.productIds.includes(id);
|
|
312
|
+
return menu.scope === 'product_all' && !menu.excludedProductIds.includes(id) || menu.scope === 'products' && menu.productIds.includes(id);
|
|
298
313
|
};
|
|
299
314
|
var isAvailable = function isAvailable(menu) {
|
|
300
315
|
return getDateIsInSchedule(currentTime, menu.scheduleIds.map(function (scheduleId) {
|
|
@@ -302,7 +317,7 @@ function _prepareScanOrderMenuAvailability() {
|
|
|
302
317
|
}));
|
|
303
318
|
};
|
|
304
319
|
// A known valid direct relation is sufficient regardless of missing
|
|
305
|
-
// collection data on a
|
|
320
|
+
// collection data on a product appended after preparation.
|
|
306
321
|
if (menus.some(function (menu) {
|
|
307
322
|
return matchesDirectly(menu) && isAvailable(menu);
|
|
308
323
|
})) return 0; // continue
|
|
@@ -317,8 +332,12 @@ function _prepareScanOrderMenuAvailability() {
|
|
|
317
332
|
});
|
|
318
333
|
});
|
|
319
334
|
if (associated.some(isAvailable)) return 0; // continue
|
|
320
|
-
|
|
321
|
-
|
|
335
|
+
// Keep the fallback for unmapped retail prefills, but never let it
|
|
336
|
+
// override a menu's explicit product exclusion.
|
|
337
|
+
var explicitlyExcluded = menus.some(function (menu) {
|
|
338
|
+
return menu.excludedProductIds.includes(id);
|
|
339
|
+
});
|
|
340
|
+
if (associated.length === 0 && !explicitlyExcluded && ((_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.item_rule_prefill) === true) return 0; // continue
|
|
322
341
|
unavailable.push(id);
|
|
323
342
|
},
|
|
324
343
|
_ret;
|
|
@@ -1 +1,46 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "BUY_X_GET_Y_FREE_STRATEGY", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _examples.BUY_X_GET_Y_FREE_STRATEGY;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ITEM_REWARD_STRATEGY", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _examples.ITEM_REWARD_STRATEGY;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "PromotionAdapter", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _adapter.PromotionAdapter;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "PromotionEvaluator", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _evaluator.PromotionEvaluator;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "X_ITEMS_FOR_Y_PRICE_STRATEGY", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _examples.X_ITEMS_FOR_Y_PRICE_STRATEGY;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "default", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _adapter.default;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var _evaluator = require("./evaluator");
|
|
43
|
+
var _adapter = _interopRequireWildcard(require("./adapter"));
|
|
44
|
+
var _examples = require("./examples");
|
|
45
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
46
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -163,11 +163,8 @@ function resolveCutOffPolicyIssue(policy) {
|
|
|
163
163
|
return null;
|
|
164
164
|
}
|
|
165
165
|
function addLeadWindow(base, unit, unitType, _timezoneName) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
// Positive day lead times start at midnight; zero days keeps the current-time boundary.
|
|
169
|
-
return Math.trunc(unit) > 0 ? (0, _localClock.localDateToScalarStart)((0, _localClock.formatLocalDate)(leadDate)) : leadDate;
|
|
170
|
-
}
|
|
166
|
+
// Calendar-day lead times retain the current local hour, minute and second.
|
|
167
|
+
if (unitType === 'days') return (0, _localClock.addLocalCalendarDays)(base, unit);
|
|
171
168
|
if (unitType === 'hours') return (0, _localClock.addLocalHours)(base, unit);
|
|
172
169
|
return (0, _localClock.addLocalMinutes)(base, unit);
|
|
173
170
|
}
|
|
@@ -24,6 +24,7 @@ const positiveId = value => {
|
|
|
24
24
|
return Number.isInteger(id) && id > 0 ? id : undefined;
|
|
25
25
|
};
|
|
26
26
|
const productId = product => positiveId(product?.product_id ?? product?.id);
|
|
27
|
+
const isReservationRuleProduct = product => product?.metadata?.is_rule === true;
|
|
27
28
|
const fail = (ids = []) => {
|
|
28
29
|
throw new ScanOrderMenuAvailabilityError('SCAN_ORDER_MENU_VALIDATION_FAILED', ids);
|
|
29
30
|
};
|
|
@@ -38,16 +39,22 @@ function readIds(values) {
|
|
|
38
39
|
return [...new Set(ids)];
|
|
39
40
|
}
|
|
40
41
|
function readMenu(record) {
|
|
41
|
-
const
|
|
42
|
+
const config = record.partyroom_package;
|
|
43
|
+
const scope = config?.type;
|
|
42
44
|
if (!['product_all', 'products', 'product_collection'].includes(scope)) return fail();
|
|
43
|
-
const items =
|
|
45
|
+
const items = config.products;
|
|
44
46
|
if (scope !== 'product_all' && !Array.isArray(items)) return fail();
|
|
47
|
+
const filter = Number(config.filter ?? 0);
|
|
48
|
+
if (scope === 'product_all' && ![0, 1].includes(filter)) return fail();
|
|
45
49
|
return {
|
|
46
50
|
id: positiveId(record.form_record_id),
|
|
47
51
|
scheduleIds: readIds(record.schedule),
|
|
48
52
|
scope,
|
|
49
53
|
productIds: scope === 'products' ? readIds(items.map(item => item.product_id)) : [],
|
|
50
|
-
collectionIds: scope === 'product_collection' ? readIds(items.map(item => item.product_collection_id)) : []
|
|
54
|
+
collectionIds: scope === 'product_collection' ? readIds(items.map(item => item.product_collection_id)) : [],
|
|
55
|
+
// The API resolves rule/rule_type into product_ids. For all-products menus
|
|
56
|
+
// these IDs are exclusions, and only apply while filtering is enabled.
|
|
57
|
+
excludedProductIds: scope === 'product_all' && filter === 1 ? readIds(config.product_ids) : []
|
|
51
58
|
};
|
|
52
59
|
}
|
|
53
60
|
function validateSchedule(schedule) {
|
|
@@ -111,7 +118,7 @@ async function prepareScanOrderMenuAvailability({
|
|
|
111
118
|
products,
|
|
112
119
|
productSources = []
|
|
113
120
|
}) {
|
|
114
|
-
const initialIds = products.map(productId).filter(id => id !== undefined);
|
|
121
|
+
const initialIds = products.filter(product => !isReservationRuleProduct(product)).map(productId).filter(id => id !== undefined);
|
|
115
122
|
try {
|
|
116
123
|
const now = createShopClock(timezone);
|
|
117
124
|
const configuredIds = readIds(menuIds);
|
|
@@ -169,12 +176,15 @@ async function prepareScanOrderMenuAvailability({
|
|
|
169
176
|
const unavailable = [];
|
|
170
177
|
const insufficient = [];
|
|
171
178
|
for (const product of currentProducts) {
|
|
179
|
+
// Booking rule lines attach the order to a resource; they are not
|
|
180
|
+
// customer menu items, even when a menu explicitly mentions them.
|
|
181
|
+
if (isReservationRuleProduct(product)) continue;
|
|
172
182
|
const id = productId(product);
|
|
173
183
|
if (!id) return fail();
|
|
174
|
-
const matchesDirectly = menu => menu.scope === 'product_all' || menu.scope === 'products' && menu.productIds.includes(id);
|
|
184
|
+
const matchesDirectly = menu => menu.scope === 'product_all' && !menu.excludedProductIds.includes(id) || menu.scope === 'products' && menu.productIds.includes(id);
|
|
175
185
|
const isAvailable = menu => (0, _utils.getDateIsInSchedule)(currentTime, menu.scheduleIds.map(scheduleId => scheduleById.get(scheduleId)));
|
|
176
186
|
// A known valid direct relation is sufficient regardless of missing
|
|
177
|
-
// collection data on a
|
|
187
|
+
// collection data on a product appended after preparation.
|
|
178
188
|
if (menus.some(menu => matchesDirectly(menu) && isAvailable(menu))) continue;
|
|
179
189
|
if (hasCollectionMenu && !collections.has(id)) {
|
|
180
190
|
insufficient.push(id);
|
|
@@ -183,8 +193,10 @@ async function prepareScanOrderMenuAvailability({
|
|
|
183
193
|
const productCollections = collections.get(id) || [];
|
|
184
194
|
const associated = menus.filter(menu => matchesDirectly(menu) || menu.scope === 'product_collection' && menu.collectionIds.some(collectionId => productCollections.includes(collectionId)));
|
|
185
195
|
if (associated.some(isAvailable)) continue;
|
|
186
|
-
|
|
187
|
-
|
|
196
|
+
// Keep the fallback for unmapped retail prefills, but never let it
|
|
197
|
+
// override a menu's explicit product exclusion.
|
|
198
|
+
const explicitlyExcluded = menus.some(menu => menu.excludedProductIds.includes(id));
|
|
199
|
+
if (associated.length === 0 && !explicitlyExcluded && product.metadata?.item_rule_prefill === true) continue;
|
|
188
200
|
unavailable.push(id);
|
|
189
201
|
}
|
|
190
202
|
if (insufficient.length) fail(insufficient);
|