@pisell/pisellos 2.0.60 → 2.0.61

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.
@@ -258,7 +258,8 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
258
258
  resources = params.resources,
259
259
  note = params.note,
260
260
  date = params.date,
261
- relationForms = params.relationForms;
261
+ relationForms = params.relationForms,
262
+ osWarnTips = params.osWarnTips;
262
263
  var quantity = params.quantity;
263
264
  var tempCartItem = this.store.list.find(function (i) {
264
265
  return i._id === _id;
@@ -324,6 +325,9 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
324
325
  note: note
325
326
  });
326
327
  }
328
+ if (osWarnTips) {
329
+ tempCartItem.osWarnTips = osWarnTips;
330
+ }
327
331
  return tempCartItem;
328
332
  }
329
333
 
@@ -110,6 +110,8 @@ export interface CartItem {
110
110
  bundle?: any[];
111
111
  /** 商品规格信息 */
112
112
  options?: any[];
113
+ /** 商品规格选项字符串 */
114
+ product_option_string?: string;
113
115
  /** 是否为普通商品 */
114
116
  isNormalProduct?: boolean;
115
117
  /** 资源ID */
@@ -142,8 +144,8 @@ export interface CartItem {
142
144
  _bundleOrigin?: any[];
143
145
  /** 商品规格原始数据 */
144
146
  _optionsOrigin?: any[];
145
- /** 商品规格组合字符串,提供给 UI 展示的 */
146
- product_option_string?: string;
147
+ /** 操作系统提示 */
148
+ osWarnTips?: string[];
147
149
  }
148
150
  /**
149
151
  * 购物车状态接口
@@ -217,6 +219,8 @@ export interface IUpdateItemParams {
217
219
  }[];
218
220
  /** 商品组合规格ID */
219
221
  product_variant_id?: number;
222
+ /** 操作系统提示 */
223
+ osWarnTips?: string[];
220
224
  }
221
225
  /**
222
226
  * 折扣
@@ -39,6 +39,7 @@ export var formatDateToCartItemOrigin = function formatDateToCartItemOrigin(para
39
39
  * @returns 删除后的购物车
40
40
  */
41
41
  export var deleteTimeFromCartItem = function deleteTimeFromCartItem(cartItem) {
42
+ var _cartItem$osWarnTips;
42
43
  // 删除UI层的数据
43
44
  cartItem.start_date = undefined;
44
45
  cartItem.start_time = undefined;
@@ -51,5 +52,10 @@ export var deleteTimeFromCartItem = function deleteTimeFromCartItem(cartItem) {
51
52
  cartItem._origin.start_time = null;
52
53
  cartItem._origin.end_date = null;
53
54
  cartItem._origin.end_time = null;
55
+
56
+ // 同时清空 osWarnTips 中的关于时间的提示
57
+ cartItem.osWarnTips = (_cartItem$osWarnTips = cartItem.osWarnTips) === null || _cartItem$osWarnTips === void 0 ? void 0 : _cartItem$osWarnTips.filter(function (item) {
58
+ return !item.includes('pisell2.product.card.closing-soon.warning');
59
+ });
54
60
  return cartItem;
55
61
  };
@@ -105,6 +105,11 @@ export interface ProductData {
105
105
  type: string;
106
106
  /** 值 */
107
107
  value: number;
108
+ flexible_config?: {
109
+ is_enable_minimum_duration?: 0 | 1;
110
+ warning_threshold?: number;
111
+ block_threshold?: number;
112
+ };
108
113
  };
109
114
  /** 商品显示设置 */
110
115
  product_display_setting: {
@@ -140,6 +140,12 @@ var getDaysByRepeatWeek = function getDaysByRepeatWeek(params, isGetRange) {
140
140
  for (var i = 0; i < frequency_date.length; i++) {
141
141
  var item = frequency_date[i];
142
142
  var _start = startTmp.day(item);
143
+
144
+ // 如果计算出的日期早于startTmp,则跳到下一周的相同星期几
145
+ if (_start.isBefore(startTmp, 'day')) {
146
+ _start = _start.add(1, 'week');
147
+ }
148
+
143
149
  // 如果周结束的那一天还超过了deadline,则需要把_end置为deadline
144
150
  var _end = _start.add(scheduleDiff, 'second');
145
151
  if (_end.isAfter(deadline, 'day')) {
@@ -161,7 +167,7 @@ var getDaysByRepeatWeek = function getDaysByRepeatWeek(params, isGetRange) {
161
167
  daysArr.push.apply(daysArr, _toConsumableArray(getDaysByStartEnd(_start, _end)));
162
168
  }
163
169
  }
164
- startTmp = startTmp.day(1).add(frequency, 'week');
170
+ startTmp = startTmp.add(frequency, 'week');
165
171
  }
166
172
  return Array.from(new Set(daysArr));
167
173
  };
@@ -1528,25 +1528,27 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1528
1528
  });
1529
1529
  });
1530
1530
  } else {
1531
- var _cartItem$_productOri3, _this10$shopStore$get;
1531
+ var _cartItem$_productOri3, _this10$shopStore$get, _cartItem$_productOri4, _cartItem$_productOri5;
1532
1532
  var hasFlexibleDuration = ((_cartItem$_productOri3 = cartItem._productOrigin) === null || _cartItem$_productOri3 === void 0 || (_cartItem$_productOri3 = _cartItem$_productOri3.duration) === null || _cartItem$_productOri3 === void 0 ? void 0 : _cartItem$_productOri3.type) === 'flexible';
1533
1533
  var operating_day_boundary = (_this10$shopStore$get = _this10.shopStore.get('core')) === null || _this10$shopStore$get === void 0 || (_this10$shopStore$get = _this10$shopStore$get.core) === null || _this10$shopStore$get === void 0 ? void 0 : _this10$shopStore$get.operating_day_boundary;
1534
+ var maxBlockThreshold = (_cartItem$_productOri4 = cartItem._productOrigin) !== null && _cartItem$_productOri4 !== void 0 && (_cartItem$_productOri4 = _cartItem$_productOri4.duration) !== null && _cartItem$_productOri4 !== void 0 && (_cartItem$_productOri4 = _cartItem$_productOri4.flexible_config) !== null && _cartItem$_productOri4 !== void 0 && _cartItem$_productOri4.is_enable_minimum_duration ? ((_cartItem$_productOri5 = cartItem._productOrigin) === null || _cartItem$_productOri5 === void 0 || (_cartItem$_productOri5 = _cartItem$_productOri5.duration) === null || _cartItem$_productOri5 === void 0 || (_cartItem$_productOri5 = _cartItem$_productOri5.flexible_config) === null || _cartItem$_productOri5 === void 0 ? void 0 : _cartItem$_productOri5.block_threshold) || 0 : 0;
1534
1535
  productResources.forEach(function (item) {
1535
1536
  // 如果资源的 capacity 已经小于了当前需要的 capacity ,则需要把资源给过滤掉
1536
1537
  // 同时,在这一步尝试去拉一下时间片,基于商品的时长,看每个资源是否还有空余时间能对这个商品做服务,如果没有则过滤
1537
1538
  item.renderList = item.renderList.filter(function (n) {
1538
- var _cartItem$_productOri4, _cartItem$_productOri5;
1539
+ var _cartItem$_productOri6, _cartItem$_productOri7;
1539
1540
  var recordCount = n.capacity || 0;
1540
1541
  if (n.onlyComputed) return false;
1541
1542
  // 查一下这个资源基于商品的可用时间片
1542
1543
  var timeSlots = getTimeSlicesByResource({
1543
1544
  resource: n,
1544
- duration: ((_cartItem$_productOri4 = cartItem._productOrigin) === null || _cartItem$_productOri4 === void 0 || (_cartItem$_productOri4 = _cartItem$_productOri4.duration) === null || _cartItem$_productOri4 === void 0 ? void 0 : _cartItem$_productOri4.value) || 10,
1545
+ duration: ((_cartItem$_productOri6 = cartItem._productOrigin) === null || _cartItem$_productOri6 === void 0 || (_cartItem$_productOri6 = _cartItem$_productOri6.duration) === null || _cartItem$_productOri6 === void 0 ? void 0 : _cartItem$_productOri6.value) || 10,
1545
1546
  split: 10,
1546
1547
  currentDate: dateRange[0].date,
1547
1548
  hasFlexibleDuration: hasFlexibleDuration,
1548
- cut_off_time: (_cartItem$_productOri5 = cartItem._productOrigin) === null || _cartItem$_productOri5 === void 0 ? void 0 : _cartItem$_productOri5.cut_off_time,
1549
- operating_day_boundary: operating_day_boundary
1549
+ cut_off_time: (_cartItem$_productOri7 = cartItem._productOrigin) === null || _cartItem$_productOri7 === void 0 ? void 0 : _cartItem$_productOri7.cut_off_time,
1550
+ operating_day_boundary: operating_day_boundary,
1551
+ maxBlockThreshold: maxBlockThreshold
1550
1552
  });
1551
1553
  return recordCount >= currentCapacity && timeSlots.length > 0;
1552
1554
  });
@@ -1647,7 +1649,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1647
1649
  }, {
1648
1650
  key: "autoSelectAccountResources",
1649
1651
  value: function autoSelectAccountResources(_ref9) {
1650
- var _cartItem$_productOri6, _allProductResources$;
1652
+ var _cartItem$_productOri8, _allProductResources$;
1651
1653
  var cartItem = _ref9.cartItem,
1652
1654
  holder_id = _ref9.holder_id,
1653
1655
  resources_code = _ref9.resources_code,
@@ -1696,7 +1698,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1696
1698
  var resourcesMap = getResourcesMap(cloneDeep(AllResources));
1697
1699
  var allCartItems = cloneDeep(this.store.cart.getItems());
1698
1700
  var selectedResources = getOthersSelectedResources(allCartItems, holder_id, resourcesMap);
1699
- var allProductResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri6 = cartItem._productOrigin) === null || _cartItem$_productOri6 === void 0 || (_cartItem$_productOri6 = _cartItem$_productOri6.product_resource) === null || _cartItem$_productOri6 === void 0 ? void 0 : _cartItem$_productOri6.resources) || [], selectedResources, 1);
1701
+ var allProductResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri8 = cartItem._productOrigin) === null || _cartItem$_productOri8 === void 0 || (_cartItem$_productOri8 = _cartItem$_productOri8.product_resource) === null || _cartItem$_productOri8 === void 0 ? void 0 : _cartItem$_productOri8.resources) || [], selectedResources, 1);
1700
1702
  var resources = ((_allProductResources$ = allProductResources.find(function (n) {
1701
1703
  return n.code === resources_code;
1702
1704
  })) === null || _allProductResources$ === void 0 ? void 0 : _allProductResources$.renderList) || [];
@@ -1757,14 +1759,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1757
1759
  return 0; // continue
1758
1760
  }
1759
1761
  var canUseTime = mTimes.find(function (item) {
1760
- var _cartItem$_productOri7;
1762
+ var _cartItem$_productOri9;
1761
1763
  var res = getIsUsableByTimeItem({
1762
1764
  timeSlice: timeSlots,
1763
1765
  time: item,
1764
1766
  resource: n,
1765
1767
  currentCount: totalCapacity + (capacity || 0),
1766
1768
  resourcesUseableMap: resourcesUseableMap,
1767
- cut_off_time: (_cartItem$_productOri7 = cartItem._productOrigin) === null || _cartItem$_productOri7 === void 0 ? void 0 : _cartItem$_productOri7.cut_off_time
1769
+ cut_off_time: (_cartItem$_productOri9 = cartItem._productOrigin) === null || _cartItem$_productOri9 === void 0 ? void 0 : _cartItem$_productOri9.cut_off_time
1768
1770
  });
1769
1771
  // 如果只是因为子资源容量不够,而不是子资源被预约导致没时间片,不应该标记子资源为不可用,从而影响组合资源的情况
1770
1772
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[n.id]) !== false && res.reason !== 'capacityOnly') {
@@ -2132,6 +2134,20 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2132
2134
  return ((_item$_productOrigin14 = item._productOrigin) === null || _item$_productOrigin14 === void 0 || (_item$_productOrigin14 = _item$_productOrigin14.duration) === null || _item$_productOrigin14 === void 0 ? void 0 : _item$_productOrigin14.type) === 'flexible';
2133
2135
  });
2134
2136
  var operating_day_boundary = (_this$shopStore$get = this.shopStore.get('core')) === null || _this$shopStore$get === void 0 || (_this$shopStore$get = _this$shopStore$get.core) === null || _this$shopStore$get === void 0 ? void 0 : _this$shopStore$get.operating_day_boundary;
2137
+
2138
+ // 如果有 hasFlexibleDuration,需要把动态时长商品(可能是多个,取最长的那个最低禁止购买时长)的最低禁止购买时长作为 split 的值
2139
+ var maxBlockThreshold = 0;
2140
+ if (hasFlexibleDuration) {
2141
+ maxBlockThreshold = cartItems.reduce(function (max, item) {
2142
+ var _item$_productOrigin15;
2143
+ // 如果开启了灵活时长商品配置,则取 block_threshold 的值
2144
+ if ((_item$_productOrigin15 = item._productOrigin) !== null && _item$_productOrigin15 !== void 0 && (_item$_productOrigin15 = _item$_productOrigin15.duration) !== null && _item$_productOrigin15 !== void 0 && (_item$_productOrigin15 = _item$_productOrigin15.flexible_config) !== null && _item$_productOrigin15 !== void 0 && _item$_productOrigin15.is_enable_minimum_duration) {
2145
+ var _item$_productOrigin16;
2146
+ return Math.max(max, ((_item$_productOrigin16 = item._productOrigin) === null || _item$_productOrigin16 === void 0 || (_item$_productOrigin16 = _item$_productOrigin16.duration) === null || _item$_productOrigin16 === void 0 || (_item$_productOrigin16 = _item$_productOrigin16.flexible_config) === null || _item$_productOrigin16 === void 0 ? void 0 : _item$_productOrigin16.block_threshold) || 0);
2147
+ }
2148
+ return 0;
2149
+ }, 0);
2150
+ }
2135
2151
  var timeSlots = getTimeSlicesByResources({
2136
2152
  resourceIds: resourceIds,
2137
2153
  resourcesMap: resourcesMap,
@@ -2141,7 +2157,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2141
2157
  resourcesUseableMap: resourcesUseableMap,
2142
2158
  cut_off_time: maxCutOffTime,
2143
2159
  hasFlexibleDuration: hasFlexibleDuration,
2144
- operating_day_boundary: operating_day_boundary
2160
+ operating_day_boundary: operating_day_boundary,
2161
+ maxBlockThreshold: maxBlockThreshold
2145
2162
  });
2146
2163
  return timeSlots;
2147
2164
  }
@@ -2178,12 +2195,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2178
2195
  var currentStartTime = timeSlots.start_at.format('YYYY-MM-DD HH:mm');
2179
2196
  accountItems.forEach(function (item, index) {
2180
2197
  var _newResources$;
2198
+ var osWarnTips = [];
2181
2199
  var newResources = cloneDeep(item._origin.resources);
2182
2200
  newResources.forEach(function (resource) {
2183
- var _item$_productOrigin15;
2201
+ var _item$_productOrigin17;
2184
2202
  // 如果商品配置的是灵活时长,开始时间设置为提交的时间,结束时间从资源的可用最晚时间和店铺营业结束时间里取一个最早的
2185
- if (((_item$_productOrigin15 = item._productOrigin) === null || _item$_productOrigin15 === void 0 || (_item$_productOrigin15 = _item$_productOrigin15.duration) === null || _item$_productOrigin15 === void 0 ? void 0 : _item$_productOrigin15.type) === 'flexible') {
2186
- var _allResources$find;
2203
+ if (((_item$_productOrigin17 = item._productOrigin) === null || _item$_productOrigin17 === void 0 || (_item$_productOrigin17 = _item$_productOrigin17.duration) === null || _item$_productOrigin17 === void 0 ? void 0 : _item$_productOrigin17.type) === 'flexible') {
2204
+ var _allResources$find, _item$_productOrigin18, _item$_productOrigin19;
2187
2205
  item.duration = {
2188
2206
  type: 'minutes',
2189
2207
  value: 10
@@ -2211,16 +2229,24 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2211
2229
  formattedEndTime = dayjs(endTime);
2212
2230
  }
2213
2231
  resource.endTime = formattedEndTime.format('YYYY-MM-DD HH:mm');
2232
+ // 如果是动态时长商品,并且当前选择的时间的结束时间小于了最低提示时长(warningThreshold),则追加一个提示
2233
+ // 如果currentStartTime + warningThreshold 大于 currentEndTime,且 osWarnTips 没有pisell2.product.card.closing-soon.warning 这一项,则加入这一项
2234
+ if ((_item$_productOrigin18 = item._productOrigin) !== null && _item$_productOrigin18 !== void 0 && (_item$_productOrigin18 = _item$_productOrigin18.duration) !== null && _item$_productOrigin18 !== void 0 && (_item$_productOrigin18 = _item$_productOrigin18.flexible_config) !== null && _item$_productOrigin18 !== void 0 && _item$_productOrigin18.is_enable_minimum_duration && dayjs(currentStartTime).add(((_item$_productOrigin19 = item._productOrigin) === null || _item$_productOrigin19 === void 0 || (_item$_productOrigin19 = _item$_productOrigin19.duration) === null || _item$_productOrigin19 === void 0 || (_item$_productOrigin19 = _item$_productOrigin19.flexible_config) === null || _item$_productOrigin19 === void 0 ? void 0 : _item$_productOrigin19.warning_threshold) || 0, 'minutes').isAfter(dayjs(formattedEndTime))) {
2235
+ if (!osWarnTips.includes('pisell2.product.card.closing-soon.warning')) {
2236
+ osWarnTips.push('pisell2.product.card.closing-soon.warning');
2237
+ }
2238
+ }
2214
2239
  } else {
2215
- var _item$_productOrigin16;
2240
+ var _item$_productOrigin20;
2216
2241
  resource.startTime = currentStartTime;
2217
- resource.endTime = dayjs(currentStartTime).add(((_item$_productOrigin16 = item._productOrigin) === null || _item$_productOrigin16 === void 0 || (_item$_productOrigin16 = _item$_productOrigin16.duration) === null || _item$_productOrigin16 === void 0 ? void 0 : _item$_productOrigin16.value) || 10, 'minutes').format('YYYY-MM-DD HH:mm');
2242
+ resource.endTime = dayjs(currentStartTime).add(((_item$_productOrigin20 = item._productOrigin) === null || _item$_productOrigin20 === void 0 || (_item$_productOrigin20 = _item$_productOrigin20.duration) === null || _item$_productOrigin20 === void 0 ? void 0 : _item$_productOrigin20.value) || 10, 'minutes').format('YYYY-MM-DD HH:mm');
2218
2243
  }
2219
2244
  // delete resource.times;
2220
2245
  });
2221
2246
  _this13.store.cart.updateItem({
2222
2247
  _id: item._id,
2223
- resources: newResources
2248
+ resources: newResources,
2249
+ osWarnTips: osWarnTips
2224
2250
  });
2225
2251
 
2226
2252
  // 更新下一个商品的开始时间为当前商品的结束时间
@@ -2514,7 +2540,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2514
2540
  }, {
2515
2541
  key: "getResourcesByCartItemAndCode",
2516
2542
  value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
2517
- var _cartItem$_productOri8;
2543
+ var _cartItem$_productOri10;
2518
2544
  var dateRange = this.store.date.getDateRange();
2519
2545
  var resources = [];
2520
2546
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -2546,7 +2572,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2546
2572
  } else {
2547
2573
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
2548
2574
  }
2549
- var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri8 = cartItem._productOrigin) === null || _cartItem$_productOri8 === void 0 || (_cartItem$_productOri8 = _cartItem$_productOri8.product_resource) === null || _cartItem$_productOri8 === void 0 ? void 0 : _cartItem$_productOri8.resources) || [], selectedResources, currentCapacity);
2575
+ var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri10 = cartItem._productOrigin) === null || _cartItem$_productOri10 === void 0 || (_cartItem$_productOri10 = _cartItem$_productOri10.product_resource) === null || _cartItem$_productOri10 === void 0 ? void 0 : _cartItem$_productOri10.resources) || [], selectedResources, currentCapacity);
2550
2576
  var targetResource = productResources.find(function (resource) {
2551
2577
  return resource.code === resourceCode;
2552
2578
  });
@@ -2569,7 +2595,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2569
2595
  });
2570
2596
  if (mTimes.length === 0) return false;
2571
2597
  var canUseArr = mTimes.map(function (item) {
2572
- var _cartItem$_productOri9;
2598
+ var _cartItem$_productOri11;
2573
2599
  var res = getIsUsableByTimeItem({
2574
2600
  timeSlice: {
2575
2601
  start_time: startTime.format('HH:mm'),
@@ -2581,7 +2607,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2581
2607
  resource: m,
2582
2608
  currentCount: currentCapacity || 0,
2583
2609
  resourcesUseableMap: resourcesUseableMap,
2584
- cut_off_time: (_cartItem$_productOri9 = cartItem._productOrigin) === null || _cartItem$_productOri9 === void 0 ? void 0 : _cartItem$_productOri9.cut_off_time
2610
+ cut_off_time: (_cartItem$_productOri11 = cartItem._productOrigin) === null || _cartItem$_productOri11 === void 0 ? void 0 : _cartItem$_productOri11.cut_off_time
2585
2611
  });
2586
2612
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
2587
2613
  resourcesUseableMap[m.id] = res.usable;
@@ -2595,12 +2621,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2595
2621
  });
2596
2622
  } else {
2597
2623
  targetResource.renderList = targetResource.renderList.filter(function (n) {
2598
- var _cartItem$_productOri10;
2624
+ var _cartItem$_productOri12;
2599
2625
  var recordCount = n.capacity || 0;
2600
2626
  if (n.onlyComputed) return false;
2601
2627
  var timeSlots = getTimeSlicesByResource({
2602
2628
  resource: n,
2603
- duration: ((_cartItem$_productOri10 = cartItem._productOrigin) === null || _cartItem$_productOri10 === void 0 || (_cartItem$_productOri10 = _cartItem$_productOri10.duration) === null || _cartItem$_productOri10 === void 0 ? void 0 : _cartItem$_productOri10.value) || 10,
2629
+ duration: ((_cartItem$_productOri12 = cartItem._productOrigin) === null || _cartItem$_productOri12 === void 0 || (_cartItem$_productOri12 = _cartItem$_productOri12.duration) === null || _cartItem$_productOri12 === void 0 ? void 0 : _cartItem$_productOri12.value) || 10,
2604
2630
  split: 10,
2605
2631
  currentDate: dateRange[0].date
2606
2632
  });
@@ -79,7 +79,7 @@ export declare const formatResources: ({ booking, resources, }: {
79
79
  * @return {*}
80
80
  * @Author: zhiwei.Wang
81
81
  */
82
- export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary, }: {
82
+ export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary, maxBlockThreshold }: {
83
83
  resource: ResourceItem;
84
84
  duration: number;
85
85
  split: number;
@@ -101,6 +101,7 @@ export declare const getTimeSlicesByResource: ({ resource, duration, split, curr
101
101
  type: string;
102
102
  time: string;
103
103
  } | undefined;
104
+ maxBlockThreshold?: number | undefined;
104
105
  }) => TimeSliceItem[];
105
106
  /**
106
107
  * @title: 获取时间切片列表的交集
@@ -138,7 +139,7 @@ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], re
138
139
  * @return {*}
139
140
  * @Author: zhiwei.Wang
140
141
  */
141
- export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary, }: {
142
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary, maxBlockThreshold }: {
142
143
  resourceIds: number[];
143
144
  resourcesMap: any;
144
145
  duration: number;
@@ -161,6 +162,7 @@ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, dur
161
162
  type: string;
162
163
  time: string;
163
164
  } | undefined;
165
+ maxBlockThreshold?: number | undefined;
164
166
  }) => any[];
165
167
  /**
166
168
  * @title: 获取其他人的已选资源
@@ -417,11 +417,16 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref5) {
417
417
  resourcesUseableMap = _ref5$resourcesUseabl === void 0 ? {} : _ref5$resourcesUseabl,
418
418
  cut_off_time = _ref5.cut_off_time,
419
419
  hasFlexibleDuration = _ref5.hasFlexibleDuration,
420
- operating_day_boundary = _ref5.operating_day_boundary;
420
+ operating_day_boundary = _ref5.operating_day_boundary,
421
+ maxBlockThreshold = _ref5.maxBlockThreshold;
421
422
  var times = resource.times;
422
423
 
423
424
  // 存储所有时间切片
424
425
  var timeSlices = [];
426
+ // times 先以开始时间为准做个排序,时间早的先循环
427
+ times.sort(function (a, b) {
428
+ return dayjs(a.start_at).diff(dayjs(b.start_at), 'minute');
429
+ });
425
430
 
426
431
  // 处理每个时间范围
427
432
  times.forEach(function (time) {
@@ -467,6 +472,13 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref5) {
467
472
  if (hasFlexibleDuration && operating_day_boundary && timeSlice.start_time >= (operatingBoundaryDateTime || '23:59')) {
468
473
  break;
469
474
  }
475
+ // 如果有配置了最低禁止购买时长,则需要判断时间切片是否在最低禁止购买时长内
476
+ // 看一下endTime和operatingBoundaryDateTime哪个早,哪个早用哪个去比较
477
+ var operatingBoundaryDateTimeObj = dayjs("".concat(endTime.format('YYYY-MM-DD'), " ").concat(operatingBoundaryDateTime));
478
+ var earlyTime = endTime.isBefore(operatingBoundaryDateTimeObj) ? endTime : operatingBoundaryDateTimeObj;
479
+ if (hasFlexibleDuration && operating_day_boundary && maxBlockThreshold && timeSlice.start_at.add(maxBlockThreshold || 0, 'minutes').isAfter(earlyTime)) {
480
+ break;
481
+ }
470
482
  // 添加时间切片 09:00 ~ 10:00 09:20 ~ 10:20 09:00 ~ 10:00 09:20 ~ 10:20 11:00 ~ 12:00 11:20 ~ 12:20
471
483
  timeSlices.push(_objectSpread(_objectSpread({}, timeSlice), {}, {
472
484
  // 这里需要补充这个时间段内是否可预约
@@ -574,7 +586,8 @@ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref6) {
574
586
  resourcesUseableMap = _ref6.resourcesUseableMap,
575
587
  cut_off_time = _ref6.cut_off_time,
576
588
  hasFlexibleDuration = _ref6.hasFlexibleDuration,
577
- operating_day_boundary = _ref6.operating_day_boundary;
589
+ operating_day_boundary = _ref6.operating_day_boundary,
590
+ maxBlockThreshold = _ref6.maxBlockThreshold;
578
591
  // 获取资源列表
579
592
  var resources = getResourcesByIds(resourcesMap, resourceIds);
580
593
  mergeSubResourcesTimeSlices(resources, resourcesMap);
@@ -599,7 +612,8 @@ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref6) {
599
612
  resourcesUseableMap: resourcesUseableMap,
600
613
  cut_off_time: cut_off_time,
601
614
  hasFlexibleDuration: hasFlexibleDuration,
602
- operating_day_boundary: operating_day_boundary
615
+ operating_day_boundary: operating_day_boundary,
616
+ maxBlockThreshold: maxBlockThreshold
603
617
  }));
604
618
  }, []);
605
619
 
@@ -144,7 +144,8 @@ var CartModule = class extends import_BaseModule.BaseModule {
144
144
  resources,
145
145
  note,
146
146
  date,
147
- relationForms
147
+ relationForms,
148
+ osWarnTips
148
149
  } = params;
149
150
  let quantity = params.quantity;
150
151
  let tempCartItem = this.store.list.find((i) => i._id === _id);
@@ -202,6 +203,9 @@ var CartModule = class extends import_BaseModule.BaseModule {
202
203
  if (note) {
203
204
  tempCartItem = (0, import_utils.formatNoteToCartItem)({ cartItem: tempCartItem, note });
204
205
  }
206
+ if (osWarnTips) {
207
+ tempCartItem.osWarnTips = osWarnTips;
208
+ }
205
209
  return tempCartItem;
206
210
  }
207
211
  /**
@@ -110,6 +110,8 @@ export interface CartItem {
110
110
  bundle?: any[];
111
111
  /** 商品规格信息 */
112
112
  options?: any[];
113
+ /** 商品规格选项字符串 */
114
+ product_option_string?: string;
113
115
  /** 是否为普通商品 */
114
116
  isNormalProduct?: boolean;
115
117
  /** 资源ID */
@@ -142,8 +144,8 @@ export interface CartItem {
142
144
  _bundleOrigin?: any[];
143
145
  /** 商品规格原始数据 */
144
146
  _optionsOrigin?: any[];
145
- /** 商品规格组合字符串,提供给 UI 展示的 */
146
- product_option_string?: string;
147
+ /** 操作系统提示 */
148
+ osWarnTips?: string[];
147
149
  }
148
150
  /**
149
151
  * 购物车状态接口
@@ -217,6 +219,8 @@ export interface IUpdateItemParams {
217
219
  }[];
218
220
  /** 商品组合规格ID */
219
221
  product_variant_id?: number;
222
+ /** 操作系统提示 */
223
+ osWarnTips?: string[];
220
224
  }
221
225
  /**
222
226
  * 折扣
@@ -56,6 +56,7 @@ var formatDateToCartItemOrigin = (params) => {
56
56
  return origin;
57
57
  };
58
58
  var deleteTimeFromCartItem = (cartItem) => {
59
+ var _a;
59
60
  cartItem.start_date = void 0;
60
61
  cartItem.start_time = void 0;
61
62
  cartItem.end_date = void 0;
@@ -65,6 +66,7 @@ var deleteTimeFromCartItem = (cartItem) => {
65
66
  cartItem._origin.start_time = null;
66
67
  cartItem._origin.end_date = null;
67
68
  cartItem._origin.end_time = null;
69
+ cartItem.osWarnTips = (_a = cartItem.osWarnTips) == null ? void 0 : _a.filter((item) => !item.includes("pisell2.product.card.closing-soon.warning"));
68
70
  return cartItem;
69
71
  };
70
72
  // Annotate the CommonJS export names for ESM import in node:
@@ -105,6 +105,11 @@ export interface ProductData {
105
105
  type: string;
106
106
  /** 值 */
107
107
  value: number;
108
+ flexible_config?: {
109
+ is_enable_minimum_duration?: 0 | 1;
110
+ warning_threshold?: number;
111
+ block_threshold?: number;
112
+ };
108
113
  };
109
114
  /** 商品显示设置 */
110
115
  product_display_setting: {
@@ -139,7 +139,10 @@ var getDaysByRepeatWeek = (params, isGetRange) => {
139
139
  while (startTmp.isBefore(deadline, "day") || startTmp.isSame(deadline, "day")) {
140
140
  for (let i = 0; i < frequency_date.length; i++) {
141
141
  const item = frequency_date[i];
142
- const _start = startTmp.day(item);
142
+ let _start = startTmp.day(item);
143
+ if (_start.isBefore(startTmp, "day")) {
144
+ _start = _start.add(1, "week");
145
+ }
143
146
  let _end = _start.add(scheduleDiff, "second");
144
147
  if (_end.isAfter(deadline, "day")) {
145
148
  _end = deadline;
@@ -160,7 +163,7 @@ var getDaysByRepeatWeek = (params, isGetRange) => {
160
163
  daysArr.push(...getDaysByStartEnd(_start, _end));
161
164
  }
162
165
  }
163
- startTmp = startTmp.day(1).add(frequency, "week");
166
+ startTmp = startTmp.add(frequency, "week");
164
167
  }
165
168
  return Array.from(new Set(daysArr));
166
169
  };
@@ -585,7 +588,9 @@ function getAllSortedDateRanges(schedules) {
585
588
  return durationA - durationB;
586
589
  });
587
590
  const uniqueDateRanges = sortedDateRanges.filter(
588
- (range, index, self) => index === self.findIndex((t) => (0, import_dayjs.default)(t.start).isSame((0, import_dayjs.default)(range.start)) && (0, import_dayjs.default)(t.end).isSame((0, import_dayjs.default)(range.end)))
591
+ (range, index, self) => index === self.findIndex(
592
+ (t) => (0, import_dayjs.default)(t.start).isSame((0, import_dayjs.default)(range.start)) && (0, import_dayjs.default)(t.end).isSame((0, import_dayjs.default)(range.end))
593
+ )
589
594
  );
590
595
  return uniqueDateRanges;
591
596
  }
@@ -855,7 +855,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
855
855
  const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
856
856
  const arr = [];
857
857
  cartItems.forEach((cartItem) => {
858
- var _a, _b, _c, _d, _e, _f;
858
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
859
859
  let selectedResources = [];
860
860
  const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
861
861
  cartItem._origin.metadata.capacity = formatCapacity;
@@ -925,6 +925,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
925
925
  } else {
926
926
  const hasFlexibleDuration = ((_d = (_c = cartItem._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) === "flexible";
927
927
  const operating_day_boundary = (_f = (_e = this.shopStore.get("core")) == null ? void 0 : _e.core) == null ? void 0 : _f.operating_day_boundary;
928
+ const maxBlockThreshold = ((_i = (_h = (_g = cartItem._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.flexible_config) == null ? void 0 : _i.is_enable_minimum_duration) ? ((_l = (_k = (_j = cartItem._productOrigin) == null ? void 0 : _j.duration) == null ? void 0 : _k.flexible_config) == null ? void 0 : _l.block_threshold) || 0 : 0;
928
929
  productResources.forEach((item) => {
929
930
  item.renderList = item.renderList.filter((n) => {
930
931
  var _a2, _b2, _c2;
@@ -938,7 +939,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
938
939
  currentDate: dateRange[0].date,
939
940
  hasFlexibleDuration,
940
941
  cut_off_time: (_c2 = cartItem._productOrigin) == null ? void 0 : _c2.cut_off_time,
941
- operating_day_boundary
942
+ operating_day_boundary,
943
+ maxBlockThreshold
942
944
  });
943
945
  return recordCount >= currentCapacity && timeSlots.length > 0;
944
946
  });
@@ -1469,7 +1471,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1469
1471
  return ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.type) === "flexible";
1470
1472
  }
1471
1473
  );
1472
- const operating_day_boundary = (_h = (_g = this.shopStore.get("core")) == null ? void 0 : _g.core) == null ? void 0 : _h.operating_day_boundary;
1474
+ let operating_day_boundary = (_h = (_g = this.shopStore.get("core")) == null ? void 0 : _g.core) == null ? void 0 : _h.operating_day_boundary;
1475
+ let maxBlockThreshold = 0;
1476
+ if (hasFlexibleDuration) {
1477
+ maxBlockThreshold = cartItems.reduce((max, item) => {
1478
+ var _a2, _b2, _c2, _d2, _e2, _f2;
1479
+ if ((_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.flexible_config) == null ? void 0 : _c2.is_enable_minimum_duration) {
1480
+ return Math.max(max, ((_f2 = (_e2 = (_d2 = item._productOrigin) == null ? void 0 : _d2.duration) == null ? void 0 : _e2.flexible_config) == null ? void 0 : _f2.block_threshold) || 0);
1481
+ }
1482
+ return 0;
1483
+ }, 0);
1484
+ }
1473
1485
  const timeSlots = (0, import_resources.getTimeSlicesByResources)({
1474
1486
  resourceIds,
1475
1487
  resourcesMap,
@@ -1479,7 +1491,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1479
1491
  resourcesUseableMap,
1480
1492
  cut_off_time: maxCutOffTime,
1481
1493
  hasFlexibleDuration,
1482
- operating_day_boundary
1494
+ operating_day_boundary,
1495
+ maxBlockThreshold
1483
1496
  });
1484
1497
  return timeSlots;
1485
1498
  }
@@ -1506,9 +1519,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1506
1519
  let currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1507
1520
  accountItems.forEach((item, index) => {
1508
1521
  var _a2;
1522
+ const osWarnTips = [];
1509
1523
  const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
1510
1524
  newResources.forEach((resource) => {
1511
- var _a3, _b2, _c, _d, _e;
1525
+ var _a3, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1512
1526
  if (((_b2 = (_a3 = item._productOrigin) == null ? void 0 : _a3.duration) == null ? void 0 : _b2.type) === "flexible") {
1513
1527
  item.duration = {
1514
1528
  type: "minutes",
@@ -1539,14 +1553,20 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1539
1553
  formattedEndTime = (0, import_dayjs.default)(endTime);
1540
1554
  }
1541
1555
  resource.endTime = formattedEndTime.format("YYYY-MM-DD HH:mm");
1556
+ if (((_f = (_e = (_d = item._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.flexible_config) == null ? void 0 : _f.is_enable_minimum_duration) && (0, import_dayjs.default)(currentStartTime).add(((_i = (_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.flexible_config) == null ? void 0 : _i.warning_threshold) || 0, "minutes").isAfter((0, import_dayjs.default)(formattedEndTime))) {
1557
+ if (!osWarnTips.includes("pisell2.product.card.closing-soon.warning")) {
1558
+ osWarnTips.push("pisell2.product.card.closing-soon.warning");
1559
+ }
1560
+ }
1542
1561
  } else {
1543
1562
  resource.startTime = currentStartTime;
1544
- resource.endTime = (0, import_dayjs.default)(currentStartTime).add(((_e = (_d = item._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.value) || 10, "minutes").format("YYYY-MM-DD HH:mm");
1563
+ resource.endTime = (0, import_dayjs.default)(currentStartTime).add(((_k = (_j = item._productOrigin) == null ? void 0 : _j.duration) == null ? void 0 : _k.value) || 10, "minutes").format("YYYY-MM-DD HH:mm");
1545
1564
  }
1546
1565
  });
1547
1566
  this.store.cart.updateItem({
1548
1567
  _id: item._id,
1549
- resources: newResources
1568
+ resources: newResources,
1569
+ osWarnTips
1550
1570
  });
1551
1571
  if (index < accountItems.length - 1 && ((_a2 = newResources == null ? void 0 : newResources[0]) == null ? void 0 : _a2.resourceType) === "single") {
1552
1572
  currentStartTime = newResources[0].endTime;
@@ -79,7 +79,7 @@ export declare const formatResources: ({ booking, resources, }: {
79
79
  * @return {*}
80
80
  * @Author: zhiwei.Wang
81
81
  */
82
- export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary, }: {
82
+ export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary, maxBlockThreshold }: {
83
83
  resource: ResourceItem;
84
84
  duration: number;
85
85
  split: number;
@@ -101,6 +101,7 @@ export declare const getTimeSlicesByResource: ({ resource, duration, split, curr
101
101
  type: string;
102
102
  time: string;
103
103
  } | undefined;
104
+ maxBlockThreshold?: number | undefined;
104
105
  }) => TimeSliceItem[];
105
106
  /**
106
107
  * @title: 获取时间切片列表的交集
@@ -138,7 +139,7 @@ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], re
138
139
  * @return {*}
139
140
  * @Author: zhiwei.Wang
140
141
  */
141
- export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary, }: {
142
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary, maxBlockThreshold }: {
142
143
  resourceIds: number[];
143
144
  resourcesMap: any;
144
145
  duration: number;
@@ -161,6 +162,7 @@ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, dur
161
162
  type: string;
162
163
  time: string;
163
164
  } | undefined;
165
+ maxBlockThreshold?: number | undefined;
164
166
  }) => any[];
165
167
  /**
166
168
  * @title: 获取其他人的已选资源
@@ -334,10 +334,14 @@ var getTimeSlicesByResource = ({
334
334
  resourcesUseableMap = {},
335
335
  cut_off_time,
336
336
  hasFlexibleDuration,
337
- operating_day_boundary
337
+ operating_day_boundary,
338
+ maxBlockThreshold
338
339
  }) => {
339
- const { times } = resource;
340
+ let { times } = resource;
340
341
  const timeSlices = [];
342
+ times.sort((a, b) => {
343
+ return (0, import_dayjs.default)(a.start_at).diff((0, import_dayjs.default)(b.start_at), "minute");
344
+ });
341
345
  times.forEach((time) => {
342
346
  const startTime = (0, import_dayjs.default)(`${time.start_at}`);
343
347
  const endTime = (0, import_dayjs.default)(`${time.end_at}`);
@@ -369,6 +373,11 @@ var getTimeSlicesByResource = ({
369
373
  if (hasFlexibleDuration && operating_day_boundary && timeSlice.start_time >= (operatingBoundaryDateTime || "23:59")) {
370
374
  break;
371
375
  }
376
+ const operatingBoundaryDateTimeObj = (0, import_dayjs.default)(`${endTime.format("YYYY-MM-DD")} ${operatingBoundaryDateTime}`);
377
+ const earlyTime = endTime.isBefore(operatingBoundaryDateTimeObj) ? endTime : operatingBoundaryDateTimeObj;
378
+ if (hasFlexibleDuration && operating_day_boundary && maxBlockThreshold && timeSlice.start_at.add(maxBlockThreshold || 0, "minutes").isAfter(earlyTime)) {
379
+ break;
380
+ }
372
381
  timeSlices.push({
373
382
  ...timeSlice,
374
383
  // 这里需要补充这个时间段内是否可预约
@@ -428,7 +437,8 @@ var getTimeSlicesByResources = ({
428
437
  resourcesUseableMap,
429
438
  cut_off_time,
430
439
  hasFlexibleDuration,
431
- operating_day_boundary
440
+ operating_day_boundary,
441
+ maxBlockThreshold
432
442
  }) => {
433
443
  let resources = getResourcesByIds(resourcesMap, resourceIds);
434
444
  mergeSubResourcesTimeSlices(resources, resourcesMap);
@@ -454,7 +464,8 @@ var getTimeSlicesByResources = ({
454
464
  resourcesUseableMap,
455
465
  cut_off_time,
456
466
  hasFlexibleDuration,
457
- operating_day_boundary
467
+ operating_day_boundary,
468
+ maxBlockThreshold
458
469
  })
459
470
  );
460
471
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.0.60",
4
+ "version": "2.0.61",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",