@pisell/pisellos 2.1.30 → 2.1.32

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.
@@ -130,9 +130,10 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
130
130
  with_count: with_count,
131
131
  // client_schedule_ids: schedule_ids,
132
132
  schedule_date: schedule_date,
133
+ application_code: (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel,
133
134
  with_schedule: with_schedule,
134
- schedule_datetime: schedule_datetime,
135
- application_code: (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel
135
+ schedule_datetime: schedule_datetime
136
+ // is_eject: 1
136
137
  }, {
137
138
  useCache: true
138
139
  });
@@ -324,6 +324,22 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
324
324
  success: boolean;
325
325
  minAvailableCount: number;
326
326
  };
327
+ /**
328
+ * 将 ProductData 转换为 CartItem,但不添加到购物车
329
+ * 参考 addProductToCart 方法的实现
330
+ */
331
+ private convertProductToCartItem;
332
+ checkMaxDurationCapacityForDetailNums({ product, date, account, }: {
333
+ product: ProductData;
334
+ date?: {
335
+ startTime: string;
336
+ endTime: string;
337
+ } | null;
338
+ account?: Account | null;
339
+ }): {
340
+ success: boolean;
341
+ minAvailableCount: number;
342
+ };
327
343
  setOtherData(key: string, value: any): void;
328
344
  getOtherData(key: string): any;
329
345
  getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
@@ -30,6 +30,7 @@ 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 { BookingByStepHooks, createModule } from "./types";
33
+ import { formatProductToCartItem, createCartItemOrigin, getUniqueId, handleVariantProduct, formatDateToCartItem, formatAccountToCartItem } from "../../modules/Cart/utils";
33
34
  import { getAvailableProductResources } from "./utils/products";
34
35
  import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection, isConflict } from "./utils/resources";
35
36
  import dayjs from 'dayjs';
@@ -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
  };
@@ -3044,7 +3054,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3044
3054
  });
3045
3055
 
3046
3056
  // 按资源类型分组检查容量
3047
- if (!checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
3057
+ var _checkTimeSlotCapacit = checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot),
3058
+ success = _checkTimeSlotCapacit.success,
3059
+ required = _checkTimeSlotCapacit.required,
3060
+ available = _checkTimeSlotCapacit.available;
3061
+ if (!success) {
3048
3062
  // 如果有可用数量记录,返回最小值;否则返回 0
3049
3063
  var _minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
3050
3064
  return {
@@ -3069,6 +3083,437 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3069
3083
  minAvailableCount: minAvailableCount
3070
3084
  };
3071
3085
  }
3086
+
3087
+ /**
3088
+ * 将 ProductData 转换为 CartItem,但不添加到购物车
3089
+ * 参考 addProductToCart 方法的实现
3090
+ */
3091
+ }, {
3092
+ key: "convertProductToCartItem",
3093
+ value: function convertProductToCartItem(_ref11) {
3094
+ var product = _ref11.product,
3095
+ date = _ref11.date,
3096
+ account = _ref11.account;
3097
+ var _ref12 = product || {},
3098
+ bundle = _ref12.bundle,
3099
+ options = _ref12.options,
3100
+ origin = _ref12.origin,
3101
+ product_variant_id = _ref12.product_variant_id,
3102
+ _ref12$quantity = _ref12.quantity,
3103
+ quantity = _ref12$quantity === void 0 ? 1 : _ref12$quantity;
3104
+
3105
+ // 处理商品数据,类似 addProductToCart 中的逻辑
3106
+ var productData = _objectSpread(_objectSpread({}, origin), {}, {
3107
+ product_variant_id: product_variant_id
3108
+ });
3109
+
3110
+ // 处理组合商品
3111
+ var processedProduct = handleVariantProduct(productData);
3112
+
3113
+ // 如果没有传入账户,获取当前活跃账户
3114
+ if (!account) {
3115
+ var activeAccount = this.getActiveAccount();
3116
+ if (activeAccount) {
3117
+ account = activeAccount;
3118
+ }
3119
+ }
3120
+
3121
+ // 创建基础的 CartItem
3122
+ var cartItem = {
3123
+ _id: getUniqueId('temp_'),
3124
+ _origin: createCartItemOrigin(),
3125
+ _productOrigin: processedProduct,
3126
+ _productInit: product
3127
+ };
3128
+
3129
+ // 使用格式化函数填充 CartItem 数据
3130
+ formatProductToCartItem({
3131
+ cartItem: cartItem,
3132
+ product: processedProduct,
3133
+ bundle: bundle,
3134
+ options: options,
3135
+ product_variant_id: product_variant_id,
3136
+ quantity: quantity
3137
+ });
3138
+
3139
+ // 如果有日期信息,格式化日期到购物车
3140
+ if (date) {
3141
+ formatDateToCartItem({
3142
+ cartItem: cartItem,
3143
+ date: date
3144
+ });
3145
+ }
3146
+
3147
+ // 如果有账户信息,格式化账户到购物车
3148
+ if (account) {
3149
+ formatAccountToCartItem({
3150
+ cartItem: cartItem,
3151
+ account: account
3152
+ });
3153
+ }
3154
+ return cartItem;
3155
+ }
3156
+ }, {
3157
+ key: "checkMaxDurationCapacityForDetailNums",
3158
+ value: function checkMaxDurationCapacityForDetailNums(_ref13) {
3159
+ var _this16 = this;
3160
+ var product = _ref13.product,
3161
+ date = _ref13.date,
3162
+ account = _ref13.account;
3163
+ var cartItems = cloneDeep(this.store.cart.getItems());
3164
+
3165
+ // 将 ProductData 转换为 CartItem 但不真正添加到购物车
3166
+ var currentCartItem = this.convertProductToCartItem({
3167
+ product: product,
3168
+ date: date,
3169
+ account: account
3170
+ });
3171
+ cartItems.push(currentCartItem);
3172
+ if (cartItems.length === 0) return {
3173
+ success: true,
3174
+ minAvailableCount: 0
3175
+ };
3176
+
3177
+ // 将购物车商品分为有时间的和没有时间的
3178
+ var itemsWithTime = [];
3179
+ var itemsWithoutTime = [];
3180
+ // 记录每种资源类型的可用数量
3181
+ var availableCountsByResourceType = [];
3182
+ cartItems.forEach(function (cartItem) {
3183
+ if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
3184
+ itemsWithTime.push(cartItem);
3185
+ } else {
3186
+ itemsWithoutTime.push(cartItem);
3187
+ }
3188
+ });
3189
+
3190
+ // 处理没有时间的商品,为它们分配公共可用时间的第一个时间片
3191
+ var processedItemsWithoutTime = [];
3192
+ if (itemsWithoutTime.length > 0) {
3193
+ // 按资源类型分组处理没有时间的商品
3194
+ var itemsByResourceType = {};
3195
+ itemsWithoutTime.forEach(function (cartItem) {
3196
+ var _cartItem$_productOri13;
3197
+ if (!cartItem._productOrigin) return;
3198
+ var resourceTypes = ((_cartItem$_productOri13 = cartItem._productOrigin.product_resource) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.resources) || [];
3199
+ resourceTypes.forEach(function (resourceType) {
3200
+ if (resourceType.status === 1) {
3201
+ var _resourceType$id2;
3202
+ var resourceCode = resourceType.code || ((_resourceType$id2 = resourceType.id) === null || _resourceType$id2 === void 0 ? void 0 : _resourceType$id2.toString());
3203
+ if (!itemsByResourceType[resourceCode]) {
3204
+ itemsByResourceType[resourceCode] = [];
3205
+ }
3206
+ // 避免重复添加同一个商品
3207
+ if (!itemsByResourceType[resourceCode].find(function (item) {
3208
+ return item._id === cartItem._id;
3209
+ })) {
3210
+ itemsByResourceType[resourceCode].push(cartItem);
3211
+ }
3212
+ }
3213
+ });
3214
+ });
3215
+
3216
+ // 为每种资源类型检查容量
3217
+ var dateRange = this.store.date.getDateRange();
3218
+ if (!dateRange || dateRange.length === 0) return {
3219
+ success: false,
3220
+ minAvailableCount: 0
3221
+ };
3222
+ var resourcesDates = this.store.date.getDateList();
3223
+ var targetResourceDate = resourcesDates.find(function (n) {
3224
+ return n.date === dateRange[0].date;
3225
+ });
3226
+ if (!targetResourceDate) return {
3227
+ success: false,
3228
+ minAvailableCount: 0
3229
+ };
3230
+ var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
3231
+
3232
+ // 从购物车商品中获取资源类型配置,建立 resourceCode 到 form_id 的映射关系
3233
+ var resourceCodeToFormIdMap = {};
3234
+
3235
+ // 遍历购物车中的商品,收集所有资源类型配置
3236
+ Object.values(itemsByResourceType).flat().forEach(function (cartItem) {
3237
+ var _cartItem$_productOri14;
3238
+ if ((_cartItem$_productOri14 = cartItem._productOrigin) !== null && _cartItem$_productOri14 !== void 0 && (_cartItem$_productOri14 = _cartItem$_productOri14.product_resource) !== null && _cartItem$_productOri14 !== void 0 && _cartItem$_productOri14.resources) {
3239
+ cartItem._productOrigin.product_resource.resources.forEach(function (resourceConfig) {
3240
+ // 只处理启用的资源类型 (status === 1)
3241
+ if (resourceConfig.status === 1 && resourceConfig.code) {
3242
+ var _resourceConfig$id2, _resourceConfig$resou2;
3243
+ 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());
3244
+ if (formId) {
3245
+ resourceCodeToFormIdMap[resourceConfig.code] = formId;
3246
+ }
3247
+ }
3248
+ });
3249
+ }
3250
+ });
3251
+ var hasCapacityIssue = false;
3252
+ var resourceCapacityInfo = [];
3253
+
3254
+ // 用于跟踪已处理的商品,避免重复添加
3255
+ var processedCartItemIds = new Set();
3256
+
3257
+ // 先检查所有资源类型,收集可用数量信息
3258
+ var _loop5 = function _loop5() {
3259
+ var _resourceTypeConfig2;
3260
+ var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
3261
+ resourceCode = _Object$entries3$_i[0],
3262
+ items = _Object$entries3$_i[1];
3263
+ // 获取该资源类型对应的 form_id
3264
+ var targetFormId = resourceCodeToFormIdMap[resourceCode];
3265
+ if (!targetFormId) {
3266
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u627E\u4E0D\u5230\u5BF9\u5E94\u7684 form_id"));
3267
+ return {
3268
+ v: {
3269
+ success: false,
3270
+ minAvailableCount: 0
3271
+ }
3272
+ };
3273
+ }
3274
+
3275
+ // 获取该资源类型的所有资源
3276
+ var resourcesOfThisType = [];
3277
+ items.forEach(function (cartItem) {
3278
+ var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
3279
+ productResourceIds.forEach(function (resourceId) {
3280
+ var _resource$form_id2;
3281
+ var resource = resourcesMap[resourceId];
3282
+ if (resource && ((_resource$form_id2 = resource.form_id) === null || _resource$form_id2 === void 0 ? void 0 : _resource$form_id2.toString()) === targetFormId) {
3283
+ // 避免重复添加同一个资源
3284
+ if (!resourcesOfThisType.find(function (r) {
3285
+ return r.id === resource.id;
3286
+ })) {
3287
+ resourcesOfThisType.push(resource);
3288
+ }
3289
+ }
3290
+ });
3291
+ });
3292
+ if (resourcesOfThisType.length === 0) {
3293
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u627E\u5230\u53EF\u7528\u8D44\u6E90"));
3294
+ return {
3295
+ v: {
3296
+ success: false,
3297
+ minAvailableCount: 0
3298
+ }
3299
+ };
3300
+ }
3301
+
3302
+ // 检查资源类型(单个预约 vs 多个预约)
3303
+ // 从商品配置中获取资源类型信息
3304
+ var resourceTypeConfig = null;
3305
+ var _iterator4 = _createForOfIteratorHelper(items),
3306
+ _step4;
3307
+ try {
3308
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
3309
+ var _cartItem$_productOri15;
3310
+ var cartItem = _step4.value;
3311
+ if ((_cartItem$_productOri15 = cartItem._productOrigin) !== null && _cartItem$_productOri15 !== void 0 && (_cartItem$_productOri15 = _cartItem$_productOri15.product_resource) !== null && _cartItem$_productOri15 !== void 0 && _cartItem$_productOri15.resources) {
3312
+ resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
3313
+ return r.code === resourceCode && r.status === 1;
3314
+ });
3315
+ if (resourceTypeConfig) break;
3316
+ }
3317
+ }
3318
+ } catch (err) {
3319
+ _iterator4.e(err);
3320
+ } finally {
3321
+ _iterator4.f();
3322
+ }
3323
+ var isMultipleBooking = ((_resourceTypeConfig2 = resourceTypeConfig) === null || _resourceTypeConfig2 === void 0 ? void 0 : _resourceTypeConfig2.type) === 'multiple';
3324
+ var totalAvailable;
3325
+ var requiredAmount;
3326
+ var availableAmount;
3327
+ if (isMultipleBooking) {
3328
+ // 多个预约:计算容量
3329
+ totalAvailable = resourcesOfThisType.reduce(function (sum, resource) {
3330
+ return sum + (resource.capacity || 0);
3331
+ }, 0);
3332
+ requiredAmount = items.reduce(function (sum, cartItem) {
3333
+ var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
3334
+ currentCapacity = _getCapacityInfoByCar8.currentCapacity;
3335
+ return sum + currentCapacity;
3336
+ }, 0);
3337
+ availableAmount = Math.max(0, totalAvailable - requiredAmount);
3338
+ } else {
3339
+ // 单个预约:计算资源个数
3340
+ totalAvailable = resourcesOfThisType.length;
3341
+ requiredAmount = items.reduce(function (sum, cartItem) {
3342
+ return sum + (cartItem.num || 1);
3343
+ }, 0);
3344
+ availableAmount = Math.max(0, totalAvailable - requiredAmount);
3345
+ }
3346
+
3347
+ // 记录资源容量信息
3348
+ resourceCapacityInfo.push({
3349
+ code: resourceCode,
3350
+ available: availableAmount,
3351
+ total: totalAvailable,
3352
+ required: requiredAmount,
3353
+ isMultiple: isMultipleBooking
3354
+ });
3355
+ availableCountsByResourceType.push(availableAmount);
3356
+
3357
+ // 检查是否有容量问题
3358
+ if (requiredAmount > totalAvailable) {
3359
+ hasCapacityIssue = true;
3360
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " ").concat(isMultipleBooking ? '容量' : '资源数量', "\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredAmount, ", \u603B\u5171 ").concat(totalAvailable));
3361
+ }
3362
+
3363
+ // 为通过检测的商品分配一个公共可用时间段
3364
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u8D44\u6E90\u65F6\u95F4\u4FE1\u606F:"), resourcesOfThisType.map(function (r) {
3365
+ return {
3366
+ id: r.id,
3367
+ times: r.times.map(function (t) {
3368
+ return "".concat(t.start_at, " - ").concat(t.end_at);
3369
+ })
3370
+ };
3371
+ }));
3372
+
3373
+ // 找到所有资源都可用的时间段
3374
+ var commonTimeSlots = _this16.findCommonAvailableTimeSlots(resourcesOfThisType);
3375
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonTimeSlots);
3376
+ if (commonTimeSlots.length === 0) {
3377
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4\u6BB5"));
3378
+ return {
3379
+ v: {
3380
+ success: false,
3381
+ minAvailableCount: 0
3382
+ }
3383
+ };
3384
+ }
3385
+
3386
+ // 使用第一个公共可用时间段,但只处理未处理过的商品
3387
+ var firstCommonSlot = commonTimeSlots[0];
3388
+ console.log("\u4F7F\u7528\u516C\u5171\u65F6\u95F4\u6BB5: ".concat(firstCommonSlot.startTime, " - ").concat(firstCommonSlot.endTime));
3389
+ items.forEach(function (cartItem) {
3390
+ // 只处理未处理过的商品,避免重复添加
3391
+ if (!processedCartItemIds.has(cartItem._id)) {
3392
+ processedCartItemIds.add(cartItem._id);
3393
+ var processedItem = _objectSpread(_objectSpread({}, cartItem), {}, {
3394
+ start_date: dateRange[0].date,
3395
+ start_time: firstCommonSlot.startTime,
3396
+ end_time: firstCommonSlot.endTime,
3397
+ end_date: dateRange[0].date
3398
+ });
3399
+ processedItemsWithoutTime.push(processedItem);
3400
+ }
3401
+ });
3402
+ },
3403
+ _ret5;
3404
+ for (var _i3 = 0, _Object$entries3 = Object.entries(itemsByResourceType); _i3 < _Object$entries3.length; _i3++) {
3405
+ _ret5 = _loop5();
3406
+ if (_ret5) return _ret5.v;
3407
+ }
3408
+
3409
+ // 如果有容量问题,找出限制最严格的资源类型,返回其总容量
3410
+ if (hasCapacityIssue) {
3411
+ // 找出超出容量的资源类型中,总容量最少的那个
3412
+ var overCapacityResources = resourceCapacityInfo.filter(function (info) {
3413
+ return info.required > info.total;
3414
+ });
3415
+ if (overCapacityResources.length > 0) {
3416
+ var _minTotalCapacity2 = Math.min.apply(Math, _toConsumableArray(overCapacityResources.map(function (info) {
3417
+ return info.total;
3418
+ })));
3419
+ return {
3420
+ success: false,
3421
+ minAvailableCount: _minTotalCapacity2
3422
+ };
3423
+ }
3424
+ // 如果没有超出容量的(理论上不应该发生),返回总容量最少的
3425
+ var minTotalCapacity = Math.min.apply(Math, _toConsumableArray(resourceCapacityInfo.map(function (info) {
3426
+ return info.total;
3427
+ })));
3428
+ return {
3429
+ success: false,
3430
+ minAvailableCount: minTotalCapacity
3431
+ };
3432
+ }
3433
+ }
3434
+
3435
+ // 合并所有商品(有时间的 + 处理后的没有时间的)
3436
+ var allProcessedItems = [].concat(itemsWithTime, processedItemsWithoutTime);
3437
+
3438
+ // 按时间段分组检查
3439
+ var cartItemsByTimeSlot = {};
3440
+ allProcessedItems.forEach(function (cartItem) {
3441
+ if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date) return;
3442
+ var timeSlotKey = "".concat(cartItem.start_date, "_").concat(cartItem.start_time, "_").concat(cartItem.end_date || cartItem.start_date, "_").concat(cartItem.end_time);
3443
+ if (!cartItemsByTimeSlot[timeSlotKey]) {
3444
+ cartItemsByTimeSlot[timeSlotKey] = [];
3445
+ }
3446
+ cartItemsByTimeSlot[timeSlotKey].push(cartItem);
3447
+ });
3448
+ // 检查每个时间段是否有足够的资源容量
3449
+ var _loop6 = function _loop6() {
3450
+ var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
3451
+ timeSlotKey = _Object$entries4$_i[0],
3452
+ itemsInTimeSlot = _Object$entries4$_i[1];
3453
+ var _timeSlotKey$split3 = timeSlotKey.split('_'),
3454
+ _timeSlotKey$split4 = _slicedToArray(_timeSlotKey$split3, 4),
3455
+ startDate = _timeSlotKey$split4[0],
3456
+ startTime = _timeSlotKey$split4[1],
3457
+ endDate = _timeSlotKey$split4[2],
3458
+ endTime = _timeSlotKey$split4[3];
3459
+ var timeSlotStart = "".concat(startDate, " ").concat(startTime);
3460
+ var timeSlotEnd = "".concat(endDate, " ").concat(endTime);
3461
+
3462
+ // 获取这个时间段所有商品涉及的资源
3463
+ var allResourcesForTimeSlot = [];
3464
+ var resourcesIdSet = new Set();
3465
+
3466
+ // 获取资源数据
3467
+ // const dateRange = this.store.date.getDateRange();
3468
+ var resourcesDates = _this16.store.date.getDateList();
3469
+ var targetResourceDate = resourcesDates.find(function (n) {
3470
+ return n.date === startDate;
3471
+ });
3472
+ if (!targetResourceDate) return 0; // continue
3473
+ var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
3474
+ itemsInTimeSlot.forEach(function (cartItem) {
3475
+ if (!cartItem._productOrigin) return;
3476
+
3477
+ // 获取商品的资源配置
3478
+ var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
3479
+ productResourceIds.forEach(function (resourceId) {
3480
+ if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
3481
+ resourcesIdSet.add(resourceId);
3482
+ allResourcesForTimeSlot.push(resourcesMap[resourceId]);
3483
+ }
3484
+ });
3485
+ });
3486
+
3487
+ // 按资源类型分组检查容量
3488
+ var _checkTimeSlotCapacit2 = checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot),
3489
+ success = _checkTimeSlotCapacit2.success,
3490
+ required = _checkTimeSlotCapacit2.required,
3491
+ available = _checkTimeSlotCapacit2.available;
3492
+ if (!success) {
3493
+ // 如果有可用数量记录,返回最小值;否则返回 0
3494
+ // const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
3495
+ return {
3496
+ v: {
3497
+ success: false,
3498
+ minAvailableCount: available
3499
+ }
3500
+ };
3501
+ }
3502
+ },
3503
+ _ret6;
3504
+ for (var _i4 = 0, _Object$entries4 = Object.entries(cartItemsByTimeSlot); _i4 < _Object$entries4.length; _i4++) {
3505
+ _ret6 = _loop6();
3506
+ if (_ret6 === 0) continue;
3507
+ if (_ret6) return _ret6.v;
3508
+ }
3509
+
3510
+ // 全部通过检测,返回成功和最小可用数量
3511
+ var minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
3512
+ return {
3513
+ success: true,
3514
+ minAvailableCount: minAvailableCount
3515
+ };
3516
+ }
3072
3517
  }, {
3073
3518
  key: "setOtherData",
3074
3519
  value: function setOtherData(key, value) {
@@ -3140,7 +3585,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3140
3585
  }, {
3141
3586
  key: "getResourcesByCartItemAndCode",
3142
3587
  value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
3143
- var _cartItem$_productOri13;
3588
+ var _cartItem$_productOri16;
3144
3589
  var dateRange = this.store.date.getDateRange();
3145
3590
  var resources = [];
3146
3591
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -3163,16 +3608,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3163
3608
  });
3164
3609
  if (!cartItem) return [];
3165
3610
  var selectedResources = [];
3166
- var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
3167
- currentCapacity = _getCapacityInfoByCar8.currentCapacity,
3168
- formatCapacity = _getCapacityInfoByCar8.formatCapacity;
3611
+ var _getCapacityInfoByCar9 = getCapacityInfoByCartItem(cartItem),
3612
+ currentCapacity = _getCapacityInfoByCar9.currentCapacity,
3613
+ formatCapacity = _getCapacityInfoByCar9.formatCapacity;
3169
3614
  cartItem._origin.metadata.capacity = formatCapacity;
3170
3615
  if (cartItem.holder_id) {
3171
3616
  selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
3172
3617
  } else {
3173
3618
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
3174
3619
  }
3175
- 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);
3620
+ 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);
3176
3621
  var targetResource = productResources.find(function (resource) {
3177
3622
  return resource.code === resourceCode;
3178
3623
  });
@@ -3195,7 +3640,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3195
3640
  });
3196
3641
  if (mTimes.length === 0) return false;
3197
3642
  var canUseArr = mTimes.map(function (item) {
3198
- var _cartItem$_productOri14;
3643
+ var _cartItem$_productOri17;
3199
3644
  var res = getIsUsableByTimeItem({
3200
3645
  timeSlice: {
3201
3646
  start_time: startTime.format('HH:mm'),
@@ -3207,7 +3652,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3207
3652
  resource: m,
3208
3653
  currentCount: currentCapacity || 0,
3209
3654
  resourcesUseableMap: resourcesUseableMap,
3210
- cut_off_time: (_cartItem$_productOri14 = cartItem._productOrigin) === null || _cartItem$_productOri14 === void 0 ? void 0 : _cartItem$_productOri14.cut_off_time
3655
+ cut_off_time: (_cartItem$_productOri17 = cartItem._productOrigin) === null || _cartItem$_productOri17 === void 0 ? void 0 : _cartItem$_productOri17.cut_off_time
3211
3656
  });
3212
3657
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
3213
3658
  resourcesUseableMap[m.id] = res.usable;
@@ -3221,12 +3666,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3221
3666
  });
3222
3667
  } else {
3223
3668
  targetResource.renderList = targetResource.renderList.filter(function (n) {
3224
- var _cartItem$_productOri15;
3669
+ var _cartItem$_productOri18;
3225
3670
  var recordCount = n.capacity || 0;
3226
3671
  if (n.onlyComputed) return false;
3227
3672
  var timeSlots = getTimeSlicesByResource({
3228
3673
  resource: n,
3229
- 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,
3674
+ 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,
3230
3675
  split: 10,
3231
3676
  currentDate: dateRange[0].date
3232
3677
  });
@@ -3244,12 +3689,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3244
3689
  }, {
3245
3690
  key: "getTimeslotsScheduleByDateRange",
3246
3691
  value: (function () {
3247
- var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref11) {
3248
- var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i3, _dates, date;
3692
+ var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref14) {
3693
+ var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i5, _dates, date;
3249
3694
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3250
3695
  while (1) switch (_context26.prev = _context26.next) {
3251
3696
  case 0:
3252
- startDate = _ref11.startDate, endDate = _ref11.endDate, scheduleIds = _ref11.scheduleIds, resources = _ref11.resources;
3697
+ startDate = _ref14.startDate, endDate = _ref14.endDate, scheduleIds = _ref14.scheduleIds, resources = _ref14.resources;
3253
3698
  console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
3254
3699
  startDate: startDate,
3255
3700
  endDate: endDate,
@@ -3266,8 +3711,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3266
3711
  }
3267
3712
  // 如果不支持 Web Worker,使用同步方式处理
3268
3713
  results = {};
3269
- for (_i3 = 0, _dates = dates; _i3 < _dates.length; _i3++) {
3270
- date = _dates[_i3];
3714
+ for (_i5 = 0, _dates = dates; _i5 < _dates.length; _i5++) {
3715
+ date = _dates[_i5];
3271
3716
  results[date] = this.getTimeslotBySchedule({
3272
3717
  date: date,
3273
3718
  scheduleIds: scheduleIds,
@@ -3308,7 +3753,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3308
3753
  openResources,
3309
3754
  allProductResources,
3310
3755
  targetSchedules,
3311
- _loop5,
3756
+ _loop7,
3312
3757
  _args28 = arguments;
3313
3758
  return _regeneratorRuntime().wrap(function _callee27$(_context28) {
3314
3759
  while (1) switch (_context28.prev = _context28.next) {
@@ -3385,9 +3830,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3385
3830
  }
3386
3831
  });
3387
3832
  targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
3388
- _loop5 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop5() {
3833
+ _loop7 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop7() {
3389
3834
  var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
3390
- return _regeneratorRuntime().wrap(function _loop5$(_context27) {
3835
+ return _regeneratorRuntime().wrap(function _loop7$(_context27) {
3391
3836
  while (1) switch (_context27.prev = _context27.next) {
3392
3837
  case 0:
3393
3838
  currentDateStr = currentDate.format('YYYY-MM-DD');
@@ -3490,14 +3935,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3490
3935
  case "end":
3491
3936
  return _context27.stop();
3492
3937
  }
3493
- }, _loop5);
3938
+ }, _loop7);
3494
3939
  });
3495
3940
  case 28:
3496
3941
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
3497
3942
  _context28.next = 34;
3498
3943
  break;
3499
3944
  }
3500
- return _context28.delegateYield(_loop5(), "t0", 30);
3945
+ return _context28.delegateYield(_loop7(), "t0", 30);
3501
3946
  case 30:
3502
3947
  if (!_context28.t0) {
3503
3948
  _context28.next = 32;
@@ -15,8 +15,9 @@ export declare const formatDefaultCapacitys: ({ capacity, product_bundle, }: any
15
15
  * @return {*}
16
16
  * @Author: zhiwei.Wang
17
17
  */
18
- export declare const getSumCapacity: ({ capacity }: {
18
+ export declare const getSumCapacity: ({ capacity, num }: {
19
19
  capacity: CapacityItem[];
20
+ num: number;
20
21
  }) => number;
21
22
  /**
22
23
  * 给定购物车数据,返回对应的 capacity 信息和套餐 capacity
@@ -67,4 +68,8 @@ export declare function getResourcesIdsByProduct(product: any): number[];
67
68
  /**
68
69
  * 检查特定时间段的容量是否足够
69
70
  */
70
- export declare function checkTimeSlotCapacity(timeSlotStart: string, timeSlotEnd: string, cartItems: CartItem[], allResources: ResourceItem[]): boolean;
71
+ export declare function checkTimeSlotCapacity(timeSlotStart: string, timeSlotEnd: string, cartItems: CartItem[], allResources: ResourceItem[]): {
72
+ success: boolean;
73
+ required: number;
74
+ available: number;
75
+ };