@pisell/pisellos 3.0.9 → 3.0.11

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.
@@ -38,11 +38,12 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
38
38
  * 删除step
39
39
  */
40
40
  removeStep(key: string): void;
41
- loadProducts({ category_ids, product_ids, collection, schedule_ids, }: {
41
+ loadProducts({ category_ids, product_ids, collection, schedule_ids, schedule_date, }: {
42
42
  category_ids?: number[];
43
43
  product_ids?: number[];
44
44
  collection?: number | string[];
45
45
  schedule_ids?: number[];
46
+ schedule_date?: string;
46
47
  }): Promise<any>;
47
48
  loadProductByScheduleDate({ date, product_ids, category_ids, }: {
48
49
  date: string;
@@ -50,10 +51,11 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
50
51
  category_ids?: number[];
51
52
  }): Promise<any>;
52
53
  loadAllSchedule(): Promise<void>;
53
- loadScheduleAvailableDate({ startDate, endDate, custom_page_id, }: {
54
+ loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel }: {
54
55
  startDate: string;
55
56
  endDate: string;
56
57
  custom_page_id?: number;
58
+ channel?: string;
57
59
  }): Promise<ITime[]>;
58
60
  storeProduct(productData: ProductData): Promise<void>;
59
61
  addAccount(account: Account | IHolder, extra?: {
@@ -193,11 +193,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
193
193
  value: function () {
194
194
  var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
195
195
  var _schedule_ids;
196
- var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, _ref$schedule_ids, schedule_ids, schedule_ids_data, productsData;
196
+ var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, _ref$schedule_ids, schedule_ids, schedule_date, schedule_ids_data, productsData;
197
197
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
198
198
  while (1) switch (_context2.prev = _context2.next) {
199
199
  case 0:
200
- _ref$category_ids = _ref.category_ids, category_ids = _ref$category_ids === void 0 ? [] : _ref$category_ids, _ref$product_ids = _ref.product_ids, product_ids = _ref$product_ids === void 0 ? [] : _ref$product_ids, _ref$collection = _ref.collection, collection = _ref$collection === void 0 ? [] : _ref$collection, _ref$schedule_ids = _ref.schedule_ids, schedule_ids = _ref$schedule_ids === void 0 ? [] : _ref$schedule_ids;
200
+ _ref$category_ids = _ref.category_ids, category_ids = _ref$category_ids === void 0 ? [] : _ref$category_ids, _ref$product_ids = _ref.product_ids, product_ids = _ref$product_ids === void 0 ? [] : _ref$product_ids, _ref$collection = _ref.collection, collection = _ref$collection === void 0 ? [] : _ref$collection, _ref$schedule_ids = _ref.schedule_ids, schedule_ids = _ref$schedule_ids === void 0 ? [] : _ref$schedule_ids, schedule_date = _ref.schedule_date;
201
201
  // 如果 schedule_ids 为空,则需要尝试从 schedule 模块里获取
202
202
  if (!((_schedule_ids = schedule_ids) !== null && _schedule_ids !== void 0 && _schedule_ids.length)) {
203
203
  schedule_ids_data = this.store.schedule.getScheduleListByIds(schedule_ids).map(function (n) {
@@ -220,7 +220,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
220
220
  ids: product_ids,
221
221
  collection: collection,
222
222
  front_end_cache_id: this.cacheId,
223
- client_schedule_ids: schedule_ids
223
+ client_schedule_ids: schedule_ids,
224
+ schedule_date: schedule_date
224
225
  }, {
225
226
  useCache: true
226
227
  });
@@ -269,7 +270,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
269
270
  return this.loadProducts({
270
271
  schedule_ids: scheduleIds,
271
272
  product_ids: product_ids,
272
- category_ids: category_ids
273
+ category_ids: category_ids,
274
+ schedule_date: date
273
275
  });
274
276
  case 6:
275
277
  return _context3.abrupt("return", _context3.sent);
@@ -314,11 +316,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
314
316
  value: function () {
315
317
  var _loadScheduleAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref3) {
316
318
  var _res$data$date_list;
317
- var startDate, endDate, custom_page_id, dates, res;
319
+ var startDate, endDate, custom_page_id, channel, dates, res;
318
320
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
319
321
  while (1) switch (_context5.prev = _context5.next) {
320
322
  case 0:
321
- startDate = _ref3.startDate, endDate = _ref3.endDate, custom_page_id = _ref3.custom_page_id;
323
+ startDate = _ref3.startDate, endDate = _ref3.endDate, custom_page_id = _ref3.custom_page_id, channel = _ref3.channel;
322
324
  // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天,需要把 startDate 置为今天
323
325
  if (dayjs(startDate).isBefore(dayjs(), 'day')) {
324
326
  startDate = dayjs().format('YYYY-MM-DD');
@@ -337,7 +339,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
337
339
  return this.request.get("/schedule/product/availability", {
338
340
  start_date: startDate,
339
341
  end_date: endDate,
340
- custom_page_id: custom_page_id
342
+ custom_page_id: custom_page_id,
343
+ channel: channel
341
344
  });
342
345
  case 8:
343
346
  res = _context5.sent;
@@ -350,13 +353,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
350
353
  return _context5.abrupt("return", dates);
351
354
  case 12:
352
355
  res.data.date_list.forEach(function (n) {
353
- if (n.schedule_id && n.schedule_id.length) {
354
- var index = dates.findIndex(function (m) {
355
- return m.date === n.date;
356
- });
357
- if (index !== -1) {
358
- dates[index].status = 'available';
359
- }
356
+ var index = dates.findIndex(function (m) {
357
+ return m.date === n.date;
358
+ });
359
+ if (index !== -1) {
360
+ dates[index].status = 'available';
360
361
  }
361
362
  });
362
363
  dates = disableDatesBeforeOneDay(dates);
@@ -1195,7 +1196,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1195
1196
  });
1196
1197
  n.renderList = n.renderList.filter(function (m) {
1197
1198
  var recordCount = capacityMap[m.id] || 0;
1198
- var canUseTime = m.times.find(function (item) {
1199
+ var canUseArr = m.times.map(function (item) {
1199
1200
  var res = getIsUsableByTimeItem({
1200
1201
  timeSlice: {
1201
1202
  start_time: startTime.format('HH:mm'),
@@ -1208,12 +1209,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1208
1209
  currentCount: recordCount + (currentCapacity || 0),
1209
1210
  resourcesUseableMap: resourcesUseableMap
1210
1211
  });
1211
- 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') {
1212
1214
  resourcesUseableMap[m.id] = res.usable;
1213
1215
  }
1214
1216
  return res.usable;
1215
1217
  });
1216
- return canUseTime;
1218
+ if (m.onlyComputed) return false;
1219
+ // 在已经选定时间的情况下,只要canUseTime 里有一个 false,那就代表不可用
1220
+ return !canUseArr.some(function (n) {
1221
+ return n === false;
1222
+ });
1217
1223
  });
1218
1224
  });
1219
1225
  } else {
@@ -1221,6 +1227,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1221
1227
  // 如果资源的 capacity 已经小于了当前需要的 capacity ,则需要把资源给过滤掉
1222
1228
  item.renderList = item.renderList.filter(function (n) {
1223
1229
  var recordCount = n.capacity || 0;
1230
+ if (n.onlyComputed) return false;
1224
1231
  return recordCount >= currentCapacity;
1225
1232
  });
1226
1233
  });
@@ -1273,6 +1280,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1273
1280
  capacity: formatCapacity
1274
1281
  });
1275
1282
  var productResources = getResourcesByProduct(resourcesMap, ((_targetCartItem$_prod3 = targetCartItem._productOrigin) === null || _targetCartItem$_prod3 === void 0 || (_targetCartItem$_prod3 = _targetCartItem$_prod3.product_resource) === null || _targetCartItem$_prod3 === void 0 ? void 0 : _targetCartItem$_prod3.resources) || [], selectedResources, currentCapacity);
1283
+ productResources.forEach(function (item) {
1284
+ item.renderList = item.renderList.filter(function (n) {
1285
+ var recordCount = n.capacity || 0;
1286
+ if (n.onlyComputed) return false;
1287
+ return recordCount >= currentCapacity;
1288
+ });
1289
+ });
1276
1290
  if (productResources) {
1277
1291
  return {
1278
1292
  id: targetCartItem.id,
@@ -1376,7 +1390,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1376
1390
  currentCount: recordCount + (capacity || 0),
1377
1391
  resourcesUseableMap: resourcesUseableMap
1378
1392
  });
1379
- 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') {
1380
1395
  resourcesUseableMap[n.id] = res.usable;
1381
1396
  }
1382
1397
  return res.usable;
@@ -1533,6 +1548,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1533
1548
  selectedResources = getOthersCartSelectedResources(allCartItems, item._id, _resourcesMap);
1534
1549
  }
1535
1550
  var productResources = getResourcesByProduct(_resourcesMap, cloneDeep(_resources), selectedResources, currentCapacity);
1551
+ productResources.forEach(function (item) {
1552
+ item.renderList = item.renderList.filter(function (n) {
1553
+ var recordCount = n.capacity || 0;
1554
+ if (n.onlyComputed) return false;
1555
+ return recordCount >= currentCapacity;
1556
+ });
1557
+ });
1536
1558
  // 自动选择 productResources 中对应 resources_code 的资源
1537
1559
  var targetRenderList = (_productResources$fin = productResources.find(function (n) {
1538
1560
  return n.code === resources_code;
@@ -1613,7 +1635,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1613
1635
  if ((_dateRange = dateRange) !== null && _dateRange !== void 0 && (_dateRange = _dateRange[0]) !== null && _dateRange !== void 0 && (_dateRange = _dateRange.resource) !== null && _dateRange !== void 0 && _dateRange.length) {
1614
1636
  // resources.push(...dateRange[0].resource);
1615
1637
  dateRange[0].resource.forEach(function (n) {
1616
- if (n.form_id === resourcesTypeId) {
1638
+ if (n.form_id === resourcesTypeId && !resources.find(function (m) {
1639
+ return m.id === n.id;
1640
+ })) {
1617
1641
  resources.push(n);
1618
1642
  }
1619
1643
  });
@@ -1838,10 +1862,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1838
1862
  currentCount: 1,
1839
1863
  resourcesUseableMap: resourcesUseableMap
1840
1864
  });
1841
- if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false) {
1865
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
1842
1866
  resourcesUseableMap[m.id] = res.usable;
1843
1867
  }
1844
- // 如果资源可用,且是独占资源,remainingCapacity 始终为 1
1845
1868
  if (res.usable && res.remainingCapacity >= count) {
1846
1869
  count = res.remainingCapacity;
1847
1870
  }
@@ -38,6 +38,7 @@ export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, curren
38
38
  capacity: boolean;
39
39
  usable: boolean;
40
40
  remainingCapacity: number;
41
+ reason: string;
41
42
  };
42
43
  /**
43
44
  * @title: 获取商品下绑定的资源列表
@@ -95,6 +96,15 @@ export declare const getTimesIntersection: (times: TimeSliceItem[], count: numbe
95
96
  * @Date: 2024-09-19 20:23
96
97
  */
97
98
  export declare const getResourcesByIds: (resourcesMap: Record<string, ResourceItem>, ids: number[]) => ResourceItem[];
99
+ /**
100
+ * @title: 合并子资源的时间切片至组合资源
101
+ * @description:
102
+ * @param {ResourceItem[]} resources
103
+ * @param {Record<string, ResourceItem>} resourcesMap
104
+ * @return {*}
105
+ * @Author: zhiwei.Wang
106
+ */
107
+ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], resourcesMap: Record<string, ResourceItem>) => void;
98
108
  /**
99
109
  * @title: 根据资源id列表获取时间切片
100
110
  * @description: 传入一个技师id列表, 找出技师列表中公共的时间切片
@@ -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) {
@@ -179,7 +180,9 @@ export var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref2) {
179
180
  afterToDay: false,
180
181
  capacity: false,
181
182
  usable: false,
182
- remainingCapacity: 0 // 剩余容量
183
+ remainingCapacity: 0,
184
+ // 剩余容量
185
+ reason: ''
183
186
  };
184
187
  // 最早可预约时间为 当前日期之后并且提前量之后
185
188
  var earliest = dayjs();
@@ -204,6 +207,7 @@ export var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref2) {
204
207
  }
205
208
  });
206
209
  }
210
+ status.reason = checkCapacityResult.reason || '';
207
211
  if (!checkCapacityResult.status) {
208
212
  return status;
209
213
  }
@@ -238,6 +242,16 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
238
242
  resourcesMap[d].combined_resource.resource_ids.forEach(function (id) {
239
243
  if (resourcesMap[id]) {
240
244
  combiningResources.push(resourcesMap[id]);
245
+ childAcc.push(Object.assign({}, resourcesMap[id], {
246
+ form_id: form_id,
247
+ resourceType: item.type,
248
+ children: combiningResources,
249
+ onlyComputed: true,
250
+ // 是否是只用来计算用,组合资源里,假设商品只关联了组合资源没关联子资源,需要通过这个计算来在后面从 renderList 里删除这个资源
251
+ metadata: _objectSpread(_objectSpread({}, resourcesMap[id].metadata), {}, {
252
+ combined_resource: resourcesMap[id].combined_resource
253
+ })
254
+ }));
241
255
  }
242
256
  });
243
257
  }
@@ -260,6 +274,16 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
260
274
  resourcesMap[d].combined_resource.resource_ids.forEach(function (id) {
261
275
  if (resourcesMap[id]) {
262
276
  combiningResources.push(resourcesMap[id]);
277
+ childAcc.push(Object.assign({}, resourcesMap[id], {
278
+ form_id: form_id,
279
+ resourceType: item.type,
280
+ children: combiningResources,
281
+ onlyComputed: true,
282
+ // 是否是只用来计算用,组合资源里,假设商品只关联了组合资源没关联子资源,需要通过这个计算来在后面从 renderList 里删除这个资源
283
+ metadata: _objectSpread(_objectSpread({}, resourcesMap[id].metadata), {}, {
284
+ combined_resource: resourcesMap[id].combined_resource
285
+ })
286
+ }));
263
287
  }
264
288
  });
265
289
  }
@@ -458,6 +482,37 @@ export var getResourcesByIds = function getResourcesByIds(resourcesMap, ids) {
458
482
  });
459
483
  };
460
484
 
485
+ /**
486
+ * @title: 合并子资源的时间切片至组合资源
487
+ * @description:
488
+ * @param {ResourceItem[]} resources
489
+ * @param {Record<string, ResourceItem>} resourcesMap
490
+ * @return {*}
491
+ * @Author: zhiwei.Wang
492
+ */
493
+ export var mergeSubResourcesTimeSlices = function mergeSubResourcesTimeSlices(resources, resourcesMap) {
494
+ return resources.forEach(function (item) {
495
+ var _item$combined_resour;
496
+ if ((item === null || item === void 0 || (_item$combined_resour = item.combined_resource) === null || _item$combined_resour === void 0 ? void 0 : _item$combined_resour.status) === 1) {
497
+ var _item$combined_resour2;
498
+ item === null || item === void 0 || (_item$combined_resour2 = item.combined_resource) === null || _item$combined_resour2 === void 0 || _item$combined_resour2.resource_ids.forEach(function (id) {
499
+ var subResource = resourcesMap[id];
500
+ if (subResource) {
501
+ subResource.times.forEach(function (time) {
502
+ var fatherResourcesTime = item.times.find(function (n) {
503
+ return n.start_at === time.start_at && n.end_at === time.end_at;
504
+ });
505
+ if (fatherResourcesTime) {
506
+ var _fatherResourcesTime$;
507
+ (_fatherResourcesTime$ = fatherResourcesTime.event_list).push.apply(_fatherResourcesTime$, _toConsumableArray(time.event_list || []));
508
+ }
509
+ });
510
+ }
511
+ });
512
+ }
513
+ });
514
+ };
515
+
461
516
  /**
462
517
  * @title: 根据资源id列表获取时间切片
463
518
  * @description: 传入一个技师id列表, 找出技师列表中公共的时间切片
@@ -476,6 +531,7 @@ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref5) {
476
531
  resourcesUseableMap = _ref5.resourcesUseableMap;
477
532
  // 获取资源列表
478
533
  var resources = getResourcesByIds(resourcesMap, resourceIds);
534
+ mergeSubResourcesTimeSlices(resources, resourcesMap);
479
535
  // 资源排下序,把单个资源靠前,组合资源排在后面
480
536
  resources.sort(function (a, b) {
481
537
  var _a$metadata, _b$metadata;
@@ -38,11 +38,12 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
38
38
  * 删除step
39
39
  */
40
40
  removeStep(key: string): void;
41
- loadProducts({ category_ids, product_ids, collection, schedule_ids, }: {
41
+ loadProducts({ category_ids, product_ids, collection, schedule_ids, schedule_date, }: {
42
42
  category_ids?: number[];
43
43
  product_ids?: number[];
44
44
  collection?: number | string[];
45
45
  schedule_ids?: number[];
46
+ schedule_date?: string;
46
47
  }): Promise<any>;
47
48
  loadProductByScheduleDate({ date, product_ids, category_ids, }: {
48
49
  date: string;
@@ -50,10 +51,11 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
50
51
  category_ids?: number[];
51
52
  }): Promise<any>;
52
53
  loadAllSchedule(): Promise<void>;
53
- loadScheduleAvailableDate({ startDate, endDate, custom_page_id, }: {
54
+ loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel }: {
54
55
  startDate: string;
55
56
  endDate: string;
56
57
  custom_page_id?: number;
58
+ channel?: string;
57
59
  }): Promise<ITime[]>;
58
60
  storeProduct(productData: ProductData): Promise<void>;
59
61
  addAccount(account: Account | IHolder, extra?: {
@@ -151,7 +151,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
151
151
  category_ids = [],
152
152
  product_ids = [],
153
153
  collection = [],
154
- schedule_ids = []
154
+ schedule_ids = [],
155
+ schedule_date
155
156
  }) {
156
157
  if (!(schedule_ids == null ? void 0 : schedule_ids.length)) {
157
158
  const schedule_ids_data = this.store.schedule.getScheduleListByIds(schedule_ids).map((n) => n.id);
@@ -178,7 +179,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
178
179
  ids: product_ids,
179
180
  collection,
180
181
  front_end_cache_id: this.cacheId,
181
- client_schedule_ids: schedule_ids
182
+ client_schedule_ids: schedule_ids,
183
+ schedule_date
182
184
  },
183
185
  { useCache: true }
184
186
  );
@@ -196,7 +198,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
196
198
  { date, status: "available", week: "", weekNum: 0 }
197
199
  ]);
198
200
  const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
199
- return await this.loadProducts({ schedule_ids: scheduleIds, product_ids, category_ids });
201
+ return await this.loadProducts({ schedule_ids: scheduleIds, product_ids, category_ids, schedule_date: date });
200
202
  }
201
203
  // 加载当前店铺下所有 schedule
202
204
  async loadAllSchedule() {
@@ -208,7 +210,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
208
210
  async loadScheduleAvailableDate({
209
211
  startDate,
210
212
  endDate,
211
- custom_page_id
213
+ custom_page_id,
214
+ channel
212
215
  }) {
213
216
  var _a;
214
217
  if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day")) {
@@ -224,7 +227,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
224
227
  {
225
228
  start_date: startDate,
226
229
  end_date: endDate,
227
- custom_page_id
230
+ custom_page_id,
231
+ channel
228
232
  }
229
233
  );
230
234
  this.store.schedule.setAvailabilityScheduleDateList(res.data.date_list);
@@ -232,11 +236,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
232
236
  return dates;
233
237
  }
234
238
  res.data.date_list.forEach((n) => {
235
- if (n.schedule_id && n.schedule_id.length) {
236
- const index = dates.findIndex((m) => m.date === n.date);
237
- if (index !== -1) {
238
- dates[index].status = "available";
239
- }
239
+ const index = dates.findIndex((m) => m.date === n.date);
240
+ if (index !== -1) {
241
+ dates[index].status = "available";
240
242
  }
241
243
  });
242
244
  dates = (0, import_utils3.disableDatesBeforeOneDay)(dates);
@@ -646,7 +648,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
646
648
  });
647
649
  n.renderList = n.renderList.filter((m) => {
648
650
  const recordCount = capacityMap[m.id] || 0;
649
- const canUseTime = m.times.find((item) => {
651
+ const canUseArr = m.times.map((item) => {
650
652
  const res = (0, import_resources.getIsUsableByTimeItem)({
651
653
  timeSlice: {
652
654
  start_time: startTime.format("HH:mm"),
@@ -659,18 +661,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
659
661
  currentCount: recordCount + (currentCapacity || 0),
660
662
  resourcesUseableMap
661
663
  });
662
- if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false) {
664
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
663
665
  resourcesUseableMap[m.id] = res.usable;
664
666
  }
665
667
  return res.usable;
666
668
  });
667
- return canUseTime;
669
+ if (m.onlyComputed)
670
+ return false;
671
+ return !canUseArr.some((n2) => n2 === false);
668
672
  });
669
673
  });
670
674
  } else {
671
675
  productResources.forEach((item) => {
672
676
  item.renderList = item.renderList.filter((n) => {
673
677
  const recordCount = n.capacity || 0;
678
+ if (n.onlyComputed)
679
+ return false;
674
680
  return recordCount >= currentCapacity;
675
681
  });
676
682
  });
@@ -728,6 +734,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
728
734
  selectedResources,
729
735
  currentCapacity
730
736
  );
737
+ productResources.forEach((item) => {
738
+ item.renderList = item.renderList.filter((n) => {
739
+ const recordCount = n.capacity || 0;
740
+ if (n.onlyComputed)
741
+ return false;
742
+ return recordCount >= currentCapacity;
743
+ });
744
+ });
731
745
  if (productResources) {
732
746
  return {
733
747
  id: targetCartItem.id,
@@ -806,7 +820,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
806
820
  currentCount: recordCount + (capacity || 0),
807
821
  resourcesUseableMap
808
822
  });
809
- if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[n.id]) !== false) {
823
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[n.id]) !== false && res.reason !== "capacityOnly") {
810
824
  resourcesUseableMap[n.id] = res.usable;
811
825
  }
812
826
  return res.usable;
@@ -952,6 +966,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
952
966
  selectedResources,
953
967
  currentCapacity
954
968
  );
969
+ productResources.forEach((item2) => {
970
+ item2.renderList = item2.renderList.filter((n) => {
971
+ const recordCount = n.capacity || 0;
972
+ if (n.onlyComputed)
973
+ return false;
974
+ return recordCount >= currentCapacity;
975
+ });
976
+ });
955
977
  const targetRenderList = (_l = productResources.find(
956
978
  (n) => n.code === resources_code
957
979
  )) == null ? void 0 : _l.renderList;
@@ -1012,7 +1034,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1012
1034
  });
1013
1035
  if ((_b = (_a = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _a.resource) == null ? void 0 : _b.length) {
1014
1036
  dateRange[0].resource.forEach((n) => {
1015
- if (n.form_id === resourcesTypeId) {
1037
+ if (n.form_id === resourcesTypeId && !resources.find((m) => m.id === n.id)) {
1016
1038
  resources.push(n);
1017
1039
  }
1018
1040
  });
@@ -1209,7 +1231,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1209
1231
  currentCount: 1,
1210
1232
  resourcesUseableMap
1211
1233
  });
1212
- if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false) {
1234
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
1213
1235
  resourcesUseableMap[m.id] = res.usable;
1214
1236
  }
1215
1237
  if (res.usable && res.remainingCapacity >= count) {
@@ -38,6 +38,7 @@ export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, curren
38
38
  capacity: boolean;
39
39
  usable: boolean;
40
40
  remainingCapacity: number;
41
+ reason: string;
41
42
  };
42
43
  /**
43
44
  * @title: 获取商品下绑定的资源列表
@@ -95,6 +96,15 @@ export declare const getTimesIntersection: (times: TimeSliceItem[], count: numbe
95
96
  * @Date: 2024-09-19 20:23
96
97
  */
97
98
  export declare const getResourcesByIds: (resourcesMap: Record<string, ResourceItem>, ids: number[]) => ResourceItem[];
99
+ /**
100
+ * @title: 合并子资源的时间切片至组合资源
101
+ * @description:
102
+ * @param {ResourceItem[]} resources
103
+ * @param {Record<string, ResourceItem>} resourcesMap
104
+ * @return {*}
105
+ * @Author: zhiwei.Wang
106
+ */
107
+ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], resourcesMap: Record<string, ResourceItem>) => void;
98
108
  /**
99
109
  * @title: 根据资源id列表获取时间切片
100
110
  * @description: 传入一个技师id列表, 找出技师列表中公共的时间切片
@@ -40,7 +40,8 @@ __export(resources_exports, {
40
40
  getSumCapacity: () => getSumCapacity,
41
41
  getTimeSlicesByResource: () => getTimeSlicesByResource,
42
42
  getTimeSlicesByResources: () => getTimeSlicesByResources,
43
- getTimesIntersection: () => getTimesIntersection
43
+ getTimesIntersection: () => getTimesIntersection,
44
+ mergeSubResourcesTimeSlices: () => mergeSubResourcesTimeSlices
44
45
  });
45
46
  module.exports = __toCommonJS(resources_exports);
46
47
  var import_dayjs = __toESM(require("dayjs"));
@@ -84,7 +85,8 @@ var checkCapacity = ({
84
85
  if (currentCount > resource.capacity) {
85
86
  return {
86
87
  status: false,
87
- capacity: resource.capacity
88
+ capacity: resource.capacity,
89
+ reason: "capacityOnly"
88
90
  };
89
91
  }
90
92
  let conflict = (event_list || []).filter((d) => {
@@ -132,8 +134,9 @@ var getIsUsableByTimeItem = ({
132
134
  afterToDay: false,
133
135
  capacity: false,
134
136
  usable: false,
135
- remainingCapacity: 0
137
+ remainingCapacity: 0,
136
138
  // 剩余容量
139
+ reason: ""
137
140
  };
138
141
  let earliest = (0, import_dayjs.default)();
139
142
  if (!checkAfterToDay(timeSlice.start_at, earliest)) {
@@ -154,6 +157,7 @@ var getIsUsableByTimeItem = ({
154
157
  }
155
158
  });
156
159
  }
160
+ status.reason = checkCapacityResult.reason || "";
157
161
  if (!checkCapacityResult.status) {
158
162
  return status;
159
163
  }
@@ -178,6 +182,19 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
178
182
  (id) => {
179
183
  if (resourcesMap[id]) {
180
184
  combiningResources.push(resourcesMap[id]);
185
+ childAcc.push(
186
+ Object.assign({}, resourcesMap[id], {
187
+ form_id,
188
+ resourceType: item.type,
189
+ children: combiningResources,
190
+ onlyComputed: true,
191
+ // 是否是只用来计算用,组合资源里,假设商品只关联了组合资源没关联子资源,需要通过这个计算来在后面从 renderList 里删除这个资源
192
+ metadata: {
193
+ ...resourcesMap[id].metadata,
194
+ combined_resource: resourcesMap[id].combined_resource
195
+ }
196
+ })
197
+ );
181
198
  }
182
199
  }
183
200
  );
@@ -207,6 +224,19 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
207
224
  (id) => {
208
225
  if (resourcesMap[id]) {
209
226
  combiningResources.push(resourcesMap[id]);
227
+ childAcc.push(
228
+ Object.assign({}, resourcesMap[id], {
229
+ form_id,
230
+ resourceType: item.type,
231
+ children: combiningResources,
232
+ onlyComputed: true,
233
+ // 是否是只用来计算用,组合资源里,假设商品只关联了组合资源没关联子资源,需要通过这个计算来在后面从 renderList 里删除这个资源
234
+ metadata: {
235
+ ...resourcesMap[id].metadata,
236
+ combined_resource: resourcesMap[id].combined_resource
237
+ }
238
+ })
239
+ );
210
240
  }
211
241
  }
212
242
  );
@@ -335,6 +365,24 @@ var getTimesIntersection = (times, count) => {
335
365
  var getResourcesByIds = (resourcesMap, ids) => {
336
366
  return (ids || []).map((id) => resourcesMap[id]);
337
367
  };
368
+ var mergeSubResourcesTimeSlices = (resources, resourcesMap) => {
369
+ return resources.forEach((item) => {
370
+ var _a, _b;
371
+ if (((_a = item == null ? void 0 : item.combined_resource) == null ? void 0 : _a.status) === 1) {
372
+ (_b = item == null ? void 0 : item.combined_resource) == null ? void 0 : _b.resource_ids.forEach((id) => {
373
+ const subResource = resourcesMap[id];
374
+ if (subResource) {
375
+ subResource.times.forEach((time) => {
376
+ const fatherResourcesTime = item.times.find((n) => n.start_at === time.start_at && n.end_at === time.end_at);
377
+ if (fatherResourcesTime) {
378
+ fatherResourcesTime.event_list.push(...time.event_list || []);
379
+ }
380
+ });
381
+ }
382
+ });
383
+ }
384
+ });
385
+ };
338
386
  var getTimeSlicesByResources = ({
339
387
  resourceIds,
340
388
  resourcesMap,
@@ -345,6 +393,7 @@ var getTimeSlicesByResources = ({
345
393
  resourcesUseableMap
346
394
  }) => {
347
395
  let resources = getResourcesByIds(resourcesMap, resourceIds);
396
+ mergeSubResourcesTimeSlices(resources, resourcesMap);
348
397
  resources.sort((a, b) => {
349
398
  var _a, _b, _c, _d;
350
399
  const aIsCombined = ((_b = (_a = a.metadata) == null ? void 0 : _a.combined_resource) == null ? void 0 : _b.status) === 1;
@@ -506,5 +555,6 @@ var checkSubResourcesCapacity = (resource) => {
506
555
  getSumCapacity,
507
556
  getTimeSlicesByResource,
508
557
  getTimeSlicesByResources,
509
- getTimesIntersection
558
+ getTimesIntersection,
559
+ mergeSubResourcesTimeSlices
510
560
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "3.0.9",
4
+ "version": "3.0.11",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",