@pisell/pisellos 2.1.154 → 2.1.155
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/solution/ScanOrder/index.js +9 -5
- package/dist/solution/ScanOrder/utils.d.ts +5 -0
- package/dist/solution/ScanOrder/utils.js +55 -23
- package/lib/model/strategy/adapter/promotion/index.js +0 -49
- package/lib/solution/ScanOrder/index.js +9 -4
- package/lib/solution/ScanOrder/utils.d.ts +5 -0
- package/lib/solution/ScanOrder/utils.js +23 -0
- package/package.json +1 -1
|
@@ -32,7 +32,7 @@ import { OrderModule } from "../../modules/Order";
|
|
|
32
32
|
import { AccountHooks } from "../../modules/Account/types";
|
|
33
33
|
import { RegisterAndLoginHooks } from "../RegisterAndLogin/types";
|
|
34
34
|
import Decimal from 'decimal.js';
|
|
35
|
-
import { attachItemRuleLimitsToTopLevelProducts, buildProductKey, buildItemRuleBusinessData, collectLinkProductIdsFromReservationRules, computeResourceIsFull, createEmptySummary, getProductIdentityIndex, getSafeProductNum, hasCustomCapacityProduct, pickFirstCustomCapacityDimensionId, pickFirstCustomCapacityPaxBounds, normalizeEnabledItemRuleIds, normalizeOrderProduct, normalizeItemRuleStrategies, pickFirstDurationMinutesFromProducts, toNonNegativeInt, toPriceString, toBoolean, toPositiveString } from "./utils";
|
|
35
|
+
import { attachItemRuleLimitsToTopLevelProducts, buildProductKey, buildItemRuleBusinessData, collectLinkProductIdsFromReservationRules, computeResourceIsFull, createEmptySummary, findReservationRuleProductByResourceId, getProductIdentityIndex, getSafeProductNum, hasCustomCapacityProduct, pickFirstCustomCapacityDimensionId, pickFirstCustomCapacityPaxBounds, normalizeEnabledItemRuleIds, normalizeOrderProduct, normalizeItemRuleStrategies, pickFirstDurationMinutesFromProducts, toNonNegativeInt, toPriceString, toBoolean, toPositiveString } from "./utils";
|
|
36
36
|
import { createModule } from "../BookingByStep/types";
|
|
37
37
|
import { ProductList } from "../../modules/ProductList";
|
|
38
38
|
import { ScheduleModule } from "../../modules/Schedule";
|
|
@@ -2713,6 +2713,8 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2713
2713
|
scheduleDate,
|
|
2714
2714
|
scheduleDatetime,
|
|
2715
2715
|
loaded,
|
|
2716
|
+
matchedRuleProduct,
|
|
2717
|
+
ruleProductsForResource,
|
|
2716
2718
|
occupancyMinutes,
|
|
2717
2719
|
paxBounds,
|
|
2718
2720
|
error,
|
|
@@ -2863,14 +2865,16 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2863
2865
|
case 46:
|
|
2864
2866
|
loaded = _context37.sent;
|
|
2865
2867
|
if (Array.isArray(loaded)) {
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
+
matchedRuleProduct = findReservationRuleProductByResourceId(loaded, normalizedResourceId);
|
|
2869
|
+
ruleProductsForResource = matchedRuleProduct ? [matchedRuleProduct] : [];
|
|
2870
|
+
this.enabledReservationRuleProducts = ruleProductsForResource;
|
|
2871
|
+
occupancyMinutes = pickFirstDurationMinutesFromProducts(ruleProductsForResource);
|
|
2868
2872
|
if (occupancyMinutes !== undefined) {
|
|
2869
2873
|
tempOrder.metadata.table_occupancy_duration = occupancyMinutes;
|
|
2870
2874
|
}
|
|
2871
|
-
if (hasCustomCapacityProduct(
|
|
2875
|
+
if (hasCustomCapacityProduct(ruleProductsForResource)) {
|
|
2872
2876
|
pendingRequestEntryPax = 1;
|
|
2873
|
-
paxBounds = pickFirstCustomCapacityPaxBounds(
|
|
2877
|
+
paxBounds = pickFirstCustomCapacityPaxBounds(ruleProductsForResource);
|
|
2874
2878
|
if ((paxBounds === null || paxBounds === void 0 ? void 0 : paxBounds.min) !== undefined) pendingRequestPaxMin = paxBounds.min;
|
|
2875
2879
|
if ((paxBounds === null || paxBounds === void 0 ? void 0 : paxBounds.max) !== undefined) pendingRequestPaxMax = paxBounds.max;
|
|
2876
2880
|
}
|
|
@@ -134,6 +134,11 @@ export declare function normalizeOrderProduct(product: Partial<ScanOrderOrderPro
|
|
|
134
134
|
* 从 reservation.enabled_reservation_rules 中收集 type=link 的商品 id。
|
|
135
135
|
*/
|
|
136
136
|
export declare function collectLinkProductIdsFromReservationRules(rules: unknown): number[];
|
|
137
|
+
/**
|
|
138
|
+
* 找到第一个归属指定桌台的预约规则商品。
|
|
139
|
+
* 归属判断基于商品资源中的 default_resource / optional_resource。
|
|
140
|
+
*/
|
|
141
|
+
export declare function findReservationRuleProductByResourceId(products: ProductData[], resourceId: string | number | null | undefined): ProductData | undefined;
|
|
137
142
|
/**
|
|
138
143
|
* 返回列表中第一个带有效 duration.value(分钟)的商品时长。
|
|
139
144
|
*/
|
|
@@ -629,23 +629,55 @@ export function collectLinkProductIdsFromReservationRules(rules) {
|
|
|
629
629
|
}
|
|
630
630
|
|
|
631
631
|
/**
|
|
632
|
-
*
|
|
632
|
+
* 找到第一个归属指定桌台的预约规则商品。
|
|
633
|
+
* 归属判断基于商品资源中的 default_resource / optional_resource。
|
|
633
634
|
*/
|
|
634
|
-
export function
|
|
635
|
+
export function findReservationRuleProductByResourceId(products, resourceId) {
|
|
636
|
+
var numericResourceId = Number(resourceId);
|
|
637
|
+
if (!Number.isFinite(numericResourceId) || numericResourceId <= 0) return undefined;
|
|
635
638
|
var _iterator7 = _createForOfIteratorHelper(products),
|
|
636
639
|
_step7;
|
|
637
640
|
try {
|
|
638
641
|
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
639
|
-
var _product$
|
|
642
|
+
var _product$product_reso;
|
|
640
643
|
var product = _step7.value;
|
|
644
|
+
var resources = product === null || product === void 0 || (_product$product_reso = product.product_resource) === null || _product$product_reso === void 0 ? void 0 : _product$product_reso.resources;
|
|
645
|
+
if (!Array.isArray(resources)) continue;
|
|
646
|
+
var hasMatchedResource = resources.some(function (resource) {
|
|
647
|
+
var defaultResources = Array.isArray(resource === null || resource === void 0 ? void 0 : resource.default_resource) ? resource.default_resource : [];
|
|
648
|
+
var optionalResources = Array.isArray(resource === null || resource === void 0 ? void 0 : resource.optional_resource) ? resource.optional_resource : [];
|
|
649
|
+
return [].concat(_toConsumableArray(defaultResources), _toConsumableArray(optionalResources)).some(function (id) {
|
|
650
|
+
return Number(id) === numericResourceId;
|
|
651
|
+
});
|
|
652
|
+
});
|
|
653
|
+
if (hasMatchedResource) return product;
|
|
654
|
+
}
|
|
655
|
+
} catch (err) {
|
|
656
|
+
_iterator7.e(err);
|
|
657
|
+
} finally {
|
|
658
|
+
_iterator7.f();
|
|
659
|
+
}
|
|
660
|
+
return undefined;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* 返回列表中第一个带有效 duration.value(分钟)的商品时长。
|
|
665
|
+
*/
|
|
666
|
+
export function pickFirstDurationMinutesFromProducts(products) {
|
|
667
|
+
var _iterator8 = _createForOfIteratorHelper(products),
|
|
668
|
+
_step8;
|
|
669
|
+
try {
|
|
670
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
671
|
+
var _product$duration;
|
|
672
|
+
var product = _step8.value;
|
|
641
673
|
var value = product === null || product === void 0 || (_product$duration = product.duration) === null || _product$duration === void 0 ? void 0 : _product$duration.value;
|
|
642
674
|
var n = Number(value);
|
|
643
675
|
if (Number.isFinite(n) && n > 0) return Math.floor(n);
|
|
644
676
|
}
|
|
645
677
|
} catch (err) {
|
|
646
|
-
|
|
678
|
+
_iterator8.e(err);
|
|
647
679
|
} finally {
|
|
648
|
-
|
|
680
|
+
_iterator8.f();
|
|
649
681
|
}
|
|
650
682
|
return undefined;
|
|
651
683
|
}
|
|
@@ -675,11 +707,11 @@ export function computeResourceIsFull(params) {
|
|
|
675
707
|
if (!Number.isFinite(totalCapacity) || totalCapacity <= 0) return false;
|
|
676
708
|
var now = dayjs();
|
|
677
709
|
var occupied = 0;
|
|
678
|
-
var
|
|
679
|
-
|
|
710
|
+
var _iterator9 = _createForOfIteratorHelper(capacityList || []),
|
|
711
|
+
_step9;
|
|
680
712
|
try {
|
|
681
|
-
for (
|
|
682
|
-
var slot =
|
|
713
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
714
|
+
var slot = _step9.value;
|
|
683
715
|
var start = dayjs(slot === null || slot === void 0 ? void 0 : slot.start_at);
|
|
684
716
|
var end = dayjs(slot === null || slot === void 0 ? void 0 : slot.end_at);
|
|
685
717
|
if (!start.isValid() || !end.isValid()) continue;
|
|
@@ -689,9 +721,9 @@ export function computeResourceIsFull(params) {
|
|
|
689
721
|
}
|
|
690
722
|
}
|
|
691
723
|
} catch (err) {
|
|
692
|
-
|
|
724
|
+
_iterator9.e(err);
|
|
693
725
|
} finally {
|
|
694
|
-
|
|
726
|
+
_iterator9.f();
|
|
695
727
|
}
|
|
696
728
|
return occupied >= totalCapacity;
|
|
697
729
|
}
|
|
@@ -701,11 +733,11 @@ export function computeResourceIsFull(params) {
|
|
|
701
733
|
* 仅返回有限数字字段;若均无法解析则返回 `undefined`。
|
|
702
734
|
*/
|
|
703
735
|
export function pickFirstCustomCapacityPaxBounds(products) {
|
|
704
|
-
var
|
|
705
|
-
|
|
736
|
+
var _iterator10 = _createForOfIteratorHelper(products),
|
|
737
|
+
_step10;
|
|
706
738
|
try {
|
|
707
|
-
for (
|
|
708
|
-
var p =
|
|
739
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
740
|
+
var p = _step10.value;
|
|
709
741
|
var cap = p === null || p === void 0 ? void 0 : p.capacity;
|
|
710
742
|
if (!cap || cap.type !== 'custom') continue;
|
|
711
743
|
if (!Array.isArray(cap.custom) || cap.custom.length === 0) continue;
|
|
@@ -724,9 +756,9 @@ export function pickFirstCustomCapacityPaxBounds(products) {
|
|
|
724
756
|
if (out.min !== undefined || out.max !== undefined) return out;
|
|
725
757
|
}
|
|
726
758
|
} catch (err) {
|
|
727
|
-
|
|
759
|
+
_iterator10.e(err);
|
|
728
760
|
} finally {
|
|
729
|
-
|
|
761
|
+
_iterator10.f();
|
|
730
762
|
}
|
|
731
763
|
return undefined;
|
|
732
764
|
}
|
|
@@ -736,11 +768,11 @@ export function pickFirstCustomCapacityPaxBounds(products) {
|
|
|
736
768
|
* 无匹配时返回 `undefined`,调用方应回退为 `0`。
|
|
737
769
|
*/
|
|
738
770
|
export function pickFirstCustomCapacityDimensionId(products) {
|
|
739
|
-
var
|
|
740
|
-
|
|
771
|
+
var _iterator11 = _createForOfIteratorHelper(products),
|
|
772
|
+
_step11;
|
|
741
773
|
try {
|
|
742
|
-
for (
|
|
743
|
-
var p =
|
|
774
|
+
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
775
|
+
var p = _step11.value;
|
|
744
776
|
var cap = p === null || p === void 0 ? void 0 : p.capacity;
|
|
745
777
|
if (!cap || cap.type !== 'custom') continue;
|
|
746
778
|
if (!Array.isArray(cap.custom) || cap.custom.length === 0) continue;
|
|
@@ -756,9 +788,9 @@ export function pickFirstCustomCapacityDimensionId(products) {
|
|
|
756
788
|
}
|
|
757
789
|
}
|
|
758
790
|
} catch (err) {
|
|
759
|
-
|
|
791
|
+
_iterator11.e(err);
|
|
760
792
|
} finally {
|
|
761
|
-
|
|
793
|
+
_iterator11.f();
|
|
762
794
|
}
|
|
763
795
|
return undefined;
|
|
764
796
|
}
|
|
@@ -1,49 +0,0 @@
|
|
|
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/model/strategy/adapter/promotion/index.ts
|
|
30
|
-
var promotion_exports = {};
|
|
31
|
-
__export(promotion_exports, {
|
|
32
|
-
BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
|
|
33
|
-
PromotionAdapter: () => import_adapter.PromotionAdapter,
|
|
34
|
-
PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
|
|
35
|
-
X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
|
|
36
|
-
default: () => import_adapter2.default
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(promotion_exports);
|
|
39
|
-
var import_evaluator = require("./evaluator");
|
|
40
|
-
var import_adapter = require("./adapter");
|
|
41
|
-
var import_adapter2 = __toESM(require("./adapter"));
|
|
42
|
-
var import_examples = require("./examples");
|
|
43
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
-
0 && (module.exports = {
|
|
45
|
-
BUY_X_GET_Y_FREE_STRATEGY,
|
|
46
|
-
PromotionAdapter,
|
|
47
|
-
PromotionEvaluator,
|
|
48
|
-
X_ITEMS_FOR_Y_PRICE_STRATEGY
|
|
49
|
-
});
|
|
@@ -1693,14 +1693,19 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
|
|
|
1693
1693
|
cacheId: this.cacheId
|
|
1694
1694
|
});
|
|
1695
1695
|
if (Array.isArray(loaded)) {
|
|
1696
|
-
|
|
1697
|
-
|
|
1696
|
+
const matchedRuleProduct = (0, import_utils.findReservationRuleProductByResourceId)(
|
|
1697
|
+
loaded,
|
|
1698
|
+
normalizedResourceId
|
|
1699
|
+
);
|
|
1700
|
+
const ruleProductsForResource = matchedRuleProduct ? [matchedRuleProduct] : [];
|
|
1701
|
+
this.enabledReservationRuleProducts = ruleProductsForResource;
|
|
1702
|
+
const occupancyMinutes = (0, import_utils.pickFirstDurationMinutesFromProducts)(ruleProductsForResource);
|
|
1698
1703
|
if (occupancyMinutes !== void 0) {
|
|
1699
1704
|
tempOrder.metadata.table_occupancy_duration = occupancyMinutes;
|
|
1700
1705
|
}
|
|
1701
|
-
if ((0, import_utils.hasCustomCapacityProduct)(
|
|
1706
|
+
if ((0, import_utils.hasCustomCapacityProduct)(ruleProductsForResource)) {
|
|
1702
1707
|
pendingRequestEntryPax = 1;
|
|
1703
|
-
const paxBounds = (0, import_utils.pickFirstCustomCapacityPaxBounds)(
|
|
1708
|
+
const paxBounds = (0, import_utils.pickFirstCustomCapacityPaxBounds)(ruleProductsForResource);
|
|
1704
1709
|
if ((paxBounds == null ? void 0 : paxBounds.min) !== void 0)
|
|
1705
1710
|
pendingRequestPaxMin = paxBounds.min;
|
|
1706
1711
|
if ((paxBounds == null ? void 0 : paxBounds.max) !== void 0)
|
|
@@ -134,6 +134,11 @@ export declare function normalizeOrderProduct(product: Partial<ScanOrderOrderPro
|
|
|
134
134
|
* 从 reservation.enabled_reservation_rules 中收集 type=link 的商品 id。
|
|
135
135
|
*/
|
|
136
136
|
export declare function collectLinkProductIdsFromReservationRules(rules: unknown): number[];
|
|
137
|
+
/**
|
|
138
|
+
* 找到第一个归属指定桌台的预约规则商品。
|
|
139
|
+
* 归属判断基于商品资源中的 default_resource / optional_resource。
|
|
140
|
+
*/
|
|
141
|
+
export declare function findReservationRuleProductByResourceId(products: ProductData[], resourceId: string | number | null | undefined): ProductData | undefined;
|
|
137
142
|
/**
|
|
138
143
|
* 返回列表中第一个带有效 duration.value(分钟)的商品时长。
|
|
139
144
|
*/
|
|
@@ -39,6 +39,7 @@ __export(utils_exports, {
|
|
|
39
39
|
computeResourceIsFull: () => computeResourceIsFull,
|
|
40
40
|
createEmptySummary: () => createEmptySummary,
|
|
41
41
|
extractStrategyModelIdsFromTableConfig: () => extractStrategyModelIdsFromTableConfig,
|
|
42
|
+
findReservationRuleProductByResourceId: () => findReservationRuleProductByResourceId,
|
|
42
43
|
getProductIdentityIndex: () => getProductIdentityIndex,
|
|
43
44
|
getSafeProductNum: () => getSafeProductNum,
|
|
44
45
|
getTopLevelProductId: () => getTopLevelProductId,
|
|
@@ -510,6 +511,27 @@ function collectLinkProductIdsFromReservationRules(rules) {
|
|
|
510
511
|
}
|
|
511
512
|
return [...new Set(ids)];
|
|
512
513
|
}
|
|
514
|
+
function findReservationRuleProductByResourceId(products, resourceId) {
|
|
515
|
+
var _a;
|
|
516
|
+
const numericResourceId = Number(resourceId);
|
|
517
|
+
if (!Number.isFinite(numericResourceId) || numericResourceId <= 0)
|
|
518
|
+
return void 0;
|
|
519
|
+
for (const product of products) {
|
|
520
|
+
const resources = (_a = product == null ? void 0 : product.product_resource) == null ? void 0 : _a.resources;
|
|
521
|
+
if (!Array.isArray(resources))
|
|
522
|
+
continue;
|
|
523
|
+
const hasMatchedResource = resources.some((resource) => {
|
|
524
|
+
const defaultResources = Array.isArray(resource == null ? void 0 : resource.default_resource) ? resource.default_resource : [];
|
|
525
|
+
const optionalResources = Array.isArray(resource == null ? void 0 : resource.optional_resource) ? resource.optional_resource : [];
|
|
526
|
+
return [...defaultResources, ...optionalResources].some(
|
|
527
|
+
(id) => Number(id) === numericResourceId
|
|
528
|
+
);
|
|
529
|
+
});
|
|
530
|
+
if (hasMatchedResource)
|
|
531
|
+
return product;
|
|
532
|
+
}
|
|
533
|
+
return void 0;
|
|
534
|
+
}
|
|
513
535
|
function pickFirstDurationMinutesFromProducts(products) {
|
|
514
536
|
var _a;
|
|
515
537
|
for (const product of products) {
|
|
@@ -613,6 +635,7 @@ function pickFirstCustomCapacityDimensionId(products) {
|
|
|
613
635
|
computeResourceIsFull,
|
|
614
636
|
createEmptySummary,
|
|
615
637
|
extractStrategyModelIdsFromTableConfig,
|
|
638
|
+
findReservationRuleProductByResourceId,
|
|
616
639
|
getProductIdentityIndex,
|
|
617
640
|
getSafeProductNum,
|
|
618
641
|
getTopLevelProductId,
|