@pisell/pisellos 2.0.38 → 2.0.40

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 (57) hide show
  1. package/dist/modules/AccountList/index.js +17 -12
  2. package/dist/modules/Cart/index.d.ts +14 -0
  3. package/dist/modules/Cart/index.js +38 -1
  4. package/dist/modules/Cart/utils/cartProduct.d.ts +2 -0
  5. package/dist/modules/Cart/utils/cartProduct.js +23 -5
  6. package/dist/modules/Cart/utils/changePrice.d.ts +3 -0
  7. package/dist/modules/Cart/utils/changePrice.js +104 -0
  8. package/dist/modules/Date/index.js +57 -6
  9. package/dist/modules/Discount/index.d.ts +1 -0
  10. package/dist/modules/Discount/index.js +13 -6
  11. package/dist/modules/Discount/types.d.ts +10 -0
  12. package/dist/modules/ProductList/index.d.ts +7 -0
  13. package/dist/modules/ProductList/index.js +102 -39
  14. package/dist/modules/Rules/index.js +191 -75
  15. package/dist/modules/Rules/types.d.ts +7 -1
  16. package/dist/modules/Schedule/index.d.ts +9 -1
  17. package/dist/modules/Schedule/index.js +122 -2
  18. package/dist/modules/Schedule/types.d.ts +13 -0
  19. package/dist/solution/BookingByStep/index.d.ts +120 -30
  20. package/dist/solution/BookingByStep/index.js +750 -1078
  21. package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
  22. package/dist/solution/BookingByStep/utils/capacity.js +132 -0
  23. package/dist/solution/BookingByStep/utils/resources.d.ts +29 -31
  24. package/dist/solution/BookingByStep/utils/resources.js +39 -94
  25. package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  26. package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
  27. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  28. package/dist/solution/ShopDiscount/index.js +119 -44
  29. package/lib/modules/AccountList/index.js +4 -0
  30. package/lib/modules/Cart/index.d.ts +14 -0
  31. package/lib/modules/Cart/index.js +34 -1
  32. package/lib/modules/Cart/utils/cartProduct.d.ts +2 -0
  33. package/lib/modules/Cart/utils/cartProduct.js +16 -5
  34. package/lib/modules/Cart/utils/changePrice.d.ts +3 -0
  35. package/lib/modules/Cart/utils/changePrice.js +78 -0
  36. package/lib/modules/Date/index.js +62 -10
  37. package/lib/modules/Discount/index.d.ts +1 -0
  38. package/lib/modules/Discount/index.js +17 -6
  39. package/lib/modules/Discount/types.d.ts +10 -0
  40. package/lib/modules/ProductList/index.d.ts +7 -0
  41. package/lib/modules/ProductList/index.js +45 -0
  42. package/lib/modules/Rules/index.js +142 -62
  43. package/lib/modules/Rules/types.d.ts +7 -1
  44. package/lib/modules/Schedule/index.d.ts +9 -1
  45. package/lib/modules/Schedule/index.js +79 -1
  46. package/lib/modules/Schedule/types.d.ts +13 -0
  47. package/lib/solution/BookingByStep/index.d.ts +120 -30
  48. package/lib/solution/BookingByStep/index.js +389 -587
  49. package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
  50. package/lib/solution/BookingByStep/utils/capacity.js +106 -0
  51. package/lib/solution/BookingByStep/utils/resources.d.ts +29 -31
  52. package/lib/solution/BookingByStep/utils/resources.js +23 -59
  53. package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  54. package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
  55. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  56. package/lib/solution/ShopDiscount/index.js +91 -19
  57. 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,29 +817,30 @@ 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
  }
823
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
816
824
  if (!resources.length) {
817
- const dateList = this.store.date.getDateList();
818
- dateList.forEach((n) => {
819
- if (n.resource)
820
- resources.push(...n.resource);
821
- });
825
+ const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
826
+ if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
827
+ const dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
828
+ resources.push(...dateResources || []);
829
+ } else {
830
+ const dateList = this.store.date.getDateList();
831
+ dateList.forEach((n) => {
832
+ if (n.resource)
833
+ resources.push(...n.resource);
834
+ });
835
+ }
822
836
  }
823
837
  const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
824
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
825
838
  const arr = [];
826
839
  cartItems.forEach((cartItem) => {
827
- var _a, _b, _c, _d, _e, _f, _g, _h;
840
+ var _a, _b, _c, _d, _e, _f;
828
841
  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
- });
842
+ const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
833
843
  cartItem._origin.metadata.capacity = formatCapacity;
834
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
835
844
  if (cartItem.holder_id) {
836
845
  selectedResources = (0, import_resources.getOthersSelectedResources)(
837
846
  cartItems,
@@ -847,7 +856,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
847
856
  }
848
857
  const productResources = (0, import_resources.getResourcesByProduct)(
849
858
  resourcesMap,
850
- ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
859
+ ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
851
860
  selectedResources,
852
861
  currentCapacity
853
862
  );
@@ -860,20 +869,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
860
869
  );
861
870
  const resourcesUseableMap = {};
862
871
  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
- });
872
+ n.renderList = (0, import_resources.sortCombinedResources)(n.renderList);
873
873
  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
- });
874
+ const mTimes = (0, import_timeslots.filterConditionTimeSlots)(
875
+ m.times,
876
+ startTime,
877
+ endTime
878
+ );
877
879
  if (mTimes.length === 0) {
878
880
  return false;
879
881
  }
@@ -903,8 +905,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
903
905
  });
904
906
  });
905
907
  } 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;
908
+ const hasFlexibleDuration = ((_d = (_c = cartItem._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) === "flexible";
909
+ const operating_day_boundary = (_f = (_e = this.shopStore.get("core")) == null ? void 0 : _e.core) == null ? void 0 : _f.operating_day_boundary;
908
910
  productResources.forEach((item) => {
909
911
  item.renderList = item.renderList.filter((n) => {
910
912
  var _a2, _b2, _c2;
@@ -937,138 +939,28 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
937
939
  });
938
940
  return arr;
939
941
  }
940
- // 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
942
+ /**
943
+ * 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
944
+ *
945
+ * @return {*}
946
+ * @memberof BookingByStepImpl
947
+ */
941
948
  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)
949
+ const resourcesList = this.getResourcesList();
950
+ const hasResource = resourcesList.every(
951
+ (item) => item.resources.every((resource) => resource.renderList.length > 0)
1066
952
  );
1067
953
  return hasResource;
1068
954
  }
1069
- // 给单个购物车里的商品获取资源列表
955
+ /**
956
+ * 给单个购物车里的商品获取资源列表,给 UI 用的
957
+ *
958
+ * @param {(string | number)} id
959
+ * @return {*}
960
+ * @memberof BookingByStepImpl
961
+ */
1070
962
  getResourcesListByCartItem(id) {
1071
- var _a, _b, _c;
963
+ var _a, _b;
1072
964
  const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1073
965
  const dateRange = this.store.date.getDateRange();
1074
966
  const resources = [];
@@ -1082,11 +974,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1082
974
  throw new Error(`没有找到${id}购物车商品`);
1083
975
  }
1084
976
  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 });
977
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(targetCartItem);
1090
978
  if (targetCartItem.holder_id) {
1091
979
  selectedResources = (0, import_resources.getOthersSelectedResources)(
1092
980
  cartItems,
@@ -1102,7 +990,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1102
990
  }
1103
991
  const productResources = (0, import_resources.getResourcesByProduct)(
1104
992
  resourcesMap,
1105
- ((_c = (_b = targetCartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
993
+ ((_b = (_a = targetCartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
1106
994
  selectedResources,
1107
995
  currentCapacity
1108
996
  );
@@ -1127,21 +1015,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1127
1015
  };
1128
1016
  }
1129
1017
  }
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
1018
  // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
1146
1019
  autoSelectAccountResources({
1147
1020
  cartItem,
@@ -1297,17 +1170,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1297
1170
  const accountList = this.store.accountList.getAccounts();
1298
1171
  const selectForCartResources = (cartItems2) => {
1299
1172
  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
- });
1173
+ const hasFlexibleProduct = cartItems2.some(
1174
+ (item) => {
1175
+ var _a2, _b;
1176
+ return ((_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b.type) === "flexible";
1177
+ }
1178
+ );
1304
1179
  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 });
1180
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1181
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
1311
1182
  if (item._origin.start_time && !(timeSlots == null ? void 0 : timeSlots.start_time)) {
1312
1183
  recordTimeSlots = {
1313
1184
  start_time: item._origin.start_time,
@@ -1317,16 +1188,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1317
1188
  };
1318
1189
  }
1319
1190
  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(
1191
+ const currentResourceConfig = (_c = (_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.find(
1321
1192
  (n) => n.code === resources_code
1322
1193
  );
1323
- if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((_e = item._productOrigin) == null ? void 0 : _e.duration) && !hasFlexibleProduct) {
1194
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((_d = item._productOrigin) == null ? void 0 : _d.duration) && !hasFlexibleProduct) {
1324
1195
  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,
1196
+ ((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) || 10,
1326
1197
  "minutes"
1327
1198
  );
1328
1199
  let end_at = start_at.add(
1329
- ((_i = (_h = item._productOrigin) == null ? void 0 : _h.duration) == null ? void 0 : _i.value) || 10,
1200
+ ((_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.value) || 10,
1330
1201
  "minutes"
1331
1202
  );
1332
1203
  recordTimeSlots = {
@@ -1359,7 +1230,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1359
1230
  });
1360
1231
  }
1361
1232
  res.selectedResource.capacity = currentCapacity;
1362
- (0, import_resources.checkSubResourcesCapacity)(res.selectedResource);
1233
+ (0, import_capacity.checkSubResourcesCapacity)(res.selectedResource);
1363
1234
  this.store.cart.updateItem({
1364
1235
  _id: item._id,
1365
1236
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
@@ -1380,7 +1251,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1380
1251
  const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1381
1252
  let selectedResources = [];
1382
1253
  const resources2 = (0, import_lodash_es.cloneDeep)(
1383
- ((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || []
1254
+ ((_j = (_i = item._productOrigin) == null ? void 0 : _i.product_resource) == null ? void 0 : _j.resources) || []
1384
1255
  );
1385
1256
  const currentResourcesRenderList = [];
1386
1257
  resources2.forEach((n) => {
@@ -1428,11 +1299,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1428
1299
  return recordCount >= currentCapacity;
1429
1300
  });
1430
1301
  });
1431
- const targetRenderList = (_l = productResources.find(
1302
+ const targetRenderList = (_k = productResources.find(
1432
1303
  (n) => n.code === resources_code
1433
- )) == null ? void 0 : _l.renderList;
1304
+ )) == null ? void 0 : _k.renderList;
1434
1305
  if (targetRenderList && targetRenderList.length > 0) {
1435
- if ((_m = item._origin.resources) == null ? void 0 : _m.some(
1306
+ if ((_l = item._origin.resources) == null ? void 0 : _l.some(
1436
1307
  (n) => n.form_id === targetRenderList[0].form_id
1437
1308
  )) {
1438
1309
  return;
@@ -1444,7 +1315,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1444
1315
  });
1445
1316
  const targetResource = fastestResource || targetRenderList[0];
1446
1317
  targetResource.capacity = currentCapacity;
1447
- (0, import_resources.checkSubResourcesCapacity)(targetResource);
1318
+ (0, import_capacity.checkSubResourcesCapacity)(targetResource);
1448
1319
  if (!selectResourcesMap[targetResource.id]) {
1449
1320
  selectResourcesMap[targetResource.id] = currentCapacity;
1450
1321
  } else {
@@ -1478,7 +1349,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1478
1349
  }
1479
1350
  // 从购物车中获取已经分配好第一步资源的所有时间片
1480
1351
  getTimeSlotByAllResources(resources_code) {
1481
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1352
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1482
1353
  let dateRange = this.store.date.getDateRange();
1483
1354
  const resources = [];
1484
1355
  const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
@@ -1488,7 +1359,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1488
1359
  let maxCutOffTime = void 0;
1489
1360
  let maxCutOffTimeValue = (0, import_dayjs.default)();
1490
1361
  cartItems.forEach((item) => {
1491
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2;
1362
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i;
1492
1363
  (_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
1493
1364
  if (n.code === resources_code) {
1494
1365
  resources.push(...n.renderList || []);
@@ -1501,7 +1372,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1501
1372
  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
1373
  (n) => n.code === resources_code
1503
1374
  )) == 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") {
1375
+ if (((_h2 = item._productOrigin) == null ? void 0 : _h2.cut_off_time) && ((_i = item._productOrigin) == null ? void 0 : _i.cut_off_time.type) === "advance") {
1505
1376
  const currentCutOffTime = (0, import_dayjs.default)().add(
1506
1377
  item._productOrigin.cut_off_time.unit,
1507
1378
  item._productOrigin.cut_off_time.unit_type
@@ -1566,11 +1437,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1566
1437
  ];
1567
1438
  }
1568
1439
  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;
1440
+ const hasFlexibleDuration = cartItems.some(
1441
+ (item) => {
1442
+ var _a2, _b2;
1443
+ return ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.type) === "flexible";
1444
+ }
1445
+ );
1446
+ const operating_day_boundary = (_h = (_g = this.shopStore.get("core")) == null ? void 0 : _g.core) == null ? void 0 : _h.operating_day_boundary;
1574
1447
  const timeSlots = (0, import_resources.getTimeSlicesByResources)({
1575
1448
  resourceIds,
1576
1449
  resourcesMap,
@@ -1586,9 +1459,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1586
1459
  }
1587
1460
  // 提交时间切片,绑定到对应购物车的商品上,更新购物车---只有 duration 商品
1588
1461
  submitTimeSlot(timeSlots) {
1589
- var _a, _b, _c;
1462
+ var _a, _b;
1590
1463
  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"));
1464
+ const allResources = this.store.date.getResourcesListByDate(
1465
+ timeSlots.start_at.format("YYYY-MM-DD")
1466
+ );
1592
1467
  const itemsByAccount = cartItems.reduce(
1593
1468
  (acc, item) => {
1594
1469
  const holderId = item.holder_id;
@@ -1600,27 +1475,36 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1600
1475
  },
1601
1476
  {}
1602
1477
  );
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;
1478
+ const operating_day_boundary = (_b = (_a = this.shopStore.get("core")) == null ? void 0 : _a.core) == null ? void 0 : _b.operating_day_boundary;
1604
1479
  Object.values(itemsByAccount).forEach((accountItems) => {
1605
1480
  let currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1606
1481
  accountItems.forEach((item, index) => {
1607
1482
  var _a2;
1608
1483
  const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
1609
1484
  newResources.forEach((resource) => {
1610
- var _a3, _b2, _c2, _d, _e;
1485
+ var _a3, _b2, _c, _d, _e;
1611
1486
  if (((_b2 = (_a3 = item._productOrigin) == null ? void 0 : _a3.duration) == null ? void 0 : _b2.type) === "flexible") {
1612
1487
  item.duration = {
1613
1488
  type: "minutes",
1614
1489
  value: 10
1615
1490
  };
1616
1491
  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;
1492
+ const targetResourceTimes = (_c = allResources == null ? void 0 : allResources.find(
1493
+ (n) => n.id === resource.id
1494
+ )) == null ? void 0 : _c.times;
1495
+ const resourcesEndTime = targetResourceTimes.reduce(
1496
+ (acc, curr) => {
1497
+ return (0, import_dayjs.default)(curr.end_at).isBefore((0, import_dayjs.default)(acc.end_at)) ? curr : acc;
1498
+ },
1499
+ targetResourceTimes[0]
1500
+ );
1501
+ const resourceDate = (0, import_dayjs.default)(resourcesEndTime.end_at).format(
1502
+ "YYYY-MM-DD"
1503
+ );
1504
+ const operatingBoundaryDateTime = `${resourceDate} ${operating_day_boundary.type === "start_time" ? "23:59" : operating_day_boundary.time}`;
1505
+ const endTime = (0, import_dayjs.default)(resourcesEndTime.end_at).isBefore(
1506
+ (0, import_dayjs.default)(operatingBoundaryDateTime)
1507
+ ) ? resourcesEndTime.end_at : operatingBoundaryDateTime;
1624
1508
  let formattedEndTime;
1625
1509
  if (typeof endTime === "string" && endTime.includes(":") && !endTime.includes(" ") && !endTime.includes("T")) {
1626
1510
  const currentDate = timeSlots.start_at.format("YYYY-MM-DD");
@@ -1631,10 +1515,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1631
1515
  resource.endTime = formattedEndTime.format("YYYY-MM-DD HH:mm");
1632
1516
  } else {
1633
1517
  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");
1518
+ 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
1519
  }
1639
1520
  });
1640
1521
  this.store.cart.updateItem({
@@ -1680,10 +1561,21 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1680
1561
  if (targetProduct) {
1681
1562
  const targetProductData = targetProduct.getData();
1682
1563
  this.store.currentProduct = targetProduct;
1683
- const newScheduleArr = this.getScheduleDataByIds(
1684
- targetProductData["schedule.ids"]
1685
- );
1686
- targetProduct.setOtherParams("schedule", newScheduleArr);
1564
+ if (targetProductData["schedule.ids"]) {
1565
+ const newScheduleArr = this.getScheduleDataByIds(
1566
+ targetProductData["schedule.ids"]
1567
+ );
1568
+ targetProduct.setOtherParams("schedule", newScheduleArr);
1569
+ } else if (targetProductData.duration) {
1570
+ const dateRange = this.store.date.getDateRange();
1571
+ if (!(dateRange == null ? void 0 : dateRange.length))
1572
+ return;
1573
+ this.getAvailableDate({
1574
+ startDate: dateRange[0].date,
1575
+ endDate: dateRange[dateRange.length - 1].date,
1576
+ products: [targetProductData]
1577
+ });
1578
+ }
1687
1579
  }
1688
1580
  }
1689
1581
  closeProductDetail() {
@@ -1740,7 +1632,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1740
1632
  return -1;
1741
1633
  return 0;
1742
1634
  });
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;
1635
+ const firstEnabledResourceId = (_f = (_e = (_d = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.find(
1636
+ (n) => n.status === 1
1637
+ )) == null ? void 0 : _f.id;
1744
1638
  const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1745
1639
  const resourcesUseableMap = {};
1746
1640
  let count = 0;
@@ -1776,7 +1670,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1776
1670
  }
1777
1671
  currentResourcesTimeSlotCanUsedArr.push(res.usable);
1778
1672
  });
1779
- if (!currentResourcesTimeSlotCanUsedArr.some((n) => n === false) && m.form_id === firstEnabledResourceId) {
1673
+ if (!currentResourcesTimeSlotCanUsedArr.some(
1674
+ (n) => n === false
1675
+ ) && // 只统计第一种资源的容量和 left
1676
+ m.form_id === firstEnabledResourceId) {
1780
1677
  if (currentResourcesCount >= count) {
1781
1678
  count = currentResourcesCount;
1782
1679
  }
@@ -1798,56 +1695,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1798
1695
  });
1799
1696
  return formatScheduleTimeSlots;
1800
1697
  }
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
1698
  setOtherData(key, value) {
1852
1699
  this.otherData[key] = value;
1853
1700
  this.checkSaveCache({
@@ -1876,7 +1723,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1876
1723
  * @memberof BookingByStepImpl
1877
1724
  */
1878
1725
  getResourcesByCartItemAndCode(cartItemId, resourceCode) {
1879
- var _a, _b, _c;
1726
+ var _a, _b;
1880
1727
  const dateRange = this.store.date.getDateRange();
1881
1728
  const resources = [];
1882
1729
  if (dateRange == null ? void 0 : dateRange.length) {
@@ -1898,12 +1745,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1898
1745
  if (!cartItem)
1899
1746
  return [];
1900
1747
  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
- });
1748
+ const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
1905
1749
  cartItem._origin.metadata.capacity = formatCapacity;
1906
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
1907
1750
  if (cartItem.holder_id) {
1908
1751
  selectedResources = (0, import_resources.getOthersSelectedResources)(
1909
1752
  cartItems,
@@ -1919,7 +1762,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1919
1762
  }
1920
1763
  const productResources = (0, import_resources.getResourcesByProduct)(
1921
1764
  resourcesMap,
1922
- ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
1765
+ ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
1923
1766
  selectedResources,
1924
1767
  currentCapacity
1925
1768
  );
@@ -1938,9 +1781,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1938
1781
  const resourcesUseableMap = {};
1939
1782
  targetResource.renderList = targetResource.renderList.sort(
1940
1783
  (a, b) => {
1941
- var _a2, _b2, _c2, _d;
1784
+ var _a2, _b2, _c, _d;
1942
1785
  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;
1786
+ const bIsCombined = ((_d = (_c = b.metadata) == null ? void 0 : _c.combined_resource) == null ? void 0 : _d.status) === 1;
1944
1787
  if (aIsCombined && !bIsCombined)
1945
1788
  return 1;
1946
1789
  if (!aIsCombined && bIsCombined)
@@ -2027,56 +1870,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2027
1870
  }
2028
1871
  return results;
2029
1872
  }
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
1873
  async getAvailableDateForSessionOptimize(params = {}) {
2081
1874
  var _a, _b, _c, _d, _e, _f;
2082
1875
  let { startDate, endDate } = params;
@@ -2084,14 +1877,29 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2084
1877
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
2085
1878
  }
2086
1879
  const endDateAfterMonth = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
1880
+ let tempEndDate = endDateAfterMonth;
2087
1881
  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");
1882
+ tempEndDate = (0, import_dayjs.default)(startDate).add(7, "day").format("YYYY-MM-DD");
2089
1883
  } else {
2090
- endDate = endDateAfterMonth;
1884
+ tempEndDate = endDateAfterMonth;
1885
+ }
1886
+ if ((0, import_dayjs.default)(tempEndDate).isBefore((0, import_dayjs.default)(endDate), "day")) {
1887
+ tempEndDate = endDate || "";
1888
+ }
1889
+ endDate = tempEndDate;
1890
+ const cache = (_a = this.store.currentProduct) == null ? void 0 : _a.getOtherParams()["timeSlotBySchedule"];
1891
+ if (cache) {
1892
+ 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")) {
1893
+ this.store.date.setDateList(cache.dateList);
1894
+ return {
1895
+ dateList: cache.dateList,
1896
+ firstAvailableDate: cache.firstAvailableDate
1897
+ };
1898
+ }
2091
1899
  }
2092
1900
  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"];
1901
+ tempProducts = (_b = this.store.currentProduct) == null ? void 0 : _b.getData();
1902
+ const schedule = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["schedule"];
2095
1903
  const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
2096
1904
  schedule,
2097
1905
  startDate || "",
@@ -2105,16 +1913,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2105
1913
  resource_ids: tempResourceIds
2106
1914
  }
2107
1915
  });
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
1916
  let dates = [];
2119
1917
  let currentDate = (0, import_dayjs.default)(startDate);
2120
1918
  let firstAvailableDate = "";
@@ -2174,25 +1972,27 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2174
1972
  if (mTimes.length === 0) {
2175
1973
  return;
2176
1974
  }
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;
1975
+ const targetCanUseTimes = mTimes.some(
1976
+ (childTiem) => {
1977
+ const res2 = (0, import_resources.getIsUsableByTimeItem)({
1978
+ timeSlice: {
1979
+ start_time: item.start,
1980
+ end_time: item.end,
1981
+ start_at: (0, import_dayjs.default)(item.start),
1982
+ end_at: (0, import_dayjs.default)(item.end)
1983
+ },
1984
+ time: childTiem,
1985
+ resource: m,
1986
+ currentCount: 1,
1987
+ resourcesUseableMap,
1988
+ cut_off_time: tempProducts == null ? void 0 : tempProducts.cut_off_time
1989
+ });
1990
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res2.reason !== "capacityOnly") {
1991
+ resourcesUseableMap[m.id] = res2.usable;
1992
+ }
1993
+ return res2.usable && !m.onlyComputed;
2193
1994
  }
2194
- return res2.usable && !m.onlyComputed;
2195
- });
1995
+ );
2196
1996
  return targetCanUseTimes;
2197
1997
  });
2198
1998
  });
@@ -2240,6 +2040,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2240
2040
  });
2241
2041
  }
2242
2042
  isTargetNormalProduct(product) {
2043
+ if (!product)
2044
+ return false;
2243
2045
  return (0, import_utils4.isNormalProduct)(product);
2244
2046
  }
2245
2047
  isTargetCartIdNormalProduct(id) {