@pisell/pisellos 2.1.174 → 2.1.176

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 (60) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
  3. package/dist/model/strategy/adapter/walletPass/evaluator.js +2 -4
  4. package/dist/modules/Discount/index.d.ts +3 -6
  5. package/dist/modules/Discount/index.js +23 -125
  6. package/dist/modules/Discount/types.d.ts +5 -34
  7. package/dist/modules/OpenData/types.d.ts +1 -0
  8. package/dist/modules/ProductList/index.js +13 -6
  9. package/dist/modules/Rules/index.d.ts +2 -12
  10. package/dist/modules/Rules/index.js +113 -377
  11. package/dist/modules/Rules/types.d.ts +2 -2
  12. package/dist/plugins/window.d.ts +0 -2
  13. package/dist/solution/BookingByStep/index.d.ts +1 -1
  14. package/dist/solution/ScanOrder/index.d.ts +7 -5
  15. package/dist/solution/ScanOrder/index.js +123 -31
  16. package/dist/solution/ScanOrder/resourceSchedule.d.ts +12 -0
  17. package/dist/solution/ScanOrder/resourceSchedule.js +300 -0
  18. package/dist/solution/ScanOrder/types.d.ts +9 -1
  19. package/dist/solution/ShopDiscount/index.d.ts +0 -3
  20. package/dist/solution/ShopDiscount/index.js +78 -161
  21. package/dist/solution/ShopDiscount/utils.d.ts +0 -1
  22. package/dist/solution/ShopDiscount/utils.js +1 -40
  23. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
  24. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -4
  25. package/lib/modules/Discount/index.d.ts +3 -6
  26. package/lib/modules/Discount/index.js +16 -66
  27. package/lib/modules/Discount/types.d.ts +5 -34
  28. package/lib/modules/OpenData/types.d.ts +1 -0
  29. package/lib/modules/ProductList/index.js +8 -1
  30. package/lib/modules/Rules/index.d.ts +2 -12
  31. package/lib/modules/Rules/index.js +69 -303
  32. package/lib/modules/Rules/types.d.ts +2 -2
  33. package/lib/plugins/window.d.ts +0 -2
  34. package/lib/solution/BookingByStep/index.d.ts +1 -1
  35. package/lib/solution/ScanOrder/index.d.ts +7 -5
  36. package/lib/solution/ScanOrder/index.js +90 -12
  37. package/lib/solution/ScanOrder/resourceSchedule.d.ts +12 -0
  38. package/lib/solution/ScanOrder/resourceSchedule.js +272 -0
  39. package/lib/solution/ScanOrder/types.d.ts +9 -1
  40. package/lib/solution/ShopDiscount/index.d.ts +0 -3
  41. package/lib/solution/ShopDiscount/index.js +28 -78
  42. package/lib/solution/ShopDiscount/utils.d.ts +0 -1
  43. package/lib/solution/ShopDiscount/utils.js +1 -42
  44. package/package.json +1 -1
  45. package/dist/modules/Discount/availability.d.ts +0 -7
  46. package/dist/modules/Discount/availability.js +0 -52
  47. package/dist/modules/Discount/entitlementPass.d.ts +0 -34
  48. package/dist/modules/Discount/entitlementPass.js +0 -147
  49. package/dist/modules/Discount/entitlementState.d.ts +0 -8
  50. package/dist/modules/Discount/entitlementState.js +0 -205
  51. package/dist/modules/Rules/entitlementLines.d.ts +0 -8
  52. package/dist/modules/Rules/entitlementLines.js +0 -157
  53. package/lib/modules/Discount/availability.d.ts +0 -7
  54. package/lib/modules/Discount/availability.js +0 -91
  55. package/lib/modules/Discount/entitlementPass.d.ts +0 -34
  56. package/lib/modules/Discount/entitlementPass.js +0 -184
  57. package/lib/modules/Discount/entitlementState.d.ts +0 -8
  58. package/lib/modules/Discount/entitlementState.js +0 -206
  59. package/lib/modules/Rules/entitlementLines.d.ts +0 -8
  60. package/lib/modules/Rules/entitlementLines.js +0 -158
@@ -40,9 +40,6 @@ var import_utils = require("./utils");
40
40
  var import_types = require("../../modules/Rules/types");
41
41
  var import_decimal = __toESM(require("decimal.js"));
42
42
  var import_lodash_es = require("lodash-es");
43
- var import_entitlementPass = require("../../modules/Discount/entitlementPass");
44
- var import_availability = require("../../modules/Discount/availability");
45
- var import_entitlementState = require("../../modules/Discount/entitlementState");
46
43
  var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
47
44
  constructor(name, version) {
48
45
  super(name, version);
@@ -50,7 +47,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
50
47
  this.defaultVersion = "1.0.0";
51
48
  this.isSolution = true;
52
49
  this.options = {};
53
- this.entitlementPassEnabled = false;
54
50
  this.store = {
55
51
  customer: null,
56
52
  productList: [],
@@ -64,15 +60,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
64
60
  orderId: void 0
65
61
  };
66
62
  }
67
- // 由使用多次卡的预约组件显式开启,其他入口沿用原券流程。
68
- setEntitlementPassEnabled(enabled) {
69
- var _a, _b;
70
- this.entitlementPassEnabled = enabled;
71
- (_a = this.store.rules) == null ? void 0 : _a.setEntitlementPassEnabled(enabled);
72
- if (!enabled) {
73
- (_b = this.store.discount) == null ? void 0 : _b.setDiscountList(this.getDiscountList().filter((item) => !(0, import_entitlementPass.isEntitlementPass)(item)));
74
- }
75
- }
76
63
  // =========== 生命周期方法 ===========
77
64
  async initialize(core, options) {
78
65
  var _a, _b;
@@ -146,8 +133,9 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
146
133
  `${this.name}:onCustomerChange`,
147
134
  (customer) => {
148
135
  var _a;
149
- if (!this.entitlementPassEnabled && ((_a = this.options.otherParams) == null ? void 0 : _a.cacheId) && this.getDiscountList().length)
136
+ if (((_a = this.options.otherParams) == null ? void 0 : _a.cacheId) && this.getDiscountList().length) {
150
137
  return;
138
+ }
151
139
  this.loadPrepareConfig({
152
140
  customerId: customer.id,
153
141
  action: "create",
@@ -198,13 +186,9 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
198
186
  // }
199
187
  // 设置客户
200
188
  async setCustomer(customer) {
201
- var _a, _b;
189
+ var _a;
202
190
  if (((_a = this.store.customer) == null ? void 0 : _a.id) !== customer.id) {
203
191
  this.store.customer = customer;
204
- if (this.entitlementPassEnabled) {
205
- const retained = this.getDiscountList().filter((item) => !(0, import_entitlementPass.isEntitlementPass)(item) || item.isEditMode || item.isScan && String(item.customer_id) === String(customer.id));
206
- await ((_b = this.store.discount) == null ? void 0 : _b.setDiscountList(retained));
207
- }
208
192
  await this.core.effects.emit(
209
193
  `${this.name}:onCustomerChange`,
210
194
  customer
@@ -238,8 +222,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
238
222
  },
239
223
  options
240
224
  ) || { productList, discountList: this.getDiscountList() };
241
- if (this.entitlementPassEnabled)
242
- this.store.productList = newProductList || productList;
243
225
  if (newDiscountList) {
244
226
  newDiscountList = this.setDiscountList(newDiscountList);
245
227
  }
@@ -297,13 +279,9 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
297
279
  }
298
280
  // 扫码输入code
299
281
  async scanCode(code, customerId) {
300
- var _a, _b, _c, _d, _e;
282
+ var _a, _b, _c;
301
283
  try {
302
- const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, {
303
- customerId,
304
- orderId: this.store.orderId,
305
- withEntitlementPass: this.entitlementPassEnabled
306
- })) || { discountList: [], unavailableReasonKey: null };
284
+ const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId, orderId: this.store.orderId })) || { discountList: [], unavailableReasonKey: null };
307
285
  const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
308
286
  const rulesModule = this.store.rules;
309
287
  if (!rulesModule) {
@@ -331,7 +309,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
331
309
  };
332
310
  });
333
311
  const currentSelectedDiscountList = this.getDiscountList().filter((n) => n.isSelected);
334
- if (!withScanList.some(import_entitlementPass.isEntitlementPass) && currentSelectedDiscountList.length && currentSelectedDiscountList.some((n) => withScanList.some((m) => m.id === n.id))) {
312
+ if (currentSelectedDiscountList.length && currentSelectedDiscountList.some((n) => withScanList.some((m) => m.id === n.id))) {
335
313
  return {
336
314
  type: "clientCalc",
337
315
  isAvailable: true,
@@ -342,7 +320,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
342
320
  const {
343
321
  productList: newProductList,
344
322
  discountList: newDiscountList,
345
- evaluatedDiscountList,
346
323
  isAvailable,
347
324
  unavailableReason
348
325
  } = rulesModule.isDiscountListAvailable({
@@ -356,42 +333,22 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
356
333
  productList: this.store.productList || [],
357
334
  discountList: this.getDiscountList()
358
335
  };
359
- let isAccepted = isAvailable;
360
336
  if (isAvailable) {
361
- if (this.entitlementPassEnabled)
362
- this.setProductList(newProductList || []);
363
337
  this.setDiscountList(newDiscountList || []);
364
338
  this.store.originalDiscountList = newDiscountList || [];
365
- if (!this.entitlementPassEnabled)
366
- this.setProductList(newProductList || []);
339
+ this.setProductList(newProductList || []);
367
340
  if (this.isWalkIn() && resultDiscountList.length && ((_c = this.options.otherParams) == null ? void 0 : _c.platform) === "shop") {
368
341
  await this.getCustomerWallet(
369
342
  resultDiscountList[0].customer_id
370
343
  );
371
344
  }
372
345
  }
373
- if (!isAvailable) {
374
- const ids = new Set(withScanList.map((item) => String(item.id)));
375
- const retainable = (evaluatedDiscountList || []).filter((item) => ids.has(String(item.id)) && (0, import_entitlementPass.isEntitlementPass)(item) && !(0, import_availability.getDiscountLifecycleReason)(item));
376
- if (retainable.length) {
377
- this.setDiscountList((0, import_entitlementState.retainScannedEntitlements)(this.getDiscountList(), retainable));
378
- isAccepted = true;
379
- }
380
- }
381
- if (this.entitlementPassEnabled) {
382
- this.store.originalDiscountList = this.getDiscountList();
383
- await ((_d = this.store.discount) == null ? void 0 : _d.setOriginalDiscountList(this.getDiscountList()));
384
- }
385
346
  return {
386
347
  type: "clientCalc",
387
348
  isAvailable: isAvailable || false,
388
- isAccepted,
389
- productList: isAvailable ? newProductList : this.store.productList || [],
390
- discountList: this.getDiscountList(),
391
- unavailableReason,
392
- unavailableReasonKey: ((_e = (evaluatedDiscountList || []).find(
393
- (item) => withScanList.some((scanned) => String(scanned.id) === String(item.id)) && item.reasonCode
394
- )) == null ? void 0 : _e.reasonCode) || unavailableReasonKey
349
+ productList: newProductList || this.store.productList || [],
350
+ discountList: newDiscountList || this.getDiscountList(),
351
+ unavailableReason
395
352
  };
396
353
  } catch (error) {
397
354
  console.error("[ShopDiscount] 扫码出错:", error);
@@ -429,7 +386,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
429
386
  }
430
387
  // 设置优惠券列表
431
388
  setDiscountList(discountList) {
432
- var _a, _b;
389
+ var _a;
433
390
  const productList = this.store.productList || [];
434
391
  const editModeDiscountList = [];
435
392
  productList.forEach((item) => {
@@ -437,7 +394,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
437
394
  if (item.booking_id) {
438
395
  const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(item);
439
396
  (item.discount_list || []).forEach((discount) => {
440
- var _a3, _b2, _c, _d, _e;
397
+ var _a3, _b, _c, _d, _e;
441
398
  if (discount.id && ["good_pass", "discount_card"].includes(discount.type)) {
442
399
  const index = editModeDiscountList.findIndex((n) => {
443
400
  var _a4;
@@ -458,7 +415,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
458
415
  name: discount.name || discount.discount.title.auto,
459
416
  isEditMode: true,
460
417
  limited_relation_product_data: {},
461
- savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.quantity) || (product == null ? void 0 : product.num) || 1).plus(((_b2 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b2.product_discount_difference) || 0).toNumber(),
418
+ savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.quantity) || (product == null ? void 0 : product.num) || 1).plus(((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.product_discount_difference) || 0).toNumber(),
462
419
  isAvailable: true,
463
420
  id: ((_c = discount.discount) == null ? void 0 : _c.resource_id) || discount.id,
464
421
  format_title: ((_d = discount.discount) == null ? void 0 : _d.title) || discount.format_title,
@@ -471,10 +428,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
471
428
  });
472
429
  }
473
430
  });
474
- const newDiscountList = this.entitlementPassEnabled ? (0, import_entitlementState.withCommittedEntitlementDetails)([
475
- ...editModeDiscountList.filter((item) => !(0, import_entitlementPass.isEntitlementPass)(item)),
476
- ...discountList.filter((item) => (0, import_entitlementPass.isEntitlementPass)(item) || !item.isDisabled)
477
- ], productList, ((_a = this.hooks) == null ? void 0 : _a.getProduct) || ((item) => item)) : [...editModeDiscountList, ...discountList.filter((item) => !item.isDisabled && !(0, import_entitlementPass.isEntitlementPass)(item))];
431
+ const newDiscountList = [
432
+ ...editModeDiscountList,
433
+ ...discountList.filter((item) => !item.isDisabled)
434
+ ];
478
435
  const isProductFree = (id) => {
479
436
  var _a2;
480
437
  const targetProduct = productList.find((n) => n.id === id);
@@ -504,7 +461,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
504
461
  item.isDisabledForProductUsed = false;
505
462
  }
506
463
  });
507
- (_b = this.store.discount) == null ? void 0 : _b.setDiscountList(newDiscountList);
464
+ (_a = this.store.discount) == null ? void 0 : _a.setDiscountList(newDiscountList);
508
465
  this.emitDiscountListChange(newDiscountList);
509
466
  return newDiscountList;
510
467
  }
@@ -521,9 +478,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
521
478
  });
522
479
  if (result == null ? void 0 : result.data) {
523
480
  const { ...customer } = result.data;
524
- const customerUpdate = this.setCustomer(customer);
525
- if (this.entitlementPassEnabled)
526
- await customerUpdate;
481
+ this.setCustomer(customer);
527
482
  await this.core.effects.emit(
528
483
  `${this.name}:onScanCustomerChange`,
529
484
  customer
@@ -552,9 +507,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
552
507
  }
553
508
  // 加载准备配置
554
509
  async loadPrepareConfig(params) {
555
- var _a, _b, _c, _d, _e, _f;
510
+ var _a, _b, _c, _d, _e;
556
511
  try {
557
- const entitlementPassEnabled = this.entitlementPassEnabled;
558
512
  const orderId = this.store.orderId;
559
513
  const customerId = params.customerId || ((_a = this.getCustomer()) == null ? void 0 : _a.id);
560
514
  const goodPassList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
@@ -563,25 +517,21 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
563
517
  with_good_pass: 1,
564
518
  with_discount_card: 1,
565
519
  with_wallet_pass_holder: 1,
566
- ...this.entitlementPassEnabled ? { with_entitlement_pass: 1, filter_order_wallet_pass_usage: 0 } : {},
567
520
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
568
521
  ...orderId ? { order_id: orderId } : {}
569
522
  }));
570
- if (entitlementPassEnabled !== this.entitlementPassEnabled)
571
- return;
572
- if (entitlementPassEnabled && (String(customerId) !== String((_c = this.getCustomer()) == null ? void 0 : _c.id) || String(orderId) !== String(this.store.orderId)))
573
- return;
574
- const newDiscountList = (0, import_entitlementState.mergeEntitlementDiscountLists)(
575
- this.getDiscountList(),
576
- goodPassList || [],
577
- (_d = this.store.discount) == null ? void 0 : _d.getOriginalDiscountList()
523
+ const scanDiscount = (_c = this.getDiscountList()) == null ? void 0 : _c.filter(
524
+ (item) => item.isScan
578
525
  );
526
+ const scanDiscountIds = scanDiscount.map((n) => n.id);
527
+ const newGoodPassList = goodPassList == null ? void 0 : goodPassList.filter((n) => !scanDiscountIds.includes(n.id));
528
+ const newDiscountList = [...scanDiscount, ...newGoodPassList || []];
579
529
  this.store.originalDiscountList = newDiscountList;
580
- await ((_e = this.store.discount) == null ? void 0 : _e.setOriginalDiscountList(newDiscountList));
581
- const filteredDiscountList = newDiscountList.filter((item) => (0, import_entitlementPass.isEntitlementPass)(item) || this.filterDiscountListByBookingTime([item], this.store.currentBookingTime).length > 0);
530
+ await ((_d = this.store.discount) == null ? void 0 : _d.setOriginalDiscountList(newDiscountList));
531
+ const filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
582
532
  this.store.filteredDiscountList = filteredDiscountList;
583
533
  this.setDiscountList(filteredDiscountList || []);
584
- if ((_f = this.store.productList) == null ? void 0 : _f.length) {
534
+ if ((_e = this.store.productList) == null ? void 0 : _e.length) {
585
535
  const result = this.calcDiscount(this.store.productList);
586
536
  await this.core.effects.emit(
587
537
  `${this.name}:onLoadPrepareCalcResult`,
@@ -89,4 +89,3 @@ export declare const calculateOrderLevelDiscountAllocation: (discount: Discount,
89
89
  discountAmount: number;
90
90
  difference: number;
91
91
  }>;
92
- export declare const getDiscountTimeUnavailableReason: (discount: Discount, useTime: string) => 'not_started' | 'time_limit' | 'outside_schedule' | undefined;
@@ -35,7 +35,6 @@ __export(utils_exports, {
35
35
  getDiscountAmount: () => getDiscountAmount,
36
36
  getDiscountListAmount: () => getDiscountListAmount,
37
37
  getDiscountListAmountTotal: () => getDiscountListAmountTotal,
38
- getDiscountTimeUnavailableReason: () => getDiscountTimeUnavailableReason,
39
38
  isAllNormalProduct: () => isAllNormalProduct,
40
39
  isNormalProductByDurationSchedule: () => isNormalProductByDurationSchedule,
41
40
  isOrderLevelFixedAmountDiscount: () => isOrderLevelFixedAmountDiscount,
@@ -44,11 +43,6 @@ __export(utils_exports, {
44
43
  module.exports = __toCommonJS(utils_exports);
45
44
  var import_decimal = __toESM(require("decimal.js"));
46
45
  var import_dayjs = __toESM(require("dayjs"));
47
- var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
48
- var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
49
- var import_entitlementPass = require("../../modules/Discount/entitlementPass");
50
- import_dayjs.default.extend(import_isSameOrAfter.default);
51
- import_dayjs.default.extend(import_isSameOrBefore.default);
52
46
  var uniqueById = (arr, key = "id") => {
53
47
  const seen = /* @__PURE__ */ new Set();
54
48
  return arr.filter((item) => !seen.has(item[key]) && seen.add(item[key]));
@@ -62,7 +56,7 @@ var isAllNormalProduct = (items) => {
62
56
  };
63
57
  var getDiscountAmount = (discount, total, price) => {
64
58
  var _a;
65
- if ((0, import_entitlementPass.isFullCoveragePass)(discount)) {
59
+ if (discount.tag === "good_pass") {
66
60
  return new import_decimal.default(price).minus(new import_decimal.default(price || 0)).toNumber();
67
61
  }
68
62
  const isFixedAmount = ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount";
@@ -299,8 +293,6 @@ var filterDiscountListByBookingTime = (discountList, bookingTime) => {
299
293
  }
300
294
  return discountList.filter((discount) => {
301
295
  var _a, _b;
302
- if ((0, import_entitlementPass.isEntitlementPass)(discount))
303
- return !getDiscountTimeUnavailableReason(discount, bookingTime);
304
296
  if (((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.validity_type) === "custom_schedule_validity") {
305
297
  return getDateIsInSchedule(bookingTime, ((_b = discount.custom_schedule_snapshot) == null ? void 0 : _b.data) || []);
306
298
  }
@@ -399,38 +391,6 @@ var calculateOrderLevelDiscountAllocation = (discount, applicableProducts) => {
399
391
  }
400
392
  return result;
401
393
  };
402
- var getDiscountTimeUnavailableReason = (discount, useTime) => {
403
- var _a, _b, _c, _d, _e;
404
- const useTimeDayjs = (0, import_dayjs.default)(useTime);
405
- if (!useTimeDayjs.isValid())
406
- return "time_limit";
407
- try {
408
- if (((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.validity_type) === "custom_schedule_validity") {
409
- return getDateIsInSchedule(useTime, ((_b = discount.custom_schedule_snapshot) == null ? void 0 : _b.data) || []) ? void 0 : "outside_schedule";
410
- }
411
- const isHasStart = !!discount.start_date && !!discount.start_time;
412
- const startDate = (0, import_dayjs.default)(`${discount.start_date} ${discount.start_time}`);
413
- if (isHasStart) {
414
- if (!startDate.isValid())
415
- return "time_limit";
416
- if (useTimeDayjs.isBefore(startDate))
417
- return "not_started";
418
- }
419
- const expireTime = discount.expire_time ? (0, import_dayjs.default)(discount.expire_time) : null;
420
- const isBeforeExpire = expireTime ? expireTime.isValid() && useTimeDayjs.isBefore(expireTime) : true;
421
- if (!isBeforeExpire)
422
- return "time_limit";
423
- const validity = (_d = (_c = discount.extension_data) == null ? void 0 : _c.find(
424
- (field) => field.field_key === "valid_times"
425
- )) == null ? void 0 : _d.value;
426
- if ((validity == null ? void 0 : validity.restrict_use_by_schedule) === true && !getDateIsInSchedule(useTime, ((_e = discount.custom_schedule_snapshot) == null ? void 0 : _e.data) || [])) {
427
- return "outside_schedule";
428
- }
429
- return void 0;
430
- } catch (error) {
431
- return "time_limit";
432
- }
433
- };
434
394
  // Annotate the CommonJS export names for ESM import in node:
435
395
  0 && (module.exports = {
436
396
  calculateOrderLevelDiscountAllocation,
@@ -439,7 +399,6 @@ var getDiscountTimeUnavailableReason = (discount, useTime) => {
439
399
  getDiscountAmount,
440
400
  getDiscountListAmount,
441
401
  getDiscountListAmountTotal,
442
- getDiscountTimeUnavailableReason,
443
402
  isAllNormalProduct,
444
403
  isNormalProductByDurationSchedule,
445
404
  isOrderLevelFixedAmountDiscount,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.174",
4
+ "version": "2.1.176",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -1,7 +0,0 @@
1
- import type { Discount, DiscountFilterRejectKey } from './types';
2
- /** 周期限制只影响当前使用;total_credits 才代表整张卡的次数耗尽。 */
3
- export declare function getDiscountUsageLimitFailKey(discount: Discount): DiscountFilterRejectKey | null;
4
- export declare function hasAvailableDiscountBalance(discount: Discount): boolean;
5
- /** 按卡本身当前生命周期判断;预约时间或一次日程不匹配不代表已失效。 */
6
- export declare function getDiscountLifecycleReason(discount: Discount): 'disabled' | 'exhausted' | 'expired' | 'not_shared_at_store' | undefined;
7
- export declare function getDiscountUsageBlockReason(discount: Discount): string | undefined;
@@ -1,52 +0,0 @@
1
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- import dayjs from 'dayjs';
8
- import Decimal from 'decimal.js';
9
- import { hasAvailableEntitlementUses, isEntitlementPass } from "./entitlementPass";
10
-
11
- /** 周期限制只影响当前使用;total_credits 才代表整张卡的次数耗尽。 */
12
- export function getDiscountUsageLimitFailKey(discount) {
13
- var _discount$extension_d, _limits$find;
14
- var value = (_discount$extension_d = discount.extension_data) === null || _discount$extension_d === void 0 || (_discount$extension_d = _discount$extension_d.find(function (field) {
15
- return field.field_key === 'usage_credits';
16
- })) === null || _discount$extension_d === void 0 ? void 0 : _discount$extension_d.value;
17
- if (!value) return null;
18
- var limits = [['total_credits', discount.total_order_behavior_count], ['per_user_limit', discount.customer_order_behavior_count], ['max_per_day', discount.today_order_behavior_count], ['max_per_week', discount.week_order_behavior_count], ['max_per_month', discount.month_order_behavior_count]];
19
- return ((_limits$find = limits.find(function (_ref) {
20
- var _ref2 = _slicedToArray(_ref, 2),
21
- key = _ref2[0],
22
- count = _ref2[1];
23
- return Number(value[key]) > 0 && Number(count || 0) >= Number(value[key]);
24
- })) === null || _limits$find === void 0 ? void 0 : _limits$find[0]) || null;
25
- }
26
- export function hasAvailableDiscountBalance(discount) {
27
- if (isEntitlementPass(discount)) return hasAvailableEntitlementUses(discount);
28
- return new Decimal(discount.par_value || 0).minus(discount.used_par_value || 0).greaterThan(0);
29
- }
30
-
31
- /** 按卡本身当前生命周期判断;预约时间或一次日程不匹配不代表已失效。 */
32
- export function getDiscountLifecycleReason(discount) {
33
- var _discount$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
- }
@@ -1,34 +0,0 @@
1
- export declare const ENTITLEMENT_PASS_TYPE = "entitlement_pass";
2
- export declare const GOOD_PASS_TYPE = "good_pass";
3
- type DiscountLike = {
4
- id?: number | string | null;
5
- tag?: unknown;
6
- type?: unknown;
7
- discount?: object | null;
8
- metadata?: object | null;
9
- extension_data?: unknown;
10
- balance?: unknown;
11
- expire_time?: unknown;
12
- };
13
- export type EntitlementQuota = {
14
- type: 'limited';
15
- value: number;
16
- balance: number;
17
- } | {
18
- type: 'unlimited';
19
- value: null;
20
- balance: null;
21
- };
22
- export declare function isEntitlementPass(discount: DiscountLike | null | undefined): boolean;
23
- export declare function isFullCoveragePass(discount: DiscountLike | null | undefined): boolean;
24
- /**
25
- * Resolve the authoritative total-use contract for an Entitlement Pass.
26
- * Invalid or missing configuration fails closed. Legacy mode/total_uses fields
27
- * are intentionally unsupported.
28
- */
29
- export declare function resolveEntitlementQuota(discount: DiscountLike | null | undefined): EntitlementQuota | null;
30
- export declare function getRemainingEntitlementUses(discount: DiscountLike | null | undefined, usedCount: number, requestedCount: number): number;
31
- export declare function hasAvailableEntitlementUses(discount: DiscountLike | null | undefined): boolean;
32
- /** Sort Entitlement Passes by expiry, finite balance, then card instance id. */
33
- export declare function compareEntitlementPassPriority(left: DiscountLike, right: DiscountLike): number;
34
- export {};
@@ -1,147 +0,0 @@
1
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
8
- import dayjs from 'dayjs';
9
- export var ENTITLEMENT_PASS_TYPE = 'entitlement_pass';
10
- export var GOOD_PASS_TYPE = 'good_pass';
11
- function getDiscountType(discount) {
12
- var nestedDiscount = discount === null || discount === void 0 ? void 0 : discount.discount;
13
- return String((discount === null || discount === void 0 ? void 0 : discount.tag) || (discount === null || discount === void 0 ? void 0 : discount.type) || (nestedDiscount === null || nestedDiscount === void 0 ? void 0 : nestedDiscount.tag) || (nestedDiscount === null || nestedDiscount === void 0 ? void 0 : nestedDiscount.type) || '');
14
- }
15
- export function isEntitlementPass(discount) {
16
- return getDiscountType(discount) === ENTITLEMENT_PASS_TYPE;
17
- }
18
- export function isFullCoveragePass(discount) {
19
- var type = getDiscountType(discount);
20
- return type === GOOD_PASS_TYPE || type === ENTITLEMENT_PASS_TYPE;
21
- }
22
- function resolveIncludedUses(discount) {
23
- var _discount$extension_d;
24
- var metadata = discount.metadata;
25
- var hasMetadataIncludedUses = !!metadata && _typeof(metadata) === 'object' && Object.prototype.hasOwnProperty.call(metadata, 'included_uses');
26
- var rawValue = hasMetadataIncludedUses ? metadata === null || metadata === void 0 ? void 0 : metadata.included_uses : Array.isArray(discount.extension_data) ? (_discount$extension_d = discount.extension_data.find(function (item) {
27
- return (item === null || item === void 0 ? void 0 : item.field_key) === 'included_uses';
28
- })) === null || _discount$extension_d === void 0 ? void 0 : _discount$extension_d.value : undefined;
29
- if (!rawValue || _typeof(rawValue) !== 'object' || Array.isArray(rawValue)) {
30
- return null;
31
- }
32
- var includedUses = rawValue;
33
- if (includedUses.type === 'unlimited' && includedUses.value === null) {
34
- return {
35
- type: 'unlimited',
36
- value: null
37
- };
38
- }
39
- if (includedUses.type === 'limited' && typeof includedUses.value === 'number' && Number.isInteger(includedUses.value) && includedUses.value >= 1 && includedUses.value <= 9999) {
40
- return {
41
- type: 'limited',
42
- value: includedUses.value
43
- };
44
- }
45
- return null;
46
- }
47
- function resolveNonNegativeInteger(value) {
48
- if (typeof value !== 'number' && typeof value !== 'string' || typeof value === 'string' && value.trim() === '') {
49
- return null;
50
- }
51
- var normalizedValue = Number(value);
52
- if (!Number.isInteger(normalizedValue) || normalizedValue < 0) return null;
53
- return normalizedValue;
54
- }
55
-
56
- /**
57
- * Resolve the authoritative total-use contract for an Entitlement Pass.
58
- * Invalid or missing configuration fails closed. Legacy mode/total_uses fields
59
- * are intentionally unsupported.
60
- */
61
- export function resolveEntitlementQuota(discount) {
62
- if (!isEntitlementPass(discount)) return null;
63
- var includedUses = resolveIncludedUses(discount);
64
- if (!includedUses) return null;
65
- if (includedUses.type === 'unlimited') {
66
- return {
67
- type: 'unlimited',
68
- value: null,
69
- balance: null
70
- };
71
- }
72
- var balance = resolveNonNegativeInteger(discount === null || discount === void 0 ? void 0 : discount.balance);
73
- if (balance === null) return null;
74
- return {
75
- type: 'limited',
76
- value: includedUses.value,
77
- balance: balance
78
- };
79
- }
80
- export function getRemainingEntitlementUses(discount, usedCount, requestedCount) {
81
- var quota = resolveEntitlementQuota(discount);
82
- var normalizedRequestedCount = Math.max(Math.floor(Number(requestedCount) || 0), 0);
83
- if (!quota || normalizedRequestedCount <= 0) return 0;
84
- if (quota.type === 'unlimited') return normalizedRequestedCount;
85
- var normalizedUsedCount = Math.max(Math.floor(Number(usedCount) || 0), 0);
86
- return Math.min(Math.max(quota.balance - normalizedUsedCount, 0), normalizedRequestedCount);
87
- }
88
- export function hasAvailableEntitlementUses(discount) {
89
- var quota = resolveEntitlementQuota(discount);
90
- return !!quota && (quota.type === 'unlimited' || quota.balance > 0);
91
- }
92
- function resolveExpireTimestamp(value) {
93
- if (typeof value !== 'string' || !value.trim()) return Number.POSITIVE_INFINITY;
94
- var normalizedValue = value.trim();
95
- var calendarParts = normalizedValue.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/);
96
- if (calendarParts) {
97
- var _calendarParts = _slicedToArray(calendarParts, 7),
98
- year = _calendarParts[1],
99
- month = _calendarParts[2],
100
- day = _calendarParts[3],
101
- _calendarParts$ = _calendarParts[4],
102
- hour = _calendarParts$ === void 0 ? '0' : _calendarParts$,
103
- _calendarParts$2 = _calendarParts[5],
104
- minute = _calendarParts$2 === void 0 ? '0' : _calendarParts$2,
105
- _calendarParts$3 = _calendarParts[6],
106
- second = _calendarParts$3 === void 0 ? '0' : _calendarParts$3;
107
- var yearNumber = Number(year);
108
- var monthNumber = Number(month);
109
- var dayNumber = Number(day);
110
- var hourNumber = Number(hour);
111
- var minuteNumber = Number(minute);
112
- var secondNumber = Number(second);
113
- var daysInMonth = new Date(Date.UTC(yearNumber, monthNumber, 0)).getUTCDate();
114
- if (yearNumber <= 0 || monthNumber < 1 || monthNumber > 12 || dayNumber < 1 || dayNumber > daysInMonth || hourNumber < 0 || hourNumber > 23 || minuteNumber < 0 || minuteNumber > 59 || secondNumber < 0 || secondNumber > 59) {
115
- return Number.POSITIVE_INFINITY;
116
- }
117
- }
118
- var date = dayjs(normalizedValue);
119
- return date.isValid() ? date.valueOf() : Number.POSITIVE_INFINITY;
120
- }
121
- function compareIds(left, right) {
122
- var leftNumber = Number(left);
123
- var rightNumber = Number(right);
124
- if (Number.isFinite(leftNumber) && Number.isFinite(rightNumber)) {
125
- return leftNumber - rightNumber;
126
- }
127
- return String(left !== null && left !== void 0 ? left : '').localeCompare(String(right !== null && right !== void 0 ? right : ''), undefined, {
128
- numeric: true
129
- });
130
- }
131
-
132
- /** Sort Entitlement Passes by expiry, finite balance, then card instance id. */
133
- export function compareEntitlementPassPriority(left, right) {
134
- var expireDifference = resolveExpireTimestamp(left.expire_time) - resolveExpireTimestamp(right.expire_time);
135
- if (!Number.isNaN(expireDifference) && expireDifference !== 0) {
136
- return expireDifference;
137
- }
138
- var leftQuota = resolveEntitlementQuota(left);
139
- var rightQuota = resolveEntitlementQuota(right);
140
- var leftBalance = (leftQuota === null || leftQuota === void 0 ? void 0 : leftQuota.type) === 'limited' ? leftQuota.balance : Number.POSITIVE_INFINITY;
141
- var rightBalance = (rightQuota === null || rightQuota === void 0 ? void 0 : rightQuota.type) === 'limited' ? rightQuota.balance : Number.POSITIVE_INFINITY;
142
- var balanceDifference = leftBalance - rightBalance;
143
- if (!Number.isNaN(balanceDifference) && balanceDifference !== 0) {
144
- return balanceDifference;
145
- }
146
- return compareIds(left.id, right.id);
147
- }
@@ -1,8 +0,0 @@
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[];