@pisell/pisellos 2.3.124 → 2.3.125
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 +13 -8
- 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 +13 -8
- 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
|
@@ -36,22 +36,14 @@ function formatGlobalScanResult(raw, scanCode) {
|
|
|
36
36
|
return {
|
|
37
37
|
searchType,
|
|
38
38
|
data: resultData?.customer,
|
|
39
|
-
scanCode
|
|
40
|
-
customerId: resultData?.customer_id,
|
|
41
|
-
isCrossShopWallet: resultData?.is_cross_shop_wallet === true || Number(resultData?.is_cross_shop_wallet) === 1
|
|
39
|
+
scanCode
|
|
42
40
|
};
|
|
43
41
|
}
|
|
44
42
|
if (searchType === 'walletPass') {
|
|
45
|
-
const firstResult = resultData?.[0];
|
|
46
|
-
const isWalletPassUnavailableAtStore = firstResult?.is_franchisor_pass === 1 && firstResult?.franchisee_wallet_pass?.use !== 'enabled';
|
|
47
43
|
return {
|
|
48
44
|
searchType,
|
|
49
|
-
data:
|
|
50
|
-
scanCode
|
|
51
|
-
customerId: firstResult?.customer_id ?? firstResult?.holder?.customer_id ?? firstResult?.customer?.id ?? firstResult?.customer?.customer_id,
|
|
52
|
-
...(isWalletPassUnavailableAtStore ? {
|
|
53
|
-
isWalletPassUnavailableAtStore: true
|
|
54
|
-
} : {})
|
|
45
|
+
data: resultData?.[0]?.customer,
|
|
46
|
+
scanCode
|
|
55
47
|
};
|
|
56
48
|
}
|
|
57
49
|
if (searchType === 'product' || searchType === 'local_product') {
|
|
@@ -43,7 +43,6 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
43
43
|
batchSearchByProductIds(productIds: number[]): Promise<Discount[]>;
|
|
44
44
|
scanCode(code: string, customerId?: number): Promise<{
|
|
45
45
|
isAvailable: boolean;
|
|
46
|
-
isAccepted?: boolean;
|
|
47
46
|
productList: Record<string, any>[];
|
|
48
47
|
discountList: Discount[];
|
|
49
48
|
type: "server" | "clientCalc";
|
|
@@ -63,7 +62,6 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
63
62
|
action?: 'create' | 'edit';
|
|
64
63
|
with_good_pass?: 0 | 1;
|
|
65
64
|
with_discount_card?: 0 | 1;
|
|
66
|
-
with_entitlement_pass?: 0 | 1;
|
|
67
65
|
}): Promise<void>;
|
|
68
66
|
}
|
|
69
67
|
export default ShopDiscountImpl;
|
|
@@ -7,10 +7,8 @@ exports.default = exports.ShopDiscountImpl = void 0;
|
|
|
7
7
|
var _BaseModule = require("../../modules/BaseModule");
|
|
8
8
|
var _Discount = require("../../modules/Discount");
|
|
9
9
|
var _Rules = require("../../modules/Rules");
|
|
10
|
-
var _entitlementPass = require("../../modules/Discount/entitlementPass");
|
|
11
10
|
var _utils = require("./utils");
|
|
12
11
|
var _types = require("../../modules/Rules/types");
|
|
13
|
-
var _availability = require("../../modules/Discount/availability");
|
|
14
12
|
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
15
13
|
var _lodashEs = require("lodash-es");
|
|
16
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -127,8 +125,7 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
|
127
125
|
customerId: customer.id,
|
|
128
126
|
action: 'create',
|
|
129
127
|
with_good_pass: 1,
|
|
130
|
-
with_discount_card: 1
|
|
131
|
-
with_entitlement_pass: 1
|
|
128
|
+
with_discount_card: 1
|
|
132
129
|
});
|
|
133
130
|
});
|
|
134
131
|
}
|
|
@@ -350,7 +347,6 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
|
350
347
|
const {
|
|
351
348
|
productList: newProductList,
|
|
352
349
|
discountList: newDiscountList,
|
|
353
|
-
evaluatedDiscountList,
|
|
354
350
|
isAvailable,
|
|
355
351
|
unavailableReason
|
|
356
352
|
} = rulesModule.isDiscountListAvailable({
|
|
@@ -365,7 +361,6 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
|
365
361
|
productList: this.store.productList || [],
|
|
366
362
|
discountList: this.getDiscountList()
|
|
367
363
|
};
|
|
368
|
-
let isAccepted = isAvailable;
|
|
369
364
|
if (isAvailable) {
|
|
370
365
|
this.setDiscountList(newDiscountList || []);
|
|
371
366
|
this.store.originalDiscountList = newDiscountList || [];
|
|
@@ -373,34 +368,12 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
|
373
368
|
if (this.isWalkIn() && resultDiscountList.length && this.options.otherParams?.platform === 'shop' && !((resultDiscountList[0].customer_id || 1) === 1)) {
|
|
374
369
|
await this.getCustomerWallet(resultDiscountList[0].customer_id);
|
|
375
370
|
}
|
|
376
|
-
} else {
|
|
377
|
-
const scannedIds = new Set(withScanList.map(discount => String(discount.id)));
|
|
378
|
-
const retainedScannedDiscounts = (evaluatedDiscountList || withScanList).filter(discount => scannedIds.has(String(discount.id)) && !(0, _availability.getDiscountLifecycleReason)(discount));
|
|
379
|
-
if (retainedScannedDiscounts.length) {
|
|
380
|
-
const retainedDiscounts = new Map(this.getDiscountList().map(discount => [String(discount.id), discount]));
|
|
381
|
-
retainedScannedDiscounts.forEach(discount => {
|
|
382
|
-
retainedDiscounts.set(String(discount.id), {
|
|
383
|
-
...discount,
|
|
384
|
-
isScan: true,
|
|
385
|
-
isAvailable: false,
|
|
386
|
-
isSelected: false,
|
|
387
|
-
reasonCode: discount.reasonCode || 'product_not_applicable',
|
|
388
|
-
appliedProductDetails: [],
|
|
389
|
-
savedAmount: 0
|
|
390
|
-
});
|
|
391
|
-
});
|
|
392
|
-
this.setDiscountList([...retainedDiscounts.values()]);
|
|
393
|
-
this.store.originalDiscountList = this.getDiscountList();
|
|
394
|
-
await this.store.discount?.setOriginalDiscountList(this.getDiscountList());
|
|
395
|
-
isAccepted = true;
|
|
396
|
-
}
|
|
397
371
|
}
|
|
398
372
|
return {
|
|
399
373
|
type: "clientCalc",
|
|
400
374
|
isAvailable: isAvailable || false,
|
|
401
|
-
isAccepted: Boolean(isAccepted),
|
|
402
375
|
productList: newProductList || this.store.productList || [],
|
|
403
|
-
discountList: this.getDiscountList(),
|
|
376
|
+
discountList: newDiscountList || this.getDiscountList(),
|
|
404
377
|
unavailableReason
|
|
405
378
|
};
|
|
406
379
|
} catch (error) {
|
|
@@ -443,7 +416,7 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
|
443
416
|
if (item.booking_id) {
|
|
444
417
|
const product = this.hooks?.getProduct(item);
|
|
445
418
|
(item.discount_list || []).forEach(discount => {
|
|
446
|
-
if (discount.id && ['
|
|
419
|
+
if (discount.id && ['good_pass', 'discount_card'].includes(discount.type)) {
|
|
447
420
|
const index = editModeDiscountList.findIndex(n => n.id === (discount.discount?.resource_id || discount.id));
|
|
448
421
|
if (index !== -1) {
|
|
449
422
|
editModeDiscountList[index] = {
|
|
@@ -549,8 +522,6 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
|
549
522
|
with_good_pass: 1,
|
|
550
523
|
with_discount_card: 1,
|
|
551
524
|
with_wallet_pass_holder: 1,
|
|
552
|
-
with_entitlement_pass: 1,
|
|
553
|
-
filter_order_wallet_pass_usage: 0,
|
|
554
525
|
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
555
526
|
...(orderId ? {
|
|
556
527
|
order_id: orderId
|
|
@@ -559,34 +530,17 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
|
559
530
|
const goodPassList = prepareConfigResult?.discountList || [];
|
|
560
531
|
const scanDiscount = this.getDiscountList()?.filter(item => item.isScan);
|
|
561
532
|
|
|
562
|
-
//
|
|
563
|
-
|
|
564
|
-
const
|
|
565
|
-
const
|
|
566
|
-
const newGoodPassList = goodPassList.flatMap(discount => {
|
|
567
|
-
const key = String(discount.id);
|
|
568
|
-
const scannedDiscount = scanDiscountById.get(key);
|
|
569
|
-
if (!scannedDiscount) return [discount];
|
|
570
|
-
if ((0, _entitlementPass.isEntitlementPass)(scannedDiscount) && (0, _entitlementPass.isEntitlementPass)(discount)) {
|
|
571
|
-
refreshedScanEntitlementIds.add(key);
|
|
572
|
-
return [{
|
|
573
|
-
...discount,
|
|
574
|
-
isScan: true,
|
|
575
|
-
isSelected: scannedDiscount.isSelected ?? discount.isSelected,
|
|
576
|
-
isManualSelect: scannedDiscount.isManualSelect ?? discount.isManualSelect
|
|
577
|
-
}];
|
|
578
|
-
}
|
|
579
|
-
return [];
|
|
580
|
-
});
|
|
581
|
-
const retainedScanDiscounts = scanDiscount.filter(discount => !refreshedScanEntitlementIds.has(String(discount.id)));
|
|
582
|
-
const newDiscountList = [...retainedScanDiscounts, ...newGoodPassList];
|
|
533
|
+
// goodPassList 里可能有 scanDiscount 重合的部分,goodPassList 需要剔除
|
|
534
|
+
const scanDiscountIds = scanDiscount.map(n => n.id);
|
|
535
|
+
const newGoodPassList = goodPassList?.filter(n => !scanDiscountIds.includes(n.id));
|
|
536
|
+
const newDiscountList = [...scanDiscount, ...(newGoodPassList || [])];
|
|
583
537
|
|
|
584
538
|
// 存储原始优惠券列表
|
|
585
539
|
this.store.originalDiscountList = newDiscountList;
|
|
586
540
|
await this.store.discount?.setOriginalDiscountList(newDiscountList);
|
|
587
541
|
|
|
588
|
-
//
|
|
589
|
-
const filteredDiscountList = newDiscountList;
|
|
542
|
+
// 根据当前预约时间过滤优惠券列表
|
|
543
|
+
const filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
|
|
590
544
|
this.store.filteredDiscountList = filteredDiscountList;
|
|
591
545
|
this.setDiscountList(filteredDiscountList || []);
|
|
592
546
|
if (this.store.productList?.length) {
|
|
@@ -59,14 +59,12 @@ export interface ScheduleItem {
|
|
|
59
59
|
}
|
|
60
60
|
export declare const getDateIsInSchedule: (dateTime: string, scheduleList: ScheduleItem[]) => boolean;
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
62
|
+
* 根据预约时间过滤优惠券列表
|
|
63
63
|
* @param discountList 优惠券列表
|
|
64
|
-
* @param bookingTime
|
|
64
|
+
* @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
|
|
65
65
|
* @returns 过滤后的优惠券列表
|
|
66
66
|
*/
|
|
67
67
|
export declare const filterDiscountListByBookingTime: (discountList: Discount[], bookingTime: string | null) => Discount[];
|
|
68
|
-
/** 与抵扣计算共用时间判断,区分未开始、有效期不匹配和日程限制。 */
|
|
69
|
-
export declare const getDiscountTimeUnavailableReason: (discount: Discount, useTime: string) => 'not_started' | 'time_limit' | 'outside_schedule' | undefined;
|
|
70
68
|
/**
|
|
71
69
|
* 判断是否是订单级别的固定金额折扣卡
|
|
72
70
|
* @param discount 折扣
|
|
@@ -3,15 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.uniqueById = exports.isOrderLevelFixedAmountDiscount = exports.isNormalProductByDurationSchedule = exports.isAllNormalProduct = exports.
|
|
6
|
+
exports.uniqueById = exports.isOrderLevelFixedAmountDiscount = exports.isNormalProductByDurationSchedule = exports.isAllNormalProduct = exports.getDiscountListAmountTotal = exports.getDiscountListAmount = exports.getDiscountAmount = exports.getDateIsInSchedule = exports.filterDiscountListByBookingTime = exports.calculateOrderLevelDiscountAllocation = void 0;
|
|
7
7
|
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
8
8
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
9
|
-
var _isSameOrAfter = _interopRequireDefault(require("dayjs/plugin/isSameOrAfter"));
|
|
10
|
-
var _isSameOrBefore = _interopRequireDefault(require("dayjs/plugin/isSameOrBefore"));
|
|
11
|
-
var _entitlementPass = require("../../modules/Discount/entitlementPass");
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
_dayjs.default.extend(_isSameOrAfter.default);
|
|
14
|
-
_dayjs.default.extend(_isSameOrBefore.default);
|
|
15
10
|
const uniqueById = (arr, key = 'id') => {
|
|
16
11
|
const seen = new Set();
|
|
17
12
|
return arr.filter(item => !seen.has(item[key]) && seen.add(item[key]));
|
|
@@ -40,8 +35,8 @@ const isAllNormalProduct = items => {
|
|
|
40
35
|
*/
|
|
41
36
|
exports.isAllNormalProduct = isAllNormalProduct;
|
|
42
37
|
const getDiscountAmount = (discount, total, price) => {
|
|
43
|
-
//
|
|
44
|
-
if (
|
|
38
|
+
// 商品券
|
|
39
|
+
if (discount.tag === 'good_pass') {
|
|
45
40
|
return new _decimal.default(price).minus(new _decimal.default(price || 0)).toNumber();
|
|
46
41
|
}
|
|
47
42
|
|
|
@@ -381,53 +376,41 @@ const isInWeeklyRepeatForDate = (targetDate, startDate, repeatRule) => {
|
|
|
381
376
|
};
|
|
382
377
|
|
|
383
378
|
/**
|
|
384
|
-
*
|
|
379
|
+
* 根据预约时间过滤优惠券列表
|
|
385
380
|
* @param discountList 优惠券列表
|
|
386
|
-
* @param bookingTime
|
|
381
|
+
* @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
|
|
387
382
|
* @returns 过滤后的优惠券列表
|
|
388
383
|
*/
|
|
389
384
|
const filterDiscountListByBookingTime = (discountList, bookingTime) => {
|
|
390
|
-
if (!bookingTime)
|
|
391
|
-
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/** 与抵扣计算共用时间判断,区分未开始、有效期不匹配和日程限制。 */
|
|
395
|
-
exports.filterDiscountListByBookingTime = filterDiscountListByBookingTime;
|
|
396
|
-
const getDiscountTimeUnavailableReason = (discount, useTime) => {
|
|
397
|
-
const useTimeDayjs = (0, _dayjs.default)(useTime);
|
|
398
|
-
if (!useTimeDayjs.isValid()) return 'time_limit';
|
|
399
|
-
try {
|
|
385
|
+
if (!bookingTime) {
|
|
386
|
+
return discountList;
|
|
387
|
+
}
|
|
388
|
+
return discountList.filter(discount => {
|
|
400
389
|
if (discount?.metadata?.validity_type === "custom_schedule_validity") {
|
|
401
|
-
return getDateIsInSchedule(
|
|
402
|
-
}
|
|
403
|
-
const isHasStart = !!discount.start_date && !!discount.start_time;
|
|
404
|
-
const startDate = (0, _dayjs.default)(`${discount.start_date} ${discount.start_time}`);
|
|
405
|
-
|
|
406
|
-
// 开始时刻包含在有效期内。
|
|
407
|
-
if (isHasStart) {
|
|
408
|
-
if (!startDate.isValid()) return 'time_limit';
|
|
409
|
-
if (useTimeDayjs.isBefore(startDate)) return 'not_started';
|
|
390
|
+
return getDateIsInSchedule(bookingTime, discount.custom_schedule_snapshot?.data || []);
|
|
410
391
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
392
|
+
try {
|
|
393
|
+
const isHasStart = !!discount.start_date && !!discount.start_time;
|
|
394
|
+
const startDate = (0, _dayjs.default)(`${discount.start_date} ${discount.start_time}`);
|
|
395
|
+
const bookingTimeDayjs = (0, _dayjs.default)(bookingTime);
|
|
396
|
+
|
|
397
|
+
// 判断预约时间是否在开始时间之后
|
|
398
|
+
const isAfterStart = isHasStart ? bookingTimeDayjs.isSameOrAfter(startDate) : true;
|
|
399
|
+
|
|
400
|
+
// 判断预约时间是否在过期时间之前(expire_time 为空时为长期有效)
|
|
401
|
+
const isBeforeExpire = discount.expire_time ? bookingTimeDayjs.isSameOrBefore((0, _dayjs.default)(discount.expire_time)) : true;
|
|
402
|
+
return isAfterStart && isBeforeExpire;
|
|
403
|
+
} catch (error) {
|
|
404
|
+
return true;
|
|
419
405
|
}
|
|
420
|
-
|
|
421
|
-
} catch (error) {
|
|
422
|
-
return 'time_limit';
|
|
423
|
-
}
|
|
406
|
+
});
|
|
424
407
|
};
|
|
425
408
|
/**
|
|
426
409
|
* 判断是否是订单级别的固定金额折扣卡
|
|
427
410
|
* @param discount 折扣
|
|
428
411
|
* @returns 是否是订单级别的固定金额折扣卡
|
|
429
412
|
*/
|
|
430
|
-
exports.
|
|
413
|
+
exports.filterDiscountListByBookingTime = filterDiscountListByBookingTime;
|
|
431
414
|
const isOrderLevelFixedAmountDiscount = discount => {
|
|
432
415
|
return discount.tag === 'product_discount_card' && discount?.metadata?.discount_card_type === 'fixed_amount' && discount?.metadata?.discount_calculation_mode === 'order_level';
|
|
433
416
|
};
|
|
@@ -159,7 +159,7 @@ function buildPlannerDiscountResult(params) {
|
|
|
159
159
|
const productDiscounts = [...(Array.isArray(product.discount_list) ? product.discount_list : []), ...(Array.isArray(product.product_bundle) ? product.product_bundle.flatMap(bundle => bundle?.discount_list || []) : [])];
|
|
160
160
|
productDiscounts.forEach(discount => {
|
|
161
161
|
const type = discount.tag || discount.type;
|
|
162
|
-
if (!['
|
|
162
|
+
if (!['good_pass', 'discount_card', 'product_discount_card'].includes(type)) return;
|
|
163
163
|
const discountId = resolvePlannerDiscountId(discount);
|
|
164
164
|
applications.push({
|
|
165
165
|
discountId,
|
|
@@ -201,7 +201,7 @@ function isLocalOrderId(orderId) {
|
|
|
201
201
|
}
|
|
202
202
|
function isCustomerBoundDiscount(discount) {
|
|
203
203
|
const type = discount?.type ?? discount?.tag;
|
|
204
|
-
return type === '
|
|
204
|
+
return type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
|
|
205
205
|
}
|
|
206
206
|
function filterCustomerBoundDiscounts(discountList) {
|
|
207
207
|
if (!Array.isArray(discountList)) return [];
|
package/package.json
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Discount, DiscountFilterRejectKey } from './types';
|
|
2
|
-
/** 周期限制只影响当前使用;total_credits 才代表整张卡的次数耗尽。 */
|
|
3
|
-
export declare function getDiscountUsageLimitFailKey(discount: Discount): DiscountFilterRejectKey | null;
|
|
4
|
-
export declare function hasAvailableDiscountBalance(discount: Discount): boolean;
|
|
5
|
-
/** 按卡本身当前生命周期判断;预约时间或一次日程不匹配不代表已失效。 */
|
|
6
|
-
export declare function getDiscountLifecycleReason(discount: Discount): 'disabled' | 'exhausted' | 'expired' | undefined;
|
|
7
|
-
export declare function getDiscountUsageBlockReason(discount: Discount): string | undefined;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
import dayjs from 'dayjs';
|
|
8
|
-
import Decimal from 'decimal.js';
|
|
9
|
-
import { hasAvailableEntitlementUses, isEntitlementPass } from "./entitlementPass";
|
|
10
|
-
|
|
11
|
-
/** 周期限制只影响当前使用;total_credits 才代表整张卡的次数耗尽。 */
|
|
12
|
-
export function getDiscountUsageLimitFailKey(discount) {
|
|
13
|
-
var _discount$extension_d, _limits$find;
|
|
14
|
-
var value = (_discount$extension_d = discount.extension_data) === null || _discount$extension_d === void 0 || (_discount$extension_d = _discount$extension_d.find(function (field) {
|
|
15
|
-
return field.field_key === 'usage_credits';
|
|
16
|
-
})) === null || _discount$extension_d === void 0 ? void 0 : _discount$extension_d.value;
|
|
17
|
-
if (!value) return null;
|
|
18
|
-
var limits = [['total_credits', discount.total_order_behavior_count], ['per_user_limit', discount.customer_order_behavior_count], ['max_per_day', discount.today_order_behavior_count], ['max_per_week', discount.week_order_behavior_count], ['max_per_month', discount.month_order_behavior_count]];
|
|
19
|
-
return ((_limits$find = limits.find(function (_ref) {
|
|
20
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
21
|
-
key = _ref2[0],
|
|
22
|
-
count = _ref2[1];
|
|
23
|
-
return Number(value[key]) > 0 && Number(count || 0) >= Number(value[key]);
|
|
24
|
-
})) === null || _limits$find === void 0 ? void 0 : _limits$find[0]) || null;
|
|
25
|
-
}
|
|
26
|
-
export function hasAvailableDiscountBalance(discount) {
|
|
27
|
-
if (isEntitlementPass(discount)) return hasAvailableEntitlementUses(discount);
|
|
28
|
-
return new Decimal(discount.par_value || 0).minus(discount.used_par_value || 0).greaterThan(0);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** 按卡本身当前生命周期判断;预约时间或一次日程不匹配不代表已失效。 */
|
|
32
|
-
export function getDiscountLifecycleReason(discount) {
|
|
33
|
-
var _discount$metadata;
|
|
34
|
-
if (discount.limit_status && discount.limit_status !== 'enable') {
|
|
35
|
-
return 'disabled';
|
|
36
|
-
}
|
|
37
|
-
if ((isEntitlementPass(discount) || discount.par_value != null) && !hasAvailableDiscountBalance(discount) || getDiscountUsageLimitFailKey(discount) === 'total_credits') {
|
|
38
|
-
return 'exhausted';
|
|
39
|
-
}
|
|
40
|
-
// 自定义日程沿用快照语义,不使用遗留固定有效期字段推断过期。
|
|
41
|
-
if (((_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.validity_type) !== 'custom_schedule_validity' && discount.expire_time) {
|
|
42
|
-
var expiry = dayjs(discount.expire_time);
|
|
43
|
-
if (expiry.isValid() && !dayjs().isBefore(expiry)) return 'expired';
|
|
44
|
-
}
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
export function getDiscountUsageBlockReason(discount) {
|
|
48
|
-
return getDiscountLifecycleReason(discount) || getDiscountUsageLimitFailKey(discount) || (discount.unified_available_status != null && String(discount.unified_available_status) !== '' && Number(discount.unified_available_status) === 0 ? 'server_unavailable' : undefined);
|
|
49
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export declare const ENTITLEMENT_PASS_TYPE = "entitlement_pass";
|
|
2
|
-
export declare const GOOD_PASS_TYPE = "good_pass";
|
|
3
|
-
type DiscountLike = {
|
|
4
|
-
id?: number | string | null;
|
|
5
|
-
tag?: unknown;
|
|
6
|
-
type?: unknown;
|
|
7
|
-
discount?: object | null;
|
|
8
|
-
metadata?: object | null;
|
|
9
|
-
extension_data?: unknown;
|
|
10
|
-
balance?: unknown;
|
|
11
|
-
expire_time?: unknown;
|
|
12
|
-
};
|
|
13
|
-
export type EntitlementQuota = {
|
|
14
|
-
type: 'limited';
|
|
15
|
-
value: number;
|
|
16
|
-
balance: number;
|
|
17
|
-
} | {
|
|
18
|
-
type: 'unlimited';
|
|
19
|
-
value: null;
|
|
20
|
-
balance: null;
|
|
21
|
-
};
|
|
22
|
-
export declare function isEntitlementPass(discount: DiscountLike | null | undefined): boolean;
|
|
23
|
-
export declare function isFullCoveragePass(discount: DiscountLike | null | undefined): boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Resolve the authoritative total-use contract for an Entitlement Pass.
|
|
26
|
-
* Invalid or missing configuration fails closed. Legacy mode/total_uses fields
|
|
27
|
-
* are intentionally unsupported.
|
|
28
|
-
*/
|
|
29
|
-
export declare function resolveEntitlementQuota(discount: DiscountLike | null | undefined): EntitlementQuota | null;
|
|
30
|
-
export declare function getRemainingEntitlementUses(discount: DiscountLike | null | undefined, usedCount: number, requestedCount: number): number;
|
|
31
|
-
export declare function hasAvailableEntitlementUses(discount: DiscountLike | null | undefined): boolean;
|
|
32
|
-
/** Sort Entitlement Passes by expiry, finite balance, then card instance id. */
|
|
33
|
-
export declare function compareEntitlementPassPriority(left: DiscountLike, right: DiscountLike): number;
|
|
34
|
-
export {};
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
8
|
-
import dayjs from 'dayjs';
|
|
9
|
-
export var ENTITLEMENT_PASS_TYPE = 'entitlement_pass';
|
|
10
|
-
export var GOOD_PASS_TYPE = 'good_pass';
|
|
11
|
-
function getDiscountType(discount) {
|
|
12
|
-
var nestedDiscount = discount === null || discount === void 0 ? void 0 : discount.discount;
|
|
13
|
-
return String((discount === null || discount === void 0 ? void 0 : discount.tag) || (discount === null || discount === void 0 ? void 0 : discount.type) || (nestedDiscount === null || nestedDiscount === void 0 ? void 0 : nestedDiscount.tag) || (nestedDiscount === null || nestedDiscount === void 0 ? void 0 : nestedDiscount.type) || '');
|
|
14
|
-
}
|
|
15
|
-
export function isEntitlementPass(discount) {
|
|
16
|
-
return getDiscountType(discount) === ENTITLEMENT_PASS_TYPE;
|
|
17
|
-
}
|
|
18
|
-
export function isFullCoveragePass(discount) {
|
|
19
|
-
var type = getDiscountType(discount);
|
|
20
|
-
return type === GOOD_PASS_TYPE || type === ENTITLEMENT_PASS_TYPE;
|
|
21
|
-
}
|
|
22
|
-
function resolveIncludedUses(discount) {
|
|
23
|
-
var _discount$extension_d;
|
|
24
|
-
var metadata = discount.metadata;
|
|
25
|
-
var hasMetadataIncludedUses = !!metadata && _typeof(metadata) === 'object' && Object.prototype.hasOwnProperty.call(metadata, 'included_uses');
|
|
26
|
-
var rawValue = hasMetadataIncludedUses ? metadata === null || metadata === void 0 ? void 0 : metadata.included_uses : Array.isArray(discount.extension_data) ? (_discount$extension_d = discount.extension_data.find(function (item) {
|
|
27
|
-
return (item === null || item === void 0 ? void 0 : item.field_key) === 'included_uses';
|
|
28
|
-
})) === null || _discount$extension_d === void 0 ? void 0 : _discount$extension_d.value : undefined;
|
|
29
|
-
if (!rawValue || _typeof(rawValue) !== 'object' || Array.isArray(rawValue)) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
var includedUses = rawValue;
|
|
33
|
-
if (includedUses.type === 'unlimited' && includedUses.value === null) {
|
|
34
|
-
return {
|
|
35
|
-
type: 'unlimited',
|
|
36
|
-
value: null
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
if (includedUses.type === 'limited' && typeof includedUses.value === 'number' && Number.isInteger(includedUses.value) && includedUses.value >= 1 && includedUses.value <= 9999) {
|
|
40
|
-
return {
|
|
41
|
-
type: 'limited',
|
|
42
|
-
value: includedUses.value
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
function resolveNonNegativeInteger(value) {
|
|
48
|
-
if (typeof value !== 'number' && typeof value !== 'string' || typeof value === 'string' && value.trim() === '') {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
var normalizedValue = Number(value);
|
|
52
|
-
if (!Number.isInteger(normalizedValue) || normalizedValue < 0) return null;
|
|
53
|
-
return normalizedValue;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Resolve the authoritative total-use contract for an Entitlement Pass.
|
|
58
|
-
* Invalid or missing configuration fails closed. Legacy mode/total_uses fields
|
|
59
|
-
* are intentionally unsupported.
|
|
60
|
-
*/
|
|
61
|
-
export function resolveEntitlementQuota(discount) {
|
|
62
|
-
if (!isEntitlementPass(discount)) return null;
|
|
63
|
-
var includedUses = resolveIncludedUses(discount);
|
|
64
|
-
if (!includedUses) return null;
|
|
65
|
-
if (includedUses.type === 'unlimited') {
|
|
66
|
-
return {
|
|
67
|
-
type: 'unlimited',
|
|
68
|
-
value: null,
|
|
69
|
-
balance: null
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
var balance = resolveNonNegativeInteger(discount === null || discount === void 0 ? void 0 : discount.balance);
|
|
73
|
-
if (balance === null) return null;
|
|
74
|
-
return {
|
|
75
|
-
type: 'limited',
|
|
76
|
-
value: includedUses.value,
|
|
77
|
-
balance: balance
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
export function getRemainingEntitlementUses(discount, usedCount, requestedCount) {
|
|
81
|
-
var quota = resolveEntitlementQuota(discount);
|
|
82
|
-
var normalizedRequestedCount = Math.max(Math.floor(Number(requestedCount) || 0), 0);
|
|
83
|
-
if (!quota || normalizedRequestedCount <= 0) return 0;
|
|
84
|
-
if (quota.type === 'unlimited') return normalizedRequestedCount;
|
|
85
|
-
var normalizedUsedCount = Math.max(Math.floor(Number(usedCount) || 0), 0);
|
|
86
|
-
return Math.min(Math.max(quota.balance - normalizedUsedCount, 0), normalizedRequestedCount);
|
|
87
|
-
}
|
|
88
|
-
export function hasAvailableEntitlementUses(discount) {
|
|
89
|
-
var quota = resolveEntitlementQuota(discount);
|
|
90
|
-
return !!quota && (quota.type === 'unlimited' || quota.balance > 0);
|
|
91
|
-
}
|
|
92
|
-
function resolveExpireTimestamp(value) {
|
|
93
|
-
if (typeof value !== 'string' || !value.trim()) return Number.POSITIVE_INFINITY;
|
|
94
|
-
var normalizedValue = value.trim();
|
|
95
|
-
var calendarParts = normalizedValue.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/);
|
|
96
|
-
if (calendarParts) {
|
|
97
|
-
var _calendarParts = _slicedToArray(calendarParts, 7),
|
|
98
|
-
year = _calendarParts[1],
|
|
99
|
-
month = _calendarParts[2],
|
|
100
|
-
day = _calendarParts[3],
|
|
101
|
-
_calendarParts$ = _calendarParts[4],
|
|
102
|
-
hour = _calendarParts$ === void 0 ? '0' : _calendarParts$,
|
|
103
|
-
_calendarParts$2 = _calendarParts[5],
|
|
104
|
-
minute = _calendarParts$2 === void 0 ? '0' : _calendarParts$2,
|
|
105
|
-
_calendarParts$3 = _calendarParts[6],
|
|
106
|
-
second = _calendarParts$3 === void 0 ? '0' : _calendarParts$3;
|
|
107
|
-
var yearNumber = Number(year);
|
|
108
|
-
var monthNumber = Number(month);
|
|
109
|
-
var dayNumber = Number(day);
|
|
110
|
-
var hourNumber = Number(hour);
|
|
111
|
-
var minuteNumber = Number(minute);
|
|
112
|
-
var secondNumber = Number(second);
|
|
113
|
-
var daysInMonth = new Date(Date.UTC(yearNumber, monthNumber, 0)).getUTCDate();
|
|
114
|
-
if (yearNumber <= 0 || monthNumber < 1 || monthNumber > 12 || dayNumber < 1 || dayNumber > daysInMonth || hourNumber < 0 || hourNumber > 23 || minuteNumber < 0 || minuteNumber > 59 || secondNumber < 0 || secondNumber > 59) {
|
|
115
|
-
return Number.POSITIVE_INFINITY;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
var date = dayjs(normalizedValue);
|
|
119
|
-
return date.isValid() ? date.valueOf() : Number.POSITIVE_INFINITY;
|
|
120
|
-
}
|
|
121
|
-
function compareIds(left, right) {
|
|
122
|
-
var leftNumber = Number(left);
|
|
123
|
-
var rightNumber = Number(right);
|
|
124
|
-
if (Number.isFinite(leftNumber) && Number.isFinite(rightNumber)) {
|
|
125
|
-
return leftNumber - rightNumber;
|
|
126
|
-
}
|
|
127
|
-
return String(left !== null && left !== void 0 ? left : '').localeCompare(String(right !== null && right !== void 0 ? right : ''), undefined, {
|
|
128
|
-
numeric: true
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/** Sort Entitlement Passes by expiry, finite balance, then card instance id. */
|
|
133
|
-
export function compareEntitlementPassPriority(left, right) {
|
|
134
|
-
var expireDifference = resolveExpireTimestamp(left.expire_time) - resolveExpireTimestamp(right.expire_time);
|
|
135
|
-
if (!Number.isNaN(expireDifference) && expireDifference !== 0) {
|
|
136
|
-
return expireDifference;
|
|
137
|
-
}
|
|
138
|
-
var leftQuota = resolveEntitlementQuota(left);
|
|
139
|
-
var rightQuota = resolveEntitlementQuota(right);
|
|
140
|
-
var leftBalance = (leftQuota === null || leftQuota === void 0 ? void 0 : leftQuota.type) === 'limited' ? leftQuota.balance : Number.POSITIVE_INFINITY;
|
|
141
|
-
var rightBalance = (rightQuota === null || rightQuota === void 0 ? void 0 : rightQuota.type) === 'limited' ? rightQuota.balance : Number.POSITIVE_INFINITY;
|
|
142
|
-
var balanceDifference = leftBalance - rightBalance;
|
|
143
|
-
if (!Number.isNaN(balanceDifference) && balanceDifference !== 0) {
|
|
144
|
-
return balanceDifference;
|
|
145
|
-
}
|
|
146
|
-
return compareIds(left.id, right.id);
|
|
147
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Discount, DiscountFilterRejectKey } from './types';
|
|
2
|
-
/** 周期限制只影响当前使用;total_credits 才代表整张卡的次数耗尽。 */
|
|
3
|
-
export declare function getDiscountUsageLimitFailKey(discount: Discount): DiscountFilterRejectKey | null;
|
|
4
|
-
export declare function hasAvailableDiscountBalance(discount: Discount): boolean;
|
|
5
|
-
/** 按卡本身当前生命周期判断;预约时间或一次日程不匹配不代表已失效。 */
|
|
6
|
-
export declare function getDiscountLifecycleReason(discount: Discount): 'disabled' | 'exhausted' | 'expired' | undefined;
|
|
7
|
-
export declare function getDiscountUsageBlockReason(discount: Discount): string | undefined;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getDiscountLifecycleReason = getDiscountLifecycleReason;
|
|
7
|
-
exports.getDiscountUsageBlockReason = getDiscountUsageBlockReason;
|
|
8
|
-
exports.getDiscountUsageLimitFailKey = getDiscountUsageLimitFailKey;
|
|
9
|
-
exports.hasAvailableDiscountBalance = hasAvailableDiscountBalance;
|
|
10
|
-
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
11
|
-
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
12
|
-
var _entitlementPass = require("./entitlementPass");
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
/** 周期限制只影响当前使用;total_credits 才代表整张卡的次数耗尽。 */
|
|
15
|
-
function getDiscountUsageLimitFailKey(discount) {
|
|
16
|
-
const value = discount.extension_data?.find(field => field.field_key === 'usage_credits')?.value;
|
|
17
|
-
if (!value) return null;
|
|
18
|
-
const limits = [['total_credits', discount.total_order_behavior_count], ['per_user_limit', discount.customer_order_behavior_count], ['max_per_day', discount.today_order_behavior_count], ['max_per_week', discount.week_order_behavior_count], ['max_per_month', discount.month_order_behavior_count]];
|
|
19
|
-
return limits.find(([key, count]) => Number(value[key]) > 0 && Number(count || 0) >= Number(value[key]))?.[0] || null;
|
|
20
|
-
}
|
|
21
|
-
function hasAvailableDiscountBalance(discount) {
|
|
22
|
-
if ((0, _entitlementPass.isEntitlementPass)(discount)) return (0, _entitlementPass.hasAvailableEntitlementUses)(discount);
|
|
23
|
-
return new _decimal.default(discount.par_value || 0).minus(discount.used_par_value || 0).greaterThan(0);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** 按卡本身当前生命周期判断;预约时间或一次日程不匹配不代表已失效。 */
|
|
27
|
-
function getDiscountLifecycleReason(discount) {
|
|
28
|
-
if (discount.limit_status && discount.limit_status !== 'enable') {
|
|
29
|
-
return 'disabled';
|
|
30
|
-
}
|
|
31
|
-
if (((0, _entitlementPass.isEntitlementPass)(discount) || discount.par_value != null) && !hasAvailableDiscountBalance(discount) || getDiscountUsageLimitFailKey(discount) === 'total_credits') {
|
|
32
|
-
return 'exhausted';
|
|
33
|
-
}
|
|
34
|
-
// 自定义日程沿用快照语义,不使用遗留固定有效期字段推断过期。
|
|
35
|
-
if (discount.metadata?.validity_type !== 'custom_schedule_validity' && discount.expire_time) {
|
|
36
|
-
const expiry = (0, _dayjs.default)(discount.expire_time);
|
|
37
|
-
if (expiry.isValid() && !(0, _dayjs.default)().isBefore(expiry)) return 'expired';
|
|
38
|
-
}
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
function getDiscountUsageBlockReason(discount) {
|
|
42
|
-
return getDiscountLifecycleReason(discount) || getDiscountUsageLimitFailKey(discount) || (discount.unified_available_status != null && String(discount.unified_available_status) !== '' && Number(discount.unified_available_status) === 0 ? 'server_unavailable' : undefined);
|
|
43
|
-
}
|