@pisell/pisellos 1.0.70 → 1.0.71

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.
@@ -30,8 +30,9 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
30
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); }
31
31
  import { BaseModule } from "../../modules/BaseModule";
32
32
  import { createModule } from "./types";
33
+ import { formatProductToCartItem, createCartItemOrigin, getUniqueId, handleVariantProduct, formatDateToCartItem, formatAccountToCartItem } from "../../modules/Cart/utils";
33
34
  import { getAvailableProductResources } from "./utils/products";
34
- import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection } from "./utils/resources";
35
+ import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection, isConflict } from "./utils/resources";
35
36
  import dayjs from 'dayjs';
36
37
  import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
37
38
  import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
@@ -1194,7 +1195,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1194
1195
  this.addProductCheck({
1195
1196
  date: date
1196
1197
  });
1197
- this.store.cart.addItem(addItemParams);
1198
+ // 如果 quantity 大于 1,且是预约商品,则进入购物车拆散成多条数据
1199
+ if (addItemParams.quantity > 1 && !isNormalProduct(productData.origin)) {
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
+ }
1198
1208
  return {
1199
1209
  success: true
1200
1210
  };
@@ -2061,7 +2071,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2061
2071
  // item._origin.resources?.forEach((n: any) => {
2062
2072
  // resourceIds.push(n.relation_id);
2063
2073
  // });
2064
- if (item.resource_id) {
2074
+ if (item.resource_id && !resourceIds.includes(item.resource_id)) {
2065
2075
  resourceIds.push(item.resource_id);
2066
2076
  }
2067
2077
  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) {
@@ -2156,6 +2166,26 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2156
2166
  return 0;
2157
2167
  }, 0);
2158
2168
  }
2169
+ // 计算容量的辅助函数
2170
+ var calculateCapacityFromCartItems = function calculateCapacityFromCartItems(items) {
2171
+ return items.reduce(function (total, item) {
2172
+ return total + (getCapacityInfoByCartItem(item).currentCapacity || 0);
2173
+ }, 0);
2174
+ };
2175
+
2176
+ // 如果是多个预约,去要求助几个 holder 下最大的需求容量capacity
2177
+ var maxCapacity = 1;
2178
+ if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
2179
+ accountList.forEach(function (account) {
2180
+ var accountCartItems = _this12.store.cart.getCartByAccount(account.getId());
2181
+ var currentCapacity = calculateCapacityFromCartItems(accountCartItems);
2182
+ if (currentCapacity > maxCapacity) {
2183
+ maxCapacity = currentCapacity;
2184
+ }
2185
+ });
2186
+ } else {
2187
+ maxCapacity = calculateCapacityFromCartItems(cartItems);
2188
+ }
2159
2189
  var timeSlots = getTimeSlicesByResources({
2160
2190
  resourceIds: resourceIds,
2161
2191
  resourcesMap: resourcesMap,
@@ -2163,6 +2193,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2163
2193
  currentDate: dateRange[0].date,
2164
2194
  split: 10,
2165
2195
  resourcesUseableMap: resourcesUseableMap,
2196
+ capacity: maxCapacity,
2166
2197
  cut_off_time: maxCutOffTime,
2167
2198
  hasFlexibleDuration: hasFlexibleDuration,
2168
2199
  operating_day_boundary: operating_day_boundary,
@@ -2584,7 +2615,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2584
2615
  // acc += n.event_list?.reduce((acc: any, curr: any) => acc + curr.pax, 0);
2585
2616
  // mSet.set(n)
2586
2617
  n.event_list.forEach(function (m) {
2587
- mSet.set(m.id, m.pax || 1);
2618
+ // 需要确认 m 的时间段是否和 item 的时间段有交集
2619
+ if (isConflict({
2620
+ start_at: m.start_at,
2621
+ end_at: m.end_at
2622
+ }, {
2623
+ start_at: dayjs(item.start),
2624
+ end_at: dayjs(item.end)
2625
+ })) {
2626
+ mSet.set(m.id, m.pax || 1);
2627
+ }
2588
2628
  });
2589
2629
  });
2590
2630
  acc += Array.from(mSet.values()).reduce(function (acc, curr) {
@@ -3017,7 +3057,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3017
3057
  });
3018
3058
 
3019
3059
  // 按资源类型分组检查容量
3020
- if (!checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
3060
+ var _checkTimeSlotCapacit = checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot),
3061
+ success = _checkTimeSlotCapacit.success,
3062
+ required = _checkTimeSlotCapacit.required,
3063
+ available = _checkTimeSlotCapacit.available;
3064
+ if (!success) {
3021
3065
  // 如果有可用数量记录,返回最小值;否则返回 0
3022
3066
  var _minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
3023
3067
  return {
@@ -3042,6 +3086,437 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3042
3086
  minAvailableCount: minAvailableCount
3043
3087
  };
3044
3088
  }
3089
+
3090
+ /**
3091
+ * 将 ProductData 转换为 CartItem,但不添加到购物车
3092
+ * 参考 addProductToCart 方法的实现
3093
+ */
3094
+ }, {
3095
+ key: "convertProductToCartItem",
3096
+ value: function convertProductToCartItem(_ref11) {
3097
+ var product = _ref11.product,
3098
+ date = _ref11.date,
3099
+ account = _ref11.account;
3100
+ var _ref12 = product || {},
3101
+ bundle = _ref12.bundle,
3102
+ options = _ref12.options,
3103
+ origin = _ref12.origin,
3104
+ product_variant_id = _ref12.product_variant_id,
3105
+ _ref12$quantity = _ref12.quantity,
3106
+ quantity = _ref12$quantity === void 0 ? 1 : _ref12$quantity;
3107
+
3108
+ // 处理商品数据,类似 addProductToCart 中的逻辑
3109
+ var productData = _objectSpread(_objectSpread({}, origin), {}, {
3110
+ product_variant_id: product_variant_id
3111
+ });
3112
+
3113
+ // 处理组合商品
3114
+ var processedProduct = handleVariantProduct(productData);
3115
+
3116
+ // 如果没有传入账户,获取当前活跃账户
3117
+ if (!account) {
3118
+ var activeAccount = this.getActiveAccount();
3119
+ if (activeAccount) {
3120
+ account = activeAccount;
3121
+ }
3122
+ }
3123
+
3124
+ // 创建基础的 CartItem
3125
+ var cartItem = {
3126
+ _id: getUniqueId('temp_'),
3127
+ _origin: createCartItemOrigin(),
3128
+ _productOrigin: processedProduct,
3129
+ _productInit: product
3130
+ };
3131
+
3132
+ // 使用格式化函数填充 CartItem 数据
3133
+ formatProductToCartItem({
3134
+ cartItem: cartItem,
3135
+ product: processedProduct,
3136
+ bundle: bundle,
3137
+ options: options,
3138
+ product_variant_id: product_variant_id,
3139
+ quantity: quantity
3140
+ });
3141
+
3142
+ // 如果有日期信息,格式化日期到购物车
3143
+ if (date) {
3144
+ formatDateToCartItem({
3145
+ cartItem: cartItem,
3146
+ date: date
3147
+ });
3148
+ }
3149
+
3150
+ // 如果有账户信息,格式化账户到购物车
3151
+ if (account) {
3152
+ formatAccountToCartItem({
3153
+ cartItem: cartItem,
3154
+ account: account
3155
+ });
3156
+ }
3157
+ return cartItem;
3158
+ }
3159
+ }, {
3160
+ key: "checkMaxDurationCapacityForDetailNums",
3161
+ value: function checkMaxDurationCapacityForDetailNums(_ref13) {
3162
+ var _this16 = this;
3163
+ var product = _ref13.product,
3164
+ date = _ref13.date,
3165
+ account = _ref13.account;
3166
+ var cartItems = cloneDeep(this.store.cart.getItems());
3167
+
3168
+ // 将 ProductData 转换为 CartItem 但不真正添加到购物车
3169
+ var currentCartItem = this.convertProductToCartItem({
3170
+ product: product,
3171
+ date: date,
3172
+ account: account
3173
+ });
3174
+ cartItems.push(currentCartItem);
3175
+ if (cartItems.length === 0) return {
3176
+ success: true,
3177
+ minAvailableCount: 0
3178
+ };
3179
+
3180
+ // 将购物车商品分为有时间的和没有时间的
3181
+ var itemsWithTime = [];
3182
+ var itemsWithoutTime = [];
3183
+ // 记录每种资源类型的可用数量
3184
+ var availableCountsByResourceType = [];
3185
+ cartItems.forEach(function (cartItem) {
3186
+ if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
3187
+ itemsWithTime.push(cartItem);
3188
+ } else {
3189
+ itemsWithoutTime.push(cartItem);
3190
+ }
3191
+ });
3192
+
3193
+ // 处理没有时间的商品,为它们分配公共可用时间的第一个时间片
3194
+ var processedItemsWithoutTime = [];
3195
+ if (itemsWithoutTime.length > 0) {
3196
+ // 按资源类型分组处理没有时间的商品
3197
+ var itemsByResourceType = {};
3198
+ itemsWithoutTime.forEach(function (cartItem) {
3199
+ var _cartItem$_productOri13;
3200
+ if (!cartItem._productOrigin) return;
3201
+ var resourceTypes = ((_cartItem$_productOri13 = cartItem._productOrigin.product_resource) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.resources) || [];
3202
+ resourceTypes.forEach(function (resourceType) {
3203
+ if (resourceType.status === 1) {
3204
+ var _resourceType$id2;
3205
+ var resourceCode = resourceType.code || ((_resourceType$id2 = resourceType.id) === null || _resourceType$id2 === void 0 ? void 0 : _resourceType$id2.toString());
3206
+ if (!itemsByResourceType[resourceCode]) {
3207
+ itemsByResourceType[resourceCode] = [];
3208
+ }
3209
+ // 避免重复添加同一个商品
3210
+ if (!itemsByResourceType[resourceCode].find(function (item) {
3211
+ return item._id === cartItem._id;
3212
+ })) {
3213
+ itemsByResourceType[resourceCode].push(cartItem);
3214
+ }
3215
+ }
3216
+ });
3217
+ });
3218
+
3219
+ // 为每种资源类型检查容量
3220
+ var dateRange = this.store.date.getDateRange();
3221
+ if (!dateRange || dateRange.length === 0) return {
3222
+ success: false,
3223
+ minAvailableCount: 0
3224
+ };
3225
+ var resourcesDates = this.store.date.getDateList();
3226
+ var targetResourceDate = resourcesDates.find(function (n) {
3227
+ return n.date === dateRange[0].date;
3228
+ });
3229
+ if (!targetResourceDate) return {
3230
+ success: false,
3231
+ minAvailableCount: 0
3232
+ };
3233
+ var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
3234
+
3235
+ // 从购物车商品中获取资源类型配置,建立 resourceCode 到 form_id 的映射关系
3236
+ var resourceCodeToFormIdMap = {};
3237
+
3238
+ // 遍历购物车中的商品,收集所有资源类型配置
3239
+ Object.values(itemsByResourceType).flat().forEach(function (cartItem) {
3240
+ var _cartItem$_productOri14;
3241
+ if ((_cartItem$_productOri14 = cartItem._productOrigin) !== null && _cartItem$_productOri14 !== void 0 && (_cartItem$_productOri14 = _cartItem$_productOri14.product_resource) !== null && _cartItem$_productOri14 !== void 0 && _cartItem$_productOri14.resources) {
3242
+ cartItem._productOrigin.product_resource.resources.forEach(function (resourceConfig) {
3243
+ // 只处理启用的资源类型 (status === 1)
3244
+ if (resourceConfig.status === 1 && resourceConfig.code) {
3245
+ var _resourceConfig$id2, _resourceConfig$resou2;
3246
+ 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());
3247
+ if (formId) {
3248
+ resourceCodeToFormIdMap[resourceConfig.code] = formId;
3249
+ }
3250
+ }
3251
+ });
3252
+ }
3253
+ });
3254
+ var hasCapacityIssue = false;
3255
+ var resourceCapacityInfo = [];
3256
+
3257
+ // 用于跟踪已处理的商品,避免重复添加
3258
+ var processedCartItemIds = new Set();
3259
+
3260
+ // 先检查所有资源类型,收集可用数量信息
3261
+ var _loop5 = function _loop5() {
3262
+ var _resourceTypeConfig2;
3263
+ var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
3264
+ resourceCode = _Object$entries3$_i[0],
3265
+ items = _Object$entries3$_i[1];
3266
+ // 获取该资源类型对应的 form_id
3267
+ var targetFormId = resourceCodeToFormIdMap[resourceCode];
3268
+ if (!targetFormId) {
3269
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u627E\u4E0D\u5230\u5BF9\u5E94\u7684 form_id"));
3270
+ return {
3271
+ v: {
3272
+ success: false,
3273
+ minAvailableCount: 0
3274
+ }
3275
+ };
3276
+ }
3277
+
3278
+ // 获取该资源类型的所有资源
3279
+ var resourcesOfThisType = [];
3280
+ items.forEach(function (cartItem) {
3281
+ var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
3282
+ productResourceIds.forEach(function (resourceId) {
3283
+ var _resource$form_id2;
3284
+ var resource = resourcesMap[resourceId];
3285
+ if (resource && ((_resource$form_id2 = resource.form_id) === null || _resource$form_id2 === void 0 ? void 0 : _resource$form_id2.toString()) === targetFormId) {
3286
+ // 避免重复添加同一个资源
3287
+ if (!resourcesOfThisType.find(function (r) {
3288
+ return r.id === resource.id;
3289
+ })) {
3290
+ resourcesOfThisType.push(resource);
3291
+ }
3292
+ }
3293
+ });
3294
+ });
3295
+ if (resourcesOfThisType.length === 0) {
3296
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u627E\u5230\u53EF\u7528\u8D44\u6E90"));
3297
+ return {
3298
+ v: {
3299
+ success: false,
3300
+ minAvailableCount: 0
3301
+ }
3302
+ };
3303
+ }
3304
+
3305
+ // 检查资源类型(单个预约 vs 多个预约)
3306
+ // 从商品配置中获取资源类型信息
3307
+ var resourceTypeConfig = null;
3308
+ var _iterator4 = _createForOfIteratorHelper(items),
3309
+ _step4;
3310
+ try {
3311
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
3312
+ var _cartItem$_productOri15;
3313
+ var cartItem = _step4.value;
3314
+ if ((_cartItem$_productOri15 = cartItem._productOrigin) !== null && _cartItem$_productOri15 !== void 0 && (_cartItem$_productOri15 = _cartItem$_productOri15.product_resource) !== null && _cartItem$_productOri15 !== void 0 && _cartItem$_productOri15.resources) {
3315
+ resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
3316
+ return r.code === resourceCode && r.status === 1;
3317
+ });
3318
+ if (resourceTypeConfig) break;
3319
+ }
3320
+ }
3321
+ } catch (err) {
3322
+ _iterator4.e(err);
3323
+ } finally {
3324
+ _iterator4.f();
3325
+ }
3326
+ var isMultipleBooking = ((_resourceTypeConfig2 = resourceTypeConfig) === null || _resourceTypeConfig2 === void 0 ? void 0 : _resourceTypeConfig2.type) === 'multiple';
3327
+ var totalAvailable;
3328
+ var requiredAmount;
3329
+ var availableAmount;
3330
+ if (isMultipleBooking) {
3331
+ // 多个预约:计算容量
3332
+ totalAvailable = resourcesOfThisType.reduce(function (sum, resource) {
3333
+ return sum + (resource.capacity || 0);
3334
+ }, 0);
3335
+ requiredAmount = items.reduce(function (sum, cartItem) {
3336
+ var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
3337
+ currentCapacity = _getCapacityInfoByCar8.currentCapacity;
3338
+ return sum + currentCapacity;
3339
+ }, 0);
3340
+ availableAmount = Math.max(0, totalAvailable - requiredAmount);
3341
+ } else {
3342
+ // 单个预约:计算资源个数
3343
+ totalAvailable = resourcesOfThisType.length;
3344
+ requiredAmount = items.reduce(function (sum, cartItem) {
3345
+ return sum + (cartItem.num || 1);
3346
+ }, 0);
3347
+ availableAmount = Math.max(0, totalAvailable - requiredAmount);
3348
+ }
3349
+
3350
+ // 记录资源容量信息
3351
+ resourceCapacityInfo.push({
3352
+ code: resourceCode,
3353
+ available: availableAmount,
3354
+ total: totalAvailable,
3355
+ required: requiredAmount,
3356
+ isMultiple: isMultipleBooking
3357
+ });
3358
+ availableCountsByResourceType.push(availableAmount);
3359
+
3360
+ // 检查是否有容量问题
3361
+ if (requiredAmount > totalAvailable) {
3362
+ hasCapacityIssue = true;
3363
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " ").concat(isMultipleBooking ? '容量' : '资源数量', "\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredAmount, ", \u603B\u5171 ").concat(totalAvailable));
3364
+ }
3365
+
3366
+ // 为通过检测的商品分配一个公共可用时间段
3367
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u8D44\u6E90\u65F6\u95F4\u4FE1\u606F:"), resourcesOfThisType.map(function (r) {
3368
+ return {
3369
+ id: r.id,
3370
+ times: r.times.map(function (t) {
3371
+ return "".concat(t.start_at, " - ").concat(t.end_at);
3372
+ })
3373
+ };
3374
+ }));
3375
+
3376
+ // 找到所有资源都可用的时间段
3377
+ var commonTimeSlots = _this16.findCommonAvailableTimeSlots(resourcesOfThisType);
3378
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonTimeSlots);
3379
+ if (commonTimeSlots.length === 0) {
3380
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4\u6BB5"));
3381
+ return {
3382
+ v: {
3383
+ success: false,
3384
+ minAvailableCount: 0
3385
+ }
3386
+ };
3387
+ }
3388
+
3389
+ // 使用第一个公共可用时间段,但只处理未处理过的商品
3390
+ var firstCommonSlot = commonTimeSlots[0];
3391
+ console.log("\u4F7F\u7528\u516C\u5171\u65F6\u95F4\u6BB5: ".concat(firstCommonSlot.startTime, " - ").concat(firstCommonSlot.endTime));
3392
+ items.forEach(function (cartItem) {
3393
+ // 只处理未处理过的商品,避免重复添加
3394
+ if (!processedCartItemIds.has(cartItem._id)) {
3395
+ processedCartItemIds.add(cartItem._id);
3396
+ var processedItem = _objectSpread(_objectSpread({}, cartItem), {}, {
3397
+ start_date: dateRange[0].date,
3398
+ start_time: firstCommonSlot.startTime,
3399
+ end_time: firstCommonSlot.endTime,
3400
+ end_date: dateRange[0].date
3401
+ });
3402
+ processedItemsWithoutTime.push(processedItem);
3403
+ }
3404
+ });
3405
+ },
3406
+ _ret5;
3407
+ for (var _i3 = 0, _Object$entries3 = Object.entries(itemsByResourceType); _i3 < _Object$entries3.length; _i3++) {
3408
+ _ret5 = _loop5();
3409
+ if (_ret5) return _ret5.v;
3410
+ }
3411
+
3412
+ // 如果有容量问题,找出限制最严格的资源类型,返回其总容量
3413
+ if (hasCapacityIssue) {
3414
+ // 找出超出容量的资源类型中,总容量最少的那个
3415
+ var overCapacityResources = resourceCapacityInfo.filter(function (info) {
3416
+ return info.required > info.total;
3417
+ });
3418
+ if (overCapacityResources.length > 0) {
3419
+ var _minTotalCapacity2 = Math.min.apply(Math, _toConsumableArray(overCapacityResources.map(function (info) {
3420
+ return info.total;
3421
+ })));
3422
+ return {
3423
+ success: false,
3424
+ minAvailableCount: _minTotalCapacity2
3425
+ };
3426
+ }
3427
+ // 如果没有超出容量的(理论上不应该发生),返回总容量最少的
3428
+ var minTotalCapacity = Math.min.apply(Math, _toConsumableArray(resourceCapacityInfo.map(function (info) {
3429
+ return info.total;
3430
+ })));
3431
+ return {
3432
+ success: false,
3433
+ minAvailableCount: minTotalCapacity
3434
+ };
3435
+ }
3436
+ }
3437
+
3438
+ // 合并所有商品(有时间的 + 处理后的没有时间的)
3439
+ var allProcessedItems = [].concat(itemsWithTime, processedItemsWithoutTime);
3440
+
3441
+ // 按时间段分组检查
3442
+ var cartItemsByTimeSlot = {};
3443
+ allProcessedItems.forEach(function (cartItem) {
3444
+ if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date) return;
3445
+ var timeSlotKey = "".concat(cartItem.start_date, "_").concat(cartItem.start_time, "_").concat(cartItem.end_date || cartItem.start_date, "_").concat(cartItem.end_time);
3446
+ if (!cartItemsByTimeSlot[timeSlotKey]) {
3447
+ cartItemsByTimeSlot[timeSlotKey] = [];
3448
+ }
3449
+ cartItemsByTimeSlot[timeSlotKey].push(cartItem);
3450
+ });
3451
+ // 检查每个时间段是否有足够的资源容量
3452
+ var _loop6 = function _loop6() {
3453
+ var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
3454
+ timeSlotKey = _Object$entries4$_i[0],
3455
+ itemsInTimeSlot = _Object$entries4$_i[1];
3456
+ var _timeSlotKey$split3 = timeSlotKey.split('_'),
3457
+ _timeSlotKey$split4 = _slicedToArray(_timeSlotKey$split3, 4),
3458
+ startDate = _timeSlotKey$split4[0],
3459
+ startTime = _timeSlotKey$split4[1],
3460
+ endDate = _timeSlotKey$split4[2],
3461
+ endTime = _timeSlotKey$split4[3];
3462
+ var timeSlotStart = "".concat(startDate, " ").concat(startTime);
3463
+ var timeSlotEnd = "".concat(endDate, " ").concat(endTime);
3464
+
3465
+ // 获取这个时间段所有商品涉及的资源
3466
+ var allResourcesForTimeSlot = [];
3467
+ var resourcesIdSet = new Set();
3468
+
3469
+ // 获取资源数据
3470
+ // const dateRange = this.store.date.getDateRange();
3471
+ var resourcesDates = _this16.store.date.getDateList();
3472
+ var targetResourceDate = resourcesDates.find(function (n) {
3473
+ return n.date === startDate;
3474
+ });
3475
+ if (!targetResourceDate) return 0; // continue
3476
+ var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
3477
+ itemsInTimeSlot.forEach(function (cartItem) {
3478
+ if (!cartItem._productOrigin) return;
3479
+
3480
+ // 获取商品的资源配置
3481
+ var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
3482
+ productResourceIds.forEach(function (resourceId) {
3483
+ if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
3484
+ resourcesIdSet.add(resourceId);
3485
+ allResourcesForTimeSlot.push(resourcesMap[resourceId]);
3486
+ }
3487
+ });
3488
+ });
3489
+
3490
+ // 按资源类型分组检查容量
3491
+ var _checkTimeSlotCapacit2 = checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot),
3492
+ success = _checkTimeSlotCapacit2.success,
3493
+ required = _checkTimeSlotCapacit2.required,
3494
+ available = _checkTimeSlotCapacit2.available;
3495
+ if (!success) {
3496
+ // 如果有可用数量记录,返回最小值;否则返回 0
3497
+ // const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
3498
+ return {
3499
+ v: {
3500
+ success: false,
3501
+ minAvailableCount: available
3502
+ }
3503
+ };
3504
+ }
3505
+ },
3506
+ _ret6;
3507
+ for (var _i4 = 0, _Object$entries4 = Object.entries(cartItemsByTimeSlot); _i4 < _Object$entries4.length; _i4++) {
3508
+ _ret6 = _loop6();
3509
+ if (_ret6 === 0) continue;
3510
+ if (_ret6) return _ret6.v;
3511
+ }
3512
+
3513
+ // 全部通过检测,返回成功和最小可用数量
3514
+ var minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
3515
+ return {
3516
+ success: true,
3517
+ minAvailableCount: minAvailableCount
3518
+ };
3519
+ }
3045
3520
  }, {
3046
3521
  key: "setOtherData",
3047
3522
  value: function setOtherData(key, value) {
@@ -3113,7 +3588,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3113
3588
  }, {
3114
3589
  key: "getResourcesByCartItemAndCode",
3115
3590
  value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
3116
- var _cartItem$_productOri13;
3591
+ var _cartItem$_productOri16;
3117
3592
  var dateRange = this.store.date.getDateRange();
3118
3593
  var resources = [];
3119
3594
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -3136,16 +3611,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3136
3611
  });
3137
3612
  if (!cartItem) return [];
3138
3613
  var selectedResources = [];
3139
- var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
3140
- currentCapacity = _getCapacityInfoByCar8.currentCapacity,
3141
- formatCapacity = _getCapacityInfoByCar8.formatCapacity;
3614
+ var _getCapacityInfoByCar9 = getCapacityInfoByCartItem(cartItem),
3615
+ currentCapacity = _getCapacityInfoByCar9.currentCapacity,
3616
+ formatCapacity = _getCapacityInfoByCar9.formatCapacity;
3142
3617
  cartItem._origin.metadata.capacity = formatCapacity;
3143
3618
  if (cartItem.holder_id) {
3144
3619
  selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
3145
3620
  } else {
3146
3621
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
3147
3622
  }
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);
3623
+ 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);
3149
3624
  var targetResource = productResources.find(function (resource) {
3150
3625
  return resource.code === resourceCode;
3151
3626
  });
@@ -3168,7 +3643,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3168
3643
  });
3169
3644
  if (mTimes.length === 0) return false;
3170
3645
  var canUseArr = mTimes.map(function (item) {
3171
- var _cartItem$_productOri14;
3646
+ var _cartItem$_productOri17;
3172
3647
  var res = getIsUsableByTimeItem({
3173
3648
  timeSlice: {
3174
3649
  start_time: startTime.format('HH:mm'),
@@ -3180,7 +3655,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3180
3655
  resource: m,
3181
3656
  currentCount: currentCapacity || 0,
3182
3657
  resourcesUseableMap: resourcesUseableMap,
3183
- cut_off_time: (_cartItem$_productOri14 = cartItem._productOrigin) === null || _cartItem$_productOri14 === void 0 ? void 0 : _cartItem$_productOri14.cut_off_time
3658
+ cut_off_time: (_cartItem$_productOri17 = cartItem._productOrigin) === null || _cartItem$_productOri17 === void 0 ? void 0 : _cartItem$_productOri17.cut_off_time
3184
3659
  });
3185
3660
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
3186
3661
  resourcesUseableMap[m.id] = res.usable;
@@ -3194,12 +3669,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3194
3669
  });
3195
3670
  } else {
3196
3671
  targetResource.renderList = targetResource.renderList.filter(function (n) {
3197
- var _cartItem$_productOri15;
3672
+ var _cartItem$_productOri18;
3198
3673
  var recordCount = n.capacity || 0;
3199
3674
  if (n.onlyComputed) return false;
3200
3675
  var timeSlots = getTimeSlicesByResource({
3201
3676
  resource: n,
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,
3677
+ 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,
3203
3678
  split: 10,
3204
3679
  currentDate: dateRange[0].date
3205
3680
  });
@@ -3217,12 +3692,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3217
3692
  }, {
3218
3693
  key: "getTimeslotsScheduleByDateRange",
3219
3694
  value: (function () {
3220
- var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref11) {
3221
- var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i3, _dates, date;
3695
+ var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref14) {
3696
+ var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i5, _dates, date;
3222
3697
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3223
3698
  while (1) switch (_context26.prev = _context26.next) {
3224
3699
  case 0:
3225
- startDate = _ref11.startDate, endDate = _ref11.endDate, scheduleIds = _ref11.scheduleIds, resources = _ref11.resources;
3700
+ startDate = _ref14.startDate, endDate = _ref14.endDate, scheduleIds = _ref14.scheduleIds, resources = _ref14.resources;
3226
3701
  console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
3227
3702
  startDate: startDate,
3228
3703
  endDate: endDate,
@@ -3239,8 +3714,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3239
3714
  }
3240
3715
  // 如果不支持 Web Worker,使用同步方式处理
3241
3716
  results = {};
3242
- for (_i3 = 0, _dates = dates; _i3 < _dates.length; _i3++) {
3243
- date = _dates[_i3];
3717
+ for (_i5 = 0, _dates = dates; _i5 < _dates.length; _i5++) {
3718
+ date = _dates[_i5];
3244
3719
  results[date] = this.getTimeslotBySchedule({
3245
3720
  date: date,
3246
3721
  scheduleIds: scheduleIds,
@@ -3281,7 +3756,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3281
3756
  openResources,
3282
3757
  allProductResources,
3283
3758
  targetSchedules,
3284
- _loop5,
3759
+ _loop7,
3285
3760
  _args28 = arguments;
3286
3761
  return _regeneratorRuntime().wrap(function _callee27$(_context28) {
3287
3762
  while (1) switch (_context28.prev = _context28.next) {
@@ -3358,9 +3833,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3358
3833
  }
3359
3834
  });
3360
3835
  targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
3361
- _loop5 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop5() {
3836
+ _loop7 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop7() {
3362
3837
  var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
3363
- return _regeneratorRuntime().wrap(function _loop5$(_context27) {
3838
+ return _regeneratorRuntime().wrap(function _loop7$(_context27) {
3364
3839
  while (1) switch (_context27.prev = _context27.next) {
3365
3840
  case 0:
3366
3841
  currentDateStr = currentDate.format('YYYY-MM-DD');
@@ -3463,14 +3938,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3463
3938
  case "end":
3464
3939
  return _context27.stop();
3465
3940
  }
3466
- }, _loop5);
3941
+ }, _loop7);
3467
3942
  });
3468
3943
  case 28:
3469
3944
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
3470
3945
  _context28.next = 34;
3471
3946
  break;
3472
3947
  }
3473
- return _context28.delegateYield(_loop5(), "t0", 30);
3948
+ return _context28.delegateYield(_loop7(), "t0", 30);
3474
3949
  case 30:
3475
3950
  if (!_context28.t0) {
3476
3951
  _context28.next = 32;