@pisell/pisellos 3.0.66 → 3.0.68

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,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)) {
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
  };
@@ -2668,41 +2678,35 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2668
2678
 
2669
2679
  // 与其他资源的时间段求交集
2670
2680
  var _loop2 = function _loop2() {
2671
- var currentResourceSlots = allTimeSlots[i];
2672
- var intersections = [];
2673
-
2674
- // 计算当前公共时间段与下一个资源时间段的交集
2675
- commonSlots.forEach(function (commonSlot) {
2676
- currentResourceSlots.forEach(function (currentSlot) {
2677
- var overlapStart = commonSlot.start.isAfter(currentSlot.start) ? commonSlot.start : currentSlot.start;
2678
- var overlapEnd = commonSlot.end.isBefore(currentSlot.end) ? commonSlot.end : currentSlot.end;
2679
-
2680
- // 如果有重叠时间且重叠时间大于0
2681
- if (overlapStart.isBefore(overlapEnd)) {
2682
- intersections.push({
2683
- start: overlapStart,
2684
- end: overlapEnd
2685
- });
2686
- }
2687
- });
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
+ }
2688
2697
  });
2689
- commonSlots = intersections;
2690
- console.log("\u4E0E\u8D44\u6E90".concat(i, "\u6C42\u4EA4\u96C6\u540E\u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonSlots.map(function (slot) {
2691
- return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
2692
- }));
2693
-
2694
- // 如果没有公共时间段,直接返回
2695
- if (commonSlots.length === 0) {
2696
- console.log('没有找到公共时间段');
2697
- return {
2698
- v: []
2699
- };
2700
- }
2701
- },
2702
- _ret2;
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
+ };
2703
2708
  for (var i = 1; i < allTimeSlots.length; i++) {
2704
- _ret2 = _loop2();
2705
- if (_ret2) return _ret2.v;
2709
+ if (_loop2()) continue;
2706
2710
  }
2707
2711
 
2708
2712
  // 格式化返回结果
@@ -2719,7 +2723,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2719
2723
  key: "checkMaxDurationCapacity",
2720
2724
  value: function checkMaxDurationCapacity() {
2721
2725
  var _this15 = this;
2722
- var cartItems = cloneDeep(this.store.cart.getItems());
2726
+ var cartItems = this.store.cart.getItems().filter(function (item) {
2727
+ return !isNormalProduct(item._productOrigin);
2728
+ });
2723
2729
  if (cartItems.length === 0) return {
2724
2730
  success: true,
2725
2731
  minAvailableCount: 0
@@ -2951,10 +2957,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2951
2957
  }
2952
2958
  });
2953
2959
  },
2954
- _ret3;
2960
+ _ret2;
2955
2961
  for (var _i = 0, _Object$entries = Object.entries(itemsByResourceType); _i < _Object$entries.length; _i++) {
2956
- _ret3 = _loop3();
2957
- if (_ret3) return _ret3.v;
2962
+ _ret2 = _loop3();
2963
+ if (_ret2) return _ret2.v;
2958
2964
  }
2959
2965
 
2960
2966
  // 如果有容量问题,找出限制最严格的资源类型,返回其总容量
@@ -3036,7 +3042,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3036
3042
  });
3037
3043
 
3038
3044
  // 按资源类型分组检查容量
3039
- if (!checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
3045
+ var _checkTimeSlotCapacit = checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot),
3046
+ success = _checkTimeSlotCapacit.success,
3047
+ required = _checkTimeSlotCapacit.required,
3048
+ available = _checkTimeSlotCapacit.available;
3049
+ if (!success) {
3040
3050
  // 如果有可用数量记录,返回最小值;否则返回 0
3041
3051
  var _minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
3042
3052
  return {
@@ -3047,11 +3057,444 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3047
3057
  };
3048
3058
  }
3049
3059
  },
3050
- _ret4;
3060
+ _ret3;
3051
3061
  for (var _i2 = 0, _Object$entries2 = Object.entries(cartItemsByTimeSlot); _i2 < _Object$entries2.length; _i2++) {
3052
- _ret4 = _loop4();
3053
- if (_ret4 === 0) continue;
3054
- if (_ret4) return _ret4.v;
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;
3055
3498
  }
3056
3499
 
3057
3500
  // 全部通过检测,返回成功和最小可用数量
@@ -3132,7 +3575,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3132
3575
  }, {
3133
3576
  key: "getResourcesByCartItemAndCode",
3134
3577
  value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
3135
- var _cartItem$_productOri13;
3578
+ var _cartItem$_productOri16;
3136
3579
  var dateRange = this.store.date.getDateRange();
3137
3580
  var resources = [];
3138
3581
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -3155,16 +3598,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3155
3598
  });
3156
3599
  if (!cartItem) return [];
3157
3600
  var selectedResources = [];
3158
- var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
3159
- currentCapacity = _getCapacityInfoByCar8.currentCapacity,
3160
- formatCapacity = _getCapacityInfoByCar8.formatCapacity;
3601
+ var _getCapacityInfoByCar9 = getCapacityInfoByCartItem(cartItem),
3602
+ currentCapacity = _getCapacityInfoByCar9.currentCapacity,
3603
+ formatCapacity = _getCapacityInfoByCar9.formatCapacity;
3161
3604
  cartItem._origin.metadata.capacity = formatCapacity;
3162
3605
  if (cartItem.holder_id) {
3163
3606
  selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
3164
3607
  } else {
3165
3608
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
3166
3609
  }
3167
- 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);
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);
3168
3611
  var targetResource = productResources.find(function (resource) {
3169
3612
  return resource.code === resourceCode;
3170
3613
  });
@@ -3187,7 +3630,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3187
3630
  });
3188
3631
  if (mTimes.length === 0) return false;
3189
3632
  var canUseArr = mTimes.map(function (item) {
3190
- var _cartItem$_productOri14;
3633
+ var _cartItem$_productOri17;
3191
3634
  var res = getIsUsableByTimeItem({
3192
3635
  timeSlice: {
3193
3636
  start_time: startTime.format('HH:mm'),
@@ -3199,7 +3642,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3199
3642
  resource: m,
3200
3643
  currentCount: currentCapacity || 0,
3201
3644
  resourcesUseableMap: resourcesUseableMap,
3202
- cut_off_time: (_cartItem$_productOri14 = cartItem._productOrigin) === null || _cartItem$_productOri14 === void 0 ? void 0 : _cartItem$_productOri14.cut_off_time
3645
+ cut_off_time: (_cartItem$_productOri17 = cartItem._productOrigin) === null || _cartItem$_productOri17 === void 0 ? void 0 : _cartItem$_productOri17.cut_off_time
3203
3646
  });
3204
3647
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
3205
3648
  resourcesUseableMap[m.id] = res.usable;
@@ -3213,12 +3656,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3213
3656
  });
3214
3657
  } else {
3215
3658
  targetResource.renderList = targetResource.renderList.filter(function (n) {
3216
- var _cartItem$_productOri15;
3659
+ var _cartItem$_productOri18;
3217
3660
  var recordCount = n.capacity || 0;
3218
3661
  if (n.onlyComputed) return false;
3219
3662
  var timeSlots = getTimeSlicesByResource({
3220
3663
  resource: n,
3221
- 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,
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,
3222
3665
  split: 10,
3223
3666
  currentDate: dateRange[0].date
3224
3667
  });
@@ -3236,12 +3679,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3236
3679
  }, {
3237
3680
  key: "getTimeslotsScheduleByDateRange",
3238
3681
  value: (function () {
3239
- var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref11) {
3240
- var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i3, _dates, date;
3682
+ var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref14) {
3683
+ var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i5, _dates, date;
3241
3684
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3242
3685
  while (1) switch (_context26.prev = _context26.next) {
3243
3686
  case 0:
3244
- startDate = _ref11.startDate, endDate = _ref11.endDate, scheduleIds = _ref11.scheduleIds, resources = _ref11.resources;
3687
+ startDate = _ref14.startDate, endDate = _ref14.endDate, scheduleIds = _ref14.scheduleIds, resources = _ref14.resources;
3245
3688
  console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
3246
3689
  startDate: startDate,
3247
3690
  endDate: endDate,
@@ -3258,8 +3701,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3258
3701
  }
3259
3702
  // 如果不支持 Web Worker,使用同步方式处理
3260
3703
  results = {};
3261
- for (_i3 = 0, _dates = dates; _i3 < _dates.length; _i3++) {
3262
- date = _dates[_i3];
3704
+ for (_i5 = 0, _dates = dates; _i5 < _dates.length; _i5++) {
3705
+ date = _dates[_i5];
3263
3706
  results[date] = this.getTimeslotBySchedule({
3264
3707
  date: date,
3265
3708
  scheduleIds: scheduleIds,
@@ -3300,7 +3743,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3300
3743
  openResources,
3301
3744
  allProductResources,
3302
3745
  targetSchedules,
3303
- _loop5,
3746
+ _loop7,
3304
3747
  _args28 = arguments;
3305
3748
  return _regeneratorRuntime().wrap(function _callee27$(_context28) {
3306
3749
  while (1) switch (_context28.prev = _context28.next) {
@@ -3377,9 +3820,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3377
3820
  }
3378
3821
  });
3379
3822
  targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
3380
- _loop5 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop5() {
3823
+ _loop7 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop7() {
3381
3824
  var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
3382
- return _regeneratorRuntime().wrap(function _loop5$(_context27) {
3825
+ return _regeneratorRuntime().wrap(function _loop7$(_context27) {
3383
3826
  while (1) switch (_context27.prev = _context27.next) {
3384
3827
  case 0:
3385
3828
  currentDateStr = currentDate.format('YYYY-MM-DD');
@@ -3482,14 +3925,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3482
3925
  case "end":
3483
3926
  return _context27.stop();
3484
3927
  }
3485
- }, _loop5);
3928
+ }, _loop7);
3486
3929
  });
3487
3930
  case 28:
3488
3931
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
3489
3932
  _context28.next = 34;
3490
3933
  break;
3491
3934
  }
3492
- return _context28.delegateYield(_loop5(), "t0", 30);
3935
+ return _context28.delegateYield(_loop7(), "t0", 30);
3493
3936
  case 30:
3494
3937
  if (!_context28.t0) {
3495
3938
  _context28.next = 32;