@pisell/pisellos 2.1.174 → 2.1.176
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 +0 -9
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
- package/dist/model/strategy/adapter/walletPass/evaluator.js +2 -4
- package/dist/modules/Discount/index.d.ts +3 -6
- package/dist/modules/Discount/index.js +23 -125
- package/dist/modules/Discount/types.d.ts +5 -34
- package/dist/modules/OpenData/types.d.ts +1 -0
- package/dist/modules/ProductList/index.js +13 -6
- package/dist/modules/Rules/index.d.ts +2 -12
- package/dist/modules/Rules/index.js +113 -377
- package/dist/modules/Rules/types.d.ts +2 -2
- package/dist/plugins/window.d.ts +0 -2
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/ScanOrder/index.d.ts +7 -5
- package/dist/solution/ScanOrder/index.js +123 -31
- package/dist/solution/ScanOrder/resourceSchedule.d.ts +12 -0
- package/dist/solution/ScanOrder/resourceSchedule.js +300 -0
- package/dist/solution/ScanOrder/types.d.ts +9 -1
- package/dist/solution/ShopDiscount/index.d.ts +0 -3
- package/dist/solution/ShopDiscount/index.js +78 -161
- package/dist/solution/ShopDiscount/utils.d.ts +0 -1
- package/dist/solution/ShopDiscount/utils.js +1 -40
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
- package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -4
- package/lib/modules/Discount/index.d.ts +3 -6
- package/lib/modules/Discount/index.js +16 -66
- package/lib/modules/Discount/types.d.ts +5 -34
- package/lib/modules/OpenData/types.d.ts +1 -0
- package/lib/modules/ProductList/index.js +8 -1
- package/lib/modules/Rules/index.d.ts +2 -12
- package/lib/modules/Rules/index.js +69 -303
- package/lib/modules/Rules/types.d.ts +2 -2
- package/lib/plugins/window.d.ts +0 -2
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/ScanOrder/index.d.ts +7 -5
- package/lib/solution/ScanOrder/index.js +90 -12
- package/lib/solution/ScanOrder/resourceSchedule.d.ts +12 -0
- package/lib/solution/ScanOrder/resourceSchedule.js +272 -0
- package/lib/solution/ScanOrder/types.d.ts +9 -1
- package/lib/solution/ShopDiscount/index.d.ts +0 -3
- package/lib/solution/ShopDiscount/index.js +28 -78
- package/lib/solution/ShopDiscount/utils.d.ts +0 -1
- package/lib/solution/ShopDiscount/utils.js +1 -42
- package/package.json +1 -1
- package/dist/modules/Discount/availability.d.ts +0 -7
- package/dist/modules/Discount/availability.js +0 -52
- package/dist/modules/Discount/entitlementPass.d.ts +0 -34
- package/dist/modules/Discount/entitlementPass.js +0 -147
- package/dist/modules/Discount/entitlementState.d.ts +0 -8
- package/dist/modules/Discount/entitlementState.js +0 -205
- package/dist/modules/Rules/entitlementLines.d.ts +0 -8
- package/dist/modules/Rules/entitlementLines.js +0 -157
- package/lib/modules/Discount/availability.d.ts +0 -7
- package/lib/modules/Discount/availability.js +0 -91
- package/lib/modules/Discount/entitlementPass.d.ts +0 -34
- package/lib/modules/Discount/entitlementPass.js +0 -184
- package/lib/modules/Discount/entitlementState.d.ts +0 -8
- package/lib/modules/Discount/entitlementState.js +0 -206
- package/lib/modules/Rules/entitlementLines.d.ts +0 -8
- package/lib/modules/Rules/entitlementLines.js +0 -158
|
@@ -39,28 +39,13 @@ var import_utils2 = require("../Cart/utils");
|
|
|
39
39
|
var import_decimal = __toESM(require("decimal.js"));
|
|
40
40
|
var import_lodash_es = require("lodash-es");
|
|
41
41
|
var import_dayjs = __toESM(require("dayjs"));
|
|
42
|
-
var import_evaluator = require("../../model/strategy/adapter/walletPass/evaluator");
|
|
43
|
-
var import_entitlementPass = require("../Discount/entitlementPass");
|
|
44
|
-
var import_availability = require("../Discount/availability");
|
|
45
|
-
var import_entitlementState = require("../Discount/entitlementState");
|
|
46
|
-
var import_utils3 = require("../../solution/ShopDiscount/utils");
|
|
47
|
-
var import_lodash_es2 = require("lodash-es");
|
|
48
|
-
var import_entitlementLines = require("./entitlementLines");
|
|
49
42
|
var RulesModule = class extends import_BaseModule.BaseModule {
|
|
50
43
|
constructor(name, version) {
|
|
51
44
|
super(name, version);
|
|
52
45
|
this.defaultName = "rules";
|
|
53
46
|
this.defaultVersion = "1.0.0";
|
|
54
|
-
this.entitlementPassEnabled = false;
|
|
55
47
|
this.hooks = {};
|
|
56
48
|
}
|
|
57
|
-
setEntitlementPassEnabled(enabled) {
|
|
58
|
-
this.entitlementPassEnabled = enabled;
|
|
59
|
-
}
|
|
60
|
-
getWalletPassEvaluator() {
|
|
61
|
-
var _a, _b, _c;
|
|
62
|
-
return ((_c = (_b = (_a = this.core) == null ? void 0 : _a.getPlugin("window")) == null ? void 0 : _b.getWalletPassEvaluator) == null ? void 0 : _c.call(_b)) || (this.defaultWalletPassEvaluator ?? (this.defaultWalletPassEvaluator = new import_evaluator.WalletPassEvaluator()));
|
|
63
|
-
}
|
|
64
49
|
async initialize(core, options) {
|
|
65
50
|
this.core = core;
|
|
66
51
|
this.hooks = options == null ? void 0 : options.hooks;
|
|
@@ -73,58 +58,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
73
58
|
getRulesList() {
|
|
74
59
|
return this.store.rulesList;
|
|
75
60
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
new Set(
|
|
80
|
-
records.map((record) => {
|
|
81
|
-
if (record && typeof record === "object") {
|
|
82
|
-
return record.form_record_id;
|
|
83
|
-
}
|
|
84
|
-
return record;
|
|
85
|
-
}).filter(
|
|
86
|
-
(record) => record !== void 0 && record !== null && record !== "" && record !== 0 && record !== "0"
|
|
87
|
-
).map(String)
|
|
88
|
-
)
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* 商品未开启 Holder 选择时跳过匹配;已开启时,特定 form Holder 卡
|
|
93
|
-
* 只适用于同一 Holder Record,是否必填不影响匹配规则。
|
|
94
|
-
*/
|
|
95
|
-
checkHolderMatch(discount, product, holderSource, holders) {
|
|
96
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
61
|
+
// 商品不需要holder,则不需要判断,直接返回true,商品需要holder但是还没填写,那么暂时不使用带有holder的券,直到填写才去匹配
|
|
62
|
+
checkHolderMatch(discount, product, holders) {
|
|
63
|
+
var _a;
|
|
97
64
|
if (((_a = discount.holder) == null ? void 0 : _a.holder_type) !== "form")
|
|
98
65
|
return true;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const holder = holders == null ? void 0 : holders[0];
|
|
103
|
-
const orderHolderId = holder && typeof holder === "object" ? holder.form_record_id : holder;
|
|
104
|
-
const productHolderId = Array.isArray(product.holder_id) ? product.holder_id[0] : product.holder_id;
|
|
105
|
-
if (!orderHolderId && !productHolderId)
|
|
106
|
-
return false;
|
|
107
|
-
return (productHolderId || orderHolderId) === discount.holder.holder_id;
|
|
108
|
-
}
|
|
109
|
-
const holderConfig = (holderSource == null ? void 0 : holderSource.holder_config) ?? ((_b = holderSource == null ? void 0 : holderSource.metadata) == null ? void 0 : _b.holder_config) ?? ((_c = holderSource == null ? void 0 : holderSource.origin) == null ? void 0 : _c.holder_config) ?? ((_e = (_d = holderSource == null ? void 0 : holderSource.metadata) == null ? void 0 : _d.origin) == null ? void 0 : _e.holder_config) ?? ((_f = holderSource == null ? void 0 : holderSource._origin) == null ? void 0 : _f.holder_config) ?? ((_h = (_g = holderSource == null ? void 0 : holderSource._origin) == null ? void 0 : _g.product) == null ? void 0 : _h.holder_config) ?? ((_j = (_i = holderSource == null ? void 0 : holderSource._originData) == null ? void 0 : _i.product) == null ? void 0 : _j.holder_config) ?? ((_k = holderSource == null ? void 0 : holderSource._productInit) == null ? void 0 : _k.holder_config) ?? ((_l = holderSource == null ? void 0 : holderSource._productOrigin) == null ? void 0 : _l.holder_config) ?? ((_m = holderSource == null ? void 0 : holderSource._extend) == null ? void 0 : _m.holder_config) ?? ((_o = (_n = holderSource == null ? void 0 : holderSource._extend) == null ? void 0 : _n.product) == null ? void 0 : _o.holder_config) ?? ((_r = (_q = (_p = holderSource == null ? void 0 : holderSource._extend) == null ? void 0 : _p.product) == null ? void 0 : _q.metadata) == null ? void 0 : _r.holder_config);
|
|
110
|
-
const holderStatus = holderConfig == null ? void 0 : holderConfig.status;
|
|
111
|
-
const holderEnabled = holderStatus == null || holderStatus === "" || holderStatus === true || ["enable", "1"].includes(String(holderStatus).trim().toLowerCase());
|
|
112
|
-
if (!holderEnabled || !(holderConfig == null ? void 0 : holderConfig.resource_id)) {
|
|
66
|
+
const orderHolderId = Array.isArray(holders) && holders.length > 0 ? holders[0].form_record_id : void 0;
|
|
67
|
+
const productHolderId = Array.isArray(product.holder_id) ? product.holder_id[0] : product.holder_id;
|
|
68
|
+
if (!product.isNeedHolder)
|
|
113
69
|
return true;
|
|
114
|
-
|
|
115
|
-
const discountHolderIds = this.normalizeHolderRecordIds(
|
|
116
|
-
discount.holder.holder_id
|
|
117
|
-
);
|
|
118
|
-
if (!discountHolderIds.length)
|
|
70
|
+
if (!orderHolderId && !productHolderId)
|
|
119
71
|
return false;
|
|
120
|
-
|
|
121
|
-
const candidateHolderIds = productHolderIds.length || Array.isArray(product.holder_id) ? productHolderIds : this.normalizeHolderRecordIds(holders);
|
|
122
|
-
if (!candidateHolderIds.length)
|
|
123
|
-
return false;
|
|
124
|
-
const discountHolderIdSet = new Set(discountHolderIds);
|
|
125
|
-
return candidateHolderIds.every(
|
|
126
|
-
(holderId) => discountHolderIdSet.has(holderId)
|
|
127
|
-
);
|
|
72
|
+
return (productHolderId || orderHolderId) === discount.holder.holder_id;
|
|
128
73
|
}
|
|
129
74
|
// 判断discountList 是否可以对当前productList生效
|
|
130
75
|
isDiscountListAvailable({
|
|
@@ -141,7 +86,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
141
86
|
productList
|
|
142
87
|
};
|
|
143
88
|
}
|
|
144
|
-
if (
|
|
89
|
+
if (productList.every((item) => {
|
|
145
90
|
var _a;
|
|
146
91
|
const product = this.hooks.getProduct(item);
|
|
147
92
|
return product.booking_id && (((_a = product.discount_list) == null ? void 0 : _a.length) || product.total == 0);
|
|
@@ -157,25 +102,21 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
157
102
|
(discount) => !discount.isEditMode && (discount.tag !== "good_pass" || discount.isScan)
|
|
158
103
|
);
|
|
159
104
|
const mergedDiscountList = (0, import_utils.uniqueById)([
|
|
160
|
-
...newDiscountList.filter(import_entitlementPass.isEntitlementPass),
|
|
161
105
|
...filteredOldDiscountList,
|
|
162
106
|
...newDiscountList
|
|
163
107
|
]);
|
|
164
108
|
const result = this.calcDiscount({
|
|
165
109
|
discountList: mergedDiscountList,
|
|
166
|
-
productList:
|
|
110
|
+
productList: [...productList],
|
|
167
111
|
holders,
|
|
168
112
|
isFormSubject
|
|
169
113
|
}, {
|
|
170
114
|
scan: true
|
|
171
115
|
});
|
|
172
116
|
let hasApplicableDiscount = false;
|
|
173
|
-
const newDiscountIds =
|
|
117
|
+
const newDiscountIds = newDiscountList.map((discount) => discount.id);
|
|
174
118
|
result.productList.forEach((product) => {
|
|
175
|
-
const
|
|
176
|
-
if ((0, import_entitlementState.isPersistedEntitlementLine)(product, mappedProduct))
|
|
177
|
-
return;
|
|
178
|
-
const { discount_list, bundle } = mappedProduct;
|
|
119
|
+
const { discount_list, bundle } = this.hooks.getProduct(product);
|
|
179
120
|
const allDiscountList = [...discount_list || []];
|
|
180
121
|
(bundle || []).forEach((item) => {
|
|
181
122
|
allDiscountList.push(...(item == null ? void 0 : item.discount_list) || []);
|
|
@@ -184,7 +125,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
184
125
|
const usedNewDiscount = allDiscountList.some(
|
|
185
126
|
(discount) => {
|
|
186
127
|
var _a;
|
|
187
|
-
return newDiscountIds.
|
|
128
|
+
return newDiscountIds.includes((_a = discount == null ? void 0 : discount.discount) == null ? void 0 : _a.resource_id);
|
|
188
129
|
}
|
|
189
130
|
);
|
|
190
131
|
if (usedNewDiscount) {
|
|
@@ -198,7 +139,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
198
139
|
}
|
|
199
140
|
return {
|
|
200
141
|
isAvailable: hasApplicableDiscount,
|
|
201
|
-
evaluatedDiscountList: result.discountList,
|
|
202
142
|
discountList: hasApplicableDiscount ? result.discountList : oldDiscountList,
|
|
203
143
|
productList: hasApplicableDiscount ? result.productList : productList,
|
|
204
144
|
unavailableReason
|
|
@@ -213,7 +153,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
213
153
|
for (const discount of discountList) {
|
|
214
154
|
for (const item of productList) {
|
|
215
155
|
const product = this.hooks.getProduct(item);
|
|
216
|
-
const bookingTime = (
|
|
156
|
+
const bookingTime = ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss");
|
|
217
157
|
const filteredList = (0, import_utils.filterDiscountListByBookingTime)([discount], bookingTime);
|
|
218
158
|
if (filteredList.length === 0) {
|
|
219
159
|
return import_types.UnavailableReason.TimeLimit;
|
|
@@ -222,8 +162,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
222
162
|
}
|
|
223
163
|
for (const discount of discountList) {
|
|
224
164
|
const limitedData = discount.limited_relation_product_data;
|
|
225
|
-
if (!limitedData)
|
|
226
|
-
return import_types.UnavailableReason.ProductNotApplicable;
|
|
227
165
|
let hasApplicableProduct = false;
|
|
228
166
|
for (const item of productList) {
|
|
229
167
|
const product = this.hooks.getProduct(item);
|
|
@@ -247,43 +185,13 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
247
185
|
holders,
|
|
248
186
|
isFormSubject
|
|
249
187
|
}, options) {
|
|
250
|
-
discountList = this.entitlementPassEnabled ? (0, import_entitlementState.withCommittedEntitlementDetails)(discountList, productList, this.hooks.getProduct) : discountList.filter((item) => !(0, import_entitlementPass.isEntitlementPass)(item));
|
|
251
|
-
const usableEntitlements = discountList.filter(
|
|
252
|
-
(discount) => (0, import_entitlementPass.isEntitlementPass)(discount) && !discount.isEditMode && !discount.isManualSelect && !(0, import_availability.getDiscountUsageBlockReason)(discount)
|
|
253
|
-
);
|
|
254
|
-
const canUseEntitlement = (originProduct) => {
|
|
255
|
-
const product = this.hooks.getProduct(originProduct);
|
|
256
|
-
const holderProducts = Array.isArray(product.holder_id) && product.holder_id.length > 1 ? product.holder_id.map((holder_id) => ({ ...product, holder_id })) : [product];
|
|
257
|
-
const items = [
|
|
258
|
-
{ type: "main", id: product.id, price: product.original_price ?? product.price },
|
|
259
|
-
...(product.bundle || []).map((bundleItem) => ({
|
|
260
|
-
type: "bundle",
|
|
261
|
-
id: bundleItem._bundle_product_id ?? bundleItem.bundle_product_id ?? bundleItem.product_id,
|
|
262
|
-
price: bundleItem.original_price ?? bundleItem.price,
|
|
263
|
-
bundleItem
|
|
264
|
-
}))
|
|
265
|
-
];
|
|
266
|
-
return usableEntitlements.some((discount) => {
|
|
267
|
-
const scope = discount.limited_relation_product_data;
|
|
268
|
-
if (!scope || !holderProducts.some((item) => this.checkHolderMatch(discount, item, originProduct, holders)) || !(0, import_utils.filterDiscountListByBookingTime)([discount], (0, import_dayjs.default)(product.startDate || void 0).format("YYYY-MM-DD HH:mm:ss")).length)
|
|
269
|
-
return false;
|
|
270
|
-
return items.some(
|
|
271
|
-
(item) => {
|
|
272
|
-
var _a, _b;
|
|
273
|
-
return Number(item.price) > 0 && (scope.type === "product_all" ? !(scope.filter === 1 && ((_a = scope.exclude_product_ids) == null ? void 0 : _a.some((id) => String(id) === String(item.id)))) : !!((_b = scope.product_ids) == null ? void 0 : _b.includes(item.id))) && this.checkPackageSubItemUsageRules(discount, { ...item, originProduct, parentProduct: product });
|
|
274
|
-
}
|
|
275
|
-
);
|
|
276
|
-
});
|
|
277
|
-
};
|
|
278
|
-
if (this.entitlementPassEnabled)
|
|
279
|
-
productList = (0, import_entitlementLines.prepareEntitlementLines)(productList, this.hooks, canUseEntitlement);
|
|
280
188
|
const editModeDiscount = [];
|
|
281
189
|
const addModeDiscount = [];
|
|
282
190
|
discountList.forEach((discount) => {
|
|
283
191
|
if (discount.isEditMode) {
|
|
284
192
|
editModeDiscount.push(discount);
|
|
285
193
|
} else {
|
|
286
|
-
addModeDiscount.push(
|
|
194
|
+
addModeDiscount.push(discount);
|
|
287
195
|
}
|
|
288
196
|
});
|
|
289
197
|
const editModeOrderLevelProductIds = /* @__PURE__ */ new Set();
|
|
@@ -329,7 +237,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
329
237
|
bundleIndex,
|
|
330
238
|
// 虚拟商品属性
|
|
331
239
|
price: Number(bundleItem.price || 0),
|
|
332
|
-
id: bundleItem._bundle_product_id
|
|
240
|
+
id: bundleItem._bundle_product_id,
|
|
241
|
+
// 🔥 使用 _bundle_product_id
|
|
333
242
|
_id: `${product._id}_bundle_${bundleIndex}`,
|
|
334
243
|
parentId: product._id,
|
|
335
244
|
num: bundleItem.num || 1,
|
|
@@ -411,9 +320,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
411
320
|
}
|
|
412
321
|
return 0;
|
|
413
322
|
}
|
|
414
|
-
if ((0, import_entitlementPass.isEntitlementPass)(a) || (0, import_entitlementPass.isEntitlementPass)(b)) {
|
|
415
|
-
return (0, import_entitlementPass.isEntitlementPass)(a) && (0, import_entitlementPass.isEntitlementPass)(b) ? (0, import_entitlementPass.compareEntitlementPassPriority)(a, b) : (0, import_entitlementPass.isEntitlementPass)(a) ? -1 : 1;
|
|
416
|
-
}
|
|
417
323
|
const priorityA = getPriority(a);
|
|
418
324
|
const priorityB = getPriority(b);
|
|
419
325
|
if (priorityA !== priorityB) {
|
|
@@ -462,79 +368,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
462
368
|
return !isExcluded;
|
|
463
369
|
};
|
|
464
370
|
const usedDiscounts = /* @__PURE__ */ new Map();
|
|
465
|
-
const entitlementUsageCounts = /* @__PURE__ */ new Map();
|
|
466
|
-
const usedProductIdCounts = /* @__PURE__ */ new Map();
|
|
467
|
-
const markDiscountUsed = (discount) => {
|
|
468
|
-
if ((0, import_entitlementPass.isEntitlementPass)(discount)) {
|
|
469
|
-
entitlementUsageCounts.set(discount.id, (entitlementUsageCounts.get(discount.id) || 0) + 1);
|
|
470
|
-
} else {
|
|
471
|
-
usedDiscounts.set(discount.id, true);
|
|
472
|
-
}
|
|
473
|
-
usedProductIdCounts.set(discount.product_id, (usedProductIdCounts.get(discount.product_id) || 0) + 1);
|
|
474
|
-
};
|
|
475
|
-
const getFullCoveragePasses = (discounts, quantity) => {
|
|
476
|
-
var _a;
|
|
477
|
-
const allocated = [];
|
|
478
|
-
const productCounts = new Map(usedProductIdCounts);
|
|
479
|
-
for (const discount of discounts) {
|
|
480
|
-
if (!(0, import_entitlementPass.isFullCoveragePass)(discount) || allocated.length >= quantity)
|
|
481
|
-
continue;
|
|
482
|
-
let count = (0, import_entitlementPass.isEntitlementPass)(discount) ? (0, import_entitlementPass.getRemainingEntitlementUses)(discount, entitlementUsageCounts.get(discount.id) || 0, quantity - allocated.length) : usedDiscounts.get(discount.id) ? 0 : 1;
|
|
483
|
-
const limit = Number(((_a = discount.config) == null ? void 0 : _a.maxUsagePerOrder) || 0);
|
|
484
|
-
if ((0, import_entitlementPass.isEntitlementPass)(discount) && limit > 0) {
|
|
485
|
-
count = Math.min(count, Math.max(0, Math.floor(limit) - (productCounts.get(discount.product_id) || 0)));
|
|
486
|
-
}
|
|
487
|
-
for (let i = 0; i < count; i++)
|
|
488
|
-
allocated.push(discount);
|
|
489
|
-
productCounts.set(discount.product_id, (productCounts.get(discount.product_id) || 0) + count);
|
|
490
|
-
}
|
|
491
|
-
return allocated;
|
|
492
|
-
};
|
|
493
|
-
let evaluator;
|
|
494
|
-
addModeDiscount.filter(import_entitlementPass.isEntitlementPass).forEach((discount) => {
|
|
495
|
-
var _a, _b;
|
|
496
|
-
discount.usageLimitFailKey = (0, import_availability.getDiscountUsageLimitFailKey)(discount);
|
|
497
|
-
discount.reasonCode = (0, import_availability.getDiscountUsageBlockReason)(discount);
|
|
498
|
-
const quota = (0, import_entitlementPass.resolveEntitlementQuota)(discount);
|
|
499
|
-
if (discount.reasonCode || !quota) {
|
|
500
|
-
discount.config = { isAvailable: false };
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
evaluator ?? (evaluator = this.getWalletPassEvaluator());
|
|
504
|
-
const result = evaluator.checkVoucherAvailability({
|
|
505
|
-
orderTotalAmount: productList.reduce((sum, item) => {
|
|
506
|
-
const product = this.hooks.getProduct(item);
|
|
507
|
-
return sum.plus(new import_decimal.default(product.origin_total || 0).times(product.quantity || product.num || 1));
|
|
508
|
-
}, new import_decimal.default(0)).toNumber(),
|
|
509
|
-
// 策略按统一商品结构读主价与数量,套餐次数还需乘父商品份数。
|
|
510
|
-
products: sortedFlattenedList.map((item) => {
|
|
511
|
-
var _a2, _b2, _c;
|
|
512
|
-
return {
|
|
513
|
-
product_id: item.id,
|
|
514
|
-
price: item.price || 0,
|
|
515
|
-
main_product_selling_price: item.price || 0,
|
|
516
|
-
quantity: (item.quantity || item.num || 1) * (item.type === "bundle" ? ((_a2 = item.parentProduct) == null ? void 0 : _a2.quantity) || ((_b2 = item.parentProduct) == null ? void 0 : _b2.num) || 1 : 1),
|
|
517
|
-
product_options: item.type === "main" ? (_c = item.product) == null ? void 0 : _c.options : void 0
|
|
518
|
-
};
|
|
519
|
-
}),
|
|
520
|
-
vouchers: [{
|
|
521
|
-
...discount,
|
|
522
|
-
amount: Number(discount.par_value || 0),
|
|
523
|
-
balance: quota.type === "unlimited" ? Number.MAX_SAFE_INTEGER : quota.balance,
|
|
524
|
-
type: "entitlement_pass",
|
|
525
|
-
unified_available_status: discount.unified_available_status ?? 1,
|
|
526
|
-
available_product_type: (_a = discount.limited_relation_product_data) == null ? void 0 : _a.type,
|
|
527
|
-
available_product_ids: (_b = discount.limited_relation_product_data) == null ? void 0 : _b.product_ids
|
|
528
|
-
}]
|
|
529
|
-
});
|
|
530
|
-
discount.config = { ...result.config, isAvailable: result.isAvailable };
|
|
531
|
-
if (!result.isAvailable) {
|
|
532
|
-
discount.reason = result.reason;
|
|
533
|
-
discount.reasonCode = result.reasonCode || "not_meet_the_required_conditions";
|
|
534
|
-
}
|
|
535
|
-
});
|
|
536
|
-
const entitlementTimeReasons = /* @__PURE__ */ new Map();
|
|
537
|
-
const entitlementHolderMismatch = /* @__PURE__ */ new Set();
|
|
538
371
|
const discountApplicability = /* @__PURE__ */ new Map();
|
|
539
372
|
const discountApplicableProducts = /* @__PURE__ */ new Map();
|
|
540
373
|
addModeDiscount.forEach((discount) => {
|
|
@@ -561,7 +394,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
561
394
|
startDate: (_a = flatItem.parentProduct) == null ? void 0 : _a.startDate
|
|
562
395
|
};
|
|
563
396
|
}
|
|
564
|
-
const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.length) && ((_c = product == null ? void 0 : product.discount_list) == null ? void 0 : _c.every((d) => d.id && ["
|
|
397
|
+
const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.length) && ((_c = product == null ? void 0 : product.discount_list) == null ? void 0 : _c.every((d) => d.id && ["good_pass", "discount_card", "product_discount_card"].includes(d.tag || d.type)))) : !((flatItem == null ? void 0 : flatItem.booking_id) && !!((_e = (_d = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _d.discount_list) == null ? void 0 : _e.length) && ((_g = (_f = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _f.discount_list) == null ? void 0 : _g.every((d) => d.id)));
|
|
565
398
|
if (!isAvailableProduct) {
|
|
566
399
|
return false;
|
|
567
400
|
}
|
|
@@ -572,7 +405,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
572
405
|
return false;
|
|
573
406
|
}
|
|
574
407
|
const limitedData = discount.limited_relation_product_data;
|
|
575
|
-
const timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (
|
|
408
|
+
const timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
576
409
|
if (!timeLimit) {
|
|
577
410
|
return false;
|
|
578
411
|
}
|
|
@@ -688,10 +521,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
688
521
|
originProduct = flatItem.originProduct;
|
|
689
522
|
}
|
|
690
523
|
addModeDiscount.forEach((discount) => {
|
|
691
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i
|
|
524
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
692
525
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
693
|
-
if (!limitedData || (0, import_entitlementPass.isEntitlementPass)(discount) && ((_a2 = discount.config) == null ? void 0 : _a2.isAvailable) === false)
|
|
694
|
-
return;
|
|
695
526
|
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
696
527
|
const isHolderMatch = this.checkHolderMatch(
|
|
697
528
|
discount,
|
|
@@ -699,49 +530,38 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
699
530
|
isNeedHolder: isFormSubject && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
|
|
700
531
|
holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
701
532
|
},
|
|
702
|
-
flatItem.originProduct,
|
|
703
533
|
holders
|
|
704
534
|
);
|
|
705
535
|
let timeLimit = true;
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
const reason = (0, import_utils3.getDiscountTimeUnavailableReason)(discount, useTime);
|
|
710
|
-
const reasons = entitlementTimeReasons.get(discount.id) || [];
|
|
711
|
-
reasons.push(reason);
|
|
712
|
-
entitlementTimeReasons.set(discount.id, reasons);
|
|
713
|
-
if (!isHolderMatch)
|
|
714
|
-
entitlementHolderMismatch.add(discount.id);
|
|
715
|
-
}
|
|
716
|
-
const isLimitedProduct = (limitedData.type === "product_all" && !(limitedData.filter === 1 && ((_b = limitedData.exclude_product_ids) == null ? void 0 : _b.includes(product.id))) || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
717
|
-
const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_c = product == null ? void 0 : product.discount_list) == null ? void 0 : _c.length) && ((_d = product == null ? void 0 : product.discount_list) == null ? void 0 : _d.every(
|
|
536
|
+
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
537
|
+
const isLimitedProduct = (limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
538
|
+
const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_a2 = product == null ? void 0 : product.discount_list) == null ? void 0 : _a2.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every(
|
|
718
539
|
(discount2) => discount2.id && [
|
|
719
|
-
"entitlement_pass",
|
|
720
540
|
"good_pass",
|
|
721
541
|
"discount_card",
|
|
722
542
|
"product_discount_card"
|
|
723
543
|
].includes(discount2.tag || discount2.type)
|
|
724
|
-
))) : !((flatItem == null ? void 0 : flatItem.booking_id) && !!((
|
|
544
|
+
))) : !((flatItem == null ? void 0 : flatItem.booking_id) && !!((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.discount_list) == null ? void 0 : _d.length) && ((_f = (_e = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _e.discount_list) == null ? void 0 : _f.every((discount2) => discount2.id)));
|
|
725
545
|
const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
|
|
726
|
-
if (isAvailableProduct &&
|
|
727
|
-
(
|
|
546
|
+
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
|
|
547
|
+
(_g = discountApplicability.get(discount.id)) == null ? void 0 : _g.push(product.id);
|
|
728
548
|
const applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
729
549
|
const discountType = discount.tag || discount.type;
|
|
730
|
-
const isGoodPass =
|
|
550
|
+
const isGoodPass = discountType === "good_pass";
|
|
731
551
|
const num = isGoodPass || (flatItem == null ? void 0 : flatItem.type) === "main" ? 1 : product.num;
|
|
732
552
|
const productData = {
|
|
733
553
|
amount: product.price * num,
|
|
734
554
|
type: discountType,
|
|
735
555
|
tag: discountType,
|
|
736
556
|
discount: {
|
|
737
|
-
discount_card_type: (
|
|
557
|
+
discount_card_type: (_h = discount == null ? void 0 : discount.metadata) == null ? void 0 : _h.discount_card_type,
|
|
738
558
|
fixed_amount: product.price,
|
|
739
|
-
discount_calculation_mode: (
|
|
559
|
+
discount_calculation_mode: (_i = discount == null ? void 0 : discount.metadata) == null ? void 0 : _i.discount_calculation_mode,
|
|
740
560
|
resource_id: discount.id,
|
|
741
561
|
title: discount.format_title,
|
|
742
562
|
original_amount: product.price || product.origin_total,
|
|
743
563
|
pre_value: discount.par_value,
|
|
744
|
-
product_id:
|
|
564
|
+
product_id: originProduct.id
|
|
745
565
|
},
|
|
746
566
|
metadata: {
|
|
747
567
|
num,
|
|
@@ -776,7 +596,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
776
596
|
};
|
|
777
597
|
originProduct = flatItem.originProduct;
|
|
778
598
|
}
|
|
779
|
-
if ((
|
|
599
|
+
if ((product == null ? void 0 : product.booking_id) && ((_e = product.discount_list) == null ? void 0 : _e.length) && ((_f = product == null ? void 0 : product.discount_list) == null ? void 0 : _f.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag || discount.type)))) {
|
|
780
600
|
if (flatItem.type === "main") {
|
|
781
601
|
processedProductsMap.set(product._id, [originProduct]);
|
|
782
602
|
} else {
|
|
@@ -788,22 +608,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
788
608
|
return;
|
|
789
609
|
}
|
|
790
610
|
const applicableDiscounts = sortedDiscountList.filter((discount) => {
|
|
791
|
-
var _a2, _b2
|
|
792
|
-
if ((
|
|
793
|
-
return false;
|
|
794
|
-
if ((Number(product.price) <= 0 || !product.price) && !((_d2 = product.discount_list) == null ? void 0 : _d2.length) && (0, import_entitlementPass.isFullCoveragePass)(discount))
|
|
611
|
+
var _a2, _b2;
|
|
612
|
+
if ((Number(product.price) <= 0 || !product.price) && !((_a2 = product.discount_list) == null ? void 0 : _a2.length) && (discount.tag || discount.type) === "good_pass")
|
|
795
613
|
return false;
|
|
796
|
-
if ((Number(product.price) <= 0 || !product.price) && !((
|
|
614
|
+
if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.find((n) => {
|
|
797
615
|
var _a3;
|
|
798
616
|
return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
|
|
799
|
-
})) &&
|
|
617
|
+
})) && (discount.tag || discount.type) !== "good_pass")
|
|
800
618
|
return false;
|
|
801
619
|
const targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
802
620
|
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
|
|
803
621
|
return false;
|
|
804
622
|
const limitedData = discount.limited_relation_product_data;
|
|
805
|
-
if (!limitedData)
|
|
806
|
-
return false;
|
|
807
623
|
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
808
624
|
const isHolderMatch = this.checkHolderMatch(
|
|
809
625
|
discount,
|
|
@@ -811,13 +627,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
811
627
|
isNeedHolder: isFormSubject && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
|
|
812
628
|
holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
813
629
|
},
|
|
814
|
-
flatItem.originProduct,
|
|
815
630
|
holders
|
|
816
631
|
);
|
|
817
632
|
if (!isHolderMatch)
|
|
818
633
|
return false;
|
|
819
634
|
let timeLimit = true;
|
|
820
|
-
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (0, import_dayjs.default)(
|
|
635
|
+
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (product.startDate || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
821
636
|
if (!timeLimit) {
|
|
822
637
|
return false;
|
|
823
638
|
}
|
|
@@ -837,9 +652,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
837
652
|
}
|
|
838
653
|
return false;
|
|
839
654
|
});
|
|
840
|
-
const selectedDiscountCard = applicableDiscounts.find((n) => n.isScan && n.isSelected &&
|
|
841
|
-
const
|
|
842
|
-
const selectedDiscount = explicitlySelected || selectedDiscountCard || applicableDiscounts[0];
|
|
655
|
+
const selectedDiscountCard = applicableDiscounts.find((n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass");
|
|
656
|
+
const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
|
|
843
657
|
let isManualDiscount = false;
|
|
844
658
|
if (flatItem.type === "main") {
|
|
845
659
|
isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every((item) => {
|
|
@@ -968,11 +782,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
968
782
|
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan) && !isEditModeAddNewProduct) {
|
|
969
783
|
return;
|
|
970
784
|
}
|
|
971
|
-
const isNeedSplit = (
|
|
785
|
+
const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
|
|
972
786
|
const totalQuantity = product.quantity || product.num || 1;
|
|
973
|
-
const
|
|
974
|
-
const
|
|
975
|
-
const splitCount = allocatedPasses.length;
|
|
787
|
+
const availableGoodPassCount = applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length;
|
|
788
|
+
const splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
|
|
976
789
|
const arr = [];
|
|
977
790
|
if (flatItem.type === "main") {
|
|
978
791
|
if (splitCount < totalQuantity && isNeedSplit) {
|
|
@@ -983,8 +796,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
983
796
|
}));
|
|
984
797
|
}
|
|
985
798
|
for (let i = 0; i < splitCount; i++) {
|
|
986
|
-
const selectedDiscount2 =
|
|
987
|
-
|
|
799
|
+
const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[i];
|
|
800
|
+
usedDiscounts.set(selectedDiscount2.id, true);
|
|
988
801
|
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
989
802
|
let productOriginTotal = product.origin_total || product.total || 0;
|
|
990
803
|
if (this.filterDiscountListByType(product.discount_list, "promotion").length && product.origin_total) {
|
|
@@ -1008,7 +821,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1008
821
|
amount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
|
|
1009
822
|
}
|
|
1010
823
|
const discountType = selectedDiscount2.tag || selectedDiscount2.type;
|
|
1011
|
-
const isGoodPass =
|
|
824
|
+
const isGoodPass = discountType === "good_pass";
|
|
1012
825
|
const discountDetail = {
|
|
1013
826
|
amount,
|
|
1014
827
|
type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : discountType,
|
|
@@ -1019,7 +832,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1019
832
|
resource_id: selectedDiscount2.id,
|
|
1020
833
|
title: selectedDiscount2.format_title,
|
|
1021
834
|
original_amount: product.price,
|
|
1022
|
-
product_id:
|
|
835
|
+
product_id: originProduct.id,
|
|
1023
836
|
percent: selectedDiscount2.par_value
|
|
1024
837
|
},
|
|
1025
838
|
// 前端使用的num数量,为了计算优惠金额
|
|
@@ -1044,7 +857,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1044
857
|
if (product.isClient) {
|
|
1045
858
|
arr.push(this.hooks.setProduct(originProduct, {
|
|
1046
859
|
discount_list: [discountDetail],
|
|
1047
|
-
price:
|
|
860
|
+
price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
|
|
1048
861
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1049
862
|
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
1050
863
|
product: {
|
|
@@ -1060,8 +873,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1060
873
|
} else {
|
|
1061
874
|
arr.push(this.hooks.setProduct(originProduct, {
|
|
1062
875
|
discount_list: this.filterDiscountListByType(product.discount_list, "promotion").concat([discountDetail]),
|
|
1063
|
-
_id: product._id.split("___")[0] + "___" + selectedDiscount2.id + index
|
|
1064
|
-
price:
|
|
876
|
+
_id: product._id.split("___")[0] + "___" + selectedDiscount2.id + index,
|
|
877
|
+
price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
|
|
1065
878
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1066
879
|
total,
|
|
1067
880
|
origin_total: productOriginTotal,
|
|
@@ -1076,14 +889,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1076
889
|
const discountNum = splitCount;
|
|
1077
890
|
const normalNum = totalQuantity - discountNum;
|
|
1078
891
|
for (let i = 0; i < discountNum; i++) {
|
|
1079
|
-
const selectedDiscount2 =
|
|
1080
|
-
|
|
892
|
+
const selectedDiscount2 = applicableDiscounts[i];
|
|
893
|
+
usedDiscounts.set(selectedDiscount2.id, true);
|
|
1081
894
|
const uniqueId = `${flatItem._id}_split_${i}`;
|
|
1082
895
|
const discountDetail = {
|
|
1083
|
-
amount: product.origin_total
|
|
1084
|
-
type:
|
|
896
|
+
amount: product.origin_total,
|
|
897
|
+
type: "good_pass",
|
|
1085
898
|
discount: {
|
|
1086
|
-
fixed_amount: product.origin_total
|
|
899
|
+
fixed_amount: product.origin_total,
|
|
1087
900
|
discount_calculation_mode: (_z = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _z.discount_calculation_mode,
|
|
1088
901
|
resource_id: selectedDiscount2.id,
|
|
1089
902
|
title: selectedDiscount2.format_title,
|
|
@@ -1127,10 +940,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1127
940
|
});
|
|
1128
941
|
}
|
|
1129
942
|
} else {
|
|
1130
|
-
|
|
943
|
+
const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[0];
|
|
944
|
+
usedDiscounts.set(selectedDiscount2.id, true);
|
|
1131
945
|
const productOriginTotal = product.original_price || product.price || 0;
|
|
1132
|
-
const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(
|
|
1133
|
-
const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(
|
|
946
|
+
const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(selectedDiscount2);
|
|
947
|
+
const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount2.id) : null;
|
|
1134
948
|
const productAllocation = orderLevelAllocation == null ? void 0 : orderLevelAllocation.get(flatItem._id);
|
|
1135
949
|
let targetProductTotal;
|
|
1136
950
|
let fixedAmountPerItem;
|
|
@@ -1141,7 +955,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1141
955
|
targetProductTotal = Math.max(new import_decimal.default(productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
|
|
1142
956
|
} else {
|
|
1143
957
|
targetProductTotal = (0, import_utils.getDiscountAmount)(
|
|
1144
|
-
|
|
958
|
+
selectedDiscount2,
|
|
1145
959
|
productOriginTotal,
|
|
1146
960
|
productOriginTotal
|
|
1147
961
|
);
|
|
@@ -1150,30 +964,30 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1150
964
|
const uniqueId = flatItem._id;
|
|
1151
965
|
const discountDetail = {
|
|
1152
966
|
amount: fixedAmountPerItem * (product.num || 1),
|
|
1153
|
-
type:
|
|
967
|
+
type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
|
|
1154
968
|
discount: {
|
|
1155
|
-
discount_card_type: (_A =
|
|
969
|
+
discount_card_type: (_A = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _A.discount_card_type,
|
|
1156
970
|
fixed_amount: fixedAmountPerItem,
|
|
1157
|
-
discount_calculation_mode: (_B =
|
|
1158
|
-
resource_id:
|
|
1159
|
-
title:
|
|
971
|
+
discount_calculation_mode: (_B = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _B.discount_calculation_mode,
|
|
972
|
+
resource_id: selectedDiscount2.id,
|
|
973
|
+
title: selectedDiscount2.format_title,
|
|
1160
974
|
original_amount: product.original_price,
|
|
1161
975
|
product_id: product.id,
|
|
1162
|
-
percent:
|
|
976
|
+
percent: selectedDiscount2.par_value
|
|
1163
977
|
},
|
|
1164
978
|
metadata: {
|
|
1165
979
|
// 🔥 使用唯一的 _id
|
|
1166
980
|
custom_product_bundle_map_id: uniqueId,
|
|
1167
|
-
discount_rule_uncheck_flag:
|
|
981
|
+
discount_rule_uncheck_flag: selectedDiscount2 == null ? void 0 : selectedDiscount2.discount_rule_uncheck_flag,
|
|
1168
982
|
num: product.num || 1,
|
|
1169
983
|
// 🔥 order_level 分摊差值
|
|
1170
984
|
...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
|
|
1171
985
|
},
|
|
1172
986
|
_num: (product.num || 1) * (((_C = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _C.num) || 1)
|
|
1173
987
|
};
|
|
1174
|
-
const appliedProducts = appliedDiscountProducts.get(
|
|
988
|
+
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
1175
989
|
appliedProducts.push(discountDetail);
|
|
1176
|
-
appliedDiscountProducts.set(
|
|
990
|
+
appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
|
|
1177
991
|
processedItems.push({
|
|
1178
992
|
...flatItem,
|
|
1179
993
|
total: targetProductTotal,
|
|
@@ -1189,31 +1003,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1189
1003
|
const result = [];
|
|
1190
1004
|
originalProductList.forEach((originProduct) => {
|
|
1191
1005
|
const product = this.hooks.getProduct(originProduct);
|
|
1192
|
-
if ((0, import_entitlementState.isPersistedEntitlementLine)(originProduct, product)) {
|
|
1193
|
-
result.push(originProduct);
|
|
1194
|
-
return;
|
|
1195
|
-
}
|
|
1196
1006
|
const mainProductArr = processedProductsMap2.get(product._id);
|
|
1197
|
-
if ((0, import_entitlementLines.isEntitlementRuntimeLine)(originProduct, product) && !product.isManualDiscount && (mainProductArr == null ? void 0 : mainProductArr.length)) {
|
|
1198
|
-
const bundle = (product.bundle || []).flatMap((item, index) => {
|
|
1199
|
-
const processed = processedFlatItemsMap2.get(`${product._id}_bundle_${index}`);
|
|
1200
|
-
if (!(processed == null ? void 0 : processed.length))
|
|
1201
|
-
return [item];
|
|
1202
|
-
return processed.map((child) => ({
|
|
1203
|
-
...item,
|
|
1204
|
-
_id: child._id,
|
|
1205
|
-
price: child.price,
|
|
1206
|
-
bundle_selling_price: child.price,
|
|
1207
|
-
num: child.num,
|
|
1208
|
-
discount_list: (child.discount_list || []).map((detail) => ({
|
|
1209
|
-
...detail,
|
|
1210
|
-
metadata: { ...detail.metadata, num: child.num, custom_product_bundle_map_id: child._id }
|
|
1211
|
-
}))
|
|
1212
|
-
}));
|
|
1213
|
-
});
|
|
1214
|
-
result.push(...mainProductArr.map((item) => (0, import_entitlementLines.rebuildEntitlementLine)(item, bundle, this.hooks)));
|
|
1215
|
-
return;
|
|
1216
|
-
}
|
|
1217
1007
|
if (!mainProductArr || mainProductArr.length === 0) {
|
|
1218
1008
|
const getDefaultProduct = () => {
|
|
1219
1009
|
if (product.isClient) {
|
|
@@ -1267,7 +1057,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1267
1057
|
(item) => {
|
|
1268
1058
|
var _a;
|
|
1269
1059
|
return (_a = item.discount_list) == null ? void 0 : _a.some(
|
|
1270
|
-
(discount) =>
|
|
1060
|
+
(discount) => discount.type === "good_pass" || discount.tag === "good_pass"
|
|
1271
1061
|
);
|
|
1272
1062
|
}
|
|
1273
1063
|
);
|
|
@@ -1546,30 +1336,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1546
1336
|
const applicableProducts = discountApplicability.get(discount.id) || [];
|
|
1547
1337
|
const applicableProductDetails = discountApplicableProducts.get(discount.id) || [];
|
|
1548
1338
|
const appliedProductDetails = appliedDiscountProducts.get(discount.id) || [];
|
|
1549
|
-
if ((0, import_entitlementPass.isEntitlementPass)(discount)) {
|
|
1550
|
-
const committed = discount.committedAppliedProductDetails || [];
|
|
1551
|
-
const details = [...committed, ...appliedProductDetails];
|
|
1552
|
-
const isAvailable2 = applicableProducts.length > 0;
|
|
1553
|
-
const timeReasons = entitlementTimeReasons.get(discount.id) || [];
|
|
1554
|
-
const timeReason = timeReasons.length ? timeReasons.every(Boolean) ? timeReasons[0] : void 0 : (0, import_utils3.getDiscountTimeUnavailableReason)(discount, (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss"));
|
|
1555
|
-
const reasonCode = isAvailable2 ? void 0 : discount.reasonCode || timeReason || (entitlementHolderMismatch.has(discount.id) ? "holder_not_matched" : "product_not_applicable");
|
|
1556
|
-
return {
|
|
1557
|
-
...discount,
|
|
1558
|
-
isAvailable: isAvailable2 || committed.length > 0,
|
|
1559
|
-
isSelected: details.length > 0,
|
|
1560
|
-
isUsed: details.length > 0,
|
|
1561
|
-
reasonCode,
|
|
1562
|
-
reason: reasonCode === discount.reasonCode ? discount.reason : void 0,
|
|
1563
|
-
isManualSelect: (options == null ? void 0 : options.scan) ? false : discount.isManualSelect,
|
|
1564
|
-
applicableProductIds: applicableProducts,
|
|
1565
|
-
applicableProductDetails,
|
|
1566
|
-
appliedProductDetails: details,
|
|
1567
|
-
savedAmount: details.reduce((sum, detail) => {
|
|
1568
|
-
var _a;
|
|
1569
|
-
return new import_decimal.default(sum).plus(new import_decimal.default(((_a = detail.discount) == null ? void 0 : _a.fixed_amount) || 0).mul(detail._num || 1)).toNumber();
|
|
1570
|
-
}, 0)
|
|
1571
|
-
};
|
|
1572
|
-
}
|
|
1573
1339
|
const isAvailable = applicableProducts.length > 0;
|
|
1574
1340
|
if (typeof discount.isSelected === "boolean" && discount.isSelected === false && discount.isManualSelect) {
|
|
1575
1341
|
return {
|
|
@@ -1622,7 +1388,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1622
1388
|
});
|
|
1623
1389
|
console.log(processedProductList, "processedProductList");
|
|
1624
1390
|
return {
|
|
1625
|
-
productList:
|
|
1391
|
+
productList: processedProductList,
|
|
1626
1392
|
discountList: [...editModeDiscount, ...updatedDiscountList]
|
|
1627
1393
|
};
|
|
1628
1394
|
}
|