@pisell/pisellos 3.0.35 → 3.0.37

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 (53) 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/Discount/index.js +2 -2
  19. package/dist/modules/Order/index.js +10 -4
  20. package/dist/modules/Product/types.d.ts +4 -0
  21. package/dist/modules/Product/utils.d.ts +17 -0
  22. package/dist/modules/Product/utils.js +41 -0
  23. package/dist/solution/BookingByStep/index.d.ts +8 -1
  24. package/dist/solution/BookingByStep/index.js +212 -78
  25. package/dist/solution/ShopDiscount/index.js +5 -4
  26. package/lib/modules/Cart/index.js +16 -24
  27. package/lib/modules/Cart/utils/cartAccount.d.ts +21 -0
  28. package/lib/modules/Cart/utils/cartAccount.js +65 -0
  29. package/lib/modules/Cart/utils/cartDate.d.ts +31 -0
  30. package/lib/modules/Cart/utils/cartDate.js +75 -0
  31. package/lib/modules/Cart/utils/cartDiscount.d.ts +19 -0
  32. package/lib/modules/Cart/utils/cartDiscount.js +52 -0
  33. package/lib/modules/Cart/utils/cartNote.d.ts +19 -0
  34. package/lib/modules/Cart/utils/cartNote.js +46 -0
  35. package/lib/modules/Cart/utils/cartProduct.d.ts +107 -0
  36. package/lib/modules/Cart/{utils.js → utils/cartProduct.js} +78 -328
  37. package/lib/modules/Cart/utils/cartRelationForms.d.ts +26 -0
  38. package/lib/modules/Cart/utils/cartRelationForms.js +48 -0
  39. package/lib/modules/Cart/utils/cartResource.d.ts +21 -0
  40. package/lib/modules/Cart/utils/cartResource.js +124 -0
  41. package/lib/modules/Cart/utils/index.d.ts +34 -0
  42. package/lib/modules/Cart/utils/index.js +91 -0
  43. package/lib/modules/Discount/index.js +3 -7
  44. package/lib/modules/Order/index.js +7 -3
  45. package/lib/modules/Product/types.d.ts +4 -0
  46. package/lib/modules/Product/utils.d.ts +17 -0
  47. package/lib/modules/Product/utils.js +46 -0
  48. package/lib/solution/BookingByStep/index.d.ts +8 -1
  49. package/lib/solution/BookingByStep/index.js +117 -47
  50. package/lib/solution/ShopDiscount/index.js +5 -9
  51. package/package.json +3 -3
  52. package/dist/modules/Cart/utils.d.ts +0 -257
  53. 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,
@@ -271,8 +272,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
271
272
  key: "loadProductByScheduleDate",
272
273
  value: function () {
273
274
  var _loadProductByScheduleDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
274
- var _product_ids;
275
- var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, _schedule$product_ids, schedule, otherProductsIds, allProductIds;
275
+ var _schedule$product_ids;
276
+ var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, schedule, otherProductsIds, allProductIds;
276
277
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
277
278
  while (1) switch (_context3.prev = _context3.next) {
278
279
  case 0:
@@ -295,29 +296,34 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
295
296
  // .filter((n) => n !== null && n !== undefined);
296
297
 
297
298
  // 如果外面没传 product_ids,尝试从对应 schedule 里拿 product_ids
298
- if (!((_product_ids = product_ids) !== null && _product_ids !== void 0 && _product_ids.length)) {
299
- schedule = scheduleList.find(function (n) {
300
- return n.date === date;
301
- });
302
- if (schedule && (_schedule$product_ids = schedule.product_ids) !== null && _schedule$product_ids !== void 0 && _schedule$product_ids.length) {
303
- product_ids = schedule.product_ids;
304
- }
299
+ // if (!product_ids?.length) {
300
+ // const schedule = scheduleList.find((n) => n.date === date);
301
+ // if (schedule && schedule.product_ids?.length) {
302
+ // product_ids = schedule.product_ids;
303
+ // }
304
+ // }
305
+ // V2接口修改后,只能从schedule 接口里拿数据,不可以从外面拿,外面给的是装修数据
306
+ schedule = scheduleList.find(function (n) {
307
+ return n.date === date;
308
+ });
309
+ if (schedule && (_schedule$product_ids = schedule.product_ids) !== null && _schedule$product_ids !== void 0 && _schedule$product_ids.length) {
310
+ product_ids = schedule.product_ids;
305
311
  }
306
312
  // 尝试去拿schedule 里的 other_product_ids 和 product_ids 拼在一起去重
307
313
  otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
308
314
  allProductIds = [].concat(_toConsumableArray(product_ids), _toConsumableArray(otherProductsIds)).filter(function (n, index, self) {
309
315
  return self.indexOf(n) === index;
310
316
  });
311
- _context3.next = 8;
317
+ _context3.next = 9;
312
318
  return this.loadProducts({
313
319
  // schedule_ids: scheduleIds,
314
320
  product_ids: allProductIds,
315
321
  category_ids: category_ids
316
322
  // schedule_date: date,
317
323
  });
318
- case 8:
319
- return _context3.abrupt("return", _context3.sent);
320
324
  case 9:
325
+ return _context3.abrupt("return", _context3.sent);
326
+ case 10:
321
327
  case "end":
322
328
  return _context3.stop();
323
329
  }
@@ -340,7 +346,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
340
346
  // 更新完商品数据以后,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
341
347
  cartItems = this.store.cart.getItems();
342
348
  if (!cartItems.length) {
343
- _context5.next = 24;
349
+ _context5.next = 25;
344
350
  break;
345
351
  }
346
352
  userPlugin = this.core.getPlugin('user');
@@ -432,6 +438,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
432
438
  _iterator.f();
433
439
  return _context5.finish(21);
434
440
  case 24:
441
+ this.core.effects.emit("".concat(this.store.cart.name, ":onUpdateQuotationPrice"), {});
442
+ case 25:
435
443
  case "end":
436
444
  return _context5.stop();
437
445
  }
@@ -545,26 +553,48 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
545
553
  key: "storeProduct",
546
554
  value: function () {
547
555
  var _storeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(productData) {
548
- var activeAccount, _ref4, bundle, options, origin, product_variant_id, product, addCartItem;
556
+ var activeAccount, _ref4, bundle, options, origin, product_variant_id, _ref4$quantity, quantity, rowKey, cartItems, targetCartItem, product, addCartItem;
549
557
  return _regeneratorRuntime().wrap(function _callee7$(_context8) {
550
558
  while (1) switch (_context8.prev = _context8.next) {
551
559
  case 0:
552
560
  // 往购物车加商品数据的时候,默认用当前 activeAccount 填充到 product 的 account 里面
553
561
  activeAccount = this.getActiveAccount();
554
- _ref4 = productData || {}, bundle = _ref4.bundle, options = _ref4.options, origin = _ref4.origin, product_variant_id = _ref4.product_variant_id;
562
+ _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相同的数据,如果是则更新数量
563
+ cartItems = this.store.cart.getItems();
564
+ if (!rowKey) {
565
+ _context8.next = 8;
566
+ break;
567
+ }
568
+ targetCartItem = cartItems.find(function (n) {
569
+ var _n$_productOrigin;
570
+ return ((_n$_productOrigin = n._productOrigin) === null || _n$_productOrigin === void 0 ? void 0 : _n$_productOrigin.rowKey) === rowKey;
571
+ });
572
+ if (!(targetCartItem && isNormalProduct(targetCartItem._productOrigin))) {
573
+ _context8.next = 8;
574
+ break;
575
+ }
576
+ this.store.cart.updateItem({
577
+ _id: targetCartItem._id,
578
+ product: _objectSpread({}, targetCartItem._productOrigin),
579
+ quantity: (targetCartItem.num || 1) + quantity
580
+ });
581
+ return _context8.abrupt("return");
582
+ case 8:
555
583
  product = _objectSpread(_objectSpread({}, origin), {}, {
556
- product_variant_id: product_variant_id
584
+ product_variant_id: product_variant_id,
585
+ rowKey: rowKey
557
586
  });
558
587
  addCartItem = {
559
588
  product: product,
560
589
  bundle: bundle,
561
- options: options
590
+ options: options,
591
+ quantity: quantity
562
592
  };
563
593
  if (activeAccount) {
564
594
  addCartItem.account = activeAccount;
565
595
  }
566
596
  this.store.cart.addItem(addCartItem);
567
- case 6:
597
+ case 12:
568
598
  case "end":
569
599
  return _context8.stop();
570
600
  }
@@ -735,7 +765,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
735
765
  key: "fetchHolderAccountsAsync",
736
766
  value: (function () {
737
767
  var _fetchHolderAccountsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
738
- var cartItems, _this$store$date$getD, date, _cartItems$;
768
+ var cartItems, _this$store$date$getD, date, normalProductCartItem;
739
769
  return _regeneratorRuntime().wrap(function _callee11$(_context12) {
740
770
  while (1) switch (_context12.prev = _context12.next) {
741
771
  case 0:
@@ -744,7 +774,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
744
774
  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
775
  if (!date) {
746
776
  // 如果没有日期,则应该是 session 类先选商品的流程,直接从购物车里拿 start_date
747
- date = (cartItems === null || cartItems === void 0 || (_cartItems$ = cartItems[0]) === null || _cartItems$ === void 0 ? void 0 : _cartItems$.start_date) || '';
777
+ // 不能从购物车里第一个找时间,而是找到购物车里第一个有 start_date 的时间
778
+ normalProductCartItem = cartItems.find(function (n) {
779
+ return !isNormalProduct(n._productOrigin);
780
+ });
781
+ date = (normalProductCartItem === null || normalProductCartItem === void 0 ? void 0 : normalProductCartItem.start_date) || '';
748
782
  }
749
783
  this.updateQuotationPriceAndCart(date);
750
784
  }
@@ -979,7 +1013,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
979
1013
  value: function () {
980
1014
  var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(accountId, accountInfo) {
981
1015
  var _this5 = this;
982
- var account, stateAccountId, cartItems, _this$store$date$getD2, date, _cartItems$2;
1016
+ var account, stateAccountId, cartItems, _this$store$date$getD2, date, normalProductCartItem;
983
1017
  return _regeneratorRuntime().wrap(function _callee18$(_context19) {
984
1018
  while (1) switch (_context19.prev = _context19.next) {
985
1019
  case 0:
@@ -1006,7 +1040,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1006
1040
  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
1041
  if (!date) {
1008
1042
  // 如果没有日期,则应该是 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) || '';
1043
+ // 不能从购物车里第一个找时间,而是找到购物车里第一个有 start_date 的时间
1044
+ normalProductCartItem = cartItems.find(function (n) {
1045
+ return !isNormalProduct(n._productOrigin);
1046
+ });
1047
+ date = (normalProductCartItem === null || normalProductCartItem === void 0 ? void 0 : normalProductCartItem.start_date) || '';
1010
1048
  }
1011
1049
  this.updateQuotationPriceAndCart(date);
1012
1050
  }
@@ -1115,14 +1153,19 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1115
1153
  item._origin.number = currentCapacity;
1116
1154
  }
1117
1155
  });
1118
- type = this.otherParams.isRetailTemplate ? 'virtual' : 'appointment_booking';
1156
+ type = this.otherParams.isRetailTemplate ? 'virtual' : 'appointment_booking'; // 如果购物车里全都是普通商品,type 也应该为 virtual
1157
+ if (areAllNormalProducts(newCartItems.map(function (n) {
1158
+ return n._productOrigin;
1159
+ }))) {
1160
+ type = 'virtual';
1161
+ }
1119
1162
  return _context22.abrupt("return", this.store.order.submitOrder({
1120
1163
  query: {
1121
1164
  cartItems: newCartItems,
1122
1165
  type: type
1123
1166
  }
1124
1167
  }));
1125
- case 5:
1168
+ case 6:
1126
1169
  case "end":
1127
1170
  return _context22.stop();
1128
1171
  }
@@ -1394,7 +1437,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1394
1437
  key: "checkCartItems",
1395
1438
  value: function checkCartItems(type) {
1396
1439
  var _this8 = this;
1397
- var cartItems = this.store.cart.getItems();
1440
+ // 预约流程中普通商品无需检测这些东西
1441
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1442
+ return !isNormalProduct(n._productOrigin);
1443
+ });
1398
1444
  var errorCartItemIds = [];
1399
1445
  cartItems.forEach(function (cartItem) {
1400
1446
  var result = _this8.store.cart.checkCartItemByType(cartItem, type);
@@ -1437,7 +1483,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1437
1483
  });
1438
1484
  }
1439
1485
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1440
- var cartItems = this.store.cart.getItems();
1486
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1487
+ return !isNormalProduct(n._productOrigin);
1488
+ });
1441
1489
  var arr = [];
1442
1490
  cartItems.forEach(function (cartItem) {
1443
1491
  var _cartItem$_productOri, _cartItem$_productOri2;
@@ -1562,7 +1610,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1562
1610
  });
1563
1611
  }
1564
1612
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1565
- var cartItems = this.store.cart.getItems();
1613
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1614
+ return !isNormalProduct(n._productOrigin);
1615
+ });
1566
1616
  var arr = [];
1567
1617
  cartItems.forEach(function (cartItem) {
1568
1618
  var _cartItem$_productOri5, _cartItem$_productOri6;
@@ -1676,7 +1726,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1676
1726
  key: "getResourcesListByCartItem",
1677
1727
  value: function getResourcesListByCartItem(id) {
1678
1728
  var _targetCartItem$_prod2, _targetCartItem$_prod3;
1679
- var cartItems = cloneDeep(this.store.cart.getItems());
1729
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1730
+ return !isNormalProduct(n._productOrigin);
1731
+ });
1680
1732
  var dateRange = this.store.date.getDateRange();
1681
1733
  var resources = [];
1682
1734
  dateRange.forEach(function (n) {
@@ -1755,6 +1807,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1755
1807
  timeSlots = _ref8.timeSlots,
1756
1808
  countMap = _ref8.countMap,
1757
1809
  capacity = _ref8.capacity;
1810
+ if (isNormalProduct(cartItem._productOrigin)) {
1811
+ return {};
1812
+ }
1758
1813
  var dateRange = this.store.date.getDateRange();
1759
1814
  var cartItems = cloneDeep(this.store.cart.getItems());
1760
1815
  // 取到账号下所有的商品,然后根据商品的 duration 和资源列表,获取所有可用的资源
@@ -1767,8 +1822,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1767
1822
  }
1768
1823
  // duration=所有商品时间的集合
1769
1824
  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);
1825
+ var _n$_productOrigin$dur, _n$_productOrigin2;
1826
+ 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
1827
  }, 0);
1773
1828
  // 正常来说,能进这个业务的所有商品的 duration 类型都是一样的,所以这里取第一个商品的 duration 类型
1774
1829
  // let durationType = accountCartItems[0]?._productOrigin?.duration?.type ?? "minutes";
@@ -2099,7 +2154,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2099
2154
  }
2100
2155
  });
2101
2156
  };
2102
- var cartItems = cloneDeep(this.store.cart.getItems());
2157
+ var cartItems = this.store.cart.getItems().filter(function (n) {
2158
+ return !isNormalProduct(n._productOrigin);
2159
+ });
2103
2160
 
2104
2161
  // 如果购物车里没有 holderid数据,证明不按 holder 类流程预约走,给所有购物车一次性分派即可,不做账号下资源互斥逻辑
2105
2162
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
@@ -2120,12 +2177,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2120
2177
  value: function getTimeSlotByAllResources(resources_code) {
2121
2178
  var _dateRange,
2122
2179
  _this10 = this,
2123
- _cartItems$3,
2124
- _cartItems$4;
2180
+ _cartItems$,
2181
+ _cartItems$2;
2125
2182
  var dateRange = this.store.date.getDateRange();
2126
2183
  // 取出购物车中所有一已选择的第一步资源
2127
2184
  var resources = [];
2128
- var cartItems = cloneDeep(this.store.cart.getItems());
2185
+ var cartItems = this.store.cart.getItems().filter(function (n) {
2186
+ return !isNormalProduct(n._productOrigin);
2187
+ });
2129
2188
  // if (cartItems?.[0].start_date) return [];
2130
2189
  var resourceIds = [];
2131
2190
  var resourcesTypeId = undefined;
@@ -2204,18 +2263,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2204
2263
  }
2205
2264
  // 如果 cartItem 上既没有时间,也没有资源,认为外部属于异常调用,直接丢一个空数组出去
2206
2265
  // 同时 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)) {
2266
+ 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
2267
  return [];
2209
2268
  }
2210
2269
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].start_date && !dateRange) {
2211
- var _cartItems$5, _cartItems$6;
2270
+ var _cartItems$3, _cartItems$4;
2212
2271
  dateRange = [{
2213
2272
  date: cartItems === null || cartItems === void 0 ? void 0 : cartItems[0].start_date,
2214
2273
  status: 'available',
2215
2274
  week: '',
2216
2275
  weekNum: 0
2217
2276
  }, {
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) || '',
2277
+ 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
2278
  status: 'available',
2220
2279
  week: '',
2221
2280
  weekNum: 0
@@ -2240,7 +2299,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2240
2299
  value: function submitTimeSlot(timeSlots) {
2241
2300
  var _this11 = this;
2242
2301
  // 以账号为维度处理数据。购物车里每一项的 startTime应该是前一个商品的 endTime,如果是第一个商品则用 timeSlots.start_at
2243
- var cartItems = cloneDeep(this.store.cart.getItems());
2302
+ var cartItems = this.store.cart.getItems().filter(function (n) {
2303
+ return !isNormalProduct(n._productOrigin);
2304
+ });
2244
2305
 
2245
2306
  // 按账号分组
2246
2307
  var itemsByAccount = cartItems.reduce(function (acc, item) {
@@ -2348,7 +2409,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2348
2409
  }, {
2349
2410
  key: "getTimeslotBySchedule",
2350
2411
  value: function getTimeslotBySchedule(_ref12) {
2351
- var _this$store$currentPr2;
2412
+ var _this$store$currentPr2, _targetProductData$pr;
2352
2413
  var date = _ref12.date,
2353
2414
  scheduleIds = _ref12.scheduleIds,
2354
2415
  resources = _ref12.resources,
@@ -2387,6 +2448,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2387
2448
  return 0;
2388
2449
  });
2389
2450
 
2451
+ // 找到当前商品下第一个启用的资源id
2452
+ 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) {
2453
+ return n.status === 1;
2454
+ })) === null || _targetProductData$pr === void 0 ? void 0 : _targetProductData$pr.id;
2455
+
2390
2456
  // 计算每个日程切片下日程可用的资源的容量总和
2391
2457
  var formatScheduleTimeSlots = scheduleTimeSlots.map(function (item) {
2392
2458
  // 用来计算资源的可使用情况,针对单个schedule 时间片
@@ -2434,7 +2500,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2434
2500
  // 在已经选定时间的情况下,只要canUseTime如果有一个 false 那就不可用
2435
2501
  if (!currentResourcesTimeSlotCanUsedArr.some(function (n) {
2436
2502
  return n === false;
2437
- })) {
2503
+ })
2504
+ // 只统计第一种资源的容量和 left
2505
+ && m.form_id === firstEnabledResourceId) {
2438
2506
  if (currentResourcesCount >= count) {
2439
2507
  count = currentResourcesCount;
2440
2508
  }
@@ -2467,7 +2535,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2467
2535
  bundle = _ref14.bundle,
2468
2536
  options = _ref14.options,
2469
2537
  origin = _ref14.origin,
2470
- product_variant_id = _ref14.product_variant_id;
2538
+ product_variant_id = _ref14.product_variant_id,
2539
+ rowKey = _ref14.rowKey,
2540
+ _ref14$quantity = _ref14.quantity,
2541
+ quantity = _ref14$quantity === void 0 ? 1 : _ref14$quantity;
2471
2542
  var productData = _objectSpread(_objectSpread({}, origin), {}, {
2472
2543
  product_variant_id: product_variant_id
2473
2544
  });
@@ -2477,17 +2548,36 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2477
2548
  account = activeAccount;
2478
2549
  }
2479
2550
  }
2551
+ if (rowKey) {
2552
+ var cartItems = this.store.cart.getItems();
2553
+ var targetCartItem = cartItems.find(function (n) {
2554
+ var _n$_productOrigin3;
2555
+ return ((_n$_productOrigin3 = n._productOrigin) === null || _n$_productOrigin3 === void 0 ? void 0 : _n$_productOrigin3.rowKey) === rowKey;
2556
+ });
2557
+ if (targetCartItem && isNormalProduct(targetCartItem._productOrigin)) {
2558
+ this.store.cart.updateItem({
2559
+ _id: targetCartItem._id,
2560
+ product: _objectSpread(_objectSpread({}, targetCartItem._productOrigin), {}, {
2561
+ quantity: (targetCartItem.num || 1) + quantity
2562
+ })
2563
+ });
2564
+ return;
2565
+ }
2566
+ }
2480
2567
  this.store.cart.addItem({
2481
2568
  product: productData,
2482
2569
  date: date,
2483
2570
  account: account,
2484
2571
  bundle: bundle,
2485
- options: options
2572
+ options: options,
2573
+ quantity: quantity
2486
2574
  });
2487
2575
  // 检测,有传递 date,检查购物车里其他商品的 date 是否在同一天,如果不在,清空那些不在同一天的商品
2488
2576
  if (date) {
2489
- var cartItems = cloneDeep(this.store.cart.getItems());
2490
- var cartItemsByDate = cartItems.filter(function (n) {
2577
+ var _cartItems = this.store.cart.getItems().filter(function (n) {
2578
+ return !isNormalProduct(n._productOrigin);
2579
+ });
2580
+ var cartItemsByDate = _cartItems.filter(function (n) {
2491
2581
  return !dayjs(n.start_date).isSame(dayjs(date.startTime), 'day');
2492
2582
  });
2493
2583
  if (cartItemsByDate.length) {
@@ -2571,7 +2661,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2571
2661
  });
2572
2662
  }
2573
2663
  var resourcesMap = getResourcesMap(cloneDeep(resources));
2574
- var cartItems = this.store.cart.getItems();
2664
+ var cartItems = this.store.cart.getItems().filter(function (n) {
2665
+ return !isNormalProduct(n._productOrigin);
2666
+ });
2575
2667
  var cartItem = cartItems.find(function (item) {
2576
2668
  return item._id === cartItemId;
2577
2669
  });
@@ -2802,14 +2894,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2802
2894
  var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2803
2895
  var _this$store$currentPr3, _this$store$currentPr4, _this$store$currentPr5, _tempProducts, _this$store$currentPr6;
2804
2896
  var params,
2805
- cache,
2806
2897
  startDate,
2807
2898
  endDate,
2899
+ endDateAfterMonth,
2808
2900
  tempProducts,
2809
2901
  schedule,
2810
2902
  filteredSchedule,
2811
2903
  tempResourceIds,
2812
2904
  res,
2905
+ cache,
2813
2906
  dates,
2814
2907
  currentDate,
2815
2908
  firstAvailableDate,
@@ -2822,34 +2915,26 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2822
2915
  while (1) switch (_context32.prev = _context32.next) {
2823
2916
  case 0:
2824
2917
  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
2918
  // 开始日期如果小于今天,直接以今天当做开始日期
2841
2919
  startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2842
2920
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
2843
2921
  startDate = dayjs().format('YYYY-MM-DD');
2844
2922
  }
2845
2923
  // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2846
- endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2924
+ // 优化策略:
2925
+ // 在 endDate 添加完一个月以后,如果 endDate 还小于 startDate + 7 天,则还需要 endDate+7 天
2926
+ endDateAfterMonth = dayjs().add(1, 'month').format('YYYY-MM-DD');
2927
+ if (dayjs(startDate).add(7, 'day').isAfter(dayjs(endDateAfterMonth), 'day')) {
2928
+ endDate = dayjs(startDate).add(7, 'day').format('YYYY-MM-DD');
2929
+ } else {
2930
+ endDate = endDateAfterMonth;
2931
+ }
2847
2932
  // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
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'];
2933
+ tempProducts = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getData();
2934
+ schedule = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getOtherParams()['schedule'];
2850
2935
  filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2851
2936
  tempResourceIds = getResourcesIdsByProduct(tempProducts);
2852
- _context32.next = 14;
2937
+ _context32.next = 11;
2853
2938
  return this.store.date.fetchResourceDates({
2854
2939
  query: {
2855
2940
  start_date: startDate || '',
@@ -2857,8 +2942,25 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2857
2942
  resource_ids: tempResourceIds
2858
2943
  }
2859
2944
  });
2860
- case 14:
2945
+ case 11:
2861
2946
  res = _context32.sent;
2947
+ // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2948
+ // TODO 优化关于为什么要放在接口后,因为在获取时间切片的时候还需要读一次接口数据,其实可以直接从这个结果里拿了,需要优化
2949
+ cache = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['timeSlotBySchedule'];
2950
+ if (!cache) {
2951
+ _context32.next = 17;
2952
+ break;
2953
+ }
2954
+ if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2955
+ _context32.next = 17;
2956
+ break;
2957
+ }
2958
+ this.store.date.setDateList(cache.dateList);
2959
+ return _context32.abrupt("return", {
2960
+ dateList: cache.dateList,
2961
+ firstAvailableDate: cache.firstAvailableDate
2962
+ });
2963
+ case 17:
2862
2964
  // 2. 商品 schedule 数据,确定日程在每一天的时间片
2863
2965
  // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
2864
2966
  dates = [];
@@ -2985,22 +3087,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2985
3087
  }
2986
3088
  }, _loop3);
2987
3089
  });
2988
- case 23:
3090
+ case 25:
2989
3091
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
2990
- _context32.next = 29;
3092
+ _context32.next = 31;
2991
3093
  break;
2992
3094
  }
2993
- return _context32.delegateYield(_loop3(), "t0", 25);
2994
- case 25:
3095
+ return _context32.delegateYield(_loop3(), "t0", 27);
3096
+ case 27:
2995
3097
  if (!_context32.t0) {
2996
- _context32.next = 27;
3098
+ _context32.next = 29;
2997
3099
  break;
2998
3100
  }
2999
- return _context32.abrupt("break", 29);
3000
- case 27:
3001
- _context32.next = 23;
3002
- break;
3101
+ return _context32.abrupt("break", 31);
3003
3102
  case 29:
3103
+ _context32.next = 25;
3104
+ break;
3105
+ case 31:
3004
3106
  // 最终把资源数据也加到日期内
3005
3107
  dates = handleAvailableDateByResource(res.data, dates);
3006
3108
  this.store.date.setDateList(dates);
@@ -3010,13 +3112,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3010
3112
  dateList: dates,
3011
3113
  firstAvailableDate: firstAvailableDate,
3012
3114
  startDate: startDate,
3013
- endDate: endDate
3115
+ endDate: dayjs(currentDate).format('YYYY-MM-DD')
3014
3116
  });
3015
3117
  return _context32.abrupt("return", {
3016
3118
  dateList: dates,
3017
3119
  firstAvailableDate: firstAvailableDate
3018
3120
  });
3019
- case 33:
3121
+ case 35:
3020
3122
  case "end":
3021
3123
  return _context32.stop();
3022
3124
  }
@@ -3027,6 +3129,38 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3027
3129
  }
3028
3130
  return getAvailableDateForSessionOptimize;
3029
3131
  }()
3132
+ }, {
3133
+ key: "isCartAllNormalProducts",
3134
+ value: function isCartAllNormalProducts() {
3135
+ var cartItems = this.store.cart.getItems().filter(function (n) {
3136
+ return !isNormalProduct(n._productOrigin);
3137
+ });
3138
+ return !cartItems.length;
3139
+ }
3140
+ }, {
3141
+ key: "isCartHasDurationProduct",
3142
+ value: function isCartHasDurationProduct() {
3143
+ var cartItems = this.store.cart.getItems().filter(function (n) {
3144
+ return !isNormalProduct(n._productOrigin);
3145
+ });
3146
+ return cartItems.some(function (n) {
3147
+ var _n$_productOrigin4;
3148
+ return (_n$_productOrigin4 = n._productOrigin) === null || _n$_productOrigin4 === void 0 ? void 0 : _n$_productOrigin4.duration;
3149
+ });
3150
+ }
3151
+ }, {
3152
+ key: "isTargetNormalProduct",
3153
+ value: function isTargetNormalProduct(product) {
3154
+ return isNormalProduct(product);
3155
+ }
3156
+ }, {
3157
+ key: "isTargetCartIdNormalProduct",
3158
+ value: function isTargetCartIdNormalProduct(id) {
3159
+ var cartItem = this.store.cart.getItems().find(function (n) {
3160
+ return n._id === id;
3161
+ });
3162
+ return cartItem && isNormalProduct(cartItem._productOrigin);
3163
+ }
3030
3164
  }]);
3031
3165
  return BookingByStepImpl;
3032
3166
  }(BaseModule);
@@ -30,7 +30,6 @@ import { BaseModule } from "../../modules/BaseModule";
30
30
  import { ShopDiscountHooks } from "./types";
31
31
  import { DiscountModule } from "../../modules/Discount";
32
32
  import { RulesModule } from "../../modules/Rules";
33
- import { uniqueById } from "./utils";
34
33
  export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
35
34
  _inherits(ShopDiscountImpl, _BaseModule);
36
35
  var _super = _createSuper(ShopDiscountImpl);
@@ -278,7 +277,9 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
278
277
  isManualSelect: !isSelected
279
278
  });
280
279
  }
281
- return discount;
280
+ return _objectSpread(_objectSpread({}, discount), {}, {
281
+ isManualSelect: !(discount !== null && discount !== void 0 && discount.isSelected)
282
+ });
282
283
  });
283
284
 
284
285
  // 更新优惠券列表
@@ -451,9 +452,9 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
451
452
  });
452
453
  }
453
454
  });
454
- var newDiscountList = uniqueById([].concat(editModeDiscountList, _toConsumableArray(discountList.filter(function (item) {
455
+ var newDiscountList = [].concat(editModeDiscountList, _toConsumableArray(discountList.filter(function (item) {
455
456
  return !item.isDisabled;
456
- }))), 'product_id');
457
+ })));
457
458
  (_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 || _this$store$discount5.setDiscountList(newDiscountList);
458
459
  this.emitDiscountListChange(newDiscountList);
459
460
  return newDiscountList;