@pisell/pisellos 3.0.35 → 3.0.36

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 (49) hide show
  1. package/dist/modules/Cart/index.js +20 -34
  2. package/dist/modules/Cart/utils/cartAccount.d.ts +21 -0
  3. package/dist/modules/Cart/utils/cartAccount.js +52 -0
  4. package/dist/modules/Cart/utils/cartDate.d.ts +31 -0
  5. package/dist/modules/Cart/utils/cartDate.js +55 -0
  6. package/dist/modules/Cart/utils/cartDiscount.d.ts +19 -0
  7. package/dist/modules/Cart/utils/cartDiscount.js +35 -0
  8. package/dist/modules/Cart/utils/cartNote.d.ts +19 -0
  9. package/dist/modules/Cart/utils/cartNote.js +29 -0
  10. package/dist/modules/Cart/utils/cartProduct.d.ts +107 -0
  11. package/dist/modules/Cart/{utils.js → utils/cartProduct.js} +77 -416
  12. package/dist/modules/Cart/utils/cartRelationForms.d.ts +26 -0
  13. package/dist/modules/Cart/utils/cartRelationForms.js +29 -0
  14. package/dist/modules/Cart/utils/cartResource.d.ts +21 -0
  15. package/dist/modules/Cart/utils/cartResource.js +102 -0
  16. package/dist/modules/Cart/utils/index.d.ts +34 -0
  17. package/dist/modules/Cart/utils/index.js +63 -0
  18. package/dist/modules/Order/index.js +10 -4
  19. package/dist/modules/Product/types.d.ts +4 -0
  20. package/dist/modules/Product/utils.d.ts +17 -0
  21. package/dist/modules/Product/utils.js +41 -0
  22. package/dist/solution/BookingByStep/index.d.ts +8 -1
  23. package/dist/solution/BookingByStep/index.js +182 -63
  24. package/lib/modules/Cart/index.js +16 -24
  25. package/lib/modules/Cart/utils/cartAccount.d.ts +21 -0
  26. package/lib/modules/Cart/utils/cartAccount.js +65 -0
  27. package/lib/modules/Cart/utils/cartDate.d.ts +31 -0
  28. package/lib/modules/Cart/utils/cartDate.js +75 -0
  29. package/lib/modules/Cart/utils/cartDiscount.d.ts +19 -0
  30. package/lib/modules/Cart/utils/cartDiscount.js +52 -0
  31. package/lib/modules/Cart/utils/cartNote.d.ts +19 -0
  32. package/lib/modules/Cart/utils/cartNote.js +46 -0
  33. package/lib/modules/Cart/utils/cartProduct.d.ts +107 -0
  34. package/lib/modules/Cart/{utils.js → utils/cartProduct.js} +78 -328
  35. package/lib/modules/Cart/utils/cartRelationForms.d.ts +26 -0
  36. package/lib/modules/Cart/utils/cartRelationForms.js +48 -0
  37. package/lib/modules/Cart/utils/cartResource.d.ts +21 -0
  38. package/lib/modules/Cart/utils/cartResource.js +124 -0
  39. package/lib/modules/Cart/utils/index.d.ts +34 -0
  40. package/lib/modules/Cart/utils/index.js +91 -0
  41. package/lib/modules/Order/index.js +7 -3
  42. package/lib/modules/Product/types.d.ts +4 -0
  43. package/lib/modules/Product/utils.d.ts +17 -0
  44. package/lib/modules/Product/utils.js +46 -0
  45. package/lib/solution/BookingByStep/index.d.ts +8 -1
  46. package/lib/solution/BookingByStep/index.js +106 -40
  47. package/package.json +1 -1
  48. package/dist/modules/Cart/utils.d.ts +0 -257
  49. package/lib/modules/Cart/utils.d.ts +0 -257
@@ -37,6 +37,7 @@ import { getResourcesMap } from "../../modules/Resource/utils";
37
37
  import { cloneDeep } from 'lodash-es';
38
38
  import { calcCalendarDataByScheduleResult, calcMinTimeMaxTimeBySchedules, getAllSortedDateRanges } from "../../modules/Schedule/utils";
39
39
  import { disableAllDates, disableDatesBeforeOneDay, generateMonthDates, handleAvailableDateByResource } from "../../modules/Date/utils";
40
+ import { areAllNormalProducts, isNormalProduct } from "../../modules/Product/utils";
40
41
  import { calculateResourceAvailableTime, findFastestAvailableResource } from "./utils/timeslots";
41
42
  export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
42
43
  _inherits(BookingByStepImpl, _BaseModule);
@@ -237,7 +238,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
237
238
  return this.request.post("/product/query", {
238
239
  open_quotation: 1,
239
240
  open_bundle: 0,
240
- extension_type: ['product_appointment', 'appointment_ticket', 'session_product', 'session_ticket', 'normal'],
241
+ exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
241
242
  with: ['category', 'collection', 'resourceRelation'],
242
243
  status: 'published',
243
244
  num: 500,
@@ -545,26 +546,48 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
545
546
  key: "storeProduct",
546
547
  value: function () {
547
548
  var _storeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(productData) {
548
- var activeAccount, _ref4, bundle, options, origin, product_variant_id, product, addCartItem;
549
+ var activeAccount, _ref4, bundle, options, origin, product_variant_id, _ref4$quantity, quantity, rowKey, cartItems, targetCartItem, product, addCartItem;
549
550
  return _regeneratorRuntime().wrap(function _callee7$(_context8) {
550
551
  while (1) switch (_context8.prev = _context8.next) {
551
552
  case 0:
552
553
  // 往购物车加商品数据的时候,默认用当前 activeAccount 填充到 product 的 account 里面
553
554
  activeAccount = this.getActiveAccount();
554
- _ref4 = productData || {}, bundle = _ref4.bundle, options = _ref4.options, origin = _ref4.origin, product_variant_id = _ref4.product_variant_id;
555
+ _ref4 = productData || {}, bundle = _ref4.bundle, options = _ref4.options, origin = _ref4.origin, product_variant_id = _ref4.product_variant_id, _ref4$quantity = _ref4.quantity, quantity = _ref4$quantity === void 0 ? 1 : _ref4$quantity, rowKey = _ref4.rowKey; // 检查购物车里是否已经存在 rowKey相同的数据,如果是则更新数量
556
+ cartItems = this.store.cart.getItems();
557
+ if (!rowKey) {
558
+ _context8.next = 8;
559
+ break;
560
+ }
561
+ targetCartItem = cartItems.find(function (n) {
562
+ var _n$_productOrigin;
563
+ return ((_n$_productOrigin = n._productOrigin) === null || _n$_productOrigin === void 0 ? void 0 : _n$_productOrigin.rowKey) === rowKey;
564
+ });
565
+ if (!(targetCartItem && isNormalProduct(targetCartItem._productOrigin))) {
566
+ _context8.next = 8;
567
+ break;
568
+ }
569
+ this.store.cart.updateItem({
570
+ _id: targetCartItem._id,
571
+ product: _objectSpread({}, targetCartItem._productOrigin),
572
+ quantity: (targetCartItem.num || 1) + quantity
573
+ });
574
+ return _context8.abrupt("return");
575
+ case 8:
555
576
  product = _objectSpread(_objectSpread({}, origin), {}, {
556
- product_variant_id: product_variant_id
577
+ product_variant_id: product_variant_id,
578
+ rowKey: rowKey
557
579
  });
558
580
  addCartItem = {
559
581
  product: product,
560
582
  bundle: bundle,
561
- options: options
583
+ options: options,
584
+ quantity: quantity
562
585
  };
563
586
  if (activeAccount) {
564
587
  addCartItem.account = activeAccount;
565
588
  }
566
589
  this.store.cart.addItem(addCartItem);
567
- case 6:
590
+ case 12:
568
591
  case "end":
569
592
  return _context8.stop();
570
593
  }
@@ -735,7 +758,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
735
758
  key: "fetchHolderAccountsAsync",
736
759
  value: (function () {
737
760
  var _fetchHolderAccountsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
738
- var cartItems, _this$store$date$getD, date, _cartItems$;
761
+ var cartItems, _this$store$date$getD, date, normalProductCartItem;
739
762
  return _regeneratorRuntime().wrap(function _callee11$(_context12) {
740
763
  while (1) switch (_context12.prev = _context12.next) {
741
764
  case 0:
@@ -744,7 +767,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
744
767
  date = (_this$store$date$getD = this.store.date.getDateRange()) === null || _this$store$date$getD === void 0 || (_this$store$date$getD = _this$store$date$getD[0]) === null || _this$store$date$getD === void 0 ? void 0 : _this$store$date$getD.date;
745
768
  if (!date) {
746
769
  // 如果没有日期,则应该是 session 类先选商品的流程,直接从购物车里拿 start_date
747
- date = (cartItems === null || cartItems === void 0 || (_cartItems$ = cartItems[0]) === null || _cartItems$ === void 0 ? void 0 : _cartItems$.start_date) || '';
770
+ // 不能从购物车里第一个找时间,而是找到购物车里第一个有 start_date 的时间
771
+ normalProductCartItem = cartItems.find(function (n) {
772
+ return !isNormalProduct(n._productOrigin);
773
+ });
774
+ date = (normalProductCartItem === null || normalProductCartItem === void 0 ? void 0 : normalProductCartItem.start_date) || '';
748
775
  }
749
776
  this.updateQuotationPriceAndCart(date);
750
777
  }
@@ -979,7 +1006,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
979
1006
  value: function () {
980
1007
  var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(accountId, accountInfo) {
981
1008
  var _this5 = this;
982
- var account, stateAccountId, cartItems, _this$store$date$getD2, date, _cartItems$2;
1009
+ var account, stateAccountId, cartItems, _this$store$date$getD2, date, normalProductCartItem;
983
1010
  return _regeneratorRuntime().wrap(function _callee18$(_context19) {
984
1011
  while (1) switch (_context19.prev = _context19.next) {
985
1012
  case 0:
@@ -1006,7 +1033,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1006
1033
  date = (_this$store$date$getD2 = this.store.date.getDateRange()) === null || _this$store$date$getD2 === void 0 || (_this$store$date$getD2 = _this$store$date$getD2[0]) === null || _this$store$date$getD2 === void 0 ? void 0 : _this$store$date$getD2.date;
1007
1034
  if (!date) {
1008
1035
  // 如果没有日期,则应该是 session 类先选商品的流程,直接从购物车里拿 start_date
1009
- date = (cartItems === null || cartItems === void 0 || (_cartItems$2 = cartItems[0]) === null || _cartItems$2 === void 0 ? void 0 : _cartItems$2.start_date) || '';
1036
+ // 不能从购物车里第一个找时间,而是找到购物车里第一个有 start_date 的时间
1037
+ normalProductCartItem = cartItems.find(function (n) {
1038
+ return !isNormalProduct(n._productOrigin);
1039
+ });
1040
+ date = (normalProductCartItem === null || normalProductCartItem === void 0 ? void 0 : normalProductCartItem.start_date) || '';
1010
1041
  }
1011
1042
  this.updateQuotationPriceAndCart(date);
1012
1043
  }
@@ -1115,14 +1146,19 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1115
1146
  item._origin.number = currentCapacity;
1116
1147
  }
1117
1148
  });
1118
- type = this.otherParams.isRetailTemplate ? 'virtual' : 'appointment_booking';
1149
+ type = this.otherParams.isRetailTemplate ? 'virtual' : 'appointment_booking'; // 如果购物车里全都是普通商品,type 也应该为 virtual
1150
+ if (areAllNormalProducts(newCartItems.map(function (n) {
1151
+ return n._productOrigin;
1152
+ }))) {
1153
+ type = 'virtual';
1154
+ }
1119
1155
  return _context22.abrupt("return", this.store.order.submitOrder({
1120
1156
  query: {
1121
1157
  cartItems: newCartItems,
1122
1158
  type: type
1123
1159
  }
1124
1160
  }));
1125
- case 5:
1161
+ case 6:
1126
1162
  case "end":
1127
1163
  return _context22.stop();
1128
1164
  }
@@ -1394,7 +1430,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1394
1430
  key: "checkCartItems",
1395
1431
  value: function checkCartItems(type) {
1396
1432
  var _this8 = this;
1397
- var cartItems = this.store.cart.getItems();
1433
+ // 预约流程中普通商品无需检测这些东西
1434
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1435
+ return !isNormalProduct(n._productOrigin);
1436
+ });
1398
1437
  var errorCartItemIds = [];
1399
1438
  cartItems.forEach(function (cartItem) {
1400
1439
  var result = _this8.store.cart.checkCartItemByType(cartItem, type);
@@ -1437,7 +1476,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1437
1476
  });
1438
1477
  }
1439
1478
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1440
- var cartItems = this.store.cart.getItems();
1479
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1480
+ return !isNormalProduct(n._productOrigin);
1481
+ });
1441
1482
  var arr = [];
1442
1483
  cartItems.forEach(function (cartItem) {
1443
1484
  var _cartItem$_productOri, _cartItem$_productOri2;
@@ -1562,7 +1603,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1562
1603
  });
1563
1604
  }
1564
1605
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1565
- var cartItems = this.store.cart.getItems();
1606
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1607
+ return !isNormalProduct(n._productOrigin);
1608
+ });
1566
1609
  var arr = [];
1567
1610
  cartItems.forEach(function (cartItem) {
1568
1611
  var _cartItem$_productOri5, _cartItem$_productOri6;
@@ -1676,7 +1719,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1676
1719
  key: "getResourcesListByCartItem",
1677
1720
  value: function getResourcesListByCartItem(id) {
1678
1721
  var _targetCartItem$_prod2, _targetCartItem$_prod3;
1679
- var cartItems = cloneDeep(this.store.cart.getItems());
1722
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1723
+ return !isNormalProduct(n._productOrigin);
1724
+ });
1680
1725
  var dateRange = this.store.date.getDateRange();
1681
1726
  var resources = [];
1682
1727
  dateRange.forEach(function (n) {
@@ -1755,6 +1800,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1755
1800
  timeSlots = _ref8.timeSlots,
1756
1801
  countMap = _ref8.countMap,
1757
1802
  capacity = _ref8.capacity;
1803
+ if (isNormalProduct(cartItem._productOrigin)) {
1804
+ return {};
1805
+ }
1758
1806
  var dateRange = this.store.date.getDateRange();
1759
1807
  var cartItems = cloneDeep(this.store.cart.getItems());
1760
1808
  // 取到账号下所有的商品,然后根据商品的 duration 和资源列表,获取所有可用的资源
@@ -1767,8 +1815,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1767
1815
  }
1768
1816
  // duration=所有商品时间的集合
1769
1817
  var duration = accountCartItems.reduce(function (acc, n) {
1770
- var _n$_productOrigin$dur, _n$_productOrigin;
1771
- return acc + ((_n$_productOrigin$dur = (_n$_productOrigin = n._productOrigin) === null || _n$_productOrigin === void 0 || (_n$_productOrigin = _n$_productOrigin.duration) === null || _n$_productOrigin === void 0 ? void 0 : _n$_productOrigin.value) !== null && _n$_productOrigin$dur !== void 0 ? _n$_productOrigin$dur : 0);
1818
+ var _n$_productOrigin$dur, _n$_productOrigin2;
1819
+ return acc + ((_n$_productOrigin$dur = (_n$_productOrigin2 = n._productOrigin) === null || _n$_productOrigin2 === void 0 || (_n$_productOrigin2 = _n$_productOrigin2.duration) === null || _n$_productOrigin2 === void 0 ? void 0 : _n$_productOrigin2.value) !== null && _n$_productOrigin$dur !== void 0 ? _n$_productOrigin$dur : 0);
1772
1820
  }, 0);
1773
1821
  // 正常来说,能进这个业务的所有商品的 duration 类型都是一样的,所以这里取第一个商品的 duration 类型
1774
1822
  // let durationType = accountCartItems[0]?._productOrigin?.duration?.type ?? "minutes";
@@ -2099,7 +2147,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2099
2147
  }
2100
2148
  });
2101
2149
  };
2102
- var cartItems = cloneDeep(this.store.cart.getItems());
2150
+ var cartItems = this.store.cart.getItems().filter(function (n) {
2151
+ return !isNormalProduct(n._productOrigin);
2152
+ });
2103
2153
 
2104
2154
  // 如果购物车里没有 holderid数据,证明不按 holder 类流程预约走,给所有购物车一次性分派即可,不做账号下资源互斥逻辑
2105
2155
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
@@ -2120,12 +2170,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2120
2170
  value: function getTimeSlotByAllResources(resources_code) {
2121
2171
  var _dateRange,
2122
2172
  _this10 = this,
2123
- _cartItems$3,
2124
- _cartItems$4;
2173
+ _cartItems$,
2174
+ _cartItems$2;
2125
2175
  var dateRange = this.store.date.getDateRange();
2126
2176
  // 取出购物车中所有一已选择的第一步资源
2127
2177
  var resources = [];
2128
- var cartItems = cloneDeep(this.store.cart.getItems());
2178
+ var cartItems = this.store.cart.getItems().filter(function (n) {
2179
+ return !isNormalProduct(n._productOrigin);
2180
+ });
2129
2181
  // if (cartItems?.[0].start_date) return [];
2130
2182
  var resourceIds = [];
2131
2183
  var resourcesTypeId = undefined;
@@ -2204,18 +2256,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2204
2256
  }
2205
2257
  // 如果 cartItem 上既没有时间,也没有资源,认为外部属于异常调用,直接丢一个空数组出去
2206
2258
  // 同时 session 类商品的流程也不应该调用这个方法
2207
- if (!(cartItems !== null && cartItems !== void 0 && (_cartItems$3 = cartItems[0]) !== null && _cartItems$3 !== void 0 && _cartItems$3.start_date) && !(cartItems !== null && cartItems !== void 0 && (_cartItems$4 = cartItems[0]) !== null && _cartItems$4 !== void 0 && _cartItems$4.resource_id) || !(cartItems !== null && cartItems !== void 0 && cartItems[0].duration)) {
2259
+ if (!(cartItems !== null && cartItems !== void 0 && (_cartItems$ = cartItems[0]) !== null && _cartItems$ !== void 0 && _cartItems$.start_date) && !(cartItems !== null && cartItems !== void 0 && (_cartItems$2 = cartItems[0]) !== null && _cartItems$2 !== void 0 && _cartItems$2.resource_id) || !(cartItems !== null && cartItems !== void 0 && cartItems[0].duration)) {
2208
2260
  return [];
2209
2261
  }
2210
2262
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].start_date && !dateRange) {
2211
- var _cartItems$5, _cartItems$6;
2263
+ var _cartItems$3, _cartItems$4;
2212
2264
  dateRange = [{
2213
2265
  date: cartItems === null || cartItems === void 0 ? void 0 : cartItems[0].start_date,
2214
2266
  status: 'available',
2215
2267
  week: '',
2216
2268
  weekNum: 0
2217
2269
  }, {
2218
- date: (cartItems === null || cartItems === void 0 || (_cartItems$5 = cartItems[0]) === null || _cartItems$5 === void 0 ? void 0 : _cartItems$5.end_date) || (cartItems === null || cartItems === void 0 || (_cartItems$6 = cartItems[0]) === null || _cartItems$6 === void 0 ? void 0 : _cartItems$6.start_date) || '',
2270
+ date: (cartItems === null || cartItems === void 0 || (_cartItems$3 = cartItems[0]) === null || _cartItems$3 === void 0 ? void 0 : _cartItems$3.end_date) || (cartItems === null || cartItems === void 0 || (_cartItems$4 = cartItems[0]) === null || _cartItems$4 === void 0 ? void 0 : _cartItems$4.start_date) || '',
2219
2271
  status: 'available',
2220
2272
  week: '',
2221
2273
  weekNum: 0
@@ -2240,7 +2292,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2240
2292
  value: function submitTimeSlot(timeSlots) {
2241
2293
  var _this11 = this;
2242
2294
  // 以账号为维度处理数据。购物车里每一项的 startTime应该是前一个商品的 endTime,如果是第一个商品则用 timeSlots.start_at
2243
- var cartItems = cloneDeep(this.store.cart.getItems());
2295
+ var cartItems = this.store.cart.getItems().filter(function (n) {
2296
+ return !isNormalProduct(n._productOrigin);
2297
+ });
2244
2298
 
2245
2299
  // 按账号分组
2246
2300
  var itemsByAccount = cartItems.reduce(function (acc, item) {
@@ -2348,7 +2402,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2348
2402
  }, {
2349
2403
  key: "getTimeslotBySchedule",
2350
2404
  value: function getTimeslotBySchedule(_ref12) {
2351
- var _this$store$currentPr2;
2405
+ var _this$store$currentPr2, _targetProductData$pr;
2352
2406
  var date = _ref12.date,
2353
2407
  scheduleIds = _ref12.scheduleIds,
2354
2408
  resources = _ref12.resources,
@@ -2387,6 +2441,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2387
2441
  return 0;
2388
2442
  });
2389
2443
 
2444
+ // 找到当前商品下第一个启用的资源id
2445
+ var firstEnabledResourceId = targetProductData === null || targetProductData === void 0 || (_targetProductData$pr = targetProductData.product_resource) === null || _targetProductData$pr === void 0 || (_targetProductData$pr = _targetProductData$pr.resources) === null || _targetProductData$pr === void 0 || (_targetProductData$pr = _targetProductData$pr.find(function (n) {
2446
+ return n.status === 1;
2447
+ })) === null || _targetProductData$pr === void 0 ? void 0 : _targetProductData$pr.id;
2448
+
2390
2449
  // 计算每个日程切片下日程可用的资源的容量总和
2391
2450
  var formatScheduleTimeSlots = scheduleTimeSlots.map(function (item) {
2392
2451
  // 用来计算资源的可使用情况,针对单个schedule 时间片
@@ -2434,7 +2493,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2434
2493
  // 在已经选定时间的情况下,只要canUseTime如果有一个 false 那就不可用
2435
2494
  if (!currentResourcesTimeSlotCanUsedArr.some(function (n) {
2436
2495
  return n === false;
2437
- })) {
2496
+ })
2497
+ // 只统计第一种资源的容量和 left
2498
+ && m.form_id === firstEnabledResourceId) {
2438
2499
  if (currentResourcesCount >= count) {
2439
2500
  count = currentResourcesCount;
2440
2501
  }
@@ -2467,7 +2528,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2467
2528
  bundle = _ref14.bundle,
2468
2529
  options = _ref14.options,
2469
2530
  origin = _ref14.origin,
2470
- product_variant_id = _ref14.product_variant_id;
2531
+ product_variant_id = _ref14.product_variant_id,
2532
+ rowKey = _ref14.rowKey,
2533
+ _ref14$quantity = _ref14.quantity,
2534
+ quantity = _ref14$quantity === void 0 ? 1 : _ref14$quantity;
2471
2535
  var productData = _objectSpread(_objectSpread({}, origin), {}, {
2472
2536
  product_variant_id: product_variant_id
2473
2537
  });
@@ -2477,17 +2541,36 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2477
2541
  account = activeAccount;
2478
2542
  }
2479
2543
  }
2544
+ if (rowKey) {
2545
+ var cartItems = this.store.cart.getItems();
2546
+ var targetCartItem = cartItems.find(function (n) {
2547
+ var _n$_productOrigin3;
2548
+ return ((_n$_productOrigin3 = n._productOrigin) === null || _n$_productOrigin3 === void 0 ? void 0 : _n$_productOrigin3.rowKey) === rowKey;
2549
+ });
2550
+ if (targetCartItem && isNormalProduct(targetCartItem._productOrigin)) {
2551
+ this.store.cart.updateItem({
2552
+ _id: targetCartItem._id,
2553
+ product: _objectSpread(_objectSpread({}, targetCartItem._productOrigin), {}, {
2554
+ quantity: (targetCartItem.num || 1) + quantity
2555
+ })
2556
+ });
2557
+ return;
2558
+ }
2559
+ }
2480
2560
  this.store.cart.addItem({
2481
2561
  product: productData,
2482
2562
  date: date,
2483
2563
  account: account,
2484
2564
  bundle: bundle,
2485
- options: options
2565
+ options: options,
2566
+ quantity: quantity
2486
2567
  });
2487
2568
  // 检测,有传递 date,检查购物车里其他商品的 date 是否在同一天,如果不在,清空那些不在同一天的商品
2488
2569
  if (date) {
2489
- var cartItems = cloneDeep(this.store.cart.getItems());
2490
- var cartItemsByDate = cartItems.filter(function (n) {
2570
+ var _cartItems = this.store.cart.getItems().filter(function (n) {
2571
+ return !isNormalProduct(n._productOrigin);
2572
+ });
2573
+ var cartItemsByDate = _cartItems.filter(function (n) {
2491
2574
  return !dayjs(n.start_date).isSame(dayjs(date.startTime), 'day');
2492
2575
  });
2493
2576
  if (cartItemsByDate.length) {
@@ -2571,7 +2654,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2571
2654
  });
2572
2655
  }
2573
2656
  var resourcesMap = getResourcesMap(cloneDeep(resources));
2574
- var cartItems = this.store.cart.getItems();
2657
+ var cartItems = this.store.cart.getItems().filter(function (n) {
2658
+ return !isNormalProduct(n._productOrigin);
2659
+ });
2575
2660
  var cartItem = cartItems.find(function (item) {
2576
2661
  return item._id === cartItemId;
2577
2662
  });
@@ -2802,7 +2887,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2802
2887
  var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2803
2888
  var _this$store$currentPr3, _this$store$currentPr4, _this$store$currentPr5, _tempProducts, _this$store$currentPr6;
2804
2889
  var params,
2805
- cache,
2806
2890
  startDate,
2807
2891
  endDate,
2808
2892
  tempProducts,
@@ -2810,6 +2894,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2810
2894
  filteredSchedule,
2811
2895
  tempResourceIds,
2812
2896
  res,
2897
+ cache,
2813
2898
  dates,
2814
2899
  currentDate,
2815
2900
  firstAvailableDate,
@@ -2822,21 +2907,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2822
2907
  while (1) switch (_context32.prev = _context32.next) {
2823
2908
  case 0:
2824
2909
  params = _args32.length > 0 && _args32[0] !== undefined ? _args32[0] : {};
2825
- // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2826
- cache = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getOtherParams()['timeSlotBySchedule'];
2827
- if (!cache) {
2828
- _context32.next = 5;
2829
- break;
2830
- }
2831
- if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2832
- _context32.next = 5;
2833
- break;
2834
- }
2835
- return _context32.abrupt("return", {
2836
- dateList: cache.dateList,
2837
- firstAvailableDate: cache.firstAvailableDate
2838
- });
2839
- case 5:
2840
2910
  // 开始日期如果小于今天,直接以今天当做开始日期
2841
2911
  startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2842
2912
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
@@ -2845,11 +2915,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2845
2915
  // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2846
2916
  endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2847
2917
  // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2848
- tempProducts = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getData();
2849
- schedule = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['schedule'];
2918
+ tempProducts = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getData();
2919
+ schedule = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getOtherParams()['schedule'];
2850
2920
  filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2851
2921
  tempResourceIds = getResourcesIdsByProduct(tempProducts);
2852
- _context32.next = 14;
2922
+ _context32.next = 10;
2853
2923
  return this.store.date.fetchResourceDates({
2854
2924
  query: {
2855
2925
  start_date: startDate || '',
@@ -2857,8 +2927,25 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2857
2927
  resource_ids: tempResourceIds
2858
2928
  }
2859
2929
  });
2860
- case 14:
2930
+ case 10:
2861
2931
  res = _context32.sent;
2932
+ // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2933
+ // TODO 优化关于为什么要放在接口后,因为在获取时间切片的时候还需要读一次接口数据,其实可以直接从这个结果里拿了,需要优化
2934
+ cache = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['timeSlotBySchedule'];
2935
+ if (!cache) {
2936
+ _context32.next = 16;
2937
+ break;
2938
+ }
2939
+ if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2940
+ _context32.next = 16;
2941
+ break;
2942
+ }
2943
+ this.store.date.setDateList(cache.dateList);
2944
+ return _context32.abrupt("return", {
2945
+ dateList: cache.dateList,
2946
+ firstAvailableDate: cache.firstAvailableDate
2947
+ });
2948
+ case 16:
2862
2949
  // 2. 商品 schedule 数据,确定日程在每一天的时间片
2863
2950
  // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
2864
2951
  dates = [];
@@ -2985,22 +3072,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2985
3072
  }
2986
3073
  }, _loop3);
2987
3074
  });
2988
- case 23:
3075
+ case 24:
2989
3076
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
2990
- _context32.next = 29;
3077
+ _context32.next = 30;
2991
3078
  break;
2992
3079
  }
2993
- return _context32.delegateYield(_loop3(), "t0", 25);
2994
- case 25:
3080
+ return _context32.delegateYield(_loop3(), "t0", 26);
3081
+ case 26:
2995
3082
  if (!_context32.t0) {
2996
- _context32.next = 27;
3083
+ _context32.next = 28;
2997
3084
  break;
2998
3085
  }
2999
- return _context32.abrupt("break", 29);
3000
- case 27:
3001
- _context32.next = 23;
3086
+ return _context32.abrupt("break", 30);
3087
+ case 28:
3088
+ _context32.next = 24;
3002
3089
  break;
3003
- case 29:
3090
+ case 30:
3004
3091
  // 最终把资源数据也加到日期内
3005
3092
  dates = handleAvailableDateByResource(res.data, dates);
3006
3093
  this.store.date.setDateList(dates);
@@ -3016,7 +3103,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3016
3103
  dateList: dates,
3017
3104
  firstAvailableDate: firstAvailableDate
3018
3105
  });
3019
- case 33:
3106
+ case 34:
3020
3107
  case "end":
3021
3108
  return _context32.stop();
3022
3109
  }
@@ -3027,6 +3114,38 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3027
3114
  }
3028
3115
  return getAvailableDateForSessionOptimize;
3029
3116
  }()
3117
+ }, {
3118
+ key: "isCartAllNormalProducts",
3119
+ value: function isCartAllNormalProducts() {
3120
+ var cartItems = this.store.cart.getItems().filter(function (n) {
3121
+ return !isNormalProduct(n._productOrigin);
3122
+ });
3123
+ return !cartItems.length;
3124
+ }
3125
+ }, {
3126
+ key: "isCartHasDurationProduct",
3127
+ value: function isCartHasDurationProduct() {
3128
+ var cartItems = this.store.cart.getItems().filter(function (n) {
3129
+ return !isNormalProduct(n._productOrigin);
3130
+ });
3131
+ return cartItems.some(function (n) {
3132
+ var _n$_productOrigin4;
3133
+ return (_n$_productOrigin4 = n._productOrigin) === null || _n$_productOrigin4 === void 0 ? void 0 : _n$_productOrigin4.duration;
3134
+ });
3135
+ }
3136
+ }, {
3137
+ key: "isTargetNormalProduct",
3138
+ value: function isTargetNormalProduct(product) {
3139
+ return isNormalProduct(product);
3140
+ }
3141
+ }, {
3142
+ key: "isTargetCartIdNormalProduct",
3143
+ value: function isTargetCartIdNormalProduct(id) {
3144
+ var cartItem = this.store.cart.getItems().find(function (n) {
3145
+ return n._id === id;
3146
+ });
3147
+ return cartItem && isNormalProduct(cartItem._productOrigin);
3148
+ }
3030
3149
  }]);
3031
3150
  return BookingByStepImpl;
3032
3151
  }(BaseModule);
@@ -70,30 +70,24 @@ var CartModule = class extends import_BaseModule.BaseModule {
70
70
  * 添加商品到购物车
71
71
  */
72
72
  async addItem(params) {
73
- const { account, product, bundle, options, date } = params;
73
+ const { account, product, bundle, options, date, quantity = 1 } = params;
74
74
  let cartItem = {
75
75
  _id: (0, import_utils.getUniqueId)(),
76
76
  _origin: (0, import_utils.createCartItemOrigin)()
77
77
  };
78
78
  if (product) {
79
- if (product.product_variant_id) {
80
- const targetVariant = product.variant.find((n) => n.id === product.product_variant_id);
81
- if (targetVariant) {
82
- product.price = targetVariant.price;
83
- product.original_price = targetVariant.original_price;
84
- product.is_charge_tax = targetVariant.is_charge_tax;
85
- }
86
- }
87
- cartItem._productOrigin = (0, import_lodash_es.cloneDeep)(product);
88
- cartItem._productInit = (0, import_lodash_es.cloneDeep)(product);
79
+ const newProduct = (0, import_utils.handleVariantProduct)(product);
80
+ cartItem._productOrigin = (0, import_lodash_es.cloneDeep)(newProduct);
81
+ cartItem._productInit = (0, import_lodash_es.cloneDeep)(newProduct);
89
82
  cartItem._bundleOrigin = (0, import_lodash_es.cloneDeep)(bundle);
90
83
  cartItem._optionsOrigin = (0, import_lodash_es.cloneDeep)(options);
91
84
  cartItem = (0, import_utils.formatProductToCartItem)({
92
85
  cartItem,
93
- product,
86
+ product: newProduct,
94
87
  bundle,
95
88
  options,
96
- product_variant_id: product.product_variant_id
89
+ product_variant_id: newProduct.product_variant_id,
90
+ quantity
97
91
  });
98
92
  }
99
93
  if (account) {
@@ -141,7 +135,11 @@ var CartModule = class extends import_BaseModule.BaseModule {
141
135
  date,
142
136
  relationForms
143
137
  } = params;
138
+ let quantity = params.quantity;
144
139
  let tempCartItem = this.store.list.find((i) => i._id === _id);
140
+ if (!quantity && (tempCartItem == null ? void 0 : tempCartItem.num)) {
141
+ quantity = (tempCartItem == null ? void 0 : tempCartItem.num) || 1;
142
+ }
145
143
  if (!tempCartItem) {
146
144
  throw new Error("[CartModule] 格式化数据到购物车失败,商品不存在");
147
145
  }
@@ -149,23 +147,17 @@ var CartModule = class extends import_BaseModule.BaseModule {
149
147
  tempCartItem = cartItem;
150
148
  }
151
149
  if (product) {
152
- if (product.product_variant_id) {
153
- const targetVariant = product.variant.find((n) => n.id === product.product_variant_id);
154
- if (targetVariant) {
155
- product.price = targetVariant.price;
156
- product.original_price = targetVariant.original_price;
157
- product.is_charge_tax = targetVariant.is_charge_tax;
158
- }
159
- }
160
- tempCartItem._productOrigin = (0, import_lodash_es.cloneDeep)(product);
150
+ const newProduct = (0, import_utils.handleVariantProduct)(product);
151
+ tempCartItem._productOrigin = (0, import_lodash_es.cloneDeep)(newProduct);
161
152
  tempCartItem._bundleOrigin = (0, import_lodash_es.cloneDeep)(bundle);
162
153
  tempCartItem._optionsOrigin = (0, import_lodash_es.cloneDeep)(options);
163
154
  tempCartItem = (0, import_utils.formatProductToCartItem)({
164
155
  cartItem: tempCartItem,
165
- product,
156
+ product: newProduct,
166
157
  bundle,
167
158
  options,
168
- product_variant_id: product.product_variant_id
159
+ product_variant_id: newProduct.product_variant_id,
160
+ quantity
169
161
  });
170
162
  }
171
163
  if (discounts) {
@@ -0,0 +1,21 @@
1
+ import { Account } from '../../Account/types';
2
+ import { CartItem } from '../types';
3
+ /**
4
+ * 格式化账户到购物车
5
+ * @param account 账户
6
+ * @returns 格式化后的账户
7
+ */
8
+ export declare const formatAccountToCartItem: (params: {
9
+ cartItem: CartItem;
10
+ account: Account;
11
+ }) => CartItem;
12
+ export declare const formatAccountToCartItemOrigin: (params: {
13
+ cartItem: CartItem;
14
+ account: Account;
15
+ }) => any;
16
+ /**
17
+ * 从购物车中删除账户信息
18
+ * @param cartItem 购物车
19
+ * @returns 删除后的购物车
20
+ */
21
+ export declare const deleteHolderFromCartItem: (cartItem: CartItem) => CartItem;