@pisell/pisellos 2.0.32 → 2.0.34

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 +150 -33
  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 +94 -29
  50. package/lib/solution/ShopDiscount/index.js +5 -9
  51. package/package.json +1 -1
  52. package/dist/modules/Cart/utils.d.ts +0 -258
  53. package/lib/modules/Cart/utils.d.ts +0 -258
@@ -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
  });
@@ -3029,6 +3114,38 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3029
3114
  }
3030
3115
  return getAvailableDateForSessionOptimize;
3031
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
+ }
3032
3149
  }]);
3033
3150
  return BookingByStepImpl;
3034
3151
  }(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;
@@ -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;
@@ -0,0 +1,65 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/modules/Cart/utils/cartAccount.ts
20
+ var cartAccount_exports = {};
21
+ __export(cartAccount_exports, {
22
+ deleteHolderFromCartItem: () => deleteHolderFromCartItem,
23
+ formatAccountToCartItem: () => formatAccountToCartItem,
24
+ formatAccountToCartItemOrigin: () => formatAccountToCartItemOrigin
25
+ });
26
+ module.exports = __toCommonJS(cartAccount_exports);
27
+ var formatAccountToCartItem = (params) => {
28
+ const { cartItem, account } = params;
29
+ if (account) {
30
+ cartItem.holder_id = account.id;
31
+ cartItem.holder_title = account.username;
32
+ }
33
+ const oringin = formatAccountToCartItemOrigin(params);
34
+ cartItem._origin = oringin;
35
+ return cartItem;
36
+ };
37
+ var formatAccountToCartItemOrigin = (params) => {
38
+ const { cartItem, account } = params;
39
+ let origin = cartItem._origin;
40
+ if (account) {
41
+ if ((account == null ? void 0 : account.type) === "holder") {
42
+ const { customer_id, form_id, form_record_id } = (account == null ? void 0 : account._origin) || {};
43
+ origin.holder = {
44
+ customer_id,
45
+ form_id,
46
+ form_record: form_record_id ? [form_record_id] : null
47
+ };
48
+ } else {
49
+ origin.metadata.account = account;
50
+ }
51
+ }
52
+ return origin;
53
+ };
54
+ var deleteHolderFromCartItem = (cartItem) => {
55
+ cartItem.holder_id = void 0;
56
+ cartItem.holder_title = void 0;
57
+ cartItem._origin.holder = null;
58
+ return cartItem;
59
+ };
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ deleteHolderFromCartItem,
63
+ formatAccountToCartItem,
64
+ formatAccountToCartItemOrigin
65
+ });
@@ -0,0 +1,31 @@
1
+ import { CartItem } from '../types';
2
+ /**
3
+ * 格式化日期到购物车
4
+ * @param date 开始时间和结束时间
5
+ * @returns 格式化后的日期
6
+ */
7
+ export declare const formatDateToCartItem: (params: {
8
+ cartItem: CartItem;
9
+ date: {
10
+ startTime: string;
11
+ endTime: string;
12
+ };
13
+ }) => CartItem;
14
+ /**
15
+ * 格式化日期到购物车原始数据
16
+ * @param date 开始时间和结束时间
17
+ * @returns 格式化后的日期原始数据
18
+ */
19
+ export declare const formatDateToCartItemOrigin: (params: {
20
+ cartItem: CartItem;
21
+ date: {
22
+ startTime: string;
23
+ endTime: string;
24
+ };
25
+ }) => any;
26
+ /**
27
+ * 从购物车中删除时间
28
+ * @param cartItem 购物车
29
+ * @returns 删除后的购物车
30
+ */
31
+ export declare const deleteTimeFromCartItem: (cartItem: CartItem) => CartItem;