@pisell/pisellos 0.0.286 → 0.0.288

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.
@@ -536,7 +536,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
536
536
  } else {
537
537
  arr.push(_this3.hooks.setProduct(originProduct, {
538
538
  discount_list: [discountDetail],
539
- _id: product._id.split('___')[0] + "___" + _selectedDiscount.id + index,
539
+ _id: product._id.split('___')[0] + "___" + _selectedDiscount.id + "___" + index,
540
540
  price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
541
541
  quantity: isNeedSplit ? 1 : product.quantity,
542
542
  total: targetProductTotal,
@@ -2061,7 +2061,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2061
2061
  // item._origin.resources?.forEach((n: any) => {
2062
2062
  // resourceIds.push(n.relation_id);
2063
2063
  // });
2064
- if (item.resource_id) {
2064
+ if (item.resource_id && !resourceIds.includes(item.resource_id)) {
2065
2065
  resourceIds.push(item.resource_id);
2066
2066
  }
2067
2067
  resourcesTypeId = item === null || item === void 0 || (_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.product_resource) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.resources) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.find(function (n) {
@@ -2156,6 +2156,26 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2156
2156
  return 0;
2157
2157
  }, 0);
2158
2158
  }
2159
+ // 计算容量的辅助函数
2160
+ var calculateCapacityFromCartItems = function calculateCapacityFromCartItems(items) {
2161
+ return items.reduce(function (total, item) {
2162
+ return total + (getCapacityInfoByCartItem(item).currentCapacity || 0);
2163
+ }, 0);
2164
+ };
2165
+
2166
+ // 如果是多个预约,去要求助几个 holder 下最大的需求容量capacity
2167
+ var maxCapacity = 1;
2168
+ if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
2169
+ accountList.forEach(function (account) {
2170
+ var accountCartItems = _this12.store.cart.getCartByAccount(account.getId());
2171
+ var currentCapacity = calculateCapacityFromCartItems(accountCartItems);
2172
+ if (currentCapacity > maxCapacity) {
2173
+ maxCapacity = currentCapacity;
2174
+ }
2175
+ });
2176
+ } else {
2177
+ maxCapacity = calculateCapacityFromCartItems(cartItems);
2178
+ }
2159
2179
  var timeSlots = getTimeSlicesByResources({
2160
2180
  resourceIds: resourceIds,
2161
2181
  resourcesMap: resourcesMap,
@@ -2163,6 +2183,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2163
2183
  currentDate: dateRange[0].date,
2164
2184
  split: 10,
2165
2185
  resourcesUseableMap: resourcesUseableMap,
2186
+ capacity: maxCapacity,
2166
2187
  cut_off_time: maxCutOffTime,
2167
2188
  hasFlexibleDuration: hasFlexibleDuration,
2168
2189
  operating_day_boundary: operating_day_boundary,
@@ -245,17 +245,28 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
245
245
  var _getCapacityInfoByCar2 = getCapacityInfoByCartItem(cartItem),
246
246
  currentCapacity = _getCapacityInfoByCar2.currentCapacity;
247
247
  Object.keys(resourceTypeMap).forEach(function (formId) {
248
+ var _cartItem$_productOri;
248
249
  var resourcesInType = resourceTypeMap[formId];
249
250
  var resourceIdsInType = resourcesInType.map(function (r) {
250
251
  return r.id;
251
252
  });
253
+ var selectType = (_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 || (_cartItem$_productOri = _cartItem$_productOri.product_resource) === null || _cartItem$_productOri === void 0 || (_cartItem$_productOri = _cartItem$_productOri.resources) === null || _cartItem$_productOri === void 0 || (_cartItem$_productOri = _cartItem$_productOri.find(function (r) {
254
+ var _r$id;
255
+ return ((_r$id = r.id) === null || _r$id === void 0 ? void 0 : _r$id.toString()) === formId;
256
+ })) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.type;
252
257
 
253
258
  // 检查该商品是否需要这种类型的资源
254
259
  var needsThisResourceType = productResourceIds.some(function (id) {
255
260
  return resourceIdsInType.includes(id);
256
261
  });
257
262
  if (needsThisResourceType) {
258
- requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
263
+ // 需要判断是单个预约还是多个预约,如果是单个预约,不用加 capacity,只用+1
264
+ if (selectType === 'single') {
265
+ requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + 1;
266
+ } else {
267
+ requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
268
+ }
269
+ // requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
259
270
  }
260
271
  });
261
272
  });
@@ -275,12 +286,12 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
275
286
  _step2;
276
287
  try {
277
288
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
278
- var _cartItem$_productOri;
289
+ var _cartItem$_productOri2;
279
290
  var cartItem = _step2.value;
280
- if ((_cartItem$_productOri = cartItem._productOrigin) !== null && _cartItem$_productOri !== void 0 && (_cartItem$_productOri = _cartItem$_productOri.product_resource) !== null && _cartItem$_productOri !== void 0 && _cartItem$_productOri.resources) {
291
+ if ((_cartItem$_productOri2 = cartItem._productOrigin) !== null && _cartItem$_productOri2 !== void 0 && (_cartItem$_productOri2 = _cartItem$_productOri2.product_resource) !== null && _cartItem$_productOri2 !== void 0 && _cartItem$_productOri2.resources) {
281
292
  resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
282
- var _r$id;
283
- return ((_r$id = r.id) === null || _r$id === void 0 ? void 0 : _r$id.toString()) === formId && r.status === 1;
293
+ var _r$id2;
294
+ return ((_r$id2 = r.id) === null || _r$id2 === void 0 ? void 0 : _r$id2.toString()) === formId && r.status === 1;
284
295
  });
285
296
  if (resourceTypeConfig) break;
286
297
  }
@@ -379,7 +379,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
379
379
  } else {
380
380
  arr.push(this.hooks.setProduct(originProduct, {
381
381
  discount_list: [discountDetail],
382
- _id: product._id.split("___")[0] + "___" + selectedDiscount2.id + index,
382
+ _id: product._id.split("___")[0] + "___" + selectedDiscount2.id + "___" + index,
383
383
  price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
384
384
  quantity: isNeedSplit ? 1 : product.quantity,
385
385
  total: targetProductTotal,
@@ -1402,7 +1402,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1402
1402
  isSingleResource = n.type === "single";
1403
1403
  }
1404
1404
  });
1405
- if (item.resource_id) {
1405
+ if (item.resource_id && !resourceIds.includes(item.resource_id)) {
1406
1406
  resourceIds.push(item.resource_id);
1407
1407
  }
1408
1408
  resourcesTypeId = (_g2 = (_f2 = (_e2 = (_d2 = item == null ? void 0 : item._productOrigin) == null ? void 0 : _d2.product_resource) == null ? void 0 : _e2.resources) == null ? void 0 : _f2.find(
@@ -1490,6 +1490,23 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1490
1490
  return 0;
1491
1491
  }, 0);
1492
1492
  }
1493
+ const calculateCapacityFromCartItems = (items) => {
1494
+ return items.reduce((total, item) => {
1495
+ return total + ((0, import_capacity.getCapacityInfoByCartItem)(item).currentCapacity || 0);
1496
+ }, 0);
1497
+ };
1498
+ let maxCapacity = 1;
1499
+ if (cartItems == null ? void 0 : cartItems[0].holder_id) {
1500
+ accountList.forEach((account) => {
1501
+ const accountCartItems = this.store.cart.getCartByAccount(account.getId());
1502
+ const currentCapacity = calculateCapacityFromCartItems(accountCartItems);
1503
+ if (currentCapacity > maxCapacity) {
1504
+ maxCapacity = currentCapacity;
1505
+ }
1506
+ });
1507
+ } else {
1508
+ maxCapacity = calculateCapacityFromCartItems(cartItems);
1509
+ }
1493
1510
  const timeSlots = (0, import_resources.getTimeSlicesByResources)({
1494
1511
  resourceIds,
1495
1512
  resourcesMap,
@@ -1497,6 +1514,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1497
1514
  currentDate: dateRange[0].date,
1498
1515
  split: 10,
1499
1516
  resourcesUseableMap,
1517
+ capacity: maxCapacity,
1500
1518
  cut_off_time: maxCutOffTime,
1501
1519
  hasFlexibleDuration,
1502
1520
  operating_day_boundary,
@@ -182,13 +182,22 @@ function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, allResourc
182
182
  const productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
183
183
  const { currentCapacity } = getCapacityInfoByCartItem(cartItem);
184
184
  Object.keys(resourceTypeMap).forEach((formId) => {
185
+ var _a2, _b2, _c, _d;
185
186
  const resourcesInType = resourceTypeMap[formId];
186
187
  const resourceIdsInType = resourcesInType.map((r) => r.id);
188
+ const selectType = (_d = (_c = (_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c.find((r) => {
189
+ var _a3;
190
+ return ((_a3 = r.id) == null ? void 0 : _a3.toString()) === formId;
191
+ })) == null ? void 0 : _d.type;
187
192
  const needsThisResourceType = productResourceIds.some(
188
193
  (id) => resourceIdsInType.includes(id)
189
194
  );
190
195
  if (needsThisResourceType) {
191
- requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
196
+ if (selectType === "single") {
197
+ requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + 1;
198
+ } else {
199
+ requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
200
+ }
192
201
  }
193
202
  });
194
203
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.286",
4
+ "version": "0.0.288",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",