@pisell/pisellos 0.0.140 → 0.0.142

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 (39) 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/changePrice.d.ts +3 -0
  4. package/dist/modules/Cart/utils/changePrice.js +100 -0
  5. package/dist/modules/Date/index.js +57 -6
  6. package/dist/modules/ProductList/index.d.ts +7 -0
  7. package/dist/modules/ProductList/index.js +102 -39
  8. package/dist/modules/Schedule/index.d.ts +9 -1
  9. package/dist/modules/Schedule/index.js +121 -1
  10. package/dist/modules/Schedule/types.d.ts +13 -0
  11. package/dist/solution/BookingByStep/index.d.ts +120 -30
  12. package/dist/solution/BookingByStep/index.js +739 -1097
  13. package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
  14. package/dist/solution/BookingByStep/utils/capacity.js +132 -0
  15. package/dist/solution/BookingByStep/utils/resources.d.ts +21 -29
  16. package/dist/solution/BookingByStep/utils/resources.js +39 -95
  17. package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  18. package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
  19. package/dist/solution/ShopDiscount/index.js +1 -1
  20. package/lib/modules/Cart/index.d.ts +14 -0
  21. package/lib/modules/Cart/index.js +32 -0
  22. package/lib/modules/Cart/utils/changePrice.d.ts +3 -0
  23. package/lib/modules/Cart/utils/changePrice.js +64 -0
  24. package/lib/modules/Date/index.js +62 -10
  25. package/lib/modules/ProductList/index.d.ts +7 -0
  26. package/lib/modules/ProductList/index.js +45 -0
  27. package/lib/modules/Schedule/index.d.ts +9 -1
  28. package/lib/modules/Schedule/index.js +78 -0
  29. package/lib/modules/Schedule/types.d.ts +13 -0
  30. package/lib/solution/BookingByStep/index.d.ts +120 -30
  31. package/lib/solution/BookingByStep/index.js +361 -580
  32. package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
  33. package/lib/solution/BookingByStep/utils/capacity.js +106 -0
  34. package/lib/solution/BookingByStep/utils/resources.d.ts +21 -29
  35. package/lib/solution/BookingByStep/utils/resources.js +21 -58
  36. package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  37. package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
  38. package/lib/solution/ShopDiscount/index.js +1 -1
  39. 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,133 +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 currentAccount = this.store.accountList.getActiveAccount();
351
- const targetCartItem = cartItems.find((n) => {
352
- var _a;
353
- return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey && n.holder_id === (currentAccount == null ? void 0 : currentAccount.getId());
354
- });
355
- const targetAccount = targetCartItem == null ? void 0 : targetCartItem.holder_id;
356
- const isSameAccount = (currentAccount == null ? void 0 : currentAccount.getId()) === targetAccount;
357
- if (targetCartItem && (0, import_utils4.isNormalProduct)(targetCartItem._productOrigin) && isSameAccount) {
358
- this.store.cart.updateItem({
359
- _id: targetCartItem._id,
360
- product: {
361
- ...targetCartItem._productOrigin
362
- },
363
- quantity: (targetCartItem.num || 1) + quantity
364
- });
365
- this.core.effects.emit(`${this.store.cart.name}:onUpdateCartItemNums`, {});
366
- return;
367
- }
368
- }
369
- const product = { ...origin, product_variant_id, rowKey };
370
- const addCartItem = {
371
- product,
372
- bundle,
373
- options,
374
- quantity
375
- };
376
- if (activeAccount) {
377
- addCartItem.account = activeAccount;
378
- }
379
- this.store.cart.addItem(addCartItem);
287
+ return await this.store.schedule.loadScheduleAvailableDate({
288
+ startDate,
289
+ endDate,
290
+ custom_page_id,
291
+ channel
292
+ });
380
293
  }
381
294
  // 添加单个账户或者 guest
382
295
  async addAccount(account, extra) {
@@ -429,7 +342,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
429
342
  }
430
343
  getActiveAccount() {
431
344
  const activeAccount = this.store.accountList.getActiveAccount();
432
- return activeAccount ? activeAccount.getAccount() : null;
345
+ const account = activeAccount == null ? void 0 : activeAccount.getAccount();
346
+ return account === null ? void 0 : account;
433
347
  }
434
348
  removeAccount(id) {
435
349
  this.store.accountList.removeAccount(id);
@@ -445,7 +359,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
445
359
  if (cartItems.length) {
446
360
  let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
447
361
  if (!date) {
448
- 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
+ );
449
365
  date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
450
366
  }
451
367
  this.updateQuotationPriceAndCart(date);
@@ -472,6 +388,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
472
388
  // 获取商品/服务的可用日期
473
389
  async getAvailableDate(params = {}) {
474
390
  var _a, _b, _c;
391
+ debugger;
475
392
  let { products, startDate, endDate, type } = params;
476
393
  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"))) {
477
394
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
@@ -552,7 +469,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
552
469
  if (cartItems.length) {
553
470
  let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
554
471
  if (!date) {
555
- const normalProductCartItem = cartItems.find((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
472
+ const normalProductCartItem = cartItems.find(
473
+ (n) => !(0, import_utils4.isNormalProduct)(n._productOrigin)
474
+ );
556
475
  date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
557
476
  }
558
477
  this.updateQuotationPriceAndCart(date);
@@ -585,7 +504,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
585
504
  const cartItems = this.store.cart.getItems();
586
505
  const newCartItems = (0, import_lodash_es.cloneDeep)(cartItems);
587
506
  newCartItems.forEach((item) => {
588
- var _a, _b;
507
+ var _a;
589
508
  if (item._origin.resources && item._origin.resources.length) {
590
509
  item._origin.resources = item._origin.resources.map((n) => {
591
510
  const newResourcesItem = (0, import_lodash_es.cloneDeep)(n);
@@ -594,12 +513,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
594
513
  delete newResourcesItem.resourceType;
595
514
  return { ...newResourcesItem };
596
515
  });
597
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
598
- capacity: (_a = item._productOrigin) == null ? void 0 : _a.capacity,
599
- product_bundle: item._origin.product.product_bundle
600
- });
601
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
602
- if (!((_b = item._origin) == null ? void 0 : _b.metadata)) {
516
+ const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
517
+ if (!((_a = item._origin) == null ? void 0 : _a.metadata)) {
603
518
  item._origin.metadata = {};
604
519
  }
605
520
  item._origin.metadata.capacity = formatCapacity;
@@ -607,10 +522,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
607
522
  }
608
523
  });
609
524
  let type = this.otherParams.isRetailTemplate ? "virtual" : "appointment_booking";
610
- if ((0, import_utils4.areAllNormalProducts)(newCartItems.map((n) => n._productOrigin))) {
525
+ if ((0, import_utils4.areAllNormalProducts)(
526
+ newCartItems.map((n) => n._productOrigin)
527
+ )) {
611
528
  type = "virtual";
612
529
  }
613
- return this.store.order.submitOrder({ query: { cartItems: newCartItems, type } });
530
+ return this.store.order.submitOrder({
531
+ query: { cartItems: newCartItems, type }
532
+ });
614
533
  }
615
534
  // 拉起支付模块
616
535
  async pay() {
@@ -628,31 +547,136 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
628
547
  async getOtherParams() {
629
548
  return this.otherParams;
630
549
  }
631
- // 更新购物车
632
- updateCart(params) {
633
- var _a;
634
- const targetCartItem = this.store.cart.getItem(params._id);
635
- if (!targetCartItem) {
636
- throw new Error(`没有找到${params._id}购物车商品`);
550
+ /**
551
+ * 往购物车加商品数据(duration 类、普通商品)
552
+ * 老接口,先不删,怕 UI 有问题,直接桥接到新接口addProductToCart上
553
+ *
554
+ * @param {ProductData} productData
555
+ * @memberof BookingByStepImpl
556
+ */
557
+ async storeProduct(productData) {
558
+ const activeAccount = this.getActiveAccount();
559
+ this.addProductToCart({
560
+ product: productData,
561
+ account: activeAccount
562
+ });
563
+ }
564
+ /**
565
+ * 往购物车加商品数据
566
+ *
567
+ * @param {({
568
+ * product: ProductData;
569
+ * date?: { startTime: string; endTime: string } | null;
570
+ * account?: Account | null;
571
+ * })} {
572
+ * product,
573
+ * date,
574
+ * account,
575
+ * }
576
+ * @return {*}
577
+ * @memberof BookingByStepImpl
578
+ */
579
+ addProductToCart({
580
+ product,
581
+ date,
582
+ account
583
+ }) {
584
+ const {
585
+ bundle,
586
+ options,
587
+ origin,
588
+ product_variant_id,
589
+ rowKey,
590
+ quantity = 1
591
+ } = product || {};
592
+ const productData = { ...origin, product_variant_id };
593
+ if (!account) {
594
+ const activeAccount = this.getActiveAccount();
595
+ if (activeAccount) {
596
+ account = activeAccount;
597
+ }
637
598
  }
638
- let currentResourcesCapacityMap = {};
599
+ const flag = this.store.cart.mergeCartItemByRowKey({
600
+ rowKey,
601
+ quantity,
602
+ account: account || void 0
603
+ });
604
+ if (flag) {
605
+ return;
606
+ }
607
+ const addItemParams = {
608
+ product: productData,
609
+ bundle,
610
+ options,
611
+ quantity
612
+ };
613
+ if (date) {
614
+ addItemParams.date = date;
615
+ }
616
+ if (account) {
617
+ addItemParams.account = account;
618
+ }
619
+ this.addProductCheck({ date });
620
+ this.store.cart.addItem(addItemParams);
621
+ }
622
+ /**
623
+ * 添加完购物车以后做的一些检测,比如日期是否在同一天
624
+ *
625
+ * @param {({ date?: { startTime: string; endTime: string } | null })} { date }
626
+ * @memberof BookingByStepImpl
627
+ */
628
+ addProductCheck({
629
+ date
630
+ }) {
631
+ if (date) {
632
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
633
+ const cartItemsByDate = cartItems.filter(
634
+ (n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
635
+ );
636
+ if (cartItemsByDate.length) {
637
+ cartItemsByDate.forEach((n) => {
638
+ this.store.cart.removeItem(n._id);
639
+ });
640
+ }
641
+ }
642
+ }
643
+ beforeUpdateCart(params, targetCartItem) {
639
644
  if (params.resources) {
640
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
641
- capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
642
- product_bundle: targetCartItem._origin.product.product_bundle
643
- });
644
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
645
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(targetCartItem);
645
646
  params.resources = params.resources.map((n) => {
646
647
  n.capacity = currentCapacity || 1;
647
- currentResourcesCapacityMap[n.id] = currentCapacity;
648
- (0, import_resources.checkSubResourcesCapacity)(n);
648
+ (0, import_capacity.checkSubResourcesCapacity)(n);
649
649
  return n;
650
650
  });
651
651
  }
652
+ }
653
+ // 更新购物车
654
+ updateCart(params) {
655
+ const targetCartItem = this.store.cart.getItem(params._id);
656
+ if (!targetCartItem) {
657
+ throw new Error(`没有找到${params._id}购物车商品`);
658
+ }
659
+ this.beforeUpdateCart(params, targetCartItem);
652
660
  this.store.cart.updateItem(params);
661
+ this.updateCartCheck(params, targetCartItem);
662
+ }
663
+ /**
664
+ * 更新购物车以后的一些操作,比如检测资源是否重复,检测资源容量是否足够
665
+ *
666
+ * @param {IUpdateItemParams} params
667
+ * @param {CartItem} targetCartItem
668
+ * @return {*}
669
+ * @memberof BookingByStepImpl
670
+ */
671
+ updateCartCheck(params, targetCartItem) {
672
+ var _a;
653
673
  if (this.otherParams.isRetailTemplate) {
654
674
  return;
655
675
  }
676
+ let currentResourcesCapacityMap = {};
677
+ (_a = params.resources) == null ? void 0 : _a.forEach((n) => {
678
+ currentResourcesCapacityMap[n.id] = n.capacity;
679
+ });
656
680
  const allOriginResources = [];
657
681
  const dateRange = this.store.date.getDateRange();
658
682
  if (dateRange == null ? void 0 : dateRange.length) {
@@ -673,50 +697,31 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
673
697
  cartItems.forEach((item) => {
674
698
  var _a2;
675
699
  if (item._id !== targetCartItem._id) {
700
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
676
701
  const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
677
- const sameFormIdResources = targetCartItem._origin.resources.filter((n) => n.form_id === m.form_id);
702
+ const sameFormIdResources = (0, import_resources.filterResourcesByFormItem)(
703
+ targetCartItem._origin.resources,
704
+ m.form_id
705
+ );
678
706
  if (!(sameFormIdResources == null ? void 0 : sameFormIdResources.length)) {
679
707
  return true;
680
708
  }
681
709
  return !sameFormIdResources.some((targetRes) => {
682
- var _a3, _b, _c;
683
710
  if (targetRes.resourceType !== "single") {
684
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
685
- capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
686
- product_bundle: item._origin.product.product_bundle
687
- });
688
- const currentCapacity = (0, import_resources.getSumCapacity)({
689
- capacity: formatCapacity
690
- });
691
711
  const originResource = allOriginResources.find(
692
712
  (n) => n.id === targetRes.id
693
713
  );
694
- if (currentResourcesCapacityMap[m.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
695
- return true;
696
- }
697
- currentResourcesCapacityMap[m.id] += currentCapacity;
698
- return false;
714
+ const canUse = (0, import_capacity.checkResourceCanUseByCapacity)(
715
+ currentResourcesCapacityMap[m.id],
716
+ currentCapacity,
717
+ originResource == null ? void 0 : originResource.capacity
718
+ );
719
+ if (canUse)
720
+ currentResourcesCapacityMap[m.id] += currentCapacity;
721
+ return !canUse;
699
722
  }
700
723
  if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
701
- if (targetRes.id === m.id)
702
- return true;
703
- if (((_b = targetRes.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && // 如果现在选择的是组合资源,需要判断
704
- // 1、当前其他购物车里是否选了当前组合资源的子资源
705
- // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
706
- (targetRes.metadata.combined_resource.resource_ids.includes(
707
- m.id
708
- ) || targetRes.metadata.combined_resource.resource_ids.some(
709
- (n) => {
710
- return m.metadata.combined_resource.resource_ids.includes(
711
- n
712
- );
713
- }
714
- )))
715
- return true;
716
- if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(
717
- targetRes.id
718
- ))
719
- return true;
724
+ return (0, import_resources.checkTwoResourcesIntersection)(targetRes, m);
720
725
  }
721
726
  return false;
722
727
  });
@@ -813,8 +818,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
813
818
  const resources = [];
814
819
  if (dateRange == null ? void 0 : dateRange.length) {
815
820
  dateRange.forEach((n) => {
816
- if (n.resource)
817
- resources.push(...n.resource);
821
+ resources.push(...this.store.date.getResourcesListByDate(n.date) || []);
818
822
  });
819
823
  }
820
824
  if (!resources.length) {
@@ -828,14 +832,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
828
832
  const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
829
833
  const arr = [];
830
834
  cartItems.forEach((cartItem) => {
831
- var _a, _b, _c, _d, _e, _f, _g;
835
+ var _a, _b, _c, _d, _e, _f;
832
836
  let selectedResources = [];
833
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
834
- capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
835
- product_bundle: cartItem._origin.product.product_bundle
836
- });
837
+ const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
837
838
  cartItem._origin.metadata.capacity = formatCapacity;
838
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
839
839
  if (cartItem.holder_id) {
840
840
  selectedResources = (0, import_resources.getOthersSelectedResources)(
841
841
  cartItems,
@@ -851,7 +851,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
851
851
  }
852
852
  const productResources = (0, import_resources.getResourcesByProduct)(
853
853
  resourcesMap,
854
- ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
854
+ ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
855
855
  selectedResources,
856
856
  currentCapacity
857
857
  );
@@ -864,20 +864,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
864
864
  );
865
865
  const resourcesUseableMap = {};
866
866
  productResources.forEach((n) => {
867
- n.renderList = n.renderList.sort((a, b) => {
868
- var _a2, _b2, _c2, _d2;
869
- const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
870
- const bIsCombined = ((_d2 = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d2.status) === 1;
871
- if (aIsCombined && !bIsCombined)
872
- return 1;
873
- if (!aIsCombined && bIsCombined)
874
- return -1;
875
- return 0;
876
- });
867
+ n.renderList = (0, import_resources.sortCombinedResources)(n.renderList);
877
868
  n.renderList = n.renderList.filter((m) => {
878
- const mTimes = m.times.filter((n2) => {
879
- 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));
880
- });
869
+ const mTimes = (0, import_timeslots.filterConditionTimeSlots)(
870
+ m.times,
871
+ startTime,
872
+ endTime
873
+ );
881
874
  if (mTimes.length === 0) {
882
875
  return false;
883
876
  }
@@ -907,8 +900,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
907
900
  });
908
901
  });
909
902
  } else {
910
- const hasFlexibleDuration = ((_e = (_d = cartItem._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.type) === "flexible";
911
- const operating_day_boundary = (_g = (_f = this.shopStore.get("core")) == null ? void 0 : _f.core) == null ? void 0 : _g.operating_day_boundary;
903
+ const hasFlexibleDuration = ((_d = (_c = cartItem._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) === "flexible";
904
+ const operating_day_boundary = (_f = (_e = this.shopStore.get("core")) == null ? void 0 : _e.core) == null ? void 0 : _f.operating_day_boundary;
912
905
  productResources.forEach((item) => {
913
906
  item.renderList = item.renderList.filter((n) => {
914
907
  var _a2, _b2, _c2;
@@ -941,138 +934,28 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
941
934
  });
942
935
  return arr;
943
936
  }
944
- // 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
937
+ /**
938
+ * 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
939
+ *
940
+ * @return {*}
941
+ * @memberof BookingByStepImpl
942
+ */
945
943
  checkResourceListForDate() {
946
- const dateRange = this.store.date.getDateRange();
947
- const resources = [];
948
- if (dateRange == null ? void 0 : dateRange.length) {
949
- dateRange.forEach((n) => {
950
- if (n.resource)
951
- resources.push(...n.resource);
952
- });
953
- }
954
- if (!resources.length) {
955
- const dateList = this.store.date.getDateList();
956
- dateList.forEach((n) => {
957
- if (n.resource)
958
- resources.push(...n.resource);
959
- });
960
- }
961
- const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
962
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
963
- const arr = [];
964
- cartItems.forEach((cartItem) => {
965
- var _a, _b, _c;
966
- let selectedResources = [];
967
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
968
- capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
969
- product_bundle: cartItem._origin.product.product_bundle
970
- });
971
- cartItem._origin.metadata.capacity = formatCapacity;
972
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
973
- if (cartItem.holder_id) {
974
- selectedResources = (0, import_resources.getOthersSelectedResources)(
975
- cartItems,
976
- cartItem.holder_id,
977
- resourcesMap
978
- );
979
- } else {
980
- selectedResources = (0, import_resources.getOthersCartSelectedResources)(
981
- cartItems,
982
- cartItem._id,
983
- resourcesMap
984
- );
985
- }
986
- const productResources = (0, import_resources.getResourcesByProduct)(
987
- resourcesMap,
988
- ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
989
- selectedResources,
990
- currentCapacity
991
- );
992
- if (cartItem._origin.start_time) {
993
- const startTime = (0, import_dayjs.default)(
994
- `${cartItem._origin.start_date} ${cartItem._origin.start_time}`
995
- );
996
- const endTime = (0, import_dayjs.default)(
997
- `${cartItem._origin.end_date} ${cartItem._origin.end_time}`
998
- );
999
- const resourcesUseableMap = {};
1000
- productResources.forEach((n) => {
1001
- n.renderList = n.renderList.sort((a, b) => {
1002
- var _a2, _b2, _c2, _d;
1003
- const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
1004
- const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
1005
- if (aIsCombined && !bIsCombined)
1006
- return 1;
1007
- if (!aIsCombined && bIsCombined)
1008
- return -1;
1009
- return 0;
1010
- });
1011
- n.renderList = n.renderList.filter((m) => {
1012
- const mTimes = m.times.filter((n2) => {
1013
- 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));
1014
- });
1015
- if (mTimes.length === 0) {
1016
- return false;
1017
- }
1018
- const canUseArr = mTimes.map((item) => {
1019
- var _a2;
1020
- const res = (0, import_resources.getIsUsableByTimeItem)({
1021
- timeSlice: {
1022
- start_time: startTime.format("HH:mm"),
1023
- end_time: endTime.format("HH:mm"),
1024
- start_at: startTime,
1025
- end_at: endTime
1026
- },
1027
- time: item,
1028
- resource: m,
1029
- currentCount: currentCapacity || 0,
1030
- resourcesUseableMap,
1031
- cut_off_time: (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.cut_off_time
1032
- });
1033
- if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
1034
- resourcesUseableMap[m.id] = res.usable;
1035
- }
1036
- return res.usable;
1037
- });
1038
- if (m.onlyComputed)
1039
- return false;
1040
- return !canUseArr.some((n2) => n2 === false);
1041
- });
1042
- });
1043
- } else {
1044
- productResources.forEach((item) => {
1045
- item.renderList = item.renderList.filter((n) => {
1046
- var _a2, _b2;
1047
- const recordCount = n.capacity || 0;
1048
- if (n.onlyComputed)
1049
- return false;
1050
- const timeSlots = (0, import_resources.getTimeSlicesByResource)({
1051
- resource: n,
1052
- duration: ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 10,
1053
- split: 10,
1054
- currentDate: dateRange[0].date
1055
- });
1056
- return recordCount >= currentCapacity && timeSlots.length > 0;
1057
- });
1058
- });
1059
- }
1060
- arr.push({
1061
- id: cartItem.id,
1062
- // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1063
- _id: cartItem._id,
1064
- // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1065
- productResources
1066
- });
1067
- });
1068
- const hasResource = arr.every(
1069
- (n) => n.productResources.every((m) => m.renderList.length > 0)
944
+ const resourcesList = this.getResourcesList();
945
+ const hasResource = resourcesList.every(
946
+ (item) => item.resources.every((resource) => resource.renderList.length > 0)
1070
947
  );
1071
948
  return hasResource;
1072
949
  }
1073
- // 给单个购物车里的商品获取资源列表
950
+ /**
951
+ * 给单个购物车里的商品获取资源列表,给 UI 用的
952
+ *
953
+ * @param {(string | number)} id
954
+ * @return {*}
955
+ * @memberof BookingByStepImpl
956
+ */
1074
957
  getResourcesListByCartItem(id) {
1075
- var _a, _b, _c;
958
+ var _a, _b;
1076
959
  const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1077
960
  const dateRange = this.store.date.getDateRange();
1078
961
  const resources = [];
@@ -1086,11 +969,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1086
969
  throw new Error(`没有找到${id}购物车商品`);
1087
970
  }
1088
971
  let selectedResources = [];
1089
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
1090
- capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
1091
- product_bundle: targetCartItem._origin.product.product_bundle
1092
- });
1093
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
972
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(targetCartItem);
1094
973
  if (targetCartItem.holder_id) {
1095
974
  selectedResources = (0, import_resources.getOthersSelectedResources)(
1096
975
  cartItems,
@@ -1106,7 +985,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1106
985
  }
1107
986
  const productResources = (0, import_resources.getResourcesByProduct)(
1108
987
  resourcesMap,
1109
- ((_c = (_b = targetCartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
988
+ ((_b = (_a = targetCartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
1110
989
  selectedResources,
1111
990
  currentCapacity
1112
991
  );
@@ -1131,21 +1010,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1131
1010
  };
1132
1011
  }
1133
1012
  }
1134
- // 通过资源列表和指定的资源 id,获取指定资源的时间切片
1135
- getResourceTimeSlot({
1136
- product,
1137
- resources,
1138
- currentResourceId
1139
- }) {
1140
- const dateRange = this.store.date.getDateRange();
1141
- const timeSlots = (0, import_resources.getTimeSlicesByResource)({
1142
- resource: resources.find((n) => n.id === currentResourceId),
1143
- duration: product.duration.value,
1144
- split: 10,
1145
- currentDate: dateRange[0].date
1146
- });
1147
- return timeSlots;
1148
- }
1149
1013
  // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
1150
1014
  autoSelectAccountResources({
1151
1015
  cartItem,
@@ -1301,17 +1165,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1301
1165
  const accountList = this.store.accountList.getAccounts();
1302
1166
  const selectForCartResources = (cartItems2) => {
1303
1167
  let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
1304
- const hasFlexibleProduct = cartItems2.some((item) => {
1305
- var _a2, _b;
1306
- return ((_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b.type) === "flexible";
1307
- });
1168
+ const hasFlexibleProduct = cartItems2.some(
1169
+ (item) => {
1170
+ var _a2, _b;
1171
+ return ((_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b.type) === "flexible";
1172
+ }
1173
+ );
1308
1174
  cartItems2.forEach((item, index) => {
1309
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1310
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
1311
- capacity: (_a2 = item._productOrigin) == null ? void 0 : _a2.capacity,
1312
- product_bundle: item._origin.product.product_bundle
1313
- });
1314
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
1175
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1176
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
1315
1177
  if (item._origin.start_time && !(timeSlots == null ? void 0 : timeSlots.start_time)) {
1316
1178
  recordTimeSlots = {
1317
1179
  start_time: item._origin.start_time,
@@ -1321,17 +1183,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1321
1183
  };
1322
1184
  }
1323
1185
  if (recordTimeSlots) {
1324
- const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find(
1186
+ const currentResourceConfig = (_c = (_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.find(
1325
1187
  (n) => n.code === resources_code
1326
1188
  );
1327
- const resourceBookingType = (currentResourceConfig == null ? void 0 : currentResourceConfig.type) || "single";
1328
- if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((_e = item._productOrigin) == null ? void 0 : _e.duration) && !hasFlexibleProduct) {
1189
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((_d = item._productOrigin) == null ? void 0 : _d.duration) && !hasFlexibleProduct) {
1329
1190
  let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
1330
- ((_g = (_f = item._productOrigin) == null ? void 0 : _f.duration) == null ? void 0 : _g.value) || 10,
1191
+ ((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) || 10,
1331
1192
  "minutes"
1332
1193
  );
1333
1194
  let end_at = start_at.add(
1334
- ((_i = (_h = item._productOrigin) == null ? void 0 : _h.duration) == null ? void 0 : _i.value) || 10,
1195
+ ((_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.value) || 10,
1335
1196
  "minutes"
1336
1197
  );
1337
1198
  recordTimeSlots = {
@@ -1364,7 +1225,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1364
1225
  });
1365
1226
  }
1366
1227
  res.selectedResource.capacity = currentCapacity;
1367
- (0, import_resources.checkSubResourcesCapacity)(res.selectedResource);
1228
+ (0, import_capacity.checkSubResourcesCapacity)(res.selectedResource);
1368
1229
  this.store.cart.updateItem({
1369
1230
  _id: item._id,
1370
1231
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
@@ -1385,7 +1246,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1385
1246
  const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1386
1247
  let selectedResources = [];
1387
1248
  const resources2 = (0, import_lodash_es.cloneDeep)(
1388
- ((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || []
1249
+ ((_j = (_i = item._productOrigin) == null ? void 0 : _i.product_resource) == null ? void 0 : _j.resources) || []
1389
1250
  );
1390
1251
  const currentResourcesRenderList = [];
1391
1252
  resources2.forEach((n) => {
@@ -1433,11 +1294,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1433
1294
  return recordCount >= currentCapacity;
1434
1295
  });
1435
1296
  });
1436
- const targetRenderList = (_l = productResources.find(
1297
+ const targetRenderList = (_k = productResources.find(
1437
1298
  (n) => n.code === resources_code
1438
- )) == null ? void 0 : _l.renderList;
1299
+ )) == null ? void 0 : _k.renderList;
1439
1300
  if (targetRenderList && targetRenderList.length > 0) {
1440
- if ((_m = item._origin.resources) == null ? void 0 : _m.some(
1301
+ if ((_l = item._origin.resources) == null ? void 0 : _l.some(
1441
1302
  (n) => n.form_id === targetRenderList[0].form_id
1442
1303
  )) {
1443
1304
  return;
@@ -1449,7 +1310,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1449
1310
  });
1450
1311
  const targetResource = fastestResource || targetRenderList[0];
1451
1312
  targetResource.capacity = currentCapacity;
1452
- (0, import_resources.checkSubResourcesCapacity)(targetResource);
1313
+ (0, import_capacity.checkSubResourcesCapacity)(targetResource);
1453
1314
  if (!selectResourcesMap[targetResource.id]) {
1454
1315
  selectResourcesMap[targetResource.id] = currentCapacity;
1455
1316
  } else {
@@ -1571,10 +1432,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1571
1432
  ];
1572
1433
  }
1573
1434
  const resourcesUseableMap = {};
1574
- const hasFlexibleDuration = cartItems.some((item) => {
1575
- var _a2, _b2;
1576
- return ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.type) === "flexible";
1577
- });
1435
+ const hasFlexibleDuration = cartItems.some(
1436
+ (item) => {
1437
+ var _a2, _b2;
1438
+ return ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.type) === "flexible";
1439
+ }
1440
+ );
1578
1441
  const operating_day_boundary = (_h = (_g = this.shopStore.get("core")) == null ? void 0 : _g.core) == null ? void 0 : _h.operating_day_boundary;
1579
1442
  const timeSlots = (0, import_resources.getTimeSlicesByResources)({
1580
1443
  resourceIds,
@@ -1593,7 +1456,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1593
1456
  submitTimeSlot(timeSlots) {
1594
1457
  var _a, _b;
1595
1458
  const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1596
- const allResources = this.store.date.getResourcesListByDate(timeSlots.start_at.format("YYYY-MM-DD"));
1459
+ const allResources = this.store.date.getResourcesListByDate(
1460
+ timeSlots.start_at.format("YYYY-MM-DD")
1461
+ );
1597
1462
  const itemsByAccount = cartItems.reduce(
1598
1463
  (acc, item) => {
1599
1464
  const holderId = item.holder_id;
@@ -1619,13 +1484,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1619
1484
  value: 10
1620
1485
  };
1621
1486
  resource.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1622
- const targetResourceTimes = (_c = allResources == null ? void 0 : allResources.find((n) => n.id === resource.id)) == null ? void 0 : _c.times;
1623
- const resourcesEndTime = targetResourceTimes.reduce((acc, curr) => {
1624
- return (0, import_dayjs.default)(curr.end_at).isBefore((0, import_dayjs.default)(acc.end_at)) ? curr : acc;
1625
- }, targetResourceTimes[0]);
1626
- const resourceDate = (0, import_dayjs.default)(resourcesEndTime.end_at).format("YYYY-MM-DD");
1487
+ const targetResourceTimes = (_c = allResources == null ? void 0 : allResources.find(
1488
+ (n) => n.id === resource.id
1489
+ )) == null ? void 0 : _c.times;
1490
+ const resourcesEndTime = targetResourceTimes.reduce(
1491
+ (acc, curr) => {
1492
+ return (0, import_dayjs.default)(curr.end_at).isBefore((0, import_dayjs.default)(acc.end_at)) ? curr : acc;
1493
+ },
1494
+ targetResourceTimes[0]
1495
+ );
1496
+ const resourceDate = (0, import_dayjs.default)(resourcesEndTime.end_at).format(
1497
+ "YYYY-MM-DD"
1498
+ );
1627
1499
  const operatingBoundaryDateTime = `${resourceDate} ${operating_day_boundary.type === "start_time" ? "23:59" : operating_day_boundary.time}`;
1628
- const endTime = (0, import_dayjs.default)(resourcesEndTime.end_at).isBefore((0, import_dayjs.default)(operatingBoundaryDateTime)) ? resourcesEndTime.end_at : operatingBoundaryDateTime;
1500
+ const endTime = (0, import_dayjs.default)(resourcesEndTime.end_at).isBefore(
1501
+ (0, import_dayjs.default)(operatingBoundaryDateTime)
1502
+ ) ? resourcesEndTime.end_at : operatingBoundaryDateTime;
1629
1503
  let formattedEndTime;
1630
1504
  if (typeof endTime === "string" && endTime.includes(":") && !endTime.includes(" ") && !endTime.includes("T")) {
1631
1505
  const currentDate = timeSlots.start_at.format("YYYY-MM-DD");
@@ -1636,10 +1510,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1636
1510
  resource.endTime = formattedEndTime.format("YYYY-MM-DD HH:mm");
1637
1511
  } else {
1638
1512
  resource.startTime = currentStartTime;
1639
- resource.endTime = (0, import_dayjs.default)(currentStartTime).add(
1640
- ((_e = (_d = item._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.value) || 10,
1641
- "minutes"
1642
- ).format("YYYY-MM-DD HH:mm");
1513
+ 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");
1643
1514
  }
1644
1515
  });
1645
1516
  this.store.cart.updateItem({
@@ -1685,10 +1556,21 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1685
1556
  if (targetProduct) {
1686
1557
  const targetProductData = targetProduct.getData();
1687
1558
  this.store.currentProduct = targetProduct;
1688
- const newScheduleArr = this.getScheduleDataByIds(
1689
- targetProductData["schedule.ids"]
1690
- );
1691
- targetProduct.setOtherParams("schedule", newScheduleArr);
1559
+ if (targetProductData["schedule.ids"]) {
1560
+ const newScheduleArr = this.getScheduleDataByIds(
1561
+ targetProductData["schedule.ids"]
1562
+ );
1563
+ targetProduct.setOtherParams("schedule", newScheduleArr);
1564
+ } else if (targetProductData.duration) {
1565
+ const dateRange = this.store.date.getDateRange();
1566
+ if (!dateRange.length)
1567
+ return;
1568
+ this.getAvailableDate({
1569
+ startDate: dateRange[0].date,
1570
+ endDate: dateRange[dateRange.length - 1].date,
1571
+ products: [targetProductData]
1572
+ });
1573
+ }
1692
1574
  }
1693
1575
  }
1694
1576
  closeProductDetail() {
@@ -1745,7 +1627,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1745
1627
  return -1;
1746
1628
  return 0;
1747
1629
  });
1748
- 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;
1630
+ const firstEnabledResourceId = (_f = (_e = (_d = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.find(
1631
+ (n) => n.status === 1
1632
+ )) == null ? void 0 : _f.id;
1749
1633
  const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1750
1634
  const resourcesUseableMap = {};
1751
1635
  let count = 0;
@@ -1781,7 +1665,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1781
1665
  }
1782
1666
  currentResourcesTimeSlotCanUsedArr.push(res.usable);
1783
1667
  });
1784
- if (!currentResourcesTimeSlotCanUsedArr.some((n) => n === false) && m.form_id === firstEnabledResourceId) {
1668
+ if (!currentResourcesTimeSlotCanUsedArr.some(
1669
+ (n) => n === false
1670
+ ) && // 只统计第一种资源的容量和 left
1671
+ m.form_id === firstEnabledResourceId) {
1785
1672
  if (currentResourcesCount >= count) {
1786
1673
  count = currentResourcesCount;
1787
1674
  }
@@ -1803,60 +1690,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1803
1690
  });
1804
1691
  return formatScheduleTimeSlots;
1805
1692
  }
1806
- addProductToCart({
1807
- product,
1808
- date,
1809
- account
1810
- }) {
1811
- const { bundle, options, origin, product_variant_id, rowKey, quantity = 1 } = product || {};
1812
- const productData = { ...origin, product_variant_id, rowKey };
1813
- if (!account) {
1814
- const activeAccount = this.getActiveAccount();
1815
- if (activeAccount) {
1816
- account = activeAccount;
1817
- }
1818
- }
1819
- if (rowKey) {
1820
- const cartItems = this.store.cart.getItems();
1821
- const targetCartItem = cartItems.find((n) => {
1822
- var _a;
1823
- return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey;
1824
- });
1825
- if (targetCartItem && (0, import_utils4.isNormalProduct)(targetCartItem._productOrigin)) {
1826
- this.store.cart.updateItem({
1827
- _id: targetCartItem._id,
1828
- product: {
1829
- ...targetCartItem._productOrigin,
1830
- quantity: (targetCartItem.num || 1) + quantity
1831
- },
1832
- bundle: targetCartItem._bundleOrigin,
1833
- options: targetCartItem._optionsOrigin,
1834
- quantity: (targetCartItem.num || 1) + quantity
1835
- });
1836
- this.core.effects.emit(`${this.store.cart.name}:onUpdateCartItemNums`, {});
1837
- return;
1838
- }
1839
- }
1840
- this.store.cart.addItem({
1841
- product: productData,
1842
- date,
1843
- account,
1844
- bundle,
1845
- options,
1846
- quantity
1847
- });
1848
- if (date) {
1849
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1850
- const cartItemsByDate = cartItems.filter(
1851
- (n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
1852
- );
1853
- if (cartItemsByDate.length) {
1854
- cartItemsByDate.forEach((n) => {
1855
- this.store.cart.removeItem(n._id);
1856
- });
1857
- }
1858
- }
1859
- }
1860
1693
  setOtherData(key, value) {
1861
1694
  this.otherData[key] = value;
1862
1695
  this.checkSaveCache({
@@ -1885,7 +1718,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1885
1718
  * @memberof BookingByStepImpl
1886
1719
  */
1887
1720
  getResourcesByCartItemAndCode(cartItemId, resourceCode) {
1888
- var _a, _b, _c;
1721
+ var _a, _b;
1889
1722
  const dateRange = this.store.date.getDateRange();
1890
1723
  const resources = [];
1891
1724
  if (dateRange == null ? void 0 : dateRange.length) {
@@ -1907,12 +1740,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1907
1740
  if (!cartItem)
1908
1741
  return [];
1909
1742
  let selectedResources = [];
1910
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
1911
- capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
1912
- product_bundle: cartItem._origin.product.product_bundle
1913
- });
1743
+ const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
1914
1744
  cartItem._origin.metadata.capacity = formatCapacity;
1915
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
1916
1745
  if (cartItem.holder_id) {
1917
1746
  selectedResources = (0, import_resources.getOthersSelectedResources)(
1918
1747
  cartItems,
@@ -1928,7 +1757,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1928
1757
  }
1929
1758
  const productResources = (0, import_resources.getResourcesByProduct)(
1930
1759
  resourcesMap,
1931
- ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
1760
+ ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
1932
1761
  selectedResources,
1933
1762
  currentCapacity
1934
1763
  );
@@ -1947,9 +1776,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1947
1776
  const resourcesUseableMap = {};
1948
1777
  targetResource.renderList = targetResource.renderList.sort(
1949
1778
  (a, b) => {
1950
- var _a2, _b2, _c2, _d;
1779
+ var _a2, _b2, _c, _d;
1951
1780
  const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
1952
- const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
1781
+ const bIsCombined = ((_d = (_c = b.metadata) == null ? void 0 : _c.combined_resource) == null ? void 0 : _d.status) === 1;
1953
1782
  if (aIsCombined && !bIsCombined)
1954
1783
  return 1;
1955
1784
  if (!aIsCombined && bIsCombined)
@@ -2036,56 +1865,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2036
1865
  }
2037
1866
  return results;
2038
1867
  }
2039
- async getAvailableDateForSession(params = {}) {
2040
- let { startDate, endDate, type } = params;
2041
- 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"))) {
2042
- startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
2043
- }
2044
- endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
2045
- let tempProducts = [];
2046
- if (this.store.currentProduct) {
2047
- tempProducts = [
2048
- {
2049
- ...this.store.currentProduct.getData(),
2050
- _schedule: this.store.currentProduct.getOtherParams()["schedule"]
2051
- }
2052
- ];
2053
- }
2054
- const { resourceIds, rules, resourcesMap } = (0, import_products.getAvailableProductResources)(tempProducts) || {};
2055
- this.otherParams.currentResourcesMap = resourcesMap;
2056
- const res = await this.store.date.getResourceDates({
2057
- query: {
2058
- start_date: startDate || "",
2059
- end_date: endDate || "",
2060
- resource_ids: resourceIds
2061
- },
2062
- rules,
2063
- type
2064
- });
2065
- if (this.store.currentProduct) {
2066
- const dateListWithTimeSlots = await this.getTimeslotsScheduleByDateRange({
2067
- startDate: startDate || "",
2068
- endDate: endDate || ""
2069
- });
2070
- res.forEach((n) => {
2071
- if (!dateListWithTimeSlots[n.date]) {
2072
- n.status = "unavailable";
2073
- } else {
2074
- const allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(
2075
- (d) => d.count
2076
- );
2077
- if (!allTimeSlotsCanUse) {
2078
- n.status = "unavailable";
2079
- }
2080
- }
2081
- });
2082
- }
2083
- const firstAvailableDate = res.find((n) => n.status === "available");
2084
- return {
2085
- dateList: res,
2086
- firstAvailableDate
2087
- };
2088
- }
2089
1868
  async getAvailableDateForSessionOptimize(params = {}) {
2090
1869
  var _a, _b, _c, _d, _e, _f;
2091
1870
  let { startDate, endDate } = params;
@@ -2103,9 +1882,19 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2103
1882
  tempEndDate = endDate || "";
2104
1883
  }
2105
1884
  endDate = tempEndDate;
1885
+ const cache = (_a = this.store.currentProduct) == null ? void 0 : _a.getOtherParams()["timeSlotBySchedule"];
1886
+ if (cache) {
1887
+ 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")) {
1888
+ this.store.date.setDateList(cache.dateList);
1889
+ return {
1890
+ dateList: cache.dateList,
1891
+ firstAvailableDate: cache.firstAvailableDate
1892
+ };
1893
+ }
1894
+ }
2106
1895
  let tempProducts;
2107
- tempProducts = (_a = this.store.currentProduct) == null ? void 0 : _a.getData();
2108
- const schedule = (_b = this.store.currentProduct) == null ? void 0 : _b.getOtherParams()["schedule"];
1896
+ tempProducts = (_b = this.store.currentProduct) == null ? void 0 : _b.getData();
1897
+ const schedule = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["schedule"];
2109
1898
  const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
2110
1899
  schedule,
2111
1900
  startDate || "",
@@ -2119,16 +1908,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2119
1908
  resource_ids: tempResourceIds
2120
1909
  }
2121
1910
  });
2122
- const cache = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["timeSlotBySchedule"];
2123
- if (cache) {
2124
- 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")) {
2125
- this.store.date.setDateList(cache.dateList);
2126
- return {
2127
- dateList: cache.dateList,
2128
- firstAvailableDate: cache.firstAvailableDate
2129
- };
2130
- }
2131
- }
2132
1911
  let dates = [];
2133
1912
  let currentDate = (0, import_dayjs.default)(startDate);
2134
1913
  let firstAvailableDate = "";
@@ -2188,25 +1967,27 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2188
1967
  if (mTimes.length === 0) {
2189
1968
  return;
2190
1969
  }
2191
- const targetCanUseTimes = mTimes.some((childTiem) => {
2192
- const res2 = (0, import_resources.getIsUsableByTimeItem)({
2193
- timeSlice: {
2194
- start_time: item.start,
2195
- end_time: item.end,
2196
- start_at: (0, import_dayjs.default)(item.start),
2197
- end_at: (0, import_dayjs.default)(item.end)
2198
- },
2199
- time: childTiem,
2200
- resource: m,
2201
- currentCount: 1,
2202
- resourcesUseableMap,
2203
- cut_off_time: tempProducts == null ? void 0 : tempProducts.cut_off_time
2204
- });
2205
- if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res2.reason !== "capacityOnly") {
2206
- resourcesUseableMap[m.id] = res2.usable;
1970
+ const targetCanUseTimes = mTimes.some(
1971
+ (childTiem) => {
1972
+ const res2 = (0, import_resources.getIsUsableByTimeItem)({
1973
+ timeSlice: {
1974
+ start_time: item.start,
1975
+ end_time: item.end,
1976
+ start_at: (0, import_dayjs.default)(item.start),
1977
+ end_at: (0, import_dayjs.default)(item.end)
1978
+ },
1979
+ time: childTiem,
1980
+ resource: m,
1981
+ currentCount: 1,
1982
+ resourcesUseableMap,
1983
+ cut_off_time: tempProducts == null ? void 0 : tempProducts.cut_off_time
1984
+ });
1985
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res2.reason !== "capacityOnly") {
1986
+ resourcesUseableMap[m.id] = res2.usable;
1987
+ }
1988
+ return res2.usable && !m.onlyComputed;
2207
1989
  }
2208
- return res2.usable && !m.onlyComputed;
2209
- });
1990
+ );
2210
1991
  return targetCanUseTimes;
2211
1992
  });
2212
1993
  });