@pisell/pisellos 3.0.90 → 3.0.92
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/apis/picoding.d.ts +0 -0
- package/dist/apis/picoding.js +1 -0
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.js +1 -0
- package/dist/model/strategy/adapter/index.d.ts +7 -0
- package/dist/model/strategy/adapter/index.js +7 -0
- package/dist/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
- package/dist/model/strategy/adapter/itemRule/adapter.js +483 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.js +169 -0
- package/dist/model/strategy/adapter/itemRule/examples.d.ts +79 -0
- package/dist/model/strategy/adapter/itemRule/examples.js +382 -0
- package/dist/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/dist/model/strategy/adapter/itemRule/index.js +5 -0
- package/dist/model/strategy/adapter/itemRule/type.d.ts +225 -0
- package/dist/model/strategy/adapter/itemRule/type.js +101 -0
- package/dist/model/strategy/adapter/promotion/adapter.d.ts +66 -0
- package/dist/model/strategy/adapter/promotion/adapter.js +271 -0
- package/dist/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
- package/dist/model/strategy/adapter/promotion/evaluator.js +1206 -0
- package/dist/model/strategy/adapter/promotion/examples.d.ts +138 -0
- package/dist/model/strategy/adapter/promotion/examples.js +166 -0
- package/dist/model/strategy/adapter/promotion/index.d.ts +4 -0
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/model/strategy/adapter/promotion/type.d.ts +447 -0
- package/dist/model/strategy/adapter/promotion/type.js +209 -0
- package/dist/model/strategy/adapter/type.d.ts +28 -0
- package/dist/model/strategy/adapter/type.js +1 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.js +502 -0
- package/dist/model/strategy/adapter/walletPass/example.d.ts +4 -0
- package/dist/model/strategy/adapter/walletPass/example.js +258 -0
- package/dist/model/strategy/adapter/walletPass/index.d.ts +32 -0
- package/dist/model/strategy/adapter/walletPass/index.js +182 -0
- package/dist/model/strategy/adapter/walletPass/locales.d.ts +1 -0
- package/dist/model/strategy/adapter/walletPass/locales.js +26 -0
- package/dist/model/strategy/adapter/walletPass/type.d.ts +187 -0
- package/dist/model/strategy/adapter/walletPass/type.js +1 -0
- package/dist/model/strategy/adapter/walletPass/utils.d.ts +50 -0
- package/dist/model/strategy/adapter/walletPass/utils.js +1104 -0
- package/dist/model/strategy/engine.d.ts +106 -0
- package/dist/model/strategy/engine.js +611 -0
- package/dist/model/strategy/index.d.ts +3 -0
- package/dist/model/strategy/index.js +8 -0
- package/dist/model/strategy/strategy-example.d.ts +5 -0
- package/dist/model/strategy/strategy-example.js +331 -0
- package/dist/model/strategy/type.d.ts +228 -0
- package/dist/model/strategy/type.js +94 -0
- package/dist/modules/Cart/utils/cartProduct.js +1 -0
- package/dist/modules/Discount/index.d.ts +4 -2
- package/dist/modules/Discount/index.js +90 -3
- package/dist/modules/Discount/types.d.ts +6 -0
- package/dist/modules/OpenData/index.d.ts +24 -0
- package/dist/modules/OpenData/index.js +173 -0
- package/dist/modules/OpenData/types.d.ts +73 -0
- package/dist/modules/OpenData/types.js +1 -0
- package/dist/modules/OpenData/utils.d.ts +2 -0
- package/dist/modules/OpenData/utils.js +75 -0
- package/dist/modules/Order/index.d.ts +66 -1
- package/dist/modules/Order/index.js +884 -10
- package/dist/modules/Order/types.d.ts +174 -12
- package/dist/modules/Order/types.js +2 -0
- package/dist/modules/Order/utils.d.ts +118 -0
- package/dist/modules/Order/utils.js +586 -2
- package/dist/modules/Product/utils.js +2 -2
- package/dist/modules/ProductList/index.d.ts +3 -1
- package/dist/modules/ProductList/index.js +26 -11
- package/dist/modules/Quotation/index.d.ts +48 -0
- package/dist/modules/Quotation/index.js +248 -0
- package/dist/modules/Quotation/types.d.ts +42 -0
- package/dist/modules/Quotation/types.js +1 -0
- package/dist/modules/Rules/index.js +17 -18
- package/dist/modules/SalesSummary/index.d.ts +63 -0
- package/dist/modules/SalesSummary/index.js +174 -0
- package/dist/modules/SalesSummary/types.d.ts +60 -0
- package/dist/modules/SalesSummary/types.js +1 -0
- package/dist/modules/SalesSummary/utils.d.ts +30 -0
- package/dist/modules/SalesSummary/utils.js +480 -0
- package/dist/modules/ScanOrderLogger/index.d.ts +23 -0
- package/dist/modules/ScanOrderLogger/index.js +174 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.js +221 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
- package/dist/modules/ScanOrderLogger/types.d.ts +53 -0
- package/dist/modules/ScanOrderLogger/types.js +1 -0
- package/dist/modules/Schedule/getDateIsInSchedule.js +11 -18
- package/dist/modules/Schedule/utils.d.ts +1 -1
- package/dist/modules/Summary/utils.d.ts +3 -3
- package/dist/modules/Summary/utils.js +41 -31
- package/dist/modules/index.d.ts +4 -0
- package/dist/modules/index.js +5 -1
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/BookingByStep/types.d.ts +3 -1
- package/dist/solution/BookingByStep/types.js +5 -1
- package/dist/solution/ScanOrder/index.d.ts +158 -0
- package/dist/solution/ScanOrder/index.js +3474 -0
- package/dist/solution/ScanOrder/types.d.ts +306 -0
- package/dist/solution/ScanOrder/types.js +35 -0
- package/dist/solution/ScanOrder/utils.d.ts +172 -0
- package/dist/solution/ScanOrder/utils.js +796 -0
- package/dist/solution/ShopDiscount/index.d.ts +1 -0
- package/dist/solution/ShopDiscount/index.js +23 -18
- package/dist/solution/VenueBooking/index.d.ts +201 -0
- package/dist/solution/VenueBooking/index.js +3472 -0
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/dist/solution/VenueBooking/types.d.ts +154 -0
- package/dist/solution/VenueBooking/types.js +21 -0
- package/dist/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
- package/dist/solution/VenueBooking/utils/dateSummary.js +104 -0
- package/dist/solution/VenueBooking/utils/resource.d.ts +14 -0
- package/dist/solution/VenueBooking/utils/resource.js +131 -0
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +239 -0
- package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/dist/solution/VenueBooking/utils/timeSlot.js +453 -0
- package/dist/solution/VenueBooking/utils.d.ts +1 -0
- package/dist/solution/VenueBooking/utils.js +1 -0
- package/dist/solution/index.d.ts +2 -0
- package/dist/solution/index.js +3 -1
- package/lib/apis/picoding.d.ts +0 -0
- package/lib/apis/picoding.js +0 -0
- package/lib/model/index.d.ts +1 -0
- package/lib/model/index.js +23 -0
- package/lib/model/strategy/adapter/index.d.ts +7 -0
- package/lib/model/strategy/adapter/index.js +57 -0
- package/lib/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
- package/lib/model/strategy/adapter/itemRule/adapter.js +377 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.js +124 -0
- package/lib/model/strategy/adapter/itemRule/examples.d.ts +79 -0
- package/lib/model/strategy/adapter/itemRule/examples.js +316 -0
- package/lib/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/lib/model/strategy/adapter/itemRule/index.js +60 -0
- package/lib/model/strategy/adapter/itemRule/type.d.ts +225 -0
- package/lib/model/strategy/adapter/itemRule/type.js +46 -0
- package/lib/model/strategy/adapter/promotion/adapter.d.ts +66 -0
- package/lib/model/strategy/adapter/promotion/adapter.js +217 -0
- package/lib/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +844 -0
- package/lib/model/strategy/adapter/promotion/examples.d.ts +138 -0
- package/lib/model/strategy/adapter/promotion/examples.js +192 -0
- package/lib/model/strategy/adapter/promotion/index.d.ts +4 -0
- package/lib/model/strategy/adapter/promotion/index.js +0 -0
- package/lib/model/strategy/adapter/promotion/type.d.ts +447 -0
- package/lib/model/strategy/adapter/promotion/type.js +51 -0
- package/lib/model/strategy/adapter/type.d.ts +28 -0
- package/lib/model/strategy/adapter/type.js +17 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.js +424 -0
- package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
- package/lib/model/strategy/adapter/walletPass/example.js +207 -0
- package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
- package/lib/model/strategy/adapter/walletPass/index.js +142 -0
- package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
- package/lib/model/strategy/adapter/walletPass/locales.js +54 -0
- package/lib/model/strategy/adapter/walletPass/type.d.ts +187 -0
- package/lib/model/strategy/adapter/walletPass/type.js +17 -0
- package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
- package/lib/model/strategy/adapter/walletPass/utils.js +791 -0
- package/lib/model/strategy/engine.d.ts +106 -0
- package/lib/model/strategy/engine.js +450 -0
- package/lib/model/strategy/index.d.ts +3 -0
- package/lib/model/strategy/index.js +38 -0
- package/lib/model/strategy/strategy-example.d.ts +5 -0
- package/lib/model/strategy/strategy-example.js +318 -0
- package/lib/model/strategy/type.d.ts +228 -0
- package/lib/model/strategy/type.js +44 -0
- package/lib/modules/Cart/utils/cartProduct.js +1 -0
- package/lib/modules/Discount/index.d.ts +4 -2
- package/lib/modules/Discount/index.js +60 -2
- package/lib/modules/Discount/types.d.ts +6 -0
- package/lib/modules/OpenData/index.d.ts +24 -0
- package/lib/modules/OpenData/index.js +119 -0
- package/lib/modules/OpenData/types.d.ts +73 -0
- package/lib/modules/OpenData/types.js +17 -0
- package/lib/modules/OpenData/utils.d.ts +2 -0
- package/lib/modules/OpenData/utils.js +111 -0
- package/lib/modules/Order/index.d.ts +66 -1
- package/lib/modules/Order/index.js +525 -0
- package/lib/modules/Order/types.d.ts +174 -12
- package/lib/modules/Order/utils.d.ts +118 -0
- package/lib/modules/Order/utils.js +483 -2
- package/lib/modules/Product/utils.js +2 -2
- package/lib/modules/ProductList/index.d.ts +3 -1
- package/lib/modules/ProductList/index.js +51 -34
- package/lib/modules/Quotation/index.d.ts +48 -0
- package/lib/modules/Quotation/index.js +152 -0
- package/lib/modules/Quotation/types.d.ts +42 -0
- package/lib/modules/Quotation/types.js +17 -0
- package/lib/modules/Rules/index.js +17 -18
- package/lib/modules/SalesSummary/index.d.ts +63 -0
- package/lib/modules/SalesSummary/index.js +105 -0
- package/lib/modules/SalesSummary/types.d.ts +60 -0
- package/lib/modules/SalesSummary/types.js +17 -0
- package/lib/modules/SalesSummary/utils.d.ts +30 -0
- package/lib/modules/SalesSummary/utils.js +420 -0
- package/lib/modules/ScanOrderLogger/index.d.ts +23 -0
- package/lib/modules/ScanOrderLogger/index.js +147 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.js +157 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
- package/lib/modules/ScanOrderLogger/types.d.ts +53 -0
- package/lib/modules/ScanOrderLogger/types.js +17 -0
- package/lib/modules/Schedule/getDateIsInSchedule.js +9 -11
- package/lib/modules/Schedule/utils.d.ts +1 -1
- package/lib/modules/Summary/utils.d.ts +3 -3
- package/lib/modules/Summary/utils.js +22 -16
- package/lib/modules/index.d.ts +4 -0
- package/lib/modules/index.js +9 -1
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/BookingByStep/types.d.ts +3 -1
- package/lib/solution/BookingByStep/types.js +10 -0
- package/lib/solution/ScanOrder/index.d.ts +158 -0
- package/lib/solution/ScanOrder/index.js +2135 -0
- package/lib/solution/ScanOrder/types.d.ts +306 -0
- package/lib/solution/ScanOrder/types.js +36 -0
- package/lib/solution/ScanOrder/utils.d.ts +172 -0
- package/lib/solution/ScanOrder/utils.js +658 -0
- package/lib/solution/ShopDiscount/index.d.ts +1 -0
- package/lib/solution/ShopDiscount/index.js +4 -2
- package/lib/solution/VenueBooking/index.d.ts +201 -0
- package/lib/solution/VenueBooking/index.js +1937 -0
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/lib/solution/VenueBooking/types.d.ts +154 -0
- package/lib/solution/VenueBooking/types.js +44 -0
- package/lib/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
- package/lib/solution/VenueBooking/utils/dateSummary.js +110 -0
- package/lib/solution/VenueBooking/utils/resource.d.ts +14 -0
- package/lib/solution/VenueBooking/utils/resource.js +92 -0
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +237 -0
- package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/lib/solution/VenueBooking/utils/timeSlot.js +339 -0
- package/lib/solution/VenueBooking/utils.d.ts +1 -0
- package/lib/solution/VenueBooking/utils.js +69 -0
- package/lib/solution/index.d.ts +2 -0
- package/lib/solution/index.js +5 -1
- package/package.json +1 -1
|
@@ -0,0 +1,658 @@
|
|
|
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/ScanOrder/utils.ts
|
|
30
|
+
var utils_exports = {};
|
|
31
|
+
__export(utils_exports, {
|
|
32
|
+
aggregateItemRuleLimit: () => aggregateItemRuleLimit,
|
|
33
|
+
attachItemRuleLimitsToTopLevelProducts: () => attachItemRuleLimitsToTopLevelProducts,
|
|
34
|
+
buildItemRuleBusinessData: () => buildItemRuleBusinessData,
|
|
35
|
+
buildProductKey: () => buildProductKey,
|
|
36
|
+
buildProductLineFingerprint: () => buildProductLineFingerprint,
|
|
37
|
+
buildQuantityLimitIndex: () => buildQuantityLimitIndex,
|
|
38
|
+
collectLinkProductIdsFromReservationRules: () => collectLinkProductIdsFromReservationRules,
|
|
39
|
+
computeResourceIsFull: () => computeResourceIsFull,
|
|
40
|
+
createEmptySummary: () => createEmptySummary,
|
|
41
|
+
extractStrategyModelIdsFromTableConfig: () => extractStrategyModelIdsFromTableConfig,
|
|
42
|
+
findReservationRuleProductByResourceId: () => findReservationRuleProductByResourceId,
|
|
43
|
+
getProductIdentityIndex: () => getProductIdentityIndex,
|
|
44
|
+
getSafeProductNum: () => getSafeProductNum,
|
|
45
|
+
getTopLevelProductId: () => getTopLevelProductId,
|
|
46
|
+
getTopLevelVariantId: () => getTopLevelVariantId,
|
|
47
|
+
hasCustomCapacityProduct: () => hasCustomCapacityProduct,
|
|
48
|
+
isIdentityMatch: () => isIdentityMatch,
|
|
49
|
+
isSkuOnlyDeleteIdentity: () => isSkuOnlyDeleteIdentity,
|
|
50
|
+
normalizeEnabledItemRuleIds: () => normalizeEnabledItemRuleIds,
|
|
51
|
+
normalizeItemRuleStrategies: () => normalizeItemRuleStrategies,
|
|
52
|
+
normalizeOrderProduct: () => normalizeOrderProduct,
|
|
53
|
+
pickFirstCustomCapacityDimensionId: () => pickFirstCustomCapacityDimensionId,
|
|
54
|
+
pickFirstCustomCapacityPaxBounds: () => pickFirstCustomCapacityPaxBounds,
|
|
55
|
+
pickFirstDurationMinutesFromProducts: () => pickFirstDurationMinutesFromProducts,
|
|
56
|
+
resolveSkuMatchedQuantityLimits: () => resolveSkuMatchedQuantityLimits,
|
|
57
|
+
toBoolean: () => toBoolean,
|
|
58
|
+
toNonNegativeInt: () => toNonNegativeInt,
|
|
59
|
+
toNonNegativeNumber: () => toNonNegativeNumber,
|
|
60
|
+
toPositiveString: () => toPositiveString,
|
|
61
|
+
toPriceString: () => toPriceString
|
|
62
|
+
});
|
|
63
|
+
module.exports = __toCommonJS(utils_exports);
|
|
64
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
65
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
66
|
+
var import_utils = require("../../modules/Order/utils");
|
|
67
|
+
function createEmptySummary() {
|
|
68
|
+
return {
|
|
69
|
+
product_quantity: 0,
|
|
70
|
+
product_original_amount: "0.00",
|
|
71
|
+
product_amount: "0.00",
|
|
72
|
+
product_expect_amount: "0.00",
|
|
73
|
+
product_tax_fee: "0.00",
|
|
74
|
+
shipping_fee: "0.00",
|
|
75
|
+
shipping_tax_fee: "0.00",
|
|
76
|
+
tax_fee: "0.00",
|
|
77
|
+
surcharge_fee: "0.00",
|
|
78
|
+
discount_amount: "0.00",
|
|
79
|
+
deposit_amount: "0.00",
|
|
80
|
+
expect_amount: "0.00",
|
|
81
|
+
total_amount: "0.00",
|
|
82
|
+
amount_gap: "0.00",
|
|
83
|
+
rounding_amount: "0.00",
|
|
84
|
+
pay_service_charge_amount: "0.00"
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function getSafeProductNum(num) {
|
|
88
|
+
if (!num || Number.isNaN(num))
|
|
89
|
+
return 1;
|
|
90
|
+
if (num < 1)
|
|
91
|
+
return 1;
|
|
92
|
+
return Math.floor(num);
|
|
93
|
+
}
|
|
94
|
+
function toBoolean(value) {
|
|
95
|
+
if (typeof value === "boolean")
|
|
96
|
+
return value;
|
|
97
|
+
if (typeof value === "number")
|
|
98
|
+
return value !== 0;
|
|
99
|
+
if (typeof value === "string") {
|
|
100
|
+
const normalized = value.trim().toLowerCase();
|
|
101
|
+
return ["1", "true", "yes", "y", "on"].includes(normalized);
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
function toPositiveString(value) {
|
|
106
|
+
if (value === null || value === void 0 || value === "")
|
|
107
|
+
return void 0;
|
|
108
|
+
const normalized = String(value).trim();
|
|
109
|
+
if (!normalized || normalized === "0" || normalized.toLowerCase() === "null") {
|
|
110
|
+
return void 0;
|
|
111
|
+
}
|
|
112
|
+
return normalized;
|
|
113
|
+
}
|
|
114
|
+
function normalizeEnabledItemRuleIds(rawIds) {
|
|
115
|
+
if (!Array.isArray(rawIds))
|
|
116
|
+
return [];
|
|
117
|
+
const uniqueIds = /* @__PURE__ */ new Set();
|
|
118
|
+
for (const item of rawIds) {
|
|
119
|
+
const strategyId = Number(item);
|
|
120
|
+
if (Number.isFinite(strategyId) && strategyId > 0) {
|
|
121
|
+
uniqueIds.add(strategyId);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return Array.from(uniqueIds);
|
|
125
|
+
}
|
|
126
|
+
function extractStrategyModelIdsFromTableConfig(tableConfig) {
|
|
127
|
+
const rawIds = Array.isArray(tableConfig == null ? void 0 : tableConfig.strategy_model_ids) ? tableConfig.strategy_model_ids : [];
|
|
128
|
+
return rawIds.map((id) => Number(id)).filter((id) => Number.isFinite(id) && id > 0);
|
|
129
|
+
}
|
|
130
|
+
function normalizeItemRuleStrategies(configs) {
|
|
131
|
+
if (!Array.isArray(configs))
|
|
132
|
+
return [];
|
|
133
|
+
return configs.filter(
|
|
134
|
+
(config) => {
|
|
135
|
+
var _a;
|
|
136
|
+
return Boolean(
|
|
137
|
+
config && typeof config === "object" && ((_a = config == null ? void 0 : config.metadata) == null ? void 0 : _a.type) === "item_rule"
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
function toNonNegativeNumber(value) {
|
|
143
|
+
if (typeof value === "number") {
|
|
144
|
+
return Number.isFinite(value) && value >= 0 ? value : 0;
|
|
145
|
+
}
|
|
146
|
+
if (typeof value === "string") {
|
|
147
|
+
const parsed = Number(value);
|
|
148
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : 0;
|
|
149
|
+
}
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
function toNonNegativeInt(value) {
|
|
153
|
+
return Math.floor(toNonNegativeNumber(value));
|
|
154
|
+
}
|
|
155
|
+
function toPriceString(value, fallback = "0.00") {
|
|
156
|
+
const parsedValue = Number(value);
|
|
157
|
+
if (Number.isNaN(parsedValue))
|
|
158
|
+
return fallback;
|
|
159
|
+
return parsedValue.toFixed(2);
|
|
160
|
+
}
|
|
161
|
+
function buildProductKey(productId, productVariantId) {
|
|
162
|
+
return `${productId}_${productVariantId}`;
|
|
163
|
+
}
|
|
164
|
+
function getTopLevelProductId(product) {
|
|
165
|
+
const rawProductId = product.product_id ?? product.id;
|
|
166
|
+
const productId = Number(rawProductId);
|
|
167
|
+
if (!Number.isFinite(productId) || productId <= 0)
|
|
168
|
+
return null;
|
|
169
|
+
return productId;
|
|
170
|
+
}
|
|
171
|
+
function getTopLevelVariantId(product) {
|
|
172
|
+
const rawVariantId = product.product_variant_id ?? product.variant_id;
|
|
173
|
+
if (rawVariantId === void 0 || rawVariantId === null || rawVariantId === "") {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
const variantId = Number(rawVariantId);
|
|
177
|
+
if (!Number.isFinite(variantId) || variantId <= 0)
|
|
178
|
+
return null;
|
|
179
|
+
return variantId;
|
|
180
|
+
}
|
|
181
|
+
function buildQuantityLimitIndex(limits) {
|
|
182
|
+
const exactLimitMap = /* @__PURE__ */ new Map();
|
|
183
|
+
const productLimitMap = /* @__PURE__ */ new Map();
|
|
184
|
+
for (const limit of limits) {
|
|
185
|
+
const targets = limit.targets || [];
|
|
186
|
+
if (targets.length !== 1)
|
|
187
|
+
continue;
|
|
188
|
+
const target = targets[0];
|
|
189
|
+
const productId = Number(target.product_id);
|
|
190
|
+
if (!Number.isFinite(productId) || productId <= 0)
|
|
191
|
+
continue;
|
|
192
|
+
const variantId = Number(target.product_variant_id);
|
|
193
|
+
const hasVariant = Number.isFinite(variantId) && variantId > 0;
|
|
194
|
+
if (hasVariant) {
|
|
195
|
+
const exactKey = buildProductKey(productId, variantId);
|
|
196
|
+
const existed = exactLimitMap.get(exactKey) || [];
|
|
197
|
+
exactLimitMap.set(exactKey, [...existed, limit]);
|
|
198
|
+
} else {
|
|
199
|
+
const existed = productLimitMap.get(productId) || [];
|
|
200
|
+
productLimitMap.set(productId, [...existed, limit]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
exactLimitMap,
|
|
205
|
+
productLimitMap
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function resolveSkuMatchedQuantityLimits(params) {
|
|
209
|
+
const { productId, variantId, limitIndex } = params;
|
|
210
|
+
const exactMatched = variantId && variantId > 0 ? limitIndex.exactLimitMap.get(buildProductKey(productId, variantId)) || [] : [];
|
|
211
|
+
const productMatched = limitIndex.productLimitMap.get(productId) || [];
|
|
212
|
+
return [...exactMatched, ...productMatched];
|
|
213
|
+
}
|
|
214
|
+
function aggregateItemRuleLimit(matchedLimits) {
|
|
215
|
+
if (!matchedLimits.length)
|
|
216
|
+
return null;
|
|
217
|
+
let min;
|
|
218
|
+
let max;
|
|
219
|
+
let remainingMax;
|
|
220
|
+
let exact;
|
|
221
|
+
let mustInclude = false;
|
|
222
|
+
let maxSourceLimit;
|
|
223
|
+
let remainingMaxSourceLimit;
|
|
224
|
+
let exactSourceLimit;
|
|
225
|
+
let minSourceLimit;
|
|
226
|
+
let firstMessagedLimit;
|
|
227
|
+
for (const limit of matchedLimits) {
|
|
228
|
+
if (typeof limit.requiredMin === "number" && Number.isFinite(limit.requiredMin)) {
|
|
229
|
+
if (min === void 0 || limit.requiredMin > min) {
|
|
230
|
+
min = limit.requiredMin;
|
|
231
|
+
minSourceLimit = limit;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (typeof limit.requiredMax === "number" && Number.isFinite(limit.requiredMax)) {
|
|
235
|
+
if (max === void 0 || limit.requiredMax < max) {
|
|
236
|
+
max = limit.requiredMax;
|
|
237
|
+
maxSourceLimit = limit;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (typeof limit.remainingMax === "number" && Number.isFinite(limit.remainingMax)) {
|
|
241
|
+
if (remainingMax === void 0 || limit.remainingMax < remainingMax) {
|
|
242
|
+
remainingMax = limit.remainingMax;
|
|
243
|
+
remainingMaxSourceLimit = limit;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (typeof limit.requiredExact === "number" && Number.isFinite(limit.requiredExact)) {
|
|
247
|
+
exact = limit.requiredExact;
|
|
248
|
+
exactSourceLimit = limit;
|
|
249
|
+
}
|
|
250
|
+
mustInclude = mustInclude || Boolean(limit.mustInclude);
|
|
251
|
+
if (!firstMessagedLimit && limit.validationMessage) {
|
|
252
|
+
firstMessagedLimit = limit;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (typeof exact === "number" && Number.isFinite(exact)) {
|
|
256
|
+
min = exact;
|
|
257
|
+
max = exact;
|
|
258
|
+
}
|
|
259
|
+
const maxMessageSource = maxSourceLimit || remainingMaxSourceLimit || exactSourceLimit || firstMessagedLimit;
|
|
260
|
+
const minMessageSource = minSourceLimit || exactSourceLimit || firstMessagedLimit;
|
|
261
|
+
const maxValidationMessage = maxMessageSource == null ? void 0 : maxMessageSource.validationMessage;
|
|
262
|
+
const rawMaxValidationMessage = maxMessageSource == null ? void 0 : maxMessageSource.rawValidationMessage;
|
|
263
|
+
const minValidationMessage = minMessageSource == null ? void 0 : minMessageSource.validationMessage;
|
|
264
|
+
const rawMinValidationMessage = minMessageSource == null ? void 0 : minMessageSource.rawValidationMessage;
|
|
265
|
+
const validationMessage = maxValidationMessage ?? minValidationMessage;
|
|
266
|
+
const rawValidationMessage = rawMaxValidationMessage ?? rawMinValidationMessage;
|
|
267
|
+
return {
|
|
268
|
+
min,
|
|
269
|
+
max,
|
|
270
|
+
remainingMax,
|
|
271
|
+
exact,
|
|
272
|
+
mustInclude,
|
|
273
|
+
validationMessage,
|
|
274
|
+
rawValidationMessage,
|
|
275
|
+
maxValidationMessage,
|
|
276
|
+
rawMaxValidationMessage,
|
|
277
|
+
minValidationMessage,
|
|
278
|
+
rawMinValidationMessage
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function buildItemRuleBusinessData(params) {
|
|
282
|
+
const { tempOrder, runtimeConfig, itemRuleConfigs } = params;
|
|
283
|
+
const rawPax = runtimeConfig.pax || {};
|
|
284
|
+
const adultPax = toNonNegativeInt(rawPax.adult);
|
|
285
|
+
const childPax = toNonNegativeInt(rawPax.child);
|
|
286
|
+
const totalPax = toNonNegativeInt(rawPax.total) || adultPax + childPax || 1;
|
|
287
|
+
const cartItems = tempOrder.products.reduce((result, product) => {
|
|
288
|
+
if (typeof product.product_id !== "number")
|
|
289
|
+
return result;
|
|
290
|
+
result.push({
|
|
291
|
+
product_id: product.product_id,
|
|
292
|
+
quantity: toNonNegativeInt(product.num),
|
|
293
|
+
...typeof product.product_variant_id === "number" ? { product_variant_id: product.product_variant_id } : {}
|
|
294
|
+
});
|
|
295
|
+
return result;
|
|
296
|
+
}, []);
|
|
297
|
+
const historicalItems = Array.isArray(runtimeConfig.historicalItems) ? runtimeConfig.historicalItems.reduce((result, item) => {
|
|
298
|
+
if (typeof (item == null ? void 0 : item.product_id) !== "number")
|
|
299
|
+
return result;
|
|
300
|
+
result.push({
|
|
301
|
+
product_id: item.product_id,
|
|
302
|
+
quantity: toNonNegativeInt(item.quantity),
|
|
303
|
+
...typeof item.product_variant_id === "number" ? { product_variant_id: item.product_variant_id } : {}
|
|
304
|
+
});
|
|
305
|
+
return result;
|
|
306
|
+
}, []) : [];
|
|
307
|
+
return {
|
|
308
|
+
pax: {
|
|
309
|
+
total: totalPax,
|
|
310
|
+
adult: adultPax,
|
|
311
|
+
child: childPax
|
|
312
|
+
},
|
|
313
|
+
cartItems,
|
|
314
|
+
historicalItems,
|
|
315
|
+
serviceType: runtimeConfig.serviceType || "dine-in",
|
|
316
|
+
submissionIndex: typeof runtimeConfig.submissionIndex === "number" ? toNonNegativeInt(runtimeConfig.submissionIndex) : tempOrder.order_id ? 1 : 0,
|
|
317
|
+
custom: runtimeConfig.custom || {},
|
|
318
|
+
strategyConfigs: itemRuleConfigs
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function attachItemRuleLimitsToTopLevelProducts(productList, limits) {
|
|
322
|
+
if (!Array.isArray(productList))
|
|
323
|
+
return productList;
|
|
324
|
+
const limitIndex = buildQuantityLimitIndex(limits || []);
|
|
325
|
+
for (const item of productList) {
|
|
326
|
+
if (!item || typeof item !== "object")
|
|
327
|
+
continue;
|
|
328
|
+
const productItem = item;
|
|
329
|
+
const productId = getTopLevelProductId(productItem);
|
|
330
|
+
if (productId === null)
|
|
331
|
+
continue;
|
|
332
|
+
const variantId = getTopLevelVariantId(productItem);
|
|
333
|
+
const matchedLimits = limits.length ? resolveSkuMatchedQuantityLimits({
|
|
334
|
+
productId,
|
|
335
|
+
variantId,
|
|
336
|
+
limitIndex
|
|
337
|
+
}) : [];
|
|
338
|
+
const aggregatedLimit = aggregateItemRuleLimit(matchedLimits);
|
|
339
|
+
if (aggregatedLimit) {
|
|
340
|
+
productItem.item_rule_limit = aggregatedLimit;
|
|
341
|
+
} else if ("item_rule_limit" in productItem) {
|
|
342
|
+
delete productItem.item_rule_limit;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return productList;
|
|
346
|
+
}
|
|
347
|
+
function buildProductLineFingerprint(productOptionItem, productBundle) {
|
|
348
|
+
const optArr = Array.isArray(productOptionItem) ? productOptionItem : [];
|
|
349
|
+
const normalizedOpts = optArr.map((item) => ({
|
|
350
|
+
product_option_item_id: Number(item == null ? void 0 : item.product_option_item_id) || 0,
|
|
351
|
+
option_group_id: Number(item == null ? void 0 : item.option_group_id) || 0,
|
|
352
|
+
num: typeof (item == null ? void 0 : item.num) === "number" && !Number.isNaN(item.num) ? Math.max(1, Math.floor(item.num)) : 1,
|
|
353
|
+
price: String((item == null ? void 0 : item.price) ?? "")
|
|
354
|
+
})).sort((p, q) => {
|
|
355
|
+
if (p.product_option_item_id !== q.product_option_item_id) {
|
|
356
|
+
return p.product_option_item_id - q.product_option_item_id;
|
|
357
|
+
}
|
|
358
|
+
if (p.option_group_id !== q.option_group_id)
|
|
359
|
+
return p.option_group_id - q.option_group_id;
|
|
360
|
+
if (p.num !== q.num)
|
|
361
|
+
return p.num - q.num;
|
|
362
|
+
return p.price.localeCompare(q.price);
|
|
363
|
+
});
|
|
364
|
+
const bundleArr = Array.isArray(productBundle) ? productBundle : [];
|
|
365
|
+
const normalizedBundles = bundleArr.map((item) => ({
|
|
366
|
+
bundle_id: Number((item == null ? void 0 : item.bundle_id) ?? (item == null ? void 0 : item.id) ?? 0) || 0,
|
|
367
|
+
product_id: Number(item == null ? void 0 : item.product_id) || 0,
|
|
368
|
+
num: typeof (item == null ? void 0 : item.num) === "number" && !Number.isNaN(item.num) ? Math.max(1, Math.floor(item.num)) : 1
|
|
369
|
+
})).sort((p, q) => {
|
|
370
|
+
if (p.bundle_id !== q.bundle_id)
|
|
371
|
+
return p.bundle_id - q.bundle_id;
|
|
372
|
+
if (p.product_id !== q.product_id)
|
|
373
|
+
return p.product_id - q.product_id;
|
|
374
|
+
return p.num - q.num;
|
|
375
|
+
});
|
|
376
|
+
return JSON.stringify([normalizedOpts, normalizedBundles]);
|
|
377
|
+
}
|
|
378
|
+
function isSkuOnlyDeleteIdentity(x) {
|
|
379
|
+
if (x.identity_key)
|
|
380
|
+
return false;
|
|
381
|
+
return !("product_option_item" in x) && !("product_bundle" in x);
|
|
382
|
+
}
|
|
383
|
+
function fingerprintForIdentityWithOptionKeys(x) {
|
|
384
|
+
const row = x;
|
|
385
|
+
const opts = "product_option_item" in row ? Array.isArray(row.product_option_item) ? row.product_option_item : [] : [];
|
|
386
|
+
const buds = "product_bundle" in row ? Array.isArray(row.product_bundle) ? row.product_bundle : [] : [];
|
|
387
|
+
return buildProductLineFingerprint(opts, buds);
|
|
388
|
+
}
|
|
389
|
+
function isIdentityMatch(a, b) {
|
|
390
|
+
if (a.product_id !== b.product_id || a.product_variant_id !== b.product_variant_id)
|
|
391
|
+
return false;
|
|
392
|
+
const aHasKey = typeof a.identity_key === "string" && a.identity_key.length > 0;
|
|
393
|
+
const bHasKey = typeof b.identity_key === "string" && b.identity_key.length > 0;
|
|
394
|
+
if (aHasKey && bHasKey)
|
|
395
|
+
return a.identity_key === b.identity_key;
|
|
396
|
+
if (isSkuOnlyDeleteIdentity(a) || isSkuOnlyDeleteIdentity(b))
|
|
397
|
+
return true;
|
|
398
|
+
return fingerprintForIdentityWithOptionKeys(a) === fingerprintForIdentityWithOptionKeys(b);
|
|
399
|
+
}
|
|
400
|
+
function getProductIdentityIndex(products, identity) {
|
|
401
|
+
return products.findIndex((item) => isIdentityMatch(item, identity));
|
|
402
|
+
}
|
|
403
|
+
function normalizeOrderProduct(product) {
|
|
404
|
+
var _a, _b;
|
|
405
|
+
const metadata = { ...product.metadata || {} };
|
|
406
|
+
const resolvedIdentityKey = product.identity_key && String(product.identity_key).length > 0 ? String(product.identity_key) : (0, import_utils.createUuidV4)();
|
|
407
|
+
if (!metadata.unique_identification_number) {
|
|
408
|
+
metadata.unique_identification_number = resolvedIdentityKey;
|
|
409
|
+
}
|
|
410
|
+
const normalizedBundle = (product.product_bundle || []).map((item) => ({
|
|
411
|
+
...item,
|
|
412
|
+
bundle_selling_price: item.bundle_selling_price ?? item.price ?? "0.00"
|
|
413
|
+
// custom_price: item.custom_price ?? item.bundle_selling_price ?? item.price ?? '0.00',
|
|
414
|
+
}));
|
|
415
|
+
const normalizedOptions = product.product_option_item || [];
|
|
416
|
+
const optionSum = (0, import_utils.sumOptionUnitPrice)(normalizedOptions);
|
|
417
|
+
const isV2 = metadata.price_schema_version === 2 || metadata.price_schema_version === "2";
|
|
418
|
+
const variantId = Number(product.product_variant_id || 0);
|
|
419
|
+
const variantList = variantId ? (_a = metadata == null ? void 0 : metadata.origin) == null ? void 0 : _a.variant : null;
|
|
420
|
+
const variantPrice = Array.isArray(variantList) ? (_b = variantList.find((v) => Number(v == null ? void 0 : v.id) === variantId)) == null ? void 0 : _b.price : void 0;
|
|
421
|
+
const resolvedSource = (() => {
|
|
422
|
+
var _a2, _b2;
|
|
423
|
+
if (metadata.source_product_price !== void 0) {
|
|
424
|
+
return String(metadata.source_product_price);
|
|
425
|
+
}
|
|
426
|
+
if (variantPrice !== void 0 && variantPrice !== null) {
|
|
427
|
+
return String(variantPrice);
|
|
428
|
+
}
|
|
429
|
+
const originPrice = (_a2 = product._origin) == null ? void 0 : _a2.price;
|
|
430
|
+
if (originPrice !== void 0 && originPrice !== null) {
|
|
431
|
+
return String(originPrice);
|
|
432
|
+
}
|
|
433
|
+
const originBasePrice = (_b2 = product._origin) == null ? void 0 : _b2.base_price;
|
|
434
|
+
if (originBasePrice !== void 0 && originBasePrice !== null) {
|
|
435
|
+
return String(originBasePrice);
|
|
436
|
+
}
|
|
437
|
+
if (!isV2 && metadata.main_product_original_price !== void 0) {
|
|
438
|
+
return String(metadata.main_product_original_price);
|
|
439
|
+
}
|
|
440
|
+
return product.original_price ?? product.selling_price ?? "0.00";
|
|
441
|
+
})();
|
|
442
|
+
const mainOriginalDec = new import_decimal.default(Number(resolvedSource) || 0).plus(optionSum);
|
|
443
|
+
const mainOriginalStr = mainOriginalDec.toDecimalPlaces(2).toFixed(2);
|
|
444
|
+
let mainSellingDec;
|
|
445
|
+
if (isV2 && metadata.main_product_selling_price != null) {
|
|
446
|
+
mainSellingDec = new import_decimal.default(Number(metadata.main_product_selling_price) || 0);
|
|
447
|
+
} else if (metadata.main_product_selling_price != null && metadata.main_product_original_price != null) {
|
|
448
|
+
const legacyOriginal = new import_decimal.default(Number(metadata.main_product_original_price) || 0);
|
|
449
|
+
const legacySelling = new import_decimal.default(Number(metadata.main_product_selling_price) || 0);
|
|
450
|
+
const legacyDiscount = legacyOriginal.minus(legacySelling);
|
|
451
|
+
mainSellingDec = mainOriginalDec.minus(legacyDiscount);
|
|
452
|
+
} else if (product.original_price != null && product.selling_price != null && new import_decimal.default(Number(product.original_price) || 0).greaterThan(
|
|
453
|
+
new import_decimal.default(Number(product.selling_price) || 0)
|
|
454
|
+
)) {
|
|
455
|
+
const topOriginal = new import_decimal.default(Number(product.original_price) || 0);
|
|
456
|
+
const topSelling = new import_decimal.default(Number(product.selling_price) || 0);
|
|
457
|
+
const legacyDiscount = topOriginal.minus(topSelling);
|
|
458
|
+
mainSellingDec = mainOriginalDec.minus(legacyDiscount);
|
|
459
|
+
} else {
|
|
460
|
+
mainSellingDec = mainOriginalDec;
|
|
461
|
+
}
|
|
462
|
+
const mainSellingStr = mainSellingDec.toDecimalPlaces(2).toFixed(2);
|
|
463
|
+
metadata.source_product_price = resolvedSource;
|
|
464
|
+
metadata.main_product_original_price = mainOriginalStr;
|
|
465
|
+
metadata.main_product_selling_price = mainSellingStr;
|
|
466
|
+
metadata.price_schema_version = 2;
|
|
467
|
+
const composedSellingPrice = (0, import_utils.composeLinePrice)({
|
|
468
|
+
mainPrice: mainSellingStr,
|
|
469
|
+
bundle: normalizedBundle
|
|
470
|
+
});
|
|
471
|
+
const composedOriginalPrice = (0, import_utils.composeLinePrice)({
|
|
472
|
+
mainPrice: mainOriginalStr,
|
|
473
|
+
bundle: normalizedBundle,
|
|
474
|
+
useOriginalBundle: true
|
|
475
|
+
});
|
|
476
|
+
return {
|
|
477
|
+
order_detail_id: product.order_detail_id || null,
|
|
478
|
+
product_id: product.product_id,
|
|
479
|
+
num: getSafeProductNum(product.num),
|
|
480
|
+
product_variant_id: product.product_variant_id,
|
|
481
|
+
identity_key: resolvedIdentityKey,
|
|
482
|
+
product_option_item: normalizedOptions,
|
|
483
|
+
selling_price: composedSellingPrice,
|
|
484
|
+
original_price: composedOriginalPrice,
|
|
485
|
+
tax_fee: product.tax_fee || "0.00",
|
|
486
|
+
is_charge_tax: product.is_charge_tax ?? 0,
|
|
487
|
+
discount_list: product.discount_list || [],
|
|
488
|
+
product_bundle: normalizedBundle,
|
|
489
|
+
metadata,
|
|
490
|
+
note: product.note != null ? String(product.note) : "",
|
|
491
|
+
_origin: product._origin
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
function collectLinkProductIdsFromReservationRules(rules) {
|
|
495
|
+
if (!Array.isArray(rules))
|
|
496
|
+
return [];
|
|
497
|
+
const ids = [];
|
|
498
|
+
for (const entry of rules) {
|
|
499
|
+
if (!entry || typeof entry !== "object")
|
|
500
|
+
continue;
|
|
501
|
+
const rec = entry;
|
|
502
|
+
if (rec.type !== "link")
|
|
503
|
+
continue;
|
|
504
|
+
if (!Array.isArray(rec.value))
|
|
505
|
+
continue;
|
|
506
|
+
for (const v of rec.value) {
|
|
507
|
+
const n = Number(v);
|
|
508
|
+
if (Number.isFinite(n) && n > 0)
|
|
509
|
+
ids.push(Math.floor(n));
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
return [...new Set(ids)];
|
|
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
|
+
}
|
|
535
|
+
function pickFirstDurationMinutesFromProducts(products) {
|
|
536
|
+
var _a;
|
|
537
|
+
for (const product of products) {
|
|
538
|
+
const value = (_a = product == null ? void 0 : product.duration) == null ? void 0 : _a.value;
|
|
539
|
+
const n = Number(value);
|
|
540
|
+
if (Number.isFinite(n) && n > 0)
|
|
541
|
+
return Math.floor(n);
|
|
542
|
+
}
|
|
543
|
+
return void 0;
|
|
544
|
+
}
|
|
545
|
+
function hasCustomCapacityProduct(products) {
|
|
546
|
+
return products.some((p) => {
|
|
547
|
+
var _a;
|
|
548
|
+
return ((_a = p == null ? void 0 : p.capacity) == null ? void 0 : _a.type) === "custom";
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
function computeResourceIsFull(params) {
|
|
552
|
+
const { resourceSelectType, lastOrderId, capacityList, capacity } = params;
|
|
553
|
+
if (resourceSelectType === "single")
|
|
554
|
+
return Boolean(lastOrderId);
|
|
555
|
+
if (resourceSelectType !== "multiple")
|
|
556
|
+
return false;
|
|
557
|
+
const totalCapacity = Number(capacity);
|
|
558
|
+
if (!Number.isFinite(totalCapacity) || totalCapacity <= 0)
|
|
559
|
+
return false;
|
|
560
|
+
const now = (0, import_dayjs.default)();
|
|
561
|
+
let occupied = 0;
|
|
562
|
+
for (const slot of capacityList || []) {
|
|
563
|
+
const start = (0, import_dayjs.default)(slot == null ? void 0 : slot.start_at);
|
|
564
|
+
const end = (0, import_dayjs.default)(slot == null ? void 0 : slot.end_at);
|
|
565
|
+
if (!start.isValid() || !end.isValid())
|
|
566
|
+
continue;
|
|
567
|
+
if ((now.isAfter(start) || now.isSame(start)) && (now.isBefore(end) || now.isSame(end))) {
|
|
568
|
+
const pax = Number(slot == null ? void 0 : slot.pax);
|
|
569
|
+
if (Number.isFinite(pax) && pax > 0)
|
|
570
|
+
occupied += pax;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return occupied >= totalCapacity;
|
|
574
|
+
}
|
|
575
|
+
function pickFirstCustomCapacityPaxBounds(products) {
|
|
576
|
+
for (const p of products) {
|
|
577
|
+
const cap = p == null ? void 0 : p.capacity;
|
|
578
|
+
if (!cap || cap.type !== "custom")
|
|
579
|
+
continue;
|
|
580
|
+
if (!Array.isArray(cap.custom) || cap.custom.length === 0)
|
|
581
|
+
continue;
|
|
582
|
+
const row = cap.custom[0];
|
|
583
|
+
if (!row || typeof row !== "object")
|
|
584
|
+
continue;
|
|
585
|
+
const raw = row;
|
|
586
|
+
const out = {};
|
|
587
|
+
if (raw.min !== null && raw.min !== void 0 && raw.min !== "") {
|
|
588
|
+
const min = Number(raw.min);
|
|
589
|
+
if (Number.isFinite(min))
|
|
590
|
+
out.min = min;
|
|
591
|
+
}
|
|
592
|
+
if (raw.max !== null && raw.max !== void 0 && raw.max !== "") {
|
|
593
|
+
const max = Number(raw.max);
|
|
594
|
+
if (Number.isFinite(max))
|
|
595
|
+
out.max = max;
|
|
596
|
+
}
|
|
597
|
+
if (out.min !== void 0 || out.max !== void 0)
|
|
598
|
+
return out;
|
|
599
|
+
}
|
|
600
|
+
return void 0;
|
|
601
|
+
}
|
|
602
|
+
function pickFirstCustomCapacityDimensionId(products) {
|
|
603
|
+
for (const p of products) {
|
|
604
|
+
const cap = p == null ? void 0 : p.capacity;
|
|
605
|
+
if (!cap || cap.type !== "custom")
|
|
606
|
+
continue;
|
|
607
|
+
if (!Array.isArray(cap.custom) || cap.custom.length === 0)
|
|
608
|
+
continue;
|
|
609
|
+
const row = cap.custom[0];
|
|
610
|
+
if (!row || typeof row !== "object")
|
|
611
|
+
continue;
|
|
612
|
+
const id = row.id;
|
|
613
|
+
if (id === null || id === void 0 || id === "")
|
|
614
|
+
continue;
|
|
615
|
+
if (typeof id === "number" && Number.isFinite(id))
|
|
616
|
+
return id;
|
|
617
|
+
if (typeof id === "string") {
|
|
618
|
+
const trimmed = id.trim();
|
|
619
|
+
if (!trimmed)
|
|
620
|
+
continue;
|
|
621
|
+
return trimmed;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return void 0;
|
|
625
|
+
}
|
|
626
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
627
|
+
0 && (module.exports = {
|
|
628
|
+
aggregateItemRuleLimit,
|
|
629
|
+
attachItemRuleLimitsToTopLevelProducts,
|
|
630
|
+
buildItemRuleBusinessData,
|
|
631
|
+
buildProductKey,
|
|
632
|
+
buildProductLineFingerprint,
|
|
633
|
+
buildQuantityLimitIndex,
|
|
634
|
+
collectLinkProductIdsFromReservationRules,
|
|
635
|
+
computeResourceIsFull,
|
|
636
|
+
createEmptySummary,
|
|
637
|
+
extractStrategyModelIdsFromTableConfig,
|
|
638
|
+
findReservationRuleProductByResourceId,
|
|
639
|
+
getProductIdentityIndex,
|
|
640
|
+
getSafeProductNum,
|
|
641
|
+
getTopLevelProductId,
|
|
642
|
+
getTopLevelVariantId,
|
|
643
|
+
hasCustomCapacityProduct,
|
|
644
|
+
isIdentityMatch,
|
|
645
|
+
isSkuOnlyDeleteIdentity,
|
|
646
|
+
normalizeEnabledItemRuleIds,
|
|
647
|
+
normalizeItemRuleStrategies,
|
|
648
|
+
normalizeOrderProduct,
|
|
649
|
+
pickFirstCustomCapacityDimensionId,
|
|
650
|
+
pickFirstCustomCapacityPaxBounds,
|
|
651
|
+
pickFirstDurationMinutesFromProducts,
|
|
652
|
+
resolveSkuMatchedQuantityLimits,
|
|
653
|
+
toBoolean,
|
|
654
|
+
toNonNegativeInt,
|
|
655
|
+
toNonNegativeNumber,
|
|
656
|
+
toPositiveString,
|
|
657
|
+
toPriceString
|
|
658
|
+
});
|
|
@@ -50,6 +50,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
50
50
|
discountList: Discount[];
|
|
51
51
|
type: "server" | "clientCalc";
|
|
52
52
|
unavailableReason?: UnavailableReason;
|
|
53
|
+
unavailableReasonKey?: string | null;
|
|
53
54
|
}>;
|
|
54
55
|
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|
|
55
56
|
private getCustomer;
|
|
@@ -256,7 +256,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
256
256
|
async scanCode(code, customerId) {
|
|
257
257
|
var _a, _b, _c;
|
|
258
258
|
try {
|
|
259
|
-
const
|
|
259
|
+
const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, customerId)) || { discountList: [], unavailableReasonKey: null };
|
|
260
|
+
const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
|
|
260
261
|
const rulesModule = this.store.rules;
|
|
261
262
|
if (!rulesModule) {
|
|
262
263
|
return {
|
|
@@ -272,7 +273,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
272
273
|
type: "server",
|
|
273
274
|
isAvailable: false,
|
|
274
275
|
productList: this.store.productList || [],
|
|
275
|
-
discountList: this.getDiscountList()
|
|
276
|
+
discountList: this.getDiscountList(),
|
|
277
|
+
unavailableReasonKey
|
|
276
278
|
};
|
|
277
279
|
}
|
|
278
280
|
const withScanList = resultDiscountList.map((item) => {
|