@pisell/pisellos 2.0.21 → 2.0.23

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.
@@ -232,8 +232,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
232
232
  _context2.next = 7;
233
233
  return this.request.post("/product/query", {
234
234
  open_quotation: 1,
235
- open_bundle: 1,
236
- extension_type: ['product_appointment', 'appointment_ticket', 'session_product', 'session_ticket'],
235
+ open_bundle: 0,
236
+ extension_type: ['product_appointment', 'appointment_ticket', 'session_product', 'session_ticket', 'normal'],
237
237
  with: ['category', 'collection', 'resourceRelation'],
238
238
  status: 'published',
239
239
  num: 500,
@@ -313,64 +313,62 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
313
313
  key: "updateQuotationPriceAndCart",
314
314
  value: function () {
315
315
  var _updateQuotationPriceAndCart = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(date) {
316
- var _this$otherParams3,
317
- _this3 = this;
318
- var dateRange, scheduleList, scheduleIds, cartItems, _iterator, _step, _loop;
316
+ var _this3 = this;
317
+ var cartItems, userPlugin, customer_id, _userPlugin$get2, res, _iterator, _step, _loop;
319
318
  return _regeneratorRuntime().wrap(function _callee4$(_context5) {
320
319
  while (1) switch (_context5.prev = _context5.next) {
321
320
  case 0:
322
- dateRange = this.store.date.getDateRange();
323
- scheduleList = this.store.schedule.getAvailabilityScheduleDateList() || [];
324
- scheduleIds = [];
325
- if (dateRange && dateRange.length) {
326
- scheduleIds = scheduleList.filter(function (n) {
327
- return n.date === dateRange[0].date;
328
- }).flatMap(function (n) {
329
- return n.schedule_id;
330
- });
331
- } else {
332
- scheduleIds = scheduleList.filter(function (n) {
333
- return n.date === date;
334
- }).flatMap(function (n) {
335
- return n.schedule_id;
336
- });
337
- }
338
- _context5.next = 6;
339
- return this.loadProducts(_objectSpread(_objectSpread({}, (_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.productModuleParams), {}, {
340
- scheduleIds: scheduleIds,
341
- schedule_date: date
342
- }));
343
- case 6:
344
321
  // 更新完商品数据以后,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
345
322
  cartItems = this.store.cart.getItems();
346
323
  if (!cartItems.length) {
347
324
  _context5.next = 25;
348
325
  break;
349
326
  }
327
+ userPlugin = this.core.getPlugin('user');
328
+ customer_id = undefined;
329
+ try {
330
+ customer_id = userPlugin === null || userPlugin === void 0 || (_userPlugin$get2 = userPlugin.get()) === null || _userPlugin$get2 === void 0 ? void 0 : _userPlugin$get2.id;
331
+ } catch (error) {
332
+ console.error(error);
333
+ }
334
+ _context5.next = 7;
335
+ return this.store.products.loadProductsPrice({
336
+ ids: cartItems.map(function (n) {
337
+ return n.id;
338
+ }),
339
+ schedule_date: date,
340
+ customer_id: customer_id
341
+ });
342
+ case 7:
343
+ res = _context5.sent;
350
344
  _iterator = _createForOfIteratorHelper(cartItems);
351
345
  _context5.prev = 9;
352
346
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
353
347
  var _bundle;
354
- var item, targetProduct, productInfo, bundle;
348
+ var item, targetProduct, cartProduct, productInfo, bundle;
355
349
  return _regeneratorRuntime().wrap(function _loop$(_context4) {
356
350
  while (1) switch (_context4.prev = _context4.next) {
357
351
  case 0:
358
352
  item = _step.value;
359
- _context4.next = 3;
353
+ targetProduct = res.find(function (n) {
354
+ return n.id === item.id;
355
+ });
356
+ _context4.next = 4;
360
357
  return _this3.store.products.getProduct(item.id);
361
- case 3:
362
- targetProduct = _context4.sent;
363
- productInfo = cloneDeep(targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData());
358
+ case 4:
359
+ cartProduct = _context4.sent;
360
+ productInfo = cartProduct === null || cartProduct === void 0 ? void 0 : cartProduct.getData();
364
361
  bundle = item._bundleOrigin;
362
+ productInfo.price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.price;
363
+ productInfo.base_price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.base_price;
365
364
  bundle = (_bundle = bundle) === null || _bundle === void 0 ? void 0 : _bundle.map(function (n) {
366
- var _productInfo$bundle;
367
- // 尝试到新的 productInfo 里找对应的 bundleitem
368
- // 然后更新 bundle 的价格
369
- var targetBundle = productInfo === null || productInfo === void 0 || (_productInfo$bundle = productInfo.bundle) === null || _productInfo$bundle === void 0 ? void 0 : _productInfo$bundle.find(function (m) {
370
- return m.group_id === n.id;
365
+ var _targetProduct$bundle;
366
+ // 更新 bundle 的价格
367
+ var targetBundle = targetProduct === null || targetProduct === void 0 || (_targetProduct$bundle = targetProduct.bundle_group) === null || _targetProduct$bundle === void 0 ? void 0 : _targetProduct$bundle.find(function (m) {
368
+ return m.id === n.group_id;
371
369
  });
372
370
  if (targetBundle) {
373
- var targetBundleItem = targetBundle.items.find(function (m) {
371
+ var targetBundleItem = targetBundle.bundle_item.find(function (m) {
374
372
  return m.id === n.id;
375
373
  });
376
374
  if (targetBundleItem) {
@@ -387,7 +385,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
387
385
  product: productInfo,
388
386
  bundle: bundle
389
387
  });
390
- case 8:
388
+ case 11:
391
389
  case "end":
392
390
  return _context4.stop();
393
391
  }
@@ -1062,40 +1060,44 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1062
1060
  key: "submitOrder",
1063
1061
  value: function () {
1064
1062
  var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1065
- var cartItems, newCartItems;
1063
+ var cartItems, newCartItems, type;
1066
1064
  return _regeneratorRuntime().wrap(function _callee21$(_context22) {
1067
1065
  while (1) switch (_context22.prev = _context22.next) {
1068
1066
  case 0:
1069
1067
  cartItems = this.store.cart.getItems();
1070
1068
  newCartItems = cloneDeep(cartItems); // 先整个临时的逻辑,把购物车里所有商品的资源给他格式化一下
1071
1069
  newCartItems.forEach(function (item) {
1072
- var _item$_productOrigin, _item$_origin;
1073
- item._origin.resources = item._origin.resources.map(function (n) {
1074
- var newResourcesItem = cloneDeep(n);
1075
- delete newResourcesItem.id;
1076
- delete newResourcesItem.main_field;
1077
- delete newResourcesItem.resourceType;
1078
- return _objectSpread({}, newResourcesItem);
1079
- });
1080
- var formatCapacity = formatDefaultCapacitys({
1081
- capacity: (_item$_productOrigin = item._productOrigin) === null || _item$_productOrigin === void 0 ? void 0 : _item$_productOrigin.capacity,
1082
- product_bundle: item._origin.product.product_bundle
1083
- });
1084
- var currentCapacity = getSumCapacity({
1085
- capacity: formatCapacity
1086
- });
1087
- if (!((_item$_origin = item._origin) !== null && _item$_origin !== void 0 && _item$_origin.metadata)) {
1088
- item._origin.metadata = {};
1070
+ if (item._origin.resources && item._origin.resources.length) {
1071
+ var _item$_productOrigin, _item$_origin;
1072
+ item._origin.resources = item._origin.resources.map(function (n) {
1073
+ var newResourcesItem = cloneDeep(n);
1074
+ delete newResourcesItem.id;
1075
+ delete newResourcesItem.main_field;
1076
+ delete newResourcesItem.resourceType;
1077
+ return _objectSpread({}, newResourcesItem);
1078
+ });
1079
+ var formatCapacity = formatDefaultCapacitys({
1080
+ capacity: (_item$_productOrigin = item._productOrigin) === null || _item$_productOrigin === void 0 ? void 0 : _item$_productOrigin.capacity,
1081
+ product_bundle: item._origin.product.product_bundle
1082
+ });
1083
+ var currentCapacity = getSumCapacity({
1084
+ capacity: formatCapacity
1085
+ });
1086
+ if (!((_item$_origin = item._origin) !== null && _item$_origin !== void 0 && _item$_origin.metadata)) {
1087
+ item._origin.metadata = {};
1088
+ }
1089
+ item._origin.metadata.capacity = formatCapacity;
1090
+ item._origin.number = currentCapacity;
1089
1091
  }
1090
- item._origin.metadata.capacity = formatCapacity;
1091
- item._origin.number = currentCapacity;
1092
1092
  });
1093
+ type = this.otherParams.isRetailTemplate ? 'virtual' : 'appointment_booking';
1093
1094
  return _context22.abrupt("return", this.store.order.submitOrder({
1094
1095
  query: {
1095
- cartItems: newCartItems
1096
+ cartItems: newCartItems,
1097
+ type: type
1096
1098
  }
1097
1099
  }));
1098
- case 4:
1100
+ case 5:
1099
1101
  case "end":
1100
1102
  return _context22.stop();
1101
1103
  }
@@ -1213,6 +1215,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1213
1215
  });
1214
1216
  }
1215
1217
  this.store.cart.updateItem(params);
1218
+ if (this.otherParams.isRetailTemplate) {
1219
+ return;
1220
+ }
1216
1221
  var allOriginResources = [];
1217
1222
  var dateRange = this.store.date.getDateRange();
1218
1223
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -1798,7 +1803,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1798
1803
  // resourcesUseableMap[n.id] = false;
1799
1804
  // continue
1800
1805
  // }
1801
- var recordCount = countMap[n.id] || 0;
1806
+ // const recordCount = countMap[n.id] || 0;
1802
1807
  // n.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1803
1808
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1804
1809
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
@@ -1809,13 +1814,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1809
1814
  if (mTimes.length === 0) {
1810
1815
  return 0; // continue
1811
1816
  }
1817
+ // 计算在时间片内有交集的预约容量总和
1818
+ var totalCapacity = (countMap[n.id] || []).reduce(function (sum, item) {
1819
+ var hasOverlap = !dayjs(item.time.start_at).isAfter(dayjs(timeSlots.start_at)) && !dayjs(item.time.end_at).isBefore(dayjs(timeSlots.end_at));
1820
+ return hasOverlap ? sum + item.pax : sum;
1821
+ }, 0);
1812
1822
  var canUseTime = mTimes.find(function (item) {
1813
1823
  var _cartItem$_productOri10;
1814
1824
  var res = getIsUsableByTimeItem({
1815
1825
  timeSlice: timeSlots,
1816
1826
  time: item,
1817
1827
  resource: n,
1818
- currentCount: recordCount + (capacity || 0),
1828
+ currentCount: totalCapacity + (capacity || 0),
1819
1829
  resourcesUseableMap: resourcesUseableMap,
1820
1830
  cut_off_time: (_cartItem$_productOri10 = cartItem._productOrigin) === null || _cartItem$_productOri10 === void 0 ? void 0 : _cartItem$_productOri10.cut_off_time
1821
1831
  });
@@ -1886,6 +1896,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1886
1896
  // 一个账号一个账号处理
1887
1897
  var errorList = [];
1888
1898
  var selectResourcesMap = {};
1899
+ var selectResourcesWithTimeSlots = {};
1889
1900
  var accountList = this.store.accountList.getAccounts();
1890
1901
  var selectForCartResources = function selectForCartResources(cartItems) {
1891
1902
  var recordTimeSlots = cloneDeep(timeSlots);
@@ -1918,8 +1929,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1918
1929
  var currentResourceConfig = (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.product_resource) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.resources) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.find(function (n) {
1919
1930
  return n.code === resources_code;
1920
1931
  });
1932
+ var resourceBookingType = (currentResourceConfig === null || currentResourceConfig === void 0 ? void 0 : currentResourceConfig.type) || 'single';
1921
1933
  // 只有 duration 类商品需要这个操作
1922
- if (index !== 0 && recordTimeSlots && (currentResourceConfig === null || currentResourceConfig === void 0 ? void 0 : currentResourceConfig.type) === 'single' && (_item$_productOrigin5 = item._productOrigin) !== null && _item$_productOrigin5 !== void 0 && _item$_productOrigin5.duration) {
1934
+ if (index !== 0 && recordTimeSlots && resourceBookingType === 'single' && (_item$_productOrigin5 = item._productOrigin) !== null && _item$_productOrigin5 !== void 0 && _item$_productOrigin5.duration) {
1923
1935
  var _item$_productOrigin$, _item$_productOrigin6, _ref9, _item$_productOrigin7, _item$_productOrigin$2, _item$_productOrigin8, _ref10, _item$_productOrigin9;
1924
1936
  var start_at = dayjs(recordTimeSlots.end_time).add((_item$_productOrigin$ = (_item$_productOrigin6 = item._productOrigin) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.duration) === null || _item$_productOrigin6 === void 0 ? void 0 : _item$_productOrigin6.value) !== null && _item$_productOrigin$ !== void 0 ? _item$_productOrigin$ : 0, (_ref9 = (_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.duration) === null || _item$_productOrigin7 === void 0 ? void 0 : _item$_productOrigin7.type) !== null && _ref9 !== void 0 ? _ref9 : 'minutes');
1925
1937
  var end_at = start_at.add((_item$_productOrigin$2 = (_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.duration) === null || _item$_productOrigin8 === void 0 ? void 0 : _item$_productOrigin8.value) !== null && _item$_productOrigin$2 !== void 0 ? _item$_productOrigin$2 : 0, (_ref10 = (_item$_productOrigin9 = item._productOrigin) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.duration) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.type) !== null && _ref10 !== void 0 ? _ref10 : 'minutes');
@@ -1936,7 +1948,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1936
1948
  holder_id: item.holder_id,
1937
1949
  resources_code: resources_code,
1938
1950
  timeSlots: recordTimeSlots,
1939
- countMap: selectResourcesMap,
1951
+ countMap: selectResourcesWithTimeSlots,
1940
1952
  capacity: currentCapacity
1941
1953
  });
1942
1954
  // // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
@@ -1944,10 +1956,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1944
1956
  // return
1945
1957
  // }
1946
1958
  if (res !== null && res !== void 0 && res.selectedResource) {
1947
- if (!selectResourcesMap[res.selectedResource.id]) {
1948
- selectResourcesMap[res.selectedResource.id] = currentCapacity;
1959
+ if (!selectResourcesWithTimeSlots[res.selectedResource.id]) {
1960
+ selectResourcesWithTimeSlots[res.selectedResource.id] = [{
1961
+ pax: currentCapacity,
1962
+ time: recordTimeSlots
1963
+ }];
1949
1964
  } else {
1950
- selectResourcesMap[res.selectedResource.id] += currentCapacity;
1965
+ selectResourcesWithTimeSlots[res.selectedResource.id].push({
1966
+ pax: currentCapacity,
1967
+ time: recordTimeSlots
1968
+ });
1951
1969
  }
1952
1970
  res.selectedResource.capacity = currentCapacity;
1953
1971
  checkSubResourcesCapacity(res.selectedResource);
@@ -2069,9 +2087,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2069
2087
  var resourceIds = [];
2070
2088
  var resourcesTypeId = undefined;
2071
2089
  var isSingleResource = false;
2090
+
2091
+ // 找出购物车里最大的 cut_off_time
2092
+ var maxCutOffTime = undefined;
2093
+ var maxCutOffTimeValue = dayjs();
2072
2094
  cartItems.forEach(function (item) {
2073
- var _item$_productOrigin11, _item$_productOrigin12;
2095
+ var _item$_productOrigin11, _item$_productOrigin12, _item$_productOrigin13, _item$_productOrigin14;
2074
2096
  (_item$_productOrigin11 = item._productOrigin) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.product_resource) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.resources) === null || _item$_productOrigin11 === void 0 || _item$_productOrigin11.forEach(function (n) {
2097
+ // TODO: 少了个 status 的判断
2075
2098
  if (n.code === resources_code) {
2076
2099
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
2077
2100
  isSingleResource = n.type === 'single';
@@ -2086,6 +2109,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2086
2109
  resourcesTypeId = item === null || item === void 0 || (_item$_productOrigin12 = item._productOrigin) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.product_resource) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.resources) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.find(function (n) {
2087
2110
  return n.code === resources_code;
2088
2111
  })) === null || _item$_productOrigin12 === void 0 ? void 0 : _item$_productOrigin12.id;
2112
+ if ((_item$_productOrigin13 = item._productOrigin) !== null && _item$_productOrigin13 !== void 0 && _item$_productOrigin13.cut_off_time && ((_item$_productOrigin14 = item._productOrigin) === null || _item$_productOrigin14 === void 0 ? void 0 : _item$_productOrigin14.cut_off_time.type) === 'advance') {
2113
+ var currentCutOffTime = dayjs().add(item._productOrigin.cut_off_time.unit, item._productOrigin.cut_off_time.unit_type);
2114
+ if (currentCutOffTime.isAfter(maxCutOffTimeValue, 'minute')) {
2115
+ maxCutOffTimeValue = currentCutOffTime;
2116
+ maxCutOffTime = item._productOrigin.cut_off_time;
2117
+ }
2118
+ }
2089
2119
  });
2090
2120
  // 保险起见,在这里如果 dateRange 里也有 resources 的话,也 push 进去
2091
2121
  if ((_dateRange = dateRange) !== null && _dateRange !== void 0 && (_dateRange = _dateRange[0]) !== null && _dateRange !== void 0 && (_dateRange = _dateRange.resource) !== null && _dateRange !== void 0 && _dateRange.length) {
@@ -2107,13 +2137,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2107
2137
  cartItems.forEach(function (item) {
2108
2138
  // 单个预约累加账号 多个预约取最大值
2109
2139
  if (isSingleResource) {
2110
- var _item$_productOrigin$3, _item$_productOrigin13;
2111
- accountDuration += (_item$_productOrigin$3 = (_item$_productOrigin13 = item._productOrigin) === null || _item$_productOrigin13 === void 0 || (_item$_productOrigin13 = _item$_productOrigin13.duration) === null || _item$_productOrigin13 === void 0 ? void 0 : _item$_productOrigin13.value) !== null && _item$_productOrigin$3 !== void 0 ? _item$_productOrigin$3 : 0;
2140
+ var _item$_productOrigin$3, _item$_productOrigin15;
2141
+ accountDuration += (_item$_productOrigin$3 = (_item$_productOrigin15 = item._productOrigin) === null || _item$_productOrigin15 === void 0 || (_item$_productOrigin15 = _item$_productOrigin15.duration) === null || _item$_productOrigin15 === void 0 ? void 0 : _item$_productOrigin15.value) !== null && _item$_productOrigin$3 !== void 0 ? _item$_productOrigin$3 : 0;
2112
2142
  } else {
2113
- var _item$_productOrigin$4, _item$_productOrigin14;
2114
- if (accountDuration < ((_item$_productOrigin$4 = (_item$_productOrigin14 = item._productOrigin) === null || _item$_productOrigin14 === void 0 || (_item$_productOrigin14 = _item$_productOrigin14.duration) === null || _item$_productOrigin14 === void 0 ? void 0 : _item$_productOrigin14.value) !== null && _item$_productOrigin$4 !== void 0 ? _item$_productOrigin$4 : 0)) {
2115
- var _item$_productOrigin$5, _item$_productOrigin15;
2116
- accountDuration = (_item$_productOrigin$5 = (_item$_productOrigin15 = item._productOrigin) === null || _item$_productOrigin15 === void 0 || (_item$_productOrigin15 = _item$_productOrigin15.duration) === null || _item$_productOrigin15 === void 0 ? void 0 : _item$_productOrigin15.value) !== null && _item$_productOrigin$5 !== void 0 ? _item$_productOrigin$5 : 0;
2143
+ var _item$_productOrigin$4, _item$_productOrigin16;
2144
+ if (accountDuration < ((_item$_productOrigin$4 = (_item$_productOrigin16 = item._productOrigin) === null || _item$_productOrigin16 === void 0 || (_item$_productOrigin16 = _item$_productOrigin16.duration) === null || _item$_productOrigin16 === void 0 ? void 0 : _item$_productOrigin16.value) !== null && _item$_productOrigin$4 !== void 0 ? _item$_productOrigin$4 : 0)) {
2145
+ var _item$_productOrigin$5, _item$_productOrigin17;
2146
+ accountDuration = (_item$_productOrigin$5 = (_item$_productOrigin17 = item._productOrigin) === null || _item$_productOrigin17 === void 0 || (_item$_productOrigin17 = _item$_productOrigin17.duration) === null || _item$_productOrigin17 === void 0 ? void 0 : _item$_productOrigin17.value) !== null && _item$_productOrigin$5 !== void 0 ? _item$_productOrigin$5 : 0;
2117
2147
  }
2118
2148
  }
2119
2149
  });
@@ -2155,7 +2185,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2155
2185
  duration: duration,
2156
2186
  currentDate: dateRange[0].date,
2157
2187
  split: 10,
2158
- resourcesUseableMap: resourcesUseableMap
2188
+ resourcesUseableMap: resourcesUseableMap,
2189
+ cut_off_time: maxCutOffTime
2159
2190
  });
2160
2191
  return timeSlots;
2161
2192
  }
@@ -2185,9 +2216,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2185
2216
  var _newResources$;
2186
2217
  var newResources = cloneDeep(item._origin.resources);
2187
2218
  newResources.forEach(function (resource) {
2188
- var _item$_productOrigin$6, _item$_productOrigin16, _ref11, _item$_productOrigin17;
2219
+ var _item$_productOrigin$6, _item$_productOrigin18, _ref11, _item$_productOrigin19;
2189
2220
  resource.startTime = currentStartTime;
2190
- resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$6 = (_item$_productOrigin16 = item._productOrigin) === null || _item$_productOrigin16 === void 0 || (_item$_productOrigin16 = _item$_productOrigin16.duration) === null || _item$_productOrigin16 === void 0 ? void 0 : _item$_productOrigin16.value) !== null && _item$_productOrigin$6 !== void 0 ? _item$_productOrigin$6 : 0, (_ref11 = (_item$_productOrigin17 = item._productOrigin) === null || _item$_productOrigin17 === void 0 || (_item$_productOrigin17 = _item$_productOrigin17.duration) === null || _item$_productOrigin17 === void 0 ? void 0 : _item$_productOrigin17.type) !== null && _ref11 !== void 0 ? _ref11 : 'minutes').format('YYYY-MM-DD HH:mm');
2221
+ resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$6 = (_item$_productOrigin18 = item._productOrigin) === null || _item$_productOrigin18 === void 0 || (_item$_productOrigin18 = _item$_productOrigin18.duration) === null || _item$_productOrigin18 === void 0 ? void 0 : _item$_productOrigin18.value) !== null && _item$_productOrigin$6 !== void 0 ? _item$_productOrigin$6 : 0, (_ref11 = (_item$_productOrigin19 = item._productOrigin) === null || _item$_productOrigin19 === void 0 || (_item$_productOrigin19 = _item$_productOrigin19.duration) === null || _item$_productOrigin19 === void 0 ? void 0 : _item$_productOrigin19.type) !== null && _ref11 !== void 0 ? _ref11 : 'minutes').format('YYYY-MM-DD HH:mm');
2191
2222
  delete resource.times;
2192
2223
  });
2193
2224
  _this11.store.cart.updateItem({
@@ -2277,9 +2308,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2277
2308
  var _this$store$currentPr2;
2278
2309
  var date = _ref12.date,
2279
2310
  scheduleIds = _ref12.scheduleIds,
2280
- resources = _ref12.resources;
2311
+ resources = _ref12.resources,
2312
+ product = _ref12.product;
2281
2313
  var targetProduct = this.store.currentProduct;
2282
- var targetProductData = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData();
2314
+ // 如果外面传递了product 优先用外面的
2315
+ var targetProductData = product || (targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData());
2283
2316
  var targetSchedules = [];
2284
2317
  // 如果外面传递了 scheduleIds,优先取入参
2285
2318
  if (scheduleIds !== null && scheduleIds !== void 0 && scheduleIds.length) {
@@ -2326,7 +2359,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2326
2359
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
2327
2360
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
2328
2361
  var mTimes = m.times.filter(function (n) {
2329
- return !dayjs(n.start_at).isAfter(dayjs(item.start)) && !dayjs(n.end_at).isBefore(dayjs(item.end));
2362
+ return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute');
2330
2363
  });
2331
2364
  // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
2332
2365
  if (mTimes.length === 0) {
@@ -2463,6 +2496,173 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2463
2496
  }
2464
2497
  return getProductTypeById;
2465
2498
  }()
2499
+ /**
2500
+ * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
2501
+ *
2502
+ * @param {string} cartItemId
2503
+ * @param {string} resourceCode
2504
+ * @return {*}
2505
+ * @memberof BookingByStepImpl
2506
+ */
2507
+ }, {
2508
+ key: "getResourcesByCartItemAndCode",
2509
+ value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
2510
+ var _cartItem$_productOri11, _cartItem$_productOri12;
2511
+ var dateRange = this.store.date.getDateRange();
2512
+ var resources = [];
2513
+ if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
2514
+ dateRange.forEach(function (n) {
2515
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
2516
+ });
2517
+ }
2518
+ if (!resources.length) {
2519
+ var dateList = this.store.date.getDateList();
2520
+ dateList.forEach(function (n) {
2521
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
2522
+ });
2523
+ }
2524
+ var resourcesMap = getResourcesMap(cloneDeep(resources));
2525
+ var cartItems = this.store.cart.getItems();
2526
+ var cartItem = cartItems.find(function (item) {
2527
+ return item._id === cartItemId;
2528
+ });
2529
+ if (!cartItem) return [];
2530
+ var selectedResources = [];
2531
+ var formatCapacity = formatDefaultCapacitys({
2532
+ capacity: (_cartItem$_productOri11 = cartItem._productOrigin) === null || _cartItem$_productOri11 === void 0 ? void 0 : _cartItem$_productOri11.capacity,
2533
+ product_bundle: cartItem._origin.product.product_bundle
2534
+ });
2535
+ cartItem._origin.metadata.capacity = formatCapacity;
2536
+ var currentCapacity = getSumCapacity({
2537
+ capacity: formatCapacity
2538
+ });
2539
+ if (cartItem.holder_id) {
2540
+ selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
2541
+ } else {
2542
+ selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
2543
+ }
2544
+ var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri12 = cartItem._productOrigin) === null || _cartItem$_productOri12 === void 0 || (_cartItem$_productOri12 = _cartItem$_productOri12.product_resource) === null || _cartItem$_productOri12 === void 0 ? void 0 : _cartItem$_productOri12.resources) || [], selectedResources, currentCapacity);
2545
+ var targetResource = productResources.find(function (resource) {
2546
+ return resource.code === resourceCode;
2547
+ });
2548
+ if (!targetResource) return [];
2549
+ if (cartItem._origin.start_time) {
2550
+ var startTime = dayjs("".concat(cartItem._origin.start_date, " ").concat(cartItem._origin.start_time));
2551
+ var endTime = dayjs("".concat(cartItem._origin.end_date, " ").concat(cartItem._origin.end_time));
2552
+ var resourcesUseableMap = {};
2553
+ targetResource.renderList = targetResource.renderList.sort(function (a, b) {
2554
+ var _a$metadata5, _b$metadata5;
2555
+ var aIsCombined = ((_a$metadata5 = a.metadata) === null || _a$metadata5 === void 0 || (_a$metadata5 = _a$metadata5.combined_resource) === null || _a$metadata5 === void 0 ? void 0 : _a$metadata5.status) === 1;
2556
+ var bIsCombined = ((_b$metadata5 = b.metadata) === null || _b$metadata5 === void 0 || (_b$metadata5 = _b$metadata5.combined_resource) === null || _b$metadata5 === void 0 ? void 0 : _b$metadata5.status) === 1;
2557
+ if (aIsCombined && !bIsCombined) return 1;
2558
+ if (!aIsCombined && bIsCombined) return -1;
2559
+ return 0;
2560
+ });
2561
+ targetResource.renderList = targetResource.renderList.filter(function (m) {
2562
+ var mTimes = m.times.filter(function (n) {
2563
+ return !dayjs(n.start_at).isAfter(dayjs(startTime)) && !dayjs(n.end_at).isBefore(dayjs(endTime));
2564
+ });
2565
+ if (mTimes.length === 0) return false;
2566
+ var canUseArr = mTimes.map(function (item) {
2567
+ var _cartItem$_productOri13;
2568
+ var res = getIsUsableByTimeItem({
2569
+ timeSlice: {
2570
+ start_time: startTime.format('HH:mm'),
2571
+ end_time: endTime.format('HH:mm'),
2572
+ start_at: startTime,
2573
+ end_at: endTime
2574
+ },
2575
+ time: item,
2576
+ resource: m,
2577
+ currentCount: currentCapacity || 0,
2578
+ resourcesUseableMap: resourcesUseableMap,
2579
+ cut_off_time: (_cartItem$_productOri13 = cartItem._productOrigin) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.cut_off_time
2580
+ });
2581
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
2582
+ resourcesUseableMap[m.id] = res.usable;
2583
+ }
2584
+ return res.usable;
2585
+ });
2586
+ if (m.onlyComputed) return false;
2587
+ return !canUseArr.some(function (n) {
2588
+ return n === false;
2589
+ });
2590
+ });
2591
+ } else {
2592
+ targetResource.renderList = targetResource.renderList.filter(function (n) {
2593
+ var _cartItem$_productOri14;
2594
+ var recordCount = n.capacity || 0;
2595
+ if (n.onlyComputed) return false;
2596
+ var timeSlots = getTimeSlicesByResource({
2597
+ resource: n,
2598
+ duration: ((_cartItem$_productOri14 = cartItem._productOrigin) === null || _cartItem$_productOri14 === void 0 || (_cartItem$_productOri14 = _cartItem$_productOri14.duration) === null || _cartItem$_productOri14 === void 0 ? void 0 : _cartItem$_productOri14.value) || 0,
2599
+ split: 10,
2600
+ currentDate: dateRange[0].date
2601
+ });
2602
+ return recordCount >= currentCapacity && timeSlots.length > 0;
2603
+ });
2604
+ }
2605
+ return targetResource.renderList;
2606
+ }
2607
+ }, {
2608
+ key: "getAvailableDateForSession",
2609
+ value: function () {
2610
+ var _getAvailableDateForSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2611
+ var params,
2612
+ startDate,
2613
+ endDate,
2614
+ type,
2615
+ tempProducts,
2616
+ _ref15,
2617
+ resourceIds,
2618
+ rules,
2619
+ resourcesMap,
2620
+ res,
2621
+ _args29 = arguments;
2622
+ return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2623
+ while (1) switch (_context29.prev = _context29.next) {
2624
+ case 0:
2625
+ params = _args29.length > 0 && _args29[0] !== undefined ? _args29[0] : {};
2626
+ // 开始日期如果小于今天,直接以今天当做开始日期
2627
+ startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2628
+ if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
2629
+ startDate = dayjs().format('YYYY-MM-DD');
2630
+ }
2631
+ // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2632
+ endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2633
+ tempProducts = []; // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2634
+ if (this.store.currentProduct) {
2635
+ tempProducts = [_objectSpread(_objectSpread({}, this.store.currentProduct.getData()), {}, {
2636
+ _schedule: this.store.currentProduct.getOtherParams()['schedule']
2637
+ })];
2638
+ }
2639
+ // 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
2640
+ _ref15 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref15.resourceIds, rules = _ref15.rules, resourcesMap = _ref15.resourcesMap;
2641
+ this.otherParams.currentResourcesMap = resourcesMap;
2642
+ _context29.next = 10;
2643
+ return this.store.date.getResourceDates({
2644
+ query: {
2645
+ start_date: startDate || '',
2646
+ end_date: endDate || '',
2647
+ resource_ids: resourceIds
2648
+ },
2649
+ rules: rules,
2650
+ type: type
2651
+ });
2652
+ case 10:
2653
+ res = _context29.sent;
2654
+ return _context29.abrupt("return", res);
2655
+ case 12:
2656
+ case "end":
2657
+ return _context29.stop();
2658
+ }
2659
+ }, _callee28, this);
2660
+ }));
2661
+ function getAvailableDateForSession() {
2662
+ return _getAvailableDateForSession.apply(this, arguments);
2663
+ }
2664
+ return getAvailableDateForSession;
2665
+ }()
2466
2666
  }]);
2467
2667
  return BookingByStepImpl;
2468
2668
  }(BaseModule);
@@ -79,13 +79,23 @@ export declare const formatResources: ({ booking, resources, }: {
79
79
  * @return {*}
80
80
  * @Author: zhiwei.Wang
81
81
  */
82
- export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, }: {
82
+ export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time }: {
83
83
  resource: ResourceItem;
84
84
  duration: number;
85
85
  split: number;
86
86
  currentDate: DateType | string;
87
87
  capacity?: number | undefined;
88
88
  resourcesUseableMap?: Record<string, boolean> | undefined;
89
+ cut_off_time?: {
90
+ future_day: number;
91
+ unit: number;
92
+ unit_type: string;
93
+ type: string;
94
+ ongoing?: {
95
+ type: string;
96
+ unit: number;
97
+ } | undefined;
98
+ } | undefined;
89
99
  }) => TimeSliceItem[];
90
100
  /**
91
101
  * @title: 获取时间切片列表的交集
@@ -123,7 +133,7 @@ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], re
123
133
  * @return {*}
124
134
  * @Author: zhiwei.Wang
125
135
  */
126
- export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, }: {
136
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time }: {
127
137
  resourceIds: number[];
128
138
  resourcesMap: any;
129
139
  duration: number;
@@ -131,6 +141,16 @@ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, dur
131
141
  split: number;
132
142
  capacity?: number | undefined;
133
143
  resourcesUseableMap: Record<string, boolean>;
144
+ cut_off_time?: {
145
+ future_day: number;
146
+ unit: number;
147
+ unit_type: string;
148
+ type: string;
149
+ ongoing?: {
150
+ type: string;
151
+ unit: number;
152
+ } | undefined;
153
+ } | undefined;
134
154
  }) => any[];
135
155
  /**
136
156
  * @title: 获取其他人的已选资源
@@ -414,7 +414,8 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref5) {
414
414
  currentDate = _ref5$currentDate === void 0 ? dayjs() : _ref5$currentDate,
415
415
  capacity = _ref5.capacity,
416
416
  _ref5$resourcesUseabl = _ref5.resourcesUseableMap,
417
- resourcesUseableMap = _ref5$resourcesUseabl === void 0 ? {} : _ref5$resourcesUseabl;
417
+ resourcesUseableMap = _ref5$resourcesUseabl === void 0 ? {} : _ref5$resourcesUseabl,
418
+ cut_off_time = _ref5.cut_off_time;
418
419
  var times = resource.times;
419
420
 
420
421
  // 存储所有时间切片
@@ -452,7 +453,8 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref5) {
452
453
  time: time,
453
454
  resource: resource,
454
455
  currentCount: capacity || 1,
455
- resourcesUseableMap: resourcesUseableMap
456
+ resourcesUseableMap: resourcesUseableMap,
457
+ cut_off_time: cut_off_time
456
458
  });
457
459
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[resource.id]) !== false) {
458
460
  resourcesUseableMap[resource.id] = _status.usable;
@@ -562,7 +564,8 @@ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref6) {
562
564
  currentDate = _ref6.currentDate,
563
565
  split = _ref6.split,
564
566
  capacity = _ref6.capacity,
565
- resourcesUseableMap = _ref6.resourcesUseableMap;
567
+ resourcesUseableMap = _ref6.resourcesUseableMap,
568
+ cut_off_time = _ref6.cut_off_time;
566
569
  // 获取资源列表
567
570
  var resources = getResourcesByIds(resourcesMap, resourceIds);
568
571
  mergeSubResourcesTimeSlices(resources, resourcesMap);
@@ -584,7 +587,8 @@ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref6) {
584
587
  split: split,
585
588
  currentDate: currentDate,
586
589
  capacity: capacity,
587
- resourcesUseableMap: resourcesUseableMap
590
+ resourcesUseableMap: resourcesUseableMap,
591
+ cut_off_time: cut_off_time
588
592
  }));
589
593
  }, []);
590
594