@pisell/pisellos 2.2.309 → 2.2.310

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 (121) hide show
  1. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  2. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
  3. package/dist/modules/BookingContext/index.js +4 -4
  4. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +58 -19
  5. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +24 -12
  6. package/dist/modules/Customer/index.js +6 -3
  7. package/dist/modules/Customer/types.d.ts +2 -0
  8. package/dist/modules/Discount/availability.d.ts +7 -0
  9. package/dist/modules/Discount/availability.js +49 -0
  10. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  11. package/dist/modules/Discount/entitlementPass.js +147 -0
  12. package/dist/modules/Discount/index.d.ts +2 -2
  13. package/dist/modules/Discount/index.js +37 -151
  14. package/dist/modules/Discount/types.d.ts +36 -5
  15. package/dist/modules/OpenData/index.d.ts +1 -1
  16. package/dist/modules/OpenData/index.js +21 -12
  17. package/dist/modules/Order/index.d.ts +32 -4
  18. package/dist/modules/Order/index.js +733 -373
  19. package/dist/modules/Order/types.d.ts +17 -0
  20. package/dist/modules/Order/utils/orderCollectionIdentity.js +16 -12
  21. package/dist/modules/Order/utils.d.ts +14 -2
  22. package/dist/modules/Order/utils.js +275 -76
  23. package/dist/modules/Payment/index.d.ts +0 -5
  24. package/dist/modules/Payment/index.js +35 -85
  25. package/dist/modules/Payment/types.d.ts +21 -1
  26. package/dist/modules/Payment/types.js +2 -0
  27. package/dist/modules/Payment/walletpass.d.ts +1 -1
  28. package/dist/modules/Payment/walletpass.js +80 -47
  29. package/dist/modules/ProductList/index.js +18 -5
  30. package/dist/modules/Rules/index.d.ts +2 -2
  31. package/dist/modules/Rules/index.js +480 -186
  32. package/dist/modules/Rules/types.d.ts +4 -0
  33. package/dist/server/index.js +8 -5
  34. package/dist/server/modules/order/index.js +6 -0
  35. package/dist/server/modules/order/types.d.ts +12 -0
  36. package/dist/server/modules/payment/index.d.ts +25 -6
  37. package/dist/server/modules/payment/index.js +660 -133
  38. package/dist/server/utils/small-ticket.d.ts +8 -5
  39. package/dist/server/utils/small-ticket.js +1269 -199
  40. package/dist/solution/BaseSales/index.d.ts +11 -2
  41. package/dist/solution/BaseSales/index.js +1463 -1173
  42. package/dist/solution/BaseSales/types.d.ts +7 -3
  43. package/dist/solution/BaseSales/utils/cartPromotion.js +141 -126
  44. package/dist/solution/BookingByStep/index.d.ts +1 -1
  45. package/dist/solution/BookingTicket/index.d.ts +12 -3
  46. package/dist/solution/BookingTicket/index.js +663 -542
  47. package/dist/solution/BookingTicket/types.d.ts +5 -1
  48. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  49. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +338 -147
  50. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  51. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  52. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +19 -6
  53. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  54. package/dist/solution/ShopDiscount/index.js +99 -42
  55. package/dist/solution/ShopDiscount/utils.d.ts +4 -2
  56. package/dist/solution/ShopDiscount/utils.js +43 -23
  57. package/dist/solution/UnifiedBookingSales/index.d.ts +2 -2
  58. package/dist/solution/UnifiedBookingSales/index.js +5 -5
  59. package/dist/utils/os-private-payload.d.ts +5 -0
  60. package/dist/utils/os-private-payload.js +17 -0
  61. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  62. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
  63. package/lib/modules/BookingContext/index.js +3 -3
  64. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +35 -6
  65. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +13 -6
  66. package/lib/modules/Customer/index.js +5 -1
  67. package/lib/modules/Customer/types.d.ts +2 -0
  68. package/lib/modules/Discount/availability.d.ts +7 -0
  69. package/lib/modules/Discount/availability.js +43 -0
  70. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  71. package/lib/modules/Discount/entitlementPass.js +141 -0
  72. package/lib/modules/Discount/index.d.ts +2 -2
  73. package/lib/modules/Discount/index.js +23 -129
  74. package/lib/modules/Discount/types.d.ts +36 -5
  75. package/lib/modules/OpenData/index.d.ts +1 -1
  76. package/lib/modules/OpenData/index.js +11 -2
  77. package/lib/modules/Order/index.d.ts +32 -4
  78. package/lib/modules/Order/index.js +341 -71
  79. package/lib/modules/Order/types.d.ts +17 -0
  80. package/lib/modules/Order/utils/orderCollectionIdentity.js +14 -11
  81. package/lib/modules/Order/utils.d.ts +14 -2
  82. package/lib/modules/Order/utils.js +186 -3
  83. package/lib/modules/Payment/index.d.ts +0 -5
  84. package/lib/modules/Payment/index.js +3 -28
  85. package/lib/modules/Payment/types.d.ts +21 -1
  86. package/lib/modules/Payment/types.js +1 -0
  87. package/lib/modules/Payment/walletpass.d.ts +1 -1
  88. package/lib/modules/Payment/walletpass.js +29 -9
  89. package/lib/modules/ProductList/index.js +14 -1
  90. package/lib/modules/Rules/index.d.ts +2 -2
  91. package/lib/modules/Rules/index.js +357 -110
  92. package/lib/modules/Rules/types.d.ts +4 -0
  93. package/lib/server/index.js +8 -5
  94. package/lib/server/modules/order/index.js +6 -0
  95. package/lib/server/modules/order/types.d.ts +12 -0
  96. package/lib/server/modules/payment/index.d.ts +25 -6
  97. package/lib/server/modules/payment/index.js +350 -78
  98. package/lib/server/utils/small-ticket.d.ts +8 -5
  99. package/lib/server/utils/small-ticket.js +1009 -121
  100. package/lib/solution/BaseSales/index.d.ts +11 -2
  101. package/lib/solution/BaseSales/index.js +164 -30
  102. package/lib/solution/BaseSales/types.d.ts +7 -3
  103. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -4
  104. package/lib/solution/BookingByStep/index.d.ts +1 -1
  105. package/lib/solution/BookingTicket/index.d.ts +12 -3
  106. package/lib/solution/BookingTicket/index.js +103 -41
  107. package/lib/solution/BookingTicket/types.d.ts +5 -1
  108. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  109. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +174 -42
  110. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  111. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  112. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +11 -3
  113. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  114. package/lib/solution/ShopDiscount/index.js +55 -9
  115. package/lib/solution/ShopDiscount/utils.d.ts +4 -2
  116. package/lib/solution/ShopDiscount/utils.js +42 -25
  117. package/lib/solution/UnifiedBookingSales/index.d.ts +2 -2
  118. package/lib/solution/UnifiedBookingSales/index.js +5 -5
  119. package/lib/utils/os-private-payload.d.ts +5 -0
  120. package/lib/utils/os-private-payload.js +22 -0
  121. package/package.json +1 -1
@@ -28,6 +28,8 @@ export declare class WalletPassEvaluator {
28
28
  /** 检查代金券/折扣卡是否可用 并返回config */
29
29
  checkVoucherAvailability(input: EvaluatorInput): {
30
30
  isAvailable: boolean;
31
+ reason: string | undefined;
32
+ reasonCode: string | undefined;
31
33
  config: {
32
34
  [x: string]: any;
33
35
  };
@@ -283,7 +283,7 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
283
283
  }, {
284
284
  key: "checkVoucherAvailability",
285
285
  value: function checkVoucherAvailability(input) {
286
- var _results$, _results$2;
286
+ var _results$, _results$2, _results$3, _results$4;
287
287
  var orderTotalAmount = input.orderTotalAmount,
288
288
  products = input.products,
289
289
  vouchers = input.vouchers;
@@ -291,7 +291,9 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
291
291
  var isAvailable = ((_results$ = results[0]) === null || _results$ === void 0 ? void 0 : _results$.isApplicable) || false;
292
292
  return {
293
293
  isAvailable: isAvailable,
294
- 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)
294
+ reason: (_results$2 = results[0]) === null || _results$2 === void 0 ? void 0 : _results$2.reason,
295
+ reasonCode: (_results$3 = results[0]) === null || _results$3 === void 0 ? void 0 : _results$3.reasonCode,
296
+ config: _objectSpread({}, (_results$4 = results[0]) === null || _results$4 === void 0 || (_results$4 = _results$4.strategyResult) === null || _results$4 === void 0 || (_results$4 = _results$4.config) === null || _results$4 === void 0 || (_results$4 = _results$4.metadata) === null || _results$4 === void 0 ? void 0 : _results$4.custom)
295
297
  };
296
298
  }
297
299
 
@@ -26,7 +26,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
26
26
  import dayjs from 'dayjs';
27
27
  import { BaseModule } from "../BaseModule";
28
28
  import { RequestModeENUM } from "../../plugins/request";
29
- import { normalizeRuntimePlatform } from "../../utils/platform";
29
+ import { isCustomerUserPlatform } from "../../utils/platform";
30
30
  import { BookingContextEvent } from "./types";
31
31
  import { formatResourceListAndMap } from "./utils/formatResourceList";
32
32
  export * from "./types";
@@ -158,9 +158,9 @@ export function buildBookingConfigQueryKey() {
158
158
  }
159
159
  function resolveBookingConfigRequest(platform) {
160
160
  var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
161
- var isH5 = normalizeRuntimePlatform(platform) === 'h5';
162
- var endpoint = isH5 ? H5_BOOKING_CONFIG_ENDPOINT : BOOKING_CONFIG_ENDPOINT;
163
- var query = isH5 ? {
161
+ var isCustomerPlatform = isCustomerUserPlatform(platform);
162
+ var endpoint = isCustomerPlatform ? H5_BOOKING_CONFIG_ENDPOINT : BOOKING_CONFIG_ENDPOINT;
163
+ var query = isCustomerPlatform ? {
164
164
  item_type: params.item_type || DEFAULT_BOOKING_CONFIG_PARAMS.item_type
165
165
  } : _objectSpread(_objectSpread({}, DEFAULT_BOOKING_CONFIG_PARAMS), params);
166
166
  var keys = Object.keys(query).sort();
@@ -13,6 +13,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
13
13
  import dayjs from 'dayjs';
14
14
  import { getProductSkuOptions } from "../../Order/utils";
15
15
  import { resolveManualDiscountMessage } from "../../Order/utils/manualProductDiscount";
16
+ import { isEntitlementPass } from "../../Discount/entitlementPass";
16
17
  import { buildProductOptionStringFromOrderLine } from "./orderLineDisplay";
17
18
  function safeFormat(value, fmt) {
18
19
  if (value === undefined || value === null) return undefined;
@@ -125,20 +126,56 @@ function resolveProductCover(product, booking, sourceProduct) {
125
126
  var _ref6, _cover;
126
127
  return (_ref6 = (_cover = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.cover) !== null && _cover !== void 0 ? _cover : product.product_cover) !== null && _ref6 !== void 0 ? _ref6 : '';
127
128
  }
128
- function resolveMainProductPrice(product, fallback) {
129
- var _metadata$main_produc;
130
- var metadata = product.metadata || {};
131
- var value = (_metadata$main_produc = metadata.main_product_original_price) !== null && _metadata$main_produc !== void 0 ? _metadata$main_produc : metadata.source_product_price;
129
+ function toFinitePrice(value) {
130
+ if (value === undefined || value === null || value === '') return null;
132
131
  var parsed = Number(value);
133
- return Number.isFinite(parsed) ? parsed : fallback;
132
+ return Number.isFinite(parsed) ? parsed : null;
133
+ }
134
+ function hasEntitlementPassDiscount(product) {
135
+ var hasEntitlementDiscount = function hasEntitlementDiscount(discountList) {
136
+ return Array.isArray(discountList) && discountList.some(isEntitlementPass);
137
+ };
138
+ return hasEntitlementDiscount(product.discount_list) || Array.isArray(product.product_bundle) && product.product_bundle.some(function (bundle) {
139
+ return hasEntitlementDiscount(bundle === null || bundle === void 0 ? void 0 : bundle.discount_list);
140
+ });
141
+ }
142
+ function resolveMainProductPrice(product, fallback, sourceProduct) {
143
+ var _variant, _metadata$origin, _ref7, _ref8, _price, _metadata$origin2, _metadata$origin3;
144
+ var restoreEntitlementPrice = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
145
+ var metadata = product.metadata || {};
146
+ if (!restoreEntitlementPrice) {
147
+ var _metadata$main_produc;
148
+ var value = (_metadata$main_produc = metadata.main_product_original_price) !== null && _metadata$main_produc !== void 0 ? _metadata$main_produc : metadata.source_product_price;
149
+ var parsed = Number(value);
150
+ return Number.isFinite(parsed) ? parsed : fallback;
151
+ }
152
+ var sourcePrice = toFinitePrice(metadata.source_product_price);
153
+ if (sourcePrice !== null) return sourcePrice;
154
+ var variantId = Number(product.product_variant_id || 0);
155
+ var variantList = (_variant = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.variant) !== null && _variant !== void 0 ? _variant : (_metadata$origin = metadata.origin) === null || _metadata$origin === void 0 ? void 0 : _metadata$origin.variant;
156
+ if (variantId > 0 && Array.isArray(variantList)) {
157
+ var _matched$price;
158
+ var matched = variantList.find(function (variant) {
159
+ return Number(variant === null || variant === void 0 ? void 0 : variant.id) === variantId;
160
+ });
161
+ var variantPrice = toFinitePrice((_matched$price = matched === null || matched === void 0 ? void 0 : matched.price) !== null && _matched$price !== void 0 ? _matched$price : matched === null || matched === void 0 ? void 0 : matched.base_price);
162
+ if (variantPrice !== null) return variantPrice;
163
+ }
164
+ var catalogPrice = toFinitePrice((_ref7 = (_ref8 = (_price = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _price !== void 0 ? _price : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.base_price) !== null && _ref8 !== void 0 ? _ref8 : (_metadata$origin2 = metadata.origin) === null || _metadata$origin2 === void 0 ? void 0 : _metadata$origin2.price) !== null && _ref7 !== void 0 ? _ref7 : (_metadata$origin3 = metadata.origin) === null || _metadata$origin3 === void 0 ? void 0 : _metadata$origin3.base_price);
165
+ if (catalogPrice !== null) return catalogPrice;
166
+
167
+ // legacy 数据没有 source_product_price 时,main_product_original_price
168
+ // 仍比已被月卡改写为 0 的 selling_price 更可靠。
169
+ var legacyMainPrice = toFinitePrice(metadata.main_product_original_price);
170
+ return legacyMainPrice !== null && legacyMainPrice !== void 0 ? legacyMainPrice : fallback;
134
171
  }
135
172
  function mapOrderBundleToOtherBundle(bundle) {
136
173
  return bundle.map(function (item) {
137
- var _ref7, _ref8, _item$original_price;
174
+ var _ref9, _ref10, _item$original_price;
138
175
  return _objectSpread(_objectSpread({}, item), {}, {
139
176
  // 后端历史订单可能没有 original_price;此时 price 是折前毛价,
140
177
  // bundle_selling_price 已包含折扣,不能把它当成编辑时的新原价。
141
- original_price: (_ref7 = (_ref8 = (_item$original_price = item.original_price) !== null && _item$original_price !== void 0 ? _item$original_price : item.product_price) !== null && _ref8 !== void 0 ? _ref8 : item.price) !== null && _ref7 !== void 0 ? _ref7 : item.bundle_selling_price
178
+ original_price: (_ref9 = (_ref10 = (_item$original_price = item.original_price) !== null && _item$original_price !== void 0 ? _item$original_price : item.product_price) !== null && _ref10 !== void 0 ? _ref10 : item.price) !== null && _ref9 !== void 0 ? _ref9 : item.bundle_selling_price
142
179
  });
143
180
  });
144
181
  }
@@ -169,10 +206,10 @@ function synthesizeProductResourceFromBooking(booking) {
169
206
  });
170
207
  if (relationIdsByForm.size === 0) return undefined;
171
208
  return {
172
- resources: Array.from(relationIdsByForm.entries()).map(function (_ref9) {
173
- var _ref10 = _slicedToArray(_ref9, 2),
174
- formId = _ref10[0],
175
- relationIds = _ref10[1];
209
+ resources: Array.from(relationIdsByForm.entries()).map(function (_ref11) {
210
+ var _ref12 = _slicedToArray(_ref11, 2),
211
+ formId = _ref12[0],
212
+ relationIds = _ref12[1];
176
213
  return {
177
214
  id: formId,
178
215
  status: 1,
@@ -192,15 +229,16 @@ function synthesizeProductResourceFromBooking(booking) {
192
229
  * 调用方须传入与该行关联的 booking(通常 bookings[].product_uid === product.metadata.unique_identification_number)。
193
230
  */
194
231
  export function buildCacheItemFromOrderLine(input) {
195
- var _ref11, _sourceProduct$holder, _sourceProduct$origin, _product$metadata, _product$product_id, _product$selling_pric, _product$original_pri, _booking$metadata$hol, _booking$metadata2, _product$bundle_edit, _product$product_vari, _product$num, _ref12, _product$note, _booking$detail2, _product$metadata2, _product$metadata3, _ref13, _extension_type, _booking$product2, _booking$product3, _price, _product$product_sku, _product$order_detail, _ref14, _booking$id;
232
+ var _ref13, _sourceProduct$holder, _sourceProduct$origin, _product$metadata, _product$product_id, _product$selling_pric, _product$original_pri, _booking$metadata$hol, _booking$metadata2, _product$bundle_edit, _product$product_vari, _product$num, _ref14, _product$note, _booking$detail2, _product$metadata2, _product$metadata3, _ref15, _extension_type, _booking$product2, _booking$product3, _price2, _product$product_sku, _product$order_detail, _ref16, _booking$id;
196
233
  var product = input.product,
197
234
  booking = input.booking,
198
235
  sourceProduct = input.sourceProduct;
199
- var holderConfig = (_ref11 = (_sourceProduct$holder = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.holder_config) !== null && _sourceProduct$holder !== void 0 ? _sourceProduct$holder : sourceProduct === null || sourceProduct === void 0 || (_sourceProduct$origin = sourceProduct.origin) === null || _sourceProduct$origin === void 0 ? void 0 : _sourceProduct$origin.holder_config) !== null && _ref11 !== void 0 ? _ref11 : (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.holder_config;
236
+ var holderConfig = (_ref13 = (_sourceProduct$holder = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.holder_config) !== null && _sourceProduct$holder !== void 0 ? _sourceProduct$holder : sourceProduct === null || sourceProduct === void 0 || (_sourceProduct$origin = sourceProduct.origin) === null || _sourceProduct$origin === void 0 ? void 0 : _sourceProduct$origin.holder_config) !== null && _ref13 !== void 0 ? _ref13 : (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.holder_config;
200
237
  var resolvedId = (_product$product_id = product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.id;
201
238
  var selling = Number((_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : 0);
202
239
  var original = Number((_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : selling);
203
- var mainProductPrice = resolveMainProductPrice(product, selling);
240
+ var shouldRestoreEntitlementPrice = hasEntitlementPassDiscount(product);
241
+ var mainProductPrice = resolveMainProductPrice(product, selling, sourceProduct, shouldRestoreEntitlementPrice);
204
242
  var startDate = safeFormat(booking.start_date, 'YYYY-MM-DD');
205
243
  var endDate = safeFormat(booking.end_date, 'YYYY-MM-DD');
206
244
  var startTime = normalizeTimeString(booking.start_time);
@@ -230,7 +268,7 @@ export function buildCacheItemFromOrderLine(input) {
230
268
  quantity: (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : 1,
231
269
  product_name: productTitle,
232
270
  product_cover: productCover,
233
- note: (_ref12 = (_product$note = product.note) !== null && _product$note !== void 0 ? _product$note : booking === null || booking === void 0 || (_booking$detail2 = booking.detail) === null || _booking$detail2 === void 0 ? void 0 : _booking$detail2.note) !== null && _ref12 !== void 0 ? _ref12 : '',
271
+ note: (_ref14 = (_product$note = product.note) !== null && _product$note !== void 0 ? _product$note : booking === null || booking === void 0 || (_booking$detail2 = booking.detail) === null || _booking$detail2 === void 0 ? void 0 : _booking$detail2.note) !== null && _ref14 !== void 0 ? _ref14 : '',
234
272
  price: mainProductPrice,
235
273
  total: selling,
236
274
  origin_total: original,
@@ -256,7 +294,8 @@ export function buildCacheItemFromOrderLine(input) {
256
294
  }
257
295
  }
258
296
  if (((_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.price_override) != null || manualDiscount) {
259
- extend.priceOverride = selling;
297
+ var _product$metadata$pri, _product$metadata4;
298
+ extend.priceOverride = shouldRestoreEntitlementPrice ? (_product$metadata$pri = (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.price_override) !== null && _product$metadata$pri !== void 0 ? _product$metadata$pri : selling : selling;
260
299
  }
261
300
  if (booking.holder !== undefined) {
262
301
  extend.holder = booking.holder;
@@ -269,9 +308,9 @@ export function buildCacheItemFromOrderLine(input) {
269
308
  } : {}), {}, {
270
309
  id: resolvedId,
271
310
  product_id: resolvedId,
272
- extension_type: (_ref13 = (_extension_type = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.extension_type) !== null && _extension_type !== void 0 ? _extension_type : booking === null || booking === void 0 || (_booking$product2 = booking.product) === null || _booking$product2 === void 0 ? void 0 : _booking$product2.extension_type) !== null && _ref13 !== void 0 ? _ref13 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.extension_type,
311
+ extension_type: (_ref15 = (_extension_type = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.extension_type) !== null && _extension_type !== void 0 ? _extension_type : booking === null || booking === void 0 || (_booking$product2 = booking.product) === null || _booking$product2 === void 0 ? void 0 : _booking$product2.extension_type) !== null && _ref15 !== void 0 ? _ref15 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.extension_type,
273
312
  title: productTitle || (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) || (booking === null || booking === void 0 || (_booking$product3 = booking.product) === null || _booking$product3 === void 0 ? void 0 : _booking$product3.title),
274
- price: (_price = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _price !== void 0 ? _price : selling,
313
+ price: (_price2 = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _price2 !== void 0 ? _price2 : selling,
275
314
  selling_price: product.selling_price,
276
315
  original_price: product.original_price
277
316
  }, Number(((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.open_sold_weight) || 0) === 1 ? {
@@ -283,7 +322,7 @@ export function buildCacheItemFromOrderLine(input) {
283
322
  new: 0,
284
323
  autoClose: false,
285
324
  order_detail_id: (_product$order_detail = product.order_detail_id) !== null && _product$order_detail !== void 0 ? _product$order_detail : null,
286
- booking_id: (_ref14 = (_booking$id = booking.id) !== null && _booking$id !== void 0 ? _booking$id : booking.booking_id) !== null && _ref14 !== void 0 ? _ref14 : 0
325
+ booking_id: (_ref16 = (_booking$id = booking.id) !== null && _booking$id !== void 0 ? _booking$id : booking.booking_id) !== null && _ref16 !== void 0 ? _ref16 : 0
287
326
  });
288
327
  if ((sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.capacity) !== undefined) {
289
328
  base.capacity = sourceProduct.capacity;
@@ -8,6 +8,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
8
8
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
9
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
10
  import { getProductSkuOptions } from "../../Order/utils";
11
+ import { isEntitlementPass } from "../../Discount/entitlementPass";
11
12
  import { buildProductOptionStringFromOrderLine } from "./orderLineDisplay";
12
13
  /**
13
14
  * 从已加车的普通商品 order line 反查 SkuDetailModal edit 所需的 cacheItem。
@@ -52,13 +53,22 @@ function resolveSourceProductPrice(product, sourceProduct) {
52
53
  }
53
54
  return Number((_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : 0);
54
55
  }
56
+ function hasEntitlementPassDiscount(product) {
57
+ var hasEntitlementDiscount = function hasEntitlementDiscount(discountList) {
58
+ return Array.isArray(discountList) && discountList.some(isEntitlementPass);
59
+ };
60
+ return hasEntitlementDiscount(product.discount_list) || Array.isArray(product.product_bundle) && product.product_bundle.some(function (bundle) {
61
+ return hasEntitlementDiscount(bundle === null || bundle === void 0 ? void 0 : bundle.discount_list);
62
+ });
63
+ }
55
64
 
56
65
  /** 订单行 bundle → booking other.bundle(保留 original_price 供 setProductPrice 按比例分摊) */
57
66
  function mapOrderBundleToOtherBundle(bundle) {
67
+ var preferManualPrice = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
58
68
  return bundle.map(function (item) {
59
- var _ref, _ref2, _item$original_price, _ref3, _item$bundle_selling_, _item$original_total, _ref4, _item$num, _ref5, _item$quantity;
69
+ var _ref, _ref2, _item$original_price, _ref3, _item$price, _ref4, _item$bundle_selling_, _item$original_total, _ref5, _item$num, _ref6, _item$quantity;
60
70
  var catalogOriginal = (_ref = (_ref2 = (_item$original_price = item.original_price) !== null && _item$original_price !== void 0 ? _item$original_price : item.product_price) !== null && _ref2 !== void 0 ? _ref2 : item.price) !== null && _ref !== void 0 ? _ref : item.bundle_selling_price;
61
- var selling = (_ref3 = (_item$bundle_selling_ = item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item.price) !== null && _ref3 !== void 0 ? _ref3 : catalogOriginal;
71
+ var selling = preferManualPrice ? (_ref3 = (_item$price = item.price) !== null && _item$price !== void 0 ? _item$price : item.bundle_selling_price) !== null && _ref3 !== void 0 ? _ref3 : catalogOriginal : (_ref4 = (_item$bundle_selling_ = item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item.price) !== null && _ref4 !== void 0 ? _ref4 : catalogOriginal;
62
72
  var _omitBundleSelling = item.bundle_selling_price,
63
73
  rest = _objectWithoutProperties(item, _excluded);
64
74
  var isMarkupOrMarkdown = (item.price_type === 'markdown' || item.price_type === 'markup') && (item.price_type_ext === '' || item.price_type_ext === undefined || item.price_type_ext === null);
@@ -69,13 +79,13 @@ function mapOrderBundleToOtherBundle(bundle) {
69
79
  }, isMarkupOrMarkdown ? {} : {
70
80
  original_total: (_item$original_total = item.original_total) !== null && _item$original_total !== void 0 ? _item$original_total : catalogOriginal
71
81
  }), {}, {
72
- num: (_ref4 = (_item$num = item.num) !== null && _item$num !== void 0 ? _item$num : item.quantity) !== null && _ref4 !== void 0 ? _ref4 : 1,
73
- quantity: (_ref5 = (_item$quantity = item.quantity) !== null && _item$quantity !== void 0 ? _item$quantity : item.num) !== null && _ref5 !== void 0 ? _ref5 : 1
82
+ num: (_ref5 = (_item$num = item.num) !== null && _item$num !== void 0 ? _item$num : item.quantity) !== null && _ref5 !== void 0 ? _ref5 : 1,
83
+ quantity: (_ref6 = (_item$quantity = item.quantity) !== null && _item$quantity !== void 0 ? _item$quantity : item.num) !== null && _ref6 !== void 0 ? _ref6 : 1
74
84
  });
75
85
  });
76
86
  }
77
87
  export function buildNormalProductCacheItemFromOrderLine(input) {
78
- var _product$product_id, _product$selling_pric2, _product$original_pri, _product$metadata, _product$metadata2, _product$product_vari, _originExtend$other, _product$num, _product$product_vari2, _product$num2, _title, _product$note, _originExtend$price, _originExtend$total, _originExtend$origin_, _product$metadata3, _ref6, _title2, _ref7, _cover, _price3, _product$order_detail, _product$product_sku;
88
+ var _product$product_id, _product$selling_pric2, _product$original_pri, _product$metadata, _product$metadata2, _product$metadata3, _product$product_vari, _originExtend$other, _product$num, _product$product_vari2, _product$num2, _title, _product$note, _originExtend$price, _originExtend$total, _originExtend$origin_, _product$metadata4, _originExtend$priceOv, _product$metadata5, _ref7, _title2, _ref8, _cover, _price3, _product$order_detail, _product$product_sku;
79
89
  var product = input.product,
80
90
  sourceProduct = input.sourceProduct;
81
91
  var resolvedId = (_product$product_id = product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.id;
@@ -83,9 +93,11 @@ export function buildNormalProductCacheItemFromOrderLine(input) {
83
93
  var selling = Number((_product$selling_pric2 = product.selling_price) !== null && _product$selling_pric2 !== void 0 ? _product$selling_pric2 : 0);
84
94
  var original = Number((_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : selling);
85
95
  var uid = (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.unique_identification_number;
86
- var option = getProductSkuOptions(product);
87
- var bundle = mapOrderBundleToOtherBundle(Array.isArray(product.product_bundle) ? product.product_bundle : []);
88
96
  var originExtend = (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 || (_product$metadata2 = _product$metadata2.origin) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2._extend;
97
+ var shouldPreserveEntitlementPriceOverride = hasEntitlementPassDiscount(product) && ((originExtend === null || originExtend === void 0 ? void 0 : originExtend.priceOverride) !== undefined || ((_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.price_override) != null);
98
+ var hasPriceOverride = (originExtend === null || originExtend === void 0 ? void 0 : originExtend.priceOverride) !== undefined || shouldPreserveEntitlementPriceOverride;
99
+ var option = getProductSkuOptions(product);
100
+ var bundle = mapOrderBundleToOtherBundle(Array.isArray(product.product_bundle) ? product.product_bundle : [], shouldPreserveEntitlementPriceOverride);
89
101
  var productOptionString = buildProductOptionStringFromOrderLine(product);
90
102
  var discountList = product.discount_list || [];
91
103
  var other = {
@@ -114,12 +126,12 @@ export function buildNormalProductCacheItemFromOrderLine(input) {
114
126
  _skuValue: JSON.parse(JSON.stringify(skuValue)),
115
127
  isNormalProduct: true,
116
128
  metadata: {
117
- product_add_schedule_time: (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.product_add_schedule_time
129
+ product_add_schedule_time: (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.product_add_schedule_time
118
130
  }
119
131
  }, productOptionString ? {
120
132
  product_option_string: productOptionString
121
- } : {}), (originExtend === null || originExtend === void 0 ? void 0 : originExtend.priceOverride) !== undefined ? {
122
- priceOverride: originExtend.priceOverride
133
+ } : {}), hasPriceOverride ? {
134
+ priceOverride: shouldPreserveEntitlementPriceOverride ? (_originExtend$priceOv = originExtend === null || originExtend === void 0 ? void 0 : originExtend.priceOverride) !== null && _originExtend$priceOv !== void 0 ? _originExtend$priceOv : (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.price_override : originExtend === null || originExtend === void 0 ? void 0 : originExtend.priceOverride
123
135
  } : {}), (originExtend === null || originExtend === void 0 ? void 0 : originExtend.bundle_edit) !== undefined ? {
124
136
  bundle_edit: originExtend.bundle_edit
125
137
  } : {});
@@ -131,8 +143,8 @@ export function buildNormalProductCacheItemFromOrderLine(input) {
131
143
  id: resolvedId,
132
144
  product_id: resolvedId,
133
145
  _id: uid,
134
- title: (_ref6 = (_title2 = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) !== null && _title2 !== void 0 ? _title2 : product.product_title) !== null && _ref6 !== void 0 ? _ref6 : '',
135
- cover: (_ref7 = (_cover = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.cover) !== null && _cover !== void 0 ? _cover : product.product_cover) !== null && _ref7 !== void 0 ? _ref7 : '',
146
+ title: (_ref7 = (_title2 = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) !== null && _title2 !== void 0 ? _title2 : product.product_title) !== null && _ref7 !== void 0 ? _ref7 : '',
147
+ cover: (_ref8 = (_cover = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.cover) !== null && _cover !== void 0 ? _cover : product.product_cover) !== null && _ref8 !== void 0 ? _ref8 : '',
136
148
  price: (_price3 = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _price3 !== void 0 ? _price3 : sourcePrice,
137
149
  selling_price: product.selling_price,
138
150
  original_price: product.original_price
@@ -197,16 +197,19 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
197
197
  url = '/franchisee/customer/select-list';
198
198
  }
199
199
  _params$skip = params.skip, skip = _params$skip === void 0 ? 1 : _params$skip, _params$num = params.num, num = _params$num === void 0 ? DEFAULT_PAGE_SIZE : _params$num, search = params.search, _otherParams = _objectWithoutProperties(params, _excluded);
200
- queryParams = _objectSpread(_objectSpread({
200
+ queryParams = _objectSpread(_objectSpread(_objectSpread({
201
201
  skip: skip,
202
202
  num: num,
203
203
  sort_by: SORT_BY,
204
204
  with: ['latestWalletDetail.wallet', 'contactsInfo', 'formRecord'],
205
205
  search_wallet_flag: 1,
206
- search_wallet_pass_flag: 1
206
+ search_wallet_pass_flag: 1,
207
+ filter_franchisor_permissions: ['use']
207
208
  }, search && {
208
209
  search: search
209
- }), _otherParams);
210
+ }), _otherParams), url === '/customer/select-list' ? {
211
+ with_franchisor_data: 1
212
+ } : {});
210
213
  _context2.next = 7;
211
214
  return this.request.get(url, queryParams, {
212
215
  cache: {
@@ -50,6 +50,8 @@ export interface ShopGetCustomerListParams {
50
50
  search_wallet_flag?: 0 | 1;
51
51
  /** wallet pass搜索标识 */
52
52
  search_wallet_pass_flag?: 0 | 1;
53
+ /** 是否查询连锁加盟组合店铺数据 */
54
+ with_franchisor_data?: boolean | 0 | 1;
53
55
  /** 其他筛选参数 */
54
56
  [key: string]: any;
55
57
  }
@@ -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' | undefined;
7
+ export declare function getDiscountUsageBlockReason(discount: Discount): string | undefined;
@@ -0,0 +1,49 @@
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
+ }
@@ -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
+ }
@@ -25,6 +25,8 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
25
25
  with_wallet_pass_holder: 0 | 1;
26
26
  with_available_wallet_flag?: 0 | 1;
27
27
  with_available_wallet_pass_flag?: 0 | 1;
28
+ with_entitlement_pass?: 0 | 1;
29
+ filter_order_wallet_pass_usage?: 0 | 1;
28
30
  with_virtual_currency?: 0 | 1;
29
31
  request_timezone: string;
30
32
  order_id?: number | string;
@@ -36,9 +38,7 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
36
38
  }): Promise<DiscountWithReason>;
37
39
  batchSearchByProductIds(productIds: number[]): Promise<any>;
38
40
  filterEnabledDiscountList(discountList: Discount[]): Discount[];
39
- private checkUsageCreditsLimit;
40
41
  filterEnabledDiscountListWithReason(discountList: Discount[]): DiscountWithReason;
41
- private checkUsageCreditsLimitWithFailKey;
42
42
  uniqueByProductId(discountList: Discount[]): Discount[];
43
43
  filterDiscountListByProductIds(discountList: Discount[], productIds: number[]): Discount[];
44
44
  calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;