@pisell/pisellos 1.0.5 → 1.0.7

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.
Files changed (53) hide show
  1. package/dist/modules/Cart/index.d.ts +14 -0
  2. package/dist/modules/Cart/index.js +36 -0
  3. package/dist/modules/Cart/utils/cartProduct.js +1 -1
  4. package/dist/modules/Cart/utils/changePrice.d.ts +3 -0
  5. package/dist/modules/Cart/utils/changePrice.js +100 -0
  6. package/dist/modules/Date/index.js +57 -6
  7. package/dist/modules/Discount/index.d.ts +1 -0
  8. package/dist/modules/Discount/index.js +15 -7
  9. package/dist/modules/Discount/types.d.ts +10 -0
  10. package/dist/modules/ProductList/index.d.ts +7 -0
  11. package/dist/modules/ProductList/index.js +102 -39
  12. package/dist/modules/Rules/index.js +59 -24
  13. package/dist/modules/Rules/types.d.ts +1 -0
  14. package/dist/modules/Schedule/index.d.ts +9 -1
  15. package/dist/modules/Schedule/index.js +121 -1
  16. package/dist/modules/Schedule/types.d.ts +13 -0
  17. package/dist/solution/BookingByStep/index.d.ts +120 -30
  18. package/dist/solution/BookingByStep/index.js +749 -1083
  19. package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
  20. package/dist/solution/BookingByStep/utils/capacity.js +132 -0
  21. package/dist/solution/BookingByStep/utils/resources.d.ts +29 -31
  22. package/dist/solution/BookingByStep/utils/resources.js +39 -94
  23. package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  24. package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
  25. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  26. package/dist/solution/ShopDiscount/index.js +63 -24
  27. package/lib/modules/Cart/index.d.ts +14 -0
  28. package/lib/modules/Cart/index.js +32 -0
  29. package/lib/modules/Cart/utils/cartProduct.js +1 -1
  30. package/lib/modules/Cart/utils/changePrice.d.ts +3 -0
  31. package/lib/modules/Cart/utils/changePrice.js +64 -0
  32. package/lib/modules/Date/index.js +62 -10
  33. package/lib/modules/Discount/index.d.ts +1 -0
  34. package/lib/modules/Discount/index.js +18 -6
  35. package/lib/modules/Discount/types.d.ts +10 -0
  36. package/lib/modules/ProductList/index.d.ts +7 -0
  37. package/lib/modules/ProductList/index.js +45 -0
  38. package/lib/modules/Rules/index.js +59 -22
  39. package/lib/modules/Rules/types.d.ts +1 -0
  40. package/lib/modules/Schedule/index.d.ts +9 -1
  41. package/lib/modules/Schedule/index.js +78 -0
  42. package/lib/modules/Schedule/types.d.ts +13 -0
  43. package/lib/solution/BookingByStep/index.d.ts +120 -30
  44. package/lib/solution/BookingByStep/index.js +379 -581
  45. package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
  46. package/lib/solution/BookingByStep/utils/capacity.js +106 -0
  47. package/lib/solution/BookingByStep/utils/resources.d.ts +29 -31
  48. package/lib/solution/BookingByStep/utils/resources.js +23 -59
  49. package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  50. package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
  51. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  52. package/lib/solution/ShopDiscount/index.js +68 -18
  53. package/package.json +1 -1
@@ -45,6 +45,8 @@ var import_utils2 = require("../../modules/Schedule/utils");
45
45
  var import_utils3 = require("../../modules/Date/utils");
46
46
  var import_utils4 = require("../../modules/Product/utils");
47
47
  var import_timeslots = require("./utils/timeslots");
48
+ var import_changePrice = require("../../modules/Cart/utils/changePrice");
49
+ var import_capacity = require("./utils/capacity");
48
50
  import_dayjs.default.extend(import_isSameOrBefore.default);
49
51
  import_dayjs.default.extend(import_isSameOrAfter.default);
50
52
  var BookingByStepImpl = class extends import_BaseModule.BaseModule {
@@ -111,7 +113,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
111
113
  throw new Error(`模块 ${step} 不存在`);
112
114
  }
113
115
  });
114
- this.loadAllSchedule();
116
+ this.store.schedule.loadAllSchedule();
115
117
  this.core.effects.emit(import_types.BookingByStepHooks.onInited, {});
116
118
  }
117
119
  // 初始化step
@@ -158,56 +160,52 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
158
160
  updateStep(key, step) {
159
161
  this.store.step.updateStep(key, step);
160
162
  }
161
- // 获取购物车里 temp.xxx的方法
162
- // async getStoreCart(key?: string) {
163
- // return this.store.cart.getTemp(key);
164
- // }
165
- // 加载商品,然后导到商品列表里去
163
+ /**
164
+ *
165
+ * 加载商品,然后导到商品列表里去
166
+ * @param {({
167
+ * category_ids?: number[];
168
+ * product_ids?: number[];
169
+ * collection?: number | string[];
170
+ * schedule_date?: string;
171
+ * })} {
172
+ * category_ids = [],
173
+ * product_ids = [],
174
+ * collection = [],
175
+ * schedule_date,
176
+ * }
177
+ * @return {*}
178
+ * @memberof BookingByStepImpl
179
+ */
166
180
  async loadProducts({
167
181
  category_ids = [],
168
182
  product_ids = [],
169
183
  collection = [],
170
- // schedule_ids = [],
171
184
  schedule_date
172
185
  }) {
173
- var _a;
174
- let userPlugin = this.core.getPlugin("user");
175
- let customer_id = void 0;
176
- try {
177
- customer_id = (_a = userPlugin == null ? void 0 : userPlugin.get()) == null ? void 0 : _a.id;
178
- } catch (error) {
179
- console.error(error);
180
- }
181
- const productsData = await this.request.post(
182
- `/product/query`,
183
- {
184
- open_quotation: 1,
185
- open_bundle: 0,
186
- exclude_extension_type: [
187
- "product_party",
188
- "product_event",
189
- "product_series_event",
190
- "product_package_ticket",
191
- "ticket",
192
- "event_item"
193
- ],
194
- with: ["category", "collection", "resourceRelation"],
195
- status: "published",
196
- num: 500,
197
- skip: 1,
198
- customer_id,
199
- category_ids,
200
- ids: product_ids,
201
- collection,
202
- front_end_cache_id: this.cacheId,
203
- // client_schedule_ids: schedule_ids,
204
- schedule_date
205
- },
206
- { useCache: true }
207
- );
208
- this.store.products.addProduct(productsData.data.list);
209
- return productsData.data.list;
186
+ return this.store.products.loadProducts({
187
+ category_ids,
188
+ product_ids,
189
+ collection,
190
+ schedule_date,
191
+ cacheId: this.cacheId
192
+ });
210
193
  }
194
+ /**
195
+ * 通过 schedule 来读取商品,适用于 session 类商品
196
+ *
197
+ * @param {{
198
+ * date: string;
199
+ * product_ids?: number[];
200
+ * category_ids?: number[];
201
+ * }} {
202
+ * date,
203
+ * product_ids = [],
204
+ * category_ids = [],
205
+ * }
206
+ * @return {*}
207
+ * @memberof BookingByStepImpl
208
+ */
211
209
  async loadProductByScheduleDate({
212
210
  date,
213
211
  product_ids = [],
@@ -228,12 +226,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
228
226
  (n, index, self) => self.indexOf(n) === index
229
227
  );
230
228
  return await this.loadProducts({
231
- // schedule_ids: scheduleIds,
232
229
  product_ids: allProductIds,
233
230
  category_ids,
234
231
  schedule_date: date
235
232
  });
236
233
  }
234
+ /**
235
+ * 更新完商品数据、切换日期、或者在较后的流程里登录了,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
236
+ *
237
+ * @param {string} date
238
+ * @memberof BookingByStepImpl
239
+ */
237
240
  async updateQuotationPriceAndCart(date) {
238
241
  var _a;
239
242
  const cartItems = this.store.cart.getItems();
@@ -250,129 +253,43 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
250
253
  schedule_date: date,
251
254
  customer_id
252
255
  });
253
- for (const item of cartItems) {
254
- const targetProduct = res.find((n) => n.id === item.id);
255
- const cartProduct = await this.store.products.getProduct(
256
- item.id
257
- );
258
- const productInfo = cartProduct == null ? void 0 : cartProduct.getData();
259
- let bundle = item._bundleOrigin;
260
- productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
261
- productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
262
- bundle = bundle == null ? void 0 : bundle.map((n) => {
263
- var _a2;
264
- const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find(
265
- (m) => m.id === n.group_id
266
- );
267
- if (targetBundle) {
268
- const targetBundleItem = targetBundle.bundle_item.find(
269
- (m) => m.id === n.id
270
- );
271
- if (targetBundleItem) {
272
- return {
273
- ...n,
274
- price: targetBundleItem.price,
275
- base_price: targetBundleItem.base_price
276
- };
277
- }
278
- }
279
- return n;
280
- });
281
- this.store.cart.updateItem({
282
- _id: item._id,
283
- product: productInfo,
284
- bundle
285
- });
286
- }
287
- this.core.effects.emit(`${this.store.cart.name}:onUpdateQuotationPrice`, {});
256
+ await (0, import_changePrice.updateAllCartItemPrice)(
257
+ cartItems,
258
+ res,
259
+ (id) => this.store.products.getProduct(id),
260
+ (params) => this.store.cart.updateItem(params)
261
+ );
262
+ this.core.effects.emit(
263
+ `${this.store.cart.name}:onUpdateQuotationPrice`,
264
+ {}
265
+ );
288
266
  }
289
267
  }
290
- // 加载当前店铺下所有 schedule
291
- async loadAllSchedule() {
292
- var _a;
293
- const scheduleList = await this.request.get(
294
- `/schedule`,
295
- { num: 999 },
296
- { useCache: true }
297
- );
298
- this.store.schedule.setScheduleList(((_a = scheduleList.data) == null ? void 0 : _a.list) || []);
299
- }
300
- // ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
268
+ /**
269
+ * ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
270
+ * 适用于先选日期的流程,确定日期是否可用
271
+ * 已知问题:如果挂接的商品的资源不可用,后端是不会计算的
272
+ *
273
+ * @param {LoadScheduleAvailableDateParams} {
274
+ * startDate,
275
+ * endDate,
276
+ * custom_page_id,
277
+ * channel,
278
+ * }
279
+ * @memberof BookingByStepImpl
280
+ */
301
281
  async loadScheduleAvailableDate({
302
282
  startDate,
303
283
  endDate,
304
284
  custom_page_id,
305
285
  channel
306
286
  }) {
307
- var _a, _b, _c;
308
- if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day")) {
309
- startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
310
- }
311
- let dates = (0, import_utils3.generateMonthDates)(startDate, endDate);
312
- dates = (0, import_utils3.disableAllDates)(dates);
313
- if ((0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
314
- return dates;
315
- }
316
- const res = await this.request.get(
317
- `/schedule/product/availability/v2`,
318
- {
319
- start_date: startDate,
320
- end_date: endDate,
321
- custom_page_id,
322
- channel
323
- }
324
- );
325
- this.store.schedule.setAvailabilityScheduleDateList(res.data.date_list);
326
- this.store.schedule.setOtherProductsIds(res.data.other_product_ids || []);
327
- if (!((_a = res.data.date_list) == null ? void 0 : _a.length) && !((_b = res.data.other_product_ids) == null ? void 0 : _b.length) || (0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
328
- return dates;
329
- }
330
- if ((_c = res.data.other_product_ids) == null ? void 0 : _c.length) {
331
- dates.forEach((n) => {
332
- n.status = "available";
333
- });
334
- } else {
335
- res.data.date_list.forEach((n) => {
336
- const index = dates.findIndex((m) => m.date === n.date);
337
- if (index !== -1) {
338
- dates[index].status = "available";
339
- }
340
- });
341
- }
342
- dates = (0, import_utils3.disableDatesBeforeOneDay)(dates);
343
- return dates;
344
- }
345
- async storeProduct(productData) {
346
- const activeAccount = this.getActiveAccount();
347
- const { bundle, options, origin, product_variant_id, quantity = 1, rowKey } = productData || {};
348
- const cartItems = this.store.cart.getItems();
349
- if (rowKey) {
350
- const targetCartItem = cartItems.find((n) => {
351
- var _a;
352
- return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey;
353
- });
354
- if (targetCartItem && (0, import_utils4.isNormalProduct)(targetCartItem._productOrigin)) {
355
- this.store.cart.updateItem({
356
- _id: targetCartItem._id,
357
- product: {
358
- ...targetCartItem._productOrigin
359
- },
360
- quantity: (targetCartItem.num || 1) + quantity
361
- });
362
- return;
363
- }
364
- }
365
- const product = { ...origin, product_variant_id, rowKey };
366
- const addCartItem = {
367
- product,
368
- bundle,
369
- options,
370
- quantity
371
- };
372
- if (activeAccount) {
373
- addCartItem.account = activeAccount;
374
- }
375
- this.store.cart.addItem(addCartItem);
287
+ return await this.store.schedule.loadScheduleAvailableDate({
288
+ startDate,
289
+ endDate,
290
+ custom_page_id,
291
+ channel
292
+ });
376
293
  }
377
294
  // 添加单个账户或者 guest
378
295
  async addAccount(account, extra) {
@@ -425,7 +342,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
425
342
  }
426
343
  getActiveAccount() {
427
344
  const activeAccount = this.store.accountList.getActiveAccount();
428
- return activeAccount ? activeAccount.getAccount() : null;
345
+ const account = activeAccount == null ? void 0 : activeAccount.getAccount();
346
+ return account === null ? void 0 : account;
429
347
  }
430
348
  removeAccount(id) {
431
349
  this.store.accountList.removeAccount(id);
@@ -441,7 +359,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
441
359
  if (cartItems.length) {
442
360
  let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
443
361
  if (!date) {
444
- const normalProductCartItem = cartItems.find((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
362
+ const normalProductCartItem = cartItems.find(
363
+ (n) => !(0, import_utils4.isNormalProduct)(n._productOrigin)
364
+ );
445
365
  date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
446
366
  }
447
367
  this.updateQuotationPriceAndCart(date);
@@ -548,7 +468,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
548
468
  if (cartItems.length) {
549
469
  let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
550
470
  if (!date) {
551
- const normalProductCartItem = cartItems.find((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
471
+ const normalProductCartItem = cartItems.find(
472
+ (n) => !(0, import_utils4.isNormalProduct)(n._productOrigin)
473
+ );
552
474
  date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
553
475
  }
554
476
  this.updateQuotationPriceAndCart(date);
@@ -581,7 +503,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
581
503
  const cartItems = this.store.cart.getItems();
582
504
  const newCartItems = (0, import_lodash_es.cloneDeep)(cartItems);
583
505
  newCartItems.forEach((item) => {
584
- var _a, _b;
506
+ var _a;
585
507
  if (item._origin.resources && item._origin.resources.length) {
586
508
  item._origin.resources = item._origin.resources.map((n) => {
587
509
  const newResourcesItem = (0, import_lodash_es.cloneDeep)(n);
@@ -590,12 +512,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
590
512
  delete newResourcesItem.resourceType;
591
513
  return { ...newResourcesItem };
592
514
  });
593
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
594
- capacity: (_a = item._productOrigin) == null ? void 0 : _a.capacity,
595
- product_bundle: item._origin.product.product_bundle
596
- });
597
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
598
- if (!((_b = item._origin) == null ? void 0 : _b.metadata)) {
515
+ const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
516
+ if (!((_a = item._origin) == null ? void 0 : _a.metadata)) {
599
517
  item._origin.metadata = {};
600
518
  }
601
519
  item._origin.metadata.capacity = formatCapacity;
@@ -603,10 +521,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
603
521
  }
604
522
  });
605
523
  let type = this.otherParams.isRetailTemplate ? "virtual" : "appointment_booking";
606
- if ((0, import_utils4.areAllNormalProducts)(newCartItems.map((n) => n._productOrigin))) {
524
+ if ((0, import_utils4.areAllNormalProducts)(
525
+ newCartItems.map((n) => n._productOrigin)
526
+ )) {
607
527
  type = "virtual";
608
528
  }
609
- return this.store.order.submitOrder({ query: { cartItems: newCartItems, type } });
529
+ return this.store.order.submitOrder({
530
+ query: { cartItems: newCartItems, type }
531
+ });
610
532
  }
611
533
  // 拉起支付模块
612
534
  async pay() {
@@ -624,31 +546,136 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
624
546
  async getOtherParams() {
625
547
  return this.otherParams;
626
548
  }
627
- // 更新购物车
628
- updateCart(params) {
629
- var _a;
630
- const targetCartItem = this.store.cart.getItem(params._id);
631
- if (!targetCartItem) {
632
- throw new Error(`没有找到${params._id}购物车商品`);
549
+ /**
550
+ * 往购物车加商品数据(duration 类、普通商品)
551
+ * 老接口,先不删,怕 UI 有问题,直接桥接到新接口addProductToCart上
552
+ *
553
+ * @param {ProductData} productData
554
+ * @memberof BookingByStepImpl
555
+ */
556
+ async storeProduct(productData) {
557
+ const activeAccount = this.getActiveAccount();
558
+ this.addProductToCart({
559
+ product: productData,
560
+ account: activeAccount
561
+ });
562
+ }
563
+ /**
564
+ * 往购物车加商品数据
565
+ *
566
+ * @param {({
567
+ * product: ProductData;
568
+ * date?: { startTime: string; endTime: string } | null;
569
+ * account?: Account | null;
570
+ * })} {
571
+ * product,
572
+ * date,
573
+ * account,
574
+ * }
575
+ * @return {*}
576
+ * @memberof BookingByStepImpl
577
+ */
578
+ addProductToCart({
579
+ product,
580
+ date,
581
+ account
582
+ }) {
583
+ const {
584
+ bundle,
585
+ options,
586
+ origin,
587
+ product_variant_id,
588
+ rowKey,
589
+ quantity = 1
590
+ } = product || {};
591
+ const productData = { ...origin, product_variant_id };
592
+ if (!account) {
593
+ const activeAccount = this.getActiveAccount();
594
+ if (activeAccount) {
595
+ account = activeAccount;
596
+ }
633
597
  }
634
- let currentResourcesCapacityMap = {};
598
+ const flag = this.store.cart.mergeCartItemByRowKey({
599
+ rowKey,
600
+ quantity,
601
+ account: account || void 0
602
+ });
603
+ if (flag) {
604
+ return;
605
+ }
606
+ const addItemParams = {
607
+ product: productData,
608
+ bundle,
609
+ options,
610
+ quantity
611
+ };
612
+ if (date) {
613
+ addItemParams.date = date;
614
+ }
615
+ if (account) {
616
+ addItemParams.account = account;
617
+ }
618
+ this.addProductCheck({ date });
619
+ this.store.cart.addItem(addItemParams);
620
+ }
621
+ /**
622
+ * 添加完购物车以后做的一些检测,比如日期是否在同一天
623
+ *
624
+ * @param {({ date?: { startTime: string; endTime: string } | null })} { date }
625
+ * @memberof BookingByStepImpl
626
+ */
627
+ addProductCheck({
628
+ date
629
+ }) {
630
+ if (date) {
631
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
632
+ const cartItemsByDate = cartItems.filter(
633
+ (n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
634
+ );
635
+ if (cartItemsByDate.length) {
636
+ cartItemsByDate.forEach((n) => {
637
+ this.store.cart.removeItem(n._id);
638
+ });
639
+ }
640
+ }
641
+ }
642
+ beforeUpdateCart(params, targetCartItem) {
635
643
  if (params.resources) {
636
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
637
- capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
638
- product_bundle: targetCartItem._origin.product.product_bundle
639
- });
640
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
644
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(targetCartItem);
641
645
  params.resources = params.resources.map((n) => {
642
646
  n.capacity = currentCapacity || 1;
643
- currentResourcesCapacityMap[n.id] = currentCapacity;
644
- (0, import_resources.checkSubResourcesCapacity)(n);
647
+ (0, import_capacity.checkSubResourcesCapacity)(n);
645
648
  return n;
646
649
  });
647
650
  }
651
+ }
652
+ // 更新购物车
653
+ updateCart(params) {
654
+ const targetCartItem = this.store.cart.getItem(params._id);
655
+ if (!targetCartItem) {
656
+ throw new Error(`没有找到${params._id}购物车商品`);
657
+ }
658
+ this.beforeUpdateCart(params, targetCartItem);
648
659
  this.store.cart.updateItem(params);
660
+ this.updateCartCheck(params, targetCartItem);
661
+ }
662
+ /**
663
+ * 更新购物车以后的一些操作,比如检测资源是否重复,检测资源容量是否足够
664
+ *
665
+ * @param {IUpdateItemParams} params
666
+ * @param {CartItem} targetCartItem
667
+ * @return {*}
668
+ * @memberof BookingByStepImpl
669
+ */
670
+ updateCartCheck(params, targetCartItem) {
671
+ var _a;
649
672
  if (this.otherParams.isRetailTemplate) {
650
673
  return;
651
674
  }
675
+ let currentResourcesCapacityMap = {};
676
+ (_a = params.resources) == null ? void 0 : _a.forEach((n) => {
677
+ currentResourcesCapacityMap[n.id] = n.capacity;
678
+ });
652
679
  const allOriginResources = [];
653
680
  const dateRange = this.store.date.getDateRange();
654
681
  if (dateRange == null ? void 0 : dateRange.length) {
@@ -669,50 +696,31 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
669
696
  cartItems.forEach((item) => {
670
697
  var _a2;
671
698
  if (item._id !== targetCartItem._id) {
699
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
672
700
  const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
673
- const sameFormIdResources = targetCartItem._origin.resources.filter((n) => n.form_id === m.form_id);
701
+ const sameFormIdResources = (0, import_resources.filterResourcesByFormItem)(
702
+ targetCartItem._origin.resources,
703
+ m.form_id
704
+ );
674
705
  if (!(sameFormIdResources == null ? void 0 : sameFormIdResources.length)) {
675
706
  return true;
676
707
  }
677
708
  return !sameFormIdResources.some((targetRes) => {
678
- var _a3, _b, _c;
679
709
  if (targetRes.resourceType !== "single") {
680
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
681
- capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
682
- product_bundle: item._origin.product.product_bundle
683
- });
684
- const currentCapacity = (0, import_resources.getSumCapacity)({
685
- capacity: formatCapacity
686
- });
687
710
  const originResource = allOriginResources.find(
688
711
  (n) => n.id === targetRes.id
689
712
  );
690
- if (currentResourcesCapacityMap[m.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
691
- return true;
692
- }
693
- currentResourcesCapacityMap[m.id] += currentCapacity;
694
- return false;
713
+ const canUse = (0, import_capacity.checkResourceCanUseByCapacity)(
714
+ currentResourcesCapacityMap[m.id],
715
+ currentCapacity,
716
+ originResource == null ? void 0 : originResource.capacity
717
+ );
718
+ if (canUse)
719
+ currentResourcesCapacityMap[m.id] += currentCapacity;
720
+ return !canUse;
695
721
  }
696
722
  if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
697
- if (targetRes.id === m.id)
698
- return true;
699
- if (((_b = targetRes.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && // 如果现在选择的是组合资源,需要判断
700
- // 1、当前其他购物车里是否选了当前组合资源的子资源
701
- // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
702
- (targetRes.metadata.combined_resource.resource_ids.includes(
703
- m.id
704
- ) || targetRes.metadata.combined_resource.resource_ids.some(
705
- (n) => {
706
- return m.metadata.combined_resource.resource_ids.includes(
707
- n
708
- );
709
- }
710
- )))
711
- return true;
712
- if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(
713
- targetRes.id
714
- ))
715
- return true;
723
+ return (0, import_resources.checkTwoResourcesIntersection)(targetRes, m);
716
724
  }
717
725
  return false;
718
726
  });
@@ -809,8 +817,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
809
817
  const resources = [];
810
818
  if (dateRange == null ? void 0 : dateRange.length) {
811
819
  dateRange.forEach((n) => {
812
- if (n.resource)
813
- resources.push(...n.resource);
820
+ resources.push(...this.store.date.getResourcesListByDate(n.date) || []);
814
821
  });
815
822
  }
816
823
  if (!resources.length) {
@@ -824,14 +831,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
824
831
  const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
825
832
  const arr = [];
826
833
  cartItems.forEach((cartItem) => {
827
- var _a, _b, _c, _d, _e, _f, _g, _h;
834
+ var _a, _b, _c, _d, _e, _f;
828
835
  let selectedResources = [];
829
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
830
- capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
831
- product_bundle: cartItem._origin.product.product_bundle
832
- });
836
+ const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
833
837
  cartItem._origin.metadata.capacity = formatCapacity;
834
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
835
838
  if (cartItem.holder_id) {
836
839
  selectedResources = (0, import_resources.getOthersSelectedResources)(
837
840
  cartItems,
@@ -847,7 +850,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
847
850
  }
848
851
  const productResources = (0, import_resources.getResourcesByProduct)(
849
852
  resourcesMap,
850
- ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
853
+ ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
851
854
  selectedResources,
852
855
  currentCapacity
853
856
  );
@@ -860,20 +863,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
860
863
  );
861
864
  const resourcesUseableMap = {};
862
865
  productResources.forEach((n) => {
863
- n.renderList = n.renderList.sort((a, b) => {
864
- var _a2, _b2, _c2, _d2;
865
- const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
866
- const bIsCombined = ((_d2 = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d2.status) === 1;
867
- if (aIsCombined && !bIsCombined)
868
- return 1;
869
- if (!aIsCombined && bIsCombined)
870
- return -1;
871
- return 0;
872
- });
866
+ n.renderList = (0, import_resources.sortCombinedResources)(n.renderList);
873
867
  n.renderList = n.renderList.filter((m) => {
874
- const mTimes = m.times.filter((n2) => {
875
- return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(startTime)) && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(endTime));
876
- });
868
+ const mTimes = (0, import_timeslots.filterConditionTimeSlots)(
869
+ m.times,
870
+ startTime,
871
+ endTime
872
+ );
877
873
  if (mTimes.length === 0) {
878
874
  return false;
879
875
  }
@@ -903,8 +899,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
903
899
  });
904
900
  });
905
901
  } else {
906
- const hasFlexibleDuration = ((_e = (_d = cartItem._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.type) === "flexible";
907
- const operating_day_boundary = (_h = (_g = (_f = this.shopStore.get("core")) == null ? void 0 : _f.core) == null ? void 0 : _g.operating_day_boundary) == null ? void 0 : _h.time;
902
+ const hasFlexibleDuration = ((_d = (_c = cartItem._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) === "flexible";
903
+ const operating_day_boundary = (_f = (_e = this.shopStore.get("core")) == null ? void 0 : _e.core) == null ? void 0 : _f.operating_day_boundary;
908
904
  productResources.forEach((item) => {
909
905
  item.renderList = item.renderList.filter((n) => {
910
906
  var _a2, _b2, _c2;
@@ -937,138 +933,28 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
937
933
  });
938
934
  return arr;
939
935
  }
940
- // 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
936
+ /**
937
+ * 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
938
+ *
939
+ * @return {*}
940
+ * @memberof BookingByStepImpl
941
+ */
941
942
  checkResourceListForDate() {
942
- const dateRange = this.store.date.getDateRange();
943
- const resources = [];
944
- if (dateRange == null ? void 0 : dateRange.length) {
945
- dateRange.forEach((n) => {
946
- if (n.resource)
947
- resources.push(...n.resource);
948
- });
949
- }
950
- if (!resources.length) {
951
- const dateList = this.store.date.getDateList();
952
- dateList.forEach((n) => {
953
- if (n.resource)
954
- resources.push(...n.resource);
955
- });
956
- }
957
- const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
958
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
959
- const arr = [];
960
- cartItems.forEach((cartItem) => {
961
- var _a, _b, _c;
962
- let selectedResources = [];
963
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
964
- capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
965
- product_bundle: cartItem._origin.product.product_bundle
966
- });
967
- cartItem._origin.metadata.capacity = formatCapacity;
968
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
969
- if (cartItem.holder_id) {
970
- selectedResources = (0, import_resources.getOthersSelectedResources)(
971
- cartItems,
972
- cartItem.holder_id,
973
- resourcesMap
974
- );
975
- } else {
976
- selectedResources = (0, import_resources.getOthersCartSelectedResources)(
977
- cartItems,
978
- cartItem._id,
979
- resourcesMap
980
- );
981
- }
982
- const productResources = (0, import_resources.getResourcesByProduct)(
983
- resourcesMap,
984
- ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
985
- selectedResources,
986
- currentCapacity
987
- );
988
- if (cartItem._origin.start_time) {
989
- const startTime = (0, import_dayjs.default)(
990
- `${cartItem._origin.start_date} ${cartItem._origin.start_time}`
991
- );
992
- const endTime = (0, import_dayjs.default)(
993
- `${cartItem._origin.end_date} ${cartItem._origin.end_time}`
994
- );
995
- const resourcesUseableMap = {};
996
- productResources.forEach((n) => {
997
- n.renderList = n.renderList.sort((a, b) => {
998
- var _a2, _b2, _c2, _d;
999
- const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
1000
- const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
1001
- if (aIsCombined && !bIsCombined)
1002
- return 1;
1003
- if (!aIsCombined && bIsCombined)
1004
- return -1;
1005
- return 0;
1006
- });
1007
- n.renderList = n.renderList.filter((m) => {
1008
- const mTimes = m.times.filter((n2) => {
1009
- return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(startTime)) && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(endTime));
1010
- });
1011
- if (mTimes.length === 0) {
1012
- return false;
1013
- }
1014
- const canUseArr = mTimes.map((item) => {
1015
- var _a2;
1016
- const res = (0, import_resources.getIsUsableByTimeItem)({
1017
- timeSlice: {
1018
- start_time: startTime.format("HH:mm"),
1019
- end_time: endTime.format("HH:mm"),
1020
- start_at: startTime,
1021
- end_at: endTime
1022
- },
1023
- time: item,
1024
- resource: m,
1025
- currentCount: currentCapacity || 0,
1026
- resourcesUseableMap,
1027
- cut_off_time: (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.cut_off_time
1028
- });
1029
- if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
1030
- resourcesUseableMap[m.id] = res.usable;
1031
- }
1032
- return res.usable;
1033
- });
1034
- if (m.onlyComputed)
1035
- return false;
1036
- return !canUseArr.some((n2) => n2 === false);
1037
- });
1038
- });
1039
- } else {
1040
- productResources.forEach((item) => {
1041
- item.renderList = item.renderList.filter((n) => {
1042
- var _a2, _b2;
1043
- const recordCount = n.capacity || 0;
1044
- if (n.onlyComputed)
1045
- return false;
1046
- const timeSlots = (0, import_resources.getTimeSlicesByResource)({
1047
- resource: n,
1048
- duration: ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 10,
1049
- split: 10,
1050
- currentDate: dateRange[0].date
1051
- });
1052
- return recordCount >= currentCapacity && timeSlots.length > 0;
1053
- });
1054
- });
1055
- }
1056
- arr.push({
1057
- id: cartItem.id,
1058
- // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1059
- _id: cartItem._id,
1060
- // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1061
- productResources
1062
- });
1063
- });
1064
- const hasResource = arr.every(
1065
- (n) => n.productResources.every((m) => m.renderList.length > 0)
943
+ const resourcesList = this.getResourcesList();
944
+ const hasResource = resourcesList.every(
945
+ (item) => item.resources.every((resource) => resource.renderList.length > 0)
1066
946
  );
1067
947
  return hasResource;
1068
948
  }
1069
- // 给单个购物车里的商品获取资源列表
949
+ /**
950
+ * 给单个购物车里的商品获取资源列表,给 UI 用的
951
+ *
952
+ * @param {(string | number)} id
953
+ * @return {*}
954
+ * @memberof BookingByStepImpl
955
+ */
1070
956
  getResourcesListByCartItem(id) {
1071
- var _a, _b, _c;
957
+ var _a, _b;
1072
958
  const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1073
959
  const dateRange = this.store.date.getDateRange();
1074
960
  const resources = [];
@@ -1082,11 +968,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1082
968
  throw new Error(`没有找到${id}购物车商品`);
1083
969
  }
1084
970
  let selectedResources = [];
1085
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
1086
- capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
1087
- product_bundle: targetCartItem._origin.product.product_bundle
1088
- });
1089
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
971
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(targetCartItem);
1090
972
  if (targetCartItem.holder_id) {
1091
973
  selectedResources = (0, import_resources.getOthersSelectedResources)(
1092
974
  cartItems,
@@ -1102,7 +984,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1102
984
  }
1103
985
  const productResources = (0, import_resources.getResourcesByProduct)(
1104
986
  resourcesMap,
1105
- ((_c = (_b = targetCartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
987
+ ((_b = (_a = targetCartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
1106
988
  selectedResources,
1107
989
  currentCapacity
1108
990
  );
@@ -1127,21 +1009,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1127
1009
  };
1128
1010
  }
1129
1011
  }
1130
- // 通过资源列表和指定的资源 id,获取指定资源的时间切片
1131
- getResourceTimeSlot({
1132
- product,
1133
- resources,
1134
- currentResourceId
1135
- }) {
1136
- const dateRange = this.store.date.getDateRange();
1137
- const timeSlots = (0, import_resources.getTimeSlicesByResource)({
1138
- resource: resources.find((n) => n.id === currentResourceId),
1139
- duration: product.duration.value,
1140
- split: 10,
1141
- currentDate: dateRange[0].date
1142
- });
1143
- return timeSlots;
1144
- }
1145
1012
  // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
1146
1013
  autoSelectAccountResources({
1147
1014
  cartItem,
@@ -1297,17 +1164,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1297
1164
  const accountList = this.store.accountList.getAccounts();
1298
1165
  const selectForCartResources = (cartItems2) => {
1299
1166
  let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
1300
- const hasFlexibleProduct = cartItems2.some((item) => {
1301
- var _a2, _b;
1302
- return ((_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b.type) === "flexible";
1303
- });
1167
+ const hasFlexibleProduct = cartItems2.some(
1168
+ (item) => {
1169
+ var _a2, _b;
1170
+ return ((_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b.type) === "flexible";
1171
+ }
1172
+ );
1304
1173
  cartItems2.forEach((item, index) => {
1305
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1306
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
1307
- capacity: (_a2 = item._productOrigin) == null ? void 0 : _a2.capacity,
1308
- product_bundle: item._origin.product.product_bundle
1309
- });
1310
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
1174
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1175
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
1311
1176
  if (item._origin.start_time && !(timeSlots == null ? void 0 : timeSlots.start_time)) {
1312
1177
  recordTimeSlots = {
1313
1178
  start_time: item._origin.start_time,
@@ -1317,16 +1182,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1317
1182
  };
1318
1183
  }
1319
1184
  if (recordTimeSlots) {
1320
- const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find(
1185
+ const currentResourceConfig = (_c = (_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.find(
1321
1186
  (n) => n.code === resources_code
1322
1187
  );
1323
- if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((_e = item._productOrigin) == null ? void 0 : _e.duration) && !hasFlexibleProduct) {
1188
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((_d = item._productOrigin) == null ? void 0 : _d.duration) && !hasFlexibleProduct) {
1324
1189
  let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
1325
- ((_g = (_f = item._productOrigin) == null ? void 0 : _f.duration) == null ? void 0 : _g.value) || 10,
1190
+ ((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) || 10,
1326
1191
  "minutes"
1327
1192
  );
1328
1193
  let end_at = start_at.add(
1329
- ((_i = (_h = item._productOrigin) == null ? void 0 : _h.duration) == null ? void 0 : _i.value) || 10,
1194
+ ((_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.value) || 10,
1330
1195
  "minutes"
1331
1196
  );
1332
1197
  recordTimeSlots = {
@@ -1359,7 +1224,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1359
1224
  });
1360
1225
  }
1361
1226
  res.selectedResource.capacity = currentCapacity;
1362
- (0, import_resources.checkSubResourcesCapacity)(res.selectedResource);
1227
+ (0, import_capacity.checkSubResourcesCapacity)(res.selectedResource);
1363
1228
  this.store.cart.updateItem({
1364
1229
  _id: item._id,
1365
1230
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
@@ -1380,7 +1245,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1380
1245
  const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1381
1246
  let selectedResources = [];
1382
1247
  const resources2 = (0, import_lodash_es.cloneDeep)(
1383
- ((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || []
1248
+ ((_j = (_i = item._productOrigin) == null ? void 0 : _i.product_resource) == null ? void 0 : _j.resources) || []
1384
1249
  );
1385
1250
  const currentResourcesRenderList = [];
1386
1251
  resources2.forEach((n) => {
@@ -1428,11 +1293,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1428
1293
  return recordCount >= currentCapacity;
1429
1294
  });
1430
1295
  });
1431
- const targetRenderList = (_l = productResources.find(
1296
+ const targetRenderList = (_k = productResources.find(
1432
1297
  (n) => n.code === resources_code
1433
- )) == null ? void 0 : _l.renderList;
1298
+ )) == null ? void 0 : _k.renderList;
1434
1299
  if (targetRenderList && targetRenderList.length > 0) {
1435
- if ((_m = item._origin.resources) == null ? void 0 : _m.some(
1300
+ if ((_l = item._origin.resources) == null ? void 0 : _l.some(
1436
1301
  (n) => n.form_id === targetRenderList[0].form_id
1437
1302
  )) {
1438
1303
  return;
@@ -1444,7 +1309,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1444
1309
  });
1445
1310
  const targetResource = fastestResource || targetRenderList[0];
1446
1311
  targetResource.capacity = currentCapacity;
1447
- (0, import_resources.checkSubResourcesCapacity)(targetResource);
1312
+ (0, import_capacity.checkSubResourcesCapacity)(targetResource);
1448
1313
  if (!selectResourcesMap[targetResource.id]) {
1449
1314
  selectResourcesMap[targetResource.id] = currentCapacity;
1450
1315
  } else {
@@ -1478,7 +1343,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1478
1343
  }
1479
1344
  // 从购物车中获取已经分配好第一步资源的所有时间片
1480
1345
  getTimeSlotByAllResources(resources_code) {
1481
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1346
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1482
1347
  let dateRange = this.store.date.getDateRange();
1483
1348
  const resources = [];
1484
1349
  const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
@@ -1488,7 +1353,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1488
1353
  let maxCutOffTime = void 0;
1489
1354
  let maxCutOffTimeValue = (0, import_dayjs.default)();
1490
1355
  cartItems.forEach((item) => {
1491
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2;
1356
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i;
1492
1357
  (_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
1493
1358
  if (n.code === resources_code) {
1494
1359
  resources.push(...n.renderList || []);
@@ -1501,7 +1366,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1501
1366
  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(
1502
1367
  (n) => n.code === resources_code
1503
1368
  )) == null ? void 0 : _g2.id;
1504
- if (((_h2 = item._productOrigin) == null ? void 0 : _h2.cut_off_time) && ((_i2 = item._productOrigin) == null ? void 0 : _i2.cut_off_time.type) === "advance") {
1369
+ if (((_h2 = item._productOrigin) == null ? void 0 : _h2.cut_off_time) && ((_i = item._productOrigin) == null ? void 0 : _i.cut_off_time.type) === "advance") {
1505
1370
  const currentCutOffTime = (0, import_dayjs.default)().add(
1506
1371
  item._productOrigin.cut_off_time.unit,
1507
1372
  item._productOrigin.cut_off_time.unit_type
@@ -1566,11 +1431,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1566
1431
  ];
1567
1432
  }
1568
1433
  const resourcesUseableMap = {};
1569
- const hasFlexibleDuration = cartItems.some((item) => {
1570
- var _a2, _b2;
1571
- return ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.type) === "flexible";
1572
- });
1573
- const operating_day_boundary = (_i = (_h = (_g = this.shopStore.get("core")) == null ? void 0 : _g.core) == null ? void 0 : _h.operating_day_boundary) == null ? void 0 : _i.time;
1434
+ const hasFlexibleDuration = cartItems.some(
1435
+ (item) => {
1436
+ var _a2, _b2;
1437
+ return ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.type) === "flexible";
1438
+ }
1439
+ );
1440
+ const operating_day_boundary = (_h = (_g = this.shopStore.get("core")) == null ? void 0 : _g.core) == null ? void 0 : _h.operating_day_boundary;
1574
1441
  const timeSlots = (0, import_resources.getTimeSlicesByResources)({
1575
1442
  resourceIds,
1576
1443
  resourcesMap,
@@ -1586,9 +1453,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1586
1453
  }
1587
1454
  // 提交时间切片,绑定到对应购物车的商品上,更新购物车---只有 duration 商品
1588
1455
  submitTimeSlot(timeSlots) {
1589
- var _a, _b, _c;
1456
+ var _a, _b;
1590
1457
  const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1591
- const allResources = this.store.date.getResourcesListByDate(timeSlots.start_at.format("YYYY-MM-DD"));
1458
+ const allResources = this.store.date.getResourcesListByDate(
1459
+ timeSlots.start_at.format("YYYY-MM-DD")
1460
+ );
1592
1461
  const itemsByAccount = cartItems.reduce(
1593
1462
  (acc, item) => {
1594
1463
  const holderId = item.holder_id;
@@ -1600,27 +1469,36 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1600
1469
  },
1601
1470
  {}
1602
1471
  );
1603
- const operating_day_boundary = (_c = (_b = (_a = this.shopStore.get("core")) == null ? void 0 : _a.core) == null ? void 0 : _b.operating_day_boundary) == null ? void 0 : _c.time;
1472
+ const operating_day_boundary = (_b = (_a = this.shopStore.get("core")) == null ? void 0 : _a.core) == null ? void 0 : _b.operating_day_boundary;
1604
1473
  Object.values(itemsByAccount).forEach((accountItems) => {
1605
1474
  let currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1606
1475
  accountItems.forEach((item, index) => {
1607
1476
  var _a2;
1608
1477
  const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
1609
1478
  newResources.forEach((resource) => {
1610
- var _a3, _b2, _c2, _d, _e;
1479
+ var _a3, _b2, _c, _d, _e;
1611
1480
  if (((_b2 = (_a3 = item._productOrigin) == null ? void 0 : _a3.duration) == null ? void 0 : _b2.type) === "flexible") {
1612
1481
  item.duration = {
1613
1482
  type: "minutes",
1614
1483
  value: 10
1615
1484
  };
1616
1485
  resource.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1617
- const targetResourceTimes = (_c2 = allResources == null ? void 0 : allResources.find((n) => n.id === resource.id)) == null ? void 0 : _c2.times;
1618
- const resourcesEndTime = targetResourceTimes.reduce((acc, curr) => {
1619
- return (0, import_dayjs.default)(curr.end_at).isBefore((0, import_dayjs.default)(acc.end_at)) ? curr : acc;
1620
- }, targetResourceTimes[0]);
1621
- const resourceDate = (0, import_dayjs.default)(resourcesEndTime.end_at).format("YYYY-MM-DD");
1622
- const operatingBoundaryDateTime = `${resourceDate} ${operating_day_boundary}`;
1623
- const endTime = (0, import_dayjs.default)(resourcesEndTime.end_at).isBefore((0, import_dayjs.default)(operatingBoundaryDateTime)) ? resourcesEndTime.end_at : operatingBoundaryDateTime;
1486
+ const targetResourceTimes = (_c = allResources == null ? void 0 : allResources.find(
1487
+ (n) => n.id === resource.id
1488
+ )) == null ? void 0 : _c.times;
1489
+ const resourcesEndTime = targetResourceTimes.reduce(
1490
+ (acc, curr) => {
1491
+ return (0, import_dayjs.default)(curr.end_at).isBefore((0, import_dayjs.default)(acc.end_at)) ? curr : acc;
1492
+ },
1493
+ targetResourceTimes[0]
1494
+ );
1495
+ const resourceDate = (0, import_dayjs.default)(resourcesEndTime.end_at).format(
1496
+ "YYYY-MM-DD"
1497
+ );
1498
+ const operatingBoundaryDateTime = `${resourceDate} ${operating_day_boundary.type === "start_time" ? "23:59" : operating_day_boundary.time}`;
1499
+ const endTime = (0, import_dayjs.default)(resourcesEndTime.end_at).isBefore(
1500
+ (0, import_dayjs.default)(operatingBoundaryDateTime)
1501
+ ) ? resourcesEndTime.end_at : operatingBoundaryDateTime;
1624
1502
  let formattedEndTime;
1625
1503
  if (typeof endTime === "string" && endTime.includes(":") && !endTime.includes(" ") && !endTime.includes("T")) {
1626
1504
  const currentDate = timeSlots.start_at.format("YYYY-MM-DD");
@@ -1631,10 +1509,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1631
1509
  resource.endTime = formattedEndTime.format("YYYY-MM-DD HH:mm");
1632
1510
  } else {
1633
1511
  resource.startTime = currentStartTime;
1634
- resource.endTime = (0, import_dayjs.default)(currentStartTime).add(
1635
- ((_e = (_d = item._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.value) || 10,
1636
- "minutes"
1637
- ).format("YYYY-MM-DD HH:mm");
1512
+ 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");
1638
1513
  }
1639
1514
  });
1640
1515
  this.store.cart.updateItem({
@@ -1680,10 +1555,21 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1680
1555
  if (targetProduct) {
1681
1556
  const targetProductData = targetProduct.getData();
1682
1557
  this.store.currentProduct = targetProduct;
1683
- const newScheduleArr = this.getScheduleDataByIds(
1684
- targetProductData["schedule.ids"]
1685
- );
1686
- targetProduct.setOtherParams("schedule", newScheduleArr);
1558
+ if (targetProductData["schedule.ids"]) {
1559
+ const newScheduleArr = this.getScheduleDataByIds(
1560
+ targetProductData["schedule.ids"]
1561
+ );
1562
+ targetProduct.setOtherParams("schedule", newScheduleArr);
1563
+ } else if (targetProductData.duration) {
1564
+ const dateRange = this.store.date.getDateRange();
1565
+ if (!dateRange.length)
1566
+ return;
1567
+ this.getAvailableDate({
1568
+ startDate: dateRange[0].date,
1569
+ endDate: dateRange[dateRange.length - 1].date,
1570
+ products: [targetProductData]
1571
+ });
1572
+ }
1687
1573
  }
1688
1574
  }
1689
1575
  closeProductDetail() {
@@ -1740,7 +1626,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1740
1626
  return -1;
1741
1627
  return 0;
1742
1628
  });
1743
- const firstEnabledResourceId = (_f = (_e = (_d = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.find((n) => n.status === 1)) == null ? void 0 : _f.id;
1629
+ const firstEnabledResourceId = (_f = (_e = (_d = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.find(
1630
+ (n) => n.status === 1
1631
+ )) == null ? void 0 : _f.id;
1744
1632
  const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1745
1633
  const resourcesUseableMap = {};
1746
1634
  let count = 0;
@@ -1776,7 +1664,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1776
1664
  }
1777
1665
  currentResourcesTimeSlotCanUsedArr.push(res.usable);
1778
1666
  });
1779
- if (!currentResourcesTimeSlotCanUsedArr.some((n) => n === false) && m.form_id === firstEnabledResourceId) {
1667
+ if (!currentResourcesTimeSlotCanUsedArr.some(
1668
+ (n) => n === false
1669
+ ) && // 只统计第一种资源的容量和 left
1670
+ m.form_id === firstEnabledResourceId) {
1780
1671
  if (currentResourcesCount >= count) {
1781
1672
  count = currentResourcesCount;
1782
1673
  }
@@ -1798,56 +1689,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1798
1689
  });
1799
1690
  return formatScheduleTimeSlots;
1800
1691
  }
1801
- addProductToCart({
1802
- product,
1803
- date,
1804
- account
1805
- }) {
1806
- const { bundle, options, origin, product_variant_id, rowKey, quantity = 1 } = product || {};
1807
- const productData = { ...origin, product_variant_id };
1808
- if (!account) {
1809
- const activeAccount = this.getActiveAccount();
1810
- if (activeAccount) {
1811
- account = activeAccount;
1812
- }
1813
- }
1814
- if (rowKey) {
1815
- const cartItems = this.store.cart.getItems();
1816
- const targetCartItem = cartItems.find((n) => {
1817
- var _a;
1818
- return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey;
1819
- });
1820
- if (targetCartItem && (0, import_utils4.isNormalProduct)(targetCartItem._productOrigin)) {
1821
- this.store.cart.updateItem({
1822
- _id: targetCartItem._id,
1823
- product: {
1824
- ...targetCartItem._productOrigin,
1825
- quantity: (targetCartItem.num || 1) + quantity
1826
- }
1827
- });
1828
- return;
1829
- }
1830
- }
1831
- this.store.cart.addItem({
1832
- product: productData,
1833
- date,
1834
- account,
1835
- bundle,
1836
- options,
1837
- quantity
1838
- });
1839
- if (date) {
1840
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1841
- const cartItemsByDate = cartItems.filter(
1842
- (n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
1843
- );
1844
- if (cartItemsByDate.length) {
1845
- cartItemsByDate.forEach((n) => {
1846
- this.store.cart.removeItem(n._id);
1847
- });
1848
- }
1849
- }
1850
- }
1851
1692
  setOtherData(key, value) {
1852
1693
  this.otherData[key] = value;
1853
1694
  this.checkSaveCache({
@@ -1876,7 +1717,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1876
1717
  * @memberof BookingByStepImpl
1877
1718
  */
1878
1719
  getResourcesByCartItemAndCode(cartItemId, resourceCode) {
1879
- var _a, _b, _c;
1720
+ var _a, _b;
1880
1721
  const dateRange = this.store.date.getDateRange();
1881
1722
  const resources = [];
1882
1723
  if (dateRange == null ? void 0 : dateRange.length) {
@@ -1898,12 +1739,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1898
1739
  if (!cartItem)
1899
1740
  return [];
1900
1741
  let selectedResources = [];
1901
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
1902
- capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
1903
- product_bundle: cartItem._origin.product.product_bundle
1904
- });
1742
+ const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
1905
1743
  cartItem._origin.metadata.capacity = formatCapacity;
1906
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
1907
1744
  if (cartItem.holder_id) {
1908
1745
  selectedResources = (0, import_resources.getOthersSelectedResources)(
1909
1746
  cartItems,
@@ -1919,7 +1756,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1919
1756
  }
1920
1757
  const productResources = (0, import_resources.getResourcesByProduct)(
1921
1758
  resourcesMap,
1922
- ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
1759
+ ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
1923
1760
  selectedResources,
1924
1761
  currentCapacity
1925
1762
  );
@@ -1938,9 +1775,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1938
1775
  const resourcesUseableMap = {};
1939
1776
  targetResource.renderList = targetResource.renderList.sort(
1940
1777
  (a, b) => {
1941
- var _a2, _b2, _c2, _d;
1778
+ var _a2, _b2, _c, _d;
1942
1779
  const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
1943
- const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
1780
+ const bIsCombined = ((_d = (_c = b.metadata) == null ? void 0 : _c.combined_resource) == null ? void 0 : _d.status) === 1;
1944
1781
  if (aIsCombined && !bIsCombined)
1945
1782
  return 1;
1946
1783
  if (!aIsCombined && bIsCombined)
@@ -2027,56 +1864,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2027
1864
  }
2028
1865
  return results;
2029
1866
  }
2030
- async getAvailableDateForSession(params = {}) {
2031
- let { startDate, endDate, type } = params;
2032
- if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
2033
- startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
2034
- }
2035
- endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
2036
- let tempProducts = [];
2037
- if (this.store.currentProduct) {
2038
- tempProducts = [
2039
- {
2040
- ...this.store.currentProduct.getData(),
2041
- _schedule: this.store.currentProduct.getOtherParams()["schedule"]
2042
- }
2043
- ];
2044
- }
2045
- const { resourceIds, rules, resourcesMap } = (0, import_products.getAvailableProductResources)(tempProducts) || {};
2046
- this.otherParams.currentResourcesMap = resourcesMap;
2047
- const res = await this.store.date.getResourceDates({
2048
- query: {
2049
- start_date: startDate || "",
2050
- end_date: endDate || "",
2051
- resource_ids: resourceIds
2052
- },
2053
- rules,
2054
- type
2055
- });
2056
- if (this.store.currentProduct) {
2057
- const dateListWithTimeSlots = await this.getTimeslotsScheduleByDateRange({
2058
- startDate: startDate || "",
2059
- endDate: endDate || ""
2060
- });
2061
- res.forEach((n) => {
2062
- if (!dateListWithTimeSlots[n.date]) {
2063
- n.status = "unavailable";
2064
- } else {
2065
- const allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(
2066
- (d) => d.count
2067
- );
2068
- if (!allTimeSlotsCanUse) {
2069
- n.status = "unavailable";
2070
- }
2071
- }
2072
- });
2073
- }
2074
- const firstAvailableDate = res.find((n) => n.status === "available");
2075
- return {
2076
- dateList: res,
2077
- firstAvailableDate
2078
- };
2079
- }
2080
1867
  async getAvailableDateForSessionOptimize(params = {}) {
2081
1868
  var _a, _b, _c, _d, _e, _f;
2082
1869
  let { startDate, endDate } = params;
@@ -2084,14 +1871,33 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2084
1871
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
2085
1872
  }
2086
1873
  const endDateAfterMonth = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
1874
+ let tempEndDate = endDateAfterMonth;
2087
1875
  if ((0, import_dayjs.default)(startDate).add(7, "day").isAfter((0, import_dayjs.default)(endDateAfterMonth), "day")) {
2088
- endDate = (0, import_dayjs.default)(startDate).add(7, "day").format("YYYY-MM-DD");
1876
+ tempEndDate = (0, import_dayjs.default)(startDate).add(7, "day").format("YYYY-MM-DD");
2089
1877
  } else {
2090
- endDate = endDateAfterMonth;
1878
+ tempEndDate = endDateAfterMonth;
1879
+ }
1880
+ if ((0, import_dayjs.default)(tempEndDate).isBefore((0, import_dayjs.default)(endDate), "day")) {
1881
+ tempEndDate = endDate || "";
2091
1882
  }
1883
+ endDate = tempEndDate;
1884
+ const cache = (_a = this.store.currentProduct) == null ? void 0 : _a.getOtherParams()["timeSlotBySchedule"];
1885
+ if (cache) {
1886
+ if ((0, import_dayjs.default)(params.startDate).isSameOrAfter((0, import_dayjs.default)(cache.startDate), "day") && (0, import_dayjs.default)(params.endDate).isSameOrBefore((0, import_dayjs.default)(cache.endDate), "day")) {
1887
+ this.store.date.setDateList(cache.dateList);
1888
+ return {
1889
+ dateList: cache.dateList,
1890
+ firstAvailableDate: cache.firstAvailableDate
1891
+ };
1892
+ }
1893
+ }
1894
+ if ((0, import_dayjs.default)(tempEndDate).isBefore((0, import_dayjs.default)(endDate), "day")) {
1895
+ tempEndDate = endDate || "";
1896
+ }
1897
+ endDate = tempEndDate;
2092
1898
  let tempProducts;
2093
- tempProducts = (_a = this.store.currentProduct) == null ? void 0 : _a.getData();
2094
- const schedule = (_b = this.store.currentProduct) == null ? void 0 : _b.getOtherParams()["schedule"];
1899
+ tempProducts = (_b = this.store.currentProduct) == null ? void 0 : _b.getData();
1900
+ const schedule = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["schedule"];
2095
1901
  const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
2096
1902
  schedule,
2097
1903
  startDate || "",
@@ -2105,16 +1911,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2105
1911
  resource_ids: tempResourceIds
2106
1912
  }
2107
1913
  });
2108
- const cache = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["timeSlotBySchedule"];
2109
- if (cache) {
2110
- if ((0, import_dayjs.default)(params.startDate).isSameOrAfter((0, import_dayjs.default)(cache.startDate), "day") && (0, import_dayjs.default)(params.endDate).isSameOrBefore((0, import_dayjs.default)(cache.endDate), "day")) {
2111
- this.store.date.setDateList(cache.dateList);
2112
- return {
2113
- dateList: cache.dateList,
2114
- firstAvailableDate: cache.firstAvailableDate
2115
- };
2116
- }
2117
- }
2118
1914
  let dates = [];
2119
1915
  let currentDate = (0, import_dayjs.default)(startDate);
2120
1916
  let firstAvailableDate = "";
@@ -2174,25 +1970,27 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2174
1970
  if (mTimes.length === 0) {
2175
1971
  return;
2176
1972
  }
2177
- const targetCanUseTimes = mTimes.some((childTiem) => {
2178
- const res2 = (0, import_resources.getIsUsableByTimeItem)({
2179
- timeSlice: {
2180
- start_time: item.start,
2181
- end_time: item.end,
2182
- start_at: (0, import_dayjs.default)(item.start),
2183
- end_at: (0, import_dayjs.default)(item.end)
2184
- },
2185
- time: childTiem,
2186
- resource: m,
2187
- currentCount: 1,
2188
- resourcesUseableMap,
2189
- cut_off_time: tempProducts == null ? void 0 : tempProducts.cut_off_time
2190
- });
2191
- if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res2.reason !== "capacityOnly") {
2192
- resourcesUseableMap[m.id] = res2.usable;
1973
+ const targetCanUseTimes = mTimes.some(
1974
+ (childTiem) => {
1975
+ const res2 = (0, import_resources.getIsUsableByTimeItem)({
1976
+ timeSlice: {
1977
+ start_time: item.start,
1978
+ end_time: item.end,
1979
+ start_at: (0, import_dayjs.default)(item.start),
1980
+ end_at: (0, import_dayjs.default)(item.end)
1981
+ },
1982
+ time: childTiem,
1983
+ resource: m,
1984
+ currentCount: 1,
1985
+ resourcesUseableMap,
1986
+ cut_off_time: tempProducts == null ? void 0 : tempProducts.cut_off_time
1987
+ });
1988
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res2.reason !== "capacityOnly") {
1989
+ resourcesUseableMap[m.id] = res2.usable;
1990
+ }
1991
+ return res2.usable && !m.onlyComputed;
2193
1992
  }
2194
- return res2.usable && !m.onlyComputed;
2195
- });
1993
+ );
2196
1994
  return targetCanUseTimes;
2197
1995
  });
2198
1996
  });