@pisell/pisellos 2.1.177 → 2.1.179

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 (47) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  3. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
  4. package/dist/modules/Discount/availability.d.ts +7 -0
  5. package/dist/modules/Discount/availability.js +52 -0
  6. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  7. package/dist/modules/Discount/entitlementPass.js +147 -0
  8. package/dist/modules/Discount/entitlementState.d.ts +8 -0
  9. package/dist/modules/Discount/entitlementState.js +205 -0
  10. package/dist/modules/Discount/index.d.ts +6 -3
  11. package/dist/modules/Discount/index.js +125 -23
  12. package/dist/modules/Discount/types.d.ts +34 -5
  13. package/dist/modules/Rules/entitlementLines.d.ts +8 -0
  14. package/dist/modules/Rules/entitlementLines.js +157 -0
  15. package/dist/modules/Rules/index.d.ts +12 -2
  16. package/dist/modules/Rules/index.js +377 -113
  17. package/dist/modules/Rules/types.d.ts +2 -2
  18. package/dist/plugins/window.d.ts +2 -0
  19. package/dist/solution/ScanOrder/index.js +52 -20
  20. package/dist/solution/ShopDiscount/index.d.ts +3 -0
  21. package/dist/solution/ShopDiscount/index.js +161 -78
  22. package/dist/solution/ShopDiscount/utils.d.ts +1 -0
  23. package/dist/solution/ShopDiscount/utils.js +40 -1
  24. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  25. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  26. package/lib/model/strategy/adapter/walletPass/evaluator.js +4 -2
  27. package/lib/modules/Discount/availability.d.ts +7 -0
  28. package/lib/modules/Discount/availability.js +91 -0
  29. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  30. package/lib/modules/Discount/entitlementPass.js +184 -0
  31. package/lib/modules/Discount/entitlementState.d.ts +8 -0
  32. package/lib/modules/Discount/entitlementState.js +206 -0
  33. package/lib/modules/Discount/index.d.ts +6 -3
  34. package/lib/modules/Discount/index.js +66 -16
  35. package/lib/modules/Discount/types.d.ts +34 -5
  36. package/lib/modules/Rules/entitlementLines.d.ts +8 -0
  37. package/lib/modules/Rules/entitlementLines.js +158 -0
  38. package/lib/modules/Rules/index.d.ts +12 -2
  39. package/lib/modules/Rules/index.js +303 -69
  40. package/lib/modules/Rules/types.d.ts +2 -2
  41. package/lib/plugins/window.d.ts +2 -0
  42. package/lib/solution/ScanOrder/index.js +36 -6
  43. package/lib/solution/ShopDiscount/index.d.ts +3 -0
  44. package/lib/solution/ShopDiscount/index.js +78 -28
  45. package/lib/solution/ShopDiscount/utils.d.ts +1 -0
  46. package/lib/solution/ShopDiscount/utils.js +42 -1
  47. package/package.json +1 -1
@@ -29,7 +29,7 @@ export interface RulesModuleAPI {
29
29
  discountList: any[];
30
30
  productList: any[];
31
31
  holders: {
32
- form_record_id: number;
32
+ form_record_id: number | string;
33
33
  }[];
34
34
  isFormSubject: boolean;
35
35
  }) => DiscountResult;
@@ -49,7 +49,7 @@ type ProductDetail = {
49
49
  original_price?: number | string;
50
50
  num?: number;
51
51
  quantity: number;
52
- holder_id?: number | string;
52
+ holder_id?: number | string | Array<number | string>;
53
53
  vouchersApplicable?: boolean;
54
54
  startDate?: any;
55
55
  };
@@ -1,4 +1,5 @@
1
1
  import { Plugin } from '../types';
2
+ import type { WalletPassEvaluator } from '../model/strategy/adapter/walletPass/evaluator';
2
3
  /**
3
4
  * WindowPlugin 接口定义
4
5
  */
@@ -14,6 +15,7 @@ export interface WindowPlugin extends Plugin {
14
15
  document: Partial<Document>;
15
16
  history: History;
16
17
  interaction?: any;
18
+ getWalletPassEvaluator?: () => WalletPassEvaluator | undefined;
17
19
  getLocalStorage?: (key: string) => string | null;
18
20
  }
19
21
  /**
@@ -913,7 +913,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
913
913
  return 1;
914
914
  };
915
915
  return (payload, { bookingUuid, tempOrder }) => {
916
- var _a, _b;
916
+ var _a, _b, _c, _d, _e, _f, _g;
917
917
  const resourceId = String(tempOrder.resource_id ?? (resourceState == null ? void 0 : resourceState.relationId) ?? "").trim();
918
918
  const hasReservationBookingContext = Boolean(
919
919
  ruleProduct && resourceState && resourceId && (tempOrder.relation_id || resourceState.relationId) && (tempOrder.table_form_id || resourceState.tableFormId)
@@ -928,14 +928,44 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
928
928
  const rawCollectPax = (_a = tempOrder.metadata) == null ? void 0 : _a.collect_pax;
929
929
  const hasExplicitCollectPax = rawCollectPax !== null && rawCollectPax !== void 0 && rawCollectPax !== "";
930
930
  const bookingCapacityValue = resolveBookingCapacityValue();
931
- const pickOriginal = (value) => {
932
- if (value && typeof value === "object" && !Array.isArray(value)) {
933
- const original = value.original;
934
- return typeof original === "string" && original.length > 0 ? original : void 0;
931
+ const resourceNameCandidates = [
932
+ tempOrder.table_number,
933
+ (_b = resourceState == null ? void 0 : resourceState.table_form_record) == null ? void 0 : _b.name
934
+ ];
935
+ const toNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0 ? value : void 0;
936
+ const toNameMap = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
937
+ const pickFromCandidates = (picker) => {
938
+ for (const candidate of resourceNameCandidates) {
939
+ const resolved = picker(candidate);
940
+ if (resolved !== void 0)
941
+ return resolved;
935
942
  }
936
943
  return void 0;
937
944
  };
938
- const mainField = pickOriginal(tempOrder.table_number) ?? pickOriginal((_b = resourceState == null ? void 0 : resourceState.table_form_record) == null ? void 0 : _b.name) ?? "";
945
+ const pickDirectOrOriginal = (value) => {
946
+ var _a2;
947
+ return toNonEmptyString(value) ?? toNonEmptyString((_a2 = toNameMap(value)) == null ? void 0 : _a2.original);
948
+ };
949
+ const pickLocalized = (value, locale) => {
950
+ var _a2;
951
+ return toNonEmptyString((_a2 = toNameMap(value)) == null ? void 0 : _a2[locale]);
952
+ };
953
+ const pickFirstNonEmpty = (value) => {
954
+ const nameMap = toNameMap(value);
955
+ if (!nameMap)
956
+ return void 0;
957
+ for (const candidate of Object.values(nameMap)) {
958
+ const resolved = toNonEmptyString(candidate);
959
+ if (resolved !== void 0)
960
+ return resolved;
961
+ }
962
+ return void 0;
963
+ };
964
+ const coreState = (_d = (_c = this.core) == null ? void 0 : _c.getPlugin("shopStore")) == null ? void 0 : _d.get("core");
965
+ const activeLocale = String(
966
+ (coreState == null ? void 0 : coreState.translateLocale) || ((_f = (_e = coreState == null ? void 0 : coreState.core) == null ? void 0 : _e.shop) == null ? void 0 : _f.primary_locale) || "en"
967
+ );
968
+ const mainField = pickFromCandidates(pickDirectOrOriginal) ?? toNonEmptyString((_g = resourceState == null ? void 0 : resourceState.table_form_record) == null ? void 0 : _g.main_field) ?? pickFromCandidates((value) => pickLocalized(value, activeLocale)) ?? pickFromCandidates((value) => pickLocalized(value, "en")) ?? pickFromCandidates(pickFirstNonEmpty) ?? "";
939
969
  const resourceEntry = resourceState && resourceId ? {
940
970
  relation_type: "form",
941
971
  like_status: "common",
@@ -12,6 +12,8 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
12
12
  private store;
13
13
  private options;
14
14
  private hooks?;
15
+ private entitlementPassEnabled;
16
+ setEntitlementPassEnabled(enabled: boolean): void;
15
17
  constructor(name?: string, version?: string);
16
18
  initialize(core: PisellCore, options: any): Promise<void>;
17
19
  destroy(): Promise<void>;
@@ -42,6 +44,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
42
44
  batchSearchByProductIds(productIds: number[]): Promise<Discount[]>;
43
45
  scanCode(code: string, customerId?: number): Promise<{
44
46
  isAvailable: boolean;
47
+ isAccepted?: boolean;
45
48
  productList: Record<string, any>[];
46
49
  discountList: Discount[];
47
50
  type: "server" | "clientCalc";
@@ -40,6 +40,9 @@ 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");
43
46
  var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
44
47
  constructor(name, version) {
45
48
  super(name, version);
@@ -47,6 +50,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
47
50
  this.defaultVersion = "1.0.0";
48
51
  this.isSolution = true;
49
52
  this.options = {};
53
+ this.entitlementPassEnabled = false;
50
54
  this.store = {
51
55
  customer: null,
52
56
  productList: [],
@@ -60,6 +64,15 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
60
64
  orderId: void 0
61
65
  };
62
66
  }
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
+ }
63
76
  // =========== 生命周期方法 ===========
64
77
  async initialize(core, options) {
65
78
  var _a, _b;
@@ -133,9 +146,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
133
146
  `${this.name}:onCustomerChange`,
134
147
  (customer) => {
135
148
  var _a;
136
- if (((_a = this.options.otherParams) == null ? void 0 : _a.cacheId) && this.getDiscountList().length) {
149
+ if (!this.entitlementPassEnabled && ((_a = this.options.otherParams) == null ? void 0 : _a.cacheId) && this.getDiscountList().length)
137
150
  return;
138
- }
139
151
  this.loadPrepareConfig({
140
152
  customerId: customer.id,
141
153
  action: "create",
@@ -186,9 +198,13 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
186
198
  // }
187
199
  // 设置客户
188
200
  async setCustomer(customer) {
189
- var _a;
201
+ var _a, _b;
190
202
  if (((_a = this.store.customer) == null ? void 0 : _a.id) !== customer.id) {
191
203
  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
+ }
192
208
  await this.core.effects.emit(
193
209
  `${this.name}:onCustomerChange`,
194
210
  customer
@@ -222,6 +238,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
222
238
  },
223
239
  options
224
240
  ) || { productList, discountList: this.getDiscountList() };
241
+ if (this.entitlementPassEnabled)
242
+ this.store.productList = newProductList || productList;
225
243
  if (newDiscountList) {
226
244
  newDiscountList = this.setDiscountList(newDiscountList);
227
245
  }
@@ -279,9 +297,13 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
279
297
  }
280
298
  // 扫码输入code
281
299
  async scanCode(code, customerId) {
282
- var _a, _b, _c;
300
+ var _a, _b, _c, _d, _e;
283
301
  try {
284
- const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId, orderId: this.store.orderId })) || { discountList: [], unavailableReasonKey: null };
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 };
285
307
  const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
286
308
  const rulesModule = this.store.rules;
287
309
  if (!rulesModule) {
@@ -309,7 +331,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
309
331
  };
310
332
  });
311
333
  const currentSelectedDiscountList = this.getDiscountList().filter((n) => n.isSelected);
312
- if (currentSelectedDiscountList.length && currentSelectedDiscountList.some((n) => withScanList.some((m) => m.id === n.id))) {
334
+ if (!withScanList.some(import_entitlementPass.isEntitlementPass) && currentSelectedDiscountList.length && currentSelectedDiscountList.some((n) => withScanList.some((m) => m.id === n.id))) {
313
335
  return {
314
336
  type: "clientCalc",
315
337
  isAvailable: true,
@@ -320,6 +342,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
320
342
  const {
321
343
  productList: newProductList,
322
344
  discountList: newDiscountList,
345
+ evaluatedDiscountList,
323
346
  isAvailable,
324
347
  unavailableReason
325
348
  } = rulesModule.isDiscountListAvailable({
@@ -333,22 +356,42 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
333
356
  productList: this.store.productList || [],
334
357
  discountList: this.getDiscountList()
335
358
  };
359
+ let isAccepted = isAvailable;
336
360
  if (isAvailable) {
361
+ if (this.entitlementPassEnabled)
362
+ this.setProductList(newProductList || []);
337
363
  this.setDiscountList(newDiscountList || []);
338
364
  this.store.originalDiscountList = newDiscountList || [];
339
- this.setProductList(newProductList || []);
365
+ if (!this.entitlementPassEnabled)
366
+ this.setProductList(newProductList || []);
340
367
  if (this.isWalkIn() && resultDiscountList.length && ((_c = this.options.otherParams) == null ? void 0 : _c.platform) === "shop") {
341
368
  await this.getCustomerWallet(
342
369
  resultDiscountList[0].customer_id
343
370
  );
344
371
  }
345
372
  }
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
+ }
346
385
  return {
347
386
  type: "clientCalc",
348
387
  isAvailable: isAvailable || false,
349
- productList: newProductList || this.store.productList || [],
350
- discountList: newDiscountList || this.getDiscountList(),
351
- unavailableReason
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
352
395
  };
353
396
  } catch (error) {
354
397
  console.error("[ShopDiscount] 扫码出错:", error);
@@ -386,7 +429,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
386
429
  }
387
430
  // 设置优惠券列表
388
431
  setDiscountList(discountList) {
389
- var _a;
432
+ var _a, _b;
390
433
  const productList = this.store.productList || [];
391
434
  const editModeDiscountList = [];
392
435
  productList.forEach((item) => {
@@ -394,7 +437,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
394
437
  if (item.booking_id) {
395
438
  const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(item);
396
439
  (item.discount_list || []).forEach((discount) => {
397
- var _a3, _b, _c, _d, _e;
440
+ var _a3, _b2, _c, _d, _e;
398
441
  if (discount.id && ["good_pass", "discount_card"].includes(discount.type)) {
399
442
  const index = editModeDiscountList.findIndex((n) => {
400
443
  var _a4;
@@ -415,7 +458,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
415
458
  name: discount.name || discount.discount.title.auto,
416
459
  isEditMode: true,
417
460
  limited_relation_product_data: {},
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(),
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(),
419
462
  isAvailable: true,
420
463
  id: ((_c = discount.discount) == null ? void 0 : _c.resource_id) || discount.id,
421
464
  format_title: ((_d = discount.discount) == null ? void 0 : _d.title) || discount.format_title,
@@ -428,10 +471,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
428
471
  });
429
472
  }
430
473
  });
431
- const newDiscountList = [
432
- ...editModeDiscountList,
433
- ...discountList.filter((item) => !item.isDisabled)
434
- ];
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))];
435
478
  const isProductFree = (id) => {
436
479
  var _a2;
437
480
  const targetProduct = productList.find((n) => n.id === id);
@@ -461,7 +504,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
461
504
  item.isDisabledForProductUsed = false;
462
505
  }
463
506
  });
464
- (_a = this.store.discount) == null ? void 0 : _a.setDiscountList(newDiscountList);
507
+ (_b = this.store.discount) == null ? void 0 : _b.setDiscountList(newDiscountList);
465
508
  this.emitDiscountListChange(newDiscountList);
466
509
  return newDiscountList;
467
510
  }
@@ -478,7 +521,9 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
478
521
  });
479
522
  if (result == null ? void 0 : result.data) {
480
523
  const { ...customer } = result.data;
481
- this.setCustomer(customer);
524
+ const customerUpdate = this.setCustomer(customer);
525
+ if (this.entitlementPassEnabled)
526
+ await customerUpdate;
482
527
  await this.core.effects.emit(
483
528
  `${this.name}:onScanCustomerChange`,
484
529
  customer
@@ -507,8 +552,9 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
507
552
  }
508
553
  // 加载准备配置
509
554
  async loadPrepareConfig(params) {
510
- var _a, _b, _c, _d, _e;
555
+ var _a, _b, _c, _d, _e, _f;
511
556
  try {
557
+ const entitlementPassEnabled = this.entitlementPassEnabled;
512
558
  const orderId = this.store.orderId;
513
559
  const customerId = params.customerId || ((_a = this.getCustomer()) == null ? void 0 : _a.id);
514
560
  const goodPassList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
@@ -517,21 +563,25 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
517
563
  with_good_pass: 1,
518
564
  with_discount_card: 1,
519
565
  with_wallet_pass_holder: 1,
566
+ ...this.entitlementPassEnabled ? { with_entitlement_pass: 1, filter_order_wallet_pass_usage: 0 } : {},
520
567
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
521
568
  ...orderId ? { order_id: orderId } : {}
522
569
  }));
523
- const scanDiscount = (_c = this.getDiscountList()) == null ? void 0 : _c.filter(
524
- (item) => item.isScan
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()
525
578
  );
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 || []];
529
579
  this.store.originalDiscountList = newDiscountList;
530
- await ((_d = this.store.discount) == null ? void 0 : _d.setOriginalDiscountList(newDiscountList));
531
- const filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
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);
532
582
  this.store.filteredDiscountList = filteredDiscountList;
533
583
  this.setDiscountList(filteredDiscountList || []);
534
- if ((_e = this.store.productList) == null ? void 0 : _e.length) {
584
+ if ((_f = this.store.productList) == null ? void 0 : _f.length) {
535
585
  const result = this.calcDiscount(this.store.productList);
536
586
  await this.core.effects.emit(
537
587
  `${this.name}:onLoadPrepareCalcResult`,
@@ -89,3 +89,4 @@ 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,6 +35,7 @@ __export(utils_exports, {
35
35
  getDiscountAmount: () => getDiscountAmount,
36
36
  getDiscountListAmount: () => getDiscountListAmount,
37
37
  getDiscountListAmountTotal: () => getDiscountListAmountTotal,
38
+ getDiscountTimeUnavailableReason: () => getDiscountTimeUnavailableReason,
38
39
  isAllNormalProduct: () => isAllNormalProduct,
39
40
  isNormalProductByDurationSchedule: () => isNormalProductByDurationSchedule,
40
41
  isOrderLevelFixedAmountDiscount: () => isOrderLevelFixedAmountDiscount,
@@ -43,6 +44,11 @@ __export(utils_exports, {
43
44
  module.exports = __toCommonJS(utils_exports);
44
45
  var import_decimal = __toESM(require("decimal.js"));
45
46
  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);
46
52
  var uniqueById = (arr, key = "id") => {
47
53
  const seen = /* @__PURE__ */ new Set();
48
54
  return arr.filter((item) => !seen.has(item[key]) && seen.add(item[key]));
@@ -56,7 +62,7 @@ var isAllNormalProduct = (items) => {
56
62
  };
57
63
  var getDiscountAmount = (discount, total, price) => {
58
64
  var _a;
59
- if (discount.tag === "good_pass") {
65
+ if ((0, import_entitlementPass.isFullCoveragePass)(discount)) {
60
66
  return new import_decimal.default(price).minus(new import_decimal.default(price || 0)).toNumber();
61
67
  }
62
68
  const isFixedAmount = ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount";
@@ -293,6 +299,8 @@ var filterDiscountListByBookingTime = (discountList, bookingTime) => {
293
299
  }
294
300
  return discountList.filter((discount) => {
295
301
  var _a, _b;
302
+ if ((0, import_entitlementPass.isEntitlementPass)(discount))
303
+ return !getDiscountTimeUnavailableReason(discount, bookingTime);
296
304
  if (((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.validity_type) === "custom_schedule_validity") {
297
305
  return getDateIsInSchedule(bookingTime, ((_b = discount.custom_schedule_snapshot) == null ? void 0 : _b.data) || []);
298
306
  }
@@ -391,6 +399,38 @@ var calculateOrderLevelDiscountAllocation = (discount, applicableProducts) => {
391
399
  }
392
400
  return result;
393
401
  };
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
+ };
394
434
  // Annotate the CommonJS export names for ESM import in node:
395
435
  0 && (module.exports = {
396
436
  calculateOrderLevelDiscountAllocation,
@@ -399,6 +439,7 @@ var calculateOrderLevelDiscountAllocation = (discount, applicableProducts) => {
399
439
  getDiscountAmount,
400
440
  getDiscountListAmount,
401
441
  getDiscountListAmountTotal,
442
+ getDiscountTimeUnavailableReason,
402
443
  isAllNormalProduct,
403
444
  isNormalProductByDurationSchedule,
404
445
  isOrderLevelFixedAmountDiscount,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.177",
4
+ "version": "2.1.179",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",