@pisell/pisellos 0.0.55 → 0.0.57

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.
@@ -176,6 +176,8 @@ export interface IUpdateItemParams {
176
176
  quantity?: number;
177
177
  /** 资源 */
178
178
  resources?: Resource[];
179
+ /** 元数据 */
180
+ metadata?: any;
179
181
  /** 备注 */
180
182
  note?: string;
181
183
  /** 日期 */
@@ -878,6 +878,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
878
878
  cartItems = this.store.cart.getItems();
879
879
  newCartItems = cloneDeep(cartItems); // 先整个临时的逻辑,把购物车里所有商品的资源给他格式化一下
880
880
  newCartItems.forEach(function (item) {
881
+ var _item$_productOrigin;
881
882
  item._origin.resources = item._origin.resources.map(function (n) {
882
883
  var newResourcesItem = cloneDeep(n);
883
884
  delete newResourcesItem.id;
@@ -885,6 +886,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
885
886
  delete newResourcesItem.resourceType;
886
887
  return _objectSpread({}, newResourcesItem);
887
888
  });
889
+ var formatCapacity = formatDefaultCapacitys({
890
+ capacity: (_item$_productOrigin = item._productOrigin) === null || _item$_productOrigin === void 0 ? void 0 : _item$_productOrigin.capacity,
891
+ product_bundle: item._origin.product.product_bundle
892
+ });
893
+ item._origin.metadata.capacity = formatCapacity;
888
894
  });
889
895
  return _context20.abrupt("return", this.store.order.submitOrder({
890
896
  query: {
@@ -992,8 +998,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
992
998
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(params._id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
993
999
  }
994
1000
  if (params.resources) {
1001
+ var _targetCartItem$_prod;
1002
+ var formatCapacity = formatDefaultCapacitys({
1003
+ capacity: (_targetCartItem$_prod = targetCartItem._productOrigin) === null || _targetCartItem$_prod === void 0 ? void 0 : _targetCartItem$_prod.capacity,
1004
+ product_bundle: targetCartItem._origin.product.product_bundle
1005
+ });
1006
+ var currentCapacity = getSumCapacity({
1007
+ capacity: formatCapacity
1008
+ });
995
1009
  params.resources = params.resources.map(function (n) {
996
- n.capacity = targetCartItem.num || 1;
1010
+ n.capacity = currentCapacity || 1;
997
1011
  checkSubResourcesCapacity(n);
998
1012
  return n;
999
1013
  });
@@ -1116,6 +1130,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1116
1130
  capacity: (_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.capacity,
1117
1131
  product_bundle: cartItem._origin.product.product_bundle
1118
1132
  });
1133
+ cartItem._origin.metadata.capacity = formatCapacity;
1119
1134
  var currentCapacity = getSumCapacity({
1120
1135
  capacity: formatCapacity
1121
1136
  });
@@ -1163,7 +1178,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1163
1178
  }, {
1164
1179
  key: "getResourcesListByCartItem",
1165
1180
  value: function getResourcesListByCartItem(id) {
1166
- var _targetCartItem$_prod, _targetCartItem$_prod2;
1181
+ var _targetCartItem$_prod2, _targetCartItem$_prod3;
1167
1182
  var cartItems = this.store.cart.getItems();
1168
1183
  var dateRange = this.store.date.getDateRange();
1169
1184
  var resources = [];
@@ -1186,13 +1201,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1186
1201
  selectedResources = getOthersCartSelectedResources(cartItems, targetCartItem._id, resourcesMap);
1187
1202
  }
1188
1203
  var formatCapacity = formatDefaultCapacitys({
1189
- capacity: (_targetCartItem$_prod = targetCartItem._productOrigin) === null || _targetCartItem$_prod === void 0 ? void 0 : _targetCartItem$_prod.capacity,
1204
+ capacity: (_targetCartItem$_prod2 = targetCartItem._productOrigin) === null || _targetCartItem$_prod2 === void 0 ? void 0 : _targetCartItem$_prod2.capacity,
1190
1205
  product_bundle: targetCartItem._origin.product.product_bundle
1191
1206
  });
1192
1207
  var currentCapacity = getSumCapacity({
1193
1208
  capacity: formatCapacity
1194
1209
  });
1195
- var productResources = getResourcesByProduct(resourcesMap, ((_targetCartItem$_prod2 = targetCartItem._productOrigin) === null || _targetCartItem$_prod2 === void 0 || (_targetCartItem$_prod2 = _targetCartItem$_prod2.product_resource) === null || _targetCartItem$_prod2 === void 0 ? void 0 : _targetCartItem$_prod2.resources) || [], selectedResources, currentCapacity);
1210
+ var productResources = getResourcesByProduct(resourcesMap, ((_targetCartItem$_prod3 = targetCartItem._productOrigin) === null || _targetCartItem$_prod3 === void 0 || (_targetCartItem$_prod3 = _targetCartItem$_prod3.product_resource) === null || _targetCartItem$_prod3 === void 0 ? void 0 : _targetCartItem$_prod3.resources) || [], selectedResources, currentCapacity);
1196
1211
  if (productResources) {
1197
1212
  return {
1198
1213
  id: targetCartItem.id,
@@ -1327,8 +1342,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1327
1342
  // 取出账号下所对应类型的所有的可用资源
1328
1343
  var resources = [];
1329
1344
  accountCartItems.forEach(function (item) {
1330
- var _item$_productOrigin;
1331
- (_item$_productOrigin = item._productOrigin) === null || _item$_productOrigin === void 0 || (_item$_productOrigin = _item$_productOrigin.product_resource) === null || _item$_productOrigin === void 0 || (_item$_productOrigin = _item$_productOrigin.resources) === null || _item$_productOrigin === void 0 || _item$_productOrigin.forEach(function (n) {
1345
+ var _item$_productOrigin2;
1346
+ (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 || (_item$_productOrigin2 = _item$_productOrigin2.product_resource) === null || _item$_productOrigin2 === void 0 || (_item$_productOrigin2 = _item$_productOrigin2.resources) === null || _item$_productOrigin2 === void 0 || _item$_productOrigin2.forEach(function (n) {
1332
1347
  if (n.code === resources_code) {
1333
1348
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1334
1349
  }
@@ -1424,9 +1439,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1424
1439
  // 第一个商品分配完以后,第二个商品分配的start_time应该是第一个商品的 end_time ,然后 end_time 应该是 start_time+duration
1425
1440
 
1426
1441
  cartItems.forEach(function (item, index) {
1427
- var _item$_productOrigin2;
1442
+ var _item$_productOrigin3;
1428
1443
  var formatCapacity = formatDefaultCapacitys({
1429
- capacity: (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.capacity,
1444
+ capacity: (_item$_productOrigin3 = item._productOrigin) === null || _item$_productOrigin3 === void 0 ? void 0 : _item$_productOrigin3.capacity,
1430
1445
  product_bundle: item._origin.product.product_bundle
1431
1446
  });
1432
1447
  var currentCapacity = getSumCapacity({
@@ -1443,9 +1458,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1443
1458
  }
1444
1459
  if (recordTimeSlots) {
1445
1460
  if (index !== 0 && recordTimeSlots) {
1446
- var _item$_productOrigin$, _item$_productOrigin3, _ref10, _item$_productOrigin4, _item$_productOrigin$2, _item$_productOrigin5, _ref11, _item$_productOrigin6;
1447
- var start_at = dayjs(recordTimeSlots.end_time).add((_item$_productOrigin$ = (_item$_productOrigin3 = item._productOrigin) === null || _item$_productOrigin3 === void 0 || (_item$_productOrigin3 = _item$_productOrigin3.duration) === null || _item$_productOrigin3 === void 0 ? void 0 : _item$_productOrigin3.value) !== null && _item$_productOrigin$ !== void 0 ? _item$_productOrigin$ : 0, (_ref10 = (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.duration) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.type) !== null && _ref10 !== void 0 ? _ref10 : 'minutes');
1448
- var end_at = start_at.add((_item$_productOrigin$2 = (_item$_productOrigin5 = item._productOrigin) === null || _item$_productOrigin5 === void 0 || (_item$_productOrigin5 = _item$_productOrigin5.duration) === null || _item$_productOrigin5 === void 0 ? void 0 : _item$_productOrigin5.value) !== null && _item$_productOrigin$2 !== void 0 ? _item$_productOrigin$2 : 0, (_ref11 = (_item$_productOrigin6 = item._productOrigin) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.duration) === null || _item$_productOrigin6 === void 0 ? void 0 : _item$_productOrigin6.type) !== null && _ref11 !== void 0 ? _ref11 : 'minutes');
1461
+ var _item$_productOrigin$, _item$_productOrigin4, _ref10, _item$_productOrigin5, _item$_productOrigin$2, _item$_productOrigin6, _ref11, _item$_productOrigin7;
1462
+ var start_at = dayjs(recordTimeSlots.end_time).add((_item$_productOrigin$ = (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.duration) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.value) !== null && _item$_productOrigin$ !== void 0 ? _item$_productOrigin$ : 0, (_ref10 = (_item$_productOrigin5 = item._productOrigin) === null || _item$_productOrigin5 === void 0 || (_item$_productOrigin5 = _item$_productOrigin5.duration) === null || _item$_productOrigin5 === void 0 ? void 0 : _item$_productOrigin5.type) !== null && _ref10 !== void 0 ? _ref10 : 'minutes');
1463
+ var end_at = start_at.add((_item$_productOrigin$2 = (_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$2 !== void 0 ? _item$_productOrigin$2 : 0, (_ref11 = (_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 && _ref11 !== void 0 ? _ref11 : 'minutes');
1449
1464
  recordTimeSlots = {
1450
1465
  start_time: start_at.format('HH:mm'),
1451
1466
  end_time: end_at.format('HH:mm'),
@@ -1485,7 +1500,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1485
1500
  errorList.push(item._id);
1486
1501
  }
1487
1502
  } else {
1488
- var _item$_productOrigin7, _productResources$fin;
1503
+ var _item$_productOrigin8, _productResources$fin;
1489
1504
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1490
1505
  var allCartItems = _this7.store.cart.getItems();
1491
1506
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
@@ -1495,7 +1510,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1495
1510
  } else {
1496
1511
  selectedResources = getOthersCartSelectedResources(allCartItems, item._id, resourcesMap);
1497
1512
  }
1498
- var productResources = getResourcesByProduct(resourcesMap, ((_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.product_resource) === null || _item$_productOrigin7 === void 0 ? void 0 : _item$_productOrigin7.resources) || [], selectedResources, currentCapacity);
1513
+ var productResources = getResourcesByProduct(resourcesMap, ((_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.product_resource) === null || _item$_productOrigin8 === void 0 ? void 0 : _item$_productOrigin8.resources) || [], selectedResources, currentCapacity);
1499
1514
  // 自动选择 productResources 中对应 resources_code 的资源
1500
1515
  var targetRenderList = (_productResources$fin = productResources.find(function (n) {
1501
1516
  return n.code === resources_code;
@@ -1552,8 +1567,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1552
1567
  // if (cartItems?.[0].start_date) return [];
1553
1568
  var resourceIds = [];
1554
1569
  cartItems.forEach(function (item) {
1555
- var _item$_productOrigin8;
1556
- (_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.forEach(function (n) {
1570
+ var _item$_productOrigin9;
1571
+ (_item$_productOrigin9 = item._productOrigin) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.product_resource) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.resources) === null || _item$_productOrigin9 === void 0 || _item$_productOrigin9.forEach(function (n) {
1557
1572
  if (n.code === resources_code) {
1558
1573
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1559
1574
  }
@@ -1572,8 +1587,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1572
1587
  var checkDuration = function checkDuration(cartItems) {
1573
1588
  var accountDuration = 0;
1574
1589
  cartItems.forEach(function (item) {
1575
- var _item$_productOrigin$3, _item$_productOrigin9;
1576
- accountDuration += (_item$_productOrigin$3 = (_item$_productOrigin9 = item._productOrigin) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.duration) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.value) !== null && _item$_productOrigin$3 !== void 0 ? _item$_productOrigin$3 : 0;
1590
+ var _item$_productOrigin$3, _item$_productOrigin10;
1591
+ accountDuration += (_item$_productOrigin$3 = (_item$_productOrigin10 = item._productOrigin) === null || _item$_productOrigin10 === void 0 || (_item$_productOrigin10 = _item$_productOrigin10.duration) === null || _item$_productOrigin10 === void 0 ? void 0 : _item$_productOrigin10.value) !== null && _item$_productOrigin$3 !== void 0 ? _item$_productOrigin$3 : 0;
1577
1592
  });
1578
1593
  if (accountDuration > duration) {
1579
1594
  duration = accountDuration;
@@ -1587,9 +1602,20 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1587
1602
  } else {
1588
1603
  checkDuration(cartItems);
1589
1604
  }
1590
- this.store.accountList.getAccounts().forEach(function (account) {
1591
- var cartItems = _this8.store.cart.getCartByAccount(account.getId());
1592
- });
1605
+ if (cartItems !== null && cartItems !== void 0 && cartItems[0].start_date && !dateRange) {
1606
+ var _cartItems$, _cartItems$2;
1607
+ dateRange = [{
1608
+ date: cartItems === null || cartItems === void 0 ? void 0 : cartItems[0].start_date,
1609
+ status: 'available',
1610
+ week: '',
1611
+ weekNum: 0
1612
+ }, {
1613
+ date: (cartItems === null || cartItems === void 0 || (_cartItems$ = cartItems[0]) === null || _cartItems$ === void 0 ? void 0 : _cartItems$.end_date) || (cartItems === null || cartItems === void 0 || (_cartItems$2 = cartItems[0]) === null || _cartItems$2 === void 0 ? void 0 : _cartItems$2.start_date) || '',
1614
+ status: 'available',
1615
+ week: '',
1616
+ weekNum: 0
1617
+ }];
1618
+ }
1593
1619
  var timeSlots = getTimeSlicesByResources({
1594
1620
  resourceIds: resourceIds,
1595
1621
  resourcesMap: resourcesMap,
@@ -1624,9 +1650,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1624
1650
  accountItems.forEach(function (item, index) {
1625
1651
  var newResources = cloneDeep(item._origin.resources);
1626
1652
  newResources.forEach(function (resource) {
1627
- var _item$_productOrigin$4, _item$_productOrigin10, _ref12, _item$_productOrigin11;
1653
+ var _item$_productOrigin$4, _item$_productOrigin11, _ref12, _item$_productOrigin12;
1628
1654
  resource.startTime = currentStartTime;
1629
- resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$4 = (_item$_productOrigin10 = item._productOrigin) === null || _item$_productOrigin10 === void 0 || (_item$_productOrigin10 = _item$_productOrigin10.duration) === null || _item$_productOrigin10 === void 0 ? void 0 : _item$_productOrigin10.value) !== null && _item$_productOrigin$4 !== void 0 ? _item$_productOrigin$4 : 0, (_ref12 = (_item$_productOrigin11 = item._productOrigin) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.duration) === null || _item$_productOrigin11 === void 0 ? void 0 : _item$_productOrigin11.type) !== null && _ref12 !== void 0 ? _ref12 : 'minutes').format('YYYY-MM-DD HH:mm');
1655
+ resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$4 = (_item$_productOrigin11 = item._productOrigin) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.duration) === null || _item$_productOrigin11 === void 0 ? void 0 : _item$_productOrigin11.value) !== null && _item$_productOrigin$4 !== void 0 ? _item$_productOrigin$4 : 0, (_ref12 = (_item$_productOrigin12 = item._productOrigin) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.duration) === null || _item$_productOrigin12 === void 0 ? void 0 : _item$_productOrigin12.type) !== null && _ref12 !== void 0 ? _ref12 : 'minutes').format('YYYY-MM-DD HH:mm');
1630
1656
  delete resource.times;
1631
1657
  });
1632
1658
  _this9.store.cart.updateItem({
@@ -1713,7 +1739,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1713
1739
  var date = _ref13.date,
1714
1740
  scheduleIds = _ref13.scheduleIds,
1715
1741
  resources = _ref13.resources;
1716
- debugger;
1717
1742
  var targetProduct = this.store.currentProduct;
1718
1743
  var targetProductData = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData();
1719
1744
  var targetSchedules = [];
@@ -1758,8 +1783,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1758
1783
  currentCount: 1
1759
1784
  });
1760
1785
  // 如果资源可用,且是独占资源,remainingCapacity 始终为 1
1761
- if (res.usable) {
1762
- count += (res === null || res === void 0 ? void 0 : res.remainingCapacity) || 0;
1786
+ if (res.usable && res.remainingCapacity >= count) {
1787
+ count = res.remainingCapacity;
1763
1788
  }
1764
1789
  });
1765
1790
  });
@@ -126,24 +126,24 @@ var checkCapacity = function checkCapacity(_ref) {
126
126
  });
127
127
  });
128
128
 
129
+ // 减去重叠的总量
130
+ var conflictCount = getUseableEventCount(conflict, resource.capacity);
131
+
129
132
  // 同一时间段内只能进行一个预约,无论容量是否已满。
130
133
  if (resource.resourceType === 'single') {
131
134
  // 0代表着不重叠,则满足条件
132
135
  if (conflict.length === 0) {
133
136
  return {
134
137
  status: true,
135
- capacity: 1
138
+ capacity: conflictCount
136
139
  };
137
140
  } else {
138
141
  return {
139
142
  status: false,
140
- capacity: 1
143
+ capacity: conflictCount
141
144
  };
142
145
  }
143
146
  } else {
144
- // 减去重叠的总量
145
- var conflictCount = getUseableEventCount(conflict, resource.capacity);
146
-
147
147
  // 当前预约量 <= 总剩余容量
148
148
  if (currentCount <= conflictCount) {
149
149
  return {
@@ -533,7 +533,6 @@ export var getOthersCartSelectedResources = function getOthersCartSelectedResour
533
533
  if (d._id !== cartItemId) {
534
534
  var _d$_origin2;
535
535
  if ((_d$_origin2 = d._origin) !== null && _d$_origin2 !== void 0 && _d$_origin2.resources) {
536
- debugger;
537
536
  d._origin.resources.forEach(function (n) {
538
537
  // 如果是组合资源,还需要检查组合资源里子资源是否被占用过
539
538
  if (n.metadata.combined_resource && n.metadata.combined_resource.status === 1) {
@@ -643,13 +642,19 @@ export var getSumCapacity = function getSumCapacity(_ref7) {
643
642
  */
644
643
  export var checkSubResourcesCapacity = function checkSubResourcesCapacity(resource) {
645
644
  if (resource.children && resource.children.length) {
646
- var countCapacity = resource.capacity;
647
- resource.children.forEach(function (child) {
645
+ var countCapacity = resource.capacity; // 100
646
+ resource.children.forEach(function (child, index) {
647
+ if (index === resource.children.length - 1) {
648
+ // 如果是最后一个资源,直接拿剩余未分配完的容量去占用
649
+ // 哪怕这个东西会超过资源本身的 capacity也得让他占,PRD 里有写
650
+ child.capacity = countCapacity;
651
+ return;
652
+ }
648
653
  if (child.capacity <= countCapacity) {
649
- countCapacity -= child.capacity;
654
+ countCapacity -= child.capacity; // 100 - = 90
650
655
  } else {
651
- child.capacity = countCapacity;
652
- countCapacity = 0;
656
+ child.capacity = countCapacity; // 10
657
+ countCapacity = 0; // 0
653
658
  }
654
659
  });
655
660
  }
@@ -176,6 +176,8 @@ export interface IUpdateItemParams {
176
176
  quantity?: number;
177
177
  /** 资源 */
178
178
  resources?: Resource[];
179
+ /** 元数据 */
180
+ metadata?: any;
179
181
  /** 备注 */
180
182
  note?: string;
181
183
  /** 日期 */
@@ -427,6 +427,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
427
427
  const cartItems = this.store.cart.getItems();
428
428
  const newCartItems = (0, import_lodash_es.cloneDeep)(cartItems);
429
429
  newCartItems.forEach((item) => {
430
+ var _a;
430
431
  item._origin.resources = item._origin.resources.map((n) => {
431
432
  const newResourcesItem = (0, import_lodash_es.cloneDeep)(n);
432
433
  delete newResourcesItem.id;
@@ -434,6 +435,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
434
435
  delete newResourcesItem.resourceType;
435
436
  return { ...newResourcesItem };
436
437
  });
438
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
439
+ capacity: (_a = item._productOrigin) == null ? void 0 : _a.capacity,
440
+ product_bundle: item._origin.product.product_bundle
441
+ });
442
+ item._origin.metadata.capacity = formatCapacity;
437
443
  });
438
444
  return this.store.order.submitOrder({ query: { cartItems: newCartItems } });
439
445
  }
@@ -455,13 +461,19 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
455
461
  }
456
462
  // 更新购物车
457
463
  updateCart(params) {
464
+ var _a;
458
465
  const targetCartItem = this.store.cart.getItem(params._id);
459
466
  if (!targetCartItem) {
460
467
  throw new Error(`没有找到${params._id}购物车商品`);
461
468
  }
462
469
  if (params.resources) {
470
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
471
+ capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
472
+ product_bundle: targetCartItem._origin.product.product_bundle
473
+ });
474
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
463
475
  params.resources = params.resources.map((n) => {
464
- n.capacity = targetCartItem.num || 1;
476
+ n.capacity = currentCapacity || 1;
465
477
  (0, import_resources.checkSubResourcesCapacity)(n);
466
478
  return n;
467
479
  });
@@ -469,14 +481,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
469
481
  this.store.cart.updateItem(params);
470
482
  const cartItems = this.store.cart.getItems();
471
483
  cartItems.forEach((item) => {
472
- var _a;
484
+ var _a2;
473
485
  if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
474
- const resources = (_a = item._origin.resources) == null ? void 0 : _a.filter((m) => {
486
+ const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
475
487
  return !targetCartItem._origin.resources.some((targetRes) => {
476
- var _a2, _b;
488
+ var _a3, _b;
477
489
  if (targetRes.id === m.id)
478
490
  return true;
479
- if (((_a2 = targetRes.metadata.combined_resource) == null ? void 0 : _a2.status) === 1 && targetRes.metadata.combined_resource.resource_ids.includes(m.id))
491
+ if (((_a3 = targetRes.metadata.combined_resource) == null ? void 0 : _a3.status) === 1 && targetRes.metadata.combined_resource.resource_ids.includes(m.id))
480
492
  return true;
481
493
  if (((_b = m.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
482
494
  return true;
@@ -571,6 +583,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
571
583
  capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
572
584
  product_bundle: cartItem._origin.product.product_bundle
573
585
  });
586
+ cartItem._origin.metadata.capacity = formatCapacity;
574
587
  const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
575
588
  const productResources = (0, import_resources.getResourcesByProduct)(
576
589
  resourcesMap,
@@ -941,13 +954,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
941
954
  }
942
955
  // 从购物车中获取已经分配好第一步资源的所有时间片
943
956
  getTimeSlotByAllResources(resources_code) {
944
- const dateRange = this.store.date.getDateRange();
957
+ var _a, _b;
958
+ let dateRange = this.store.date.getDateRange();
945
959
  const resources = [];
946
960
  const cartItems = this.store.cart.getItems();
947
961
  const resourceIds = [];
948
962
  cartItems.forEach((item) => {
949
- var _a, _b, _c;
950
- (_c = (_b = (_a = item._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.forEach((n) => {
963
+ var _a2, _b2, _c;
964
+ (_c = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c.forEach((n) => {
951
965
  if (n.code === resources_code) {
952
966
  resources.push(...n.renderList || []);
953
967
  }
@@ -962,8 +976,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
962
976
  const checkDuration = (cartItems2) => {
963
977
  let accountDuration = 0;
964
978
  cartItems2.forEach((item) => {
965
- var _a, _b;
966
- accountDuration += ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0;
979
+ var _a2, _b2;
980
+ accountDuration += ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) ?? 0;
967
981
  });
968
982
  if (accountDuration > duration) {
969
983
  duration = accountDuration;
@@ -977,9 +991,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
977
991
  } else {
978
992
  checkDuration(cartItems);
979
993
  }
980
- this.store.accountList.getAccounts().forEach((account) => {
981
- const cartItems2 = this.store.cart.getCartByAccount(account.getId());
982
- });
994
+ if ((cartItems == null ? void 0 : cartItems[0].start_date) && !dateRange) {
995
+ dateRange = [
996
+ {
997
+ date: cartItems == null ? void 0 : cartItems[0].start_date,
998
+ status: "available",
999
+ week: "",
1000
+ weekNum: 0
1001
+ },
1002
+ {
1003
+ date: ((_a = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _a.end_date) || ((_b = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _b.start_date) || "",
1004
+ status: "available",
1005
+ week: "",
1006
+ weekNum: 0
1007
+ }
1008
+ ];
1009
+ }
983
1010
  const timeSlots = (0, import_resources.getTimeSlicesByResources)({
984
1011
  resourceIds,
985
1012
  resourcesMap,
@@ -1070,7 +1097,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1070
1097
  resources
1071
1098
  }) {
1072
1099
  var _a, _b, _c;
1073
- debugger;
1074
1100
  const targetProduct = this.store.currentProduct;
1075
1101
  const targetProductData = targetProduct == null ? void 0 : targetProduct.getData();
1076
1102
  let targetSchedules = [];
@@ -1119,8 +1145,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1119
1145
  resource: m,
1120
1146
  currentCount: 1
1121
1147
  });
1122
- if (res.usable) {
1123
- count += (res == null ? void 0 : res.remainingCapacity) || 0;
1148
+ if (res.usable && res.remainingCapacity >= count) {
1149
+ count = res.remainingCapacity;
1124
1150
  }
1125
1151
  });
1126
1152
  });
@@ -93,20 +93,20 @@ var checkCapacity = ({
93
93
  { start_at: timeSlice.start_at, end_at: timeSlice.end_at }
94
94
  );
95
95
  });
96
+ let conflictCount = getUseableEventCount(conflict, resource.capacity);
96
97
  if (resource.resourceType === "single") {
97
98
  if (conflict.length === 0) {
98
99
  return {
99
100
  status: true,
100
- capacity: 1
101
+ capacity: conflictCount
101
102
  };
102
103
  } else {
103
104
  return {
104
105
  status: false,
105
- capacity: 1
106
+ capacity: conflictCount
106
107
  };
107
108
  }
108
109
  } else {
109
- let conflictCount = getUseableEventCount(conflict, resource.capacity);
110
110
  if (currentCount <= conflictCount) {
111
111
  return {
112
112
  status: true,
@@ -385,7 +385,6 @@ var getOthersCartSelectedResources = (cartItems, cartItemId, resourcesMap) => {
385
385
  var _a;
386
386
  if (d._id !== cartItemId) {
387
387
  if ((_a = d._origin) == null ? void 0 : _a.resources) {
388
- debugger;
389
388
  d._origin.resources.forEach((n) => {
390
389
  if (n.metadata.combined_resource && n.metadata.combined_resource.status === 1) {
391
390
  if (n.metadata.combined_resource.resource_ids.some(
@@ -453,7 +452,11 @@ var getSumCapacity = ({ capacity }) => {
453
452
  var checkSubResourcesCapacity = (resource) => {
454
453
  if (resource.children && resource.children.length) {
455
454
  let countCapacity = resource.capacity;
456
- resource.children.forEach((child) => {
455
+ resource.children.forEach((child, index) => {
456
+ if (index === resource.children.length - 1) {
457
+ child.capacity = countCapacity;
458
+ return;
459
+ }
457
460
  if (child.capacity <= countCapacity) {
458
461
  countCapacity -= child.capacity;
459
462
  } else {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.55",
4
+ "version": "0.0.57",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",