@pisell/pisellos 2.3.127 → 2.3.128
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 +2 -7
- package/dist/modules/Order/index.js +331 -480
- package/dist/modules/Order/utils/orderCollectionIdentity.js +12 -16
- package/dist/modules/Order/utils/weighedProduct.d.ts +12 -0
- package/dist/modules/Order/utils/weighedProduct.js +94 -0
- package/dist/modules/Order/utils.d.ts +1 -1
- package/dist/modules/Order/utils.js +65 -104
- 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 +190 -482
- package/dist/modules/Rules/types.d.ts +2 -4
- package/dist/server/modules/order/types.d.ts +0 -2
- package/dist/server/utils/small-ticket.js +1 -1
- package/dist/solution/BaseSales/index.d.ts +2 -3
- package/dist/solution/BaseSales/index.js +77 -44
- package/dist/solution/BaseSales/types.d.ts +7 -3
- package/dist/solution/BaseSales/utils/cartPromotion.js +126 -141
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +40 -25
- package/dist/solution/BaseSales/utils.js +3 -2
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +3 -2
- 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/ScanOrder/utils.js +3 -2
- 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 +2 -7
- package/lib/modules/Order/index.js +109 -222
- package/lib/modules/Order/utils/orderCollectionIdentity.js +11 -14
- package/lib/modules/Order/utils/weighedProduct.d.ts +12 -0
- package/lib/modules/Order/utils/weighedProduct.js +89 -0
- package/lib/modules/Order/utils.d.ts +1 -1
- package/lib/modules/Order/utils.js +6 -41
- 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 +114 -359
- package/lib/modules/Rules/types.d.ts +2 -4
- package/lib/server/modules/order/types.d.ts +0 -2
- package/lib/server/utils/small-ticket.js +1 -1
- package/lib/solution/BaseSales/index.d.ts +2 -3
- package/lib/solution/BaseSales/index.js +17 -11
- package/lib/solution/BaseSales/types.d.ts +7 -3
- package/lib/solution/BaseSales/utils/cartPromotion.js +4 -12
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -9
- package/lib/solution/BaseSales/utils.js +2 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +3 -2
- 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/ScanOrder/utils.js +2 -1
- 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
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
|
-
}
|
|
@@ -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,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.GOOD_PASS_TYPE = exports.ENTITLEMENT_PASS_TYPE = void 0;
|
|
7
|
-
exports.compareEntitlementPassPriority = compareEntitlementPassPriority;
|
|
8
|
-
exports.getRemainingEntitlementUses = getRemainingEntitlementUses;
|
|
9
|
-
exports.hasAvailableEntitlementUses = hasAvailableEntitlementUses;
|
|
10
|
-
exports.isEntitlementPass = isEntitlementPass;
|
|
11
|
-
exports.isFullCoveragePass = isFullCoveragePass;
|
|
12
|
-
exports.resolveEntitlementQuota = resolveEntitlementQuota;
|
|
13
|
-
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
const ENTITLEMENT_PASS_TYPE = exports.ENTITLEMENT_PASS_TYPE = 'entitlement_pass';
|
|
16
|
-
const GOOD_PASS_TYPE = exports.GOOD_PASS_TYPE = 'good_pass';
|
|
17
|
-
function getDiscountType(discount) {
|
|
18
|
-
const nestedDiscount = discount?.discount;
|
|
19
|
-
return String(discount?.tag || discount?.type || nestedDiscount?.tag || nestedDiscount?.type || '');
|
|
20
|
-
}
|
|
21
|
-
function isEntitlementPass(discount) {
|
|
22
|
-
return getDiscountType(discount) === ENTITLEMENT_PASS_TYPE;
|
|
23
|
-
}
|
|
24
|
-
function isFullCoveragePass(discount) {
|
|
25
|
-
const type = getDiscountType(discount);
|
|
26
|
-
return type === GOOD_PASS_TYPE || type === ENTITLEMENT_PASS_TYPE;
|
|
27
|
-
}
|
|
28
|
-
function resolveIncludedUses(discount) {
|
|
29
|
-
const metadata = discount.metadata;
|
|
30
|
-
const hasMetadataIncludedUses = !!metadata && typeof metadata === 'object' && Object.prototype.hasOwnProperty.call(metadata, 'included_uses');
|
|
31
|
-
const rawValue = hasMetadataIncludedUses ? metadata?.included_uses : Array.isArray(discount.extension_data) ? discount.extension_data.find(item => item?.field_key === 'included_uses')?.value : undefined;
|
|
32
|
-
if (!rawValue || typeof rawValue !== 'object' || Array.isArray(rawValue)) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
const includedUses = rawValue;
|
|
36
|
-
if (includedUses.type === 'unlimited' && includedUses.value === null) {
|
|
37
|
-
return {
|
|
38
|
-
type: 'unlimited',
|
|
39
|
-
value: null
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
if (includedUses.type === 'limited' && typeof includedUses.value === 'number' && Number.isInteger(includedUses.value) && includedUses.value >= 1 && includedUses.value <= 9999) {
|
|
43
|
-
return {
|
|
44
|
-
type: 'limited',
|
|
45
|
-
value: includedUses.value
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
function resolveNonNegativeInteger(value) {
|
|
51
|
-
if (typeof value !== 'number' && typeof value !== 'string' || typeof value === 'string' && value.trim() === '') {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
const normalizedValue = Number(value);
|
|
55
|
-
if (!Number.isInteger(normalizedValue) || normalizedValue < 0) return null;
|
|
56
|
-
return normalizedValue;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Resolve the authoritative total-use contract for an Entitlement Pass.
|
|
61
|
-
* Invalid or missing configuration fails closed. Legacy mode/total_uses fields
|
|
62
|
-
* are intentionally unsupported.
|
|
63
|
-
*/
|
|
64
|
-
function resolveEntitlementQuota(discount) {
|
|
65
|
-
if (!isEntitlementPass(discount)) return null;
|
|
66
|
-
const includedUses = resolveIncludedUses(discount);
|
|
67
|
-
if (!includedUses) return null;
|
|
68
|
-
if (includedUses.type === 'unlimited') {
|
|
69
|
-
return {
|
|
70
|
-
type: 'unlimited',
|
|
71
|
-
value: null,
|
|
72
|
-
balance: null
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
const balance = resolveNonNegativeInteger(discount?.balance);
|
|
76
|
-
if (balance === null) return null;
|
|
77
|
-
return {
|
|
78
|
-
type: 'limited',
|
|
79
|
-
value: includedUses.value,
|
|
80
|
-
balance
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function getRemainingEntitlementUses(discount, usedCount, requestedCount) {
|
|
84
|
-
const quota = resolveEntitlementQuota(discount);
|
|
85
|
-
const normalizedRequestedCount = Math.max(Math.floor(Number(requestedCount) || 0), 0);
|
|
86
|
-
if (!quota || normalizedRequestedCount <= 0) return 0;
|
|
87
|
-
if (quota.type === 'unlimited') return normalizedRequestedCount;
|
|
88
|
-
const normalizedUsedCount = Math.max(Math.floor(Number(usedCount) || 0), 0);
|
|
89
|
-
return Math.min(Math.max(quota.balance - normalizedUsedCount, 0), normalizedRequestedCount);
|
|
90
|
-
}
|
|
91
|
-
function hasAvailableEntitlementUses(discount) {
|
|
92
|
-
const quota = resolveEntitlementQuota(discount);
|
|
93
|
-
return !!quota && (quota.type === 'unlimited' || quota.balance > 0);
|
|
94
|
-
}
|
|
95
|
-
function resolveExpireTimestamp(value) {
|
|
96
|
-
if (typeof value !== 'string' || !value.trim()) return Number.POSITIVE_INFINITY;
|
|
97
|
-
const normalizedValue = value.trim();
|
|
98
|
-
const calendarParts = normalizedValue.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/);
|
|
99
|
-
if (calendarParts) {
|
|
100
|
-
const [, year, month, day, hour = '0', minute = '0', second = '0'] = calendarParts;
|
|
101
|
-
const yearNumber = Number(year);
|
|
102
|
-
const monthNumber = Number(month);
|
|
103
|
-
const dayNumber = Number(day);
|
|
104
|
-
const hourNumber = Number(hour);
|
|
105
|
-
const minuteNumber = Number(minute);
|
|
106
|
-
const secondNumber = Number(second);
|
|
107
|
-
const daysInMonth = new Date(Date.UTC(yearNumber, monthNumber, 0)).getUTCDate();
|
|
108
|
-
if (yearNumber <= 0 || monthNumber < 1 || monthNumber > 12 || dayNumber < 1 || dayNumber > daysInMonth || hourNumber < 0 || hourNumber > 23 || minuteNumber < 0 || minuteNumber > 59 || secondNumber < 0 || secondNumber > 59) {
|
|
109
|
-
return Number.POSITIVE_INFINITY;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const date = (0, _dayjs.default)(normalizedValue);
|
|
113
|
-
return date.isValid() ? date.valueOf() : Number.POSITIVE_INFINITY;
|
|
114
|
-
}
|
|
115
|
-
function compareIds(left, right) {
|
|
116
|
-
const leftNumber = Number(left);
|
|
117
|
-
const rightNumber = Number(right);
|
|
118
|
-
if (Number.isFinite(leftNumber) && Number.isFinite(rightNumber)) {
|
|
119
|
-
return leftNumber - rightNumber;
|
|
120
|
-
}
|
|
121
|
-
return String(left ?? '').localeCompare(String(right ?? ''), undefined, {
|
|
122
|
-
numeric: true
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/** Sort Entitlement Passes by expiry, finite balance, then card instance id. */
|
|
127
|
-
function compareEntitlementPassPriority(left, right) {
|
|
128
|
-
const expireDifference = resolveExpireTimestamp(left.expire_time) - resolveExpireTimestamp(right.expire_time);
|
|
129
|
-
if (!Number.isNaN(expireDifference) && expireDifference !== 0) {
|
|
130
|
-
return expireDifference;
|
|
131
|
-
}
|
|
132
|
-
const leftQuota = resolveEntitlementQuota(left);
|
|
133
|
-
const rightQuota = resolveEntitlementQuota(right);
|
|
134
|
-
const leftBalance = leftQuota?.type === 'limited' ? leftQuota.balance : Number.POSITIVE_INFINITY;
|
|
135
|
-
const rightBalance = rightQuota?.type === 'limited' ? rightQuota.balance : Number.POSITIVE_INFINITY;
|
|
136
|
-
const balanceDifference = leftBalance - rightBalance;
|
|
137
|
-
if (!Number.isNaN(balanceDifference) && balanceDifference !== 0) {
|
|
138
|
-
return balanceDifference;
|
|
139
|
-
}
|
|
140
|
-
return compareIds(left.id, right.id);
|
|
141
|
-
}
|