@pisell/pisellos 2.1.173 → 2.1.174

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.
Files changed (93) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  3. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
  4. package/dist/modules/Discount/availability.d.ts +7 -0
  5. package/dist/modules/Discount/availability.js +52 -0
  6. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  7. package/dist/modules/Discount/entitlementPass.js +147 -0
  8. package/dist/modules/Discount/entitlementState.d.ts +8 -0
  9. package/dist/modules/Discount/entitlementState.js +205 -0
  10. package/dist/modules/Discount/index.d.ts +6 -3
  11. package/dist/modules/Discount/index.js +125 -23
  12. package/dist/modules/Discount/types.d.ts +34 -5
  13. package/dist/modules/Holder/index.d.ts +48 -0
  14. package/dist/modules/Holder/index.js +640 -0
  15. package/dist/modules/Holder/types.d.ts +123 -0
  16. package/dist/modules/Holder/types.js +1 -0
  17. package/dist/modules/Holder/utils.d.ts +13 -0
  18. package/dist/modules/Holder/utils.js +34 -0
  19. package/dist/modules/Order/index.d.ts +1 -0
  20. package/dist/modules/Order/index.js +18 -1
  21. package/dist/modules/Order/types.d.ts +2 -0
  22. package/dist/modules/Order/utils.d.ts +10 -0
  23. package/dist/modules/Order/utils.js +35 -3
  24. package/dist/modules/Product/types.d.ts +7 -0
  25. package/dist/modules/Rules/entitlementLines.d.ts +8 -0
  26. package/dist/modules/Rules/entitlementLines.js +157 -0
  27. package/dist/modules/Rules/index.d.ts +12 -2
  28. package/dist/modules/Rules/index.js +377 -112
  29. package/dist/modules/Rules/types.d.ts +2 -2
  30. package/dist/modules/index.d.ts +1 -0
  31. package/dist/modules/index.js +2 -1
  32. package/dist/plugins/window.d.ts +3 -0
  33. package/dist/solution/BookingByStep/index.d.ts +17 -2
  34. package/dist/solution/BookingByStep/index.js +276 -204
  35. package/dist/solution/BookingByStep/types.d.ts +2 -1
  36. package/dist/solution/BookingByStep/types.js +3 -1
  37. package/dist/solution/ScanOrder/index.js +1 -1
  38. package/dist/solution/ScanOrder/types.d.ts +1 -0
  39. package/dist/solution/ShopDiscount/index.d.ts +3 -0
  40. package/dist/solution/ShopDiscount/index.js +161 -78
  41. package/dist/solution/ShopDiscount/utils.d.ts +1 -0
  42. package/dist/solution/ShopDiscount/utils.js +40 -1
  43. package/dist/solution/VenueBooking/index.d.ts +19 -0
  44. package/dist/solution/VenueBooking/index.js +978 -748
  45. package/dist/solution/VenueBooking/types.d.ts +2 -0
  46. package/dist/types/index.d.ts +1 -0
  47. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  48. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  49. package/lib/model/strategy/adapter/walletPass/evaluator.js +4 -2
  50. package/lib/modules/Discount/availability.d.ts +7 -0
  51. package/lib/modules/Discount/availability.js +91 -0
  52. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  53. package/lib/modules/Discount/entitlementPass.js +184 -0
  54. package/lib/modules/Discount/entitlementState.d.ts +8 -0
  55. package/lib/modules/Discount/entitlementState.js +206 -0
  56. package/lib/modules/Discount/index.d.ts +6 -3
  57. package/lib/modules/Discount/index.js +66 -16
  58. package/lib/modules/Discount/types.d.ts +34 -5
  59. package/lib/modules/Holder/index.d.ts +48 -0
  60. package/lib/modules/Holder/index.js +402 -0
  61. package/lib/modules/Holder/types.d.ts +123 -0
  62. package/lib/modules/Holder/types.js +17 -0
  63. package/lib/modules/Holder/utils.d.ts +13 -0
  64. package/lib/modules/Holder/utils.js +71 -0
  65. package/lib/modules/Order/index.d.ts +1 -0
  66. package/lib/modules/Order/index.js +14 -0
  67. package/lib/modules/Order/types.d.ts +2 -0
  68. package/lib/modules/Order/utils.d.ts +10 -0
  69. package/lib/modules/Order/utils.js +36 -5
  70. package/lib/modules/Product/types.d.ts +7 -0
  71. package/lib/modules/Rules/entitlementLines.d.ts +8 -0
  72. package/lib/modules/Rules/entitlementLines.js +158 -0
  73. package/lib/modules/Rules/index.d.ts +12 -2
  74. package/lib/modules/Rules/index.js +304 -70
  75. package/lib/modules/Rules/types.d.ts +2 -2
  76. package/lib/modules/index.d.ts +1 -0
  77. package/lib/modules/index.js +3 -1
  78. package/lib/plugins/window.d.ts +3 -0
  79. package/lib/solution/BookingByStep/index.d.ts +17 -2
  80. package/lib/solution/BookingByStep/index.js +39 -0
  81. package/lib/solution/BookingByStep/types.d.ts +2 -1
  82. package/lib/solution/BookingByStep/types.js +5 -0
  83. package/lib/solution/ScanOrder/index.js +1 -1
  84. package/lib/solution/ScanOrder/types.d.ts +1 -0
  85. package/lib/solution/ShopDiscount/index.d.ts +3 -0
  86. package/lib/solution/ShopDiscount/index.js +78 -28
  87. package/lib/solution/ShopDiscount/utils.d.ts +1 -0
  88. package/lib/solution/ShopDiscount/utils.js +42 -1
  89. package/lib/solution/VenueBooking/index.d.ts +19 -0
  90. package/lib/solution/VenueBooking/index.js +134 -16
  91. package/lib/solution/VenueBooking/types.d.ts +2 -0
  92. package/lib/types/index.d.ts +1 -0
  93. package/package.json +1 -1
@@ -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 } from "./examples";
@@ -26,6 +26,8 @@ export declare class WalletPassEvaluator {
26
26
  /** 检查代金券/折扣卡是否可用 并返回config */
27
27
  checkVoucherAvailability(input: EvaluatorInput): {
28
28
  isAvailable: boolean;
29
+ reason: string | undefined;
30
+ reasonCode: string | undefined;
29
31
  config: {
30
32
  [x: string]: any;
31
33
  };
@@ -232,7 +232,7 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
232
232
  }, {
233
233
  key: "checkVoucherAvailability",
234
234
  value: function checkVoucherAvailability(input) {
235
- var _results$, _results$2;
235
+ var _results$, _results$2, _results$3, _results$4;
236
236
  var orderTotalAmount = input.orderTotalAmount,
237
237
  products = input.products,
238
238
  vouchers = input.vouchers;
@@ -240,7 +240,9 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
240
240
  var isAvailable = ((_results$ = results[0]) === null || _results$ === void 0 ? void 0 : _results$.isApplicable) || false;
241
241
  return {
242
242
  isAvailable: isAvailable,
243
- 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)
243
+ reason: (_results$2 = results[0]) === null || _results$2 === void 0 ? void 0 : _results$2.reason,
244
+ reasonCode: (_results$3 = results[0]) === null || _results$3 === void 0 ? void 0 : _results$3.reasonCode,
245
+ 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)
244
246
  };
245
247
  }
246
248
 
@@ -0,0 +1,7 @@
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' | 'not_shared_at_store' | undefined;
7
+ export declare function getDiscountUsageBlockReason(discount: Discount): string | undefined;
@@ -0,0 +1,52 @@
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$franchisee_, _discount$metadata;
34
+ if (discount.is_franchisor_pass === 1 && ((_discount$franchisee_ = discount.franchisee_wallet_pass) === null || _discount$franchisee_ === void 0 ? void 0 : _discount$franchisee_.use) !== 'enabled') {
35
+ return 'not_shared_at_store';
36
+ }
37
+ if (discount.limit_status && discount.limit_status !== 'enable') {
38
+ return 'disabled';
39
+ }
40
+ if ((isEntitlementPass(discount) || discount.par_value != null) && !hasAvailableDiscountBalance(discount) || getDiscountUsageLimitFailKey(discount) === 'total_credits') {
41
+ return 'exhausted';
42
+ }
43
+ // 自定义日程沿用快照语义,不使用遗留固定有效期字段推断过期。
44
+ if (((_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.validity_type) !== 'custom_schedule_validity' && discount.expire_time) {
45
+ var expiry = dayjs(discount.expire_time);
46
+ if (expiry.isValid() && !dayjs().isBefore(expiry)) return 'expired';
47
+ }
48
+ return undefined;
49
+ }
50
+ export function getDiscountUsageBlockReason(discount) {
51
+ return getDiscountLifecycleReason(discount) || getDiscountUsageLimitFailKey(discount) || (discount.unified_available_status != null && String(discount.unified_available_status) !== '' && Number(discount.unified_available_status) === 0 ? 'server_unavailable' : undefined);
52
+ }
@@ -0,0 +1,34 @@
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 {};
@@ -0,0 +1,147 @@
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
+ }
@@ -0,0 +1,8 @@
1
+ import type { Discount } from './types';
2
+ export declare function hasEntitlementDiscount(product: any): boolean;
3
+ export declare function isPersistedEntitlementLine(product: any, mappedProduct?: any): boolean;
4
+ /** Refresh authoritative balances while retaining the user's scan/selection state. */
5
+ export declare function mergeEntitlementDiscountLists(current: Discount[], incoming: Discount[], observed?: Discount[]): Discount[];
6
+ export declare function retainScannedEntitlements(current: Discount[], scanned: Discount[]): Discount[];
7
+ /** Historical uses are display records; backend balance already excludes them. */
8
+ export declare function withCommittedEntitlementDetails(discounts: Discount[], products: any[], getProduct: (item: any) => any): Discount[];
@@ -0,0 +1,205 @@
1
+ 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); }
2
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
+ 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); }
11
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
13
+ 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; }
14
+ import { cloneDeep } from 'lodash-es';
15
+ import Decimal from 'decimal.js';
16
+ import { getDiscountLifecycleReason } from "./availability";
17
+ import { isEntitlementPass, resolveEntitlementQuota } from "./entitlementPass";
18
+ function getEntitlementDiscountLines(product) {
19
+ var _product$_origin$prod, _product$_origin, _product$_originData, _ref, _product$discount_lis, _ref2, _ref3, _ref4, _product$product_bund, _product$_extend;
20
+ var nested = (_product$_origin$prod = product === null || product === void 0 || (_product$_origin = product._origin) === null || _product$_origin === void 0 ? void 0 : _product$_origin.product) !== null && _product$_origin$prod !== void 0 ? _product$_origin$prod : product === null || product === void 0 || (_product$_originData = product._originData) === null || _product$_originData === void 0 ? void 0 : _product$_originData.product;
21
+ return [{
22
+ discount_list: (_ref = (_product$discount_lis = product === null || product === void 0 ? void 0 : product.discount_list) !== null && _product$discount_lis !== void 0 ? _product$discount_lis : nested === null || nested === void 0 ? void 0 : nested.discount_list) !== null && _ref !== void 0 ? _ref : []
23
+ }].concat(_toConsumableArray((_ref2 = (_ref3 = (_ref4 = (_product$product_bund = product === null || product === void 0 ? void 0 : product.product_bundle) !== null && _product$product_bund !== void 0 ? _product$product_bund : product === null || product === void 0 ? void 0 : product.bundle) !== null && _ref4 !== void 0 ? _ref4 : product === null || product === void 0 || (_product$_extend = product._extend) === null || _product$_extend === void 0 || (_product$_extend = _product$_extend.other) === null || _product$_extend === void 0 ? void 0 : _product$_extend.bundle) !== null && _ref3 !== void 0 ? _ref3 : nested === null || nested === void 0 ? void 0 : nested.product_bundle) !== null && _ref2 !== void 0 ? _ref2 : []));
24
+ }
25
+ export function hasEntitlementDiscount(product) {
26
+ return getEntitlementDiscountLines(product).some(function (line) {
27
+ return (line.discount_list || []).some(isEntitlementPass);
28
+ });
29
+ }
30
+ export function isPersistedEntitlementLine(product, mappedProduct) {
31
+ var _product$_origin$prod2, _product$_origin2, _product$_originData2, _product$_origin3, _product$_originData3, _product$_extend2, _product$metadata;
32
+ var nested = (_product$_origin$prod2 = product === null || product === void 0 || (_product$_origin2 = product._origin) === null || _product$_origin2 === void 0 ? void 0 : _product$_origin2.product) !== null && _product$_origin$prod2 !== void 0 ? _product$_origin$prod2 : product === null || product === void 0 || (_product$_originData2 = product._originData) === null || _product$_originData2 === void 0 ? void 0 : _product$_originData2.product;
33
+ var persisted = [product === null || product === void 0 ? void 0 : product.order_detail_id, product === null || product === void 0 ? void 0 : product.booking_id, product === null || product === void 0 || (_product$_origin3 = product._origin) === null || _product$_origin3 === void 0 ? void 0 : _product$_origin3.booking_id, product === null || product === void 0 || (_product$_originData3 = product._originData) === null || _product$_originData3 === void 0 ? void 0 : _product$_originData3.booking_id, product === null || product === void 0 || (_product$_extend2 = product._extend) === null || _product$_extend2 === void 0 ? void 0 : _product$_extend2.order_detail_id, nested === null || nested === void 0 ? void 0 : nested.order_detail_id, nested === null || nested === void 0 ? void 0 : nested.booking_id, mappedProduct === null || mappedProduct === void 0 ? void 0 : mappedProduct.order_detail_id, mappedProduct === null || mappedProduct === void 0 ? void 0 : mappedProduct.booking_id].some(function (value) {
34
+ return value !== undefined && value !== null && value !== '' && value !== 0 && value !== '0';
35
+ });
36
+ var lines = getEntitlementDiscountLines(mappedProduct !== null && mappedProduct !== void 0 ? mappedProduct : product);
37
+ // 已有预约上刚选的卡仍属本次使用,只有接口回传的明细才计入历史。
38
+ return lines.some(function (line) {
39
+ return (line.discount_list || []).some(isEntitlementPass);
40
+ }) && (persisted && (product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.entitlement_source_identity) == null || lines.some(function (line) {
41
+ return (line.discount_list || []).some(function (item) {
42
+ return isEntitlementPass(item) && item.id;
43
+ });
44
+ }));
45
+ }
46
+
47
+ /** Refresh authoritative balances while retaining the user's scan/selection state. */
48
+ export function mergeEntitlementDiscountLists(current, incoming) {
49
+ var observed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : incoming;
50
+ var previous = new Map(current.map(function (item) {
51
+ return [String(item.id), item];
52
+ }));
53
+ var observedById = new Map(observed.map(function (item) {
54
+ return [String(item.id), item];
55
+ }));
56
+ var next = new Map();
57
+ current.filter(function (item) {
58
+ return item.isScan;
59
+ }).forEach(function (item) {
60
+ var fresh = observedById.get(String(item.id));
61
+ if (isEntitlementPass(item) && getDiscountLifecycleReason(fresh || item)) return;
62
+ next.set(String(item.id), item);
63
+ });
64
+ incoming.forEach(function (item) {
65
+ var old = previous.get(String(item.id));
66
+ if (old !== null && old !== void 0 && old.isScan && !isEntitlementPass(item)) return;
67
+ next.set(String(item.id), old && isEntitlementPass(item) ? _objectSpread(_objectSpread({}, item), {}, {
68
+ isScan: old.isScan,
69
+ isSelected: old.isSelected,
70
+ isManualSelect: old.isManualSelect
71
+ }) : item);
72
+ });
73
+ return _toConsumableArray(next.values());
74
+ }
75
+ export function retainScannedEntitlements(current, scanned) {
76
+ var result = new Map(current.map(function (item) {
77
+ return [String(item.id), item];
78
+ }));
79
+ scanned.filter(function (item) {
80
+ return isEntitlementPass(item) && !getDiscountLifecycleReason(item);
81
+ }).forEach(function (item) {
82
+ var previous = result.get(String(item.id));
83
+ var committed = item.committedAppliedProductDetails || (previous === null || previous === void 0 ? void 0 : previous.committedAppliedProductDetails) || [];
84
+ var isAvailable = !!item.isAvailable;
85
+ result.set(String(item.id), _objectSpread(_objectSpread({}, item), {}, {
86
+ isScan: true,
87
+ isAvailable: isAvailable,
88
+ isSelected: committed.length > 0,
89
+ reasonCode: isAvailable ? undefined : item.reasonCode || 'product_not_applicable',
90
+ committedAppliedProductDetails: committed,
91
+ appliedProductDetails: committed,
92
+ savedAmount: committed.length ? previous === null || previous === void 0 ? void 0 : previous.savedAmount : 0
93
+ }));
94
+ });
95
+ return _toConsumableArray(result.values());
96
+ }
97
+
98
+ /** Historical uses are display records; backend balance already excludes them. */
99
+ export function withCommittedEntitlementDetails(discounts, products, getProduct) {
100
+ var savedAmount = function savedAmount(details) {
101
+ return details.reduce(function (sum, detail) {
102
+ var _detail$discount;
103
+ return sum.plus(new Decimal(((_detail$discount = detail.discount) === null || _detail$discount === void 0 ? void 0 : _detail$discount.fixed_amount) || 0).times(detail._num));
104
+ }, new Decimal(0)).toNumber();
105
+ };
106
+ var committed = new Map();
107
+ var _iterator = _createForOfIteratorHelper(products),
108
+ _step;
109
+ try {
110
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
111
+ var origin = _step.value;
112
+ var product = getProduct(origin);
113
+ var persisted = isPersistedEntitlementLine(origin, product);
114
+ var lines = [product].concat(_toConsumableArray(product.bundle || []));
115
+ var bundleKeys = new Set((product.bundle || []).flatMap(function (line) {
116
+ return (line.discount_list || []).map(function (detail) {
117
+ var _detail$discount$reso, _detail$discount2, _detail$metadata;
118
+ return "".concat((_detail$discount$reso = (_detail$discount2 = detail.discount) === null || _detail$discount2 === void 0 ? void 0 : _detail$discount2.resource_id) !== null && _detail$discount$reso !== void 0 ? _detail$discount$reso : detail.id, ":").concat((_detail$metadata = detail.metadata) === null || _detail$metadata === void 0 ? void 0 : _detail$metadata.custom_product_bundle_map_id);
119
+ });
120
+ }));
121
+ var _iterator2 = _createForOfIteratorHelper(lines),
122
+ _step2;
123
+ try {
124
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
125
+ var line = _step2.value;
126
+ var _iterator3 = _createForOfIteratorHelper(line.discount_list || []),
127
+ _step3;
128
+ try {
129
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
130
+ var _detail$metadata2, _detail$discount$reso2, _detail$discount3, _ref5, _detail$discount$reso3, _detail$discount4, _ref6, _ref7, _detail$metadata$num, _detail$metadata3, _ref8, _product$quantity, _detail$discount$fixe, _detail$discount5;
131
+ var detail = _step3.value;
132
+ var bundleId = (_detail$metadata2 = detail.metadata) === null || _detail$metadata2 === void 0 ? void 0 : _detail$metadata2.custom_product_bundle_map_id;
133
+ if (!isEntitlementPass(detail) || !persisted && !detail.id || line === product && bundleId && bundleKeys.has("".concat((_detail$discount$reso2 = (_detail$discount3 = detail.discount) === null || _detail$discount3 === void 0 ? void 0 : _detail$discount3.resource_id) !== null && _detail$discount$reso2 !== void 0 ? _detail$discount$reso2 : detail.id, ":").concat(bundleId))) continue;
134
+ var id = (_ref5 = (_detail$discount$reso3 = (_detail$discount4 = detail.discount) === null || _detail$discount4 === void 0 ? void 0 : _detail$discount4.resource_id) !== null && _detail$discount$reso3 !== void 0 ? _detail$discount$reso3 : detail.resource_id) !== null && _ref5 !== void 0 ? _ref5 : detail.id;
135
+ if (id == null) continue;
136
+ var lineUses = Number((_ref6 = (_ref7 = (_detail$metadata$num = (_detail$metadata3 = detail.metadata) === null || _detail$metadata3 === void 0 ? void 0 : _detail$metadata3.num) !== null && _detail$metadata$num !== void 0 ? _detail$metadata$num : line.num) !== null && _ref7 !== void 0 ? _ref7 : line.quantity) !== null && _ref6 !== void 0 ? _ref6 : 1);
137
+ if (!Number.isFinite(lineUses) || lineUses <= 0) continue;
138
+ var count = lineUses * (line === product && !bundleId ? 1 : Number((_ref8 = (_product$quantity = product.quantity) !== null && _product$quantity !== void 0 ? _product$quantity : product.num) !== null && _ref8 !== void 0 ? _ref8 : 1));
139
+ var list = committed.get(String(id)) || [];
140
+ list.push(_objectSpread(_objectSpread({}, cloneDeep(detail)), {}, {
141
+ _num: count,
142
+ metadata: _objectSpread(_objectSpread({}, detail.metadata), {}, {
143
+ num: count
144
+ }),
145
+ discount: _objectSpread(_objectSpread({}, detail.discount), {}, {
146
+ fixed_amount: (_detail$discount$fixe = (_detail$discount5 = detail.discount) === null || _detail$discount5 === void 0 ? void 0 : _detail$discount5.fixed_amount) !== null && _detail$discount$fixe !== void 0 ? _detail$discount$fixe : new Decimal(detail.amount || 0).div(bundleId ? lineUses : 1).toNumber()
147
+ })
148
+ }));
149
+ committed.set(String(id), list);
150
+ }
151
+ } catch (err) {
152
+ _iterator3.e(err);
153
+ } finally {
154
+ _iterator3.f();
155
+ }
156
+ }
157
+ } catch (err) {
158
+ _iterator2.e(err);
159
+ } finally {
160
+ _iterator2.f();
161
+ }
162
+ }
163
+ } catch (err) {
164
+ _iterator.e(err);
165
+ } finally {
166
+ _iterator.f();
167
+ }
168
+ var next = discounts.map(function (item) {
169
+ if (!isEntitlementPass(item)) return item;
170
+ var details = committed.get(String(item.id)) || [];
171
+ committed.delete(String(item.id));
172
+ return _objectSpread(_objectSpread(_objectSpread({}, item), {}, {
173
+ committedAppliedProductDetails: details,
174
+ isEditMode: details.length > 0 && !resolveEntitlementQuota(item)
175
+ }, item.isEditMode && resolveEntitlementQuota(item) ? {
176
+ isDisabled: false
177
+ } : {}), details.length && !resolveEntitlementQuota(item) ? {
178
+ isSelected: true,
179
+ isDisabled: true,
180
+ isUsed: true,
181
+ appliedProductDetails: details,
182
+ savedAmount: savedAmount(details)
183
+ } : {});
184
+ });
185
+ committed.forEach(function (details, id) {
186
+ var _first$discount;
187
+ var first = details[0];
188
+ next.push(_objectSpread(_objectSpread({}, first), {}, {
189
+ id: Number(id),
190
+ tag: 'entitlement_pass',
191
+ type: 'entitlement_pass',
192
+ format_title: (_first$discount = first.discount) === null || _first$discount === void 0 ? void 0 : _first$discount.title,
193
+ isEditMode: true,
194
+ isSelected: true,
195
+ isDisabled: true,
196
+ isUsed: true,
197
+ isAvailable: true,
198
+ committedAppliedProductDetails: details,
199
+ appliedProductDetails: details,
200
+ applicableProductDetails: [],
201
+ savedAmount: savedAmount(details)
202
+ }));
203
+ });
204
+ return next;
205
+ }
@@ -23,11 +23,14 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
23
23
  customer_id: number;
24
24
  with_wallet_pass_holder: 0 | 1;
25
25
  request_timezone: string;
26
- order_id?: number;
26
+ order_id?: number | string;
27
+ with_entitlement_pass?: 0 | 1;
28
+ filter_order_wallet_pass_usage?: 0 | 1;
27
29
  }): Promise<Discount[]>;
28
- batchSearch(code: string, options?: {
30
+ batchSearch(code: string, customerIdOrOptions?: number | {
29
31
  customerId?: number;
30
- orderId?: number;
32
+ orderId?: number | string;
33
+ withEntitlementPass?: boolean;
31
34
  }): Promise<DiscountWithReason>;
32
35
  batchSearchByProductIds(productIds: number[]): Promise<any>;
33
36
  filterEnabledDiscountList(discountList: Discount[]): Discount[];