@pisell/pisellos 0.0.329 → 0.0.331
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.d.ts +10 -1
- package/dist/solution/BookingByStep/index.js +426 -20
- package/dist/solution/BookingByStep/utils/capacity.d.ts +2 -1
- package/dist/solution/BookingByStep/utils/capacity.js +7 -4
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.d.ts +10 -1
- package/lib/solution/BookingByStep/index.js +285 -38
- package/lib/solution/BookingByStep/utils/capacity.d.ts +2 -1
- package/lib/solution/BookingByStep/utils/capacity.js +4 -4
- package/package.json +1 -1
|
@@ -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(): "
|
|
52
|
+
getProductType(): "duration" | "session" | "normal";
|
|
53
53
|
}
|
|
@@ -324,9 +324,18 @@ 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
|
-
getProductTypeById(id: number): Promise<"
|
|
338
|
+
getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
|
|
330
339
|
/**
|
|
331
340
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
332
341
|
*
|
|
@@ -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';
|
|
@@ -1194,7 +1195,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1194
1195
|
this.addProductCheck({
|
|
1195
1196
|
date: date
|
|
1196
1197
|
});
|
|
1197
|
-
|
|
1198
|
+
// 如果 quantity 大于 1,则进入购物车拆散成多条数据
|
|
1199
|
+
if (addItemParams.quantity > 1) {
|
|
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
|
};
|
|
@@ -3072,6 +3082,402 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3072
3082
|
minAvailableCount: minAvailableCount
|
|
3073
3083
|
};
|
|
3074
3084
|
}
|
|
3085
|
+
|
|
3086
|
+
/**
|
|
3087
|
+
* 将 ProductData 转换为 CartItem,但不添加到购物车
|
|
3088
|
+
* 参考 addProductToCart 方法的实现
|
|
3089
|
+
*/
|
|
3090
|
+
}, {
|
|
3091
|
+
key: "convertProductToCartItem",
|
|
3092
|
+
value: function convertProductToCartItem(product) {
|
|
3093
|
+
var _ref11 = product || {},
|
|
3094
|
+
bundle = _ref11.bundle,
|
|
3095
|
+
options = _ref11.options,
|
|
3096
|
+
origin = _ref11.origin,
|
|
3097
|
+
product_variant_id = _ref11.product_variant_id,
|
|
3098
|
+
_ref11$quantity = _ref11.quantity,
|
|
3099
|
+
quantity = _ref11$quantity === void 0 ? 1 : _ref11$quantity;
|
|
3100
|
+
|
|
3101
|
+
// 处理商品数据,类似 addProductToCart 中的逻辑
|
|
3102
|
+
var productData = _objectSpread(_objectSpread({}, origin), {}, {
|
|
3103
|
+
product_variant_id: product_variant_id
|
|
3104
|
+
});
|
|
3105
|
+
|
|
3106
|
+
// 处理组合商品
|
|
3107
|
+
var processedProduct = handleVariantProduct(productData);
|
|
3108
|
+
|
|
3109
|
+
// 创建基础的 CartItem
|
|
3110
|
+
var cartItem = {
|
|
3111
|
+
_id: getUniqueId('temp_'),
|
|
3112
|
+
_origin: createCartItemOrigin(),
|
|
3113
|
+
_productOrigin: processedProduct,
|
|
3114
|
+
_productInit: product
|
|
3115
|
+
};
|
|
3116
|
+
|
|
3117
|
+
// 获取当前活跃账户
|
|
3118
|
+
var activeAccount = this.getActiveAccount();
|
|
3119
|
+
|
|
3120
|
+
// 使用格式化函数填充 CartItem 数据
|
|
3121
|
+
formatProductToCartItem({
|
|
3122
|
+
cartItem: cartItem,
|
|
3123
|
+
product: processedProduct,
|
|
3124
|
+
bundle: bundle,
|
|
3125
|
+
options: options,
|
|
3126
|
+
product_variant_id: product_variant_id,
|
|
3127
|
+
quantity: quantity
|
|
3128
|
+
});
|
|
3129
|
+
return cartItem;
|
|
3130
|
+
}
|
|
3131
|
+
}, {
|
|
3132
|
+
key: "checkMaxDurationCapacityForDetailNums",
|
|
3133
|
+
value: function checkMaxDurationCapacityForDetailNums(currentProduct) {
|
|
3134
|
+
var _this16 = this;
|
|
3135
|
+
var cartItems = cloneDeep(this.store.cart.getItems());
|
|
3136
|
+
|
|
3137
|
+
// 将 ProductData 转换为 CartItem 但不真正添加到购物车
|
|
3138
|
+
var currentCartItem = this.convertProductToCartItem(currentProduct);
|
|
3139
|
+
cartItems.push(currentCartItem);
|
|
3140
|
+
if (cartItems.length === 0) return {
|
|
3141
|
+
success: true,
|
|
3142
|
+
minAvailableCount: 0
|
|
3143
|
+
};
|
|
3144
|
+
|
|
3145
|
+
// 将购物车商品分为有时间的和没有时间的
|
|
3146
|
+
var itemsWithTime = [];
|
|
3147
|
+
var itemsWithoutTime = [];
|
|
3148
|
+
// 记录每种资源类型的可用数量
|
|
3149
|
+
var availableCountsByResourceType = [];
|
|
3150
|
+
cartItems.forEach(function (cartItem) {
|
|
3151
|
+
if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
|
|
3152
|
+
itemsWithTime.push(cartItem);
|
|
3153
|
+
} else {
|
|
3154
|
+
itemsWithoutTime.push(cartItem);
|
|
3155
|
+
}
|
|
3156
|
+
});
|
|
3157
|
+
|
|
3158
|
+
// 处理没有时间的商品,为它们分配公共可用时间的第一个时间片
|
|
3159
|
+
var processedItemsWithoutTime = [];
|
|
3160
|
+
if (itemsWithoutTime.length > 0) {
|
|
3161
|
+
// 按资源类型分组处理没有时间的商品
|
|
3162
|
+
var itemsByResourceType = {};
|
|
3163
|
+
itemsWithoutTime.forEach(function (cartItem) {
|
|
3164
|
+
var _cartItem$_productOri13;
|
|
3165
|
+
if (!cartItem._productOrigin) return;
|
|
3166
|
+
var resourceTypes = ((_cartItem$_productOri13 = cartItem._productOrigin.product_resource) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.resources) || [];
|
|
3167
|
+
resourceTypes.forEach(function (resourceType) {
|
|
3168
|
+
if (resourceType.status === 1) {
|
|
3169
|
+
var _resourceType$id2;
|
|
3170
|
+
var resourceCode = resourceType.code || ((_resourceType$id2 = resourceType.id) === null || _resourceType$id2 === void 0 ? void 0 : _resourceType$id2.toString());
|
|
3171
|
+
if (!itemsByResourceType[resourceCode]) {
|
|
3172
|
+
itemsByResourceType[resourceCode] = [];
|
|
3173
|
+
}
|
|
3174
|
+
// 避免重复添加同一个商品
|
|
3175
|
+
if (!itemsByResourceType[resourceCode].find(function (item) {
|
|
3176
|
+
return item._id === cartItem._id;
|
|
3177
|
+
})) {
|
|
3178
|
+
itemsByResourceType[resourceCode].push(cartItem);
|
|
3179
|
+
}
|
|
3180
|
+
}
|
|
3181
|
+
});
|
|
3182
|
+
});
|
|
3183
|
+
|
|
3184
|
+
// 为每种资源类型检查容量
|
|
3185
|
+
var dateRange = this.store.date.getDateRange();
|
|
3186
|
+
if (!dateRange || dateRange.length === 0) return {
|
|
3187
|
+
success: false,
|
|
3188
|
+
minAvailableCount: 0
|
|
3189
|
+
};
|
|
3190
|
+
var resourcesDates = this.store.date.getDateList();
|
|
3191
|
+
var targetResourceDate = resourcesDates.find(function (n) {
|
|
3192
|
+
return n.date === dateRange[0].date;
|
|
3193
|
+
});
|
|
3194
|
+
if (!targetResourceDate) return {
|
|
3195
|
+
success: false,
|
|
3196
|
+
minAvailableCount: 0
|
|
3197
|
+
};
|
|
3198
|
+
var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
|
|
3199
|
+
|
|
3200
|
+
// 从购物车商品中获取资源类型配置,建立 resourceCode 到 form_id 的映射关系
|
|
3201
|
+
var resourceCodeToFormIdMap = {};
|
|
3202
|
+
|
|
3203
|
+
// 遍历购物车中的商品,收集所有资源类型配置
|
|
3204
|
+
Object.values(itemsByResourceType).flat().forEach(function (cartItem) {
|
|
3205
|
+
var _cartItem$_productOri14;
|
|
3206
|
+
if ((_cartItem$_productOri14 = cartItem._productOrigin) !== null && _cartItem$_productOri14 !== void 0 && (_cartItem$_productOri14 = _cartItem$_productOri14.product_resource) !== null && _cartItem$_productOri14 !== void 0 && _cartItem$_productOri14.resources) {
|
|
3207
|
+
cartItem._productOrigin.product_resource.resources.forEach(function (resourceConfig) {
|
|
3208
|
+
// 只处理启用的资源类型 (status === 1)
|
|
3209
|
+
if (resourceConfig.status === 1 && resourceConfig.code) {
|
|
3210
|
+
var _resourceConfig$id2, _resourceConfig$resou2;
|
|
3211
|
+
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());
|
|
3212
|
+
if (formId) {
|
|
3213
|
+
resourceCodeToFormIdMap[resourceConfig.code] = formId;
|
|
3214
|
+
}
|
|
3215
|
+
}
|
|
3216
|
+
});
|
|
3217
|
+
}
|
|
3218
|
+
});
|
|
3219
|
+
var hasCapacityIssue = false;
|
|
3220
|
+
var resourceCapacityInfo = [];
|
|
3221
|
+
|
|
3222
|
+
// 用于跟踪已处理的商品,避免重复添加
|
|
3223
|
+
var processedCartItemIds = new Set();
|
|
3224
|
+
|
|
3225
|
+
// 先检查所有资源类型,收集可用数量信息
|
|
3226
|
+
var _loop5 = function _loop5() {
|
|
3227
|
+
var _resourceTypeConfig2;
|
|
3228
|
+
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
|
|
3229
|
+
resourceCode = _Object$entries3$_i[0],
|
|
3230
|
+
items = _Object$entries3$_i[1];
|
|
3231
|
+
// 获取该资源类型对应的 form_id
|
|
3232
|
+
var targetFormId = resourceCodeToFormIdMap[resourceCode];
|
|
3233
|
+
if (!targetFormId) {
|
|
3234
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u627E\u4E0D\u5230\u5BF9\u5E94\u7684 form_id"));
|
|
3235
|
+
return {
|
|
3236
|
+
v: {
|
|
3237
|
+
success: false,
|
|
3238
|
+
minAvailableCount: 0
|
|
3239
|
+
}
|
|
3240
|
+
};
|
|
3241
|
+
}
|
|
3242
|
+
|
|
3243
|
+
// 获取该资源类型的所有资源
|
|
3244
|
+
var resourcesOfThisType = [];
|
|
3245
|
+
items.forEach(function (cartItem) {
|
|
3246
|
+
var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
3247
|
+
productResourceIds.forEach(function (resourceId) {
|
|
3248
|
+
var _resource$form_id2;
|
|
3249
|
+
var resource = resourcesMap[resourceId];
|
|
3250
|
+
if (resource && ((_resource$form_id2 = resource.form_id) === null || _resource$form_id2 === void 0 ? void 0 : _resource$form_id2.toString()) === targetFormId) {
|
|
3251
|
+
// 避免重复添加同一个资源
|
|
3252
|
+
if (!resourcesOfThisType.find(function (r) {
|
|
3253
|
+
return r.id === resource.id;
|
|
3254
|
+
})) {
|
|
3255
|
+
resourcesOfThisType.push(resource);
|
|
3256
|
+
}
|
|
3257
|
+
}
|
|
3258
|
+
});
|
|
3259
|
+
});
|
|
3260
|
+
if (resourcesOfThisType.length === 0) {
|
|
3261
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u627E\u5230\u53EF\u7528\u8D44\u6E90"));
|
|
3262
|
+
return {
|
|
3263
|
+
v: {
|
|
3264
|
+
success: false,
|
|
3265
|
+
minAvailableCount: 0
|
|
3266
|
+
}
|
|
3267
|
+
};
|
|
3268
|
+
}
|
|
3269
|
+
|
|
3270
|
+
// 检查资源类型(单个预约 vs 多个预约)
|
|
3271
|
+
// 从商品配置中获取资源类型信息
|
|
3272
|
+
var resourceTypeConfig = null;
|
|
3273
|
+
var _iterator4 = _createForOfIteratorHelper(items),
|
|
3274
|
+
_step4;
|
|
3275
|
+
try {
|
|
3276
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
3277
|
+
var _cartItem$_productOri15;
|
|
3278
|
+
var cartItem = _step4.value;
|
|
3279
|
+
if ((_cartItem$_productOri15 = cartItem._productOrigin) !== null && _cartItem$_productOri15 !== void 0 && (_cartItem$_productOri15 = _cartItem$_productOri15.product_resource) !== null && _cartItem$_productOri15 !== void 0 && _cartItem$_productOri15.resources) {
|
|
3280
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
|
|
3281
|
+
return r.code === resourceCode && r.status === 1;
|
|
3282
|
+
});
|
|
3283
|
+
if (resourceTypeConfig) break;
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
} catch (err) {
|
|
3287
|
+
_iterator4.e(err);
|
|
3288
|
+
} finally {
|
|
3289
|
+
_iterator4.f();
|
|
3290
|
+
}
|
|
3291
|
+
var isMultipleBooking = ((_resourceTypeConfig2 = resourceTypeConfig) === null || _resourceTypeConfig2 === void 0 ? void 0 : _resourceTypeConfig2.type) === 'multiple';
|
|
3292
|
+
var totalAvailable;
|
|
3293
|
+
var requiredAmount;
|
|
3294
|
+
var availableAmount;
|
|
3295
|
+
if (isMultipleBooking) {
|
|
3296
|
+
// 多个预约:计算容量
|
|
3297
|
+
totalAvailable = resourcesOfThisType.reduce(function (sum, resource) {
|
|
3298
|
+
return sum + (resource.capacity || 0);
|
|
3299
|
+
}, 0);
|
|
3300
|
+
requiredAmount = items.reduce(function (sum, cartItem) {
|
|
3301
|
+
var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
|
|
3302
|
+
currentCapacity = _getCapacityInfoByCar8.currentCapacity;
|
|
3303
|
+
return sum + currentCapacity;
|
|
3304
|
+
}, 0);
|
|
3305
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
3306
|
+
} else {
|
|
3307
|
+
// 单个预约:计算资源个数
|
|
3308
|
+
totalAvailable = resourcesOfThisType.length;
|
|
3309
|
+
requiredAmount = items.reduce(function (sum, cartItem) {
|
|
3310
|
+
return sum + (cartItem.num || 1);
|
|
3311
|
+
}, 0);
|
|
3312
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
3313
|
+
}
|
|
3314
|
+
|
|
3315
|
+
// 记录资源容量信息
|
|
3316
|
+
resourceCapacityInfo.push({
|
|
3317
|
+
code: resourceCode,
|
|
3318
|
+
available: availableAmount,
|
|
3319
|
+
total: totalAvailable,
|
|
3320
|
+
required: requiredAmount,
|
|
3321
|
+
isMultiple: isMultipleBooking
|
|
3322
|
+
});
|
|
3323
|
+
availableCountsByResourceType.push(availableAmount);
|
|
3324
|
+
|
|
3325
|
+
// 检查是否有容量问题
|
|
3326
|
+
if (requiredAmount > totalAvailable) {
|
|
3327
|
+
hasCapacityIssue = true;
|
|
3328
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " ").concat(isMultipleBooking ? '容量' : '资源数量', "\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredAmount, ", \u603B\u5171 ").concat(totalAvailable));
|
|
3329
|
+
}
|
|
3330
|
+
|
|
3331
|
+
// 为通过检测的商品分配一个公共可用时间段
|
|
3332
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u8D44\u6E90\u65F6\u95F4\u4FE1\u606F:"), resourcesOfThisType.map(function (r) {
|
|
3333
|
+
return {
|
|
3334
|
+
id: r.id,
|
|
3335
|
+
times: r.times.map(function (t) {
|
|
3336
|
+
return "".concat(t.start_at, " - ").concat(t.end_at);
|
|
3337
|
+
})
|
|
3338
|
+
};
|
|
3339
|
+
}));
|
|
3340
|
+
|
|
3341
|
+
// 找到所有资源都可用的时间段
|
|
3342
|
+
var commonTimeSlots = _this16.findCommonAvailableTimeSlots(resourcesOfThisType);
|
|
3343
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonTimeSlots);
|
|
3344
|
+
if (commonTimeSlots.length === 0) {
|
|
3345
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4\u6BB5"));
|
|
3346
|
+
return {
|
|
3347
|
+
v: {
|
|
3348
|
+
success: false,
|
|
3349
|
+
minAvailableCount: 0
|
|
3350
|
+
}
|
|
3351
|
+
};
|
|
3352
|
+
}
|
|
3353
|
+
|
|
3354
|
+
// 使用第一个公共可用时间段,但只处理未处理过的商品
|
|
3355
|
+
var firstCommonSlot = commonTimeSlots[0];
|
|
3356
|
+
console.log("\u4F7F\u7528\u516C\u5171\u65F6\u95F4\u6BB5: ".concat(firstCommonSlot.startTime, " - ").concat(firstCommonSlot.endTime));
|
|
3357
|
+
items.forEach(function (cartItem) {
|
|
3358
|
+
// 只处理未处理过的商品,避免重复添加
|
|
3359
|
+
if (!processedCartItemIds.has(cartItem._id)) {
|
|
3360
|
+
processedCartItemIds.add(cartItem._id);
|
|
3361
|
+
var processedItem = _objectSpread(_objectSpread({}, cartItem), {}, {
|
|
3362
|
+
start_date: dateRange[0].date,
|
|
3363
|
+
start_time: firstCommonSlot.startTime,
|
|
3364
|
+
end_time: firstCommonSlot.endTime,
|
|
3365
|
+
end_date: dateRange[0].date
|
|
3366
|
+
});
|
|
3367
|
+
processedItemsWithoutTime.push(processedItem);
|
|
3368
|
+
}
|
|
3369
|
+
});
|
|
3370
|
+
},
|
|
3371
|
+
_ret5;
|
|
3372
|
+
for (var _i3 = 0, _Object$entries3 = Object.entries(itemsByResourceType); _i3 < _Object$entries3.length; _i3++) {
|
|
3373
|
+
_ret5 = _loop5();
|
|
3374
|
+
if (_ret5) return _ret5.v;
|
|
3375
|
+
}
|
|
3376
|
+
|
|
3377
|
+
// 如果有容量问题,找出限制最严格的资源类型,返回其总容量
|
|
3378
|
+
if (hasCapacityIssue) {
|
|
3379
|
+
// 找出超出容量的资源类型中,总容量最少的那个
|
|
3380
|
+
var overCapacityResources = resourceCapacityInfo.filter(function (info) {
|
|
3381
|
+
return info.required > info.total;
|
|
3382
|
+
});
|
|
3383
|
+
if (overCapacityResources.length > 0) {
|
|
3384
|
+
var _minTotalCapacity2 = Math.min.apply(Math, _toConsumableArray(overCapacityResources.map(function (info) {
|
|
3385
|
+
return info.total;
|
|
3386
|
+
})));
|
|
3387
|
+
return {
|
|
3388
|
+
success: false,
|
|
3389
|
+
minAvailableCount: _minTotalCapacity2
|
|
3390
|
+
};
|
|
3391
|
+
}
|
|
3392
|
+
// 如果没有超出容量的(理论上不应该发生),返回总容量最少的
|
|
3393
|
+
var minTotalCapacity = Math.min.apply(Math, _toConsumableArray(resourceCapacityInfo.map(function (info) {
|
|
3394
|
+
return info.total;
|
|
3395
|
+
})));
|
|
3396
|
+
return {
|
|
3397
|
+
success: false,
|
|
3398
|
+
minAvailableCount: minTotalCapacity
|
|
3399
|
+
};
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
|
|
3403
|
+
// 合并所有商品(有时间的 + 处理后的没有时间的)
|
|
3404
|
+
var allProcessedItems = [].concat(itemsWithTime, processedItemsWithoutTime);
|
|
3405
|
+
|
|
3406
|
+
// 按时间段分组检查
|
|
3407
|
+
var cartItemsByTimeSlot = {};
|
|
3408
|
+
allProcessedItems.forEach(function (cartItem) {
|
|
3409
|
+
if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date) return;
|
|
3410
|
+
var timeSlotKey = "".concat(cartItem.start_date, "_").concat(cartItem.start_time, "_").concat(cartItem.end_date || cartItem.start_date, "_").concat(cartItem.end_time);
|
|
3411
|
+
if (!cartItemsByTimeSlot[timeSlotKey]) {
|
|
3412
|
+
cartItemsByTimeSlot[timeSlotKey] = [];
|
|
3413
|
+
}
|
|
3414
|
+
cartItemsByTimeSlot[timeSlotKey].push(cartItem);
|
|
3415
|
+
});
|
|
3416
|
+
// 检查每个时间段是否有足够的资源容量
|
|
3417
|
+
var _loop6 = function _loop6() {
|
|
3418
|
+
var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
|
|
3419
|
+
timeSlotKey = _Object$entries4$_i[0],
|
|
3420
|
+
itemsInTimeSlot = _Object$entries4$_i[1];
|
|
3421
|
+
var _timeSlotKey$split3 = timeSlotKey.split('_'),
|
|
3422
|
+
_timeSlotKey$split4 = _slicedToArray(_timeSlotKey$split3, 4),
|
|
3423
|
+
startDate = _timeSlotKey$split4[0],
|
|
3424
|
+
startTime = _timeSlotKey$split4[1],
|
|
3425
|
+
endDate = _timeSlotKey$split4[2],
|
|
3426
|
+
endTime = _timeSlotKey$split4[3];
|
|
3427
|
+
var timeSlotStart = "".concat(startDate, " ").concat(startTime);
|
|
3428
|
+
var timeSlotEnd = "".concat(endDate, " ").concat(endTime);
|
|
3429
|
+
|
|
3430
|
+
// 获取这个时间段所有商品涉及的资源
|
|
3431
|
+
var allResourcesForTimeSlot = [];
|
|
3432
|
+
var resourcesIdSet = new Set();
|
|
3433
|
+
|
|
3434
|
+
// 获取资源数据
|
|
3435
|
+
var dateRange = _this16.store.date.getDateRange();
|
|
3436
|
+
var resourcesDates = _this16.store.date.getDateList();
|
|
3437
|
+
var targetResourceDate = resourcesDates.find(function (n) {
|
|
3438
|
+
return n.date === startDate;
|
|
3439
|
+
});
|
|
3440
|
+
if (!targetResourceDate) return 0; // continue
|
|
3441
|
+
var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
|
|
3442
|
+
itemsInTimeSlot.forEach(function (cartItem) {
|
|
3443
|
+
if (!cartItem._productOrigin) return;
|
|
3444
|
+
|
|
3445
|
+
// 获取商品的资源配置
|
|
3446
|
+
var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
3447
|
+
productResourceIds.forEach(function (resourceId) {
|
|
3448
|
+
if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
|
|
3449
|
+
resourcesIdSet.add(resourceId);
|
|
3450
|
+
allResourcesForTimeSlot.push(resourcesMap[resourceId]);
|
|
3451
|
+
}
|
|
3452
|
+
});
|
|
3453
|
+
});
|
|
3454
|
+
|
|
3455
|
+
// 按资源类型分组检查容量
|
|
3456
|
+
if (!checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
|
|
3457
|
+
// 如果有可用数量记录,返回最小值;否则返回 0
|
|
3458
|
+
var _minAvailableCount2 = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
|
|
3459
|
+
return {
|
|
3460
|
+
v: {
|
|
3461
|
+
success: false,
|
|
3462
|
+
minAvailableCount: _minAvailableCount2
|
|
3463
|
+
}
|
|
3464
|
+
};
|
|
3465
|
+
}
|
|
3466
|
+
},
|
|
3467
|
+
_ret6;
|
|
3468
|
+
for (var _i4 = 0, _Object$entries4 = Object.entries(cartItemsByTimeSlot); _i4 < _Object$entries4.length; _i4++) {
|
|
3469
|
+
_ret6 = _loop6();
|
|
3470
|
+
if (_ret6 === 0) continue;
|
|
3471
|
+
if (_ret6) return _ret6.v;
|
|
3472
|
+
}
|
|
3473
|
+
|
|
3474
|
+
// 全部通过检测,返回成功和最小可用数量
|
|
3475
|
+
var minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
|
|
3476
|
+
return {
|
|
3477
|
+
success: true,
|
|
3478
|
+
minAvailableCount: minAvailableCount
|
|
3479
|
+
};
|
|
3480
|
+
}
|
|
3075
3481
|
}, {
|
|
3076
3482
|
key: "setOtherData",
|
|
3077
3483
|
value: function setOtherData(key, value) {
|
|
@@ -3143,7 +3549,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3143
3549
|
}, {
|
|
3144
3550
|
key: "getResourcesByCartItemAndCode",
|
|
3145
3551
|
value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
|
|
3146
|
-
var _cartItem$
|
|
3552
|
+
var _cartItem$_productOri16;
|
|
3147
3553
|
var dateRange = this.store.date.getDateRange();
|
|
3148
3554
|
var resources = [];
|
|
3149
3555
|
if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
|
|
@@ -3166,16 +3572,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3166
3572
|
});
|
|
3167
3573
|
if (!cartItem) return [];
|
|
3168
3574
|
var selectedResources = [];
|
|
3169
|
-
var
|
|
3170
|
-
currentCapacity =
|
|
3171
|
-
formatCapacity =
|
|
3575
|
+
var _getCapacityInfoByCar9 = getCapacityInfoByCartItem(cartItem),
|
|
3576
|
+
currentCapacity = _getCapacityInfoByCar9.currentCapacity,
|
|
3577
|
+
formatCapacity = _getCapacityInfoByCar9.formatCapacity;
|
|
3172
3578
|
cartItem._origin.metadata.capacity = formatCapacity;
|
|
3173
3579
|
if (cartItem.holder_id) {
|
|
3174
3580
|
selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
|
|
3175
3581
|
} else {
|
|
3176
3582
|
selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
|
|
3177
3583
|
}
|
|
3178
|
-
var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$
|
|
3584
|
+
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
3585
|
var targetResource = productResources.find(function (resource) {
|
|
3180
3586
|
return resource.code === resourceCode;
|
|
3181
3587
|
});
|
|
@@ -3198,7 +3604,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3198
3604
|
});
|
|
3199
3605
|
if (mTimes.length === 0) return false;
|
|
3200
3606
|
var canUseArr = mTimes.map(function (item) {
|
|
3201
|
-
var _cartItem$
|
|
3607
|
+
var _cartItem$_productOri17;
|
|
3202
3608
|
var res = getIsUsableByTimeItem({
|
|
3203
3609
|
timeSlice: {
|
|
3204
3610
|
start_time: startTime.format('HH:mm'),
|
|
@@ -3210,7 +3616,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3210
3616
|
resource: m,
|
|
3211
3617
|
currentCount: currentCapacity || 0,
|
|
3212
3618
|
resourcesUseableMap: resourcesUseableMap,
|
|
3213
|
-
cut_off_time: (_cartItem$
|
|
3619
|
+
cut_off_time: (_cartItem$_productOri17 = cartItem._productOrigin) === null || _cartItem$_productOri17 === void 0 ? void 0 : _cartItem$_productOri17.cut_off_time
|
|
3214
3620
|
});
|
|
3215
3621
|
if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
|
|
3216
3622
|
resourcesUseableMap[m.id] = res.usable;
|
|
@@ -3224,12 +3630,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3224
3630
|
});
|
|
3225
3631
|
} else {
|
|
3226
3632
|
targetResource.renderList = targetResource.renderList.filter(function (n) {
|
|
3227
|
-
var _cartItem$
|
|
3633
|
+
var _cartItem$_productOri18;
|
|
3228
3634
|
var recordCount = n.capacity || 0;
|
|
3229
3635
|
if (n.onlyComputed) return false;
|
|
3230
3636
|
var timeSlots = getTimeSlicesByResource({
|
|
3231
3637
|
resource: n,
|
|
3232
|
-
duration: ((_cartItem$
|
|
3638
|
+
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
3639
|
split: 10,
|
|
3234
3640
|
currentDate: dateRange[0].date
|
|
3235
3641
|
});
|
|
@@ -3247,12 +3653,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3247
3653
|
}, {
|
|
3248
3654
|
key: "getTimeslotsScheduleByDateRange",
|
|
3249
3655
|
value: (function () {
|
|
3250
|
-
var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(
|
|
3251
|
-
var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results,
|
|
3656
|
+
var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref12) {
|
|
3657
|
+
var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i5, _dates, date;
|
|
3252
3658
|
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
3253
3659
|
while (1) switch (_context26.prev = _context26.next) {
|
|
3254
3660
|
case 0:
|
|
3255
|
-
startDate =
|
|
3661
|
+
startDate = _ref12.startDate, endDate = _ref12.endDate, scheduleIds = _ref12.scheduleIds, resources = _ref12.resources;
|
|
3256
3662
|
console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
|
|
3257
3663
|
startDate: startDate,
|
|
3258
3664
|
endDate: endDate,
|
|
@@ -3269,8 +3675,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3269
3675
|
}
|
|
3270
3676
|
// 如果不支持 Web Worker,使用同步方式处理
|
|
3271
3677
|
results = {};
|
|
3272
|
-
for (
|
|
3273
|
-
date = _dates[
|
|
3678
|
+
for (_i5 = 0, _dates = dates; _i5 < _dates.length; _i5++) {
|
|
3679
|
+
date = _dates[_i5];
|
|
3274
3680
|
results[date] = this.getTimeslotBySchedule({
|
|
3275
3681
|
date: date,
|
|
3276
3682
|
scheduleIds: scheduleIds,
|
|
@@ -3311,7 +3717,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3311
3717
|
openResources,
|
|
3312
3718
|
allProductResources,
|
|
3313
3719
|
targetSchedules,
|
|
3314
|
-
|
|
3720
|
+
_loop7,
|
|
3315
3721
|
_args28 = arguments;
|
|
3316
3722
|
return _regeneratorRuntime().wrap(function _callee27$(_context28) {
|
|
3317
3723
|
while (1) switch (_context28.prev = _context28.next) {
|
|
@@ -3388,9 +3794,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3388
3794
|
}
|
|
3389
3795
|
});
|
|
3390
3796
|
targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
|
|
3391
|
-
|
|
3797
|
+
_loop7 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop7() {
|
|
3392
3798
|
var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
|
|
3393
|
-
return _regeneratorRuntime().wrap(function
|
|
3799
|
+
return _regeneratorRuntime().wrap(function _loop7$(_context27) {
|
|
3394
3800
|
while (1) switch (_context27.prev = _context27.next) {
|
|
3395
3801
|
case 0:
|
|
3396
3802
|
currentDateStr = currentDate.format('YYYY-MM-DD');
|
|
@@ -3493,14 +3899,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3493
3899
|
case "end":
|
|
3494
3900
|
return _context27.stop();
|
|
3495
3901
|
}
|
|
3496
|
-
},
|
|
3902
|
+
}, _loop7);
|
|
3497
3903
|
});
|
|
3498
3904
|
case 28:
|
|
3499
3905
|
if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
|
|
3500
3906
|
_context28.next = 34;
|
|
3501
3907
|
break;
|
|
3502
3908
|
}
|
|
3503
|
-
return _context28.delegateYield(
|
|
3909
|
+
return _context28.delegateYield(_loop7(), "t0", 30);
|
|
3504
3910
|
case 30:
|
|
3505
3911
|
if (!_context28.t0) {
|
|
3506
3912
|
_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(): "
|
|
52
|
+
getProductType(): "duration" | "session" | "normal";
|
|
53
53
|
}
|
|
@@ -324,9 +324,18 @@ 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
|
-
getProductTypeById(id: number): Promise<"
|
|
338
|
+
getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
|
|
330
339
|
/**
|
|
331
340
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
332
341
|
*
|
|
@@ -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
|
|
43
|
+
var import_utils2 = require("../../modules/Resource/utils");
|
|
43
44
|
var import_lodash_es = require("lodash-es");
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
var
|
|
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,
|
|
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,
|
|
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,
|
|
529
|
+
if ((0, import_utils5.areAllNormalProducts)(
|
|
529
530
|
newCartItems.map((n) => n._productOrigin)
|
|
530
531
|
)) {
|
|
531
532
|
type = "virtual";
|
|
@@ -635,7 +636,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
635
636
|
addItemParams.account = account;
|
|
636
637
|
}
|
|
637
638
|
this.addProductCheck({ date });
|
|
638
|
-
|
|
639
|
+
if (addItemParams.quantity > 1) {
|
|
640
|
+
for (let i = 0; i < addItemParams.quantity; i++) {
|
|
641
|
+
const newAddItemParams = (0, import_lodash_es.cloneDeep)(addItemParams);
|
|
642
|
+
newAddItemParams.quantity = 1;
|
|
643
|
+
this.store.cart.addItem(newAddItemParams);
|
|
644
|
+
}
|
|
645
|
+
} else {
|
|
646
|
+
this.store.cart.addItem(addItemParams);
|
|
647
|
+
}
|
|
639
648
|
return { success: true };
|
|
640
649
|
}
|
|
641
650
|
/**
|
|
@@ -648,7 +657,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
648
657
|
date
|
|
649
658
|
}) {
|
|
650
659
|
if (date) {
|
|
651
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
660
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
652
661
|
const cartItemsByDate = cartItems.filter(
|
|
653
662
|
(n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
|
|
654
663
|
);
|
|
@@ -810,7 +819,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
810
819
|
* @returns 不符合条件的购物车商品ID列表
|
|
811
820
|
*/
|
|
812
821
|
checkCartItems(type) {
|
|
813
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
822
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
814
823
|
const errorCartItemIds = [];
|
|
815
824
|
cartItems.forEach((cartItem) => {
|
|
816
825
|
const result = this.store.cart.checkCartItemByType(cartItem, type);
|
|
@@ -844,7 +853,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
844
853
|
resources.push(...n.resource);
|
|
845
854
|
});
|
|
846
855
|
}
|
|
847
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
856
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
848
857
|
if (!resources.length) {
|
|
849
858
|
const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
|
|
850
859
|
if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
|
|
@@ -860,7 +869,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
860
869
|
});
|
|
861
870
|
}
|
|
862
871
|
}
|
|
863
|
-
const resourcesMap = (0,
|
|
872
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
864
873
|
const arr = [];
|
|
865
874
|
cartItems.forEach((cartItem) => {
|
|
866
875
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
@@ -989,14 +998,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
989
998
|
*/
|
|
990
999
|
getResourcesListByCartItem(id) {
|
|
991
1000
|
var _a, _b;
|
|
992
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
1001
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
993
1002
|
const dateRange = this.store.date.getDateRange();
|
|
994
1003
|
const resources = [];
|
|
995
1004
|
dateRange.forEach((n) => {
|
|
996
1005
|
if (n.resource)
|
|
997
1006
|
resources.push(...n.resource);
|
|
998
1007
|
});
|
|
999
|
-
const resourcesMap = (0,
|
|
1008
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
|
|
1000
1009
|
const targetCartItem = cartItems.find((n) => n._id === id);
|
|
1001
1010
|
if (!targetCartItem) {
|
|
1002
1011
|
throw new Error(`没有找到${id}购物车商品`);
|
|
@@ -1053,7 +1062,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1053
1062
|
capacity
|
|
1054
1063
|
}) {
|
|
1055
1064
|
var _a, _b, _c;
|
|
1056
|
-
if ((0,
|
|
1065
|
+
if ((0, import_utils5.isNormalProduct)(cartItem._productOrigin)) {
|
|
1057
1066
|
return {};
|
|
1058
1067
|
}
|
|
1059
1068
|
const dateRange = this.store.date.getDateRange();
|
|
@@ -1088,7 +1097,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1088
1097
|
});
|
|
1089
1098
|
}
|
|
1090
1099
|
}
|
|
1091
|
-
const resourcesMap = (0,
|
|
1100
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(AllResources));
|
|
1092
1101
|
const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
1093
1102
|
const selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1094
1103
|
allCartItems,
|
|
@@ -1169,7 +1178,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1169
1178
|
selectedResource: targetResource
|
|
1170
1179
|
};
|
|
1171
1180
|
} else {
|
|
1172
|
-
const resourcesMap2 = (0,
|
|
1181
|
+
const resourcesMap2 = (0, import_utils2.getResourcesMap)(resources);
|
|
1173
1182
|
const resourceIds = resources.map((n) => n.id);
|
|
1174
1183
|
const timeSlots2 = (0, import_resources.getTimeSlicesByResources)({
|
|
1175
1184
|
resourceIds,
|
|
@@ -1307,7 +1316,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1307
1316
|
currentResourcesRenderList.push(...n.renderList || []);
|
|
1308
1317
|
}
|
|
1309
1318
|
});
|
|
1310
|
-
const resourcesMap = (0,
|
|
1319
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(currentResourcesRenderList);
|
|
1311
1320
|
if (item.holder_id) {
|
|
1312
1321
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1313
1322
|
allCartItems,
|
|
@@ -1372,7 +1381,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1372
1381
|
}
|
|
1373
1382
|
});
|
|
1374
1383
|
};
|
|
1375
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
1384
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
1376
1385
|
if (cartItems == null ? void 0 : cartItems[0].holder_id) {
|
|
1377
1386
|
accountList.forEach((account) => {
|
|
1378
1387
|
const cartItems2 = this.store.cart.getCartByAccount(account.getId());
|
|
@@ -1388,7 +1397,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1388
1397
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1389
1398
|
let dateRange = this.store.date.getDateRange();
|
|
1390
1399
|
const resources = [];
|
|
1391
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
1400
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
1392
1401
|
const resourceIds = [];
|
|
1393
1402
|
let resourcesTypeId = void 0;
|
|
1394
1403
|
let isSingleResource = false;
|
|
@@ -1426,7 +1435,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1426
1435
|
}
|
|
1427
1436
|
});
|
|
1428
1437
|
}
|
|
1429
|
-
const resourcesMap = (0,
|
|
1438
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
|
|
1430
1439
|
let duration = 0;
|
|
1431
1440
|
const accountList = this.store.accountList.getAccounts();
|
|
1432
1441
|
const checkDuration = (cartItems2) => {
|
|
@@ -1525,7 +1534,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1525
1534
|
// 提交时间切片,绑定到对应购物车的商品上,更新购物车---只有 duration 商品
|
|
1526
1535
|
submitTimeSlot(timeSlots) {
|
|
1527
1536
|
var _a, _b;
|
|
1528
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
1537
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
1529
1538
|
const allResources = this.store.date.getResourcesListByDate(
|
|
1530
1539
|
timeSlots.start_at.format("YYYY-MM-DD")
|
|
1531
1540
|
);
|
|
@@ -1603,7 +1612,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1603
1612
|
getScheduleDataByIds(scheduleIds) {
|
|
1604
1613
|
const targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
|
|
1605
1614
|
const targetSchedulesData = targetSchedules.map((item) => {
|
|
1606
|
-
return (0,
|
|
1615
|
+
return (0, import_utils3.calcCalendarDataByScheduleResult)(item);
|
|
1607
1616
|
});
|
|
1608
1617
|
const newSchedule = {};
|
|
1609
1618
|
targetSchedulesData.forEach((item) => {
|
|
@@ -1675,7 +1684,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1675
1684
|
const resourcesDates = this.store.date.getDateList();
|
|
1676
1685
|
const targetResourceDate = resourcesDates.find((n) => n.date === date);
|
|
1677
1686
|
const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
1678
|
-
const resourcesMap = (0,
|
|
1687
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []);
|
|
1679
1688
|
const selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1680
1689
|
cartItems,
|
|
1681
1690
|
"",
|
|
@@ -1687,12 +1696,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1687
1696
|
selectedResources,
|
|
1688
1697
|
1
|
|
1689
1698
|
);
|
|
1690
|
-
const minTimeMaxTime = (0,
|
|
1699
|
+
const minTimeMaxTime = (0, import_utils3.calcMinTimeMaxTimeBySchedules)(
|
|
1691
1700
|
targetSchedules,
|
|
1692
1701
|
{},
|
|
1693
1702
|
date
|
|
1694
1703
|
);
|
|
1695
|
-
const scheduleTimeSlots = (0,
|
|
1704
|
+
const scheduleTimeSlots = (0, import_utils3.getAllSortedDateRanges)(minTimeMaxTime);
|
|
1696
1705
|
let allProductResources = productResources.flatMap((n) => n.renderList);
|
|
1697
1706
|
allProductResources.sort((a, b) => {
|
|
1698
1707
|
var _a2, _b2, _c2, _d2;
|
|
@@ -1808,7 +1817,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1808
1817
|
otherSameTimesCartItems.forEach((m) => {
|
|
1809
1818
|
var _a2, _b2;
|
|
1810
1819
|
const productResources2 = (0, import_resources.getResourcesByProduct)(
|
|
1811
|
-
(0,
|
|
1820
|
+
(0, import_utils2.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []),
|
|
1812
1821
|
((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) || [],
|
|
1813
1822
|
selectedResources,
|
|
1814
1823
|
1
|
|
@@ -1955,7 +1964,245 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1955
1964
|
const targetResourceDate = resourcesDates.find((n) => n.date === dateRange[0].date);
|
|
1956
1965
|
if (!targetResourceDate)
|
|
1957
1966
|
return { success: false, minAvailableCount: 0 };
|
|
1958
|
-
const resourcesMap = (0,
|
|
1967
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
|
|
1968
|
+
const resourceCodeToFormIdMap = {};
|
|
1969
|
+
Object.values(itemsByResourceType).flat().forEach((cartItem) => {
|
|
1970
|
+
var _a2, _b2;
|
|
1971
|
+
if ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) {
|
|
1972
|
+
cartItem._productOrigin.product_resource.resources.forEach((resourceConfig) => {
|
|
1973
|
+
var _a3, _b3;
|
|
1974
|
+
if (resourceConfig.status === 1 && resourceConfig.code) {
|
|
1975
|
+
const formId = ((_a3 = resourceConfig.id) == null ? void 0 : _a3.toString()) || ((_b3 = resourceConfig.resource_type_id) == null ? void 0 : _b3.toString());
|
|
1976
|
+
if (formId) {
|
|
1977
|
+
resourceCodeToFormIdMap[resourceConfig.code] = formId;
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
});
|
|
1981
|
+
}
|
|
1982
|
+
});
|
|
1983
|
+
let hasCapacityIssue = false;
|
|
1984
|
+
const resourceCapacityInfo = [];
|
|
1985
|
+
const processedCartItemIds = /* @__PURE__ */ new Set();
|
|
1986
|
+
for (const [resourceCode, items] of Object.entries(itemsByResourceType)) {
|
|
1987
|
+
const targetFormId = resourceCodeToFormIdMap[resourceCode];
|
|
1988
|
+
if (!targetFormId) {
|
|
1989
|
+
console.log(`资源类型 ${resourceCode} 找不到对应的 form_id`);
|
|
1990
|
+
return { success: false, minAvailableCount: 0 };
|
|
1991
|
+
}
|
|
1992
|
+
const resourcesOfThisType = [];
|
|
1993
|
+
items.forEach((cartItem) => {
|
|
1994
|
+
const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
|
|
1995
|
+
productResourceIds.forEach((resourceId) => {
|
|
1996
|
+
var _a2;
|
|
1997
|
+
const resource = resourcesMap[resourceId];
|
|
1998
|
+
if (resource && ((_a2 = resource.form_id) == null ? void 0 : _a2.toString()) === targetFormId) {
|
|
1999
|
+
if (!resourcesOfThisType.find((r) => r.id === resource.id)) {
|
|
2000
|
+
resourcesOfThisType.push(resource);
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
});
|
|
2004
|
+
});
|
|
2005
|
+
if (resourcesOfThisType.length === 0) {
|
|
2006
|
+
console.log(`资源类型 ${resourceCode} 没有找到可用资源`);
|
|
2007
|
+
return { success: false, minAvailableCount: 0 };
|
|
2008
|
+
}
|
|
2009
|
+
let resourceTypeConfig = null;
|
|
2010
|
+
for (const cartItem of items) {
|
|
2011
|
+
if ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) {
|
|
2012
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(
|
|
2013
|
+
(r) => r.code === resourceCode && r.status === 1
|
|
2014
|
+
);
|
|
2015
|
+
if (resourceTypeConfig)
|
|
2016
|
+
break;
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
const isMultipleBooking = (resourceTypeConfig == null ? void 0 : resourceTypeConfig.type) === "multiple";
|
|
2020
|
+
let totalAvailable;
|
|
2021
|
+
let requiredAmount;
|
|
2022
|
+
let availableAmount;
|
|
2023
|
+
if (isMultipleBooking) {
|
|
2024
|
+
totalAvailable = resourcesOfThisType.reduce((sum, resource) => {
|
|
2025
|
+
return sum + (resource.capacity || 0);
|
|
2026
|
+
}, 0);
|
|
2027
|
+
requiredAmount = items.reduce((sum, cartItem) => {
|
|
2028
|
+
const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
|
|
2029
|
+
return sum + currentCapacity;
|
|
2030
|
+
}, 0);
|
|
2031
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
2032
|
+
} else {
|
|
2033
|
+
totalAvailable = resourcesOfThisType.length;
|
|
2034
|
+
requiredAmount = items.reduce((sum, cartItem) => {
|
|
2035
|
+
return sum + (cartItem.num || 1);
|
|
2036
|
+
}, 0);
|
|
2037
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
2038
|
+
}
|
|
2039
|
+
resourceCapacityInfo.push({
|
|
2040
|
+
code: resourceCode,
|
|
2041
|
+
available: availableAmount,
|
|
2042
|
+
total: totalAvailable,
|
|
2043
|
+
required: requiredAmount,
|
|
2044
|
+
isMultiple: isMultipleBooking
|
|
2045
|
+
});
|
|
2046
|
+
availableCountsByResourceType.push(availableAmount);
|
|
2047
|
+
if (requiredAmount > totalAvailable) {
|
|
2048
|
+
hasCapacityIssue = true;
|
|
2049
|
+
console.log(`资源类型 ${resourceCode} ${isMultipleBooking ? "容量" : "资源数量"}不足: 需要 ${requiredAmount}, 总共 ${totalAvailable}`);
|
|
2050
|
+
}
|
|
2051
|
+
console.log(`资源类型 ${resourceCode} 的资源时间信息:`, resourcesOfThisType.map((r) => ({
|
|
2052
|
+
id: r.id,
|
|
2053
|
+
times: r.times.map((t) => `${t.start_at} - ${t.end_at}`)
|
|
2054
|
+
})));
|
|
2055
|
+
const commonTimeSlots = this.findCommonAvailableTimeSlots(resourcesOfThisType);
|
|
2056
|
+
console.log(`资源类型 ${resourceCode} 的公共时间段:`, commonTimeSlots);
|
|
2057
|
+
if (commonTimeSlots.length === 0) {
|
|
2058
|
+
console.log(`资源类型 ${resourceCode} 没有公共可用时间段`);
|
|
2059
|
+
return { success: false, minAvailableCount: 0 };
|
|
2060
|
+
}
|
|
2061
|
+
const firstCommonSlot = commonTimeSlots[0];
|
|
2062
|
+
console.log(`使用公共时间段: ${firstCommonSlot.startTime} - ${firstCommonSlot.endTime}`);
|
|
2063
|
+
items.forEach((cartItem) => {
|
|
2064
|
+
if (!processedCartItemIds.has(cartItem._id)) {
|
|
2065
|
+
processedCartItemIds.add(cartItem._id);
|
|
2066
|
+
const processedItem = {
|
|
2067
|
+
...cartItem,
|
|
2068
|
+
start_date: dateRange[0].date,
|
|
2069
|
+
start_time: firstCommonSlot.startTime,
|
|
2070
|
+
end_time: firstCommonSlot.endTime,
|
|
2071
|
+
end_date: dateRange[0].date
|
|
2072
|
+
};
|
|
2073
|
+
processedItemsWithoutTime.push(processedItem);
|
|
2074
|
+
}
|
|
2075
|
+
});
|
|
2076
|
+
}
|
|
2077
|
+
if (hasCapacityIssue) {
|
|
2078
|
+
const overCapacityResources = resourceCapacityInfo.filter((info) => info.required > info.total);
|
|
2079
|
+
if (overCapacityResources.length > 0) {
|
|
2080
|
+
const minTotalCapacity2 = Math.min(...overCapacityResources.map((info) => info.total));
|
|
2081
|
+
return { success: false, minAvailableCount: minTotalCapacity2 };
|
|
2082
|
+
}
|
|
2083
|
+
const minTotalCapacity = Math.min(...resourceCapacityInfo.map((info) => info.total));
|
|
2084
|
+
return { success: false, minAvailableCount: minTotalCapacity };
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
const allProcessedItems = [...itemsWithTime, ...processedItemsWithoutTime];
|
|
2088
|
+
const cartItemsByTimeSlot = {};
|
|
2089
|
+
allProcessedItems.forEach((cartItem) => {
|
|
2090
|
+
if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date)
|
|
2091
|
+
return;
|
|
2092
|
+
const timeSlotKey = `${cartItem.start_date}_${cartItem.start_time}_${cartItem.end_date || cartItem.start_date}_${cartItem.end_time}`;
|
|
2093
|
+
if (!cartItemsByTimeSlot[timeSlotKey]) {
|
|
2094
|
+
cartItemsByTimeSlot[timeSlotKey] = [];
|
|
2095
|
+
}
|
|
2096
|
+
cartItemsByTimeSlot[timeSlotKey].push(cartItem);
|
|
2097
|
+
});
|
|
2098
|
+
for (const [timeSlotKey, itemsInTimeSlot] of Object.entries(cartItemsByTimeSlot)) {
|
|
2099
|
+
const [startDate, startTime, endDate, endTime] = timeSlotKey.split("_");
|
|
2100
|
+
const timeSlotStart = `${startDate} ${startTime}`;
|
|
2101
|
+
const timeSlotEnd = `${endDate} ${endTime}`;
|
|
2102
|
+
const allResourcesForTimeSlot = [];
|
|
2103
|
+
const resourcesIdSet = /* @__PURE__ */ new Set();
|
|
2104
|
+
const dateRange = this.store.date.getDateRange();
|
|
2105
|
+
const resourcesDates = this.store.date.getDateList();
|
|
2106
|
+
const targetResourceDate = resourcesDates.find((n) => n.date === startDate);
|
|
2107
|
+
if (!targetResourceDate)
|
|
2108
|
+
continue;
|
|
2109
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
|
|
2110
|
+
itemsInTimeSlot.forEach((cartItem) => {
|
|
2111
|
+
if (!cartItem._productOrigin)
|
|
2112
|
+
return;
|
|
2113
|
+
const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
|
|
2114
|
+
productResourceIds.forEach((resourceId) => {
|
|
2115
|
+
if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
|
|
2116
|
+
resourcesIdSet.add(resourceId);
|
|
2117
|
+
allResourcesForTimeSlot.push(resourcesMap[resourceId]);
|
|
2118
|
+
}
|
|
2119
|
+
});
|
|
2120
|
+
});
|
|
2121
|
+
if (!(0, import_capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
|
|
2122
|
+
const minAvailableCount2 = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
2123
|
+
return { success: false, minAvailableCount: minAvailableCount2 };
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
2127
|
+
return { success: true, minAvailableCount };
|
|
2128
|
+
}
|
|
2129
|
+
/**
|
|
2130
|
+
* 将 ProductData 转换为 CartItem,但不添加到购物车
|
|
2131
|
+
* 参考 addProductToCart 方法的实现
|
|
2132
|
+
*/
|
|
2133
|
+
convertProductToCartItem(product) {
|
|
2134
|
+
const {
|
|
2135
|
+
bundle,
|
|
2136
|
+
options,
|
|
2137
|
+
origin,
|
|
2138
|
+
product_variant_id,
|
|
2139
|
+
quantity = 1
|
|
2140
|
+
} = product || {};
|
|
2141
|
+
const productData = { ...origin, product_variant_id };
|
|
2142
|
+
const processedProduct = (0, import_utils.handleVariantProduct)(productData);
|
|
2143
|
+
const cartItem = {
|
|
2144
|
+
_id: (0, import_utils.getUniqueId)("temp_"),
|
|
2145
|
+
_origin: (0, import_utils.createCartItemOrigin)(),
|
|
2146
|
+
_productOrigin: processedProduct,
|
|
2147
|
+
_productInit: product
|
|
2148
|
+
};
|
|
2149
|
+
const activeAccount = this.getActiveAccount();
|
|
2150
|
+
(0, import_utils.formatProductToCartItem)({
|
|
2151
|
+
cartItem,
|
|
2152
|
+
product: processedProduct,
|
|
2153
|
+
bundle,
|
|
2154
|
+
options,
|
|
2155
|
+
product_variant_id,
|
|
2156
|
+
quantity
|
|
2157
|
+
});
|
|
2158
|
+
return cartItem;
|
|
2159
|
+
}
|
|
2160
|
+
checkMaxDurationCapacityForDetailNums(currentProduct) {
|
|
2161
|
+
var _a, _b;
|
|
2162
|
+
const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
2163
|
+
const currentCartItem = this.convertProductToCartItem(currentProduct);
|
|
2164
|
+
cartItems.push(currentCartItem);
|
|
2165
|
+
if (cartItems.length === 0)
|
|
2166
|
+
return { success: true, minAvailableCount: 0 };
|
|
2167
|
+
const itemsWithTime = [];
|
|
2168
|
+
const itemsWithoutTime = [];
|
|
2169
|
+
const availableCountsByResourceType = [];
|
|
2170
|
+
cartItems.forEach((cartItem) => {
|
|
2171
|
+
if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
|
|
2172
|
+
itemsWithTime.push(cartItem);
|
|
2173
|
+
} else {
|
|
2174
|
+
itemsWithoutTime.push(cartItem);
|
|
2175
|
+
}
|
|
2176
|
+
});
|
|
2177
|
+
const processedItemsWithoutTime = [];
|
|
2178
|
+
if (itemsWithoutTime.length > 0) {
|
|
2179
|
+
const itemsByResourceType = {};
|
|
2180
|
+
itemsWithoutTime.forEach((cartItem) => {
|
|
2181
|
+
var _a2;
|
|
2182
|
+
if (!cartItem._productOrigin)
|
|
2183
|
+
return;
|
|
2184
|
+
const resourceTypes = ((_a2 = cartItem._productOrigin.product_resource) == null ? void 0 : _a2.resources) || [];
|
|
2185
|
+
resourceTypes.forEach((resourceType) => {
|
|
2186
|
+
var _a3;
|
|
2187
|
+
if (resourceType.status === 1) {
|
|
2188
|
+
const resourceCode = resourceType.code || ((_a3 = resourceType.id) == null ? void 0 : _a3.toString());
|
|
2189
|
+
if (!itemsByResourceType[resourceCode]) {
|
|
2190
|
+
itemsByResourceType[resourceCode] = [];
|
|
2191
|
+
}
|
|
2192
|
+
if (!itemsByResourceType[resourceCode].find((item) => item._id === cartItem._id)) {
|
|
2193
|
+
itemsByResourceType[resourceCode].push(cartItem);
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
});
|
|
2197
|
+
});
|
|
2198
|
+
const dateRange = this.store.date.getDateRange();
|
|
2199
|
+
if (!dateRange || dateRange.length === 0)
|
|
2200
|
+
return { success: false, minAvailableCount: 0 };
|
|
2201
|
+
const resourcesDates = this.store.date.getDateList();
|
|
2202
|
+
const targetResourceDate = resourcesDates.find((n) => n.date === dateRange[0].date);
|
|
2203
|
+
if (!targetResourceDate)
|
|
2204
|
+
return { success: false, minAvailableCount: 0 };
|
|
2205
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
|
|
1959
2206
|
const resourceCodeToFormIdMap = {};
|
|
1960
2207
|
Object.values(itemsByResourceType).flat().forEach((cartItem) => {
|
|
1961
2208
|
var _a2, _b2;
|
|
@@ -2097,7 +2344,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2097
2344
|
const targetResourceDate = resourcesDates.find((n) => n.date === startDate);
|
|
2098
2345
|
if (!targetResourceDate)
|
|
2099
2346
|
continue;
|
|
2100
|
-
const resourcesMap = (0,
|
|
2347
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
|
|
2101
2348
|
itemsInTimeSlot.forEach((cartItem) => {
|
|
2102
2349
|
if (!cartItem._productOrigin)
|
|
2103
2350
|
return;
|
|
@@ -2168,8 +2415,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2168
2415
|
resources.push(...n.resource);
|
|
2169
2416
|
});
|
|
2170
2417
|
}
|
|
2171
|
-
const resourcesMap = (0,
|
|
2172
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
2418
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
2419
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
2173
2420
|
const cartItem = cartItems.find((item) => item._id === cartItemId);
|
|
2174
2421
|
if (!cartItem)
|
|
2175
2422
|
return [];
|
|
@@ -2382,12 +2629,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2382
2629
|
}
|
|
2383
2630
|
}
|
|
2384
2631
|
if (status === "available") {
|
|
2385
|
-
const minTimeMaxTime = (0,
|
|
2632
|
+
const minTimeMaxTime = (0, import_utils3.calcMinTimeMaxTimeBySchedules)(
|
|
2386
2633
|
targetSchedules,
|
|
2387
2634
|
{},
|
|
2388
2635
|
currentDateStr
|
|
2389
2636
|
);
|
|
2390
|
-
const scheduleTimeSlots = (0,
|
|
2637
|
+
const scheduleTimeSlots = (0, import_utils3.getAllSortedDateRanges)(minTimeMaxTime);
|
|
2391
2638
|
const timesSlotCanUse = scheduleTimeSlots.some((item) => {
|
|
2392
2639
|
const resourcesUseableMap = {};
|
|
2393
2640
|
return openResources.every((resource) => {
|
|
@@ -2444,7 +2691,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2444
2691
|
}
|
|
2445
2692
|
currentDate = (0, import_dayjs.default)(currentDate).add(1, "day");
|
|
2446
2693
|
}
|
|
2447
|
-
dates = (0,
|
|
2694
|
+
dates = (0, import_utils4.handleAvailableDateByResource)(res.data, dates);
|
|
2448
2695
|
this.store.date.setDateList(dates);
|
|
2449
2696
|
if (!this.store.currentProductMeta)
|
|
2450
2697
|
this.store.currentProductMeta = {};
|
|
@@ -2460,11 +2707,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2460
2707
|
};
|
|
2461
2708
|
}
|
|
2462
2709
|
isCartAllNormalProducts() {
|
|
2463
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
2710
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
2464
2711
|
return !cartItems.length;
|
|
2465
2712
|
}
|
|
2466
2713
|
isCartHasDurationProduct() {
|
|
2467
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
2714
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
2468
2715
|
return cartItems.some((n) => {
|
|
2469
2716
|
var _a;
|
|
2470
2717
|
return (_a = n._productOrigin) == null ? void 0 : _a.duration;
|
|
@@ -2473,11 +2720,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2473
2720
|
isTargetNormalProduct(product) {
|
|
2474
2721
|
if (!product)
|
|
2475
2722
|
return false;
|
|
2476
|
-
return (0,
|
|
2723
|
+
return (0, import_utils5.isNormalProduct)(product);
|
|
2477
2724
|
}
|
|
2478
2725
|
isTargetCartIdNormalProduct(id) {
|
|
2479
2726
|
const cartItem = this.store.cart.getItems().find((n) => n._id === id);
|
|
2480
|
-
return cartItem && (0,
|
|
2727
|
+
return cartItem && (0, import_utils5.isNormalProduct)(cartItem._productOrigin);
|
|
2481
2728
|
}
|
|
2482
2729
|
};
|
|
2483
2730
|
// 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
|