@pisell/pisellos 3.0.53 → 3.0.54

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: {
@@ -1513,25 +1513,27 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1513
1513
  });
1514
1514
  });
1515
1515
  } else {
1516
- var _cartItem$_productOri3, _this10$shopStore$get;
1516
+ var _cartItem$_productOri3, _this10$shopStore$get, _cartItem$_productOri4, _cartItem$_productOri5;
1517
1517
  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';
1518
1518
  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;
1519
+ 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;
1519
1520
  productResources.forEach(function (item) {
1520
1521
  // 如果资源的 capacity 已经小于了当前需要的 capacity ,则需要把资源给过滤掉
1521
1522
  // 同时,在这一步尝试去拉一下时间片,基于商品的时长,看每个资源是否还有空余时间能对这个商品做服务,如果没有则过滤
1522
1523
  item.renderList = item.renderList.filter(function (n) {
1523
- var _cartItem$_productOri4, _cartItem$_productOri5;
1524
+ var _cartItem$_productOri6, _cartItem$_productOri7;
1524
1525
  var recordCount = n.capacity || 0;
1525
1526
  if (n.onlyComputed) return false;
1526
1527
  // 查一下这个资源基于商品的可用时间片
1527
1528
  var timeSlots = getTimeSlicesByResource({
1528
1529
  resource: n,
1529
- 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,
1530
+ 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,
1530
1531
  split: 10,
1531
1532
  currentDate: dateRange[0].date,
1532
1533
  hasFlexibleDuration: hasFlexibleDuration,
1533
- cut_off_time: (_cartItem$_productOri5 = cartItem._productOrigin) === null || _cartItem$_productOri5 === void 0 ? void 0 : _cartItem$_productOri5.cut_off_time,
1534
- operating_day_boundary: operating_day_boundary
1534
+ cut_off_time: (_cartItem$_productOri7 = cartItem._productOrigin) === null || _cartItem$_productOri7 === void 0 ? void 0 : _cartItem$_productOri7.cut_off_time,
1535
+ operating_day_boundary: operating_day_boundary,
1536
+ maxBlockThreshold: maxBlockThreshold
1535
1537
  });
1536
1538
  return recordCount >= currentCapacity && timeSlots.length > 0;
1537
1539
  });
@@ -1632,7 +1634,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1632
1634
  }, {
1633
1635
  key: "autoSelectAccountResources",
1634
1636
  value: function autoSelectAccountResources(_ref9) {
1635
- var _cartItem$_productOri6, _allProductResources$;
1637
+ var _cartItem$_productOri8, _allProductResources$;
1636
1638
  var cartItem = _ref9.cartItem,
1637
1639
  holder_id = _ref9.holder_id,
1638
1640
  resources_code = _ref9.resources_code,
@@ -1681,7 +1683,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1681
1683
  var resourcesMap = getResourcesMap(cloneDeep(AllResources));
1682
1684
  var allCartItems = cloneDeep(this.store.cart.getItems());
1683
1685
  var selectedResources = getOthersSelectedResources(allCartItems, holder_id, resourcesMap);
1684
- 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);
1686
+ 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);
1685
1687
  var resources = ((_allProductResources$ = allProductResources.find(function (n) {
1686
1688
  return n.code === resources_code;
1687
1689
  })) === null || _allProductResources$ === void 0 ? void 0 : _allProductResources$.renderList) || [];
@@ -1742,14 +1744,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1742
1744
  return 0; // continue
1743
1745
  }
1744
1746
  var canUseTime = mTimes.find(function (item) {
1745
- var _cartItem$_productOri7;
1747
+ var _cartItem$_productOri9;
1746
1748
  var res = getIsUsableByTimeItem({
1747
1749
  timeSlice: timeSlots,
1748
1750
  time: item,
1749
1751
  resource: n,
1750
1752
  currentCount: totalCapacity + (capacity || 0),
1751
1753
  resourcesUseableMap: resourcesUseableMap,
1752
- cut_off_time: (_cartItem$_productOri7 = cartItem._productOrigin) === null || _cartItem$_productOri7 === void 0 ? void 0 : _cartItem$_productOri7.cut_off_time
1754
+ cut_off_time: (_cartItem$_productOri9 = cartItem._productOrigin) === null || _cartItem$_productOri9 === void 0 ? void 0 : _cartItem$_productOri9.cut_off_time
1753
1755
  });
1754
1756
  // 如果只是因为子资源容量不够,而不是子资源被预约导致没时间片,不应该标记子资源为不可用,从而影响组合资源的情况
1755
1757
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[n.id]) !== false && res.reason !== 'capacityOnly') {
@@ -2117,6 +2119,20 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2117
2119
  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';
2118
2120
  });
2119
2121
  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;
2122
+
2123
+ // 如果有 hasFlexibleDuration,需要把动态时长商品(可能是多个,取最长的那个最低禁止购买时长)的最低禁止购买时长作为 split 的值
2124
+ var maxBlockThreshold = 0;
2125
+ if (hasFlexibleDuration) {
2126
+ maxBlockThreshold = cartItems.reduce(function (max, item) {
2127
+ var _item$_productOrigin15;
2128
+ // 如果开启了灵活时长商品配置,则取 block_threshold 的值
2129
+ 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) {
2130
+ var _item$_productOrigin16;
2131
+ 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);
2132
+ }
2133
+ return 0;
2134
+ }, 0);
2135
+ }
2120
2136
  var timeSlots = getTimeSlicesByResources({
2121
2137
  resourceIds: resourceIds,
2122
2138
  resourcesMap: resourcesMap,
@@ -2126,7 +2142,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2126
2142
  resourcesUseableMap: resourcesUseableMap,
2127
2143
  cut_off_time: maxCutOffTime,
2128
2144
  hasFlexibleDuration: hasFlexibleDuration,
2129
- operating_day_boundary: operating_day_boundary
2145
+ operating_day_boundary: operating_day_boundary,
2146
+ maxBlockThreshold: maxBlockThreshold
2130
2147
  });
2131
2148
  return timeSlots;
2132
2149
  }
@@ -2163,12 +2180,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2163
2180
  var currentStartTime = timeSlots.start_at.format('YYYY-MM-DD HH:mm');
2164
2181
  accountItems.forEach(function (item, index) {
2165
2182
  var _newResources$;
2183
+ var osWarnTips = [];
2166
2184
  var newResources = cloneDeep(item._origin.resources);
2167
2185
  newResources.forEach(function (resource) {
2168
- var _item$_productOrigin15;
2186
+ var _item$_productOrigin17;
2169
2187
  // 如果商品配置的是灵活时长,开始时间设置为提交的时间,结束时间从资源的可用最晚时间和店铺营业结束时间里取一个最早的
2170
- 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') {
2171
- var _allResources$find;
2188
+ 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') {
2189
+ var _allResources$find, _item$_productOrigin18, _item$_productOrigin19;
2172
2190
  item.duration = {
2173
2191
  type: 'minutes',
2174
2192
  value: 10
@@ -2196,16 +2214,24 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2196
2214
  formattedEndTime = dayjs(endTime);
2197
2215
  }
2198
2216
  resource.endTime = formattedEndTime.format('YYYY-MM-DD HH:mm');
2217
+ // 如果是动态时长商品,并且当前选择的时间的结束时间小于了最低提示时长(warningThreshold),则追加一个提示
2218
+ // 如果currentStartTime + warningThreshold 大于 currentEndTime,且 osWarnTips 没有pisell2.product.card.closing-soon.warning 这一项,则加入这一项
2219
+ 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))) {
2220
+ if (!osWarnTips.includes('pisell2.product.card.closing-soon.warning')) {
2221
+ osWarnTips.push('pisell2.product.card.closing-soon.warning');
2222
+ }
2223
+ }
2199
2224
  } else {
2200
- var _item$_productOrigin16;
2225
+ var _item$_productOrigin20;
2201
2226
  resource.startTime = currentStartTime;
2202
- 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');
2227
+ 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');
2203
2228
  }
2204
2229
  // delete resource.times;
2205
2230
  });
2206
2231
  _this13.store.cart.updateItem({
2207
2232
  _id: item._id,
2208
- resources: newResources
2233
+ resources: newResources,
2234
+ osWarnTips: osWarnTips
2209
2235
  });
2210
2236
 
2211
2237
  // 更新下一个商品的开始时间为当前商品的结束时间
@@ -2499,7 +2525,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2499
2525
  }, {
2500
2526
  key: "getResourcesByCartItemAndCode",
2501
2527
  value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
2502
- var _cartItem$_productOri8;
2528
+ var _cartItem$_productOri10;
2503
2529
  var dateRange = this.store.date.getDateRange();
2504
2530
  var resources = [];
2505
2531
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -2531,7 +2557,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2531
2557
  } else {
2532
2558
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
2533
2559
  }
2534
- 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);
2560
+ 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);
2535
2561
  var targetResource = productResources.find(function (resource) {
2536
2562
  return resource.code === resourceCode;
2537
2563
  });
@@ -2554,7 +2580,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2554
2580
  });
2555
2581
  if (mTimes.length === 0) return false;
2556
2582
  var canUseArr = mTimes.map(function (item) {
2557
- var _cartItem$_productOri9;
2583
+ var _cartItem$_productOri11;
2558
2584
  var res = getIsUsableByTimeItem({
2559
2585
  timeSlice: {
2560
2586
  start_time: startTime.format('HH:mm'),
@@ -2566,7 +2592,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2566
2592
  resource: m,
2567
2593
  currentCount: currentCapacity || 0,
2568
2594
  resourcesUseableMap: resourcesUseableMap,
2569
- cut_off_time: (_cartItem$_productOri9 = cartItem._productOrigin) === null || _cartItem$_productOri9 === void 0 ? void 0 : _cartItem$_productOri9.cut_off_time
2595
+ cut_off_time: (_cartItem$_productOri11 = cartItem._productOrigin) === null || _cartItem$_productOri11 === void 0 ? void 0 : _cartItem$_productOri11.cut_off_time
2570
2596
  });
2571
2597
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
2572
2598
  resourcesUseableMap[m.id] = res.usable;
@@ -2580,12 +2606,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2580
2606
  });
2581
2607
  } else {
2582
2608
  targetResource.renderList = targetResource.renderList.filter(function (n) {
2583
- var _cartItem$_productOri10;
2609
+ var _cartItem$_productOri12;
2584
2610
  var recordCount = n.capacity || 0;
2585
2611
  if (n.onlyComputed) return false;
2586
2612
  var timeSlots = getTimeSlicesByResource({
2587
2613
  resource: n,
2588
- 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,
2614
+ 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,
2589
2615
  split: 10,
2590
2616
  currentDate: dateRange[0].date
2591
2617
  });
@@ -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: {
@@ -848,7 +848,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
848
848
  const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
849
849
  const arr = [];
850
850
  cartItems.forEach((cartItem) => {
851
- var _a, _b, _c, _d, _e, _f;
851
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
852
852
  let selectedResources = [];
853
853
  const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
854
854
  cartItem._origin.metadata.capacity = formatCapacity;
@@ -918,6 +918,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
918
918
  } else {
919
919
  const hasFlexibleDuration = ((_d = (_c = cartItem._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) === "flexible";
920
920
  const operating_day_boundary = (_f = (_e = this.shopStore.get("core")) == null ? void 0 : _e.core) == null ? void 0 : _f.operating_day_boundary;
921
+ 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;
921
922
  productResources.forEach((item) => {
922
923
  item.renderList = item.renderList.filter((n) => {
923
924
  var _a2, _b2, _c2;
@@ -931,7 +932,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
931
932
  currentDate: dateRange[0].date,
932
933
  hasFlexibleDuration,
933
934
  cut_off_time: (_c2 = cartItem._productOrigin) == null ? void 0 : _c2.cut_off_time,
934
- operating_day_boundary
935
+ operating_day_boundary,
936
+ maxBlockThreshold
935
937
  });
936
938
  return recordCount >= currentCapacity && timeSlots.length > 0;
937
939
  });
@@ -1462,7 +1464,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1462
1464
  return ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.type) === "flexible";
1463
1465
  }
1464
1466
  );
1465
- const operating_day_boundary = (_h = (_g = this.shopStore.get("core")) == null ? void 0 : _g.core) == null ? void 0 : _h.operating_day_boundary;
1467
+ let operating_day_boundary = (_h = (_g = this.shopStore.get("core")) == null ? void 0 : _g.core) == null ? void 0 : _h.operating_day_boundary;
1468
+ let maxBlockThreshold = 0;
1469
+ if (hasFlexibleDuration) {
1470
+ maxBlockThreshold = cartItems.reduce((max, item) => {
1471
+ var _a2, _b2, _c2, _d2, _e2, _f2;
1472
+ 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) {
1473
+ 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);
1474
+ }
1475
+ return 0;
1476
+ }, 0);
1477
+ }
1466
1478
  const timeSlots = (0, import_resources.getTimeSlicesByResources)({
1467
1479
  resourceIds,
1468
1480
  resourcesMap,
@@ -1472,7 +1484,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1472
1484
  resourcesUseableMap,
1473
1485
  cut_off_time: maxCutOffTime,
1474
1486
  hasFlexibleDuration,
1475
- operating_day_boundary
1487
+ operating_day_boundary,
1488
+ maxBlockThreshold
1476
1489
  });
1477
1490
  return timeSlots;
1478
1491
  }
@@ -1499,9 +1512,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1499
1512
  let currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1500
1513
  accountItems.forEach((item, index) => {
1501
1514
  var _a2;
1515
+ const osWarnTips = [];
1502
1516
  const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
1503
1517
  newResources.forEach((resource) => {
1504
- var _a3, _b2, _c, _d, _e;
1518
+ var _a3, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1505
1519
  if (((_b2 = (_a3 = item._productOrigin) == null ? void 0 : _a3.duration) == null ? void 0 : _b2.type) === "flexible") {
1506
1520
  item.duration = {
1507
1521
  type: "minutes",
@@ -1532,14 +1546,20 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1532
1546
  formattedEndTime = (0, import_dayjs.default)(endTime);
1533
1547
  }
1534
1548
  resource.endTime = formattedEndTime.format("YYYY-MM-DD HH:mm");
1549
+ 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))) {
1550
+ if (!osWarnTips.includes("pisell2.product.card.closing-soon.warning")) {
1551
+ osWarnTips.push("pisell2.product.card.closing-soon.warning");
1552
+ }
1553
+ }
1535
1554
  } else {
1536
1555
  resource.startTime = currentStartTime;
1537
- 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");
1556
+ 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");
1538
1557
  }
1539
1558
  });
1540
1559
  this.store.cart.updateItem({
1541
1560
  _id: item._id,
1542
- resources: newResources
1561
+ resources: newResources,
1562
+ osWarnTips
1543
1563
  });
1544
1564
  if (index < accountItems.length - 1 && ((_a2 = newResources == null ? void 0 : newResources[0]) == null ? void 0 : _a2.resourceType) === "single") {
1545
1565
  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": "3.0.53",
4
+ "version": "3.0.54",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",