@pisell/pisellos 3.0.65 → 3.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.
- package/dist/modules/ProductList/index.js +10 -2
- package/dist/solution/BookingByStep/index.d.ts +32 -4
- package/dist/solution/BookingByStep/index.js +1147 -112
- package/dist/solution/BookingByStep/utils/capacity.d.ts +29 -1
- package/dist/solution/BookingByStep/utils/capacity.js +249 -4
- package/dist/solution/BookingByStep/utils/resources.d.ts +15 -0
- package/dist/solution/BookingByStep/utils/resources.js +1 -1
- package/dist/solution/BookingByStep/utils/stock.d.ts +29 -0
- package/dist/solution/BookingByStep/utils/stock.js +126 -0
- package/dist/solution/ShopDiscount/index.js +27 -9
- package/lib/modules/ProductList/index.js +9 -1
- package/lib/solution/BookingByStep/index.d.ts +32 -4
- package/lib/solution/BookingByStep/index.js +694 -44
- package/lib/solution/BookingByStep/utils/capacity.d.ts +29 -1
- package/lib/solution/BookingByStep/utils/capacity.js +182 -3
- package/lib/solution/BookingByStep/utils/resources.d.ts +15 -0
- package/lib/solution/BookingByStep/utils/resources.js +2 -0
- package/lib/solution/BookingByStep/utils/stock.d.ts +29 -0
- package/lib/solution/BookingByStep/utils/stock.js +89 -0
- package/lib/solution/ShopDiscount/index.js +9 -0
- 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."); }
|
|
@@ -26,8 +30,9 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
26
30
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
27
31
|
import { BaseModule } from "../../modules/BaseModule";
|
|
28
32
|
import { BookingByStepHooks, createModule } from "./types";
|
|
33
|
+
import { formatProductToCartItem, createCartItemOrigin, getUniqueId, handleVariantProduct, formatDateToCartItem, formatAccountToCartItem } from "../../modules/Cart/utils";
|
|
29
34
|
import { getAvailableProductResources } from "./utils/products";
|
|
30
|
-
import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime,
|
|
35
|
+
import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection, isConflict } from "./utils/resources";
|
|
31
36
|
import dayjs from 'dayjs';
|
|
32
37
|
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
|
33
38
|
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
|
|
@@ -40,7 +45,8 @@ import { handleAvailableDateByResource } from "../../modules/Date/utils";
|
|
|
40
45
|
import { areAllNormalProducts, isNormalProduct } from "../../modules/Product/utils";
|
|
41
46
|
import { calculateResourceAvailableTime, filterConditionTimeSlots, findFastestAvailableResource } from "./utils/timeslots";
|
|
42
47
|
import { updateAllCartItemPrice } from "../../modules/Cart/utils/changePrice";
|
|
43
|
-
import { getCapacityInfoByCartItem, checkSubResourcesCapacity, checkResourceCanUseByCapacity } from "./utils/capacity";
|
|
48
|
+
import { getCapacityInfoByCartItem, checkSubResourcesCapacity, checkResourceCanUseByCapacity, getResourcesIdsByProduct, checkTimeSlotCapacity } from "./utils/capacity";
|
|
49
|
+
import { checkProductStock } from "./utils/stock";
|
|
44
50
|
export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
45
51
|
_inherits(BookingByStepImpl, _BaseModule);
|
|
46
52
|
var _super = _createSuper(BookingByStepImpl);
|
|
@@ -1101,29 +1107,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1101
1107
|
*/
|
|
1102
1108
|
}, {
|
|
1103
1109
|
key: "storeProduct",
|
|
1104
|
-
value:
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
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
|
-
}()
|
|
1110
|
+
value: function storeProduct(productData) {
|
|
1111
|
+
// 往购物车加商品数据的时候,默认用当前 activeAccount 填充到 product 的 account 里面
|
|
1112
|
+
var activeAccount = this.getActiveAccount();
|
|
1113
|
+
// 直接调用 addProductToCart,不传递 date 参数以避免日期检查逻辑
|
|
1114
|
+
return this.addProductToCart({
|
|
1115
|
+
product: productData,
|
|
1116
|
+
account: activeAccount
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1127
1120
|
/**
|
|
1128
1121
|
* 往购物车加商品数据
|
|
1129
1122
|
*
|
|
@@ -1139,7 +1132,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1139
1132
|
* @return {*}
|
|
1140
1133
|
* @memberof BookingByStepImpl
|
|
1141
1134
|
*/
|
|
1142
|
-
)
|
|
1143
1135
|
}, {
|
|
1144
1136
|
key: "addProductToCart",
|
|
1145
1137
|
value: function addProductToCart(_ref6) {
|
|
@@ -1157,6 +1149,21 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1157
1149
|
var productData = _objectSpread(_objectSpread({}, origin), {}, {
|
|
1158
1150
|
product_variant_id: product_variant_id
|
|
1159
1151
|
});
|
|
1152
|
+
|
|
1153
|
+
// 库存检测
|
|
1154
|
+
var currentCartItems = this.store.cart.getItems();
|
|
1155
|
+
var stockCheckResult = checkProductStock({
|
|
1156
|
+
productData: productData,
|
|
1157
|
+
product_variant_id: product_variant_id,
|
|
1158
|
+
quantity: quantity,
|
|
1159
|
+
bundle: bundle,
|
|
1160
|
+
currentCartItems: currentCartItems
|
|
1161
|
+
});
|
|
1162
|
+
|
|
1163
|
+
// 如果库存检测失败,直接返回
|
|
1164
|
+
if (!stockCheckResult.success) {
|
|
1165
|
+
return stockCheckResult;
|
|
1166
|
+
}
|
|
1160
1167
|
if (!account) {
|
|
1161
1168
|
var activeAccount = this.getActiveAccount();
|
|
1162
1169
|
if (activeAccount) {
|
|
@@ -1169,7 +1176,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1169
1176
|
account: account || undefined
|
|
1170
1177
|
});
|
|
1171
1178
|
if (flag) {
|
|
1172
|
-
return
|
|
1179
|
+
return {
|
|
1180
|
+
success: true
|
|
1181
|
+
};
|
|
1173
1182
|
}
|
|
1174
1183
|
var addItemParams = {
|
|
1175
1184
|
product: productData,
|
|
@@ -1186,7 +1195,19 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1186
1195
|
this.addProductCheck({
|
|
1187
1196
|
date: date
|
|
1188
1197
|
});
|
|
1189
|
-
|
|
1198
|
+
// 如果 quantity 大于 1,且是预约商品,则进入购物车拆散成多条数据
|
|
1199
|
+
if (addItemParams.quantity > 1 && !isNormalProduct(productData)) {
|
|
1200
|
+
for (var i = 0; i < addItemParams.quantity; i++) {
|
|
1201
|
+
var newAddItemParams = cloneDeep(addItemParams);
|
|
1202
|
+
newAddItemParams.quantity = 1;
|
|
1203
|
+
this.store.cart.addItem(newAddItemParams);
|
|
1204
|
+
}
|
|
1205
|
+
} else {
|
|
1206
|
+
this.store.cart.addItem(addItemParams);
|
|
1207
|
+
}
|
|
1208
|
+
return {
|
|
1209
|
+
success: true
|
|
1210
|
+
};
|
|
1190
1211
|
}
|
|
1191
1212
|
|
|
1192
1213
|
/**
|
|
@@ -2039,7 +2060,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2039
2060
|
// item._origin.resources?.forEach((n: any) => {
|
|
2040
2061
|
// resourceIds.push(n.relation_id);
|
|
2041
2062
|
// });
|
|
2042
|
-
if (item.resource_id) {
|
|
2063
|
+
if (item.resource_id && !resourceIds.includes(item.resource_id)) {
|
|
2043
2064
|
resourceIds.push(item.resource_id);
|
|
2044
2065
|
}
|
|
2045
2066
|
resourcesTypeId = item === null || item === void 0 || (_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.product_resource) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.resources) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.find(function (n) {
|
|
@@ -2134,6 +2155,26 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2134
2155
|
return 0;
|
|
2135
2156
|
}, 0);
|
|
2136
2157
|
}
|
|
2158
|
+
// 计算容量的辅助函数
|
|
2159
|
+
var calculateCapacityFromCartItems = function calculateCapacityFromCartItems(items) {
|
|
2160
|
+
return items.reduce(function (total, item) {
|
|
2161
|
+
return total + (getCapacityInfoByCartItem(item).currentCapacity || 0);
|
|
2162
|
+
}, 0);
|
|
2163
|
+
};
|
|
2164
|
+
|
|
2165
|
+
// 如果是多个预约,去要求助几个 holder 下最大的需求容量capacity
|
|
2166
|
+
var maxCapacity = 1;
|
|
2167
|
+
if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
|
|
2168
|
+
accountList.forEach(function (account) {
|
|
2169
|
+
var accountCartItems = _this12.store.cart.getCartByAccount(account.getId());
|
|
2170
|
+
var currentCapacity = calculateCapacityFromCartItems(accountCartItems);
|
|
2171
|
+
if (currentCapacity > maxCapacity) {
|
|
2172
|
+
maxCapacity = currentCapacity;
|
|
2173
|
+
}
|
|
2174
|
+
});
|
|
2175
|
+
} else {
|
|
2176
|
+
maxCapacity = calculateCapacityFromCartItems(cartItems);
|
|
2177
|
+
}
|
|
2137
2178
|
var timeSlots = getTimeSlicesByResources({
|
|
2138
2179
|
resourceIds: resourceIds,
|
|
2139
2180
|
resourcesMap: resourcesMap,
|
|
@@ -2141,6 +2182,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2141
2182
|
currentDate: dateRange[0].date,
|
|
2142
2183
|
split: 10,
|
|
2143
2184
|
resourcesUseableMap: resourcesUseableMap,
|
|
2185
|
+
capacity: maxCapacity,
|
|
2144
2186
|
cut_off_time: maxCutOffTime,
|
|
2145
2187
|
hasFlexibleDuration: hasFlexibleDuration,
|
|
2146
2188
|
operating_day_boundary: operating_day_boundary,
|
|
@@ -2242,12 +2284,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2242
2284
|
});
|
|
2243
2285
|
});
|
|
2244
2286
|
}
|
|
2245
|
-
}, {
|
|
2246
|
-
key: "clearCache",
|
|
2247
|
-
value: function clearCache() {}
|
|
2248
|
-
}, {
|
|
2249
|
-
key: "clearCacheByModule",
|
|
2250
|
-
value: function clearCacheByModule(module) {}
|
|
2251
2287
|
}, {
|
|
2252
2288
|
key: "getScheduleDataByIds",
|
|
2253
2289
|
value: function getScheduleDataByIds(scheduleIds) {
|
|
@@ -2278,42 +2314,42 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2278
2314
|
}, {
|
|
2279
2315
|
key: "openProductDetail",
|
|
2280
2316
|
value: function () {
|
|
2281
|
-
var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2317
|
+
var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(productId) {
|
|
2282
2318
|
var targetProductData, newScheduleArr, dateRange;
|
|
2283
|
-
return _regeneratorRuntime().wrap(function
|
|
2284
|
-
while (1) switch (
|
|
2319
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
2320
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
2285
2321
|
case 0:
|
|
2286
|
-
|
|
2322
|
+
_context24.next = 2;
|
|
2287
2323
|
return this.store.products.getProduct(productId);
|
|
2288
2324
|
case 2:
|
|
2289
|
-
targetProductData =
|
|
2325
|
+
targetProductData = _context24.sent;
|
|
2290
2326
|
if (!targetProductData) {
|
|
2291
|
-
|
|
2327
|
+
_context24.next = 17;
|
|
2292
2328
|
break;
|
|
2293
2329
|
}
|
|
2294
2330
|
this.store.currentProduct = targetProductData;
|
|
2295
2331
|
this.store.currentProductMeta = {};
|
|
2296
2332
|
// 资源预加载,如果是 duration 类型的商品,且是先选日期的流程,在这里预拉取资源数据
|
|
2297
2333
|
if (!targetProductData['schedule.ids']) {
|
|
2298
|
-
|
|
2334
|
+
_context24.next = 12;
|
|
2299
2335
|
break;
|
|
2300
2336
|
}
|
|
2301
2337
|
newScheduleArr = this.getScheduleDataByIds(targetProductData['schedule.ids']);
|
|
2302
2338
|
if (!this.store.currentProductMeta) this.store.currentProductMeta = {};
|
|
2303
2339
|
this.store.currentProductMeta.schedule = newScheduleArr;
|
|
2304
|
-
|
|
2340
|
+
_context24.next = 17;
|
|
2305
2341
|
break;
|
|
2306
2342
|
case 12:
|
|
2307
2343
|
if (!targetProductData.duration) {
|
|
2308
|
-
|
|
2344
|
+
_context24.next = 17;
|
|
2309
2345
|
break;
|
|
2310
2346
|
}
|
|
2311
2347
|
dateRange = this.store.date.getDateRange(); // 如果不是先选日期的流程 duration 商品就啥也不做
|
|
2312
2348
|
if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
|
|
2313
|
-
|
|
2349
|
+
_context24.next = 16;
|
|
2314
2350
|
break;
|
|
2315
2351
|
}
|
|
2316
|
-
return
|
|
2352
|
+
return _context24.abrupt("return");
|
|
2317
2353
|
case 16:
|
|
2318
2354
|
// this.store.date.getResourceDates({
|
|
2319
2355
|
// query: {
|
|
@@ -2329,11 +2365,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2329
2365
|
});
|
|
2330
2366
|
case 17:
|
|
2331
2367
|
case "end":
|
|
2332
|
-
return
|
|
2368
|
+
return _context24.stop();
|
|
2333
2369
|
}
|
|
2334
|
-
},
|
|
2370
|
+
}, _callee24, this);
|
|
2335
2371
|
}));
|
|
2336
|
-
function openProductDetail(
|
|
2372
|
+
function openProductDetail(_x18) {
|
|
2337
2373
|
return _openProductDetail.apply(this, arguments);
|
|
2338
2374
|
}
|
|
2339
2375
|
return openProductDetail;
|
|
@@ -2346,10 +2382,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2346
2382
|
}
|
|
2347
2383
|
this.store.currentProduct = undefined;
|
|
2348
2384
|
}
|
|
2385
|
+
|
|
2386
|
+
// 通过商品和 schedule 来获取视频可用的时间片、时间片内资源可用的数据
|
|
2349
2387
|
}, {
|
|
2350
2388
|
key: "getTimeslotBySchedule",
|
|
2351
2389
|
value: function getTimeslotBySchedule(_ref10) {
|
|
2352
|
-
var _this$store$currentPr2,
|
|
2390
|
+
var _this$store$currentPr2,
|
|
2391
|
+
_targetProductData$pr,
|
|
2392
|
+
_this14 = this;
|
|
2353
2393
|
var date = _ref10.date,
|
|
2354
2394
|
scheduleIds = _ref10.scheduleIds,
|
|
2355
2395
|
resources = _ref10.resources,
|
|
@@ -2456,6 +2496,138 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2456
2496
|
}
|
|
2457
2497
|
}
|
|
2458
2498
|
});
|
|
2499
|
+
// 容量检测
|
|
2500
|
+
var cartItems = _this14.store.cart.getItems();
|
|
2501
|
+
productResources.forEach(function (n) {
|
|
2502
|
+
// 单个预约检测规则:
|
|
2503
|
+
// 1、跟我一样的商品同一时间在购物车里不可以超过我最少的那种资源的关联的资源个数
|
|
2504
|
+
// 2、跟我不一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,她配置了几个资源的个数+我配置了几个资源的个数,然后购物车里有几个这样的商品,对应的资源做一个去重,不超过这个去重以后的总数
|
|
2505
|
+
if (n.type === 'single') {
|
|
2506
|
+
var currentResourcesSet = new Set([].concat(_toConsumableArray(n.optional_resource), _toConsumableArray(n.default_resource)));
|
|
2507
|
+
// 规则 1
|
|
2508
|
+
var sameCartItems = cartItems.filter(function (m) {
|
|
2509
|
+
var _m$_productOrigin, _targetProductData$id;
|
|
2510
|
+
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;
|
|
2511
|
+
});
|
|
2512
|
+
if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length > bookingLeft) {
|
|
2513
|
+
bookingLeft = 0;
|
|
2514
|
+
count = 0;
|
|
2515
|
+
}
|
|
2516
|
+
// 规则 2
|
|
2517
|
+
var otherCartItems = cartItems.filter(function (m) {
|
|
2518
|
+
var _m$_productOrigin2, _targetProductData$id2;
|
|
2519
|
+
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;
|
|
2520
|
+
});
|
|
2521
|
+
otherCartItems.forEach(function (m) {
|
|
2522
|
+
var _m$_productOrigin3;
|
|
2523
|
+
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) {
|
|
2524
|
+
return m.type === n.type;
|
|
2525
|
+
});
|
|
2526
|
+
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) || [])));
|
|
2527
|
+
// 把sameTypeResourcesSet 加到currentResourcesSet
|
|
2528
|
+
sameTypeResourcesSet.forEach(function (resource) {
|
|
2529
|
+
return currentResourcesSet.add(resource);
|
|
2530
|
+
});
|
|
2531
|
+
});
|
|
2532
|
+
// 先确定是否每一个currentResourcesSet在这个时间点的 event_list 都是空的,如果不是空的还需要把他踢出currentResourcesSet
|
|
2533
|
+
var currentDataResources = _this14.store.date.getResourcesListByDate(dayjs(item.start).format('YYYY-MM-DD'));
|
|
2534
|
+
currentDataResources === null || currentDataResources === void 0 || currentDataResources.forEach(function (m) {
|
|
2535
|
+
if (currentResourcesSet.has(m.id)) {
|
|
2536
|
+
var mTimes = m.times.filter(function (n) {
|
|
2537
|
+
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');
|
|
2538
|
+
});
|
|
2539
|
+
if (!mTimes.length || mTimes.some(function (n) {
|
|
2540
|
+
return n.event_list.length;
|
|
2541
|
+
})) {
|
|
2542
|
+
currentResourcesSet.delete(m.id);
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
});
|
|
2546
|
+
if (currentResourcesSet.size > 0 && otherCartItems.length + sameCartItems.length >= currentResourcesSet.size) {
|
|
2547
|
+
bookingLeft = 0;
|
|
2548
|
+
count = 0;
|
|
2549
|
+
}
|
|
2550
|
+
} else {
|
|
2551
|
+
// 多个预约的检测规则:
|
|
2552
|
+
// 规则1、跟我一样的商品同一时间在购物车需要的容量总数不可以超过我配置的资源的 capacity 之和
|
|
2553
|
+
var _sameCartItems = cartItems.filter(function (m) {
|
|
2554
|
+
var _m$_productOrigin4, _targetProductData$id3;
|
|
2555
|
+
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;
|
|
2556
|
+
});
|
|
2557
|
+
var sameCartNeedCapacity = _sameCartItems.reduce(function (acc, curr) {
|
|
2558
|
+
return acc + getCapacityInfoByCartItem(curr).currentCapacity;
|
|
2559
|
+
}, 0);
|
|
2560
|
+
var currentProductResourcesCapacity = n.renderList.reduce(function (acc, curr) {
|
|
2561
|
+
return !curr.onlyComputed ? acc + curr.capacity || 0 : acc;
|
|
2562
|
+
}, 0);
|
|
2563
|
+
if (sameCartNeedCapacity >= currentProductResourcesCapacity) {
|
|
2564
|
+
bookingLeft = 0;
|
|
2565
|
+
count = 0;
|
|
2566
|
+
}
|
|
2567
|
+
// 规则2、不管是不是跟我一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,把所有购物车的 capacity 之和 和 所有当前类型资源的 capacity 之和比较,如果超过了resourcesCapacity,则不可用
|
|
2568
|
+
// const otherCartItems = cartItems.filter((m) => m._productOrigin?.id?.toString() !== targetProductData?.id?.toString() && m.start_time === item.start && m.end_time === item.end);
|
|
2569
|
+
var otherSameTimesCartItems = cartItems.filter(function (m) {
|
|
2570
|
+
return "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
|
|
2571
|
+
});
|
|
2572
|
+
var otherCartNeedCapacity = otherSameTimesCartItems.reduce(function (acc, curr) {
|
|
2573
|
+
return acc + getCapacityInfoByCartItem(curr).currentCapacity;
|
|
2574
|
+
}, 0);
|
|
2575
|
+
var allRenderList = _toConsumableArray(n.renderList.filter(function (m) {
|
|
2576
|
+
return !m.onlyComputed;
|
|
2577
|
+
}));
|
|
2578
|
+
otherSameTimesCartItems.forEach(function (m) {
|
|
2579
|
+
var _m$_productOrigin5;
|
|
2580
|
+
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);
|
|
2581
|
+
productResources.forEach(function (m) {
|
|
2582
|
+
if (m.id === n.id) {
|
|
2583
|
+
m.renderList.forEach(function (n) {
|
|
2584
|
+
if (!n.onlyComputed && !allRenderList.find(function (m) {
|
|
2585
|
+
return m.id === n.id;
|
|
2586
|
+
})) {
|
|
2587
|
+
allRenderList.push(n);
|
|
2588
|
+
}
|
|
2589
|
+
});
|
|
2590
|
+
}
|
|
2591
|
+
});
|
|
2592
|
+
});
|
|
2593
|
+
var currentTypeResourcesCapacity = allRenderList.reduce(function (acc, curr) {
|
|
2594
|
+
return acc + curr.capacity || 0;
|
|
2595
|
+
}, 0);
|
|
2596
|
+
// 计算当前时间段内所有资源的已使用容量
|
|
2597
|
+
var usedCapacity = allRenderList.reduce(function (acc, curr) {
|
|
2598
|
+
var mTimes = curr.times.filter(function (n) {
|
|
2599
|
+
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');
|
|
2600
|
+
});
|
|
2601
|
+
// 这里为什么要设置个 map,因为有可能日程有重叠,所以要把重叠的 event_list 去除
|
|
2602
|
+
var mSet = new Map();
|
|
2603
|
+
mTimes.forEach(function (n) {
|
|
2604
|
+
// acc += n.event_list?.reduce((acc: any, curr: any) => acc + curr.pax, 0);
|
|
2605
|
+
// mSet.set(n)
|
|
2606
|
+
n.event_list.forEach(function (m) {
|
|
2607
|
+
// 需要确认 m 的时间段是否和 item 的时间段有交集
|
|
2608
|
+
if (isConflict({
|
|
2609
|
+
start_at: m.start_at,
|
|
2610
|
+
end_at: m.end_at
|
|
2611
|
+
}, {
|
|
2612
|
+
start_at: dayjs(item.start),
|
|
2613
|
+
end_at: dayjs(item.end)
|
|
2614
|
+
})) {
|
|
2615
|
+
mSet.set(m.id, m.pax || 1);
|
|
2616
|
+
}
|
|
2617
|
+
});
|
|
2618
|
+
});
|
|
2619
|
+
acc += Array.from(mSet.values()).reduce(function (acc, curr) {
|
|
2620
|
+
return acc + curr;
|
|
2621
|
+
}, 0);
|
|
2622
|
+
return acc;
|
|
2623
|
+
}, 0);
|
|
2624
|
+
// 如果已使用容量超过了当前类型资源的容量,则不可用
|
|
2625
|
+
if (otherCartNeedCapacity + usedCapacity >= currentTypeResourcesCapacity) {
|
|
2626
|
+
bookingLeft = 0;
|
|
2627
|
+
count = 0;
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
});
|
|
2459
2631
|
var startDayJs = dayjs(item.start);
|
|
2460
2632
|
var endDayJs = dayjs(item.end);
|
|
2461
2633
|
return {
|
|
@@ -2469,6 +2641,869 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2469
2641
|
});
|
|
2470
2642
|
return formatScheduleTimeSlots;
|
|
2471
2643
|
}
|
|
2644
|
+
|
|
2645
|
+
// 提供给 UI的方法,当前步骤是选择商品,下一步不管是什么都需要在这里做一次检测
|
|
2646
|
+
// 时长类商品关联的资源为多个预约时,在点击进入"选择资源"步骤之前,需要检测当前所有资源的总容量
|
|
2647
|
+
// 选择商品数量大于所有资源配置的总容量时,不能进入下一步,需要在"选择商品"这一步时提示。
|
|
2648
|
+
// 注意 资源分为多个种类,需要每个种类单独检测,不能一股脑把所有资源的容量加起来检测
|
|
2649
|
+
/**
|
|
2650
|
+
* 找到多个资源的公共可用时间段
|
|
2651
|
+
*/
|
|
2652
|
+
}, {
|
|
2653
|
+
key: "findCommonAvailableTimeSlots",
|
|
2654
|
+
value: function findCommonAvailableTimeSlots(resources) {
|
|
2655
|
+
if (resources.length === 0) return [];
|
|
2656
|
+
console.log("\u8BA1\u7B97 ".concat(resources.length, " \u4E2A\u8D44\u6E90\u7684\u516C\u5171\u65F6\u95F4\u6BB5"));
|
|
2657
|
+
|
|
2658
|
+
// 收集所有资源的时间段,转换为统一的时间格式
|
|
2659
|
+
var allTimeSlots = resources.map(function (resource) {
|
|
2660
|
+
return resource.times.map(function (time) {
|
|
2661
|
+
return {
|
|
2662
|
+
start: dayjs(time.start_at),
|
|
2663
|
+
end: dayjs(time.end_at)
|
|
2664
|
+
};
|
|
2665
|
+
});
|
|
2666
|
+
});
|
|
2667
|
+
console.log('所有资源的时间段:', allTimeSlots.map(function (slots) {
|
|
2668
|
+
return slots.map(function (slot) {
|
|
2669
|
+
return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
|
|
2670
|
+
});
|
|
2671
|
+
}));
|
|
2672
|
+
|
|
2673
|
+
// 找到公共时间段的交集
|
|
2674
|
+
var commonSlots = allTimeSlots[0]; // 从第一个资源的时间段开始
|
|
2675
|
+
console.log('初始公共时间段:', commonSlots.map(function (slot) {
|
|
2676
|
+
return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
|
|
2677
|
+
}));
|
|
2678
|
+
|
|
2679
|
+
// 与其他资源的时间段求交集
|
|
2680
|
+
var _loop2 = function _loop2() {
|
|
2681
|
+
var currentResourceSlots = allTimeSlots[i];
|
|
2682
|
+
var intersections = [];
|
|
2683
|
+
|
|
2684
|
+
// 计算当前公共时间段与下一个资源时间段的交集
|
|
2685
|
+
commonSlots.forEach(function (commonSlot) {
|
|
2686
|
+
currentResourceSlots.forEach(function (currentSlot) {
|
|
2687
|
+
var overlapStart = commonSlot.start.isAfter(currentSlot.start) ? commonSlot.start : currentSlot.start;
|
|
2688
|
+
var overlapEnd = commonSlot.end.isBefore(currentSlot.end) ? commonSlot.end : currentSlot.end;
|
|
2689
|
+
|
|
2690
|
+
// 如果有重叠时间且重叠时间大于0
|
|
2691
|
+
if (overlapStart.isBefore(overlapEnd)) {
|
|
2692
|
+
intersections.push({
|
|
2693
|
+
start: overlapStart,
|
|
2694
|
+
end: overlapEnd
|
|
2695
|
+
});
|
|
2696
|
+
}
|
|
2697
|
+
});
|
|
2698
|
+
});
|
|
2699
|
+
if (intersections.length === 0) {
|
|
2700
|
+
console.log("\u8D44\u6E90".concat(i, "\u4E0E\u5F53\u524D\u516C\u5171\u65F6\u95F4\u6BB5\u65E0\u4EA4\u96C6\uFF0C\u8DF3\u8FC7\u8BE5\u8D44\u6E90"));
|
|
2701
|
+
return 1; // continue
|
|
2702
|
+
}
|
|
2703
|
+
commonSlots = intersections;
|
|
2704
|
+
console.log("\u4E0E\u8D44\u6E90".concat(i, "\u6C42\u4EA4\u96C6\u540E\u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonSlots.map(function (slot) {
|
|
2705
|
+
return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
|
|
2706
|
+
}));
|
|
2707
|
+
};
|
|
2708
|
+
for (var i = 1; i < allTimeSlots.length; i++) {
|
|
2709
|
+
if (_loop2()) continue;
|
|
2710
|
+
}
|
|
2711
|
+
|
|
2712
|
+
// 格式化返回结果
|
|
2713
|
+
var result = commonSlots.map(function (slot) {
|
|
2714
|
+
return {
|
|
2715
|
+
startTime: slot.start.format('HH:mm'),
|
|
2716
|
+
endTime: slot.end.format('HH:mm')
|
|
2717
|
+
};
|
|
2718
|
+
});
|
|
2719
|
+
console.log('最终公共时间段:', result);
|
|
2720
|
+
return result;
|
|
2721
|
+
}
|
|
2722
|
+
}, {
|
|
2723
|
+
key: "checkMaxDurationCapacity",
|
|
2724
|
+
value: function checkMaxDurationCapacity() {
|
|
2725
|
+
var _this15 = this;
|
|
2726
|
+
var cartItems = this.store.cart.getItems().filter(function (item) {
|
|
2727
|
+
return !isNormalProduct(item._productOrigin);
|
|
2728
|
+
});
|
|
2729
|
+
if (cartItems.length === 0) return {
|
|
2730
|
+
success: true,
|
|
2731
|
+
minAvailableCount: 0
|
|
2732
|
+
};
|
|
2733
|
+
|
|
2734
|
+
// 将购物车商品分为有时间的和没有时间的
|
|
2735
|
+
var itemsWithTime = [];
|
|
2736
|
+
var itemsWithoutTime = [];
|
|
2737
|
+
// 记录每种资源类型的可用数量
|
|
2738
|
+
var availableCountsByResourceType = [];
|
|
2739
|
+
cartItems.forEach(function (cartItem) {
|
|
2740
|
+
if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
|
|
2741
|
+
itemsWithTime.push(cartItem);
|
|
2742
|
+
} else {
|
|
2743
|
+
itemsWithoutTime.push(cartItem);
|
|
2744
|
+
}
|
|
2745
|
+
});
|
|
2746
|
+
|
|
2747
|
+
// 处理没有时间的商品,为它们分配公共可用时间的第一个时间片
|
|
2748
|
+
var processedItemsWithoutTime = [];
|
|
2749
|
+
if (itemsWithoutTime.length > 0) {
|
|
2750
|
+
// 按资源类型分组处理没有时间的商品
|
|
2751
|
+
var itemsByResourceType = {};
|
|
2752
|
+
itemsWithoutTime.forEach(function (cartItem) {
|
|
2753
|
+
var _cartItem$_productOri10;
|
|
2754
|
+
if (!cartItem._productOrigin) return;
|
|
2755
|
+
var resourceTypes = ((_cartItem$_productOri10 = cartItem._productOrigin.product_resource) === null || _cartItem$_productOri10 === void 0 ? void 0 : _cartItem$_productOri10.resources) || [];
|
|
2756
|
+
resourceTypes.forEach(function (resourceType) {
|
|
2757
|
+
if (resourceType.status === 1) {
|
|
2758
|
+
var _resourceType$id;
|
|
2759
|
+
var resourceCode = resourceType.code || ((_resourceType$id = resourceType.id) === null || _resourceType$id === void 0 ? void 0 : _resourceType$id.toString());
|
|
2760
|
+
if (!itemsByResourceType[resourceCode]) {
|
|
2761
|
+
itemsByResourceType[resourceCode] = [];
|
|
2762
|
+
}
|
|
2763
|
+
// 避免重复添加同一个商品
|
|
2764
|
+
if (!itemsByResourceType[resourceCode].find(function (item) {
|
|
2765
|
+
return item._id === cartItem._id;
|
|
2766
|
+
})) {
|
|
2767
|
+
itemsByResourceType[resourceCode].push(cartItem);
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
});
|
|
2771
|
+
});
|
|
2772
|
+
|
|
2773
|
+
// 为每种资源类型检查容量
|
|
2774
|
+
var dateRange = this.store.date.getDateRange();
|
|
2775
|
+
if (!dateRange || dateRange.length === 0) return {
|
|
2776
|
+
success: false,
|
|
2777
|
+
minAvailableCount: 0
|
|
2778
|
+
};
|
|
2779
|
+
var resourcesDates = this.store.date.getDateList();
|
|
2780
|
+
var targetResourceDate = resourcesDates.find(function (n) {
|
|
2781
|
+
return n.date === dateRange[0].date;
|
|
2782
|
+
});
|
|
2783
|
+
if (!targetResourceDate) return {
|
|
2784
|
+
success: false,
|
|
2785
|
+
minAvailableCount: 0
|
|
2786
|
+
};
|
|
2787
|
+
var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
|
|
2788
|
+
|
|
2789
|
+
// 从购物车商品中获取资源类型配置,建立 resourceCode 到 form_id 的映射关系
|
|
2790
|
+
var resourceCodeToFormIdMap = {};
|
|
2791
|
+
|
|
2792
|
+
// 遍历购物车中的商品,收集所有资源类型配置
|
|
2793
|
+
Object.values(itemsByResourceType).flat().forEach(function (cartItem) {
|
|
2794
|
+
var _cartItem$_productOri11;
|
|
2795
|
+
if ((_cartItem$_productOri11 = cartItem._productOrigin) !== null && _cartItem$_productOri11 !== void 0 && (_cartItem$_productOri11 = _cartItem$_productOri11.product_resource) !== null && _cartItem$_productOri11 !== void 0 && _cartItem$_productOri11.resources) {
|
|
2796
|
+
cartItem._productOrigin.product_resource.resources.forEach(function (resourceConfig) {
|
|
2797
|
+
// 只处理启用的资源类型 (status === 1)
|
|
2798
|
+
if (resourceConfig.status === 1 && resourceConfig.code) {
|
|
2799
|
+
var _resourceConfig$id, _resourceConfig$resou;
|
|
2800
|
+
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());
|
|
2801
|
+
if (formId) {
|
|
2802
|
+
resourceCodeToFormIdMap[resourceConfig.code] = formId;
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
});
|
|
2806
|
+
}
|
|
2807
|
+
});
|
|
2808
|
+
var hasCapacityIssue = false;
|
|
2809
|
+
var resourceCapacityInfo = [];
|
|
2810
|
+
|
|
2811
|
+
// 用于跟踪已处理的商品,避免重复添加
|
|
2812
|
+
var processedCartItemIds = new Set();
|
|
2813
|
+
|
|
2814
|
+
// 先检查所有资源类型,收集可用数量信息
|
|
2815
|
+
var _loop3 = function _loop3() {
|
|
2816
|
+
var _resourceTypeConfig;
|
|
2817
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
2818
|
+
resourceCode = _Object$entries$_i[0],
|
|
2819
|
+
items = _Object$entries$_i[1];
|
|
2820
|
+
// 获取该资源类型对应的 form_id
|
|
2821
|
+
var targetFormId = resourceCodeToFormIdMap[resourceCode];
|
|
2822
|
+
if (!targetFormId) {
|
|
2823
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u627E\u4E0D\u5230\u5BF9\u5E94\u7684 form_id"));
|
|
2824
|
+
return {
|
|
2825
|
+
v: {
|
|
2826
|
+
success: false,
|
|
2827
|
+
minAvailableCount: 0
|
|
2828
|
+
}
|
|
2829
|
+
};
|
|
2830
|
+
}
|
|
2831
|
+
|
|
2832
|
+
// 获取该资源类型的所有资源
|
|
2833
|
+
var resourcesOfThisType = [];
|
|
2834
|
+
items.forEach(function (cartItem) {
|
|
2835
|
+
var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
2836
|
+
productResourceIds.forEach(function (resourceId) {
|
|
2837
|
+
var _resource$form_id;
|
|
2838
|
+
var resource = resourcesMap[resourceId];
|
|
2839
|
+
if (resource && ((_resource$form_id = resource.form_id) === null || _resource$form_id === void 0 ? void 0 : _resource$form_id.toString()) === targetFormId) {
|
|
2840
|
+
// 避免重复添加同一个资源
|
|
2841
|
+
if (!resourcesOfThisType.find(function (r) {
|
|
2842
|
+
return r.id === resource.id;
|
|
2843
|
+
})) {
|
|
2844
|
+
resourcesOfThisType.push(resource);
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
});
|
|
2848
|
+
});
|
|
2849
|
+
if (resourcesOfThisType.length === 0) {
|
|
2850
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u627E\u5230\u53EF\u7528\u8D44\u6E90"));
|
|
2851
|
+
return {
|
|
2852
|
+
v: {
|
|
2853
|
+
success: false,
|
|
2854
|
+
minAvailableCount: 0
|
|
2855
|
+
}
|
|
2856
|
+
};
|
|
2857
|
+
}
|
|
2858
|
+
|
|
2859
|
+
// 检查资源类型(单个预约 vs 多个预约)
|
|
2860
|
+
// 从商品配置中获取资源类型信息
|
|
2861
|
+
var resourceTypeConfig = null;
|
|
2862
|
+
var _iterator3 = _createForOfIteratorHelper(items),
|
|
2863
|
+
_step3;
|
|
2864
|
+
try {
|
|
2865
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
2866
|
+
var _cartItem$_productOri12;
|
|
2867
|
+
var cartItem = _step3.value;
|
|
2868
|
+
if ((_cartItem$_productOri12 = cartItem._productOrigin) !== null && _cartItem$_productOri12 !== void 0 && (_cartItem$_productOri12 = _cartItem$_productOri12.product_resource) !== null && _cartItem$_productOri12 !== void 0 && _cartItem$_productOri12.resources) {
|
|
2869
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
|
|
2870
|
+
return r.code === resourceCode && r.status === 1;
|
|
2871
|
+
});
|
|
2872
|
+
if (resourceTypeConfig) break;
|
|
2873
|
+
}
|
|
2874
|
+
}
|
|
2875
|
+
} catch (err) {
|
|
2876
|
+
_iterator3.e(err);
|
|
2877
|
+
} finally {
|
|
2878
|
+
_iterator3.f();
|
|
2879
|
+
}
|
|
2880
|
+
var isMultipleBooking = ((_resourceTypeConfig = resourceTypeConfig) === null || _resourceTypeConfig === void 0 ? void 0 : _resourceTypeConfig.type) === 'multiple';
|
|
2881
|
+
var totalAvailable;
|
|
2882
|
+
var requiredAmount;
|
|
2883
|
+
var availableAmount;
|
|
2884
|
+
if (isMultipleBooking) {
|
|
2885
|
+
// 多个预约:计算容量
|
|
2886
|
+
totalAvailable = resourcesOfThisType.reduce(function (sum, resource) {
|
|
2887
|
+
return sum + (resource.capacity || 0);
|
|
2888
|
+
}, 0);
|
|
2889
|
+
requiredAmount = items.reduce(function (sum, cartItem) {
|
|
2890
|
+
var _getCapacityInfoByCar7 = getCapacityInfoByCartItem(cartItem),
|
|
2891
|
+
currentCapacity = _getCapacityInfoByCar7.currentCapacity;
|
|
2892
|
+
return sum + currentCapacity;
|
|
2893
|
+
}, 0);
|
|
2894
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
2895
|
+
} else {
|
|
2896
|
+
// 单个预约:计算资源个数
|
|
2897
|
+
totalAvailable = resourcesOfThisType.length;
|
|
2898
|
+
requiredAmount = items.reduce(function (sum, cartItem) {
|
|
2899
|
+
return sum + (cartItem.num || 1);
|
|
2900
|
+
}, 0);
|
|
2901
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
2902
|
+
}
|
|
2903
|
+
|
|
2904
|
+
// 记录资源容量信息
|
|
2905
|
+
resourceCapacityInfo.push({
|
|
2906
|
+
code: resourceCode,
|
|
2907
|
+
available: availableAmount,
|
|
2908
|
+
total: totalAvailable,
|
|
2909
|
+
required: requiredAmount,
|
|
2910
|
+
isMultiple: isMultipleBooking
|
|
2911
|
+
});
|
|
2912
|
+
availableCountsByResourceType.push(availableAmount);
|
|
2913
|
+
|
|
2914
|
+
// 检查是否有容量问题
|
|
2915
|
+
if (requiredAmount > totalAvailable) {
|
|
2916
|
+
hasCapacityIssue = true;
|
|
2917
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " ").concat(isMultipleBooking ? '容量' : '资源数量', "\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredAmount, ", \u603B\u5171 ").concat(totalAvailable));
|
|
2918
|
+
}
|
|
2919
|
+
|
|
2920
|
+
// 为通过检测的商品分配一个公共可用时间段
|
|
2921
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u8D44\u6E90\u65F6\u95F4\u4FE1\u606F:"), resourcesOfThisType.map(function (r) {
|
|
2922
|
+
return {
|
|
2923
|
+
id: r.id,
|
|
2924
|
+
times: r.times.map(function (t) {
|
|
2925
|
+
return "".concat(t.start_at, " - ").concat(t.end_at);
|
|
2926
|
+
})
|
|
2927
|
+
};
|
|
2928
|
+
}));
|
|
2929
|
+
|
|
2930
|
+
// 找到所有资源都可用的时间段
|
|
2931
|
+
var commonTimeSlots = _this15.findCommonAvailableTimeSlots(resourcesOfThisType);
|
|
2932
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonTimeSlots);
|
|
2933
|
+
if (commonTimeSlots.length === 0) {
|
|
2934
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4\u6BB5"));
|
|
2935
|
+
return {
|
|
2936
|
+
v: {
|
|
2937
|
+
success: false,
|
|
2938
|
+
minAvailableCount: 0
|
|
2939
|
+
}
|
|
2940
|
+
};
|
|
2941
|
+
}
|
|
2942
|
+
|
|
2943
|
+
// 使用第一个公共可用时间段,但只处理未处理过的商品
|
|
2944
|
+
var firstCommonSlot = commonTimeSlots[0];
|
|
2945
|
+
console.log("\u4F7F\u7528\u516C\u5171\u65F6\u95F4\u6BB5: ".concat(firstCommonSlot.startTime, " - ").concat(firstCommonSlot.endTime));
|
|
2946
|
+
items.forEach(function (cartItem) {
|
|
2947
|
+
// 只处理未处理过的商品,避免重复添加
|
|
2948
|
+
if (!processedCartItemIds.has(cartItem._id)) {
|
|
2949
|
+
processedCartItemIds.add(cartItem._id);
|
|
2950
|
+
var processedItem = _objectSpread(_objectSpread({}, cartItem), {}, {
|
|
2951
|
+
start_date: dateRange[0].date,
|
|
2952
|
+
start_time: firstCommonSlot.startTime,
|
|
2953
|
+
end_time: firstCommonSlot.endTime,
|
|
2954
|
+
end_date: dateRange[0].date
|
|
2955
|
+
});
|
|
2956
|
+
processedItemsWithoutTime.push(processedItem);
|
|
2957
|
+
}
|
|
2958
|
+
});
|
|
2959
|
+
},
|
|
2960
|
+
_ret2;
|
|
2961
|
+
for (var _i = 0, _Object$entries = Object.entries(itemsByResourceType); _i < _Object$entries.length; _i++) {
|
|
2962
|
+
_ret2 = _loop3();
|
|
2963
|
+
if (_ret2) return _ret2.v;
|
|
2964
|
+
}
|
|
2965
|
+
|
|
2966
|
+
// 如果有容量问题,找出限制最严格的资源类型,返回其总容量
|
|
2967
|
+
if (hasCapacityIssue) {
|
|
2968
|
+
// 找出超出容量的资源类型中,总容量最少的那个
|
|
2969
|
+
var overCapacityResources = resourceCapacityInfo.filter(function (info) {
|
|
2970
|
+
return info.required > info.total;
|
|
2971
|
+
});
|
|
2972
|
+
if (overCapacityResources.length > 0) {
|
|
2973
|
+
var _minTotalCapacity = Math.min.apply(Math, _toConsumableArray(overCapacityResources.map(function (info) {
|
|
2974
|
+
return info.total;
|
|
2975
|
+
})));
|
|
2976
|
+
return {
|
|
2977
|
+
success: false,
|
|
2978
|
+
minAvailableCount: _minTotalCapacity
|
|
2979
|
+
};
|
|
2980
|
+
}
|
|
2981
|
+
// 如果没有超出容量的(理论上不应该发生),返回总容量最少的
|
|
2982
|
+
var minTotalCapacity = Math.min.apply(Math, _toConsumableArray(resourceCapacityInfo.map(function (info) {
|
|
2983
|
+
return info.total;
|
|
2984
|
+
})));
|
|
2985
|
+
return {
|
|
2986
|
+
success: false,
|
|
2987
|
+
minAvailableCount: minTotalCapacity
|
|
2988
|
+
};
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
|
|
2992
|
+
// 合并所有商品(有时间的 + 处理后的没有时间的)
|
|
2993
|
+
var allProcessedItems = [].concat(itemsWithTime, processedItemsWithoutTime);
|
|
2994
|
+
|
|
2995
|
+
// 按时间段分组检查
|
|
2996
|
+
var cartItemsByTimeSlot = {};
|
|
2997
|
+
allProcessedItems.forEach(function (cartItem) {
|
|
2998
|
+
if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date) return;
|
|
2999
|
+
var timeSlotKey = "".concat(cartItem.start_date, "_").concat(cartItem.start_time, "_").concat(cartItem.end_date || cartItem.start_date, "_").concat(cartItem.end_time);
|
|
3000
|
+
if (!cartItemsByTimeSlot[timeSlotKey]) {
|
|
3001
|
+
cartItemsByTimeSlot[timeSlotKey] = [];
|
|
3002
|
+
}
|
|
3003
|
+
cartItemsByTimeSlot[timeSlotKey].push(cartItem);
|
|
3004
|
+
});
|
|
3005
|
+
// 检查每个时间段是否有足够的资源容量
|
|
3006
|
+
var _loop4 = function _loop4() {
|
|
3007
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
3008
|
+
timeSlotKey = _Object$entries2$_i[0],
|
|
3009
|
+
itemsInTimeSlot = _Object$entries2$_i[1];
|
|
3010
|
+
var _timeSlotKey$split = timeSlotKey.split('_'),
|
|
3011
|
+
_timeSlotKey$split2 = _slicedToArray(_timeSlotKey$split, 4),
|
|
3012
|
+
startDate = _timeSlotKey$split2[0],
|
|
3013
|
+
startTime = _timeSlotKey$split2[1],
|
|
3014
|
+
endDate = _timeSlotKey$split2[2],
|
|
3015
|
+
endTime = _timeSlotKey$split2[3];
|
|
3016
|
+
var timeSlotStart = "".concat(startDate, " ").concat(startTime);
|
|
3017
|
+
var timeSlotEnd = "".concat(endDate, " ").concat(endTime);
|
|
3018
|
+
|
|
3019
|
+
// 获取这个时间段所有商品涉及的资源
|
|
3020
|
+
var allResourcesForTimeSlot = [];
|
|
3021
|
+
var resourcesIdSet = new Set();
|
|
3022
|
+
|
|
3023
|
+
// 获取资源数据
|
|
3024
|
+
var dateRange = _this15.store.date.getDateRange();
|
|
3025
|
+
var resourcesDates = _this15.store.date.getDateList();
|
|
3026
|
+
var targetResourceDate = resourcesDates.find(function (n) {
|
|
3027
|
+
return n.date === startDate;
|
|
3028
|
+
});
|
|
3029
|
+
if (!targetResourceDate) return 0; // continue
|
|
3030
|
+
var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
|
|
3031
|
+
itemsInTimeSlot.forEach(function (cartItem) {
|
|
3032
|
+
if (!cartItem._productOrigin) return;
|
|
3033
|
+
|
|
3034
|
+
// 获取商品的资源配置
|
|
3035
|
+
var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
3036
|
+
productResourceIds.forEach(function (resourceId) {
|
|
3037
|
+
if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
|
|
3038
|
+
resourcesIdSet.add(resourceId);
|
|
3039
|
+
allResourcesForTimeSlot.push(resourcesMap[resourceId]);
|
|
3040
|
+
}
|
|
3041
|
+
});
|
|
3042
|
+
});
|
|
3043
|
+
|
|
3044
|
+
// 按资源类型分组检查容量
|
|
3045
|
+
var _checkTimeSlotCapacit = checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot),
|
|
3046
|
+
success = _checkTimeSlotCapacit.success,
|
|
3047
|
+
required = _checkTimeSlotCapacit.required,
|
|
3048
|
+
available = _checkTimeSlotCapacit.available;
|
|
3049
|
+
if (!success) {
|
|
3050
|
+
// 如果有可用数量记录,返回最小值;否则返回 0
|
|
3051
|
+
var _minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
|
|
3052
|
+
return {
|
|
3053
|
+
v: {
|
|
3054
|
+
success: false,
|
|
3055
|
+
minAvailableCount: _minAvailableCount
|
|
3056
|
+
}
|
|
3057
|
+
};
|
|
3058
|
+
}
|
|
3059
|
+
},
|
|
3060
|
+
_ret3;
|
|
3061
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(cartItemsByTimeSlot); _i2 < _Object$entries2.length; _i2++) {
|
|
3062
|
+
_ret3 = _loop4();
|
|
3063
|
+
if (_ret3 === 0) continue;
|
|
3064
|
+
if (_ret3) return _ret3.v;
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3067
|
+
// 全部通过检测,返回成功和最小可用数量
|
|
3068
|
+
var minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
|
|
3069
|
+
return {
|
|
3070
|
+
success: true,
|
|
3071
|
+
minAvailableCount: minAvailableCount
|
|
3072
|
+
};
|
|
3073
|
+
}
|
|
3074
|
+
|
|
3075
|
+
/**
|
|
3076
|
+
* 将 ProductData 转换为 CartItem,但不添加到购物车
|
|
3077
|
+
* 参考 addProductToCart 方法的实现
|
|
3078
|
+
*/
|
|
3079
|
+
}, {
|
|
3080
|
+
key: "convertProductToCartItem",
|
|
3081
|
+
value: function convertProductToCartItem(_ref11) {
|
|
3082
|
+
var product = _ref11.product,
|
|
3083
|
+
date = _ref11.date,
|
|
3084
|
+
account = _ref11.account;
|
|
3085
|
+
var _ref12 = product || {},
|
|
3086
|
+
bundle = _ref12.bundle,
|
|
3087
|
+
options = _ref12.options,
|
|
3088
|
+
origin = _ref12.origin,
|
|
3089
|
+
product_variant_id = _ref12.product_variant_id,
|
|
3090
|
+
_ref12$quantity = _ref12.quantity,
|
|
3091
|
+
quantity = _ref12$quantity === void 0 ? 1 : _ref12$quantity;
|
|
3092
|
+
|
|
3093
|
+
// 处理商品数据,类似 addProductToCart 中的逻辑
|
|
3094
|
+
var productData = _objectSpread(_objectSpread({}, origin), {}, {
|
|
3095
|
+
product_variant_id: product_variant_id
|
|
3096
|
+
});
|
|
3097
|
+
|
|
3098
|
+
// 处理组合商品
|
|
3099
|
+
var processedProduct = handleVariantProduct(productData);
|
|
3100
|
+
|
|
3101
|
+
// 如果没有传入账户,获取当前活跃账户
|
|
3102
|
+
if (!account) {
|
|
3103
|
+
var activeAccount = this.getActiveAccount();
|
|
3104
|
+
if (activeAccount) {
|
|
3105
|
+
account = activeAccount;
|
|
3106
|
+
}
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
// 创建基础的 CartItem
|
|
3110
|
+
var cartItem = {
|
|
3111
|
+
_id: getUniqueId('temp_'),
|
|
3112
|
+
_origin: createCartItemOrigin(),
|
|
3113
|
+
_productOrigin: processedProduct,
|
|
3114
|
+
_productInit: product
|
|
3115
|
+
};
|
|
3116
|
+
|
|
3117
|
+
// 使用格式化函数填充 CartItem 数据
|
|
3118
|
+
formatProductToCartItem({
|
|
3119
|
+
cartItem: cartItem,
|
|
3120
|
+
product: processedProduct,
|
|
3121
|
+
bundle: bundle,
|
|
3122
|
+
options: options,
|
|
3123
|
+
product_variant_id: product_variant_id,
|
|
3124
|
+
quantity: quantity
|
|
3125
|
+
});
|
|
3126
|
+
|
|
3127
|
+
// 如果有日期信息,格式化日期到购物车
|
|
3128
|
+
if (date) {
|
|
3129
|
+
formatDateToCartItem({
|
|
3130
|
+
cartItem: cartItem,
|
|
3131
|
+
date: date
|
|
3132
|
+
});
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
// 如果有账户信息,格式化账户到购物车
|
|
3136
|
+
if (account) {
|
|
3137
|
+
formatAccountToCartItem({
|
|
3138
|
+
cartItem: cartItem,
|
|
3139
|
+
account: account
|
|
3140
|
+
});
|
|
3141
|
+
}
|
|
3142
|
+
return cartItem;
|
|
3143
|
+
}
|
|
3144
|
+
}, {
|
|
3145
|
+
key: "checkMaxDurationCapacityForDetailNums",
|
|
3146
|
+
value: function checkMaxDurationCapacityForDetailNums(_ref13) {
|
|
3147
|
+
var _this16 = this;
|
|
3148
|
+
var product = _ref13.product,
|
|
3149
|
+
date = _ref13.date,
|
|
3150
|
+
account = _ref13.account;
|
|
3151
|
+
var cartItems = this.store.cart.getItems().filter(function (item) {
|
|
3152
|
+
return !isNormalProduct(item._productOrigin);
|
|
3153
|
+
});
|
|
3154
|
+
|
|
3155
|
+
// 将 ProductData 转换为 CartItem 但不真正添加到购物车
|
|
3156
|
+
var currentCartItem = this.convertProductToCartItem({
|
|
3157
|
+
product: product,
|
|
3158
|
+
date: date,
|
|
3159
|
+
account: account
|
|
3160
|
+
});
|
|
3161
|
+
cartItems.push(currentCartItem);
|
|
3162
|
+
if (cartItems.length === 0) return {
|
|
3163
|
+
success: true,
|
|
3164
|
+
minAvailableCount: 0
|
|
3165
|
+
};
|
|
3166
|
+
|
|
3167
|
+
// 将购物车商品分为有时间的和没有时间的
|
|
3168
|
+
var itemsWithTime = [];
|
|
3169
|
+
var itemsWithoutTime = [];
|
|
3170
|
+
// 记录每种资源类型的可用数量
|
|
3171
|
+
var availableCountsByResourceType = [];
|
|
3172
|
+
cartItems.forEach(function (cartItem) {
|
|
3173
|
+
if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
|
|
3174
|
+
itemsWithTime.push(cartItem);
|
|
3175
|
+
} else {
|
|
3176
|
+
itemsWithoutTime.push(cartItem);
|
|
3177
|
+
}
|
|
3178
|
+
});
|
|
3179
|
+
|
|
3180
|
+
// 处理没有时间的商品,为它们分配公共可用时间的第一个时间片
|
|
3181
|
+
var processedItemsWithoutTime = [];
|
|
3182
|
+
if (itemsWithoutTime.length > 0) {
|
|
3183
|
+
// 按资源类型分组处理没有时间的商品
|
|
3184
|
+
var itemsByResourceType = {};
|
|
3185
|
+
itemsWithoutTime.forEach(function (cartItem) {
|
|
3186
|
+
var _cartItem$_productOri13;
|
|
3187
|
+
if (!cartItem._productOrigin) return;
|
|
3188
|
+
var resourceTypes = ((_cartItem$_productOri13 = cartItem._productOrigin.product_resource) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.resources) || [];
|
|
3189
|
+
resourceTypes.forEach(function (resourceType) {
|
|
3190
|
+
if (resourceType.status === 1) {
|
|
3191
|
+
var _resourceType$id2;
|
|
3192
|
+
var resourceCode = resourceType.code || ((_resourceType$id2 = resourceType.id) === null || _resourceType$id2 === void 0 ? void 0 : _resourceType$id2.toString());
|
|
3193
|
+
if (!itemsByResourceType[resourceCode]) {
|
|
3194
|
+
itemsByResourceType[resourceCode] = [];
|
|
3195
|
+
}
|
|
3196
|
+
// 避免重复添加同一个商品
|
|
3197
|
+
if (!itemsByResourceType[resourceCode].find(function (item) {
|
|
3198
|
+
return item._id === cartItem._id;
|
|
3199
|
+
})) {
|
|
3200
|
+
itemsByResourceType[resourceCode].push(cartItem);
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
});
|
|
3204
|
+
});
|
|
3205
|
+
|
|
3206
|
+
// 为每种资源类型检查容量
|
|
3207
|
+
var dateRange = this.store.date.getDateRange();
|
|
3208
|
+
if (!dateRange || dateRange.length === 0) return {
|
|
3209
|
+
success: false,
|
|
3210
|
+
minAvailableCount: 0
|
|
3211
|
+
};
|
|
3212
|
+
var resourcesDates = this.store.date.getDateList();
|
|
3213
|
+
var targetResourceDate = resourcesDates.find(function (n) {
|
|
3214
|
+
return n.date === dateRange[0].date;
|
|
3215
|
+
});
|
|
3216
|
+
if (!targetResourceDate) return {
|
|
3217
|
+
success: false,
|
|
3218
|
+
minAvailableCount: 0
|
|
3219
|
+
};
|
|
3220
|
+
var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
|
|
3221
|
+
|
|
3222
|
+
// 从购物车商品中获取资源类型配置,建立 resourceCode 到 form_id 的映射关系
|
|
3223
|
+
var resourceCodeToFormIdMap = {};
|
|
3224
|
+
|
|
3225
|
+
// 遍历购物车中的商品,收集所有资源类型配置
|
|
3226
|
+
Object.values(itemsByResourceType).flat().forEach(function (cartItem) {
|
|
3227
|
+
var _cartItem$_productOri14;
|
|
3228
|
+
if ((_cartItem$_productOri14 = cartItem._productOrigin) !== null && _cartItem$_productOri14 !== void 0 && (_cartItem$_productOri14 = _cartItem$_productOri14.product_resource) !== null && _cartItem$_productOri14 !== void 0 && _cartItem$_productOri14.resources) {
|
|
3229
|
+
cartItem._productOrigin.product_resource.resources.forEach(function (resourceConfig) {
|
|
3230
|
+
// 只处理启用的资源类型 (status === 1)
|
|
3231
|
+
if (resourceConfig.status === 1 && resourceConfig.code) {
|
|
3232
|
+
var _resourceConfig$id2, _resourceConfig$resou2;
|
|
3233
|
+
var formId = ((_resourceConfig$id2 = resourceConfig.id) === null || _resourceConfig$id2 === void 0 ? void 0 : _resourceConfig$id2.toString()) || ((_resourceConfig$resou2 = resourceConfig.resource_type_id) === null || _resourceConfig$resou2 === void 0 ? void 0 : _resourceConfig$resou2.toString());
|
|
3234
|
+
if (formId) {
|
|
3235
|
+
resourceCodeToFormIdMap[resourceConfig.code] = formId;
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
});
|
|
3239
|
+
}
|
|
3240
|
+
});
|
|
3241
|
+
var hasCapacityIssue = false;
|
|
3242
|
+
var resourceCapacityInfo = [];
|
|
3243
|
+
|
|
3244
|
+
// 用于跟踪已处理的商品,避免重复添加
|
|
3245
|
+
var processedCartItemIds = new Set();
|
|
3246
|
+
|
|
3247
|
+
// 先检查所有资源类型,收集可用数量信息
|
|
3248
|
+
var _loop5 = function _loop5() {
|
|
3249
|
+
var _resourceTypeConfig2;
|
|
3250
|
+
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
|
|
3251
|
+
resourceCode = _Object$entries3$_i[0],
|
|
3252
|
+
items = _Object$entries3$_i[1];
|
|
3253
|
+
// 获取该资源类型对应的 form_id
|
|
3254
|
+
var targetFormId = resourceCodeToFormIdMap[resourceCode];
|
|
3255
|
+
if (!targetFormId) {
|
|
3256
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u627E\u4E0D\u5230\u5BF9\u5E94\u7684 form_id"));
|
|
3257
|
+
return {
|
|
3258
|
+
v: {
|
|
3259
|
+
success: false,
|
|
3260
|
+
minAvailableCount: 0
|
|
3261
|
+
}
|
|
3262
|
+
};
|
|
3263
|
+
}
|
|
3264
|
+
|
|
3265
|
+
// 获取该资源类型的所有资源
|
|
3266
|
+
var resourcesOfThisType = [];
|
|
3267
|
+
items.forEach(function (cartItem) {
|
|
3268
|
+
var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
3269
|
+
productResourceIds.forEach(function (resourceId) {
|
|
3270
|
+
var _resource$form_id2;
|
|
3271
|
+
var resource = resourcesMap[resourceId];
|
|
3272
|
+
if (resource && ((_resource$form_id2 = resource.form_id) === null || _resource$form_id2 === void 0 ? void 0 : _resource$form_id2.toString()) === targetFormId) {
|
|
3273
|
+
// 避免重复添加同一个资源
|
|
3274
|
+
if (!resourcesOfThisType.find(function (r) {
|
|
3275
|
+
return r.id === resource.id;
|
|
3276
|
+
})) {
|
|
3277
|
+
resourcesOfThisType.push(resource);
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
});
|
|
3281
|
+
});
|
|
3282
|
+
if (resourcesOfThisType.length === 0) {
|
|
3283
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u627E\u5230\u53EF\u7528\u8D44\u6E90"));
|
|
3284
|
+
return {
|
|
3285
|
+
v: {
|
|
3286
|
+
success: false,
|
|
3287
|
+
minAvailableCount: 0
|
|
3288
|
+
}
|
|
3289
|
+
};
|
|
3290
|
+
}
|
|
3291
|
+
|
|
3292
|
+
// 检查资源类型(单个预约 vs 多个预约)
|
|
3293
|
+
// 从商品配置中获取资源类型信息
|
|
3294
|
+
var resourceTypeConfig = null;
|
|
3295
|
+
var _iterator4 = _createForOfIteratorHelper(items),
|
|
3296
|
+
_step4;
|
|
3297
|
+
try {
|
|
3298
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
3299
|
+
var _cartItem$_productOri15;
|
|
3300
|
+
var cartItem = _step4.value;
|
|
3301
|
+
if ((_cartItem$_productOri15 = cartItem._productOrigin) !== null && _cartItem$_productOri15 !== void 0 && (_cartItem$_productOri15 = _cartItem$_productOri15.product_resource) !== null && _cartItem$_productOri15 !== void 0 && _cartItem$_productOri15.resources) {
|
|
3302
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
|
|
3303
|
+
return r.code === resourceCode && r.status === 1;
|
|
3304
|
+
});
|
|
3305
|
+
if (resourceTypeConfig) break;
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
} catch (err) {
|
|
3309
|
+
_iterator4.e(err);
|
|
3310
|
+
} finally {
|
|
3311
|
+
_iterator4.f();
|
|
3312
|
+
}
|
|
3313
|
+
var isMultipleBooking = ((_resourceTypeConfig2 = resourceTypeConfig) === null || _resourceTypeConfig2 === void 0 ? void 0 : _resourceTypeConfig2.type) === 'multiple';
|
|
3314
|
+
var totalAvailable;
|
|
3315
|
+
var requiredAmount;
|
|
3316
|
+
var availableAmount;
|
|
3317
|
+
if (isMultipleBooking) {
|
|
3318
|
+
// 多个预约:计算容量
|
|
3319
|
+
totalAvailable = resourcesOfThisType.reduce(function (sum, resource) {
|
|
3320
|
+
return sum + (resource.capacity || 0);
|
|
3321
|
+
}, 0);
|
|
3322
|
+
requiredAmount = items.reduce(function (sum, cartItem) {
|
|
3323
|
+
var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
|
|
3324
|
+
currentCapacity = _getCapacityInfoByCar8.currentCapacity;
|
|
3325
|
+
return sum + currentCapacity;
|
|
3326
|
+
}, 0);
|
|
3327
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
3328
|
+
} else {
|
|
3329
|
+
// 单个预约:计算资源个数
|
|
3330
|
+
totalAvailable = resourcesOfThisType.length;
|
|
3331
|
+
requiredAmount = items.reduce(function (sum, cartItem) {
|
|
3332
|
+
return sum + (cartItem.num || 1);
|
|
3333
|
+
}, 0);
|
|
3334
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
3335
|
+
}
|
|
3336
|
+
|
|
3337
|
+
// 记录资源容量信息
|
|
3338
|
+
resourceCapacityInfo.push({
|
|
3339
|
+
code: resourceCode,
|
|
3340
|
+
available: availableAmount,
|
|
3341
|
+
total: totalAvailable,
|
|
3342
|
+
required: requiredAmount,
|
|
3343
|
+
isMultiple: isMultipleBooking
|
|
3344
|
+
});
|
|
3345
|
+
availableCountsByResourceType.push(availableAmount);
|
|
3346
|
+
|
|
3347
|
+
// 检查是否有容量问题
|
|
3348
|
+
if (requiredAmount > totalAvailable) {
|
|
3349
|
+
hasCapacityIssue = true;
|
|
3350
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " ").concat(isMultipleBooking ? '容量' : '资源数量', "\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredAmount, ", \u603B\u5171 ").concat(totalAvailable));
|
|
3351
|
+
}
|
|
3352
|
+
|
|
3353
|
+
// 为通过检测的商品分配一个公共可用时间段
|
|
3354
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u8D44\u6E90\u65F6\u95F4\u4FE1\u606F:"), resourcesOfThisType.map(function (r) {
|
|
3355
|
+
return {
|
|
3356
|
+
id: r.id,
|
|
3357
|
+
times: r.times.map(function (t) {
|
|
3358
|
+
return "".concat(t.start_at, " - ").concat(t.end_at);
|
|
3359
|
+
})
|
|
3360
|
+
};
|
|
3361
|
+
}));
|
|
3362
|
+
|
|
3363
|
+
// 找到所有资源都可用的时间段
|
|
3364
|
+
var commonTimeSlots = _this16.findCommonAvailableTimeSlots(resourcesOfThisType);
|
|
3365
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonTimeSlots);
|
|
3366
|
+
if (commonTimeSlots.length === 0) {
|
|
3367
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4\u6BB5"));
|
|
3368
|
+
return {
|
|
3369
|
+
v: {
|
|
3370
|
+
success: false,
|
|
3371
|
+
minAvailableCount: 0
|
|
3372
|
+
}
|
|
3373
|
+
};
|
|
3374
|
+
}
|
|
3375
|
+
|
|
3376
|
+
// 使用第一个公共可用时间段,但只处理未处理过的商品
|
|
3377
|
+
var firstCommonSlot = commonTimeSlots[0];
|
|
3378
|
+
console.log("\u4F7F\u7528\u516C\u5171\u65F6\u95F4\u6BB5: ".concat(firstCommonSlot.startTime, " - ").concat(firstCommonSlot.endTime));
|
|
3379
|
+
items.forEach(function (cartItem) {
|
|
3380
|
+
// 只处理未处理过的商品,避免重复添加
|
|
3381
|
+
if (!processedCartItemIds.has(cartItem._id)) {
|
|
3382
|
+
processedCartItemIds.add(cartItem._id);
|
|
3383
|
+
var processedItem = _objectSpread(_objectSpread({}, cartItem), {}, {
|
|
3384
|
+
start_date: dateRange[0].date,
|
|
3385
|
+
start_time: firstCommonSlot.startTime,
|
|
3386
|
+
end_time: firstCommonSlot.endTime,
|
|
3387
|
+
end_date: dateRange[0].date
|
|
3388
|
+
});
|
|
3389
|
+
processedItemsWithoutTime.push(processedItem);
|
|
3390
|
+
}
|
|
3391
|
+
});
|
|
3392
|
+
},
|
|
3393
|
+
_ret4;
|
|
3394
|
+
for (var _i3 = 0, _Object$entries3 = Object.entries(itemsByResourceType); _i3 < _Object$entries3.length; _i3++) {
|
|
3395
|
+
_ret4 = _loop5();
|
|
3396
|
+
if (_ret4) return _ret4.v;
|
|
3397
|
+
}
|
|
3398
|
+
|
|
3399
|
+
// 如果有容量问题,找出限制最严格的资源类型,返回其总容量
|
|
3400
|
+
if (hasCapacityIssue) {
|
|
3401
|
+
// 找出超出容量的资源类型中,总容量最少的那个
|
|
3402
|
+
var overCapacityResources = resourceCapacityInfo.filter(function (info) {
|
|
3403
|
+
return info.required > info.total;
|
|
3404
|
+
});
|
|
3405
|
+
if (overCapacityResources.length > 0) {
|
|
3406
|
+
var _minTotalCapacity2 = Math.min.apply(Math, _toConsumableArray(overCapacityResources.map(function (info) {
|
|
3407
|
+
return info.total;
|
|
3408
|
+
})));
|
|
3409
|
+
return {
|
|
3410
|
+
success: false,
|
|
3411
|
+
minAvailableCount: _minTotalCapacity2
|
|
3412
|
+
};
|
|
3413
|
+
}
|
|
3414
|
+
// 如果没有超出容量的(理论上不应该发生),返回总容量最少的
|
|
3415
|
+
var minTotalCapacity = Math.min.apply(Math, _toConsumableArray(resourceCapacityInfo.map(function (info) {
|
|
3416
|
+
return info.total;
|
|
3417
|
+
})));
|
|
3418
|
+
return {
|
|
3419
|
+
success: false,
|
|
3420
|
+
minAvailableCount: minTotalCapacity
|
|
3421
|
+
};
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
|
|
3425
|
+
// 合并所有商品(有时间的 + 处理后的没有时间的)
|
|
3426
|
+
var allProcessedItems = [].concat(itemsWithTime, processedItemsWithoutTime);
|
|
3427
|
+
|
|
3428
|
+
// 按时间段分组检查
|
|
3429
|
+
var cartItemsByTimeSlot = {};
|
|
3430
|
+
allProcessedItems.forEach(function (cartItem) {
|
|
3431
|
+
if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date) return;
|
|
3432
|
+
var timeSlotKey = "".concat(cartItem.start_date, "_").concat(cartItem.start_time, "_").concat(cartItem.end_date || cartItem.start_date, "_").concat(cartItem.end_time);
|
|
3433
|
+
if (!cartItemsByTimeSlot[timeSlotKey]) {
|
|
3434
|
+
cartItemsByTimeSlot[timeSlotKey] = [];
|
|
3435
|
+
}
|
|
3436
|
+
cartItemsByTimeSlot[timeSlotKey].push(cartItem);
|
|
3437
|
+
});
|
|
3438
|
+
// 检查每个时间段是否有足够的资源容量
|
|
3439
|
+
var _loop6 = function _loop6() {
|
|
3440
|
+
var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
|
|
3441
|
+
timeSlotKey = _Object$entries4$_i[0],
|
|
3442
|
+
itemsInTimeSlot = _Object$entries4$_i[1];
|
|
3443
|
+
var _timeSlotKey$split3 = timeSlotKey.split('_'),
|
|
3444
|
+
_timeSlotKey$split4 = _slicedToArray(_timeSlotKey$split3, 4),
|
|
3445
|
+
startDate = _timeSlotKey$split4[0],
|
|
3446
|
+
startTime = _timeSlotKey$split4[1],
|
|
3447
|
+
endDate = _timeSlotKey$split4[2],
|
|
3448
|
+
endTime = _timeSlotKey$split4[3];
|
|
3449
|
+
var timeSlotStart = "".concat(startDate, " ").concat(startTime);
|
|
3450
|
+
var timeSlotEnd = "".concat(endDate, " ").concat(endTime);
|
|
3451
|
+
|
|
3452
|
+
// 获取这个时间段所有商品涉及的资源
|
|
3453
|
+
var allResourcesForTimeSlot = [];
|
|
3454
|
+
var resourcesIdSet = new Set();
|
|
3455
|
+
|
|
3456
|
+
// 获取资源数据
|
|
3457
|
+
// const dateRange = this.store.date.getDateRange();
|
|
3458
|
+
var resourcesDates = _this16.store.date.getDateList();
|
|
3459
|
+
var targetResourceDate = resourcesDates.find(function (n) {
|
|
3460
|
+
return n.date === startDate;
|
|
3461
|
+
});
|
|
3462
|
+
if (!targetResourceDate) return 0; // continue
|
|
3463
|
+
var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
|
|
3464
|
+
itemsInTimeSlot.forEach(function (cartItem) {
|
|
3465
|
+
if (!cartItem._productOrigin) return;
|
|
3466
|
+
|
|
3467
|
+
// 获取商品的资源配置
|
|
3468
|
+
var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
3469
|
+
productResourceIds.forEach(function (resourceId) {
|
|
3470
|
+
if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
|
|
3471
|
+
resourcesIdSet.add(resourceId);
|
|
3472
|
+
allResourcesForTimeSlot.push(resourcesMap[resourceId]);
|
|
3473
|
+
}
|
|
3474
|
+
});
|
|
3475
|
+
});
|
|
3476
|
+
|
|
3477
|
+
// 按资源类型分组检查容量
|
|
3478
|
+
var _checkTimeSlotCapacit2 = checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot),
|
|
3479
|
+
success = _checkTimeSlotCapacit2.success,
|
|
3480
|
+
required = _checkTimeSlotCapacit2.required,
|
|
3481
|
+
available = _checkTimeSlotCapacit2.available;
|
|
3482
|
+
if (!success) {
|
|
3483
|
+
// 如果有可用数量记录,返回最小值;否则返回 0
|
|
3484
|
+
// const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
3485
|
+
return {
|
|
3486
|
+
v: {
|
|
3487
|
+
success: false,
|
|
3488
|
+
minAvailableCount: available
|
|
3489
|
+
}
|
|
3490
|
+
};
|
|
3491
|
+
}
|
|
3492
|
+
},
|
|
3493
|
+
_ret5;
|
|
3494
|
+
for (var _i4 = 0, _Object$entries4 = Object.entries(cartItemsByTimeSlot); _i4 < _Object$entries4.length; _i4++) {
|
|
3495
|
+
_ret5 = _loop6();
|
|
3496
|
+
if (_ret5 === 0) continue;
|
|
3497
|
+
if (_ret5) return _ret5.v;
|
|
3498
|
+
}
|
|
3499
|
+
|
|
3500
|
+
// 全部通过检测,返回成功和最小可用数量
|
|
3501
|
+
var minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
|
|
3502
|
+
return {
|
|
3503
|
+
success: true,
|
|
3504
|
+
minAvailableCount: minAvailableCount
|
|
3505
|
+
};
|
|
3506
|
+
}
|
|
2472
3507
|
}, {
|
|
2473
3508
|
key: "setOtherData",
|
|
2474
3509
|
value: function setOtherData(key, value) {
|
|
@@ -2490,41 +3525,41 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2490
3525
|
}, {
|
|
2491
3526
|
key: "getProductTypeById",
|
|
2492
3527
|
value: function () {
|
|
2493
|
-
var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3528
|
+
var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(id) {
|
|
2494
3529
|
var productData, _productData$schedule;
|
|
2495
|
-
return _regeneratorRuntime().wrap(function
|
|
2496
|
-
while (1) switch (
|
|
3530
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
3531
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
2497
3532
|
case 0:
|
|
2498
|
-
|
|
3533
|
+
_context25.next = 2;
|
|
2499
3534
|
return this.store.products.getProduct(id);
|
|
2500
3535
|
case 2:
|
|
2501
|
-
productData =
|
|
3536
|
+
productData = _context25.sent;
|
|
2502
3537
|
if (!productData) {
|
|
2503
|
-
|
|
3538
|
+
_context25.next = 9;
|
|
2504
3539
|
break;
|
|
2505
3540
|
}
|
|
2506
3541
|
if (!productData.duration) {
|
|
2507
|
-
|
|
3542
|
+
_context25.next = 6;
|
|
2508
3543
|
break;
|
|
2509
3544
|
}
|
|
2510
|
-
return
|
|
3545
|
+
return _context25.abrupt("return", 'duration');
|
|
2511
3546
|
case 6:
|
|
2512
3547
|
if (!((_productData$schedule = productData['schedule.ids']) !== null && _productData$schedule !== void 0 && _productData$schedule.length)) {
|
|
2513
|
-
|
|
3548
|
+
_context25.next = 8;
|
|
2514
3549
|
break;
|
|
2515
3550
|
}
|
|
2516
|
-
return
|
|
3551
|
+
return _context25.abrupt("return", 'session');
|
|
2517
3552
|
case 8:
|
|
2518
|
-
return
|
|
3553
|
+
return _context25.abrupt("return", 'normal');
|
|
2519
3554
|
case 9:
|
|
2520
|
-
return
|
|
3555
|
+
return _context25.abrupt("return", 'normal');
|
|
2521
3556
|
case 10:
|
|
2522
3557
|
case "end":
|
|
2523
|
-
return
|
|
3558
|
+
return _context25.stop();
|
|
2524
3559
|
}
|
|
2525
|
-
},
|
|
3560
|
+
}, _callee25, this);
|
|
2526
3561
|
}));
|
|
2527
|
-
function getProductTypeById(
|
|
3562
|
+
function getProductTypeById(_x19) {
|
|
2528
3563
|
return _getProductTypeById.apply(this, arguments);
|
|
2529
3564
|
}
|
|
2530
3565
|
return getProductTypeById;
|
|
@@ -2540,7 +3575,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2540
3575
|
}, {
|
|
2541
3576
|
key: "getResourcesByCartItemAndCode",
|
|
2542
3577
|
value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
|
|
2543
|
-
var _cartItem$
|
|
3578
|
+
var _cartItem$_productOri16;
|
|
2544
3579
|
var dateRange = this.store.date.getDateRange();
|
|
2545
3580
|
var resources = [];
|
|
2546
3581
|
if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
|
|
@@ -2563,16 +3598,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2563
3598
|
});
|
|
2564
3599
|
if (!cartItem) return [];
|
|
2565
3600
|
var selectedResources = [];
|
|
2566
|
-
var
|
|
2567
|
-
currentCapacity =
|
|
2568
|
-
formatCapacity =
|
|
3601
|
+
var _getCapacityInfoByCar9 = getCapacityInfoByCartItem(cartItem),
|
|
3602
|
+
currentCapacity = _getCapacityInfoByCar9.currentCapacity,
|
|
3603
|
+
formatCapacity = _getCapacityInfoByCar9.formatCapacity;
|
|
2569
3604
|
cartItem._origin.metadata.capacity = formatCapacity;
|
|
2570
3605
|
if (cartItem.holder_id) {
|
|
2571
3606
|
selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
|
|
2572
3607
|
} else {
|
|
2573
3608
|
selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
|
|
2574
3609
|
}
|
|
2575
|
-
var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$
|
|
3610
|
+
var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri16 = cartItem._productOrigin) === null || _cartItem$_productOri16 === void 0 || (_cartItem$_productOri16 = _cartItem$_productOri16.product_resource) === null || _cartItem$_productOri16 === void 0 ? void 0 : _cartItem$_productOri16.resources) || [], selectedResources, currentCapacity);
|
|
2576
3611
|
var targetResource = productResources.find(function (resource) {
|
|
2577
3612
|
return resource.code === resourceCode;
|
|
2578
3613
|
});
|
|
@@ -2595,7 +3630,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2595
3630
|
});
|
|
2596
3631
|
if (mTimes.length === 0) return false;
|
|
2597
3632
|
var canUseArr = mTimes.map(function (item) {
|
|
2598
|
-
var _cartItem$
|
|
3633
|
+
var _cartItem$_productOri17;
|
|
2599
3634
|
var res = getIsUsableByTimeItem({
|
|
2600
3635
|
timeSlice: {
|
|
2601
3636
|
start_time: startTime.format('HH:mm'),
|
|
@@ -2607,7 +3642,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2607
3642
|
resource: m,
|
|
2608
3643
|
currentCount: currentCapacity || 0,
|
|
2609
3644
|
resourcesUseableMap: resourcesUseableMap,
|
|
2610
|
-
cut_off_time: (_cartItem$
|
|
3645
|
+
cut_off_time: (_cartItem$_productOri17 = cartItem._productOrigin) === null || _cartItem$_productOri17 === void 0 ? void 0 : _cartItem$_productOri17.cut_off_time
|
|
2611
3646
|
});
|
|
2612
3647
|
if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
|
|
2613
3648
|
resourcesUseableMap[m.id] = res.usable;
|
|
@@ -2621,12 +3656,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2621
3656
|
});
|
|
2622
3657
|
} else {
|
|
2623
3658
|
targetResource.renderList = targetResource.renderList.filter(function (n) {
|
|
2624
|
-
var _cartItem$
|
|
3659
|
+
var _cartItem$_productOri18;
|
|
2625
3660
|
var recordCount = n.capacity || 0;
|
|
2626
3661
|
if (n.onlyComputed) return false;
|
|
2627
3662
|
var timeSlots = getTimeSlicesByResource({
|
|
2628
3663
|
resource: n,
|
|
2629
|
-
duration: ((_cartItem$
|
|
3664
|
+
duration: ((_cartItem$_productOri18 = cartItem._productOrigin) === null || _cartItem$_productOri18 === void 0 || (_cartItem$_productOri18 = _cartItem$_productOri18.duration) === null || _cartItem$_productOri18 === void 0 ? void 0 : _cartItem$_productOri18.value) || 10,
|
|
2630
3665
|
split: 10,
|
|
2631
3666
|
currentDate: dateRange[0].date
|
|
2632
3667
|
});
|
|
@@ -2644,12 +3679,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2644
3679
|
}, {
|
|
2645
3680
|
key: "getTimeslotsScheduleByDateRange",
|
|
2646
3681
|
value: (function () {
|
|
2647
|
-
var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2648
|
-
var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results,
|
|
2649
|
-
return _regeneratorRuntime().wrap(function
|
|
2650
|
-
while (1) switch (
|
|
3682
|
+
var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref14) {
|
|
3683
|
+
var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i5, _dates, date;
|
|
3684
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
3685
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
2651
3686
|
case 0:
|
|
2652
|
-
startDate =
|
|
3687
|
+
startDate = _ref14.startDate, endDate = _ref14.endDate, scheduleIds = _ref14.scheduleIds, resources = _ref14.resources;
|
|
2653
3688
|
console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
|
|
2654
3689
|
startDate: startDate,
|
|
2655
3690
|
endDate: endDate,
|
|
@@ -2666,22 +3701,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2666
3701
|
}
|
|
2667
3702
|
// 如果不支持 Web Worker,使用同步方式处理
|
|
2668
3703
|
results = {};
|
|
2669
|
-
for (
|
|
2670
|
-
date = _dates[
|
|
3704
|
+
for (_i5 = 0, _dates = dates; _i5 < _dates.length; _i5++) {
|
|
3705
|
+
date = _dates[_i5];
|
|
2671
3706
|
results[date] = this.getTimeslotBySchedule({
|
|
2672
3707
|
date: date,
|
|
2673
3708
|
scheduleIds: scheduleIds,
|
|
2674
3709
|
resources: resources
|
|
2675
3710
|
});
|
|
2676
3711
|
}
|
|
2677
|
-
return
|
|
3712
|
+
return _context26.abrupt("return", results);
|
|
2678
3713
|
case 9:
|
|
2679
3714
|
case "end":
|
|
2680
|
-
return
|
|
3715
|
+
return _context26.stop();
|
|
2681
3716
|
}
|
|
2682
|
-
},
|
|
3717
|
+
}, _callee26, this);
|
|
2683
3718
|
}));
|
|
2684
|
-
function getTimeslotsScheduleByDateRange(
|
|
3719
|
+
function getTimeslotsScheduleByDateRange(_x20) {
|
|
2685
3720
|
return _getTimeslotsScheduleByDateRange.apply(this, arguments);
|
|
2686
3721
|
}
|
|
2687
3722
|
return getTimeslotsScheduleByDateRange;
|
|
@@ -2689,7 +3724,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2689
3724
|
}, {
|
|
2690
3725
|
key: "getAvailableDateForSessionOptimize",
|
|
2691
3726
|
value: function () {
|
|
2692
|
-
var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3727
|
+
var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
|
|
2693
3728
|
var _this$store$currentPr3, _this$store$currentPr4, _tempProducts;
|
|
2694
3729
|
var params,
|
|
2695
3730
|
startDate,
|
|
@@ -2708,12 +3743,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2708
3743
|
openResources,
|
|
2709
3744
|
allProductResources,
|
|
2710
3745
|
targetSchedules,
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
return _regeneratorRuntime().wrap(function
|
|
2714
|
-
while (1) switch (
|
|
3746
|
+
_loop7,
|
|
3747
|
+
_args28 = arguments;
|
|
3748
|
+
return _regeneratorRuntime().wrap(function _callee27$(_context28) {
|
|
3749
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
2715
3750
|
case 0:
|
|
2716
|
-
params =
|
|
3751
|
+
params = _args28.length > 0 && _args28[0] !== undefined ? _args28[0] : {};
|
|
2717
3752
|
// 开始日期如果小于今天,直接以今天当做开始日期
|
|
2718
3753
|
startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
|
|
2719
3754
|
if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
|
|
@@ -2738,15 +3773,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2738
3773
|
// 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
|
|
2739
3774
|
cache = (_this$store$currentPr3 = this.store.currentProductMeta) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3['timeSlotBySchedule'];
|
|
2740
3775
|
if (!cache) {
|
|
2741
|
-
|
|
3776
|
+
_context28.next = 13;
|
|
2742
3777
|
break;
|
|
2743
3778
|
}
|
|
2744
3779
|
if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
|
|
2745
|
-
|
|
3780
|
+
_context28.next = 13;
|
|
2746
3781
|
break;
|
|
2747
3782
|
}
|
|
2748
3783
|
this.store.date.setDateList(cache.dateList);
|
|
2749
|
-
return
|
|
3784
|
+
return _context28.abrupt("return", {
|
|
2750
3785
|
dateList: cache.dateList,
|
|
2751
3786
|
firstAvailableDate: cache.firstAvailableDate
|
|
2752
3787
|
});
|
|
@@ -2756,7 +3791,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2756
3791
|
schedule = (_this$store$currentPr4 = this.store.currentProductMeta) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4['schedule'];
|
|
2757
3792
|
filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
|
|
2758
3793
|
tempResourceIds = getResourcesIdsByProduct(tempProducts);
|
|
2759
|
-
|
|
3794
|
+
_context28.next = 19;
|
|
2760
3795
|
return this.store.date.fetchResourceDates({
|
|
2761
3796
|
query: {
|
|
2762
3797
|
start_date: startDate || '',
|
|
@@ -2765,7 +3800,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2765
3800
|
}
|
|
2766
3801
|
});
|
|
2767
3802
|
case 19:
|
|
2768
|
-
res =
|
|
3803
|
+
res = _context28.sent;
|
|
2769
3804
|
// 2. 商品 schedule 数据,确定日程在每一天的时间片
|
|
2770
3805
|
// 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
|
|
2771
3806
|
dates = [];
|
|
@@ -2785,10 +3820,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2785
3820
|
}
|
|
2786
3821
|
});
|
|
2787
3822
|
targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
|
|
2788
|
-
|
|
3823
|
+
_loop7 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop7() {
|
|
2789
3824
|
var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
|
|
2790
|
-
return _regeneratorRuntime().wrap(function
|
|
2791
|
-
while (1) switch (
|
|
3825
|
+
return _regeneratorRuntime().wrap(function _loop7$(_context27) {
|
|
3826
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
2792
3827
|
case 0:
|
|
2793
3828
|
currentDateStr = currentDate.format('YYYY-MM-DD');
|
|
2794
3829
|
status = 'available'; // 1. 检查商品的提前量等情况是否满足
|
|
@@ -2880,32 +3915,32 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2880
3915
|
|
|
2881
3916
|
// 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
|
|
2882
3917
|
if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 31)) {
|
|
2883
|
-
|
|
3918
|
+
_context27.next = 9;
|
|
2884
3919
|
break;
|
|
2885
3920
|
}
|
|
2886
|
-
return
|
|
3921
|
+
return _context27.abrupt("return", 1);
|
|
2887
3922
|
case 9:
|
|
2888
3923
|
currentDate = dayjs(currentDate).add(1, 'day');
|
|
2889
3924
|
case 10:
|
|
2890
3925
|
case "end":
|
|
2891
|
-
return
|
|
3926
|
+
return _context27.stop();
|
|
2892
3927
|
}
|
|
2893
|
-
},
|
|
3928
|
+
}, _loop7);
|
|
2894
3929
|
});
|
|
2895
3930
|
case 28:
|
|
2896
3931
|
if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
|
|
2897
|
-
|
|
3932
|
+
_context28.next = 34;
|
|
2898
3933
|
break;
|
|
2899
3934
|
}
|
|
2900
|
-
return
|
|
3935
|
+
return _context28.delegateYield(_loop7(), "t0", 30);
|
|
2901
3936
|
case 30:
|
|
2902
|
-
if (!
|
|
2903
|
-
|
|
3937
|
+
if (!_context28.t0) {
|
|
3938
|
+
_context28.next = 32;
|
|
2904
3939
|
break;
|
|
2905
3940
|
}
|
|
2906
|
-
return
|
|
3941
|
+
return _context28.abrupt("break", 34);
|
|
2907
3942
|
case 32:
|
|
2908
|
-
|
|
3943
|
+
_context28.next = 28;
|
|
2909
3944
|
break;
|
|
2910
3945
|
case 34:
|
|
2911
3946
|
// 最终把资源数据也加到日期内
|
|
@@ -2920,15 +3955,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2920
3955
|
startDate: startDate,
|
|
2921
3956
|
endDate: dayjs(currentDate).format('YYYY-MM-DD')
|
|
2922
3957
|
};
|
|
2923
|
-
return
|
|
3958
|
+
return _context28.abrupt("return", {
|
|
2924
3959
|
dateList: dates,
|
|
2925
3960
|
firstAvailableDate: firstAvailableDate
|
|
2926
3961
|
});
|
|
2927
3962
|
case 39:
|
|
2928
3963
|
case "end":
|
|
2929
|
-
return
|
|
3964
|
+
return _context28.stop();
|
|
2930
3965
|
}
|
|
2931
|
-
},
|
|
3966
|
+
}, _callee27, this);
|
|
2932
3967
|
}));
|
|
2933
3968
|
function getAvailableDateForSessionOptimize() {
|
|
2934
3969
|
return _getAvailableDateForSessionOptimize.apply(this, arguments);
|