@pisell/pisellos 0.0.91 → 0.0.93

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.
@@ -209,7 +209,18 @@ export var handleAvailableDatesByRules = function handleAvailableDatesByRules(da
209
209
  var disabledDate = _objectSpread(_objectSpread({}, date), {}, {
210
210
  status: 'unavailable'
211
211
  });
212
-
212
+ var hasScheduleConfig = rules.find(function (n) {
213
+ var _n$schedule;
214
+ return (_n$schedule = n.schedule) === null || _n$schedule === void 0 ? void 0 : _n$schedule.length;
215
+ });
216
+ // 如果外面穿了 schedule,但是这个时候scheduleMap为空,则设置为不可用
217
+ // 这种情况为,商品设置了 5.1-5.31 可用,资源设置了 5.1-6.30 可用,session 类商品详情弹窗里里看到的6 月以后的日期都应该是不可用的
218
+ if (Object.keys(scheduleMap).length === 0 && hasScheduleConfig) {
219
+ return _objectSpread(_objectSpread({}, date), {}, {
220
+ color: '',
221
+ status: 'unavailable'
222
+ });
223
+ }
213
224
  // 根据日程判断日期是否可用
214
225
  if (Object.keys(scheduleMap).length) {
215
226
  var schedule = scheduleMap[date.date];
@@ -243,7 +243,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
243
243
 
244
244
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
245
245
  sortedProductList.forEach(function (originProduct) {
246
- var _product$discount_lis3, _product$discount_lis4, _product$discount_lis5;
246
+ var _product$discount_lis3, _product$discount_lis4, _product$discount_lis5, _product$discount_lis6, _product$discount_lis7;
247
247
  var product = _this3.hooks.getProduct(originProduct);
248
248
  if (product !== null && product !== void 0 && product.booking_id && (_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.length && product !== null && product !== void 0 && (_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.every(function (discount) {
249
249
  return discount.id && discount.type === 'good_pass';
@@ -271,7 +271,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
271
271
  var selectedDiscount = applicableDiscounts[0];
272
272
 
273
273
  // 如果是手动折扣,则不适用优惠券
274
- var isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && !((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length);
274
+ var isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || (product === null || product === void 0 || (_product$discount_lis6 = product.discount_list) === null || _product$discount_lis6 === void 0 || (_product$discount_lis7 = _product$discount_lis6.every) === null || _product$discount_lis7 === void 0 ? void 0 : _product$discount_lis7.call(_product$discount_lis6, function (item) {
275
+ return item.type === 'product';
276
+ })));
275
277
 
276
278
  // 勾选时覆盖手动折扣
277
279
  if (options !== null && options !== void 0 && options.discountId && (options === null || options === void 0 ? void 0 : options.discountId) === (selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.id)) {
@@ -302,7 +304,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
302
304
  })));
303
305
  } else {
304
306
  processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
305
- total: product.total,
307
+ total: product.origin_total || product.total,
306
308
  price: product.price
307
309
  }), {}, {
308
310
  discount_list: []
@@ -716,7 +716,7 @@ export function getAllSortedDateRanges(schedules) {
716
716
  }
717
717
 
718
718
  // 按照开始时间和时长排序
719
- return allDateRanges.sort(function (a, b) {
719
+ var sortedDateRanges = allDateRanges.sort(function (a, b) {
720
720
  // 首先按开始时间排序
721
721
  var startTimeCompare = dayjs(a.start).valueOf() - dayjs(b.start).valueOf();
722
722
  if (startTimeCompare !== 0) return startTimeCompare;
@@ -726,4 +726,12 @@ export function getAllSortedDateRanges(schedules) {
726
726
  var durationB = dayjs(b.end).valueOf() - dayjs(b.start).valueOf();
727
727
  return durationA - durationB;
728
728
  });
729
+
730
+ // 排序完了,还需要做个去重,如果有开始时间结束时间完全一致的,则只保留一个
731
+ var uniqueDateRanges = sortedDateRanges.filter(function (range, index, self) {
732
+ return index === self.findIndex(function (t) {
733
+ return t.start === range.start && t.end === range.end;
734
+ });
735
+ });
736
+ return uniqueDateRanges;
729
737
  }
@@ -205,6 +205,10 @@ export var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref2) {
205
205
  canBookingForOngoing = true;
206
206
  }
207
207
  }
208
+ } else if (type === 'ongoing' && (ongoing === null || ongoing === void 0 ? void 0 : ongoing.type) === 'before_end') {
209
+ if (dayjs(timeSlice.end_at).isAfter(earliest)) {
210
+ canBookingForOngoing = true;
211
+ }
208
212
  } else {
209
213
  if (unit) {
210
214
  earliest = earliest.add(unit, unit_type);
@@ -155,6 +155,13 @@ var handleAvailableDatesByRules = (dates, rules) => {
155
155
  newDates = newDates.map((date) => {
156
156
  var _a;
157
157
  const disabledDate = { ...date, status: "unavailable" };
158
+ const hasScheduleConfig = rules.find((n) => {
159
+ var _a2;
160
+ return (_a2 = n.schedule) == null ? void 0 : _a2.length;
161
+ });
162
+ if (Object.keys(scheduleMap).length === 0 && hasScheduleConfig) {
163
+ return { ...date, color: "", status: "unavailable" };
164
+ }
158
165
  if (Object.keys(scheduleMap).length) {
159
166
  const schedule = scheduleMap[date.date];
160
167
  if (!schedule || (schedule == null ? void 0 : schedule.isExcluded)) {
@@ -154,7 +154,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
154
154
  });
155
155
  });
156
156
  sortedProductList.forEach((originProduct) => {
157
- var _a, _b, _c;
157
+ var _a, _b, _c, _d, _e;
158
158
  const product = this.hooks.getProduct(originProduct);
159
159
  if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && discount.type === "good_pass"))) {
160
160
  processedProductsMap.set(product._id, originProduct);
@@ -172,7 +172,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
172
172
  return false;
173
173
  });
174
174
  const selectedDiscount = applicableDiscounts[0];
175
- let isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && !((_c = product.discount_list) == null ? void 0 : _c.length);
175
+ let isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (!((_c = product.discount_list) == null ? void 0 : _c.length) || ((_e = (_d = product == null ? void 0 : product.discount_list) == null ? void 0 : _d.every) == null ? void 0 : _e.call(_d, (item) => item.type === "product")));
176
176
  if ((options == null ? void 0 : options.discountId) && (options == null ? void 0 : options.discountId) === (selectedDiscount == null ? void 0 : selectedDiscount.id)) {
177
177
  isManualDiscount = false;
178
178
  }
@@ -206,7 +206,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
206
206
  product._id,
207
207
  this.hooks.setProduct(originProduct, {
208
208
  ...isManualDiscount ? {} : {
209
- total: product.total,
209
+ total: product.origin_total || product.total,
210
210
  price: product.price
211
211
  },
212
212
  discount_list: []
@@ -573,7 +573,7 @@ function getAllSortedDateRanges(schedules) {
573
573
  console.log("No dateRanges found in schedules:", schedules);
574
574
  return [];
575
575
  }
576
- return allDateRanges.sort((a, b) => {
576
+ let sortedDateRanges = allDateRanges.sort((a, b) => {
577
577
  const startTimeCompare = (0, import_dayjs.default)(a.start).valueOf() - (0, import_dayjs.default)(b.start).valueOf();
578
578
  if (startTimeCompare !== 0)
579
579
  return startTimeCompare;
@@ -581,6 +581,10 @@ function getAllSortedDateRanges(schedules) {
581
581
  const durationB = (0, import_dayjs.default)(b.end).valueOf() - (0, import_dayjs.default)(b.start).valueOf();
582
582
  return durationA - durationB;
583
583
  });
584
+ const uniqueDateRanges = sortedDateRanges.filter(
585
+ (range, index, self) => index === self.findIndex((t) => t.start === range.start && t.end === range.end)
586
+ );
587
+ return uniqueDateRanges;
584
588
  }
585
589
  // Annotate the CommonJS export names for ESM import in node:
586
590
  0 && (module.exports = {
@@ -149,6 +149,10 @@ var getIsUsableByTimeItem = ({
149
149
  canBookingForOngoing = true;
150
150
  }
151
151
  }
152
+ } else if (type === "ongoing" && (ongoing == null ? void 0 : ongoing.type) === "before_end") {
153
+ if ((0, import_dayjs.default)(timeSlice.end_at).isAfter(earliest)) {
154
+ canBookingForOngoing = true;
155
+ }
152
156
  } else {
153
157
  if (unit) {
154
158
  earliest = earliest.add(unit, unit_type);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.91",
4
+ "version": "0.0.93",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",