@pisell/pisellos 0.0.72 → 0.0.74

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.
@@ -1209,7 +1209,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1209
1209
  currentCount: recordCount + (currentCapacity || 0),
1210
1210
  resourcesUseableMap: resourcesUseableMap
1211
1211
  });
1212
- if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false) {
1212
+ // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况
1213
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
1213
1214
  resourcesUseableMap[m.id] = res.usable;
1214
1215
  }
1215
1216
  return res.usable;
@@ -1389,7 +1390,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1389
1390
  currentCount: recordCount + (capacity || 0),
1390
1391
  resourcesUseableMap: resourcesUseableMap
1391
1392
  });
1392
- if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[n.id]) !== false) {
1393
+ // 如果只是因为子资源容量不够,而不是子资源被预约导致没时间片,不应该标记子资源为不可用,从而影响组合资源的情况
1394
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[n.id]) !== false && res.reason !== 'capacityOnly') {
1393
1395
  resourcesUseableMap[n.id] = res.usable;
1394
1396
  }
1395
1397
  return res.usable;
@@ -1845,7 +1847,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1845
1847
  var count = 0;
1846
1848
  // 遍历所有资源
1847
1849
  allProductResources === null || allProductResources === void 0 || allProductResources.forEach(function (m) {
1850
+ debugger;
1848
1851
  // 遍历所有资源的上工时间片
1852
+ var currentResourcesCount = 0;
1853
+ var currentResourcesTimeSlotCanUsedArr = [];
1849
1854
  m.times.forEach(function (childTiem) {
1850
1855
  // 挨个去匹配某个工作时间段结合当前日程时间,资源能不能用,有多少容量能用
1851
1856
  var res = getIsUsableByTimeItem({
@@ -1858,15 +1863,23 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1858
1863
  time: childTiem,
1859
1864
  resource: m,
1860
1865
  currentCount: 1,
1861
- resourcesUseableMap: resourcesUseableMap
1866
+ resourcesUseableMap: resourcesUseableMap,
1867
+ cut_off_time: targetProductData === null || targetProductData === void 0 ? void 0 : targetProductData.cut_off_time
1862
1868
  });
1863
- if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false) {
1869
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
1864
1870
  resourcesUseableMap[m.id] = res.usable;
1865
1871
  }
1866
- if (res.usable && res.remainingCapacity >= count) {
1867
- count = res.remainingCapacity;
1872
+ if (res.usable && res.remainingCapacity >= count && !m.onlyComputed) {
1873
+ currentResourcesCount = res.remainingCapacity;
1868
1874
  }
1875
+ currentResourcesTimeSlotCanUsedArr.push(res.usable);
1869
1876
  });
1877
+ // 在已经选定时间的情况下,只要canUseTime 里有一个 false,那就代表不可用
1878
+ if (!currentResourcesTimeSlotCanUsedArr.some(function (n) {
1879
+ return n === false;
1880
+ })) {
1881
+ count = currentResourcesCount;
1882
+ }
1870
1883
  });
1871
1884
  var startDayJs = dayjs(item.start);
1872
1885
  var endDayJs = dayjs(item.end);
@@ -27,17 +27,23 @@ interface BookingItem {
27
27
  * @return {*}
28
28
  * @Author: zhiwei.Wang
29
29
  */
30
- export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, currentCount, resourcesUseableMap, }: {
30
+ export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, currentCount, resourcesUseableMap, cut_off_time, }: {
31
31
  timeSlice: TimeSliceItem;
32
32
  time: any;
33
33
  resource: ResourceItem;
34
34
  currentCount: number;
35
35
  resourcesUseableMap: Record<string, boolean>;
36
+ cut_off_time?: {
37
+ future_day: number;
38
+ unit: number;
39
+ unit_type: string;
40
+ } | undefined;
36
41
  }) => {
37
42
  afterToDay: boolean;
38
43
  capacity: boolean;
39
44
  usable: boolean;
40
45
  remainingCapacity: number;
46
+ reason: string;
41
47
  };
42
48
  /**
43
49
  * @title: 获取商品下绑定的资源列表
@@ -113,7 +113,8 @@ var checkCapacity = function checkCapacity(_ref) {
113
113
  if (currentCount > resource.capacity) {
114
114
  return {
115
115
  status: false,
116
- capacity: resource.capacity
116
+ capacity: resource.capacity,
117
+ reason: 'capacityOnly'
117
118
  };
118
119
  }
119
120
  var conflict = (event_list || []).filter(function (d) {
@@ -174,15 +175,24 @@ export var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref2) {
174
175
  _ref2$currentCount = _ref2.currentCount,
175
176
  currentCount = _ref2$currentCount === void 0 ? 1 : _ref2$currentCount,
176
177
  _ref2$resourcesUseabl = _ref2.resourcesUseableMap,
177
- resourcesUseableMap = _ref2$resourcesUseabl === void 0 ? {} : _ref2$resourcesUseabl;
178
+ resourcesUseableMap = _ref2$resourcesUseabl === void 0 ? {} : _ref2$resourcesUseabl,
179
+ cut_off_time = _ref2.cut_off_time;
178
180
  var status = {
179
181
  afterToDay: false,
180
182
  capacity: false,
181
183
  usable: false,
182
- remainingCapacity: 0 // 剩余容量
184
+ remainingCapacity: 0,
185
+ // 剩余容量
186
+ reason: ''
183
187
  };
184
188
  // 最早可预约时间为 当前日期之后并且提前量之后
185
189
  var earliest = dayjs();
190
+ var _ref3 = cut_off_time || {},
191
+ unit = _ref3.unit,
192
+ unit_type = _ref3.unit_type;
193
+ if (unit) {
194
+ earliest = earliest.add(unit, unit_type);
195
+ }
186
196
  // 不可预约提前量时间之前的
187
197
  if (!checkAfterToDay(timeSlice.start_at, earliest)) {
188
198
  return status;
@@ -204,6 +214,7 @@ export var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref2) {
204
214
  }
205
215
  });
206
216
  }
217
+ status.reason = checkCapacityResult.reason || '';
207
218
  if (!checkCapacityResult.status) {
208
219
  return status;
209
220
  }
@@ -319,9 +330,9 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
319
330
  * @Author: zhiwei.Wang
320
331
  * @Date: 2024-01-09 13:38
321
332
  */
322
- export var formatResources = function formatResources(_ref3) {
323
- var booking = _ref3.booking,
324
- resources = _ref3.resources;
333
+ export var formatResources = function formatResources(_ref4) {
334
+ var booking = _ref4.booking,
335
+ resources = _ref4.resources;
325
336
  try {
326
337
  var _list = _toConsumableArray(resources);
327
338
  var maps = {};
@@ -367,16 +378,16 @@ export var formatResources = function formatResources(_ref3) {
367
378
  * @return {*}
368
379
  * @Author: zhiwei.Wang
369
380
  */
370
- export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref4) {
371
- var resource = _ref4.resource,
372
- duration = _ref4.duration,
373
- _ref4$split = _ref4.split,
374
- split = _ref4$split === void 0 ? 10 : _ref4$split,
375
- _ref4$currentDate = _ref4.currentDate,
376
- currentDate = _ref4$currentDate === void 0 ? dayjs() : _ref4$currentDate,
377
- capacity = _ref4.capacity,
378
- _ref4$resourcesUseabl = _ref4.resourcesUseableMap,
379
- resourcesUseableMap = _ref4$resourcesUseabl === void 0 ? {} : _ref4$resourcesUseabl;
381
+ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref5) {
382
+ var resource = _ref5.resource,
383
+ duration = _ref5.duration,
384
+ _ref5$split = _ref5.split,
385
+ split = _ref5$split === void 0 ? 10 : _ref5$split,
386
+ _ref5$currentDate = _ref5.currentDate,
387
+ currentDate = _ref5$currentDate === void 0 ? dayjs() : _ref5$currentDate,
388
+ capacity = _ref5.capacity,
389
+ _ref5$resourcesUseabl = _ref5.resourcesUseableMap,
390
+ resourcesUseableMap = _ref5$resourcesUseabl === void 0 ? {} : _ref5$resourcesUseabl;
380
391
  var times = resource.times;
381
392
 
382
393
  // 存储所有时间切片
@@ -517,14 +528,14 @@ export var mergeSubResourcesTimeSlices = function mergeSubResourcesTimeSlices(re
517
528
  * @return {*}
518
529
  * @Author: zhiwei.Wang
519
530
  */
520
- export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref5) {
521
- var resourceIds = _ref5.resourceIds,
522
- resourcesMap = _ref5.resourcesMap,
523
- duration = _ref5.duration,
524
- currentDate = _ref5.currentDate,
525
- split = _ref5.split,
526
- capacity = _ref5.capacity,
527
- resourcesUseableMap = _ref5.resourcesUseableMap;
531
+ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref6) {
532
+ var resourceIds = _ref6.resourceIds,
533
+ resourcesMap = _ref6.resourcesMap,
534
+ duration = _ref6.duration,
535
+ currentDate = _ref6.currentDate,
536
+ split = _ref6.split,
537
+ capacity = _ref6.capacity,
538
+ resourcesUseableMap = _ref6.resourcesUseableMap;
528
539
  // 获取资源列表
529
540
  var resources = getResourcesByIds(resourcesMap, resourceIds);
530
541
  mergeSubResourcesTimeSlices(resources, resourcesMap);
@@ -656,9 +667,9 @@ export var getOthersCartSelectedResources = function getOthersCartSelectedResour
656
667
  * @return {*}
657
668
  * @Author: zhiwei.Wang
658
669
  */
659
- export var formatDefaultCapacitys = function formatDefaultCapacitys(_ref6) {
660
- var capacity = _ref6.capacity,
661
- product_bundle = _ref6.product_bundle;
670
+ export var formatDefaultCapacitys = function formatDefaultCapacitys(_ref7) {
671
+ var capacity = _ref7.capacity,
672
+ product_bundle = _ref7.product_bundle;
662
673
  if ((capacity === null || capacity === void 0 ? void 0 : capacity.type) === 'package') {
663
674
  return (product_bundle || []).map(function (d) {
664
675
  var id = d.bundle_product_id;
@@ -697,8 +708,8 @@ export var formatDefaultCapacitys = function formatDefaultCapacitys(_ref6) {
697
708
  * @return {*}
698
709
  * @Author: zhiwei.Wang
699
710
  */
700
- export var getSumCapacity = function getSumCapacity(_ref7) {
701
- var capacity = _ref7.capacity;
711
+ export var getSumCapacity = function getSumCapacity(_ref8) {
712
+ var capacity = _ref8.capacity;
702
713
  var sum = 0;
703
714
  var _iterator2 = _createForOfIteratorHelper(capacity || []),
704
715
  _step2;
@@ -661,7 +661,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
661
661
  currentCount: recordCount + (currentCapacity || 0),
662
662
  resourcesUseableMap
663
663
  });
664
- if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false) {
664
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
665
665
  resourcesUseableMap[m.id] = res.usable;
666
666
  }
667
667
  return res.usable;
@@ -820,7 +820,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
820
820
  currentCount: recordCount + (capacity || 0),
821
821
  resourcesUseableMap
822
822
  });
823
- if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[n.id]) !== false) {
823
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[n.id]) !== false && res.reason !== "capacityOnly") {
824
824
  resourcesUseableMap[n.id] = res.usable;
825
825
  }
826
826
  return res.usable;
@@ -1218,6 +1218,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1218
1218
  const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1219
1219
  let count = 0;
1220
1220
  allProductResources == null ? void 0 : allProductResources.forEach((m) => {
1221
+ debugger;
1222
+ let currentResourcesCount = 0;
1223
+ const currentResourcesTimeSlotCanUsedArr = [];
1221
1224
  m.times.forEach((childTiem) => {
1222
1225
  const res = (0, import_resources.getIsUsableByTimeItem)({
1223
1226
  timeSlice: {
@@ -1229,15 +1232,20 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1229
1232
  time: childTiem,
1230
1233
  resource: m,
1231
1234
  currentCount: 1,
1232
- resourcesUseableMap
1235
+ resourcesUseableMap,
1236
+ cut_off_time: targetProductData == null ? void 0 : targetProductData.cut_off_time
1233
1237
  });
1234
- if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false) {
1238
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
1235
1239
  resourcesUseableMap[m.id] = res.usable;
1236
1240
  }
1237
- if (res.usable && res.remainingCapacity >= count) {
1238
- count = res.remainingCapacity;
1241
+ if (res.usable && res.remainingCapacity >= count && !m.onlyComputed) {
1242
+ currentResourcesCount = res.remainingCapacity;
1239
1243
  }
1244
+ currentResourcesTimeSlotCanUsedArr.push(res.usable);
1240
1245
  });
1246
+ if (!currentResourcesTimeSlotCanUsedArr.some((n) => n === false)) {
1247
+ count = currentResourcesCount;
1248
+ }
1241
1249
  });
1242
1250
  const startDayJs = (0, import_dayjs.default)(item.start);
1243
1251
  const endDayJs = (0, import_dayjs.default)(item.end);
@@ -27,17 +27,23 @@ interface BookingItem {
27
27
  * @return {*}
28
28
  * @Author: zhiwei.Wang
29
29
  */
30
- export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, currentCount, resourcesUseableMap, }: {
30
+ export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, currentCount, resourcesUseableMap, cut_off_time, }: {
31
31
  timeSlice: TimeSliceItem;
32
32
  time: any;
33
33
  resource: ResourceItem;
34
34
  currentCount: number;
35
35
  resourcesUseableMap: Record<string, boolean>;
36
+ cut_off_time?: {
37
+ future_day: number;
38
+ unit: number;
39
+ unit_type: string;
40
+ } | undefined;
36
41
  }) => {
37
42
  afterToDay: boolean;
38
43
  capacity: boolean;
39
44
  usable: boolean;
40
45
  remainingCapacity: number;
46
+ reason: string;
41
47
  };
42
48
  /**
43
49
  * @title: 获取商品下绑定的资源列表
@@ -85,7 +85,8 @@ var checkCapacity = ({
85
85
  if (currentCount > resource.capacity) {
86
86
  return {
87
87
  status: false,
88
- capacity: resource.capacity
88
+ capacity: resource.capacity,
89
+ reason: "capacityOnly"
89
90
  };
90
91
  }
91
92
  let conflict = (event_list || []).filter((d) => {
@@ -126,17 +127,23 @@ var getIsUsableByTimeItem = ({
126
127
  time,
127
128
  resource,
128
129
  currentCount = 1,
129
- resourcesUseableMap = {}
130
+ resourcesUseableMap = {},
131
+ cut_off_time
130
132
  }) => {
131
133
  var _a;
132
134
  let status = {
133
135
  afterToDay: false,
134
136
  capacity: false,
135
137
  usable: false,
136
- remainingCapacity: 0
138
+ remainingCapacity: 0,
137
139
  // 剩余容量
140
+ reason: ""
138
141
  };
139
142
  let earliest = (0, import_dayjs.default)();
143
+ const { unit, unit_type } = cut_off_time || {};
144
+ if (unit) {
145
+ earliest = earliest.add(unit, unit_type);
146
+ }
140
147
  if (!checkAfterToDay(timeSlice.start_at, earliest)) {
141
148
  return status;
142
149
  }
@@ -155,6 +162,7 @@ var getIsUsableByTimeItem = ({
155
162
  }
156
163
  });
157
164
  }
165
+ status.reason = checkCapacityResult.reason || "";
158
166
  if (!checkCapacityResult.status) {
159
167
  return status;
160
168
  }
@@ -370,7 +378,9 @@ var mergeSubResourcesTimeSlices = (resources, resourcesMap) => {
370
378
  const subResource = resourcesMap[id];
371
379
  if (subResource) {
372
380
  subResource.times.forEach((time) => {
373
- const fatherResourcesTime = item.times.find((n) => n.start_at === time.start_at && n.end_at === time.end_at);
381
+ const fatherResourcesTime = item.times.find(
382
+ (n) => n.start_at === time.start_at && n.end_at === time.end_at
383
+ );
374
384
  if (fatherResourcesTime) {
375
385
  fatherResourcesTime.event_list.push(...time.event_list || []);
376
386
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.72",
4
+ "version": "0.0.74",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",