@pisell/pisellos 0.0.571 → 0.0.572

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 (143) hide show
  1. package/dist/effects/index.d.ts +2 -2
  2. package/dist/model/strategy/adapter/dataVariant/type.d.ts +3 -3
  3. package/dist/model/strategy/adapter/itemRule/type.d.ts +6 -6
  4. package/dist/model/strategy/adapter/promotion/index.d.ts +4 -0
  5. package/dist/model/strategy/adapter/promotion/type.d.ts +5 -5
  6. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  7. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
  8. package/dist/model/strategy/type.d.ts +1 -1
  9. package/dist/modules/BookingContext/types.d.ts +4 -4
  10. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +1 -1
  11. package/dist/modules/Customer/types.d.ts +1 -1
  12. package/dist/modules/Discount/availability.d.ts +7 -0
  13. package/dist/modules/Discount/availability.js +52 -0
  14. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  15. package/dist/modules/Discount/entitlementPass.js +147 -0
  16. package/dist/modules/Discount/entitlementState.d.ts +8 -0
  17. package/dist/modules/Discount/entitlementState.js +205 -0
  18. package/dist/modules/Discount/index.d.ts +5 -2
  19. package/dist/modules/Discount/index.js +124 -25
  20. package/dist/modules/Discount/types.d.ts +29 -6
  21. package/dist/modules/Holder/types.d.ts +1 -1
  22. package/dist/modules/OpenData/types.d.ts +1 -1
  23. package/dist/modules/Order/types.d.ts +5 -5
  24. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +1 -1
  25. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +1 -1
  26. package/dist/modules/Order/utils.d.ts +1 -1
  27. package/dist/modules/Payment/types.d.ts +7 -7
  28. package/dist/modules/Product/index.d.ts +1 -1
  29. package/dist/modules/ResourcePlanner/types.d.ts +4 -4
  30. package/dist/modules/Rules/entitlementLines.d.ts +8 -0
  31. package/dist/modules/Rules/entitlementLines.js +159 -0
  32. package/dist/modules/Rules/index.d.ts +13 -3
  33. package/dist/modules/Rules/index.js +617 -342
  34. package/dist/modules/Rules/types.d.ts +4 -4
  35. package/dist/modules/ScanOrderLogger/types.d.ts +2 -2
  36. package/dist/modules/Schedule/getDateIsInSchedule.d.ts +1 -1
  37. package/dist/modules/Schedule/type.d.ts +7 -7
  38. package/dist/modules/Schedule/types.d.ts +9 -9
  39. package/dist/plugins/app.d.ts +1 -1
  40. package/dist/plugins/request.d.ts +2 -2
  41. package/dist/plugins/window.d.ts +2 -2
  42. package/dist/server/modules/floor-plan/types.d.ts +1 -1
  43. package/dist/server/modules/menu/types.d.ts +1 -1
  44. package/dist/server/modules/order/types.d.ts +16 -16
  45. package/dist/server/modules/products/types.d.ts +1 -1
  46. package/dist/server/modules/resource/types.d.ts +1 -1
  47. package/dist/server/modules/schedule/utils.d.ts +1 -1
  48. package/dist/server/types.d.ts +4 -4
  49. package/dist/server/utils/small-ticket.d.ts +1 -1
  50. package/dist/solution/BaseSales/index.d.ts +1 -1
  51. package/dist/solution/BaseSales/types.d.ts +7 -7
  52. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -1
  53. package/dist/solution/BookingByStep/index.d.ts +1 -1
  54. package/dist/solution/BookingByStep/utils/resources.d.ts +1 -1
  55. package/dist/solution/BookingTicket/index.d.ts +13 -1
  56. package/dist/solution/BookingTicket/types.d.ts +3 -3
  57. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
  58. package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +1 -1
  59. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +1 -1
  60. package/dist/solution/Sales/types.d.ts +4 -4
  61. package/dist/solution/ScanOrder/types.d.ts +5 -5
  62. package/dist/solution/ShopDiscount/index.d.ts +3 -0
  63. package/dist/solution/ShopDiscount/index.js +161 -78
  64. package/dist/solution/ShopDiscount/types.d.ts +1 -1
  65. package/dist/solution/ShopDiscount/utils.d.ts +3 -2
  66. package/dist/solution/ShopDiscount/utils.js +40 -1
  67. package/dist/solution/UnifiedBookingSales/types.d.ts +1 -1
  68. package/dist/solution/VenueBooking/types.d.ts +1 -1
  69. package/dist/types/index.d.ts +1 -1
  70. package/dist/utils/task.d.ts +2 -2
  71. package/dist/utils/watch.d.ts +2 -2
  72. package/lib/effects/index.d.ts +2 -2
  73. package/lib/model/strategy/adapter/dataVariant/type.d.ts +3 -3
  74. package/lib/model/strategy/adapter/itemRule/type.d.ts +6 -6
  75. package/lib/model/strategy/adapter/promotion/index.d.ts +4 -0
  76. package/lib/model/strategy/adapter/promotion/type.d.ts +5 -5
  77. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  78. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
  79. package/lib/model/strategy/type.d.ts +1 -1
  80. package/lib/modules/BookingContext/types.d.ts +4 -4
  81. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +1 -1
  82. package/lib/modules/Customer/types.d.ts +1 -1
  83. package/lib/modules/Discount/availability.d.ts +7 -0
  84. package/lib/modules/Discount/availability.js +46 -0
  85. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  86. package/lib/modules/Discount/entitlementPass.js +141 -0
  87. package/lib/modules/Discount/entitlementState.d.ts +8 -0
  88. package/lib/modules/Discount/entitlementState.js +150 -0
  89. package/lib/modules/Discount/index.d.ts +5 -2
  90. package/lib/modules/Discount/index.js +59 -14
  91. package/lib/modules/Discount/types.d.ts +29 -6
  92. package/lib/modules/Holder/types.d.ts +1 -1
  93. package/lib/modules/OpenData/types.d.ts +1 -1
  94. package/lib/modules/Order/types.d.ts +5 -5
  95. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +1 -1
  96. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +1 -1
  97. package/lib/modules/Order/utils.d.ts +1 -1
  98. package/lib/modules/Payment/types.d.ts +7 -7
  99. package/lib/modules/Product/index.d.ts +1 -1
  100. package/lib/modules/ResourcePlanner/types.d.ts +4 -4
  101. package/lib/modules/Rules/entitlementLines.d.ts +8 -0
  102. package/lib/modules/Rules/entitlementLines.js +128 -0
  103. package/lib/modules/Rules/index.d.ts +13 -3
  104. package/lib/modules/Rules/index.js +284 -61
  105. package/lib/modules/Rules/types.d.ts +4 -4
  106. package/lib/modules/ScanOrderLogger/types.d.ts +2 -2
  107. package/lib/modules/Schedule/getDateIsInSchedule.d.ts +1 -1
  108. package/lib/modules/Schedule/type.d.ts +7 -7
  109. package/lib/modules/Schedule/types.d.ts +9 -9
  110. package/lib/plugins/app.d.ts +1 -1
  111. package/lib/plugins/request.d.ts +2 -2
  112. package/lib/plugins/window.d.ts +2 -2
  113. package/lib/server/modules/floor-plan/types.d.ts +1 -1
  114. package/lib/server/modules/menu/types.d.ts +1 -1
  115. package/lib/server/modules/order/types.d.ts +16 -16
  116. package/lib/server/modules/products/types.d.ts +1 -1
  117. package/lib/server/modules/resource/types.d.ts +1 -1
  118. package/lib/server/modules/schedule/utils.d.ts +1 -1
  119. package/lib/server/types.d.ts +4 -4
  120. package/lib/server/utils/small-ticket.d.ts +1 -1
  121. package/lib/solution/BaseSales/index.d.ts +1 -1
  122. package/lib/solution/BaseSales/types.d.ts +7 -7
  123. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -1
  124. package/lib/solution/BookingByStep/index.d.ts +1 -1
  125. package/lib/solution/BookingByStep/utils/resources.d.ts +1 -1
  126. package/lib/solution/BookingTicket/index.d.ts +13 -1
  127. package/lib/solution/BookingTicket/types.d.ts +3 -3
  128. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
  129. package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +1 -1
  130. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +1 -1
  131. package/lib/solution/Sales/types.d.ts +4 -4
  132. package/lib/solution/ScanOrder/types.d.ts +5 -5
  133. package/lib/solution/ShopDiscount/index.d.ts +3 -0
  134. package/lib/solution/ShopDiscount/index.js +55 -18
  135. package/lib/solution/ShopDiscount/types.d.ts +1 -1
  136. package/lib/solution/ShopDiscount/utils.d.ts +3 -2
  137. package/lib/solution/ShopDiscount/utils.js +39 -3
  138. package/lib/solution/UnifiedBookingSales/types.d.ts +1 -1
  139. package/lib/solution/VenueBooking/types.d.ts +1 -1
  140. package/lib/types/index.d.ts +1 -1
  141. package/lib/utils/task.d.ts +2 -2
  142. package/lib/utils/watch.d.ts +2 -2
  143. package/package.json +19 -18
@@ -11,6 +11,9 @@ var _utils = require("./utils");
11
11
  var _types = require("../../modules/Rules/types");
12
12
  var _decimal = _interopRequireDefault(require("decimal.js"));
13
13
  var _lodashEs = require("lodash-es");
14
+ var _entitlementPass = require("../../modules/Discount/entitlementPass");
15
+ var _availability = require("../../modules/Discount/availability");
16
+ var _entitlementState = require("../../modules/Discount/entitlementState");
14
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
18
  class ShopDiscountImpl extends _BaseModule.BaseModule {
16
19
  defaultName = 'shopDiscount';
@@ -21,6 +24,16 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
21
24
  store;
22
25
  options = {};
23
26
  hooks;
27
+ entitlementPassEnabled = false;
28
+
29
+ // 由使用多次卡的预约组件显式开启,其他入口沿用原券流程。
30
+ setEntitlementPassEnabled(enabled) {
31
+ this.entitlementPassEnabled = enabled;
32
+ this.store.rules?.setEntitlementPassEnabled(enabled);
33
+ if (!enabled) {
34
+ this.store.discount?.setDiscountList(this.getDiscountList().filter(item => !(0, _entitlementPass.isEntitlementPass)(item)));
35
+ }
36
+ }
24
37
  constructor(name, version) {
25
38
  super(name, version);
26
39
  // 初始化所有必要的状态属性
@@ -118,9 +131,7 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
118
131
  }
119
132
  registerEventListeners() {
120
133
  this.core.effects.only(`${this.name}:onCustomerChange`, customer => {
121
- if (this.options.otherParams?.cacheId && this.getDiscountList().length) {
122
- return;
123
- }
134
+ if (!this.entitlementPassEnabled && this.options.otherParams?.cacheId && this.getDiscountList().length) return;
124
135
  this.loadPrepareConfig({
125
136
  customerId: customer.id,
126
137
  action: 'create',
@@ -181,6 +192,10 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
181
192
  async setCustomer(customer) {
182
193
  if (this.store.customer?.id !== customer.id) {
183
194
  this.store.customer = customer;
195
+ if (this.entitlementPassEnabled) {
196
+ const retained = this.getDiscountList().filter(item => !(0, _entitlementPass.isEntitlementPass)(item) || item.isEditMode || item.isScan && String(item.customer_id) === String(customer.id));
197
+ await this.store.discount?.setDiscountList(retained);
198
+ }
184
199
  await this.core.effects.emit(`${this.name}:onCustomerChange`, customer);
185
200
  }
186
201
  }
@@ -222,6 +237,7 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
222
237
  productList,
223
238
  discountList: this.getDiscountList()
224
239
  };
240
+ if (this.entitlementPassEnabled) this.store.productList = newProductList || productList;
225
241
  if (newDiscountList) {
226
242
  newDiscountList = this.setDiscountList(newDiscountList);
227
243
  }
@@ -300,7 +316,8 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
300
316
  try {
301
317
  const resultDiscountWithReason = (await this.store.discount?.batchSearch(code, {
302
318
  customerId,
303
- orderId: this.store.orderId
319
+ orderId: this.store.orderId,
320
+ withEntitlementPass: this.entitlementPassEnabled
304
321
  })) || {
305
322
  discountList: [],
306
323
  unavailableReasonKey: null
@@ -336,7 +353,7 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
336
353
  });
337
354
  // 如果扫回来的券当前有选中的,则不进行计算
338
355
  const currentSelectedDiscountList = this.getDiscountList().filter(n => n.isSelected);
339
- if (currentSelectedDiscountList.length && currentSelectedDiscountList.some(n => withScanList.some(m => m.id === n.id))) {
356
+ if (!withScanList.some(_entitlementPass.isEntitlementPass) && currentSelectedDiscountList.length && currentSelectedDiscountList.some(n => withScanList.some(m => m.id === n.id))) {
340
357
  return {
341
358
  type: "clientCalc",
342
359
  isAvailable: true,
@@ -347,6 +364,7 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
347
364
  const {
348
365
  productList: newProductList,
349
366
  discountList: newDiscountList,
367
+ evaluatedDiscountList,
350
368
  isAvailable,
351
369
  unavailableReason
352
370
  } = rulesModule.isDiscountListAvailable({
@@ -361,20 +379,36 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
361
379
  productList: this.store.productList || [],
362
380
  discountList: this.getDiscountList()
363
381
  };
382
+ let isAccepted = isAvailable;
364
383
  if (isAvailable) {
384
+ if (this.entitlementPassEnabled) this.setProductList(newProductList || []);
365
385
  this.setDiscountList(newDiscountList || []);
366
386
  this.store.originalDiscountList = newDiscountList || [];
367
- this.setProductList(newProductList || []);
387
+ if (!this.entitlementPassEnabled) this.setProductList(newProductList || []);
368
388
  if (this.isWalkIn() && resultDiscountList.length && this.options.otherParams?.platform === 'shop' && !((resultDiscountList[0].customer_id || 1) === 1)) {
369
389
  await this.getCustomerWallet(resultDiscountList[0].customer_id);
370
390
  }
371
391
  }
392
+ if (!isAvailable) {
393
+ const ids = new Set(withScanList.map(item => String(item.id)));
394
+ const retainable = (evaluatedDiscountList || []).filter(item => ids.has(String(item.id)) && (0, _entitlementPass.isEntitlementPass)(item) && !(0, _availability.getDiscountLifecycleReason)(item));
395
+ if (retainable.length) {
396
+ this.setDiscountList((0, _entitlementState.retainScannedEntitlements)(this.getDiscountList(), retainable));
397
+ isAccepted = true;
398
+ }
399
+ }
400
+ if (this.entitlementPassEnabled) {
401
+ this.store.originalDiscountList = this.getDiscountList();
402
+ await this.store.discount?.setOriginalDiscountList(this.getDiscountList());
403
+ }
372
404
  return {
373
405
  type: "clientCalc",
374
406
  isAvailable: isAvailable || false,
375
- productList: newProductList || this.store.productList || [],
376
- discountList: newDiscountList || this.getDiscountList(),
377
- unavailableReason
407
+ isAccepted,
408
+ productList: isAvailable ? newProductList : this.store.productList || [],
409
+ discountList: this.getDiscountList(),
410
+ unavailableReason,
411
+ unavailableReasonKey: (evaluatedDiscountList || []).find(item => withScanList.some(scanned => String(scanned.id) === String(item.id)) && item.reasonCode)?.reasonCode || unavailableReasonKey
378
412
  };
379
413
  } catch (error) {
380
414
  console.error('[ShopDiscount] 扫码出错:', error);
@@ -454,7 +488,7 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
454
488
  });
455
489
  }
456
490
  });
457
- const newDiscountList = [...editModeDiscountList, ...discountList.filter(item => !item.isDisabled)];
491
+ const newDiscountList = this.entitlementPassEnabled ? (0, _entitlementState.withCommittedEntitlementDetails)([...editModeDiscountList.filter(item => !(0, _entitlementPass.isEntitlementPass)(item)), ...discountList.filter(item => (0, _entitlementPass.isEntitlementPass)(item) || !item.isDisabled)], productList, this.hooks?.getProduct || (item => item)) : [...editModeDiscountList, ...discountList.filter(item => !item.isDisabled && !(0, _entitlementPass.isEntitlementPass)(item))];
458
492
  const isProductFree = id => {
459
493
  const targetProduct = productList.find(n => n.id === id);
460
494
  if (!targetProduct) return false;
@@ -497,7 +531,8 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
497
531
  const {
498
532
  ...customer
499
533
  } = result.data;
500
- this.setCustomer(customer);
534
+ const customerUpdate = this.setCustomer(customer);
535
+ if (this.entitlementPassEnabled) await customerUpdate;
501
536
  await this.core.effects.emit(`${this.name}:onScanCustomerChange`, customer);
502
537
  }
503
538
  } catch (error) {
@@ -518,6 +553,7 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
518
553
  // 加载准备配置
519
554
  async loadPrepareConfig(params) {
520
555
  try {
556
+ const entitlementPassEnabled = this.entitlementPassEnabled;
521
557
  const orderId = this.store.orderId;
522
558
  const customerId = params.customerId || this.getCustomer()?.id;
523
559
  // if (customerId === 1 || !customerId) {
@@ -530,25 +566,26 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
530
566
  with_good_pass: 1,
531
567
  with_discount_card: 1,
532
568
  with_wallet_pass_holder: 1,
569
+ ...(this.entitlementPassEnabled ? {
570
+ with_entitlement_pass: 1,
571
+ filter_order_wallet_pass_usage: 0
572
+ } : {}),
533
573
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
534
574
  ...(orderId ? {
535
575
  order_id: orderId
536
576
  } : {})
537
577
  });
538
578
  const goodPassList = prepareConfigResult?.discountList || [];
539
- const scanDiscount = this.getDiscountList()?.filter(item => item.isScan);
540
-
541
- // goodPassList 里可能有 scanDiscount 重合的部分,goodPassList 需要剔除
542
- const scanDiscountIds = scanDiscount.map(n => n.id);
543
- const newGoodPassList = goodPassList.filter(n => !scanDiscountIds.includes(n.id));
544
- const newDiscountList = [...scanDiscount, ...(newGoodPassList || [])];
579
+ if (entitlementPassEnabled !== this.entitlementPassEnabled) return;
580
+ if (entitlementPassEnabled && (String(customerId) !== String(this.getCustomer()?.id) || String(orderId) !== String(this.store.orderId))) return;
581
+ const newDiscountList = (0, _entitlementState.mergeEntitlementDiscountLists)(this.getDiscountList(), goodPassList || [], this.store.discount?.getOriginalDiscountList());
545
582
 
546
583
  // 存储原始优惠券列表
547
584
  this.store.originalDiscountList = newDiscountList;
548
585
  await this.store.discount?.setOriginalDiscountList(newDiscountList);
549
586
 
550
587
  // 根据当前预约时间过滤优惠券列表
551
- const filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
588
+ const filteredDiscountList = newDiscountList.filter(item => (0, _entitlementPass.isEntitlementPass)(item) || this.filterDiscountListByBookingTime([item], this.store.currentBookingTime).length > 0);
552
589
  this.store.filteredDiscountList = filteredDiscountList;
553
590
  this.setDiscountList(filteredDiscountList || []);
554
591
  if (this.store.productList?.length) {
@@ -11,7 +11,7 @@ export declare enum ShopDiscountHooks {
11
11
  onRulesListChange = "shopDiscount:onRulesListChange",
12
12
  onLoadPrepareCalcResult = "shopDiscount:onLoadPrepareCalcResult"
13
13
  }
14
- export declare type Customer = {
14
+ export type Customer = {
15
15
  id: string | number;
16
16
  name: string;
17
17
  email: string;
@@ -21,13 +21,13 @@ export declare const isAllNormalProduct: (items: any[]) => boolean;
21
21
  * @returns
22
22
  */
23
23
  export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
24
- export declare const getDiscountListAmountTotal: (discount: Discount[]) => Discount;
24
+ export declare const getDiscountListAmountTotal: (discount: Discount[]) => any;
25
25
  /**
26
26
  * 获取折扣金额 计算每个折扣的金额
27
27
  * @param discount
28
28
  * @returns
29
29
  */
30
- export declare const getDiscountListAmount: (discount: Discount[]) => Discount;
30
+ export declare const getDiscountListAmount: (discount: Discount[]) => any;
31
31
  export interface ScheduleItem {
32
32
  id: number;
33
33
  name: string | {
@@ -98,3 +98,4 @@ export declare const calculateOrderLevelDiscountAllocation: (discount: Discount,
98
98
  discountAmount: number;
99
99
  difference: number;
100
100
  }>;
101
+ export declare const getDiscountTimeUnavailableReason: (discount: Discount, useTime: string) => 'not_started' | 'time_limit' | 'outside_schedule' | undefined;
@@ -3,10 +3,15 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.uniqueById = exports.isOrderLevelFixedAmountDiscount = exports.isNormalProductByDurationSchedule = exports.isAllNormalProduct = exports.getDiscountListAmountTotal = exports.getDiscountListAmount = exports.getDiscountAmount = exports.getDateIsInSchedule = exports.filterDiscountListByBookingTime = exports.calculateOrderLevelDiscountAllocation = void 0;
6
+ exports.uniqueById = exports.isOrderLevelFixedAmountDiscount = exports.isNormalProductByDurationSchedule = exports.isAllNormalProduct = exports.getDiscountTimeUnavailableReason = exports.getDiscountListAmountTotal = exports.getDiscountListAmount = exports.getDiscountAmount = exports.getDateIsInSchedule = exports.filterDiscountListByBookingTime = exports.calculateOrderLevelDiscountAllocation = void 0;
7
7
  var _decimal = _interopRequireDefault(require("decimal.js"));
8
8
  var _dayjs = _interopRequireDefault(require("dayjs"));
9
+ var _isSameOrAfter = _interopRequireDefault(require("dayjs/plugin/isSameOrAfter"));
10
+ var _isSameOrBefore = _interopRequireDefault(require("dayjs/plugin/isSameOrBefore"));
11
+ var _entitlementPass = require("../../modules/Discount/entitlementPass");
9
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ _dayjs.default.extend(_isSameOrAfter.default);
14
+ _dayjs.default.extend(_isSameOrBefore.default);
10
15
  const uniqueById = (arr, key = 'id') => {
11
16
  const seen = new Set();
12
17
  return arr.filter(item => !seen.has(item[key]) && seen.add(item[key]));
@@ -45,7 +50,7 @@ const isAllNormalProduct = items => {
45
50
  exports.isAllNormalProduct = isAllNormalProduct;
46
51
  const getDiscountAmount = (discount, total, price) => {
47
52
  // 商品券
48
- if (discount.tag === 'good_pass') {
53
+ if ((0, _entitlementPass.isFullCoveragePass)(discount)) {
49
54
  return new _decimal.default(price).minus(new _decimal.default(price || 0)).toNumber();
50
55
  }
51
56
 
@@ -395,6 +400,7 @@ const filterDiscountListByBookingTime = (discountList, bookingTime) => {
395
400
  return discountList;
396
401
  }
397
402
  return discountList.filter(discount => {
403
+ if ((0, _entitlementPass.isEntitlementPass)(discount)) return !getDiscountTimeUnavailableReason(discount, bookingTime);
398
404
  if (discount?.metadata?.validity_type === "custom_schedule_validity") {
399
405
  return getDateIsInSchedule(bookingTime, discount.custom_schedule_snapshot?.data || []);
400
406
  }
@@ -540,4 +546,34 @@ const calculateOrderLevelDiscountAllocation = (discount, applicableProducts) =>
540
546
  }
541
547
  return result;
542
548
  };
543
- exports.calculateOrderLevelDiscountAllocation = calculateOrderLevelDiscountAllocation;
549
+ exports.calculateOrderLevelDiscountAllocation = calculateOrderLevelDiscountAllocation;
550
+ const getDiscountTimeUnavailableReason = (discount, useTime) => {
551
+ const useTimeDayjs = (0, _dayjs.default)(useTime);
552
+ if (!useTimeDayjs.isValid()) return 'time_limit';
553
+ try {
554
+ if (discount?.metadata?.validity_type === "custom_schedule_validity") {
555
+ return getDateIsInSchedule(useTime, discount.custom_schedule_snapshot?.data || []) ? undefined : 'outside_schedule';
556
+ }
557
+ const isHasStart = !!discount.start_date && !!discount.start_time;
558
+ const startDate = (0, _dayjs.default)(`${discount.start_date} ${discount.start_time}`);
559
+
560
+ // 开始时刻包含在有效期内。
561
+ if (isHasStart) {
562
+ if (!startDate.isValid()) return 'time_limit';
563
+ if (useTimeDayjs.isBefore(startDate)) return 'not_started';
564
+ }
565
+
566
+ // 到期时刻不再可用;expire_time 为空时为长期有效。
567
+ const expireTime = discount.expire_time ? (0, _dayjs.default)(discount.expire_time) : null;
568
+ const isBeforeExpire = expireTime ? expireTime.isValid() && useTimeDayjs.isBefore(expireTime) : true;
569
+ if (!isBeforeExpire) return 'time_limit';
570
+ const validity = discount.extension_data?.find(field => field.field_key === 'valid_times')?.value;
571
+ if (validity?.restrict_use_by_schedule === true && !getDateIsInSchedule(useTime, discount.custom_schedule_snapshot?.data || [])) {
572
+ return 'outside_schedule';
573
+ }
574
+ return undefined;
575
+ } catch (error) {
576
+ return 'time_limit';
577
+ }
578
+ };
579
+ exports.getDiscountTimeUnavailableReason = getDiscountTimeUnavailableReason;
@@ -55,7 +55,7 @@ export interface UnifiedBookingSalesStagePlannerProductsParams {
55
55
  rawProducts?: Record<string, any>[];
56
56
  }
57
57
  /** Ordinary retail product staging. No resource, time, or booking facts are required. */
58
- export declare type UnifiedBookingSalesStageRetailProductsParams = UnifiedBookingSalesStagePlannerProductsParams;
58
+ export type UnifiedBookingSalesStageRetailProductsParams = UnifiedBookingSalesStagePlannerProductsParams;
59
59
  /** Adds one ordinary retail product without replacing other retail lines already in the cart. */
60
60
  export interface UnifiedBookingSalesAddRetailProductParams {
61
61
  /** Prefer a supplied catalog record when the UI has already loaded it. */
@@ -11,7 +11,7 @@ export declare enum VenueBookingHooks {
11
11
  /** 登录客户的智能定价、营销配置与订单汇总已完成刷新 */
12
12
  onSmartPricingUpdated = "venueBooking:onSmartPricingUpdated"
13
13
  }
14
- export declare type VenueBookingStatus = 'idle' | 'initializing' | 'ready' | 'error';
14
+ export type VenueBookingStatus = 'idle' | 'initializing' | 'ready' | 'error';
15
15
  export interface VenueBookingEntryContext {
16
16
  biz: string;
17
17
  venueId?: string;
@@ -38,7 +38,7 @@ export interface ModuleOptions {
38
38
  initialState?: Record<string, any>;
39
39
  otherParams?: Record<string, any>;
40
40
  }
41
- export declare type EventHandler = (data?: any) => void;
41
+ export type EventHandler = (data?: any) => void;
42
42
  export interface PisellCore {
43
43
  registerPlugin: (plugin: Plugin, options?: PluginOptions) => void;
44
44
  getPlugin: <T extends Plugin>(name: string) => T | null;
@@ -1,5 +1,5 @@
1
- declare type Action = (...args: any[]) => Promise<any>;
2
- declare type Task = {
1
+ type Action = (...args: any[]) => Promise<any>;
2
+ type Task = {
3
3
  uuid: string;
4
4
  type: string;
5
5
  actionParams?: Record<string, any>;
@@ -2,8 +2,8 @@
2
2
  * 监听模块
3
3
  *
4
4
  */
5
- export declare type WatchEventCallback = (...args: any[]) => void;
6
- export declare type WatchEventItem = {
5
+ export type WatchEventCallback = (...args: any[]) => void;
6
+ export type WatchEventItem = {
7
7
  key: string;
8
8
  callback: WatchEventCallback;
9
9
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.571",
4
+ "version": "0.0.572",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -9,6 +9,23 @@
9
9
  "dist",
10
10
  "lib"
11
11
  ],
12
+ "scripts": {
13
+ "build": "father build",
14
+ "dev": "father dev --watch",
15
+ "push": "yalc push --replace",
16
+ "test": "vitest",
17
+ "lint": "eslint src --ext .ts",
18
+ "format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,md}\"",
19
+ "changeset": "changeset",
20
+ "version": "changeset version",
21
+ "release": "changeset publish && npm run sync && git push",
22
+ "example": "npx parcel-bundler examples/index.html",
23
+ "docs": "typedoc --out docs src/index.ts",
24
+ "sync": "node sync.js",
25
+ "prepublishOnly": "npm run build",
26
+ "deploy": "npm run build && npm run changeset && npm run version && npm run release",
27
+ "deploy:ci": "npm run build && npm run version && changeset publish --registry=https://registry.npmjs.com/ && npm run sync"
28
+ },
12
29
  "repository": {
13
30
  "type": "git",
14
31
  "url": "git+https://github.com/username/pisell-os.git"
@@ -53,21 +70,5 @@
53
70
  },
54
71
  "publishConfig": {
55
72
  "access": "public"
56
- },
57
- "scripts": {
58
- "build": "father build",
59
- "dev": "father dev --watch",
60
- "push": "yalc push --replace",
61
- "test": "vitest",
62
- "lint": "eslint src --ext .ts",
63
- "format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,md}\"",
64
- "changeset": "changeset",
65
- "version": "changeset version",
66
- "release": "changeset publish && npm run sync && git push",
67
- "example": "npx parcel-bundler examples/index.html",
68
- "docs": "typedoc --out docs src/index.ts",
69
- "sync": "node sync.js",
70
- "deploy": "npm run build && npm run changeset && npm run version && npm run release",
71
- "deploy:ci": "npm run build && npm run version && changeset publish --registry=https://registry.npmjs.com/ && npm run sync"
72
73
  }
73
- }
74
+ }