@pisell/pisellos 2.1.20 → 2.1.22

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.
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  };
327
327
  setOtherData(key: string, value: any): void;
328
328
  getOtherData(key: string): any;
329
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
329
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
330
330
  /**
331
331
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
332
332
  *
@@ -31,7 +31,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
31
31
  import { BaseModule } from "../../modules/BaseModule";
32
32
  import { BookingByStepHooks, createModule } from "./types";
33
33
  import { getAvailableProductResources } from "./utils/products";
34
- import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection } from "./utils/resources";
34
+ import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection, isConflict } from "./utils/resources";
35
35
  import dayjs from 'dayjs';
36
36
  import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
37
37
  import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
@@ -2058,7 +2058,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2058
2058
  // item._origin.resources?.forEach((n: any) => {
2059
2059
  // resourceIds.push(n.relation_id);
2060
2060
  // });
2061
- if (item.resource_id) {
2061
+ if (item.resource_id && !resourceIds.includes(item.resource_id)) {
2062
2062
  resourceIds.push(item.resource_id);
2063
2063
  }
2064
2064
  resourcesTypeId = item === null || item === void 0 || (_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.product_resource) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.resources) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.find(function (n) {
@@ -2153,6 +2153,26 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2153
2153
  return 0;
2154
2154
  }, 0);
2155
2155
  }
2156
+ // 计算容量的辅助函数
2157
+ var calculateCapacityFromCartItems = function calculateCapacityFromCartItems(items) {
2158
+ return items.reduce(function (total, item) {
2159
+ return total + (getCapacityInfoByCartItem(item).currentCapacity || 0);
2160
+ }, 0);
2161
+ };
2162
+
2163
+ // 如果是多个预约,去要求助几个 holder 下最大的需求容量capacity
2164
+ var maxCapacity = 1;
2165
+ if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
2166
+ accountList.forEach(function (account) {
2167
+ var accountCartItems = _this12.store.cart.getCartByAccount(account.getId());
2168
+ var currentCapacity = calculateCapacityFromCartItems(accountCartItems);
2169
+ if (currentCapacity > maxCapacity) {
2170
+ maxCapacity = currentCapacity;
2171
+ }
2172
+ });
2173
+ } else {
2174
+ maxCapacity = calculateCapacityFromCartItems(cartItems);
2175
+ }
2156
2176
  var timeSlots = getTimeSlicesByResources({
2157
2177
  resourceIds: resourceIds,
2158
2178
  resourcesMap: resourcesMap,
@@ -2160,6 +2180,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2160
2180
  currentDate: dateRange[0].date,
2161
2181
  split: 10,
2162
2182
  resourcesUseableMap: resourcesUseableMap,
2183
+ capacity: maxCapacity,
2163
2184
  cut_off_time: maxCutOffTime,
2164
2185
  hasFlexibleDuration: hasFlexibleDuration,
2165
2186
  operating_day_boundary: operating_day_boundary,
@@ -2577,12 +2598,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2577
2598
  });
2578
2599
  // 这里为什么要设置个 map,因为有可能日程有重叠,所以要把重叠的 event_list 去除
2579
2600
  var mSet = new Map();
2580
- mTimes.forEach(function (n) {
2581
- // acc += n.event_list?.reduce((acc: any, curr: any) => acc + curr.pax, 0);
2582
- // mSet.set(n)
2583
- n.event_list.forEach(function (m) {
2601
+ n.event_list.forEach(function (m) {
2602
+ // 需要确认 m 的时间段是否和 item 的时间段有交集
2603
+ if (isConflict({
2604
+ start_at: m.start_at,
2605
+ end_at: m.end_at
2606
+ }, {
2607
+ start_at: dayjs(item.start),
2608
+ end_at: dayjs(item.end)
2609
+ })) {
2584
2610
  mSet.set(m.id, m.pax || 1);
2585
- });
2611
+ }
2586
2612
  });
2587
2613
  acc += Array.from(mSet.values()).reduce(function (acc, curr) {
2588
2614
  return acc + curr;
@@ -20,6 +20,21 @@ export interface ResourceItem {
20
20
  interface BookingItem {
21
21
  [key: string]: any;
22
22
  }
23
+ /**
24
+ * @title: 判断两个时间段是否有重叠
25
+ * @description:
26
+ * @param {object} event
27
+ * @param {object} current
28
+ * @return {*}
29
+ * @Author: zhiwei.Wang
30
+ */
31
+ export declare const isConflict: (event: {
32
+ start_at: DateType;
33
+ end_at: DateType;
34
+ }, current: {
35
+ start_at: DateType;
36
+ end_at?: DateType;
37
+ }) => boolean;
23
38
  /**
24
39
  * @title: 获取时间切片是否可用
25
40
  * @description: 根据时间切片、资源、当前预约量判断时间切片是否可用
@@ -42,7 +42,7 @@ var getUseableEventCount = function getUseableEventCount(eventList, current) {
42
42
  * @return {*}
43
43
  * @Author: zhiwei.Wang
44
44
  */
45
- var isConflict = function isConflict(event, current) {
45
+ export var isConflict = function isConflict(event, current) {
46
46
  var eventStart = dayjs(event.start_at);
47
47
  var eventEnd = dayjs(event.end_at);
48
48
  var currentStart = dayjs(current.start_at);
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  };
327
327
  setOtherData(key: string, value: any): void;
328
328
  getOtherData(key: string): any;
329
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
329
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
330
330
  /**
331
331
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
332
332
  *
@@ -1399,7 +1399,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1399
1399
  isSingleResource = n.type === "single";
1400
1400
  }
1401
1401
  });
1402
- if (item.resource_id) {
1402
+ if (item.resource_id && !resourceIds.includes(item.resource_id)) {
1403
1403
  resourceIds.push(item.resource_id);
1404
1404
  }
1405
1405
  resourcesTypeId = (_g2 = (_f2 = (_e2 = (_d2 = item == null ? void 0 : item._productOrigin) == null ? void 0 : _d2.product_resource) == null ? void 0 : _e2.resources) == null ? void 0 : _f2.find(
@@ -1487,6 +1487,23 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1487
1487
  return 0;
1488
1488
  }, 0);
1489
1489
  }
1490
+ const calculateCapacityFromCartItems = (items) => {
1491
+ return items.reduce((total, item) => {
1492
+ return total + ((0, import_capacity.getCapacityInfoByCartItem)(item).currentCapacity || 0);
1493
+ }, 0);
1494
+ };
1495
+ let maxCapacity = 1;
1496
+ if (cartItems == null ? void 0 : cartItems[0].holder_id) {
1497
+ accountList.forEach((account) => {
1498
+ const accountCartItems = this.store.cart.getCartByAccount(account.getId());
1499
+ const currentCapacity = calculateCapacityFromCartItems(accountCartItems);
1500
+ if (currentCapacity > maxCapacity) {
1501
+ maxCapacity = currentCapacity;
1502
+ }
1503
+ });
1504
+ } else {
1505
+ maxCapacity = calculateCapacityFromCartItems(cartItems);
1506
+ }
1490
1507
  const timeSlots = (0, import_resources.getTimeSlicesByResources)({
1491
1508
  resourceIds,
1492
1509
  resourcesMap,
@@ -1494,6 +1511,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1494
1511
  currentDate: dateRange[0].date,
1495
1512
  split: 10,
1496
1513
  resourcesUseableMap,
1514
+ capacity: maxCapacity,
1497
1515
  cut_off_time: maxCutOffTime,
1498
1516
  hasFlexibleDuration,
1499
1517
  operating_day_boundary,
@@ -1808,10 +1826,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1808
1826
  return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(item.end), "minute") || (0, import_dayjs.default)(n2.start_at).isBefore((0, import_dayjs.default)(item.end), "minute") && (0, import_dayjs.default)(n2.end_at).isAfter((0, import_dayjs.default)(item.start), "minute");
1809
1827
  });
1810
1828
  const mSet = /* @__PURE__ */ new Map();
1811
- mTimes.forEach((n2) => {
1812
- n2.event_list.forEach((m) => {
1829
+ n.event_list.forEach((m) => {
1830
+ if ((0, import_resources.isConflict)(
1831
+ { start_at: m.start_at, end_at: m.end_at },
1832
+ { start_at: (0, import_dayjs.default)(item.start), end_at: (0, import_dayjs.default)(item.end) }
1833
+ )) {
1813
1834
  mSet.set(m.id, m.pax || 1);
1814
- });
1835
+ }
1815
1836
  });
1816
1837
  acc += Array.from(mSet.values()).reduce((acc2, curr2) => acc2 + curr2, 0);
1817
1838
  return acc;
@@ -20,6 +20,21 @@ export interface ResourceItem {
20
20
  interface BookingItem {
21
21
  [key: string]: any;
22
22
  }
23
+ /**
24
+ * @title: 判断两个时间段是否有重叠
25
+ * @description:
26
+ * @param {object} event
27
+ * @param {object} current
28
+ * @return {*}
29
+ * @Author: zhiwei.Wang
30
+ */
31
+ export declare const isConflict: (event: {
32
+ start_at: DateType;
33
+ end_at: DateType;
34
+ }, current: {
35
+ start_at: DateType;
36
+ end_at?: DateType;
37
+ }) => boolean;
23
38
  /**
24
39
  * @title: 获取时间切片是否可用
25
40
  * @description: 根据时间切片、资源、当前预约量判断时间切片是否可用
@@ -43,6 +43,7 @@ __export(resources_exports, {
43
43
  getTimeSlicesByResource: () => getTimeSlicesByResource,
44
44
  getTimeSlicesByResources: () => getTimeSlicesByResources,
45
45
  getTimesIntersection: () => getTimesIntersection,
46
+ isConflict: () => isConflict,
46
47
  mergeSubResourcesTimeSlices: () => mergeSubResourcesTimeSlices,
47
48
  sortCombinedResources: () => sortCombinedResources
48
49
  });
@@ -636,6 +637,7 @@ function checkTwoResourcesIntersection(resource1, resource2) {
636
637
  getTimeSlicesByResource,
637
638
  getTimeSlicesByResources,
638
639
  getTimesIntersection,
640
+ isConflict,
639
641
  mergeSubResourcesTimeSlices,
640
642
  sortCombinedResources
641
643
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.20",
4
+ "version": "2.1.22",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",