@pisell/pisellos 2.3.124 → 2.3.126
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
- package/dist/model/strategy/adapter/walletPass/evaluator.js +2 -4
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +19 -58
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +12 -24
- package/dist/modules/Customer/index.js +3 -6
- package/dist/modules/Customer/types.d.ts +0 -2
- package/dist/modules/Discount/index.d.ts +2 -2
- package/dist/modules/Discount/index.js +151 -37
- package/dist/modules/Discount/types.d.ts +5 -36
- package/dist/modules/Order/index.d.ts +12 -7
- package/dist/modules/Order/index.js +307 -432
- package/dist/modules/Order/types.d.ts +5 -0
- package/dist/modules/Order/utils/orderCollectionIdentity.js +12 -16
- package/dist/modules/Order/utils.d.ts +11 -1
- package/dist/modules/Order/utils.js +127 -122
- package/dist/modules/Payment/types.d.ts +1 -21
- package/dist/modules/Payment/types.js +0 -2
- package/dist/modules/Payment/walletpass.d.ts +1 -1
- package/dist/modules/Payment/walletpass.js +47 -80
- package/dist/modules/Rules/index.d.ts +2 -2
- package/dist/modules/Rules/index.js +186 -480
- package/dist/modules/Rules/types.d.ts +0 -4
- package/dist/server/modules/order/types.d.ts +0 -2
- package/dist/solution/BaseSales/index.d.ts +0 -1
- package/dist/solution/BaseSales/index.js +59 -51
- package/dist/solution/BaseSales/types.d.ts +2 -2
- package/dist/solution/BaseSales/utils/cartPromotion.js +126 -141
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +2 -1
- package/dist/solution/BookingTicket/index.js +63 -60
- package/dist/solution/BookingTicket/types.d.ts +1 -5
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +147 -338
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +6 -19
- package/dist/solution/ShopDiscount/index.d.ts +0 -2
- package/dist/solution/ShopDiscount/index.js +42 -99
- package/dist/solution/ShopDiscount/utils.d.ts +2 -4
- package/dist/solution/ShopDiscount/utils.js +23 -43
- package/dist/solution/UnifiedBookingSales/index.js +2 -2
- package/lib/model/strategy/adapter/promotion/index.js +1 -46
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
- package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +6 -35
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -13
- package/lib/modules/Customer/index.js +1 -5
- package/lib/modules/Customer/types.d.ts +0 -2
- package/lib/modules/Discount/index.d.ts +2 -2
- package/lib/modules/Discount/index.js +129 -23
- package/lib/modules/Discount/types.d.ts +5 -36
- package/lib/modules/Order/index.d.ts +12 -7
- package/lib/modules/Order/index.js +107 -215
- package/lib/modules/Order/types.d.ts +5 -0
- package/lib/modules/Order/utils/orderCollectionIdentity.js +11 -14
- package/lib/modules/Order/utils.d.ts +11 -1
- package/lib/modules/Order/utils.js +45 -39
- package/lib/modules/Payment/types.d.ts +1 -21
- package/lib/modules/Payment/types.js +0 -1
- package/lib/modules/Payment/walletpass.d.ts +1 -1
- package/lib/modules/Payment/walletpass.js +9 -29
- package/lib/modules/Rules/index.d.ts +2 -2
- package/lib/modules/Rules/index.js +110 -357
- package/lib/modules/Rules/types.d.ts +0 -4
- package/lib/server/modules/order/types.d.ts +0 -2
- package/lib/solution/BaseSales/index.d.ts +0 -1
- package/lib/solution/BaseSales/index.js +12 -5
- package/lib/solution/BaseSales/types.d.ts +2 -2
- package/lib/solution/BaseSales/utils/cartPromotion.js +4 -12
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +2 -1
- package/lib/solution/BookingTicket/index.js +33 -36
- package/lib/solution/BookingTicket/types.d.ts +1 -5
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +42 -174
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +3 -11
- package/lib/solution/ShopDiscount/index.d.ts +0 -2
- package/lib/solution/ShopDiscount/index.js +9 -55
- package/lib/solution/ShopDiscount/utils.d.ts +2 -4
- package/lib/solution/ShopDiscount/utils.js +25 -42
- package/lib/solution/UnifiedBookingSales/index.js +2 -2
- package/package.json +1 -1
- package/dist/modules/Discount/availability.d.ts +0 -7
- package/dist/modules/Discount/availability.js +0 -49
- package/dist/modules/Discount/entitlementPass.d.ts +0 -34
- package/dist/modules/Discount/entitlementPass.js +0 -147
- package/lib/modules/Discount/availability.d.ts +0 -7
- package/lib/modules/Discount/availability.js +0 -43
- package/lib/modules/Discount/entitlementPass.d.ts +0 -34
- package/lib/modules/Discount/entitlementPass.js +0 -141
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// 导出评估器
|
|
2
|
+
export { PromotionEvaluator } from "./evaluator";
|
|
3
|
+
|
|
4
|
+
// 导出适配器
|
|
5
|
+
export { PromotionAdapter } from "./adapter";
|
|
6
|
+
export { default } from "./adapter";
|
|
7
|
+
|
|
8
|
+
// 导出策略配置示例常量
|
|
9
|
+
export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, ITEM_REWARD_STRATEGY } from "./examples";
|
|
@@ -28,8 +28,6 @@ export declare class WalletPassEvaluator {
|
|
|
28
28
|
/** 检查代金券/折扣卡是否可用 并返回config */
|
|
29
29
|
checkVoucherAvailability(input: EvaluatorInput): {
|
|
30
30
|
isAvailable: boolean;
|
|
31
|
-
reason: string | undefined;
|
|
32
|
-
reasonCode: string | undefined;
|
|
33
31
|
config: {
|
|
34
32
|
[x: string]: any;
|
|
35
33
|
};
|
|
@@ -283,7 +283,7 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
|
|
|
283
283
|
}, {
|
|
284
284
|
key: "checkVoucherAvailability",
|
|
285
285
|
value: function checkVoucherAvailability(input) {
|
|
286
|
-
var _results$, _results$2
|
|
286
|
+
var _results$, _results$2;
|
|
287
287
|
var orderTotalAmount = input.orderTotalAmount,
|
|
288
288
|
products = input.products,
|
|
289
289
|
vouchers = input.vouchers;
|
|
@@ -291,9 +291,7 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
|
|
|
291
291
|
var isAvailable = ((_results$ = results[0]) === null || _results$ === void 0 ? void 0 : _results$.isApplicable) || false;
|
|
292
292
|
return {
|
|
293
293
|
isAvailable: isAvailable,
|
|
294
|
-
|
|
295
|
-
reasonCode: (_results$3 = results[0]) === null || _results$3 === void 0 ? void 0 : _results$3.reasonCode,
|
|
296
|
-
config: _objectSpread({}, (_results$4 = results[0]) === null || _results$4 === void 0 || (_results$4 = _results$4.strategyResult) === null || _results$4 === void 0 || (_results$4 = _results$4.config) === null || _results$4 === void 0 || (_results$4 = _results$4.metadata) === null || _results$4 === void 0 ? void 0 : _results$4.custom)
|
|
294
|
+
config: _objectSpread({}, (_results$2 = results[0]) === null || _results$2 === void 0 || (_results$2 = _results$2.strategyResult) === null || _results$2 === void 0 || (_results$2 = _results$2.config) === null || _results$2 === void 0 || (_results$2 = _results$2.metadata) === null || _results$2 === void 0 ? void 0 : _results$2.custom)
|
|
297
295
|
};
|
|
298
296
|
}
|
|
299
297
|
|
|
@@ -13,7 +13,6 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
13
13
|
import dayjs from 'dayjs';
|
|
14
14
|
import { getProductSkuOptions } from "../../Order/utils";
|
|
15
15
|
import { resolveManualDiscountMessage } from "../../Order/utils/manualProductDiscount";
|
|
16
|
-
import { isEntitlementPass } from "../../Discount/entitlementPass";
|
|
17
16
|
import { buildProductOptionStringFromOrderLine } from "./orderLineDisplay";
|
|
18
17
|
function safeFormat(value, fmt) {
|
|
19
18
|
if (value === undefined || value === null) return undefined;
|
|
@@ -126,56 +125,20 @@ function resolveProductCover(product, booking, sourceProduct) {
|
|
|
126
125
|
var _ref6, _cover;
|
|
127
126
|
return (_ref6 = (_cover = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.cover) !== null && _cover !== void 0 ? _cover : product.product_cover) !== null && _ref6 !== void 0 ? _ref6 : '';
|
|
128
127
|
}
|
|
129
|
-
function
|
|
130
|
-
|
|
131
|
-
var parsed = Number(value);
|
|
132
|
-
return Number.isFinite(parsed) ? parsed : null;
|
|
133
|
-
}
|
|
134
|
-
function hasEntitlementPassDiscount(product) {
|
|
135
|
-
var hasEntitlementDiscount = function hasEntitlementDiscount(discountList) {
|
|
136
|
-
return Array.isArray(discountList) && discountList.some(isEntitlementPass);
|
|
137
|
-
};
|
|
138
|
-
return hasEntitlementDiscount(product.discount_list) || Array.isArray(product.product_bundle) && product.product_bundle.some(function (bundle) {
|
|
139
|
-
return hasEntitlementDiscount(bundle === null || bundle === void 0 ? void 0 : bundle.discount_list);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
function resolveMainProductPrice(product, fallback, sourceProduct) {
|
|
143
|
-
var _variant, _metadata$origin, _ref7, _ref8, _price, _metadata$origin2, _metadata$origin3;
|
|
144
|
-
var restoreEntitlementPrice = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
128
|
+
function resolveMainProductPrice(product, fallback) {
|
|
129
|
+
var _metadata$main_produc;
|
|
145
130
|
var metadata = product.metadata || {};
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
var parsed = Number(value);
|
|
150
|
-
return Number.isFinite(parsed) ? parsed : fallback;
|
|
151
|
-
}
|
|
152
|
-
var sourcePrice = toFinitePrice(metadata.source_product_price);
|
|
153
|
-
if (sourcePrice !== null) return sourcePrice;
|
|
154
|
-
var variantId = Number(product.product_variant_id || 0);
|
|
155
|
-
var variantList = (_variant = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.variant) !== null && _variant !== void 0 ? _variant : (_metadata$origin = metadata.origin) === null || _metadata$origin === void 0 ? void 0 : _metadata$origin.variant;
|
|
156
|
-
if (variantId > 0 && Array.isArray(variantList)) {
|
|
157
|
-
var _matched$price;
|
|
158
|
-
var matched = variantList.find(function (variant) {
|
|
159
|
-
return Number(variant === null || variant === void 0 ? void 0 : variant.id) === variantId;
|
|
160
|
-
});
|
|
161
|
-
var variantPrice = toFinitePrice((_matched$price = matched === null || matched === void 0 ? void 0 : matched.price) !== null && _matched$price !== void 0 ? _matched$price : matched === null || matched === void 0 ? void 0 : matched.base_price);
|
|
162
|
-
if (variantPrice !== null) return variantPrice;
|
|
163
|
-
}
|
|
164
|
-
var catalogPrice = toFinitePrice((_ref7 = (_ref8 = (_price = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _price !== void 0 ? _price : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.base_price) !== null && _ref8 !== void 0 ? _ref8 : (_metadata$origin2 = metadata.origin) === null || _metadata$origin2 === void 0 ? void 0 : _metadata$origin2.price) !== null && _ref7 !== void 0 ? _ref7 : (_metadata$origin3 = metadata.origin) === null || _metadata$origin3 === void 0 ? void 0 : _metadata$origin3.base_price);
|
|
165
|
-
if (catalogPrice !== null) return catalogPrice;
|
|
166
|
-
|
|
167
|
-
// legacy 数据没有 source_product_price 时,main_product_original_price
|
|
168
|
-
// 仍比已被月卡改写为 0 的 selling_price 更可靠。
|
|
169
|
-
var legacyMainPrice = toFinitePrice(metadata.main_product_original_price);
|
|
170
|
-
return legacyMainPrice !== null && legacyMainPrice !== void 0 ? legacyMainPrice : fallback;
|
|
131
|
+
var value = (_metadata$main_produc = metadata.main_product_original_price) !== null && _metadata$main_produc !== void 0 ? _metadata$main_produc : metadata.source_product_price;
|
|
132
|
+
var parsed = Number(value);
|
|
133
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
171
134
|
}
|
|
172
135
|
function mapOrderBundleToOtherBundle(bundle) {
|
|
173
136
|
return bundle.map(function (item) {
|
|
174
|
-
var
|
|
137
|
+
var _ref7, _ref8, _item$original_price;
|
|
175
138
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
176
139
|
// 后端历史订单可能没有 original_price;此时 price 是折前毛价,
|
|
177
140
|
// bundle_selling_price 已包含折扣,不能把它当成编辑时的新原价。
|
|
178
|
-
original_price: (
|
|
141
|
+
original_price: (_ref7 = (_ref8 = (_item$original_price = item.original_price) !== null && _item$original_price !== void 0 ? _item$original_price : item.product_price) !== null && _ref8 !== void 0 ? _ref8 : item.price) !== null && _ref7 !== void 0 ? _ref7 : item.bundle_selling_price
|
|
179
142
|
});
|
|
180
143
|
});
|
|
181
144
|
}
|
|
@@ -206,10 +169,10 @@ function synthesizeProductResourceFromBooking(booking) {
|
|
|
206
169
|
});
|
|
207
170
|
if (relationIdsByForm.size === 0) return undefined;
|
|
208
171
|
return {
|
|
209
|
-
resources: Array.from(relationIdsByForm.entries()).map(function (
|
|
210
|
-
var
|
|
211
|
-
formId =
|
|
212
|
-
relationIds =
|
|
172
|
+
resources: Array.from(relationIdsByForm.entries()).map(function (_ref9) {
|
|
173
|
+
var _ref10 = _slicedToArray(_ref9, 2),
|
|
174
|
+
formId = _ref10[0],
|
|
175
|
+
relationIds = _ref10[1];
|
|
213
176
|
return {
|
|
214
177
|
id: formId,
|
|
215
178
|
status: 1,
|
|
@@ -229,16 +192,15 @@ function synthesizeProductResourceFromBooking(booking) {
|
|
|
229
192
|
* 调用方须传入与该行关联的 booking(通常 bookings[].product_uid === product.metadata.unique_identification_number)。
|
|
230
193
|
*/
|
|
231
194
|
export function buildCacheItemFromOrderLine(input) {
|
|
232
|
-
var
|
|
195
|
+
var _ref11, _sourceProduct$holder, _sourceProduct$origin, _product$metadata, _product$product_id, _product$selling_pric, _product$original_pri, _booking$metadata$hol, _booking$metadata2, _product$bundle_edit, _product$product_vari, _product$num, _ref12, _product$note, _booking$detail2, _product$metadata2, _product$metadata3, _ref13, _extension_type, _booking$product2, _booking$product3, _price, _product$product_sku, _product$order_detail, _ref14, _booking$id;
|
|
233
196
|
var product = input.product,
|
|
234
197
|
booking = input.booking,
|
|
235
198
|
sourceProduct = input.sourceProduct;
|
|
236
|
-
var holderConfig = (
|
|
199
|
+
var holderConfig = (_ref11 = (_sourceProduct$holder = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.holder_config) !== null && _sourceProduct$holder !== void 0 ? _sourceProduct$holder : sourceProduct === null || sourceProduct === void 0 || (_sourceProduct$origin = sourceProduct.origin) === null || _sourceProduct$origin === void 0 ? void 0 : _sourceProduct$origin.holder_config) !== null && _ref11 !== void 0 ? _ref11 : (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.holder_config;
|
|
237
200
|
var resolvedId = (_product$product_id = product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.id;
|
|
238
201
|
var selling = Number((_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : 0);
|
|
239
202
|
var original = Number((_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : selling);
|
|
240
|
-
var
|
|
241
|
-
var mainProductPrice = resolveMainProductPrice(product, selling, sourceProduct, shouldRestoreEntitlementPrice);
|
|
203
|
+
var mainProductPrice = resolveMainProductPrice(product, selling);
|
|
242
204
|
var startDate = safeFormat(booking.start_date, 'YYYY-MM-DD');
|
|
243
205
|
var endDate = safeFormat(booking.end_date, 'YYYY-MM-DD');
|
|
244
206
|
var startTime = normalizeTimeString(booking.start_time);
|
|
@@ -268,7 +230,7 @@ export function buildCacheItemFromOrderLine(input) {
|
|
|
268
230
|
quantity: (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : 1,
|
|
269
231
|
product_name: productTitle,
|
|
270
232
|
product_cover: productCover,
|
|
271
|
-
note: (
|
|
233
|
+
note: (_ref12 = (_product$note = product.note) !== null && _product$note !== void 0 ? _product$note : booking === null || booking === void 0 || (_booking$detail2 = booking.detail) === null || _booking$detail2 === void 0 ? void 0 : _booking$detail2.note) !== null && _ref12 !== void 0 ? _ref12 : '',
|
|
272
234
|
price: mainProductPrice,
|
|
273
235
|
total: selling,
|
|
274
236
|
origin_total: original,
|
|
@@ -294,8 +256,7 @@ export function buildCacheItemFromOrderLine(input) {
|
|
|
294
256
|
}
|
|
295
257
|
}
|
|
296
258
|
if (((_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.price_override) != null || manualDiscount) {
|
|
297
|
-
|
|
298
|
-
extend.priceOverride = shouldRestoreEntitlementPrice ? (_product$metadata$pri = (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.price_override) !== null && _product$metadata$pri !== void 0 ? _product$metadata$pri : selling : selling;
|
|
259
|
+
extend.priceOverride = selling;
|
|
299
260
|
}
|
|
300
261
|
if (booking.holder !== undefined) {
|
|
301
262
|
extend.holder = booking.holder;
|
|
@@ -308,9 +269,9 @@ export function buildCacheItemFromOrderLine(input) {
|
|
|
308
269
|
} : {}), {}, {
|
|
309
270
|
id: resolvedId,
|
|
310
271
|
product_id: resolvedId,
|
|
311
|
-
extension_type: (
|
|
272
|
+
extension_type: (_ref13 = (_extension_type = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.extension_type) !== null && _extension_type !== void 0 ? _extension_type : booking === null || booking === void 0 || (_booking$product2 = booking.product) === null || _booking$product2 === void 0 ? void 0 : _booking$product2.extension_type) !== null && _ref13 !== void 0 ? _ref13 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.extension_type,
|
|
312
273
|
title: productTitle || (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) || (booking === null || booking === void 0 || (_booking$product3 = booking.product) === null || _booking$product3 === void 0 ? void 0 : _booking$product3.title),
|
|
313
|
-
price: (
|
|
274
|
+
price: (_price = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _price !== void 0 ? _price : selling,
|
|
314
275
|
selling_price: product.selling_price,
|
|
315
276
|
original_price: product.original_price
|
|
316
277
|
}, Number(((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.open_sold_weight) || 0) === 1 ? {
|
|
@@ -322,7 +283,7 @@ export function buildCacheItemFromOrderLine(input) {
|
|
|
322
283
|
new: 0,
|
|
323
284
|
autoClose: false,
|
|
324
285
|
order_detail_id: (_product$order_detail = product.order_detail_id) !== null && _product$order_detail !== void 0 ? _product$order_detail : null,
|
|
325
|
-
booking_id: (
|
|
286
|
+
booking_id: (_ref14 = (_booking$id = booking.id) !== null && _booking$id !== void 0 ? _booking$id : booking.booking_id) !== null && _ref14 !== void 0 ? _ref14 : 0
|
|
326
287
|
});
|
|
327
288
|
if ((sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.capacity) !== undefined) {
|
|
328
289
|
base.capacity = sourceProduct.capacity;
|
|
@@ -8,7 +8,6 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
8
8
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
9
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
10
|
import { getProductSkuOptions } from "../../Order/utils";
|
|
11
|
-
import { isEntitlementPass } from "../../Discount/entitlementPass";
|
|
12
11
|
import { buildProductOptionStringFromOrderLine } from "./orderLineDisplay";
|
|
13
12
|
/**
|
|
14
13
|
* 从已加车的普通商品 order line 反查 SkuDetailModal edit 所需的 cacheItem。
|
|
@@ -53,22 +52,13 @@ function resolveSourceProductPrice(product, sourceProduct) {
|
|
|
53
52
|
}
|
|
54
53
|
return Number((_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : 0);
|
|
55
54
|
}
|
|
56
|
-
function hasEntitlementPassDiscount(product) {
|
|
57
|
-
var hasEntitlementDiscount = function hasEntitlementDiscount(discountList) {
|
|
58
|
-
return Array.isArray(discountList) && discountList.some(isEntitlementPass);
|
|
59
|
-
};
|
|
60
|
-
return hasEntitlementDiscount(product.discount_list) || Array.isArray(product.product_bundle) && product.product_bundle.some(function (bundle) {
|
|
61
|
-
return hasEntitlementDiscount(bundle === null || bundle === void 0 ? void 0 : bundle.discount_list);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
55
|
|
|
65
56
|
/** 订单行 bundle → booking other.bundle(保留 original_price 供 setProductPrice 按比例分摊) */
|
|
66
57
|
function mapOrderBundleToOtherBundle(bundle) {
|
|
67
|
-
var preferManualPrice = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
68
58
|
return bundle.map(function (item) {
|
|
69
|
-
var _ref, _ref2, _item$original_price, _ref3, _item$
|
|
59
|
+
var _ref, _ref2, _item$original_price, _ref3, _item$bundle_selling_, _item$original_total, _ref4, _item$num, _ref5, _item$quantity;
|
|
70
60
|
var catalogOriginal = (_ref = (_ref2 = (_item$original_price = item.original_price) !== null && _item$original_price !== void 0 ? _item$original_price : item.product_price) !== null && _ref2 !== void 0 ? _ref2 : item.price) !== null && _ref !== void 0 ? _ref : item.bundle_selling_price;
|
|
71
|
-
var selling =
|
|
61
|
+
var selling = (_ref3 = (_item$bundle_selling_ = item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item.price) !== null && _ref3 !== void 0 ? _ref3 : catalogOriginal;
|
|
72
62
|
var _omitBundleSelling = item.bundle_selling_price,
|
|
73
63
|
rest = _objectWithoutProperties(item, _excluded);
|
|
74
64
|
var isMarkupOrMarkdown = (item.price_type === 'markdown' || item.price_type === 'markup') && (item.price_type_ext === '' || item.price_type_ext === undefined || item.price_type_ext === null);
|
|
@@ -79,13 +69,13 @@ function mapOrderBundleToOtherBundle(bundle) {
|
|
|
79
69
|
}, isMarkupOrMarkdown ? {} : {
|
|
80
70
|
original_total: (_item$original_total = item.original_total) !== null && _item$original_total !== void 0 ? _item$original_total : catalogOriginal
|
|
81
71
|
}), {}, {
|
|
82
|
-
num: (
|
|
83
|
-
quantity: (
|
|
72
|
+
num: (_ref4 = (_item$num = item.num) !== null && _item$num !== void 0 ? _item$num : item.quantity) !== null && _ref4 !== void 0 ? _ref4 : 1,
|
|
73
|
+
quantity: (_ref5 = (_item$quantity = item.quantity) !== null && _item$quantity !== void 0 ? _item$quantity : item.num) !== null && _ref5 !== void 0 ? _ref5 : 1
|
|
84
74
|
});
|
|
85
75
|
});
|
|
86
76
|
}
|
|
87
77
|
export function buildNormalProductCacheItemFromOrderLine(input) {
|
|
88
|
-
var _product$product_id, _product$selling_pric2, _product$original_pri, _product$metadata, _product$metadata2, _product$
|
|
78
|
+
var _product$product_id, _product$selling_pric2, _product$original_pri, _product$metadata, _product$metadata2, _product$product_vari, _originExtend$other, _product$num, _product$product_vari2, _product$num2, _title, _product$note, _originExtend$price, _originExtend$total, _originExtend$origin_, _product$metadata3, _ref6, _title2, _ref7, _cover, _price3, _product$order_detail, _product$product_sku;
|
|
89
79
|
var product = input.product,
|
|
90
80
|
sourceProduct = input.sourceProduct;
|
|
91
81
|
var resolvedId = (_product$product_id = product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.id;
|
|
@@ -93,11 +83,9 @@ export function buildNormalProductCacheItemFromOrderLine(input) {
|
|
|
93
83
|
var selling = Number((_product$selling_pric2 = product.selling_price) !== null && _product$selling_pric2 !== void 0 ? _product$selling_pric2 : 0);
|
|
94
84
|
var original = Number((_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : selling);
|
|
95
85
|
var uid = (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.unique_identification_number;
|
|
96
|
-
var originExtend = (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 || (_product$metadata2 = _product$metadata2.origin) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2._extend;
|
|
97
|
-
var shouldPreserveEntitlementPriceOverride = hasEntitlementPassDiscount(product) && ((originExtend === null || originExtend === void 0 ? void 0 : originExtend.priceOverride) !== undefined || ((_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.price_override) != null);
|
|
98
|
-
var hasPriceOverride = (originExtend === null || originExtend === void 0 ? void 0 : originExtend.priceOverride) !== undefined || shouldPreserveEntitlementPriceOverride;
|
|
99
86
|
var option = getProductSkuOptions(product);
|
|
100
|
-
var bundle = mapOrderBundleToOtherBundle(Array.isArray(product.product_bundle) ? product.product_bundle : []
|
|
87
|
+
var bundle = mapOrderBundleToOtherBundle(Array.isArray(product.product_bundle) ? product.product_bundle : []);
|
|
88
|
+
var originExtend = (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 || (_product$metadata2 = _product$metadata2.origin) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2._extend;
|
|
101
89
|
var productOptionString = buildProductOptionStringFromOrderLine(product);
|
|
102
90
|
var discountList = product.discount_list || [];
|
|
103
91
|
var other = {
|
|
@@ -126,12 +114,12 @@ export function buildNormalProductCacheItemFromOrderLine(input) {
|
|
|
126
114
|
_skuValue: JSON.parse(JSON.stringify(skuValue)),
|
|
127
115
|
isNormalProduct: true,
|
|
128
116
|
metadata: {
|
|
129
|
-
product_add_schedule_time: (_product$
|
|
117
|
+
product_add_schedule_time: (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.product_add_schedule_time
|
|
130
118
|
}
|
|
131
119
|
}, productOptionString ? {
|
|
132
120
|
product_option_string: productOptionString
|
|
133
|
-
} : {}),
|
|
134
|
-
priceOverride:
|
|
121
|
+
} : {}), (originExtend === null || originExtend === void 0 ? void 0 : originExtend.priceOverride) !== undefined ? {
|
|
122
|
+
priceOverride: originExtend.priceOverride
|
|
135
123
|
} : {}), (originExtend === null || originExtend === void 0 ? void 0 : originExtend.bundle_edit) !== undefined ? {
|
|
136
124
|
bundle_edit: originExtend.bundle_edit
|
|
137
125
|
} : {});
|
|
@@ -143,8 +131,8 @@ export function buildNormalProductCacheItemFromOrderLine(input) {
|
|
|
143
131
|
id: resolvedId,
|
|
144
132
|
product_id: resolvedId,
|
|
145
133
|
_id: uid,
|
|
146
|
-
title: (
|
|
147
|
-
cover: (
|
|
134
|
+
title: (_ref6 = (_title2 = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) !== null && _title2 !== void 0 ? _title2 : product.product_title) !== null && _ref6 !== void 0 ? _ref6 : '',
|
|
135
|
+
cover: (_ref7 = (_cover = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.cover) !== null && _cover !== void 0 ? _cover : product.product_cover) !== null && _ref7 !== void 0 ? _ref7 : '',
|
|
148
136
|
price: (_price3 = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _price3 !== void 0 ? _price3 : sourcePrice,
|
|
149
137
|
selling_price: product.selling_price,
|
|
150
138
|
original_price: product.original_price
|
|
@@ -197,19 +197,16 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
197
197
|
url = '/franchisee/customer/select-list';
|
|
198
198
|
}
|
|
199
199
|
_params$skip = params.skip, skip = _params$skip === void 0 ? 1 : _params$skip, _params$num = params.num, num = _params$num === void 0 ? DEFAULT_PAGE_SIZE : _params$num, search = params.search, _otherParams = _objectWithoutProperties(params, _excluded);
|
|
200
|
-
queryParams = _objectSpread(_objectSpread(
|
|
200
|
+
queryParams = _objectSpread(_objectSpread({
|
|
201
201
|
skip: skip,
|
|
202
202
|
num: num,
|
|
203
203
|
sort_by: SORT_BY,
|
|
204
204
|
with: ['latestWalletDetail.wallet', 'contactsInfo', 'formRecord'],
|
|
205
205
|
search_wallet_flag: 1,
|
|
206
|
-
search_wallet_pass_flag: 1
|
|
207
|
-
filter_franchisor_permissions: ['use']
|
|
206
|
+
search_wallet_pass_flag: 1
|
|
208
207
|
}, search && {
|
|
209
208
|
search: search
|
|
210
|
-
}), _otherParams)
|
|
211
|
-
with_franchisor_data: 1
|
|
212
|
-
} : {});
|
|
209
|
+
}), _otherParams);
|
|
213
210
|
_context2.next = 7;
|
|
214
211
|
return this.request.get(url, queryParams, {
|
|
215
212
|
cache: {
|
|
@@ -25,8 +25,6 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
25
25
|
with_wallet_pass_holder: 0 | 1;
|
|
26
26
|
with_available_wallet_flag?: 0 | 1;
|
|
27
27
|
with_available_wallet_pass_flag?: 0 | 1;
|
|
28
|
-
with_entitlement_pass?: 0 | 1;
|
|
29
|
-
filter_order_wallet_pass_usage?: 0 | 1;
|
|
30
28
|
with_virtual_currency?: 0 | 1;
|
|
31
29
|
request_timezone: string;
|
|
32
30
|
order_id?: number | string;
|
|
@@ -38,7 +36,9 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
38
36
|
}): Promise<DiscountWithReason>;
|
|
39
37
|
batchSearchByProductIds(productIds: number[]): Promise<any>;
|
|
40
38
|
filterEnabledDiscountList(discountList: Discount[]): Discount[];
|
|
39
|
+
private checkUsageCreditsLimit;
|
|
41
40
|
filterEnabledDiscountListWithReason(discountList: Discount[]): DiscountWithReason;
|
|
41
|
+
private checkUsageCreditsLimitWithFailKey;
|
|
42
42
|
uniqueByProductId(discountList: Discount[]): Discount[];
|
|
43
43
|
filterDiscountListByProductIds(discountList: Discount[], productIds: number[]): Discount[];
|
|
44
44
|
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|
|
@@ -29,7 +29,6 @@ import { uniqueById } from "../../solution/ShopDiscount/utils";
|
|
|
29
29
|
import { BaseModule } from "../BaseModule";
|
|
30
30
|
import { DiscountHooks } from "./types";
|
|
31
31
|
import Decimal from 'decimal.js';
|
|
32
|
-
import { getDiscountLifecycleReason, getDiscountUsageBlockReason, getDiscountUsageLimitFailKey, hasAvailableDiscountBalance } from "./availability";
|
|
33
32
|
export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
34
33
|
_inherits(DiscountModule, _BaseModule);
|
|
35
34
|
var _super = _createSuper(DiscountModule);
|
|
@@ -166,8 +165,8 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
166
165
|
key: "loadPrepareConfig",
|
|
167
166
|
value: function () {
|
|
168
167
|
var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
|
|
169
|
-
var _params$with_availabl, _params$with_availabl2, _params$with_virtual_, _prepareConfig$data, _prepareConfig$data2, _prepareConfig$data3, _prepareConfig$data4, _prepareConfig$data5, _prepareConfig$data6
|
|
170
|
-
var prepareConfig,
|
|
168
|
+
var _params$with_availabl, _params$with_availabl2, _params$with_virtual_, _prepareConfig$data, _prepareConfig$data2, _prepareConfig$data3, _prepareConfig$data4, _prepareConfig$data5, _prepareConfig$data6;
|
|
169
|
+
var prepareConfig, rawDiscountList, availableWalletList, availableWalletPassList, availableWalletIds, virtualCurrencyList, goodPassList;
|
|
171
170
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
172
171
|
while (1) switch (_context4.prev = _context4.next) {
|
|
173
172
|
case 0:
|
|
@@ -182,27 +181,15 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
182
181
|
}));
|
|
183
182
|
case 3:
|
|
184
183
|
prepareConfig = _context4.sent;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}).filter(function (id) {
|
|
189
|
-
return id !== undefined && id !== null;
|
|
190
|
-
}).map(function (id) {
|
|
191
|
-
return String(id);
|
|
192
|
-
}));
|
|
193
|
-
excludeEntitlementDuplicates = function excludeEntitlementDuplicates(discount) {
|
|
194
|
-
var id = discount === null || discount === void 0 ? void 0 : discount.id;
|
|
195
|
-
return id === undefined || id === null || !entitlementPassIds.has(String(id));
|
|
196
|
-
};
|
|
197
|
-
rawDiscountList = [].concat(_toConsumableArray(entitlementPassList), _toConsumableArray(((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data2 = prepareConfig.data) === null || _prepareConfig$data2 === void 0 ? void 0 : _prepareConfig$data2.good_pass_list) || []).filter(excludeEntitlementDuplicates)), _toConsumableArray(((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data3 = prepareConfig.data) === null || _prepareConfig$data3 === void 0 ? void 0 : _prepareConfig$data3.discount_card_list) || []).filter(excludeEntitlementDuplicates)));
|
|
198
|
-
availableWalletList = [].concat(_toConsumableArray((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data4 = prepareConfig.data) === null || _prepareConfig$data4 === void 0 ? void 0 : _prepareConfig$data4.avaiable_wallet_list) || []), _toConsumableArray((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data5 = prepareConfig.data) === null || _prepareConfig$data5 === void 0 ? void 0 : _prepareConfig$data5.available_wallet_list) || []));
|
|
199
|
-
availableWalletPassList = (prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data6 = prepareConfig.data) === null || _prepareConfig$data6 === void 0 ? void 0 : _prepareConfig$data6.available_wallet_pass_list) || [];
|
|
184
|
+
rawDiscountList = [].concat(_toConsumableArray((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data = prepareConfig.data) === null || _prepareConfig$data === void 0 ? void 0 : _prepareConfig$data.good_pass_list) || []), _toConsumableArray((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data2 = prepareConfig.data) === null || _prepareConfig$data2 === void 0 ? void 0 : _prepareConfig$data2.discount_card_list) || []));
|
|
185
|
+
availableWalletList = [].concat(_toConsumableArray((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data3 = prepareConfig.data) === null || _prepareConfig$data3 === void 0 ? void 0 : _prepareConfig$data3.avaiable_wallet_list) || []), _toConsumableArray((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data4 = prepareConfig.data) === null || _prepareConfig$data4 === void 0 ? void 0 : _prepareConfig$data4.available_wallet_list) || []));
|
|
186
|
+
availableWalletPassList = (prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data5 = prepareConfig.data) === null || _prepareConfig$data5 === void 0 ? void 0 : _prepareConfig$data5.available_wallet_pass_list) || [];
|
|
200
187
|
availableWalletIds = this.normalizePositiveNumberIds([].concat(_toConsumableArray(availableWalletList.map(function (item) {
|
|
201
188
|
return item === null || item === void 0 ? void 0 : item.wallet_id;
|
|
202
189
|
})), _toConsumableArray(availableWalletPassList.map(function (item) {
|
|
203
190
|
return item === null || item === void 0 ? void 0 : item.product_id;
|
|
204
191
|
}))));
|
|
205
|
-
virtualCurrencyList = this.normalizeVirtualCurrencyList(prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$
|
|
192
|
+
virtualCurrencyList = this.normalizeVirtualCurrencyList(prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data6 = prepareConfig.data) === null || _prepareConfig$data6 === void 0 ? void 0 : _prepareConfig$data6.virtual_currency_list);
|
|
206
193
|
goodPassList = this.filterEnabledDiscountList(rawDiscountList) || []; // this.setDiscountList(goodPassList);
|
|
207
194
|
return _context4.abrupt("return", {
|
|
208
195
|
discountList: goodPassList,
|
|
@@ -212,7 +199,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
212
199
|
return _objectSpread({}, item || {});
|
|
213
200
|
})
|
|
214
201
|
});
|
|
215
|
-
case
|
|
202
|
+
case 11:
|
|
216
203
|
case "end":
|
|
217
204
|
return _context4.stop();
|
|
218
205
|
}
|
|
@@ -266,7 +253,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
266
253
|
return this.request.get("/machinecode/batch-search", _objectSpread(_objectSpread({
|
|
267
254
|
code: code,
|
|
268
255
|
translate_flag: 1,
|
|
269
|
-
tags: ['
|
|
256
|
+
tags: ['good_pass', 'product_discount_card'],
|
|
270
257
|
// available: 1,
|
|
271
258
|
relation_product: 1,
|
|
272
259
|
with: ['extensionData', 'customScheduleSnapshot', 'holder.detail'],
|
|
@@ -305,11 +292,8 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
305
292
|
return this.request.get("/machinecode/batch-search", {
|
|
306
293
|
ids: productIds,
|
|
307
294
|
translate_flag: 1,
|
|
308
|
-
tags: ['
|
|
309
|
-
relation_product: 1
|
|
310
|
-
with: ['extensionData', 'customScheduleSnapshot', 'holder.detail'],
|
|
311
|
-
unified_status_info_flag: 1,
|
|
312
|
-
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
295
|
+
tags: ['good_pass', 'product_discount_card'],
|
|
296
|
+
relation_product: 1
|
|
313
297
|
});
|
|
314
298
|
case 2:
|
|
315
299
|
result = _context6.sent;
|
|
@@ -324,30 +308,160 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
324
308
|
return _batchSearchByProductIds.apply(this, arguments);
|
|
325
309
|
}
|
|
326
310
|
return batchSearchByProductIds;
|
|
327
|
-
}()
|
|
311
|
+
}()
|
|
328
312
|
}, {
|
|
329
313
|
key: "filterEnabledDiscountList",
|
|
330
314
|
value: function filterEnabledDiscountList(discountList) {
|
|
315
|
+
var _this2 = this;
|
|
331
316
|
return discountList.filter(function (discount) {
|
|
332
|
-
return discount.limit_status === 'enable' &&
|
|
333
|
-
}).map(function (discount) {
|
|
334
|
-
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
335
|
-
usageLimitFailKey: getDiscountUsageLimitFailKey(discount),
|
|
336
|
-
reasonCode: getDiscountUsageBlockReason(discount)
|
|
337
|
-
});
|
|
317
|
+
return discount.limit_status === 'enable' && new Decimal((discount === null || discount === void 0 ? void 0 : discount.par_value) || 0).minus(new Decimal((discount === null || discount === void 0 ? void 0 : discount.used_par_value) || 0)).greaterThan(0) && _this2.checkUsageCreditsLimit(discount);
|
|
338
318
|
});
|
|
339
319
|
}
|
|
320
|
+
|
|
321
|
+
// 检查使用次数限制
|
|
322
|
+
}, {
|
|
323
|
+
key: "checkUsageCreditsLimit",
|
|
324
|
+
value: function checkUsageCreditsLimit(discount) {
|
|
325
|
+
// 如果没有 extension_data,则不需要限制
|
|
326
|
+
if (!discount.extension_data || discount.extension_data.length === 0) {
|
|
327
|
+
return true;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// 查找 field_key 为 usage_credits 的数据
|
|
331
|
+
var usageCreditsData = discount.extension_data.find(function (data) {
|
|
332
|
+
return data.field_key === 'usage_credits';
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// 如果没有找到 usage_credits 数据,则不需要限制
|
|
336
|
+
if (!usageCreditsData) {
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
var value = usageCreditsData.value;
|
|
340
|
+
|
|
341
|
+
// 检查总次数限制
|
|
342
|
+
if (value.total_credits && value.total_credits > 0) {
|
|
343
|
+
if ((discount.total_order_behavior_count || 0) >= value.total_credits) {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// 检查单用户限制
|
|
349
|
+
if (value.per_user_limit && value.per_user_limit > 0) {
|
|
350
|
+
if ((discount.customer_order_behavior_count || 0) >= value.per_user_limit) {
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// 检查单日限制
|
|
356
|
+
if (value.max_per_day && value.max_per_day > 0) {
|
|
357
|
+
if ((discount.today_order_behavior_count || 0) >= value.max_per_day) {
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// 检查单周限制
|
|
363
|
+
if (value.max_per_week && value.max_per_week > 0) {
|
|
364
|
+
if ((discount.week_order_behavior_count || 0) >= value.max_per_week) {
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// 检查单月限制
|
|
370
|
+
if (value.max_per_month && value.max_per_month > 0) {
|
|
371
|
+
if ((discount.month_order_behavior_count || 0) >= value.max_per_month) {
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// 所有检查都通过
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// 过滤启用且可用的优惠券,并返回校验失败原因
|
|
340
381
|
}, {
|
|
341
382
|
key: "filterEnabledDiscountListWithReason",
|
|
342
383
|
value: function filterEnabledDiscountListWithReason(discountList) {
|
|
384
|
+
var _this3 = this;
|
|
385
|
+
var lists = discountList.filter(function (discount) {
|
|
386
|
+
return discount.limit_status === 'enable';
|
|
387
|
+
}).filter(function (discount) {
|
|
388
|
+
var remaining = new Decimal((discount === null || discount === void 0 ? void 0 : discount.par_value) || 0).minus(new Decimal((discount === null || discount === void 0 ? void 0 : discount.used_par_value) || 0)).greaterThan(0);
|
|
389
|
+
return remaining;
|
|
390
|
+
}).map(function (discount) {
|
|
391
|
+
var limitFailKey = _this3.checkUsageCreditsLimitWithFailKey(discount);
|
|
392
|
+
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
393
|
+
usageLimitFailKey: limitFailKey
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// 可用的列表
|
|
398
|
+
var availableLists = lists.filter(function (item) {
|
|
399
|
+
return !item.usageLimitFailKey && item.unified_available_status !== 0;
|
|
400
|
+
});
|
|
401
|
+
// 不可用数据
|
|
402
|
+
var currentFailDiscount = lists.find(function (item) {
|
|
403
|
+
return item.usageLimitFailKey;
|
|
404
|
+
});
|
|
343
405
|
return {
|
|
344
|
-
discountList:
|
|
345
|
-
unavailableReasonKey:
|
|
346
|
-
return key !== null;
|
|
347
|
-
}) || null
|
|
406
|
+
discountList: availableLists,
|
|
407
|
+
unavailableReasonKey: currentFailDiscount === null || currentFailDiscount === void 0 ? void 0 : currentFailDiscount.usageLimitFailKey
|
|
348
408
|
};
|
|
349
409
|
}
|
|
350
410
|
|
|
411
|
+
// 检查使用次数限制,并返回校验失败原因
|
|
412
|
+
}, {
|
|
413
|
+
key: "checkUsageCreditsLimitWithFailKey",
|
|
414
|
+
value: function checkUsageCreditsLimitWithFailKey(discount) {
|
|
415
|
+
if (!discount.extension_data || discount.extension_data.length === 0) {
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
var usageCreditsData = discount.extension_data.find(function (data) {
|
|
419
|
+
return data.field_key === 'usage_credits';
|
|
420
|
+
});
|
|
421
|
+
if (!usageCreditsData) {
|
|
422
|
+
return null;
|
|
423
|
+
}
|
|
424
|
+
var value = usageCreditsData.value;
|
|
425
|
+
|
|
426
|
+
// 总次数限制
|
|
427
|
+
if (value.total_credits && value.total_credits > 0) {
|
|
428
|
+
if ((discount.total_order_behavior_count || 0) >= value.total_credits) {
|
|
429
|
+
return 'total_credits';
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// 单用户限制
|
|
434
|
+
if (value.per_user_limit && value.per_user_limit > 0) {
|
|
435
|
+
if ((discount.customer_order_behavior_count || 0) >= value.per_user_limit) {
|
|
436
|
+
return 'per_user_limit';
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// 单日限制
|
|
441
|
+
if (value.max_per_day && value.max_per_day > 0) {
|
|
442
|
+
if ((discount.today_order_behavior_count || 0) >= value.max_per_day) {
|
|
443
|
+
return 'max_per_day';
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// 单周限制
|
|
448
|
+
if (value.max_per_week && value.max_per_week > 0) {
|
|
449
|
+
if ((discount.week_order_behavior_count || 0) >= value.max_per_week) {
|
|
450
|
+
return 'max_per_week';
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// 单月限制
|
|
455
|
+
if (value.max_per_month && value.max_per_month > 0) {
|
|
456
|
+
if ((discount.month_order_behavior_count || 0) >= value.max_per_month) {
|
|
457
|
+
return 'max_per_month';
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// 全部通过
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
|
|
351
465
|
// 根据productIds去重
|
|
352
466
|
}, {
|
|
353
467
|
key: "uniqueByProductId",
|