@pisell/pisellos 0.0.329 → 0.0.330

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.
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "normal" | "duration" | "session";
52
+ getProductType(): "duration" | "session" | "normal";
53
53
  }
@@ -324,6 +324,15 @@ 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(currentProduct: ProductData): {
333
+ success: boolean;
334
+ minAvailableCount: number;
335
+ };
327
336
  setOtherData(key: string, value: any): void;
328
337
  getOtherData(key: string): any;
329
338
  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 { createModule } from "./types";
33
+ import { formatProductToCartItem, createCartItemOrigin, getUniqueId, handleVariantProduct } 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';
@@ -3072,6 +3073,402 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3072
3073
  minAvailableCount: minAvailableCount
3073
3074
  };
3074
3075
  }
3076
+
3077
+ /**
3078
+ * 将 ProductData 转换为 CartItem,但不添加到购物车
3079
+ * 参考 addProductToCart 方法的实现
3080
+ */
3081
+ }, {
3082
+ key: "convertProductToCartItem",
3083
+ value: function convertProductToCartItem(product) {
3084
+ var _ref11 = product || {},
3085
+ bundle = _ref11.bundle,
3086
+ options = _ref11.options,
3087
+ origin = _ref11.origin,
3088
+ product_variant_id = _ref11.product_variant_id,
3089
+ _ref11$quantity = _ref11.quantity,
3090
+ quantity = _ref11$quantity === void 0 ? 1 : _ref11$quantity;
3091
+
3092
+ // 处理商品数据,类似 addProductToCart 中的逻辑
3093
+ var productData = _objectSpread(_objectSpread({}, origin), {}, {
3094
+ product_variant_id: product_variant_id
3095
+ });
3096
+
3097
+ // 处理组合商品
3098
+ var processedProduct = handleVariantProduct(productData);
3099
+
3100
+ // 创建基础的 CartItem
3101
+ var cartItem = {
3102
+ _id: getUniqueId('temp_'),
3103
+ _origin: createCartItemOrigin(),
3104
+ _productOrigin: processedProduct,
3105
+ _productInit: product
3106
+ };
3107
+
3108
+ // 获取当前活跃账户
3109
+ var activeAccount = this.getActiveAccount();
3110
+
3111
+ // 使用格式化函数填充 CartItem 数据
3112
+ formatProductToCartItem({
3113
+ cartItem: cartItem,
3114
+ product: processedProduct,
3115
+ bundle: bundle,
3116
+ options: options,
3117
+ product_variant_id: product_variant_id,
3118
+ quantity: quantity
3119
+ });
3120
+ return cartItem;
3121
+ }
3122
+ }, {
3123
+ key: "checkMaxDurationCapacityForDetailNums",
3124
+ value: function checkMaxDurationCapacityForDetailNums(currentProduct) {
3125
+ var _this16 = this;
3126
+ var cartItems = cloneDeep(this.store.cart.getItems());
3127
+
3128
+ // 将 ProductData 转换为 CartItem 但不真正添加到购物车
3129
+ var currentCartItem = this.convertProductToCartItem(currentProduct);
3130
+ cartItems.push(currentCartItem);
3131
+ if (cartItems.length === 0) return {
3132
+ success: true,
3133
+ minAvailableCount: 0
3134
+ };
3135
+
3136
+ // 将购物车商品分为有时间的和没有时间的
3137
+ var itemsWithTime = [];
3138
+ var itemsWithoutTime = [];
3139
+ // 记录每种资源类型的可用数量
3140
+ var availableCountsByResourceType = [];
3141
+ cartItems.forEach(function (cartItem) {
3142
+ if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
3143
+ itemsWithTime.push(cartItem);
3144
+ } else {
3145
+ itemsWithoutTime.push(cartItem);
3146
+ }
3147
+ });
3148
+
3149
+ // 处理没有时间的商品,为它们分配公共可用时间的第一个时间片
3150
+ var processedItemsWithoutTime = [];
3151
+ if (itemsWithoutTime.length > 0) {
3152
+ // 按资源类型分组处理没有时间的商品
3153
+ var itemsByResourceType = {};
3154
+ itemsWithoutTime.forEach(function (cartItem) {
3155
+ var _cartItem$_productOri13;
3156
+ if (!cartItem._productOrigin) return;
3157
+ var resourceTypes = ((_cartItem$_productOri13 = cartItem._productOrigin.product_resource) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.resources) || [];
3158
+ resourceTypes.forEach(function (resourceType) {
3159
+ if (resourceType.status === 1) {
3160
+ var _resourceType$id2;
3161
+ var resourceCode = resourceType.code || ((_resourceType$id2 = resourceType.id) === null || _resourceType$id2 === void 0 ? void 0 : _resourceType$id2.toString());
3162
+ if (!itemsByResourceType[resourceCode]) {
3163
+ itemsByResourceType[resourceCode] = [];
3164
+ }
3165
+ // 避免重复添加同一个商品
3166
+ if (!itemsByResourceType[resourceCode].find(function (item) {
3167
+ return item._id === cartItem._id;
3168
+ })) {
3169
+ itemsByResourceType[resourceCode].push(cartItem);
3170
+ }
3171
+ }
3172
+ });
3173
+ });
3174
+
3175
+ // 为每种资源类型检查容量
3176
+ var dateRange = this.store.date.getDateRange();
3177
+ if (!dateRange || dateRange.length === 0) return {
3178
+ success: false,
3179
+ minAvailableCount: 0
3180
+ };
3181
+ var resourcesDates = this.store.date.getDateList();
3182
+ var targetResourceDate = resourcesDates.find(function (n) {
3183
+ return n.date === dateRange[0].date;
3184
+ });
3185
+ if (!targetResourceDate) return {
3186
+ success: false,
3187
+ minAvailableCount: 0
3188
+ };
3189
+ var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
3190
+
3191
+ // 从购物车商品中获取资源类型配置,建立 resourceCode 到 form_id 的映射关系
3192
+ var resourceCodeToFormIdMap = {};
3193
+
3194
+ // 遍历购物车中的商品,收集所有资源类型配置
3195
+ Object.values(itemsByResourceType).flat().forEach(function (cartItem) {
3196
+ var _cartItem$_productOri14;
3197
+ if ((_cartItem$_productOri14 = cartItem._productOrigin) !== null && _cartItem$_productOri14 !== void 0 && (_cartItem$_productOri14 = _cartItem$_productOri14.product_resource) !== null && _cartItem$_productOri14 !== void 0 && _cartItem$_productOri14.resources) {
3198
+ cartItem._productOrigin.product_resource.resources.forEach(function (resourceConfig) {
3199
+ // 只处理启用的资源类型 (status === 1)
3200
+ if (resourceConfig.status === 1 && resourceConfig.code) {
3201
+ var _resourceConfig$id2, _resourceConfig$resou2;
3202
+ 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());
3203
+ if (formId) {
3204
+ resourceCodeToFormIdMap[resourceConfig.code] = formId;
3205
+ }
3206
+ }
3207
+ });
3208
+ }
3209
+ });
3210
+ var hasCapacityIssue = false;
3211
+ var resourceCapacityInfo = [];
3212
+
3213
+ // 用于跟踪已处理的商品,避免重复添加
3214
+ var processedCartItemIds = new Set();
3215
+
3216
+ // 先检查所有资源类型,收集可用数量信息
3217
+ var _loop5 = function _loop5() {
3218
+ var _resourceTypeConfig2;
3219
+ var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
3220
+ resourceCode = _Object$entries3$_i[0],
3221
+ items = _Object$entries3$_i[1];
3222
+ // 获取该资源类型对应的 form_id
3223
+ var targetFormId = resourceCodeToFormIdMap[resourceCode];
3224
+ if (!targetFormId) {
3225
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u627E\u4E0D\u5230\u5BF9\u5E94\u7684 form_id"));
3226
+ return {
3227
+ v: {
3228
+ success: false,
3229
+ minAvailableCount: 0
3230
+ }
3231
+ };
3232
+ }
3233
+
3234
+ // 获取该资源类型的所有资源
3235
+ var resourcesOfThisType = [];
3236
+ items.forEach(function (cartItem) {
3237
+ var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
3238
+ productResourceIds.forEach(function (resourceId) {
3239
+ var _resource$form_id2;
3240
+ var resource = resourcesMap[resourceId];
3241
+ if (resource && ((_resource$form_id2 = resource.form_id) === null || _resource$form_id2 === void 0 ? void 0 : _resource$form_id2.toString()) === targetFormId) {
3242
+ // 避免重复添加同一个资源
3243
+ if (!resourcesOfThisType.find(function (r) {
3244
+ return r.id === resource.id;
3245
+ })) {
3246
+ resourcesOfThisType.push(resource);
3247
+ }
3248
+ }
3249
+ });
3250
+ });
3251
+ if (resourcesOfThisType.length === 0) {
3252
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u627E\u5230\u53EF\u7528\u8D44\u6E90"));
3253
+ return {
3254
+ v: {
3255
+ success: false,
3256
+ minAvailableCount: 0
3257
+ }
3258
+ };
3259
+ }
3260
+
3261
+ // 检查资源类型(单个预约 vs 多个预约)
3262
+ // 从商品配置中获取资源类型信息
3263
+ var resourceTypeConfig = null;
3264
+ var _iterator4 = _createForOfIteratorHelper(items),
3265
+ _step4;
3266
+ try {
3267
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
3268
+ var _cartItem$_productOri15;
3269
+ var cartItem = _step4.value;
3270
+ if ((_cartItem$_productOri15 = cartItem._productOrigin) !== null && _cartItem$_productOri15 !== void 0 && (_cartItem$_productOri15 = _cartItem$_productOri15.product_resource) !== null && _cartItem$_productOri15 !== void 0 && _cartItem$_productOri15.resources) {
3271
+ resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
3272
+ return r.code === resourceCode && r.status === 1;
3273
+ });
3274
+ if (resourceTypeConfig) break;
3275
+ }
3276
+ }
3277
+ } catch (err) {
3278
+ _iterator4.e(err);
3279
+ } finally {
3280
+ _iterator4.f();
3281
+ }
3282
+ var isMultipleBooking = ((_resourceTypeConfig2 = resourceTypeConfig) === null || _resourceTypeConfig2 === void 0 ? void 0 : _resourceTypeConfig2.type) === 'multiple';
3283
+ var totalAvailable;
3284
+ var requiredAmount;
3285
+ var availableAmount;
3286
+ if (isMultipleBooking) {
3287
+ // 多个预约:计算容量
3288
+ totalAvailable = resourcesOfThisType.reduce(function (sum, resource) {
3289
+ return sum + (resource.capacity || 0);
3290
+ }, 0);
3291
+ requiredAmount = items.reduce(function (sum, cartItem) {
3292
+ var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
3293
+ currentCapacity = _getCapacityInfoByCar8.currentCapacity;
3294
+ return sum + currentCapacity;
3295
+ }, 0);
3296
+ availableAmount = Math.max(0, totalAvailable - requiredAmount);
3297
+ } else {
3298
+ // 单个预约:计算资源个数
3299
+ totalAvailable = resourcesOfThisType.length;
3300
+ requiredAmount = items.reduce(function (sum, cartItem) {
3301
+ return sum + (cartItem.num || 1);
3302
+ }, 0);
3303
+ availableAmount = Math.max(0, totalAvailable - requiredAmount);
3304
+ }
3305
+
3306
+ // 记录资源容量信息
3307
+ resourceCapacityInfo.push({
3308
+ code: resourceCode,
3309
+ available: availableAmount,
3310
+ total: totalAvailable,
3311
+ required: requiredAmount,
3312
+ isMultiple: isMultipleBooking
3313
+ });
3314
+ availableCountsByResourceType.push(availableAmount);
3315
+
3316
+ // 检查是否有容量问题
3317
+ if (requiredAmount > totalAvailable) {
3318
+ hasCapacityIssue = true;
3319
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " ").concat(isMultipleBooking ? '容量' : '资源数量', "\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredAmount, ", \u603B\u5171 ").concat(totalAvailable));
3320
+ }
3321
+
3322
+ // 为通过检测的商品分配一个公共可用时间段
3323
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u8D44\u6E90\u65F6\u95F4\u4FE1\u606F:"), resourcesOfThisType.map(function (r) {
3324
+ return {
3325
+ id: r.id,
3326
+ times: r.times.map(function (t) {
3327
+ return "".concat(t.start_at, " - ").concat(t.end_at);
3328
+ })
3329
+ };
3330
+ }));
3331
+
3332
+ // 找到所有资源都可用的时间段
3333
+ var commonTimeSlots = _this16.findCommonAvailableTimeSlots(resourcesOfThisType);
3334
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonTimeSlots);
3335
+ if (commonTimeSlots.length === 0) {
3336
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4\u6BB5"));
3337
+ return {
3338
+ v: {
3339
+ success: false,
3340
+ minAvailableCount: 0
3341
+ }
3342
+ };
3343
+ }
3344
+
3345
+ // 使用第一个公共可用时间段,但只处理未处理过的商品
3346
+ var firstCommonSlot = commonTimeSlots[0];
3347
+ console.log("\u4F7F\u7528\u516C\u5171\u65F6\u95F4\u6BB5: ".concat(firstCommonSlot.startTime, " - ").concat(firstCommonSlot.endTime));
3348
+ items.forEach(function (cartItem) {
3349
+ // 只处理未处理过的商品,避免重复添加
3350
+ if (!processedCartItemIds.has(cartItem._id)) {
3351
+ processedCartItemIds.add(cartItem._id);
3352
+ var processedItem = _objectSpread(_objectSpread({}, cartItem), {}, {
3353
+ start_date: dateRange[0].date,
3354
+ start_time: firstCommonSlot.startTime,
3355
+ end_time: firstCommonSlot.endTime,
3356
+ end_date: dateRange[0].date
3357
+ });
3358
+ processedItemsWithoutTime.push(processedItem);
3359
+ }
3360
+ });
3361
+ },
3362
+ _ret5;
3363
+ for (var _i3 = 0, _Object$entries3 = Object.entries(itemsByResourceType); _i3 < _Object$entries3.length; _i3++) {
3364
+ _ret5 = _loop5();
3365
+ if (_ret5) return _ret5.v;
3366
+ }
3367
+
3368
+ // 如果有容量问题,找出限制最严格的资源类型,返回其总容量
3369
+ if (hasCapacityIssue) {
3370
+ // 找出超出容量的资源类型中,总容量最少的那个
3371
+ var overCapacityResources = resourceCapacityInfo.filter(function (info) {
3372
+ return info.required > info.total;
3373
+ });
3374
+ if (overCapacityResources.length > 0) {
3375
+ var _minTotalCapacity2 = Math.min.apply(Math, _toConsumableArray(overCapacityResources.map(function (info) {
3376
+ return info.total;
3377
+ })));
3378
+ return {
3379
+ success: false,
3380
+ minAvailableCount: _minTotalCapacity2
3381
+ };
3382
+ }
3383
+ // 如果没有超出容量的(理论上不应该发生),返回总容量最少的
3384
+ var minTotalCapacity = Math.min.apply(Math, _toConsumableArray(resourceCapacityInfo.map(function (info) {
3385
+ return info.total;
3386
+ })));
3387
+ return {
3388
+ success: false,
3389
+ minAvailableCount: minTotalCapacity
3390
+ };
3391
+ }
3392
+ }
3393
+
3394
+ // 合并所有商品(有时间的 + 处理后的没有时间的)
3395
+ var allProcessedItems = [].concat(itemsWithTime, processedItemsWithoutTime);
3396
+
3397
+ // 按时间段分组检查
3398
+ var cartItemsByTimeSlot = {};
3399
+ allProcessedItems.forEach(function (cartItem) {
3400
+ if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date) return;
3401
+ var timeSlotKey = "".concat(cartItem.start_date, "_").concat(cartItem.start_time, "_").concat(cartItem.end_date || cartItem.start_date, "_").concat(cartItem.end_time);
3402
+ if (!cartItemsByTimeSlot[timeSlotKey]) {
3403
+ cartItemsByTimeSlot[timeSlotKey] = [];
3404
+ }
3405
+ cartItemsByTimeSlot[timeSlotKey].push(cartItem);
3406
+ });
3407
+ // 检查每个时间段是否有足够的资源容量
3408
+ var _loop6 = function _loop6() {
3409
+ var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
3410
+ timeSlotKey = _Object$entries4$_i[0],
3411
+ itemsInTimeSlot = _Object$entries4$_i[1];
3412
+ var _timeSlotKey$split3 = timeSlotKey.split('_'),
3413
+ _timeSlotKey$split4 = _slicedToArray(_timeSlotKey$split3, 4),
3414
+ startDate = _timeSlotKey$split4[0],
3415
+ startTime = _timeSlotKey$split4[1],
3416
+ endDate = _timeSlotKey$split4[2],
3417
+ endTime = _timeSlotKey$split4[3];
3418
+ var timeSlotStart = "".concat(startDate, " ").concat(startTime);
3419
+ var timeSlotEnd = "".concat(endDate, " ").concat(endTime);
3420
+
3421
+ // 获取这个时间段所有商品涉及的资源
3422
+ var allResourcesForTimeSlot = [];
3423
+ var resourcesIdSet = new Set();
3424
+
3425
+ // 获取资源数据
3426
+ var dateRange = _this16.store.date.getDateRange();
3427
+ var resourcesDates = _this16.store.date.getDateList();
3428
+ var targetResourceDate = resourcesDates.find(function (n) {
3429
+ return n.date === startDate;
3430
+ });
3431
+ if (!targetResourceDate) return 0; // continue
3432
+ var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
3433
+ itemsInTimeSlot.forEach(function (cartItem) {
3434
+ if (!cartItem._productOrigin) return;
3435
+
3436
+ // 获取商品的资源配置
3437
+ var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
3438
+ productResourceIds.forEach(function (resourceId) {
3439
+ if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
3440
+ resourcesIdSet.add(resourceId);
3441
+ allResourcesForTimeSlot.push(resourcesMap[resourceId]);
3442
+ }
3443
+ });
3444
+ });
3445
+
3446
+ // 按资源类型分组检查容量
3447
+ if (!checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
3448
+ // 如果有可用数量记录,返回最小值;否则返回 0
3449
+ var _minAvailableCount2 = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
3450
+ return {
3451
+ v: {
3452
+ success: false,
3453
+ minAvailableCount: _minAvailableCount2
3454
+ }
3455
+ };
3456
+ }
3457
+ },
3458
+ _ret6;
3459
+ for (var _i4 = 0, _Object$entries4 = Object.entries(cartItemsByTimeSlot); _i4 < _Object$entries4.length; _i4++) {
3460
+ _ret6 = _loop6();
3461
+ if (_ret6 === 0) continue;
3462
+ if (_ret6) return _ret6.v;
3463
+ }
3464
+
3465
+ // 全部通过检测,返回成功和最小可用数量
3466
+ var minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
3467
+ return {
3468
+ success: true,
3469
+ minAvailableCount: minAvailableCount
3470
+ };
3471
+ }
3075
3472
  }, {
3076
3473
  key: "setOtherData",
3077
3474
  value: function setOtherData(key, value) {
@@ -3143,7 +3540,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3143
3540
  }, {
3144
3541
  key: "getResourcesByCartItemAndCode",
3145
3542
  value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
3146
- var _cartItem$_productOri13;
3543
+ var _cartItem$_productOri16;
3147
3544
  var dateRange = this.store.date.getDateRange();
3148
3545
  var resources = [];
3149
3546
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -3166,16 +3563,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3166
3563
  });
3167
3564
  if (!cartItem) return [];
3168
3565
  var selectedResources = [];
3169
- var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
3170
- currentCapacity = _getCapacityInfoByCar8.currentCapacity,
3171
- formatCapacity = _getCapacityInfoByCar8.formatCapacity;
3566
+ var _getCapacityInfoByCar9 = getCapacityInfoByCartItem(cartItem),
3567
+ currentCapacity = _getCapacityInfoByCar9.currentCapacity,
3568
+ formatCapacity = _getCapacityInfoByCar9.formatCapacity;
3172
3569
  cartItem._origin.metadata.capacity = formatCapacity;
3173
3570
  if (cartItem.holder_id) {
3174
3571
  selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
3175
3572
  } else {
3176
3573
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
3177
3574
  }
3178
- 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);
3575
+ 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);
3179
3576
  var targetResource = productResources.find(function (resource) {
3180
3577
  return resource.code === resourceCode;
3181
3578
  });
@@ -3198,7 +3595,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3198
3595
  });
3199
3596
  if (mTimes.length === 0) return false;
3200
3597
  var canUseArr = mTimes.map(function (item) {
3201
- var _cartItem$_productOri14;
3598
+ var _cartItem$_productOri17;
3202
3599
  var res = getIsUsableByTimeItem({
3203
3600
  timeSlice: {
3204
3601
  start_time: startTime.format('HH:mm'),
@@ -3210,7 +3607,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3210
3607
  resource: m,
3211
3608
  currentCount: currentCapacity || 0,
3212
3609
  resourcesUseableMap: resourcesUseableMap,
3213
- cut_off_time: (_cartItem$_productOri14 = cartItem._productOrigin) === null || _cartItem$_productOri14 === void 0 ? void 0 : _cartItem$_productOri14.cut_off_time
3610
+ cut_off_time: (_cartItem$_productOri17 = cartItem._productOrigin) === null || _cartItem$_productOri17 === void 0 ? void 0 : _cartItem$_productOri17.cut_off_time
3214
3611
  });
3215
3612
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
3216
3613
  resourcesUseableMap[m.id] = res.usable;
@@ -3224,12 +3621,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3224
3621
  });
3225
3622
  } else {
3226
3623
  targetResource.renderList = targetResource.renderList.filter(function (n) {
3227
- var _cartItem$_productOri15;
3624
+ var _cartItem$_productOri18;
3228
3625
  var recordCount = n.capacity || 0;
3229
3626
  if (n.onlyComputed) return false;
3230
3627
  var timeSlots = getTimeSlicesByResource({
3231
3628
  resource: n,
3232
- 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,
3629
+ 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,
3233
3630
  split: 10,
3234
3631
  currentDate: dateRange[0].date
3235
3632
  });
@@ -3247,12 +3644,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3247
3644
  }, {
3248
3645
  key: "getTimeslotsScheduleByDateRange",
3249
3646
  value: (function () {
3250
- var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref11) {
3251
- var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i3, _dates, date;
3647
+ var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref12) {
3648
+ var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i5, _dates, date;
3252
3649
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3253
3650
  while (1) switch (_context26.prev = _context26.next) {
3254
3651
  case 0:
3255
- startDate = _ref11.startDate, endDate = _ref11.endDate, scheduleIds = _ref11.scheduleIds, resources = _ref11.resources;
3652
+ startDate = _ref12.startDate, endDate = _ref12.endDate, scheduleIds = _ref12.scheduleIds, resources = _ref12.resources;
3256
3653
  console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
3257
3654
  startDate: startDate,
3258
3655
  endDate: endDate,
@@ -3269,8 +3666,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3269
3666
  }
3270
3667
  // 如果不支持 Web Worker,使用同步方式处理
3271
3668
  results = {};
3272
- for (_i3 = 0, _dates = dates; _i3 < _dates.length; _i3++) {
3273
- date = _dates[_i3];
3669
+ for (_i5 = 0, _dates = dates; _i5 < _dates.length; _i5++) {
3670
+ date = _dates[_i5];
3274
3671
  results[date] = this.getTimeslotBySchedule({
3275
3672
  date: date,
3276
3673
  scheduleIds: scheduleIds,
@@ -3311,7 +3708,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3311
3708
  openResources,
3312
3709
  allProductResources,
3313
3710
  targetSchedules,
3314
- _loop5,
3711
+ _loop7,
3315
3712
  _args28 = arguments;
3316
3713
  return _regeneratorRuntime().wrap(function _callee27$(_context28) {
3317
3714
  while (1) switch (_context28.prev = _context28.next) {
@@ -3388,9 +3785,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3388
3785
  }
3389
3786
  });
3390
3787
  targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
3391
- _loop5 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop5() {
3788
+ _loop7 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop7() {
3392
3789
  var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
3393
- return _regeneratorRuntime().wrap(function _loop5$(_context27) {
3790
+ return _regeneratorRuntime().wrap(function _loop7$(_context27) {
3394
3791
  while (1) switch (_context27.prev = _context27.next) {
3395
3792
  case 0:
3396
3793
  currentDateStr = currentDate.format('YYYY-MM-DD');
@@ -3493,14 +3890,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3493
3890
  case "end":
3494
3891
  return _context27.stop();
3495
3892
  }
3496
- }, _loop5);
3893
+ }, _loop7);
3497
3894
  });
3498
3895
  case 28:
3499
3896
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
3500
3897
  _context28.next = 34;
3501
3898
  break;
3502
3899
  }
3503
- return _context28.delegateYield(_loop5(), "t0", 30);
3900
+ return _context28.delegateYield(_loop7(), "t0", 30);
3504
3901
  case 30:
3505
3902
  if (!_context28.t0) {
3506
3903
  _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
@@ -60,7 +60,9 @@ export var formatDefaultCapacitys = function formatDefaultCapacitys(_ref) {
60
60
  * @Author: zhiwei.Wang
61
61
  */
62
62
  export var getSumCapacity = function getSumCapacity(_ref2) {
63
- var capacity = _ref2.capacity;
63
+ var capacity = _ref2.capacity,
64
+ _ref2$num = _ref2.num,
65
+ num = _ref2$num === void 0 ? 1 : _ref2$num;
64
66
  var sum = 0;
65
67
  var _iterator = _createForOfIteratorHelper(capacity || []),
66
68
  _step;
@@ -74,7 +76,7 @@ export var getSumCapacity = function getSumCapacity(_ref2) {
74
76
  } finally {
75
77
  _iterator.f();
76
78
  }
77
- return sum;
79
+ return sum * num;
78
80
  };
79
81
 
80
82
  /**
@@ -85,13 +87,14 @@ export var getSumCapacity = function getSumCapacity(_ref2) {
85
87
  * @return {*}
86
88
  */
87
89
  export function getCapacityInfoByCartItem(targetCartItem) {
88
- var _targetCartItem$_prod;
90
+ var _targetCartItem$_prod, _targetCartItem$_orig;
89
91
  var formatCapacity = formatDefaultCapacitys({
90
92
  capacity: (_targetCartItem$_prod = targetCartItem._productOrigin) === null || _targetCartItem$_prod === void 0 ? void 0 : _targetCartItem$_prod.capacity,
91
93
  product_bundle: targetCartItem._origin.product.product_bundle
92
94
  });
93
95
  var currentCapacity = getSumCapacity({
94
- capacity: formatCapacity
96
+ capacity: formatCapacity,
97
+ num: (targetCartItem === null || targetCartItem === void 0 || (_targetCartItem$_orig = targetCartItem._origin) === null || _targetCartItem$_orig === void 0 || (_targetCartItem$_orig = _targetCartItem$_orig.product) === null || _targetCartItem$_orig === void 0 ? void 0 : _targetCartItem$_orig.quantity) || 1
95
98
  });
96
99
  return {
97
100
  formatCapacity: formatCapacity,
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "normal" | "duration" | "session";
52
+ getProductType(): "duration" | "session" | "normal";
53
53
  }
@@ -324,6 +324,15 @@ 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(currentProduct: ProductData): {
333
+ success: boolean;
334
+ minAvailableCount: number;
335
+ };
327
336
  setOtherData(key: string, value: any): void;
328
337
  getOtherData(key: string): any;
329
338
  getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
@@ -34,16 +34,17 @@ __export(BookingByStep_exports, {
34
34
  module.exports = __toCommonJS(BookingByStep_exports);
35
35
  var import_BaseModule = require("../../modules/BaseModule");
36
36
  var import_types = require("./types");
37
+ var import_utils = require("../../modules/Cart/utils");
37
38
  var import_products = require("./utils/products");
38
39
  var import_resources = require("./utils/resources");
39
40
  var import_dayjs = __toESM(require("dayjs"));
40
41
  var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
41
42
  var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
42
- var import_utils = require("../../modules/Resource/utils");
43
+ var import_utils2 = require("../../modules/Resource/utils");
43
44
  var import_lodash_es = require("lodash-es");
44
- var import_utils2 = require("../../modules/Schedule/utils");
45
- var import_utils3 = require("../../modules/Date/utils");
46
- var import_utils4 = require("../../modules/Product/utils");
45
+ var import_utils3 = require("../../modules/Schedule/utils");
46
+ var import_utils4 = require("../../modules/Date/utils");
47
+ var import_utils5 = require("../../modules/Product/utils");
47
48
  var import_timeslots = require("./utils/timeslots");
48
49
  var import_changePrice = require("../../modules/Cart/utils/changePrice");
49
50
  var import_capacity = require("./utils/capacity");
@@ -363,7 +364,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
363
364
  let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
364
365
  if (!date) {
365
366
  const normalProductCartItem = cartItems.find(
366
- (n) => !(0, import_utils4.isNormalProduct)(n._productOrigin)
367
+ (n) => !(0, import_utils5.isNormalProduct)(n._productOrigin)
367
368
  );
368
369
  date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
369
370
  }
@@ -473,7 +474,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
473
474
  let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
474
475
  if (!date) {
475
476
  const normalProductCartItem = cartItems.find(
476
- (n) => !(0, import_utils4.isNormalProduct)(n._productOrigin)
477
+ (n) => !(0, import_utils5.isNormalProduct)(n._productOrigin)
477
478
  );
478
479
  date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
479
480
  }
@@ -525,7 +526,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
525
526
  }
526
527
  });
527
528
  let type = this.otherParams.isRetailTemplate ? "virtual" : "appointment_booking";
528
- if ((0, import_utils4.areAllNormalProducts)(
529
+ if ((0, import_utils5.areAllNormalProducts)(
529
530
  newCartItems.map((n) => n._productOrigin)
530
531
  )) {
531
532
  type = "virtual";
@@ -648,7 +649,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
648
649
  date
649
650
  }) {
650
651
  if (date) {
651
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
652
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
652
653
  const cartItemsByDate = cartItems.filter(
653
654
  (n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
654
655
  );
@@ -810,7 +811,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
810
811
  * @returns 不符合条件的购物车商品ID列表
811
812
  */
812
813
  checkCartItems(type) {
813
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
814
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
814
815
  const errorCartItemIds = [];
815
816
  cartItems.forEach((cartItem) => {
816
817
  const result = this.store.cart.checkCartItemByType(cartItem, type);
@@ -844,7 +845,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
844
845
  resources.push(...n.resource);
845
846
  });
846
847
  }
847
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
848
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
848
849
  if (!resources.length) {
849
850
  const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
850
851
  if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
@@ -860,7 +861,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
860
861
  });
861
862
  }
862
863
  }
863
- const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
864
+ const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
864
865
  const arr = [];
865
866
  cartItems.forEach((cartItem) => {
866
867
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
@@ -989,14 +990,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
989
990
  */
990
991
  getResourcesListByCartItem(id) {
991
992
  var _a, _b;
992
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
993
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
993
994
  const dateRange = this.store.date.getDateRange();
994
995
  const resources = [];
995
996
  dateRange.forEach((n) => {
996
997
  if (n.resource)
997
998
  resources.push(...n.resource);
998
999
  });
999
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
1000
+ const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
1000
1001
  const targetCartItem = cartItems.find((n) => n._id === id);
1001
1002
  if (!targetCartItem) {
1002
1003
  throw new Error(`没有找到${id}购物车商品`);
@@ -1053,7 +1054,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1053
1054
  capacity
1054
1055
  }) {
1055
1056
  var _a, _b, _c;
1056
- if ((0, import_utils4.isNormalProduct)(cartItem._productOrigin)) {
1057
+ if ((0, import_utils5.isNormalProduct)(cartItem._productOrigin)) {
1057
1058
  return {};
1058
1059
  }
1059
1060
  const dateRange = this.store.date.getDateRange();
@@ -1088,7 +1089,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1088
1089
  });
1089
1090
  }
1090
1091
  }
1091
- const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(AllResources));
1092
+ const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(AllResources));
1092
1093
  const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1093
1094
  const selectedResources = (0, import_resources.getOthersSelectedResources)(
1094
1095
  allCartItems,
@@ -1169,7 +1170,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1169
1170
  selectedResource: targetResource
1170
1171
  };
1171
1172
  } else {
1172
- const resourcesMap2 = (0, import_utils.getResourcesMap)(resources);
1173
+ const resourcesMap2 = (0, import_utils2.getResourcesMap)(resources);
1173
1174
  const resourceIds = resources.map((n) => n.id);
1174
1175
  const timeSlots2 = (0, import_resources.getTimeSlicesByResources)({
1175
1176
  resourceIds,
@@ -1307,7 +1308,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1307
1308
  currentResourcesRenderList.push(...n.renderList || []);
1308
1309
  }
1309
1310
  });
1310
- const resourcesMap = (0, import_utils.getResourcesMap)(currentResourcesRenderList);
1311
+ const resourcesMap = (0, import_utils2.getResourcesMap)(currentResourcesRenderList);
1311
1312
  if (item.holder_id) {
1312
1313
  selectedResources = (0, import_resources.getOthersSelectedResources)(
1313
1314
  allCartItems,
@@ -1372,7 +1373,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1372
1373
  }
1373
1374
  });
1374
1375
  };
1375
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1376
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
1376
1377
  if (cartItems == null ? void 0 : cartItems[0].holder_id) {
1377
1378
  accountList.forEach((account) => {
1378
1379
  const cartItems2 = this.store.cart.getCartByAccount(account.getId());
@@ -1388,7 +1389,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1388
1389
  var _a, _b, _c, _d, _e, _f, _g, _h;
1389
1390
  let dateRange = this.store.date.getDateRange();
1390
1391
  const resources = [];
1391
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1392
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
1392
1393
  const resourceIds = [];
1393
1394
  let resourcesTypeId = void 0;
1394
1395
  let isSingleResource = false;
@@ -1426,7 +1427,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1426
1427
  }
1427
1428
  });
1428
1429
  }
1429
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
1430
+ const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
1430
1431
  let duration = 0;
1431
1432
  const accountList = this.store.accountList.getAccounts();
1432
1433
  const checkDuration = (cartItems2) => {
@@ -1525,7 +1526,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1525
1526
  // 提交时间切片,绑定到对应购物车的商品上,更新购物车---只有 duration 商品
1526
1527
  submitTimeSlot(timeSlots) {
1527
1528
  var _a, _b;
1528
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1529
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
1529
1530
  const allResources = this.store.date.getResourcesListByDate(
1530
1531
  timeSlots.start_at.format("YYYY-MM-DD")
1531
1532
  );
@@ -1603,7 +1604,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1603
1604
  getScheduleDataByIds(scheduleIds) {
1604
1605
  const targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
1605
1606
  const targetSchedulesData = targetSchedules.map((item) => {
1606
- return (0, import_utils2.calcCalendarDataByScheduleResult)(item);
1607
+ return (0, import_utils3.calcCalendarDataByScheduleResult)(item);
1607
1608
  });
1608
1609
  const newSchedule = {};
1609
1610
  targetSchedulesData.forEach((item) => {
@@ -1675,7 +1676,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1675
1676
  const resourcesDates = this.store.date.getDateList();
1676
1677
  const targetResourceDate = resourcesDates.find((n) => n.date === date);
1677
1678
  const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1678
- const resourcesMap = (0, import_utils.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []);
1679
+ const resourcesMap = (0, import_utils2.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []);
1679
1680
  const selectedResources = (0, import_resources.getOthersSelectedResources)(
1680
1681
  cartItems,
1681
1682
  "",
@@ -1687,12 +1688,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1687
1688
  selectedResources,
1688
1689
  1
1689
1690
  );
1690
- const minTimeMaxTime = (0, import_utils2.calcMinTimeMaxTimeBySchedules)(
1691
+ const minTimeMaxTime = (0, import_utils3.calcMinTimeMaxTimeBySchedules)(
1691
1692
  targetSchedules,
1692
1693
  {},
1693
1694
  date
1694
1695
  );
1695
- const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
1696
+ const scheduleTimeSlots = (0, import_utils3.getAllSortedDateRanges)(minTimeMaxTime);
1696
1697
  let allProductResources = productResources.flatMap((n) => n.renderList);
1697
1698
  allProductResources.sort((a, b) => {
1698
1699
  var _a2, _b2, _c2, _d2;
@@ -1808,7 +1809,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1808
1809
  otherSameTimesCartItems.forEach((m) => {
1809
1810
  var _a2, _b2;
1810
1811
  const productResources2 = (0, import_resources.getResourcesByProduct)(
1811
- (0, import_utils.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []),
1812
+ (0, import_utils2.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []),
1812
1813
  ((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) || [],
1813
1814
  selectedResources,
1814
1815
  1
@@ -1955,7 +1956,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1955
1956
  const targetResourceDate = resourcesDates.find((n) => n.date === dateRange[0].date);
1956
1957
  if (!targetResourceDate)
1957
1958
  return { success: false, minAvailableCount: 0 };
1958
- const resourcesMap = (0, import_utils.getResourcesMap)(targetResourceDate.resource || []);
1959
+ const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
1959
1960
  const resourceCodeToFormIdMap = {};
1960
1961
  Object.values(itemsByResourceType).flat().forEach((cartItem) => {
1961
1962
  var _a2, _b2;
@@ -2097,7 +2098,245 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2097
2098
  const targetResourceDate = resourcesDates.find((n) => n.date === startDate);
2098
2099
  if (!targetResourceDate)
2099
2100
  continue;
2100
- const resourcesMap = (0, import_utils.getResourcesMap)(targetResourceDate.resource || []);
2101
+ const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
2102
+ itemsInTimeSlot.forEach((cartItem) => {
2103
+ if (!cartItem._productOrigin)
2104
+ return;
2105
+ const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
2106
+ productResourceIds.forEach((resourceId) => {
2107
+ if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
2108
+ resourcesIdSet.add(resourceId);
2109
+ allResourcesForTimeSlot.push(resourcesMap[resourceId]);
2110
+ }
2111
+ });
2112
+ });
2113
+ if (!(0, import_capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
2114
+ const minAvailableCount2 = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
2115
+ return { success: false, minAvailableCount: minAvailableCount2 };
2116
+ }
2117
+ }
2118
+ const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
2119
+ return { success: true, minAvailableCount };
2120
+ }
2121
+ /**
2122
+ * 将 ProductData 转换为 CartItem,但不添加到购物车
2123
+ * 参考 addProductToCart 方法的实现
2124
+ */
2125
+ convertProductToCartItem(product) {
2126
+ const {
2127
+ bundle,
2128
+ options,
2129
+ origin,
2130
+ product_variant_id,
2131
+ quantity = 1
2132
+ } = product || {};
2133
+ const productData = { ...origin, product_variant_id };
2134
+ const processedProduct = (0, import_utils.handleVariantProduct)(productData);
2135
+ const cartItem = {
2136
+ _id: (0, import_utils.getUniqueId)("temp_"),
2137
+ _origin: (0, import_utils.createCartItemOrigin)(),
2138
+ _productOrigin: processedProduct,
2139
+ _productInit: product
2140
+ };
2141
+ const activeAccount = this.getActiveAccount();
2142
+ (0, import_utils.formatProductToCartItem)({
2143
+ cartItem,
2144
+ product: processedProduct,
2145
+ bundle,
2146
+ options,
2147
+ product_variant_id,
2148
+ quantity
2149
+ });
2150
+ return cartItem;
2151
+ }
2152
+ checkMaxDurationCapacityForDetailNums(currentProduct) {
2153
+ var _a, _b;
2154
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
2155
+ const currentCartItem = this.convertProductToCartItem(currentProduct);
2156
+ cartItems.push(currentCartItem);
2157
+ if (cartItems.length === 0)
2158
+ return { success: true, minAvailableCount: 0 };
2159
+ const itemsWithTime = [];
2160
+ const itemsWithoutTime = [];
2161
+ const availableCountsByResourceType = [];
2162
+ cartItems.forEach((cartItem) => {
2163
+ if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
2164
+ itemsWithTime.push(cartItem);
2165
+ } else {
2166
+ itemsWithoutTime.push(cartItem);
2167
+ }
2168
+ });
2169
+ const processedItemsWithoutTime = [];
2170
+ if (itemsWithoutTime.length > 0) {
2171
+ const itemsByResourceType = {};
2172
+ itemsWithoutTime.forEach((cartItem) => {
2173
+ var _a2;
2174
+ if (!cartItem._productOrigin)
2175
+ return;
2176
+ const resourceTypes = ((_a2 = cartItem._productOrigin.product_resource) == null ? void 0 : _a2.resources) || [];
2177
+ resourceTypes.forEach((resourceType) => {
2178
+ var _a3;
2179
+ if (resourceType.status === 1) {
2180
+ const resourceCode = resourceType.code || ((_a3 = resourceType.id) == null ? void 0 : _a3.toString());
2181
+ if (!itemsByResourceType[resourceCode]) {
2182
+ itemsByResourceType[resourceCode] = [];
2183
+ }
2184
+ if (!itemsByResourceType[resourceCode].find((item) => item._id === cartItem._id)) {
2185
+ itemsByResourceType[resourceCode].push(cartItem);
2186
+ }
2187
+ }
2188
+ });
2189
+ });
2190
+ const dateRange = this.store.date.getDateRange();
2191
+ if (!dateRange || dateRange.length === 0)
2192
+ return { success: false, minAvailableCount: 0 };
2193
+ const resourcesDates = this.store.date.getDateList();
2194
+ const targetResourceDate = resourcesDates.find((n) => n.date === dateRange[0].date);
2195
+ if (!targetResourceDate)
2196
+ return { success: false, minAvailableCount: 0 };
2197
+ const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
2198
+ const resourceCodeToFormIdMap = {};
2199
+ Object.values(itemsByResourceType).flat().forEach((cartItem) => {
2200
+ var _a2, _b2;
2201
+ if ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) {
2202
+ cartItem._productOrigin.product_resource.resources.forEach((resourceConfig) => {
2203
+ var _a3, _b3;
2204
+ if (resourceConfig.status === 1 && resourceConfig.code) {
2205
+ const formId = ((_a3 = resourceConfig.id) == null ? void 0 : _a3.toString()) || ((_b3 = resourceConfig.resource_type_id) == null ? void 0 : _b3.toString());
2206
+ if (formId) {
2207
+ resourceCodeToFormIdMap[resourceConfig.code] = formId;
2208
+ }
2209
+ }
2210
+ });
2211
+ }
2212
+ });
2213
+ let hasCapacityIssue = false;
2214
+ const resourceCapacityInfo = [];
2215
+ const processedCartItemIds = /* @__PURE__ */ new Set();
2216
+ for (const [resourceCode, items] of Object.entries(itemsByResourceType)) {
2217
+ const targetFormId = resourceCodeToFormIdMap[resourceCode];
2218
+ if (!targetFormId) {
2219
+ console.log(`资源类型 ${resourceCode} 找不到对应的 form_id`);
2220
+ return { success: false, minAvailableCount: 0 };
2221
+ }
2222
+ const resourcesOfThisType = [];
2223
+ items.forEach((cartItem) => {
2224
+ const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
2225
+ productResourceIds.forEach((resourceId) => {
2226
+ var _a2;
2227
+ const resource = resourcesMap[resourceId];
2228
+ if (resource && ((_a2 = resource.form_id) == null ? void 0 : _a2.toString()) === targetFormId) {
2229
+ if (!resourcesOfThisType.find((r) => r.id === resource.id)) {
2230
+ resourcesOfThisType.push(resource);
2231
+ }
2232
+ }
2233
+ });
2234
+ });
2235
+ if (resourcesOfThisType.length === 0) {
2236
+ console.log(`资源类型 ${resourceCode} 没有找到可用资源`);
2237
+ return { success: false, minAvailableCount: 0 };
2238
+ }
2239
+ let resourceTypeConfig = null;
2240
+ for (const cartItem of items) {
2241
+ if ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) {
2242
+ resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(
2243
+ (r) => r.code === resourceCode && r.status === 1
2244
+ );
2245
+ if (resourceTypeConfig)
2246
+ break;
2247
+ }
2248
+ }
2249
+ const isMultipleBooking = (resourceTypeConfig == null ? void 0 : resourceTypeConfig.type) === "multiple";
2250
+ let totalAvailable;
2251
+ let requiredAmount;
2252
+ let availableAmount;
2253
+ if (isMultipleBooking) {
2254
+ totalAvailable = resourcesOfThisType.reduce((sum, resource) => {
2255
+ return sum + (resource.capacity || 0);
2256
+ }, 0);
2257
+ requiredAmount = items.reduce((sum, cartItem) => {
2258
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
2259
+ return sum + currentCapacity;
2260
+ }, 0);
2261
+ availableAmount = Math.max(0, totalAvailable - requiredAmount);
2262
+ } else {
2263
+ totalAvailable = resourcesOfThisType.length;
2264
+ requiredAmount = items.reduce((sum, cartItem) => {
2265
+ return sum + (cartItem.num || 1);
2266
+ }, 0);
2267
+ availableAmount = Math.max(0, totalAvailable - requiredAmount);
2268
+ }
2269
+ resourceCapacityInfo.push({
2270
+ code: resourceCode,
2271
+ available: availableAmount,
2272
+ total: totalAvailable,
2273
+ required: requiredAmount,
2274
+ isMultiple: isMultipleBooking
2275
+ });
2276
+ availableCountsByResourceType.push(availableAmount);
2277
+ if (requiredAmount > totalAvailable) {
2278
+ hasCapacityIssue = true;
2279
+ console.log(`资源类型 ${resourceCode} ${isMultipleBooking ? "容量" : "资源数量"}不足: 需要 ${requiredAmount}, 总共 ${totalAvailable}`);
2280
+ }
2281
+ console.log(`资源类型 ${resourceCode} 的资源时间信息:`, resourcesOfThisType.map((r) => ({
2282
+ id: r.id,
2283
+ times: r.times.map((t) => `${t.start_at} - ${t.end_at}`)
2284
+ })));
2285
+ const commonTimeSlots = this.findCommonAvailableTimeSlots(resourcesOfThisType);
2286
+ console.log(`资源类型 ${resourceCode} 的公共时间段:`, commonTimeSlots);
2287
+ if (commonTimeSlots.length === 0) {
2288
+ console.log(`资源类型 ${resourceCode} 没有公共可用时间段`);
2289
+ return { success: false, minAvailableCount: 0 };
2290
+ }
2291
+ const firstCommonSlot = commonTimeSlots[0];
2292
+ console.log(`使用公共时间段: ${firstCommonSlot.startTime} - ${firstCommonSlot.endTime}`);
2293
+ items.forEach((cartItem) => {
2294
+ if (!processedCartItemIds.has(cartItem._id)) {
2295
+ processedCartItemIds.add(cartItem._id);
2296
+ const processedItem = {
2297
+ ...cartItem,
2298
+ start_date: dateRange[0].date,
2299
+ start_time: firstCommonSlot.startTime,
2300
+ end_time: firstCommonSlot.endTime,
2301
+ end_date: dateRange[0].date
2302
+ };
2303
+ processedItemsWithoutTime.push(processedItem);
2304
+ }
2305
+ });
2306
+ }
2307
+ if (hasCapacityIssue) {
2308
+ const overCapacityResources = resourceCapacityInfo.filter((info) => info.required > info.total);
2309
+ if (overCapacityResources.length > 0) {
2310
+ const minTotalCapacity2 = Math.min(...overCapacityResources.map((info) => info.total));
2311
+ return { success: false, minAvailableCount: minTotalCapacity2 };
2312
+ }
2313
+ const minTotalCapacity = Math.min(...resourceCapacityInfo.map((info) => info.total));
2314
+ return { success: false, minAvailableCount: minTotalCapacity };
2315
+ }
2316
+ }
2317
+ const allProcessedItems = [...itemsWithTime, ...processedItemsWithoutTime];
2318
+ const cartItemsByTimeSlot = {};
2319
+ allProcessedItems.forEach((cartItem) => {
2320
+ if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date)
2321
+ return;
2322
+ const timeSlotKey = `${cartItem.start_date}_${cartItem.start_time}_${cartItem.end_date || cartItem.start_date}_${cartItem.end_time}`;
2323
+ if (!cartItemsByTimeSlot[timeSlotKey]) {
2324
+ cartItemsByTimeSlot[timeSlotKey] = [];
2325
+ }
2326
+ cartItemsByTimeSlot[timeSlotKey].push(cartItem);
2327
+ });
2328
+ for (const [timeSlotKey, itemsInTimeSlot] of Object.entries(cartItemsByTimeSlot)) {
2329
+ const [startDate, startTime, endDate, endTime] = timeSlotKey.split("_");
2330
+ const timeSlotStart = `${startDate} ${startTime}`;
2331
+ const timeSlotEnd = `${endDate} ${endTime}`;
2332
+ const allResourcesForTimeSlot = [];
2333
+ const resourcesIdSet = /* @__PURE__ */ new Set();
2334
+ const dateRange = this.store.date.getDateRange();
2335
+ const resourcesDates = this.store.date.getDateList();
2336
+ const targetResourceDate = resourcesDates.find((n) => n.date === startDate);
2337
+ if (!targetResourceDate)
2338
+ continue;
2339
+ const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
2101
2340
  itemsInTimeSlot.forEach((cartItem) => {
2102
2341
  if (!cartItem._productOrigin)
2103
2342
  return;
@@ -2168,8 +2407,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2168
2407
  resources.push(...n.resource);
2169
2408
  });
2170
2409
  }
2171
- const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
2172
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
2410
+ const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
2411
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
2173
2412
  const cartItem = cartItems.find((item) => item._id === cartItemId);
2174
2413
  if (!cartItem)
2175
2414
  return [];
@@ -2382,12 +2621,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2382
2621
  }
2383
2622
  }
2384
2623
  if (status === "available") {
2385
- const minTimeMaxTime = (0, import_utils2.calcMinTimeMaxTimeBySchedules)(
2624
+ const minTimeMaxTime = (0, import_utils3.calcMinTimeMaxTimeBySchedules)(
2386
2625
  targetSchedules,
2387
2626
  {},
2388
2627
  currentDateStr
2389
2628
  );
2390
- const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
2629
+ const scheduleTimeSlots = (0, import_utils3.getAllSortedDateRanges)(minTimeMaxTime);
2391
2630
  const timesSlotCanUse = scheduleTimeSlots.some((item) => {
2392
2631
  const resourcesUseableMap = {};
2393
2632
  return openResources.every((resource) => {
@@ -2444,7 +2683,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2444
2683
  }
2445
2684
  currentDate = (0, import_dayjs.default)(currentDate).add(1, "day");
2446
2685
  }
2447
- dates = (0, import_utils3.handleAvailableDateByResource)(res.data, dates);
2686
+ dates = (0, import_utils4.handleAvailableDateByResource)(res.data, dates);
2448
2687
  this.store.date.setDateList(dates);
2449
2688
  if (!this.store.currentProductMeta)
2450
2689
  this.store.currentProductMeta = {};
@@ -2460,11 +2699,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2460
2699
  };
2461
2700
  }
2462
2701
  isCartAllNormalProducts() {
2463
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
2702
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
2464
2703
  return !cartItems.length;
2465
2704
  }
2466
2705
  isCartHasDurationProduct() {
2467
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
2706
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
2468
2707
  return cartItems.some((n) => {
2469
2708
  var _a;
2470
2709
  return (_a = n._productOrigin) == null ? void 0 : _a.duration;
@@ -2473,11 +2712,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2473
2712
  isTargetNormalProduct(product) {
2474
2713
  if (!product)
2475
2714
  return false;
2476
- return (0, import_utils4.isNormalProduct)(product);
2715
+ return (0, import_utils5.isNormalProduct)(product);
2477
2716
  }
2478
2717
  isTargetCartIdNormalProduct(id) {
2479
2718
  const cartItem = this.store.cart.getItems().find((n) => n._id === id);
2480
- return cartItem && (0, import_utils4.isNormalProduct)(cartItem._productOrigin);
2719
+ return cartItem && (0, import_utils5.isNormalProduct)(cartItem._productOrigin);
2481
2720
  }
2482
2721
  };
2483
2722
  // Annotate the CommonJS export names for ESM import in node:
@@ -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
@@ -68,20 +68,20 @@ var formatDefaultCapacitys = ({
68
68
  }
69
69
  return [{ id: 0, value: 1, name: "" }];
70
70
  };
71
- var getSumCapacity = ({ capacity }) => {
71
+ var getSumCapacity = ({ capacity, num = 1 }) => {
72
72
  let sum = 0;
73
73
  for (let item of capacity || []) {
74
74
  sum += item.value;
75
75
  }
76
- return sum;
76
+ return sum * num;
77
77
  };
78
78
  function getCapacityInfoByCartItem(targetCartItem) {
79
- var _a;
79
+ var _a, _b, _c;
80
80
  const formatCapacity = formatDefaultCapacitys({
81
81
  capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
82
82
  product_bundle: targetCartItem._origin.product.product_bundle
83
83
  });
84
- const currentCapacity = getSumCapacity({ capacity: formatCapacity });
84
+ const currentCapacity = getSumCapacity({ capacity: formatCapacity, num: ((_c = (_b = targetCartItem == null ? void 0 : targetCartItem._origin) == null ? void 0 : _b.product) == null ? void 0 : _c.quantity) || 1 });
85
85
  return {
86
86
  formatCapacity,
87
87
  currentCapacity
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.329",
4
+ "version": "0.0.330",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",