@pisell/pisellos 1.0.65 → 1.0.67

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 (43) hide show
  1. package/dist/modules/Date/index.js +4 -0
  2. package/dist/modules/Order/index.js +10 -4
  3. package/dist/modules/Payment/index.d.ts +1 -0
  4. package/dist/modules/Payment/index.js +75 -41
  5. package/dist/modules/Payment/walletpass.js +3 -4
  6. package/dist/modules/Rules/index.js +2 -0
  7. package/dist/modules/Schedule/index.d.ts +1 -1
  8. package/dist/modules/Schedule/index.js +9 -0
  9. package/dist/solution/BookingByStep/index.d.ts +16 -4
  10. package/dist/solution/BookingByStep/index.js +671 -109
  11. package/dist/solution/BookingByStep/utils/capacity.d.ts +23 -0
  12. package/dist/solution/BookingByStep/utils/capacity.js +219 -1
  13. package/dist/solution/BookingByStep/utils/stock.d.ts +29 -0
  14. package/dist/solution/BookingByStep/utils/stock.js +126 -0
  15. package/dist/solution/BookingTicket/index.d.ts +1 -1
  16. package/dist/solution/Checkout/index.d.ts +6 -148
  17. package/dist/solution/Checkout/index.js +1188 -2434
  18. package/dist/solution/Checkout/types.d.ts +7 -220
  19. package/dist/solution/Checkout/types.js +1 -49
  20. package/dist/solution/Checkout/utils/index.d.ts +9 -5
  21. package/dist/solution/Checkout/utils/index.js +18 -56
  22. package/lib/modules/Date/index.js +3 -0
  23. package/lib/modules/Order/index.js +6 -0
  24. package/lib/modules/Payment/index.d.ts +1 -0
  25. package/lib/modules/Payment/index.js +35 -8
  26. package/lib/modules/Payment/walletpass.js +2 -2
  27. package/lib/modules/Rules/index.js +2 -0
  28. package/lib/modules/Schedule/index.d.ts +1 -1
  29. package/lib/modules/Schedule/index.js +9 -0
  30. package/lib/solution/BookingByStep/index.d.ts +16 -4
  31. package/lib/solution/BookingByStep/index.js +363 -8
  32. package/lib/solution/BookingByStep/utils/capacity.d.ts +23 -0
  33. package/lib/solution/BookingByStep/utils/capacity.js +157 -0
  34. package/lib/solution/BookingByStep/utils/stock.d.ts +29 -0
  35. package/lib/solution/BookingByStep/utils/stock.js +89 -0
  36. package/lib/solution/BookingTicket/index.d.ts +1 -1
  37. package/lib/solution/Checkout/index.d.ts +6 -148
  38. package/lib/solution/Checkout/index.js +337 -1115
  39. package/lib/solution/Checkout/types.d.ts +7 -220
  40. package/lib/solution/Checkout/types.js +3 -27
  41. package/lib/solution/Checkout/utils/index.d.ts +9 -5
  42. package/lib/solution/Checkout/utils/index.js +12 -53
  43. package/package.json +1 -1
@@ -1,4 +1,8 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
5
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
2
6
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
3
7
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
8
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -27,7 +31,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
27
31
  import { BaseModule } from "../../modules/BaseModule";
28
32
  import { BookingByStepHooks, createModule } from "./types";
29
33
  import { getAvailableProductResources } from "./utils/products";
30
- import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, getResourcesIdsByProduct, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection } from "./utils/resources";
34
+ import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection } from "./utils/resources";
31
35
  import dayjs from 'dayjs';
32
36
  import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
33
37
  import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
@@ -40,7 +44,8 @@ import { handleAvailableDateByResource } from "../../modules/Date/utils";
40
44
  import { areAllNormalProducts, isNormalProduct } from "../../modules/Product/utils";
41
45
  import { calculateResourceAvailableTime, filterConditionTimeSlots, findFastestAvailableResource } from "./utils/timeslots";
42
46
  import { updateAllCartItemPrice } from "../../modules/Cart/utils/changePrice";
43
- import { getCapacityInfoByCartItem, checkSubResourcesCapacity, checkResourceCanUseByCapacity } from "./utils/capacity";
47
+ import { getCapacityInfoByCartItem, checkSubResourcesCapacity, checkResourceCanUseByCapacity, getResourcesIdsByProduct, checkTimeSlotCapacity } from "./utils/capacity";
48
+ import { checkProductStock } from "./utils/stock";
44
49
  export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
45
50
  _inherits(BookingByStepImpl, _BaseModule);
46
51
  var _super = _createSuper(BookingByStepImpl);
@@ -1101,29 +1106,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1101
1106
  */
1102
1107
  }, {
1103
1108
  key: "storeProduct",
1104
- value: (function () {
1105
- var _storeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(productData) {
1106
- var activeAccount;
1107
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1108
- while (1) switch (_context24.prev = _context24.next) {
1109
- case 0:
1110
- // 往购物车加商品数据的时候,默认用当前 activeAccount 填充到 product 的 account 里面
1111
- activeAccount = this.getActiveAccount(); // 直接调用 addProductToCart,不传递 date 参数以避免日期检查逻辑
1112
- this.addProductToCart({
1113
- product: productData,
1114
- account: activeAccount
1115
- });
1116
- case 2:
1117
- case "end":
1118
- return _context24.stop();
1119
- }
1120
- }, _callee24, this);
1121
- }));
1122
- function storeProduct(_x18) {
1123
- return _storeProduct.apply(this, arguments);
1124
- }
1125
- return storeProduct;
1126
- }()
1109
+ value: function storeProduct(productData) {
1110
+ // 往购物车加商品数据的时候,默认用当前 activeAccount 填充到 product account 里面
1111
+ var activeAccount = this.getActiveAccount();
1112
+ // 直接调用 addProductToCart,不传递 date 参数以避免日期检查逻辑
1113
+ return this.addProductToCart({
1114
+ product: productData,
1115
+ account: activeAccount
1116
+ });
1117
+ }
1118
+
1127
1119
  /**
1128
1120
  * 往购物车加商品数据
1129
1121
  *
@@ -1139,7 +1131,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1139
1131
  * @return {*}
1140
1132
  * @memberof BookingByStepImpl
1141
1133
  */
1142
- )
1143
1134
  }, {
1144
1135
  key: "addProductToCart",
1145
1136
  value: function addProductToCart(_ref6) {
@@ -1157,6 +1148,21 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1157
1148
  var productData = _objectSpread(_objectSpread({}, origin), {}, {
1158
1149
  product_variant_id: product_variant_id
1159
1150
  });
1151
+
1152
+ // 库存检测
1153
+ var currentCartItems = this.store.cart.getItems();
1154
+ var stockCheckResult = checkProductStock({
1155
+ productData: productData,
1156
+ product_variant_id: product_variant_id,
1157
+ quantity: quantity,
1158
+ bundle: bundle,
1159
+ currentCartItems: currentCartItems
1160
+ });
1161
+
1162
+ // 如果库存检测失败,直接返回
1163
+ if (!stockCheckResult.success) {
1164
+ return stockCheckResult;
1165
+ }
1160
1166
  if (!account) {
1161
1167
  var activeAccount = this.getActiveAccount();
1162
1168
  if (activeAccount) {
@@ -1169,7 +1175,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1169
1175
  account: account || undefined
1170
1176
  });
1171
1177
  if (flag) {
1172
- return;
1178
+ return {
1179
+ success: true
1180
+ };
1173
1181
  }
1174
1182
  var addItemParams = {
1175
1183
  product: productData,
@@ -1187,6 +1195,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1187
1195
  date: date
1188
1196
  });
1189
1197
  this.store.cart.addItem(addItemParams);
1198
+ return {
1199
+ success: true
1200
+ };
1190
1201
  }
1191
1202
 
1192
1203
  /**
@@ -2253,12 +2264,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2253
2264
  });
2254
2265
  });
2255
2266
  }
2256
- }, {
2257
- key: "clearCache",
2258
- value: function clearCache() {}
2259
- }, {
2260
- key: "clearCacheByModule",
2261
- value: function clearCacheByModule(module) {}
2262
2267
  }, {
2263
2268
  key: "getScheduleDataByIds",
2264
2269
  value: function getScheduleDataByIds(scheduleIds) {
@@ -2289,42 +2294,42 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2289
2294
  }, {
2290
2295
  key: "openProductDetail",
2291
2296
  value: function () {
2292
- var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(productId) {
2297
+ var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(productId) {
2293
2298
  var targetProductData, newScheduleArr, dateRange;
2294
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2295
- while (1) switch (_context25.prev = _context25.next) {
2299
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2300
+ while (1) switch (_context24.prev = _context24.next) {
2296
2301
  case 0:
2297
- _context25.next = 2;
2302
+ _context24.next = 2;
2298
2303
  return this.store.products.getProduct(productId);
2299
2304
  case 2:
2300
- targetProductData = _context25.sent;
2305
+ targetProductData = _context24.sent;
2301
2306
  if (!targetProductData) {
2302
- _context25.next = 17;
2307
+ _context24.next = 17;
2303
2308
  break;
2304
2309
  }
2305
2310
  this.store.currentProduct = targetProductData;
2306
2311
  this.store.currentProductMeta = {};
2307
2312
  // 资源预加载,如果是 duration 类型的商品,且是先选日期的流程,在这里预拉取资源数据
2308
2313
  if (!targetProductData['schedule.ids']) {
2309
- _context25.next = 12;
2314
+ _context24.next = 12;
2310
2315
  break;
2311
2316
  }
2312
2317
  newScheduleArr = this.getScheduleDataByIds(targetProductData['schedule.ids']);
2313
2318
  if (!this.store.currentProductMeta) this.store.currentProductMeta = {};
2314
2319
  this.store.currentProductMeta.schedule = newScheduleArr;
2315
- _context25.next = 17;
2320
+ _context24.next = 17;
2316
2321
  break;
2317
2322
  case 12:
2318
2323
  if (!targetProductData.duration) {
2319
- _context25.next = 17;
2324
+ _context24.next = 17;
2320
2325
  break;
2321
2326
  }
2322
2327
  dateRange = this.store.date.getDateRange(); // 如果不是先选日期的流程 duration 商品就啥也不做
2323
2328
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
2324
- _context25.next = 16;
2329
+ _context24.next = 16;
2325
2330
  break;
2326
2331
  }
2327
- return _context25.abrupt("return");
2332
+ return _context24.abrupt("return");
2328
2333
  case 16:
2329
2334
  // this.store.date.getResourceDates({
2330
2335
  // query: {
@@ -2340,11 +2345,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2340
2345
  });
2341
2346
  case 17:
2342
2347
  case "end":
2343
- return _context25.stop();
2348
+ return _context24.stop();
2344
2349
  }
2345
- }, _callee25, this);
2350
+ }, _callee24, this);
2346
2351
  }));
2347
- function openProductDetail(_x19) {
2352
+ function openProductDetail(_x18) {
2348
2353
  return _openProductDetail.apply(this, arguments);
2349
2354
  }
2350
2355
  return openProductDetail;
@@ -2357,10 +2362,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2357
2362
  }
2358
2363
  this.store.currentProduct = undefined;
2359
2364
  }
2365
+
2366
+ // 通过商品和 schedule 来获取视频可用的时间片、时间片内资源可用的数据
2360
2367
  }, {
2361
2368
  key: "getTimeslotBySchedule",
2362
2369
  value: function getTimeslotBySchedule(_ref10) {
2363
- var _this$store$currentPr2, _targetProductData$pr;
2370
+ var _this$store$currentPr2,
2371
+ _targetProductData$pr,
2372
+ _this14 = this;
2364
2373
  var date = _ref10.date,
2365
2374
  scheduleIds = _ref10.scheduleIds,
2366
2375
  resources = _ref10.resources,
@@ -2467,6 +2476,129 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2467
2476
  }
2468
2477
  }
2469
2478
  });
2479
+ // 容量检测
2480
+ var cartItems = _this14.store.cart.getItems();
2481
+ productResources.forEach(function (n) {
2482
+ // 单个预约检测规则:
2483
+ // 1、跟我一样的商品同一时间在购物车里不可以超过我最少的那种资源的关联的资源个数
2484
+ // 2、跟我不一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,她配置了几个资源的个数+我配置了几个资源的个数,然后购物车里有几个这样的商品,对应的资源做一个去重,不超过这个去重以后的总数
2485
+ if (n.type === 'single') {
2486
+ var currentResourcesSet = new Set([].concat(_toConsumableArray(n.optional_resource), _toConsumableArray(n.default_resource)));
2487
+ // 规则 1
2488
+ var sameCartItems = cartItems.filter(function (m) {
2489
+ var _m$_productOrigin, _targetProductData$id;
2490
+ return ((_m$_productOrigin = m._productOrigin) === null || _m$_productOrigin === void 0 || (_m$_productOrigin = _m$_productOrigin.id) === null || _m$_productOrigin === void 0 ? void 0 : _m$_productOrigin.toString()) === (targetProductData === null || targetProductData === void 0 || (_targetProductData$id = targetProductData.id) === null || _targetProductData$id === void 0 ? void 0 : _targetProductData$id.toString()) && "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
2491
+ });
2492
+ if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length > bookingLeft) {
2493
+ bookingLeft = 0;
2494
+ count = 0;
2495
+ }
2496
+ // 规则 2
2497
+ var otherCartItems = cartItems.filter(function (m) {
2498
+ var _m$_productOrigin2, _targetProductData$id2;
2499
+ return ((_m$_productOrigin2 = m._productOrigin) === null || _m$_productOrigin2 === void 0 || (_m$_productOrigin2 = _m$_productOrigin2.id) === null || _m$_productOrigin2 === void 0 ? void 0 : _m$_productOrigin2.toString()) !== (targetProductData === null || targetProductData === void 0 || (_targetProductData$id2 = targetProductData.id) === null || _targetProductData$id2 === void 0 ? void 0 : _targetProductData$id2.toString()) && "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
2500
+ });
2501
+ otherCartItems.forEach(function (m) {
2502
+ var _m$_productOrigin3;
2503
+ var sameTypeResources = (_m$_productOrigin3 = m._productOrigin) === null || _m$_productOrigin3 === void 0 || (_m$_productOrigin3 = _m$_productOrigin3.product_resource) === null || _m$_productOrigin3 === void 0 || (_m$_productOrigin3 = _m$_productOrigin3.resources) === null || _m$_productOrigin3 === void 0 ? void 0 : _m$_productOrigin3.find(function (m) {
2504
+ return m.type === n.type;
2505
+ });
2506
+ var sameTypeResourcesSet = new Set([].concat(_toConsumableArray((sameTypeResources === null || sameTypeResources === void 0 ? void 0 : sameTypeResources.optional_resource) || []), _toConsumableArray((sameTypeResources === null || sameTypeResources === void 0 ? void 0 : sameTypeResources.default_resource) || [])));
2507
+ // 把sameTypeResourcesSet 加到currentResourcesSet
2508
+ sameTypeResourcesSet.forEach(function (resource) {
2509
+ return currentResourcesSet.add(resource);
2510
+ });
2511
+ });
2512
+ // 先确定是否每一个currentResourcesSet在这个时间点的 event_list 都是空的,如果不是空的还需要把他踢出currentResourcesSet
2513
+ var currentDataResources = _this14.store.date.getResourcesListByDate(dayjs(item.start).format('YYYY-MM-DD'));
2514
+ currentDataResources === null || currentDataResources === void 0 || currentDataResources.forEach(function (m) {
2515
+ if (currentResourcesSet.has(m.id)) {
2516
+ var mTimes = m.times.filter(function (n) {
2517
+ return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute') || dayjs(n.start_at).isBefore(dayjs(item.end), 'minute') && dayjs(n.end_at).isAfter(dayjs(item.start), 'minute');
2518
+ });
2519
+ if (!mTimes.length || mTimes.some(function (n) {
2520
+ return n.event_list.length;
2521
+ })) {
2522
+ currentResourcesSet.delete(m.id);
2523
+ }
2524
+ }
2525
+ });
2526
+ if (currentResourcesSet.size > 0 && otherCartItems.length + sameCartItems.length >= currentResourcesSet.size) {
2527
+ bookingLeft = 0;
2528
+ count = 0;
2529
+ }
2530
+ } else {
2531
+ // 多个预约的检测规则:
2532
+ // 规则1、跟我一样的商品同一时间在购物车需要的容量总数不可以超过我配置的资源的 capacity 之和
2533
+ var _sameCartItems = cartItems.filter(function (m) {
2534
+ var _m$_productOrigin4, _targetProductData$id3;
2535
+ return ((_m$_productOrigin4 = m._productOrigin) === null || _m$_productOrigin4 === void 0 || (_m$_productOrigin4 = _m$_productOrigin4.id) === null || _m$_productOrigin4 === void 0 ? void 0 : _m$_productOrigin4.toString()) === (targetProductData === null || targetProductData === void 0 || (_targetProductData$id3 = targetProductData.id) === null || _targetProductData$id3 === void 0 ? void 0 : _targetProductData$id3.toString()) && "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
2536
+ });
2537
+ var sameCartNeedCapacity = _sameCartItems.reduce(function (acc, curr) {
2538
+ return acc + getCapacityInfoByCartItem(curr).currentCapacity;
2539
+ }, 0);
2540
+ var currentProductResourcesCapacity = n.renderList.reduce(function (acc, curr) {
2541
+ return !curr.onlyComputed ? acc + curr.capacity || 0 : acc;
2542
+ }, 0);
2543
+ if (sameCartNeedCapacity >= currentProductResourcesCapacity) {
2544
+ bookingLeft = 0;
2545
+ count = 0;
2546
+ }
2547
+ // 规则2、不管是不是跟我一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,把所有购物车的 capacity 之和 和 所有当前类型资源的 capacity 之和比较,如果超过了resourcesCapacity,则不可用
2548
+ // const otherCartItems = cartItems.filter((m) => m._productOrigin?.id?.toString() !== targetProductData?.id?.toString() && m.start_time === item.start && m.end_time === item.end);
2549
+ var otherSameTimesCartItems = cartItems.filter(function (m) {
2550
+ return "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
2551
+ });
2552
+ var otherCartNeedCapacity = otherSameTimesCartItems.reduce(function (acc, curr) {
2553
+ return acc + getCapacityInfoByCartItem(curr).currentCapacity;
2554
+ }, 0);
2555
+ var allRenderList = _toConsumableArray(n.renderList.filter(function (m) {
2556
+ return !m.onlyComputed;
2557
+ }));
2558
+ otherSameTimesCartItems.forEach(function (m) {
2559
+ var _m$_productOrigin5;
2560
+ var productResources = getResourcesByProduct(getResourcesMap((targetResourceDate === null || targetResourceDate === void 0 ? void 0 : targetResourceDate.resource) || []), ((_m$_productOrigin5 = m._productOrigin) === null || _m$_productOrigin5 === void 0 || (_m$_productOrigin5 = _m$_productOrigin5.product_resource) === null || _m$_productOrigin5 === void 0 ? void 0 : _m$_productOrigin5.resources) || [], selectedResources, 1);
2561
+ productResources.forEach(function (m) {
2562
+ if (m.id === n.id) {
2563
+ m.renderList.forEach(function (n) {
2564
+ if (!n.onlyComputed && !allRenderList.find(function (m) {
2565
+ return m.id === n.id;
2566
+ })) {
2567
+ allRenderList.push(n);
2568
+ }
2569
+ });
2570
+ }
2571
+ });
2572
+ });
2573
+ var currentTypeResourcesCapacity = allRenderList.reduce(function (acc, curr) {
2574
+ return acc + curr.capacity || 0;
2575
+ }, 0);
2576
+ // 计算当前时间段内所有资源的已使用容量
2577
+ var usedCapacity = allRenderList.reduce(function (acc, curr) {
2578
+ var mTimes = curr.times.filter(function (n) {
2579
+ return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute') || dayjs(n.start_at).isBefore(dayjs(item.end), 'minute') && dayjs(n.end_at).isAfter(dayjs(item.start), 'minute');
2580
+ });
2581
+ // 这里为什么要设置个 map,因为有可能日程有重叠,所以要把重叠的 event_list 去除
2582
+ var mSet = new Map();
2583
+ mTimes.forEach(function (n) {
2584
+ // acc += n.event_list?.reduce((acc: any, curr: any) => acc + curr.pax, 0);
2585
+ // mSet.set(n)
2586
+ n.event_list.forEach(function (m) {
2587
+ mSet.set(m.id, m.pax || 1);
2588
+ });
2589
+ });
2590
+ acc += Array.from(mSet.values()).reduce(function (acc, curr) {
2591
+ return acc + curr;
2592
+ }, 0);
2593
+ return acc;
2594
+ }, 0);
2595
+ // 如果已使用容量超过了当前类型资源的容量,则不可用
2596
+ if (otherCartNeedCapacity + usedCapacity >= currentTypeResourcesCapacity) {
2597
+ bookingLeft = 0;
2598
+ count = 0;
2599
+ }
2600
+ }
2601
+ });
2470
2602
  var startDayJs = dayjs(item.start);
2471
2603
  var endDayJs = dayjs(item.end);
2472
2604
  return {
@@ -2480,6 +2612,436 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2480
2612
  });
2481
2613
  return formatScheduleTimeSlots;
2482
2614
  }
2615
+
2616
+ // 提供给 UI的方法,当前步骤是选择商品,下一步不管是什么都需要在这里做一次检测
2617
+ // 时长类商品关联的资源为多个预约时,在点击进入"选择资源"步骤之前,需要检测当前所有资源的总容量
2618
+ // 选择商品数量大于所有资源配置的总容量时,不能进入下一步,需要在"选择商品"这一步时提示。
2619
+ // 注意 资源分为多个种类,需要每个种类单独检测,不能一股脑把所有资源的容量加起来检测
2620
+ /**
2621
+ * 找到多个资源的公共可用时间段
2622
+ */
2623
+ }, {
2624
+ key: "findCommonAvailableTimeSlots",
2625
+ value: function findCommonAvailableTimeSlots(resources) {
2626
+ if (resources.length === 0) return [];
2627
+ console.log("\u8BA1\u7B97 ".concat(resources.length, " \u4E2A\u8D44\u6E90\u7684\u516C\u5171\u65F6\u95F4\u6BB5"));
2628
+
2629
+ // 收集所有资源的时间段,转换为统一的时间格式
2630
+ var allTimeSlots = resources.map(function (resource) {
2631
+ return resource.times.map(function (time) {
2632
+ return {
2633
+ start: dayjs(time.start_at),
2634
+ end: dayjs(time.end_at)
2635
+ };
2636
+ });
2637
+ });
2638
+ console.log('所有资源的时间段:', allTimeSlots.map(function (slots) {
2639
+ return slots.map(function (slot) {
2640
+ return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
2641
+ });
2642
+ }));
2643
+
2644
+ // 找到公共时间段的交集
2645
+ var commonSlots = allTimeSlots[0]; // 从第一个资源的时间段开始
2646
+ console.log('初始公共时间段:', commonSlots.map(function (slot) {
2647
+ return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
2648
+ }));
2649
+
2650
+ // 与其他资源的时间段求交集
2651
+ var _loop2 = function _loop2() {
2652
+ var currentResourceSlots = allTimeSlots[i];
2653
+ var intersections = [];
2654
+
2655
+ // 计算当前公共时间段与下一个资源时间段的交集
2656
+ commonSlots.forEach(function (commonSlot) {
2657
+ currentResourceSlots.forEach(function (currentSlot) {
2658
+ var overlapStart = commonSlot.start.isAfter(currentSlot.start) ? commonSlot.start : currentSlot.start;
2659
+ var overlapEnd = commonSlot.end.isBefore(currentSlot.end) ? commonSlot.end : currentSlot.end;
2660
+
2661
+ // 如果有重叠时间且重叠时间大于0
2662
+ if (overlapStart.isBefore(overlapEnd)) {
2663
+ intersections.push({
2664
+ start: overlapStart,
2665
+ end: overlapEnd
2666
+ });
2667
+ }
2668
+ });
2669
+ });
2670
+ commonSlots = intersections;
2671
+ console.log("\u4E0E\u8D44\u6E90".concat(i, "\u6C42\u4EA4\u96C6\u540E\u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonSlots.map(function (slot) {
2672
+ return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
2673
+ }));
2674
+
2675
+ // 如果没有公共时间段,直接返回
2676
+ if (commonSlots.length === 0) {
2677
+ console.log('没有找到公共时间段');
2678
+ return {
2679
+ v: []
2680
+ };
2681
+ }
2682
+ },
2683
+ _ret2;
2684
+ for (var i = 1; i < allTimeSlots.length; i++) {
2685
+ _ret2 = _loop2();
2686
+ if (_ret2) return _ret2.v;
2687
+ }
2688
+
2689
+ // 格式化返回结果
2690
+ var result = commonSlots.map(function (slot) {
2691
+ return {
2692
+ startTime: slot.start.format('HH:mm'),
2693
+ endTime: slot.end.format('HH:mm')
2694
+ };
2695
+ });
2696
+ console.log('最终公共时间段:', result);
2697
+ return result;
2698
+ }
2699
+ }, {
2700
+ key: "checkMaxDurationCapacity",
2701
+ value: function checkMaxDurationCapacity() {
2702
+ var _this15 = this;
2703
+ var cartItems = cloneDeep(this.store.cart.getItems());
2704
+ if (cartItems.length === 0) return {
2705
+ success: true,
2706
+ minAvailableCount: 0
2707
+ };
2708
+
2709
+ // 将购物车商品分为有时间的和没有时间的
2710
+ var itemsWithTime = [];
2711
+ var itemsWithoutTime = [];
2712
+ // 记录每种资源类型的可用数量
2713
+ var availableCountsByResourceType = [];
2714
+ cartItems.forEach(function (cartItem) {
2715
+ if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
2716
+ itemsWithTime.push(cartItem);
2717
+ } else {
2718
+ itemsWithoutTime.push(cartItem);
2719
+ }
2720
+ });
2721
+
2722
+ // 处理没有时间的商品,为它们分配公共可用时间的第一个时间片
2723
+ var processedItemsWithoutTime = [];
2724
+ if (itemsWithoutTime.length > 0) {
2725
+ // 按资源类型分组处理没有时间的商品
2726
+ var itemsByResourceType = {};
2727
+ itemsWithoutTime.forEach(function (cartItem) {
2728
+ var _cartItem$_productOri10;
2729
+ if (!cartItem._productOrigin) return;
2730
+ var resourceTypes = ((_cartItem$_productOri10 = cartItem._productOrigin.product_resource) === null || _cartItem$_productOri10 === void 0 ? void 0 : _cartItem$_productOri10.resources) || [];
2731
+ resourceTypes.forEach(function (resourceType) {
2732
+ if (resourceType.status === 1) {
2733
+ var _resourceType$id;
2734
+ var resourceCode = resourceType.code || ((_resourceType$id = resourceType.id) === null || _resourceType$id === void 0 ? void 0 : _resourceType$id.toString());
2735
+ if (!itemsByResourceType[resourceCode]) {
2736
+ itemsByResourceType[resourceCode] = [];
2737
+ }
2738
+ // 避免重复添加同一个商品
2739
+ if (!itemsByResourceType[resourceCode].find(function (item) {
2740
+ return item._id === cartItem._id;
2741
+ })) {
2742
+ itemsByResourceType[resourceCode].push(cartItem);
2743
+ }
2744
+ }
2745
+ });
2746
+ });
2747
+
2748
+ // 为每种资源类型检查容量
2749
+ var dateRange = this.store.date.getDateRange();
2750
+ if (!dateRange || dateRange.length === 0) return {
2751
+ success: false,
2752
+ minAvailableCount: 0
2753
+ };
2754
+ var resourcesDates = this.store.date.getDateList();
2755
+ var targetResourceDate = resourcesDates.find(function (n) {
2756
+ return n.date === dateRange[0].date;
2757
+ });
2758
+ if (!targetResourceDate) return {
2759
+ success: false,
2760
+ minAvailableCount: 0
2761
+ };
2762
+ var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
2763
+
2764
+ // 从购物车商品中获取资源类型配置,建立 resourceCode 到 form_id 的映射关系
2765
+ var resourceCodeToFormIdMap = {};
2766
+
2767
+ // 遍历购物车中的商品,收集所有资源类型配置
2768
+ Object.values(itemsByResourceType).flat().forEach(function (cartItem) {
2769
+ var _cartItem$_productOri11;
2770
+ if ((_cartItem$_productOri11 = cartItem._productOrigin) !== null && _cartItem$_productOri11 !== void 0 && (_cartItem$_productOri11 = _cartItem$_productOri11.product_resource) !== null && _cartItem$_productOri11 !== void 0 && _cartItem$_productOri11.resources) {
2771
+ cartItem._productOrigin.product_resource.resources.forEach(function (resourceConfig) {
2772
+ // 只处理启用的资源类型 (status === 1)
2773
+ if (resourceConfig.status === 1 && resourceConfig.code) {
2774
+ var _resourceConfig$id, _resourceConfig$resou;
2775
+ var formId = ((_resourceConfig$id = resourceConfig.id) === null || _resourceConfig$id === void 0 ? void 0 : _resourceConfig$id.toString()) || ((_resourceConfig$resou = resourceConfig.resource_type_id) === null || _resourceConfig$resou === void 0 ? void 0 : _resourceConfig$resou.toString());
2776
+ if (formId) {
2777
+ resourceCodeToFormIdMap[resourceConfig.code] = formId;
2778
+ }
2779
+ }
2780
+ });
2781
+ }
2782
+ });
2783
+ var hasCapacityIssue = false;
2784
+ var resourceCapacityInfo = [];
2785
+
2786
+ // 用于跟踪已处理的商品,避免重复添加
2787
+ var processedCartItemIds = new Set();
2788
+
2789
+ // 先检查所有资源类型,收集可用数量信息
2790
+ var _loop3 = function _loop3() {
2791
+ var _resourceTypeConfig;
2792
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
2793
+ resourceCode = _Object$entries$_i[0],
2794
+ items = _Object$entries$_i[1];
2795
+ // 获取该资源类型对应的 form_id
2796
+ var targetFormId = resourceCodeToFormIdMap[resourceCode];
2797
+ if (!targetFormId) {
2798
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u627E\u4E0D\u5230\u5BF9\u5E94\u7684 form_id"));
2799
+ return {
2800
+ v: {
2801
+ success: false,
2802
+ minAvailableCount: 0
2803
+ }
2804
+ };
2805
+ }
2806
+
2807
+ // 获取该资源类型的所有资源
2808
+ var resourcesOfThisType = [];
2809
+ items.forEach(function (cartItem) {
2810
+ var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
2811
+ productResourceIds.forEach(function (resourceId) {
2812
+ var _resource$form_id;
2813
+ var resource = resourcesMap[resourceId];
2814
+ if (resource && ((_resource$form_id = resource.form_id) === null || _resource$form_id === void 0 ? void 0 : _resource$form_id.toString()) === targetFormId) {
2815
+ // 避免重复添加同一个资源
2816
+ if (!resourcesOfThisType.find(function (r) {
2817
+ return r.id === resource.id;
2818
+ })) {
2819
+ resourcesOfThisType.push(resource);
2820
+ }
2821
+ }
2822
+ });
2823
+ });
2824
+ if (resourcesOfThisType.length === 0) {
2825
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u627E\u5230\u53EF\u7528\u8D44\u6E90"));
2826
+ return {
2827
+ v: {
2828
+ success: false,
2829
+ minAvailableCount: 0
2830
+ }
2831
+ };
2832
+ }
2833
+
2834
+ // 检查资源类型(单个预约 vs 多个预约)
2835
+ // 从商品配置中获取资源类型信息
2836
+ var resourceTypeConfig = null;
2837
+ var _iterator3 = _createForOfIteratorHelper(items),
2838
+ _step3;
2839
+ try {
2840
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
2841
+ var _cartItem$_productOri12;
2842
+ var cartItem = _step3.value;
2843
+ if ((_cartItem$_productOri12 = cartItem._productOrigin) !== null && _cartItem$_productOri12 !== void 0 && (_cartItem$_productOri12 = _cartItem$_productOri12.product_resource) !== null && _cartItem$_productOri12 !== void 0 && _cartItem$_productOri12.resources) {
2844
+ resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
2845
+ return r.code === resourceCode && r.status === 1;
2846
+ });
2847
+ if (resourceTypeConfig) break;
2848
+ }
2849
+ }
2850
+ } catch (err) {
2851
+ _iterator3.e(err);
2852
+ } finally {
2853
+ _iterator3.f();
2854
+ }
2855
+ var isMultipleBooking = ((_resourceTypeConfig = resourceTypeConfig) === null || _resourceTypeConfig === void 0 ? void 0 : _resourceTypeConfig.type) === 'multiple';
2856
+ var totalAvailable;
2857
+ var requiredAmount;
2858
+ var availableAmount;
2859
+ if (isMultipleBooking) {
2860
+ // 多个预约:计算容量
2861
+ totalAvailable = resourcesOfThisType.reduce(function (sum, resource) {
2862
+ return sum + (resource.capacity || 0);
2863
+ }, 0);
2864
+ requiredAmount = items.reduce(function (sum, cartItem) {
2865
+ var _getCapacityInfoByCar7 = getCapacityInfoByCartItem(cartItem),
2866
+ currentCapacity = _getCapacityInfoByCar7.currentCapacity;
2867
+ return sum + currentCapacity;
2868
+ }, 0);
2869
+ availableAmount = Math.max(0, totalAvailable - requiredAmount);
2870
+ } else {
2871
+ // 单个预约:计算资源个数
2872
+ totalAvailable = resourcesOfThisType.length;
2873
+ requiredAmount = items.reduce(function (sum, cartItem) {
2874
+ return sum + (cartItem.num || 1);
2875
+ }, 0);
2876
+ availableAmount = Math.max(0, totalAvailable - requiredAmount);
2877
+ }
2878
+
2879
+ // 记录资源容量信息
2880
+ resourceCapacityInfo.push({
2881
+ code: resourceCode,
2882
+ available: availableAmount,
2883
+ total: totalAvailable,
2884
+ required: requiredAmount,
2885
+ isMultiple: isMultipleBooking
2886
+ });
2887
+ availableCountsByResourceType.push(availableAmount);
2888
+
2889
+ // 检查是否有容量问题
2890
+ if (requiredAmount > totalAvailable) {
2891
+ hasCapacityIssue = true;
2892
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " ").concat(isMultipleBooking ? '容量' : '资源数量', "\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredAmount, ", \u603B\u5171 ").concat(totalAvailable));
2893
+ }
2894
+
2895
+ // 为通过检测的商品分配一个公共可用时间段
2896
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u8D44\u6E90\u65F6\u95F4\u4FE1\u606F:"), resourcesOfThisType.map(function (r) {
2897
+ return {
2898
+ id: r.id,
2899
+ times: r.times.map(function (t) {
2900
+ return "".concat(t.start_at, " - ").concat(t.end_at);
2901
+ })
2902
+ };
2903
+ }));
2904
+
2905
+ // 找到所有资源都可用的时间段
2906
+ var commonTimeSlots = _this15.findCommonAvailableTimeSlots(resourcesOfThisType);
2907
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonTimeSlots);
2908
+ if (commonTimeSlots.length === 0) {
2909
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4\u6BB5"));
2910
+ return {
2911
+ v: {
2912
+ success: false,
2913
+ minAvailableCount: 0
2914
+ }
2915
+ };
2916
+ }
2917
+
2918
+ // 使用第一个公共可用时间段,但只处理未处理过的商品
2919
+ var firstCommonSlot = commonTimeSlots[0];
2920
+ console.log("\u4F7F\u7528\u516C\u5171\u65F6\u95F4\u6BB5: ".concat(firstCommonSlot.startTime, " - ").concat(firstCommonSlot.endTime));
2921
+ items.forEach(function (cartItem) {
2922
+ // 只处理未处理过的商品,避免重复添加
2923
+ if (!processedCartItemIds.has(cartItem._id)) {
2924
+ processedCartItemIds.add(cartItem._id);
2925
+ var processedItem = _objectSpread(_objectSpread({}, cartItem), {}, {
2926
+ start_date: dateRange[0].date,
2927
+ start_time: firstCommonSlot.startTime,
2928
+ end_time: firstCommonSlot.endTime,
2929
+ end_date: dateRange[0].date
2930
+ });
2931
+ processedItemsWithoutTime.push(processedItem);
2932
+ }
2933
+ });
2934
+ },
2935
+ _ret3;
2936
+ for (var _i = 0, _Object$entries = Object.entries(itemsByResourceType); _i < _Object$entries.length; _i++) {
2937
+ _ret3 = _loop3();
2938
+ if (_ret3) return _ret3.v;
2939
+ }
2940
+
2941
+ // 如果有容量问题,找出限制最严格的资源类型,返回其总容量
2942
+ if (hasCapacityIssue) {
2943
+ // 找出超出容量的资源类型中,总容量最少的那个
2944
+ var overCapacityResources = resourceCapacityInfo.filter(function (info) {
2945
+ return info.required > info.total;
2946
+ });
2947
+ if (overCapacityResources.length > 0) {
2948
+ var _minTotalCapacity = Math.min.apply(Math, _toConsumableArray(overCapacityResources.map(function (info) {
2949
+ return info.total;
2950
+ })));
2951
+ return {
2952
+ success: false,
2953
+ minAvailableCount: _minTotalCapacity
2954
+ };
2955
+ }
2956
+ // 如果没有超出容量的(理论上不应该发生),返回总容量最少的
2957
+ var minTotalCapacity = Math.min.apply(Math, _toConsumableArray(resourceCapacityInfo.map(function (info) {
2958
+ return info.total;
2959
+ })));
2960
+ return {
2961
+ success: false,
2962
+ minAvailableCount: minTotalCapacity
2963
+ };
2964
+ }
2965
+ }
2966
+
2967
+ // 合并所有商品(有时间的 + 处理后的没有时间的)
2968
+ var allProcessedItems = [].concat(itemsWithTime, processedItemsWithoutTime);
2969
+
2970
+ // 按时间段分组检查
2971
+ var cartItemsByTimeSlot = {};
2972
+ allProcessedItems.forEach(function (cartItem) {
2973
+ if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date) return;
2974
+ var timeSlotKey = "".concat(cartItem.start_date, "_").concat(cartItem.start_time, "_").concat(cartItem.end_date || cartItem.start_date, "_").concat(cartItem.end_time);
2975
+ if (!cartItemsByTimeSlot[timeSlotKey]) {
2976
+ cartItemsByTimeSlot[timeSlotKey] = [];
2977
+ }
2978
+ cartItemsByTimeSlot[timeSlotKey].push(cartItem);
2979
+ });
2980
+ // 检查每个时间段是否有足够的资源容量
2981
+ var _loop4 = function _loop4() {
2982
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
2983
+ timeSlotKey = _Object$entries2$_i[0],
2984
+ itemsInTimeSlot = _Object$entries2$_i[1];
2985
+ var _timeSlotKey$split = timeSlotKey.split('_'),
2986
+ _timeSlotKey$split2 = _slicedToArray(_timeSlotKey$split, 4),
2987
+ startDate = _timeSlotKey$split2[0],
2988
+ startTime = _timeSlotKey$split2[1],
2989
+ endDate = _timeSlotKey$split2[2],
2990
+ endTime = _timeSlotKey$split2[3];
2991
+ var timeSlotStart = "".concat(startDate, " ").concat(startTime);
2992
+ var timeSlotEnd = "".concat(endDate, " ").concat(endTime);
2993
+
2994
+ // 获取这个时间段所有商品涉及的资源
2995
+ var allResourcesForTimeSlot = [];
2996
+ var resourcesIdSet = new Set();
2997
+
2998
+ // 获取资源数据
2999
+ var dateRange = _this15.store.date.getDateRange();
3000
+ var resourcesDates = _this15.store.date.getDateList();
3001
+ var targetResourceDate = resourcesDates.find(function (n) {
3002
+ return n.date === startDate;
3003
+ });
3004
+ if (!targetResourceDate) return 0; // continue
3005
+ var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
3006
+ itemsInTimeSlot.forEach(function (cartItem) {
3007
+ if (!cartItem._productOrigin) return;
3008
+
3009
+ // 获取商品的资源配置
3010
+ var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
3011
+ productResourceIds.forEach(function (resourceId) {
3012
+ if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
3013
+ resourcesIdSet.add(resourceId);
3014
+ allResourcesForTimeSlot.push(resourcesMap[resourceId]);
3015
+ }
3016
+ });
3017
+ });
3018
+
3019
+ // 按资源类型分组检查容量
3020
+ if (!checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
3021
+ // 如果有可用数量记录,返回最小值;否则返回 0
3022
+ var _minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
3023
+ return {
3024
+ v: {
3025
+ success: false,
3026
+ minAvailableCount: _minAvailableCount
3027
+ }
3028
+ };
3029
+ }
3030
+ },
3031
+ _ret4;
3032
+ for (var _i2 = 0, _Object$entries2 = Object.entries(cartItemsByTimeSlot); _i2 < _Object$entries2.length; _i2++) {
3033
+ _ret4 = _loop4();
3034
+ if (_ret4 === 0) continue;
3035
+ if (_ret4) return _ret4.v;
3036
+ }
3037
+
3038
+ // 全部通过检测,返回成功和最小可用数量
3039
+ var minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
3040
+ return {
3041
+ success: true,
3042
+ minAvailableCount: minAvailableCount
3043
+ };
3044
+ }
2483
3045
  }, {
2484
3046
  key: "setOtherData",
2485
3047
  value: function setOtherData(key, value) {
@@ -2501,41 +3063,41 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2501
3063
  }, {
2502
3064
  key: "getProductTypeById",
2503
3065
  value: function () {
2504
- var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(id) {
3066
+ var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(id) {
2505
3067
  var productData, _productData$schedule;
2506
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2507
- while (1) switch (_context26.prev = _context26.next) {
3068
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
3069
+ while (1) switch (_context25.prev = _context25.next) {
2508
3070
  case 0:
2509
- _context26.next = 2;
3071
+ _context25.next = 2;
2510
3072
  return this.store.products.getProduct(id);
2511
3073
  case 2:
2512
- productData = _context26.sent;
3074
+ productData = _context25.sent;
2513
3075
  if (!productData) {
2514
- _context26.next = 9;
3076
+ _context25.next = 9;
2515
3077
  break;
2516
3078
  }
2517
3079
  if (!productData.duration) {
2518
- _context26.next = 6;
3080
+ _context25.next = 6;
2519
3081
  break;
2520
3082
  }
2521
- return _context26.abrupt("return", 'duration');
3083
+ return _context25.abrupt("return", 'duration');
2522
3084
  case 6:
2523
3085
  if (!((_productData$schedule = productData['schedule.ids']) !== null && _productData$schedule !== void 0 && _productData$schedule.length)) {
2524
- _context26.next = 8;
3086
+ _context25.next = 8;
2525
3087
  break;
2526
3088
  }
2527
- return _context26.abrupt("return", 'session');
3089
+ return _context25.abrupt("return", 'session');
2528
3090
  case 8:
2529
- return _context26.abrupt("return", 'normal');
3091
+ return _context25.abrupt("return", 'normal');
2530
3092
  case 9:
2531
- return _context26.abrupt("return", 'normal');
3093
+ return _context25.abrupt("return", 'normal');
2532
3094
  case 10:
2533
3095
  case "end":
2534
- return _context26.stop();
3096
+ return _context25.stop();
2535
3097
  }
2536
- }, _callee26, this);
3098
+ }, _callee25, this);
2537
3099
  }));
2538
- function getProductTypeById(_x20) {
3100
+ function getProductTypeById(_x19) {
2539
3101
  return _getProductTypeById.apply(this, arguments);
2540
3102
  }
2541
3103
  return getProductTypeById;
@@ -2551,7 +3113,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2551
3113
  }, {
2552
3114
  key: "getResourcesByCartItemAndCode",
2553
3115
  value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
2554
- var _cartItem$_productOri10;
3116
+ var _cartItem$_productOri13;
2555
3117
  var dateRange = this.store.date.getDateRange();
2556
3118
  var resources = [];
2557
3119
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -2574,16 +3136,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2574
3136
  });
2575
3137
  if (!cartItem) return [];
2576
3138
  var selectedResources = [];
2577
- var _getCapacityInfoByCar7 = getCapacityInfoByCartItem(cartItem),
2578
- currentCapacity = _getCapacityInfoByCar7.currentCapacity,
2579
- formatCapacity = _getCapacityInfoByCar7.formatCapacity;
3139
+ var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
3140
+ currentCapacity = _getCapacityInfoByCar8.currentCapacity,
3141
+ formatCapacity = _getCapacityInfoByCar8.formatCapacity;
2580
3142
  cartItem._origin.metadata.capacity = formatCapacity;
2581
3143
  if (cartItem.holder_id) {
2582
3144
  selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
2583
3145
  } else {
2584
3146
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
2585
3147
  }
2586
- var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri10 = cartItem._productOrigin) === null || _cartItem$_productOri10 === void 0 || (_cartItem$_productOri10 = _cartItem$_productOri10.product_resource) === null || _cartItem$_productOri10 === void 0 ? void 0 : _cartItem$_productOri10.resources) || [], selectedResources, currentCapacity);
3148
+ var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri13 = cartItem._productOrigin) === null || _cartItem$_productOri13 === void 0 || (_cartItem$_productOri13 = _cartItem$_productOri13.product_resource) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.resources) || [], selectedResources, currentCapacity);
2587
3149
  var targetResource = productResources.find(function (resource) {
2588
3150
  return resource.code === resourceCode;
2589
3151
  });
@@ -2606,7 +3168,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2606
3168
  });
2607
3169
  if (mTimes.length === 0) return false;
2608
3170
  var canUseArr = mTimes.map(function (item) {
2609
- var _cartItem$_productOri11;
3171
+ var _cartItem$_productOri14;
2610
3172
  var res = getIsUsableByTimeItem({
2611
3173
  timeSlice: {
2612
3174
  start_time: startTime.format('HH:mm'),
@@ -2618,7 +3180,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2618
3180
  resource: m,
2619
3181
  currentCount: currentCapacity || 0,
2620
3182
  resourcesUseableMap: resourcesUseableMap,
2621
- cut_off_time: (_cartItem$_productOri11 = cartItem._productOrigin) === null || _cartItem$_productOri11 === void 0 ? void 0 : _cartItem$_productOri11.cut_off_time
3183
+ cut_off_time: (_cartItem$_productOri14 = cartItem._productOrigin) === null || _cartItem$_productOri14 === void 0 ? void 0 : _cartItem$_productOri14.cut_off_time
2622
3184
  });
2623
3185
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
2624
3186
  resourcesUseableMap[m.id] = res.usable;
@@ -2632,12 +3194,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2632
3194
  });
2633
3195
  } else {
2634
3196
  targetResource.renderList = targetResource.renderList.filter(function (n) {
2635
- var _cartItem$_productOri12;
3197
+ var _cartItem$_productOri15;
2636
3198
  var recordCount = n.capacity || 0;
2637
3199
  if (n.onlyComputed) return false;
2638
3200
  var timeSlots = getTimeSlicesByResource({
2639
3201
  resource: n,
2640
- duration: ((_cartItem$_productOri12 = cartItem._productOrigin) === null || _cartItem$_productOri12 === void 0 || (_cartItem$_productOri12 = _cartItem$_productOri12.duration) === null || _cartItem$_productOri12 === void 0 ? void 0 : _cartItem$_productOri12.value) || 10,
3202
+ duration: ((_cartItem$_productOri15 = cartItem._productOrigin) === null || _cartItem$_productOri15 === void 0 || (_cartItem$_productOri15 = _cartItem$_productOri15.duration) === null || _cartItem$_productOri15 === void 0 ? void 0 : _cartItem$_productOri15.value) || 10,
2641
3203
  split: 10,
2642
3204
  currentDate: dateRange[0].date
2643
3205
  });
@@ -2655,10 +3217,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2655
3217
  }, {
2656
3218
  key: "getTimeslotsScheduleByDateRange",
2657
3219
  value: (function () {
2658
- var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(_ref11) {
2659
- var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i, _dates, date;
2660
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2661
- while (1) switch (_context27.prev = _context27.next) {
3220
+ var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref11) {
3221
+ var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i3, _dates, date;
3222
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3223
+ while (1) switch (_context26.prev = _context26.next) {
2662
3224
  case 0:
2663
3225
  startDate = _ref11.startDate, endDate = _ref11.endDate, scheduleIds = _ref11.scheduleIds, resources = _ref11.resources;
2664
3226
  console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
@@ -2677,22 +3239,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2677
3239
  }
2678
3240
  // 如果不支持 Web Worker,使用同步方式处理
2679
3241
  results = {};
2680
- for (_i = 0, _dates = dates; _i < _dates.length; _i++) {
2681
- date = _dates[_i];
3242
+ for (_i3 = 0, _dates = dates; _i3 < _dates.length; _i3++) {
3243
+ date = _dates[_i3];
2682
3244
  results[date] = this.getTimeslotBySchedule({
2683
3245
  date: date,
2684
3246
  scheduleIds: scheduleIds,
2685
3247
  resources: resources
2686
3248
  });
2687
3249
  }
2688
- return _context27.abrupt("return", results);
3250
+ return _context26.abrupt("return", results);
2689
3251
  case 9:
2690
3252
  case "end":
2691
- return _context27.stop();
3253
+ return _context26.stop();
2692
3254
  }
2693
- }, _callee27, this);
3255
+ }, _callee26, this);
2694
3256
  }));
2695
- function getTimeslotsScheduleByDateRange(_x21) {
3257
+ function getTimeslotsScheduleByDateRange(_x20) {
2696
3258
  return _getTimeslotsScheduleByDateRange.apply(this, arguments);
2697
3259
  }
2698
3260
  return getTimeslotsScheduleByDateRange;
@@ -2700,7 +3262,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2700
3262
  }, {
2701
3263
  key: "getAvailableDateForSessionOptimize",
2702
3264
  value: function () {
2703
- var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
3265
+ var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
2704
3266
  var _this$store$currentPr3, _this$store$currentPr4, _tempProducts;
2705
3267
  var params,
2706
3268
  startDate,
@@ -2719,12 +3281,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2719
3281
  openResources,
2720
3282
  allProductResources,
2721
3283
  targetSchedules,
2722
- _loop2,
2723
- _args29 = arguments;
2724
- return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2725
- while (1) switch (_context29.prev = _context29.next) {
3284
+ _loop5,
3285
+ _args28 = arguments;
3286
+ return _regeneratorRuntime().wrap(function _callee27$(_context28) {
3287
+ while (1) switch (_context28.prev = _context28.next) {
2726
3288
  case 0:
2727
- params = _args29.length > 0 && _args29[0] !== undefined ? _args29[0] : {};
3289
+ params = _args28.length > 0 && _args28[0] !== undefined ? _args28[0] : {};
2728
3290
  // 开始日期如果小于今天,直接以今天当做开始日期
2729
3291
  startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2730
3292
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
@@ -2749,15 +3311,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2749
3311
  // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2750
3312
  cache = (_this$store$currentPr3 = this.store.currentProductMeta) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3['timeSlotBySchedule'];
2751
3313
  if (!cache) {
2752
- _context29.next = 13;
3314
+ _context28.next = 13;
2753
3315
  break;
2754
3316
  }
2755
3317
  if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2756
- _context29.next = 13;
3318
+ _context28.next = 13;
2757
3319
  break;
2758
3320
  }
2759
3321
  this.store.date.setDateList(cache.dateList);
2760
- return _context29.abrupt("return", {
3322
+ return _context28.abrupt("return", {
2761
3323
  dateList: cache.dateList,
2762
3324
  firstAvailableDate: cache.firstAvailableDate
2763
3325
  });
@@ -2767,7 +3329,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2767
3329
  schedule = (_this$store$currentPr4 = this.store.currentProductMeta) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4['schedule'];
2768
3330
  filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2769
3331
  tempResourceIds = getResourcesIdsByProduct(tempProducts);
2770
- _context29.next = 19;
3332
+ _context28.next = 19;
2771
3333
  return this.store.date.fetchResourceDates({
2772
3334
  query: {
2773
3335
  start_date: startDate || '',
@@ -2776,7 +3338,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2776
3338
  }
2777
3339
  });
2778
3340
  case 19:
2779
- res = _context29.sent;
3341
+ res = _context28.sent;
2780
3342
  // 2. 商品 schedule 数据,确定日程在每一天的时间片
2781
3343
  // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
2782
3344
  dates = [];
@@ -2796,10 +3358,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2796
3358
  }
2797
3359
  });
2798
3360
  targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
2799
- _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
3361
+ _loop5 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop5() {
2800
3362
  var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
2801
- return _regeneratorRuntime().wrap(function _loop2$(_context28) {
2802
- while (1) switch (_context28.prev = _context28.next) {
3363
+ return _regeneratorRuntime().wrap(function _loop5$(_context27) {
3364
+ while (1) switch (_context27.prev = _context27.next) {
2803
3365
  case 0:
2804
3366
  currentDateStr = currentDate.format('YYYY-MM-DD');
2805
3367
  status = 'available'; // 1. 检查商品的提前量等情况是否满足
@@ -2891,32 +3453,32 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2891
3453
 
2892
3454
  // 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
2893
3455
  if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 31)) {
2894
- _context28.next = 9;
3456
+ _context27.next = 9;
2895
3457
  break;
2896
3458
  }
2897
- return _context28.abrupt("return", 1);
3459
+ return _context27.abrupt("return", 1);
2898
3460
  case 9:
2899
3461
  currentDate = dayjs(currentDate).add(1, 'day');
2900
3462
  case 10:
2901
3463
  case "end":
2902
- return _context28.stop();
3464
+ return _context27.stop();
2903
3465
  }
2904
- }, _loop2);
3466
+ }, _loop5);
2905
3467
  });
2906
3468
  case 28:
2907
3469
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
2908
- _context29.next = 34;
3470
+ _context28.next = 34;
2909
3471
  break;
2910
3472
  }
2911
- return _context29.delegateYield(_loop2(), "t0", 30);
3473
+ return _context28.delegateYield(_loop5(), "t0", 30);
2912
3474
  case 30:
2913
- if (!_context29.t0) {
2914
- _context29.next = 32;
3475
+ if (!_context28.t0) {
3476
+ _context28.next = 32;
2915
3477
  break;
2916
3478
  }
2917
- return _context29.abrupt("break", 34);
3479
+ return _context28.abrupt("break", 34);
2918
3480
  case 32:
2919
- _context29.next = 28;
3481
+ _context28.next = 28;
2920
3482
  break;
2921
3483
  case 34:
2922
3484
  // 最终把资源数据也加到日期内
@@ -2931,15 +3493,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2931
3493
  startDate: startDate,
2932
3494
  endDate: dayjs(currentDate).format('YYYY-MM-DD')
2933
3495
  };
2934
- return _context29.abrupt("return", {
3496
+ return _context28.abrupt("return", {
2935
3497
  dateList: dates,
2936
3498
  firstAvailableDate: firstAvailableDate
2937
3499
  });
2938
3500
  case 39:
2939
3501
  case "end":
2940
- return _context29.stop();
3502
+ return _context28.stop();
2941
3503
  }
2942
- }, _callee28, this);
3504
+ }, _callee27, this);
2943
3505
  }));
2944
3506
  function getAvailableDateForSessionOptimize() {
2945
3507
  return _getAvailableDateForSessionOptimize.apply(this, arguments);