@pisell/pisellos 2.3.213 → 2.3.214

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.
@@ -0,0 +1,9 @@
1
+ // 导出评估器
2
+ export { PromotionEvaluator } from "./evaluator";
3
+
4
+ // 导出适配器
5
+ export { PromotionAdapter } from "./adapter";
6
+ export { default } from "./adapter";
7
+
8
+ // 导出策略配置示例常量
9
+ export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, ITEM_REWARD_STRATEGY } from "./examples";
@@ -4,4 +4,6 @@ export declare function getDiscountUsageLimitFailKey(discount: Discount): Discou
4
4
  export declare function hasAvailableDiscountBalance(discount: Discount): boolean;
5
5
  /** 按卡本身当前生命周期判断;预约时间或一次日程不匹配不代表已失效。 */
6
6
  export declare function getDiscountLifecycleReason(discount: Discount): 'disabled' | 'exhausted' | 'expired' | undefined;
7
+ /** 仅用于扫码被过滤后的提示;不改变卡券过滤、优惠计算或列表保留规则。 */
8
+ export declare function getDiscountFilterRejectKey(discount: Discount): DiscountFilterRejectKey | null;
7
9
  export declare function getDiscountUsageBlockReason(discount: Discount): string | undefined;
@@ -27,23 +27,43 @@ export function hasAvailableDiscountBalance(discount) {
27
27
  if (isEntitlementPass(discount)) return hasAvailableEntitlementUses(discount);
28
28
  return new Decimal(discount.par_value || 0).minus(discount.used_par_value || 0).greaterThan(0);
29
29
  }
30
+ function isDiscountExpired(discount) {
31
+ var _discount$metadata;
32
+ // 自定义日程沿用快照语义,不使用遗留固定有效期字段推断过期。
33
+ if (((_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.validity_type) !== 'custom_schedule_validity' && discount.expire_time) {
34
+ var expiry = dayjs(discount.expire_time);
35
+ return expiry.isValid() && !dayjs().isBefore(expiry);
36
+ }
37
+ return false;
38
+ }
30
39
 
31
40
  /** 按卡本身当前生命周期判断;预约时间或一次日程不匹配不代表已失效。 */
32
41
  export function getDiscountLifecycleReason(discount) {
33
- var _discount$metadata;
34
42
  if (discount.limit_status && discount.limit_status !== 'enable') {
35
43
  return 'disabled';
36
44
  }
37
45
  if ((isEntitlementPass(discount) || discount.par_value != null) && !hasAvailableDiscountBalance(discount) || getDiscountUsageLimitFailKey(discount) === 'total_credits') {
38
46
  return 'exhausted';
39
47
  }
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
- }
48
+ if (isDiscountExpired(discount)) return 'expired';
45
49
  return undefined;
46
50
  }
51
+
52
+ /** 仅用于扫码被过滤后的提示;不改变卡券过滤、优惠计算或列表保留规则。 */
53
+ export function getDiscountFilterRejectKey(discount) {
54
+ var lifecycleReason = getDiscountLifecycleReason(discount);
55
+ if (lifecycleReason === 'disabled') return 'disabled';
56
+ // 卡片同时过期、额度耗尽时,扫码提示优先说明已过期。
57
+ if (isDiscountExpired(discount)) return 'expired';
58
+ if ((discount.tag || discount.type) === 'product_discount_card' && new Decimal(discount.par_value || 0).lessThanOrEqualTo(0)) {
59
+ return 'invalid_discount_value';
60
+ }
61
+ var usageLimitFailKey = getDiscountUsageLimitFailKey(discount);
62
+ if (lifecycleReason === 'exhausted') {
63
+ return usageLimitFailKey === 'total_credits' ? usageLimitFailKey : 'exhausted';
64
+ }
65
+ return usageLimitFailKey;
66
+ }
47
67
  export function getDiscountUsageBlockReason(discount) {
48
68
  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
69
  }
@@ -29,7 +29,7 @@ import { uniqueById } from "../../solution/ShopDiscount/utils";
29
29
  import { BaseModule } from "../BaseModule";
30
30
  import { DiscountHooks } from "./types";
31
31
  import Decimal from 'decimal.js';
32
- import { getDiscountLifecycleReason, getDiscountUsageBlockReason, getDiscountUsageLimitFailKey, hasAvailableDiscountBalance } from "./availability";
32
+ import { getDiscountFilterRejectKey, getDiscountLifecycleReason, getDiscountUsageBlockReason, getDiscountUsageLimitFailKey, hasAvailableDiscountBalance } from "./availability";
33
33
  export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
34
34
  _inherits(DiscountModule, _BaseModule);
35
35
  var _super = _createSuper(DiscountModule);
@@ -341,9 +341,13 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
341
341
  }, {
342
342
  key: "filterEnabledDiscountListWithReason",
343
343
  value: function filterEnabledDiscountListWithReason(discountList) {
344
+ var enabledDiscountList = this.filterEnabledDiscountList(discountList);
344
345
  return {
345
- discountList: this.filterEnabledDiscountList(discountList),
346
- unavailableReasonKey: discountList.map(getDiscountUsageLimitFailKey).find(function (key) {
346
+ discountList: enabledDiscountList,
347
+ // 查到卡但全部被过滤时保留具体原因;空响应仍沿用无效码提示。
348
+ unavailableReasonKey: discountList.length > 0 && !enabledDiscountList.length ? discountList.map(getDiscountFilterRejectKey).find(function (key) {
349
+ return key !== null;
350
+ }) || 'unavailable' : discountList.map(getDiscountUsageLimitFailKey).find(function (key) {
347
351
  return key !== null;
348
352
  }) || null
349
353
  };
@@ -73,7 +73,7 @@ export type IncludedUses = {
73
73
  type: 'unlimited';
74
74
  value: null;
75
75
  };
76
- export type DiscountFilterRejectKey = 'total_credits' | 'per_user_limit' | 'max_per_day' | 'max_per_week' | 'max_per_month';
76
+ export type DiscountFilterRejectKey = 'disabled' | 'expired' | 'exhausted' | 'invalid_discount_value' | 'unavailable' | 'total_credits' | 'per_user_limit' | 'max_per_day' | 'max_per_week' | 'max_per_month';
77
77
  export interface DiscountWithReason {
78
78
  discountList: Discount[];
79
79
  unavailableReasonKey: DiscountFilterRejectKey | null;
@@ -640,7 +640,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
640
640
  generateIdempotencyToken(): string;
641
641
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
642
642
  createOrder(params: CommitOrderParams['query']): {
643
- type: "appointment_booking" | "virtual";
643
+ type: "virtual" | "appointment_booking";
644
644
  platform: string;
645
645
  sales_channel: string;
646
646
  order_sales_channel: string;
@@ -181,6 +181,8 @@ export interface OrderScanCodeResult {
181
181
  scannedDiscountList: Discount[];
182
182
  type: 'server' | 'clientCalc';
183
183
  unavailableReason?: UnavailableReason;
184
+ /** 扫码过滤原因,供销售层透传给提示组件。 */
185
+ unavailableReasonKey?: string | null;
184
186
  }
185
187
  export interface OrderProductIdentity {
186
188
  product_id: number | null;
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "normal" | "duration" | "session";
52
+ getProductType(): "normal" | "session" | "duration";
53
53
  }
@@ -4306,6 +4306,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
4306
4306
  } : {}), {}, {
4307
4307
  type: raw.type,
4308
4308
  unavailableReason: raw.unavailableReason,
4309
+ unavailableReasonKey: raw.unavailableReasonKey,
4309
4310
  scannedDiscountList: raw.scannedDiscountList
4310
4311
  }));
4311
4312
  case 16:
@@ -465,6 +465,8 @@ export interface BaseSalesScanCodeResult {
465
465
  isAccepted?: boolean;
466
466
  type?: 'server' | string;
467
467
  unavailableReason?: 'time_limit' | string;
468
+ /** 扫码过滤原因(禁用、过期、额度或次数限制等);仅用于提示。 */
469
+ unavailableReasonKey?: string | null;
468
470
  /** 扫码卡券资料及最新可用状态,供 Holder 补全等流程使用。 */
469
471
  scannedDiscountList?: Discount[];
470
472
  }
@@ -342,7 +342,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
342
342
  date: string;
343
343
  status: string;
344
344
  week: string;
345
- weekNum: 0 | 2 | 1 | 6 | 4 | 5 | 3;
345
+ weekNum: 0 | 2 | 1 | 3 | 5 | 4 | 6;
346
346
  }[]>;
347
347
  submitTimeSlot(timeSlots: TimeSliceItem): void;
348
348
  private getScheduleDataByIds;
@@ -389,7 +389,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
389
389
  };
390
390
  setOtherData(key: string, value: any): void;
391
391
  getOtherData(key: string): any;
392
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
392
+ getProductTypeById(id: number): Promise<"normal" | "session" | "duration">;
393
393
  /**
394
394
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
395
395
  *
@@ -880,6 +880,7 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
880
880
  } : {}), {}, {
881
881
  type: raw.type,
882
882
  unavailableReason: raw.unavailableReason,
883
+ unavailableReasonKey: raw.unavailableReasonKey,
883
884
  scannedDiscountList: raw.scannedDiscountList
884
885
  }));
885
886
  case 26:
@@ -4,4 +4,6 @@ export declare function getDiscountUsageLimitFailKey(discount: Discount): Discou
4
4
  export declare function hasAvailableDiscountBalance(discount: Discount): boolean;
5
5
  /** 按卡本身当前生命周期判断;预约时间或一次日程不匹配不代表已失效。 */
6
6
  export declare function getDiscountLifecycleReason(discount: Discount): 'disabled' | 'exhausted' | 'expired' | undefined;
7
+ /** 仅用于扫码被过滤后的提示;不改变卡券过滤、优惠计算或列表保留规则。 */
8
+ export declare function getDiscountFilterRejectKey(discount: Discount): DiscountFilterRejectKey | null;
7
9
  export declare function getDiscountUsageBlockReason(discount: Discount): string | undefined;
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.getDiscountFilterRejectKey = getDiscountFilterRejectKey;
6
7
  exports.getDiscountLifecycleReason = getDiscountLifecycleReason;
7
8
  exports.getDiscountUsageBlockReason = getDiscountUsageBlockReason;
8
9
  exports.getDiscountUsageLimitFailKey = getDiscountUsageLimitFailKey;
@@ -22,6 +23,14 @@ function hasAvailableDiscountBalance(discount) {
22
23
  if ((0, _entitlementPass.isEntitlementPass)(discount)) return (0, _entitlementPass.hasAvailableEntitlementUses)(discount);
23
24
  return new _decimal.default(discount.par_value || 0).minus(discount.used_par_value || 0).greaterThan(0);
24
25
  }
26
+ function isDiscountExpired(discount) {
27
+ // 自定义日程沿用快照语义,不使用遗留固定有效期字段推断过期。
28
+ if (discount.metadata?.validity_type !== 'custom_schedule_validity' && discount.expire_time) {
29
+ const expiry = (0, _dayjs.default)(discount.expire_time);
30
+ return expiry.isValid() && !(0, _dayjs.default)().isBefore(expiry);
31
+ }
32
+ return false;
33
+ }
25
34
 
26
35
  /** 按卡本身当前生命周期判断;预约时间或一次日程不匹配不代表已失效。 */
27
36
  function getDiscountLifecycleReason(discount) {
@@ -31,13 +40,25 @@ function getDiscountLifecycleReason(discount) {
31
40
  if (((0, _entitlementPass.isEntitlementPass)(discount) || discount.par_value != null) && !hasAvailableDiscountBalance(discount) || getDiscountUsageLimitFailKey(discount) === 'total_credits') {
32
41
  return 'exhausted';
33
42
  }
34
- // 自定义日程沿用快照语义,不使用遗留固定有效期字段推断过期。
35
- if (discount.metadata?.validity_type !== 'custom_schedule_validity' && discount.expire_time) {
36
- const expiry = (0, _dayjs.default)(discount.expire_time);
37
- if (expiry.isValid() && !(0, _dayjs.default)().isBefore(expiry)) return 'expired';
38
- }
43
+ if (isDiscountExpired(discount)) return 'expired';
39
44
  return undefined;
40
45
  }
46
+
47
+ /** 仅用于扫码被过滤后的提示;不改变卡券过滤、优惠计算或列表保留规则。 */
48
+ function getDiscountFilterRejectKey(discount) {
49
+ const lifecycleReason = getDiscountLifecycleReason(discount);
50
+ if (lifecycleReason === 'disabled') return 'disabled';
51
+ // 卡片同时过期、额度耗尽时,扫码提示优先说明已过期。
52
+ if (isDiscountExpired(discount)) return 'expired';
53
+ if ((discount.tag || discount.type) === 'product_discount_card' && new _decimal.default(discount.par_value || 0).lessThanOrEqualTo(0)) {
54
+ return 'invalid_discount_value';
55
+ }
56
+ const usageLimitFailKey = getDiscountUsageLimitFailKey(discount);
57
+ if (lifecycleReason === 'exhausted') {
58
+ return usageLimitFailKey === 'total_credits' ? usageLimitFailKey : 'exhausted';
59
+ }
60
+ return usageLimitFailKey;
61
+ }
41
62
  function getDiscountUsageBlockReason(discount) {
42
63
  return getDiscountLifecycleReason(discount) || getDiscountUsageLimitFailKey(discount) || (discount.unified_available_status != null && String(discount.unified_available_status) !== '' && Number(discount.unified_available_status) === 0 ? 'server_unavailable' : undefined);
43
64
  }
@@ -180,9 +180,11 @@ class DiscountModule extends _BaseModule.BaseModule {
180
180
  }));
181
181
  }
182
182
  filterEnabledDiscountListWithReason(discountList) {
183
+ const enabledDiscountList = this.filterEnabledDiscountList(discountList);
183
184
  return {
184
- discountList: this.filterEnabledDiscountList(discountList),
185
- unavailableReasonKey: discountList.map(_availability.getDiscountUsageLimitFailKey).find(key => key !== null) || null
185
+ discountList: enabledDiscountList,
186
+ // 查到卡但全部被过滤时保留具体原因;空响应仍沿用无效码提示。
187
+ unavailableReasonKey: discountList.length > 0 && !enabledDiscountList.length ? discountList.map(_availability.getDiscountFilterRejectKey).find(key => key !== null) || 'unavailable' : discountList.map(_availability.getDiscountUsageLimitFailKey).find(key => key !== null) || null
186
188
  };
187
189
  }
188
190
 
@@ -73,7 +73,7 @@ export type IncludedUses = {
73
73
  type: 'unlimited';
74
74
  value: null;
75
75
  };
76
- export type DiscountFilterRejectKey = 'total_credits' | 'per_user_limit' | 'max_per_day' | 'max_per_week' | 'max_per_month';
76
+ export type DiscountFilterRejectKey = 'disabled' | 'expired' | 'exhausted' | 'invalid_discount_value' | 'unavailable' | 'total_credits' | 'per_user_limit' | 'max_per_day' | 'max_per_week' | 'max_per_month';
77
77
  export interface DiscountWithReason {
78
78
  discountList: Discount[];
79
79
  unavailableReasonKey: DiscountFilterRejectKey | null;
@@ -640,7 +640,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
640
640
  generateIdempotencyToken(): string;
641
641
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
642
642
  createOrder(params: CommitOrderParams['query']): {
643
- type: "appointment_booking" | "virtual";
643
+ type: "virtual" | "appointment_booking";
644
644
  platform: string;
645
645
  sales_channel: string;
646
646
  order_sales_channel: string;
@@ -181,6 +181,8 @@ export interface OrderScanCodeResult {
181
181
  scannedDiscountList: Discount[];
182
182
  type: 'server' | 'clientCalc';
183
183
  unavailableReason?: UnavailableReason;
184
+ /** 扫码过滤原因,供销售层透传给提示组件。 */
185
+ unavailableReasonKey?: string | null;
184
186
  }
185
187
  export interface OrderProductIdentity {
186
188
  product_id: number | null;
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "normal" | "duration" | "session";
52
+ getProductType(): "normal" | "session" | "duration";
53
53
  }
@@ -2628,6 +2628,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2628
2628
  } : {}),
2629
2629
  type: raw.type,
2630
2630
  unavailableReason: raw.unavailableReason,
2631
+ unavailableReasonKey: raw.unavailableReasonKey,
2631
2632
  scannedDiscountList: raw.scannedDiscountList
2632
2633
  };
2633
2634
  } catch (error) {
@@ -465,6 +465,8 @@ export interface BaseSalesScanCodeResult {
465
465
  isAccepted?: boolean;
466
466
  type?: 'server' | string;
467
467
  unavailableReason?: 'time_limit' | string;
468
+ /** 扫码过滤原因(禁用、过期、额度或次数限制等);仅用于提示。 */
469
+ unavailableReasonKey?: string | null;
468
470
  /** 扫码卡券资料及最新可用状态,供 Holder 补全等流程使用。 */
469
471
  scannedDiscountList?: Discount[];
470
472
  }
@@ -342,7 +342,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
342
342
  date: string;
343
343
  status: string;
344
344
  week: string;
345
- weekNum: 0 | 2 | 1 | 6 | 4 | 5 | 3;
345
+ weekNum: 0 | 2 | 1 | 3 | 5 | 4 | 6;
346
346
  }[]>;
347
347
  submitTimeSlot(timeSlots: TimeSliceItem): void;
348
348
  private getScheduleDataByIds;
@@ -389,7 +389,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
389
389
  };
390
390
  setOtherData(key: string, value: any): void;
391
391
  getOtherData(key: string): any;
392
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
392
+ getProductTypeById(id: number): Promise<"normal" | "session" | "duration">;
393
393
  /**
394
394
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
395
395
  *
@@ -510,6 +510,7 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
510
510
  } : {}),
511
511
  type: raw.type,
512
512
  unavailableReason: raw.unavailableReason,
513
+ unavailableReasonKey: raw.unavailableReasonKey,
513
514
  scannedDiscountList: raw.scannedDiscountList
514
515
  };
515
516
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.213",
4
+ "version": "2.3.214",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",