@pisell/pisellos 3.0.77 → 3.0.78

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.
@@ -20,7 +20,9 @@ export interface ITime {
20
20
  date: string;
21
21
  week: string;
22
22
  weekNum: number;
23
- status: 'unavailable' | 'available';
23
+ status: 'unavailable' | 'available' | 'lots_of_space' | 'filling_up_fast' | 'sold_out';
24
+ summaryCount?: number;
25
+ availableCount?: number;
24
26
  resource?: any[];
25
27
  color?: string[];
26
28
  }
@@ -137,17 +137,16 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
137
137
  productsData = _context3.sent;
138
138
  sortedList = (productsData.data.list || []).slice().sort(function (a, b) {
139
139
  return Number(b.sort) - Number(a.sort);
140
- });
141
- if (sortedList.length) {
142
- sortedList.forEach(function (n) {
143
- if (n.is_eject !== 1 && n['schedule.ids'] && n['schedule.ids'].length) {
144
- n.is_eject = 1;
145
- }
146
- });
147
- }
140
+ }); // if (sortedList.length) {
141
+ // sortedList.forEach((n: any) => {
142
+ // if (n.is_eject !== 1 && n['schedule.ids'] && n['schedule.ids'].length) {
143
+ // n.is_eject = 1
144
+ // }
145
+ // })
146
+ // }
148
147
  this.addProduct(sortedList);
149
148
  return _context3.abrupt("return", sortedList);
150
- case 11:
149
+ case 10:
151
150
  case "end":
152
151
  return _context3.stop();
153
152
  }
@@ -1,6 +1,6 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { Rules, RulesModuleAPI, DiscountResult } from './types';
3
+ import { Rules, RulesModuleAPI, DiscountResult, UnavailableReason } from './types';
4
4
  import { Discount } from "../Discount/types";
5
5
  export declare class RulesModule extends BaseModule implements Module, RulesModuleAPI {
6
6
  protected defaultName: string;
@@ -24,7 +24,9 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
24
24
  isAvailable: boolean;
25
25
  discountList: Discount[];
26
26
  productList: any[];
27
+ unavailableReason?: UnavailableReason;
27
28
  };
29
+ private getUnavailableReason;
28
30
  calcDiscount({ discountList, productList, holders, isFormSubject, }: {
29
31
  discountList: Discount[];
30
32
  productList: any[];
@@ -1,6 +1,7 @@
1
1
  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); }
2
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
4
5
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5
6
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
7
  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); }
@@ -24,7 +25,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
24
25
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
25
26
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
26
27
  import { BaseModule } from "../BaseModule";
27
- import { RulesHooks } from "./types";
28
+ import { RulesHooks, UnavailableReason } from "./types";
28
29
  import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount, filterDiscountListByBookingTime, isOrderLevelFixedAmountDiscount, calculateOrderLevelDiscountAllocation } from "../../solution/ShopDiscount/utils";
29
30
  import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
30
31
  import Decimal from 'decimal.js';
@@ -138,7 +139,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
138
139
  return {
139
140
  isAvailable: false,
140
141
  discountList: oldDiscountList,
141
- productList: productList
142
+ productList: productList,
143
+ unavailableReason: UnavailableReason.AlreadyUsed
142
144
  };
143
145
  }
144
146
 
@@ -183,12 +185,93 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
183
185
  }
184
186
  }
185
187
  });
188
+
189
+ // 如果券不可用,判断不可用原因
190
+ var unavailableReason;
191
+ if (!hasApplicableDiscount) {
192
+ unavailableReason = this.getUnavailableReason(newDiscountList, productList);
193
+ }
186
194
  return {
187
195
  isAvailable: hasApplicableDiscount,
188
196
  discountList: hasApplicableDiscount ? result.discountList : oldDiscountList,
189
- productList: hasApplicableDiscount ? result.productList : productList
197
+ productList: hasApplicableDiscount ? result.productList : productList,
198
+ unavailableReason: unavailableReason
190
199
  };
191
200
  }
201
+
202
+ // 获取券不可用的原因
203
+ }, {
204
+ key: "getUnavailableReason",
205
+ value: function getUnavailableReason(discountList, productList) {
206
+ // 检查时间限制
207
+ var _iterator = _createForOfIteratorHelper(discountList),
208
+ _step;
209
+ try {
210
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
211
+ var discount = _step.value;
212
+ var _iterator3 = _createForOfIteratorHelper(productList),
213
+ _step3;
214
+ try {
215
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
216
+ var item = _step3.value;
217
+ var product = this.hooks.getProduct(item);
218
+ var bookingTime = ((product === null || product === void 0 ? void 0 : product.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss');
219
+ var filteredList = filterDiscountListByBookingTime([discount], bookingTime);
220
+ if (filteredList.length === 0) {
221
+ return UnavailableReason.TimeLimit;
222
+ }
223
+ }
224
+ } catch (err) {
225
+ _iterator3.e(err);
226
+ } finally {
227
+ _iterator3.f();
228
+ }
229
+ }
230
+
231
+ // 检查商品适用性
232
+ } catch (err) {
233
+ _iterator.e(err);
234
+ } finally {
235
+ _iterator.f();
236
+ }
237
+ var _iterator2 = _createForOfIteratorHelper(discountList),
238
+ _step2;
239
+ try {
240
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
241
+ var _discount = _step2.value;
242
+ var limitedData = _discount.limited_relation_product_data;
243
+ var hasApplicableProduct = false;
244
+ var _iterator4 = _createForOfIteratorHelper(productList),
245
+ _step4;
246
+ try {
247
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
248
+ var _limitedData$product_;
249
+ var _item = _step4.value;
250
+ var _product = this.hooks.getProduct(_item);
251
+ if (limitedData.type === 'product_all') {
252
+ hasApplicableProduct = true;
253
+ break;
254
+ } else if ((_limitedData$product_ = limitedData.product_ids) !== null && _limitedData$product_ !== void 0 && _limitedData$product_.includes(_product.id)) {
255
+ hasApplicableProduct = true;
256
+ break;
257
+ }
258
+ }
259
+ } catch (err) {
260
+ _iterator4.e(err);
261
+ } finally {
262
+ _iterator4.f();
263
+ }
264
+ if (!hasApplicableProduct) {
265
+ return UnavailableReason.ProductNotApplicable;
266
+ }
267
+ }
268
+ } catch (err) {
269
+ _iterator2.e(err);
270
+ } finally {
271
+ _iterator2.f();
272
+ }
273
+ return UnavailableReason.Unknown;
274
+ }
192
275
  }, {
193
276
  key: "calcDiscount",
194
277
  value: function calcDiscount(_ref2, options) {
@@ -487,7 +570,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
487
570
 
488
571
  // 辅助函数:检查商品是否对某个折扣卡可用
489
572
  var checkItemApplicableForDiscount = function checkItemApplicableForDiscount(flatItem, discount) {
490
- var _product, _product2, _product3, _flatItem$bundleItem, _flatItem$bundleItem2, _product4;
573
+ var _product2, _product3, _product4, _flatItem$bundleItem, _flatItem$bundleItem2, _product5;
491
574
  var product;
492
575
  if (flatItem.type === 'main') {
493
576
  product = flatItem.product;
@@ -506,7 +589,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
506
589
  }
507
590
 
508
591
  // 编辑的商品使用了优惠券不可用
509
- var isAvailableProduct = flatItem.type === 'main' ? !((_product = product) !== null && _product !== void 0 && _product.booking_id && (_product2 = product) !== null && _product2 !== void 0 && (_product2 = _product2.discount_list) !== null && _product2 !== void 0 && _product2.length && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.every(function (d) {
592
+ var isAvailableProduct = flatItem.type === 'main' ? !((_product2 = product) !== null && _product2 !== void 0 && _product2.booking_id && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.length && (_product4 = product) !== null && _product4 !== void 0 && (_product4 = _product4.discount_list) !== null && _product4 !== void 0 && _product4.every(function (d) {
510
593
  return d.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(d.tag || d.type);
511
594
  })) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem = flatItem.bundleItem) !== null && _flatItem$bundleItem !== void 0 && (_flatItem$bundleItem = _flatItem$bundleItem.discount_list) !== null && _flatItem$bundleItem !== void 0 && _flatItem$bundleItem.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem2 = flatItem.bundleItem) !== null && _flatItem$bundleItem2 !== void 0 && (_flatItem$bundleItem2 = _flatItem$bundleItem2.discount_list) !== null && _flatItem$bundleItem2 !== void 0 && _flatItem$bundleItem2.every(function (d) {
512
595
  return d.id;
@@ -527,7 +610,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
527
610
  var limitedData = discount.limited_relation_product_data;
528
611
 
529
612
  // 时间限制检查
530
- var timeLimit = !!filterDiscountListByBookingTime([discount], (((_product4 = product) === null || _product4 === void 0 ? void 0 : _product4.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
613
+ var timeLimit = !!filterDiscountListByBookingTime([discount], (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
531
614
  if (!timeLimit) {
532
615
  return false;
533
616
  }
@@ -692,7 +775,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
692
775
  originProduct = flatItem.originProduct;
693
776
  }
694
777
  addModeDiscount.forEach(function (discount) {
695
- var _product5, _product6, _product7, _product8, _flatItem$bundleItem3, _flatItem$bundleItem4;
778
+ var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4;
696
779
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
697
780
 
698
781
  // 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
@@ -702,12 +785,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
702
785
  holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
703
786
  }, holders);
704
787
  var timeLimit = true;
705
- timeLimit = !!filterDiscountListByBookingTime([discount], (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
788
+ timeLimit = !!filterDiscountListByBookingTime([discount], (((_product6 = product) === null || _product6 === void 0 ? void 0 : _product6.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
706
789
  // 是符合折扣的商品
707
790
  var isLimitedProduct = (limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
708
791
 
709
792
  // 编辑的商品 使用了优惠券不可用
710
- var isAvailableProduct = flatItem.type === 'main' ? !((_product6 = product) !== null && _product6 !== void 0 && _product6.booking_id && (_product7 = product) !== null && _product7 !== void 0 && (_product7 = _product7.discount_list) !== null && _product7 !== void 0 && _product7.length && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.every(function (discount) {
793
+ var isAvailableProduct = flatItem.type === 'main' ? !((_product7 = product) !== null && _product7 !== void 0 && _product7.booking_id && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.length && (_product9 = product) !== null && _product9 !== void 0 && (_product9 = _product9.discount_list) !== null && _product9 !== void 0 && _product9.every(function (discount) {
711
794
  return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
712
795
  })) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem3 = flatItem.bundleItem) !== null && _flatItem$bundleItem3 !== void 0 && (_flatItem$bundleItem3 = _flatItem$bundleItem3.discount_list) !== null && _flatItem$bundleItem3 !== void 0 && _flatItem$bundleItem3.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem4 = flatItem.bundleItem) !== null && _flatItem$bundleItem4 !== void 0 && (_flatItem$bundleItem4 = _flatItem$bundleItem4.discount_list) !== null && _flatItem$bundleItem4 !== void 0 && _flatItem$bundleItem4.every(function (discount) {
713
796
  return discount.id;
@@ -759,7 +842,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
759
842
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
760
843
  // 🔥 使用扁平化后的列表进行处理
761
844
  sortedFlattenedList.forEach(function (flatItem, index) {
762
- var _product9, _product$discount_lis2, _product10;
845
+ var _product10, _product$discount_lis2, _product11;
763
846
  // 获取商品数据
764
847
  var product, originProduct;
765
848
  if (flatItem.type === 'main') {
@@ -785,7 +868,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
785
868
  }
786
869
 
787
870
  // 已有优惠的商品跳过
788
- if ((_product9 = product) !== null && _product9 !== void 0 && _product9.booking_id && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.length && (_product10 = product) !== null && _product10 !== void 0 && (_product10 = _product10.discount_list) !== null && _product10 !== void 0 && _product10.every(function (discount) {
871
+ if ((_product10 = product) !== null && _product10 !== void 0 && _product10.booking_id && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.length && (_product11 = product) !== null && _product11 !== void 0 && (_product11 = _product11.discount_list) !== null && _product11 !== void 0 && _product11.every(function (discount) {
789
872
  return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
790
873
  })) {
791
874
  if (flatItem.type === 'main') {
@@ -857,12 +940,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
857
940
  // 如果是手动折扣,则不适用优惠券
858
941
  var isManualDiscount = false;
859
942
  if (flatItem.type === 'main') {
860
- var _product$discount_lis5, _product11, _product11$every;
943
+ var _product$discount_lis5, _product12, _product12$every;
861
944
  // 主商品:判断自身是否手动折扣
862
945
  isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
863
946
  var _ref6;
864
947
  return !((_ref6 = item.discount_list || []) !== null && _ref6 !== void 0 && _ref6.length);
865
- }) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product11 = product) === null || _product11 === void 0 || (_product11 = _product11.discount_list) === null || _product11 === void 0 || (_product11$every = _product11.every) === null || _product11$every === void 0 ? void 0 : _product11$every.call(_product11, function (item) {
948
+ }) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product12 = product) === null || _product12 === void 0 || (_product12 = _product12.discount_list) === null || _product12 === void 0 || (_product12$every = _product12.every) === null || _product12$every === void 0 ? void 0 : _product12$every.call(_product12, function (item) {
866
949
  return item.type === 'product';
867
950
  })));
868
951
  } else {
@@ -1,4 +1,10 @@
1
1
  import { Discount } from '../Discount/types';
2
+ export declare enum UnavailableReason {
3
+ TimeLimit = "time_limit",
4
+ ProductNotApplicable = "product_not_applicable",
5
+ AlreadyUsed = "already_used",
6
+ Unknown = "unknown"
7
+ }
2
8
  export declare enum RulesHooks {
3
9
  OnRulesListChange = "rules:onRulesListChange",
4
10
  OnDestroy = "rules:onDestroy"
@@ -1,3 +1,11 @@
1
+ // 券不可用原因枚举
2
+ export var UnavailableReason = /*#__PURE__*/function (UnavailableReason) {
3
+ UnavailableReason["TimeLimit"] = "time_limit";
4
+ UnavailableReason["ProductNotApplicable"] = "product_not_applicable";
5
+ UnavailableReason["AlreadyUsed"] = "already_used";
6
+ UnavailableReason["Unknown"] = "unknown";
7
+ return UnavailableReason;
8
+ }({});
1
9
  export var RulesHooks = /*#__PURE__*/function (RulesHooks) {
2
10
  RulesHooks["OnRulesListChange"] = "rules:onRulesListChange";
3
11
  RulesHooks["OnDestroy"] = "rules:onDestroy";
@@ -299,6 +299,16 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
299
299
  errorList: any[];
300
300
  };
301
301
  getTimeSlotByAllResources(resources_code: string): any[];
302
+ getTimeSlotByAllResourcesForDate({ resources_code, startDate, endDate }: {
303
+ resources_code: string;
304
+ startDate: string;
305
+ endDate: string;
306
+ }): Promise<{
307
+ date: string;
308
+ status: string;
309
+ week: string;
310
+ weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
311
+ }[]>;
302
312
  submitTimeSlot(timeSlots: TimeSliceItem): void;
303
313
  private getScheduleDataByIds;
304
314
  openProductDetail(productId: number): Promise<void>;
@@ -316,6 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
316
326
  count: number;
317
327
  left: number;
318
328
  summaryCount: number;
329
+ status: keyof TimeStatusMap;
319
330
  }[];
320
331
  /**
321
332
  * 找到多个资源的公共可用时间段
@@ -380,3 +391,9 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
380
391
  */
381
392
  getContactInfo(params: any): Promise<any>;
382
393
  }
394
+ interface TimeStatusMap {
395
+ lots_of_space: true;
396
+ filling_up_fast: true;
397
+ sold_out: true;
398
+ }
399
+ export {};