@pisell/pisellos 0.0.331 → 0.0.333
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/solution/BookingByStep/index.d.ts +9 -2
- package/dist/solution/BookingByStep/index.js +62 -23
- package/dist/solution/BookingByStep/utils/capacity.d.ts +5 -1
- package/dist/solution/BookingByStep/utils/capacity.js +20 -7
- package/lib/solution/BookingByStep/index.d.ts +9 -2
- package/lib/solution/BookingByStep/index.js +35 -10
- package/lib/solution/BookingByStep/utils/capacity.d.ts +5 -1
- package/lib/solution/BookingByStep/utils/capacity.js +20 -7
- package/package.json +1 -1
|
@@ -329,13 +329,20 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
329
329
|
* 参考 addProductToCart 方法的实现
|
|
330
330
|
*/
|
|
331
331
|
private convertProductToCartItem;
|
|
332
|
-
checkMaxDurationCapacityForDetailNums(
|
|
332
|
+
checkMaxDurationCapacityForDetailNums({ product, date, account, }: {
|
|
333
|
+
product: ProductData;
|
|
334
|
+
date?: {
|
|
335
|
+
startTime: string;
|
|
336
|
+
endTime: string;
|
|
337
|
+
} | null;
|
|
338
|
+
account?: Account | null;
|
|
339
|
+
}): {
|
|
333
340
|
success: boolean;
|
|
334
341
|
minAvailableCount: number;
|
|
335
342
|
};
|
|
336
343
|
setOtherData(key: string, value: any): void;
|
|
337
344
|
getOtherData(key: string): any;
|
|
338
|
-
getProductTypeById(id: number): Promise<"
|
|
345
|
+
getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
|
|
339
346
|
/**
|
|
340
347
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
341
348
|
*
|
|
@@ -30,7 +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
|
+
import { formatProductToCartItem, createCartItemOrigin, getUniqueId, handleVariantProduct, formatDateToCartItem, formatAccountToCartItem } from "../../modules/Cart/utils";
|
|
34
34
|
import { getAvailableProductResources } from "./utils/products";
|
|
35
35
|
import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection, isConflict } from "./utils/resources";
|
|
36
36
|
import dayjs from 'dayjs';
|
|
@@ -1195,8 +1195,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1195
1195
|
this.addProductCheck({
|
|
1196
1196
|
date: date
|
|
1197
1197
|
});
|
|
1198
|
-
// 如果 quantity 大于 1
|
|
1199
|
-
if (addItemParams.quantity > 1) {
|
|
1198
|
+
// 如果 quantity 大于 1,且是预约商品,则进入购物车拆散成多条数据
|
|
1199
|
+
if (addItemParams.quantity > 1 && !isNormalProduct(productData.origin)) {
|
|
1200
1200
|
for (var i = 0; i < addItemParams.quantity; i++) {
|
|
1201
1201
|
var newAddItemParams = cloneDeep(addItemParams);
|
|
1202
1202
|
newAddItemParams.quantity = 1;
|
|
@@ -3057,7 +3057,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3057
3057
|
});
|
|
3058
3058
|
|
|
3059
3059
|
// 按资源类型分组检查容量
|
|
3060
|
-
|
|
3060
|
+
var _checkTimeSlotCapacit = checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot),
|
|
3061
|
+
success = _checkTimeSlotCapacit.success,
|
|
3062
|
+
required = _checkTimeSlotCapacit.required,
|
|
3063
|
+
available = _checkTimeSlotCapacit.available;
|
|
3064
|
+
if (!success) {
|
|
3061
3065
|
// 如果有可用数量记录,返回最小值;否则返回 0
|
|
3062
3066
|
var _minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
|
|
3063
3067
|
return {
|
|
@@ -3089,14 +3093,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3089
3093
|
*/
|
|
3090
3094
|
}, {
|
|
3091
3095
|
key: "convertProductToCartItem",
|
|
3092
|
-
value: function convertProductToCartItem(
|
|
3093
|
-
var
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3096
|
+
value: function convertProductToCartItem(_ref11) {
|
|
3097
|
+
var product = _ref11.product,
|
|
3098
|
+
date = _ref11.date,
|
|
3099
|
+
account = _ref11.account;
|
|
3100
|
+
var _ref12 = product || {},
|
|
3101
|
+
bundle = _ref12.bundle,
|
|
3102
|
+
options = _ref12.options,
|
|
3103
|
+
origin = _ref12.origin,
|
|
3104
|
+
product_variant_id = _ref12.product_variant_id,
|
|
3105
|
+
_ref12$quantity = _ref12.quantity,
|
|
3106
|
+
quantity = _ref12$quantity === void 0 ? 1 : _ref12$quantity;
|
|
3100
3107
|
|
|
3101
3108
|
// 处理商品数据,类似 addProductToCart 中的逻辑
|
|
3102
3109
|
var productData = _objectSpread(_objectSpread({}, origin), {}, {
|
|
@@ -3106,6 +3113,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3106
3113
|
// 处理组合商品
|
|
3107
3114
|
var processedProduct = handleVariantProduct(productData);
|
|
3108
3115
|
|
|
3116
|
+
// 如果没有传入账户,获取当前活跃账户
|
|
3117
|
+
if (!account) {
|
|
3118
|
+
var activeAccount = this.getActiveAccount();
|
|
3119
|
+
if (activeAccount) {
|
|
3120
|
+
account = activeAccount;
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
|
|
3109
3124
|
// 创建基础的 CartItem
|
|
3110
3125
|
var cartItem = {
|
|
3111
3126
|
_id: getUniqueId('temp_'),
|
|
@@ -3114,9 +3129,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3114
3129
|
_productInit: product
|
|
3115
3130
|
};
|
|
3116
3131
|
|
|
3117
|
-
// 获取当前活跃账户
|
|
3118
|
-
var activeAccount = this.getActiveAccount();
|
|
3119
|
-
|
|
3120
3132
|
// 使用格式化函数填充 CartItem 数据
|
|
3121
3133
|
formatProductToCartItem({
|
|
3122
3134
|
cartItem: cartItem,
|
|
@@ -3126,16 +3138,39 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3126
3138
|
product_variant_id: product_variant_id,
|
|
3127
3139
|
quantity: quantity
|
|
3128
3140
|
});
|
|
3141
|
+
|
|
3142
|
+
// 如果有日期信息,格式化日期到购物车
|
|
3143
|
+
if (date) {
|
|
3144
|
+
formatDateToCartItem({
|
|
3145
|
+
cartItem: cartItem,
|
|
3146
|
+
date: date
|
|
3147
|
+
});
|
|
3148
|
+
}
|
|
3149
|
+
|
|
3150
|
+
// 如果有账户信息,格式化账户到购物车
|
|
3151
|
+
if (account) {
|
|
3152
|
+
formatAccountToCartItem({
|
|
3153
|
+
cartItem: cartItem,
|
|
3154
|
+
account: account
|
|
3155
|
+
});
|
|
3156
|
+
}
|
|
3129
3157
|
return cartItem;
|
|
3130
3158
|
}
|
|
3131
3159
|
}, {
|
|
3132
3160
|
key: "checkMaxDurationCapacityForDetailNums",
|
|
3133
|
-
value: function checkMaxDurationCapacityForDetailNums(
|
|
3161
|
+
value: function checkMaxDurationCapacityForDetailNums(_ref13) {
|
|
3134
3162
|
var _this16 = this;
|
|
3163
|
+
var product = _ref13.product,
|
|
3164
|
+
date = _ref13.date,
|
|
3165
|
+
account = _ref13.account;
|
|
3135
3166
|
var cartItems = cloneDeep(this.store.cart.getItems());
|
|
3136
3167
|
|
|
3137
3168
|
// 将 ProductData 转换为 CartItem 但不真正添加到购物车
|
|
3138
|
-
var currentCartItem = this.convertProductToCartItem(
|
|
3169
|
+
var currentCartItem = this.convertProductToCartItem({
|
|
3170
|
+
product: product,
|
|
3171
|
+
date: date,
|
|
3172
|
+
account: account
|
|
3173
|
+
});
|
|
3139
3174
|
cartItems.push(currentCartItem);
|
|
3140
3175
|
if (cartItems.length === 0) return {
|
|
3141
3176
|
success: true,
|
|
@@ -3432,7 +3467,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3432
3467
|
var resourcesIdSet = new Set();
|
|
3433
3468
|
|
|
3434
3469
|
// 获取资源数据
|
|
3435
|
-
|
|
3470
|
+
// const dateRange = this.store.date.getDateRange();
|
|
3436
3471
|
var resourcesDates = _this16.store.date.getDateList();
|
|
3437
3472
|
var targetResourceDate = resourcesDates.find(function (n) {
|
|
3438
3473
|
return n.date === startDate;
|
|
@@ -3453,13 +3488,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3453
3488
|
});
|
|
3454
3489
|
|
|
3455
3490
|
// 按资源类型分组检查容量
|
|
3456
|
-
|
|
3491
|
+
var _checkTimeSlotCapacit2 = checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot),
|
|
3492
|
+
success = _checkTimeSlotCapacit2.success,
|
|
3493
|
+
required = _checkTimeSlotCapacit2.required,
|
|
3494
|
+
available = _checkTimeSlotCapacit2.available;
|
|
3495
|
+
if (!success) {
|
|
3457
3496
|
// 如果有可用数量记录,返回最小值;否则返回 0
|
|
3458
|
-
|
|
3497
|
+
// const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
3459
3498
|
return {
|
|
3460
3499
|
v: {
|
|
3461
3500
|
success: false,
|
|
3462
|
-
minAvailableCount:
|
|
3501
|
+
minAvailableCount: available
|
|
3463
3502
|
}
|
|
3464
3503
|
};
|
|
3465
3504
|
}
|
|
@@ -3653,12 +3692,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3653
3692
|
}, {
|
|
3654
3693
|
key: "getTimeslotsScheduleByDateRange",
|
|
3655
3694
|
value: (function () {
|
|
3656
|
-
var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(
|
|
3695
|
+
var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref14) {
|
|
3657
3696
|
var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i5, _dates, date;
|
|
3658
3697
|
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
3659
3698
|
while (1) switch (_context26.prev = _context26.next) {
|
|
3660
3699
|
case 0:
|
|
3661
|
-
startDate =
|
|
3700
|
+
startDate = _ref14.startDate, endDate = _ref14.endDate, scheduleIds = _ref14.scheduleIds, resources = _ref14.resources;
|
|
3662
3701
|
console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
|
|
3663
3702
|
startDate: startDate,
|
|
3664
3703
|
endDate: endDate,
|
|
@@ -68,4 +68,8 @@ export declare function getResourcesIdsByProduct(product: any): number[];
|
|
|
68
68
|
/**
|
|
69
69
|
* 检查特定时间段的容量是否足够
|
|
70
70
|
*/
|
|
71
|
-
export declare function checkTimeSlotCapacity(timeSlotStart: string, timeSlotEnd: string, cartItems: CartItem[], allResources: ResourceItem[]):
|
|
71
|
+
export declare function checkTimeSlotCapacity(timeSlotStart: string, timeSlotEnd: string, cartItems: CartItem[], allResources: ResourceItem[]): {
|
|
72
|
+
success: boolean;
|
|
73
|
+
required: number;
|
|
74
|
+
available: number;
|
|
75
|
+
};
|
|
@@ -87,14 +87,14 @@ export var getSumCapacity = function getSumCapacity(_ref2) {
|
|
|
87
87
|
* @return {*}
|
|
88
88
|
*/
|
|
89
89
|
export function getCapacityInfoByCartItem(targetCartItem) {
|
|
90
|
-
var _targetCartItem$_prod
|
|
90
|
+
var _targetCartItem$_prod;
|
|
91
91
|
var formatCapacity = formatDefaultCapacitys({
|
|
92
92
|
capacity: (_targetCartItem$_prod = targetCartItem._productOrigin) === null || _targetCartItem$_prod === void 0 ? void 0 : _targetCartItem$_prod.capacity,
|
|
93
93
|
product_bundle: targetCartItem._origin.product.product_bundle
|
|
94
94
|
});
|
|
95
95
|
var currentCapacity = getSumCapacity({
|
|
96
96
|
capacity: formatCapacity,
|
|
97
|
-
num: (targetCartItem === null || targetCartItem === void 0
|
|
97
|
+
num: (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.num) || 1
|
|
98
98
|
});
|
|
99
99
|
return {
|
|
100
100
|
formatCapacity: formatCapacity,
|
|
@@ -265,7 +265,7 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
|
|
|
265
265
|
if (needsThisResourceType) {
|
|
266
266
|
// 需要判断是单个预约还是多个预约,如果是单个预约,不用加 capacity,只用+1
|
|
267
267
|
if (selectType === 'single') {
|
|
268
|
-
requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + 1;
|
|
268
|
+
requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + ((cartItem === null || cartItem === void 0 ? void 0 : cartItem.num) || 1);
|
|
269
269
|
} else {
|
|
270
270
|
requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
|
|
271
271
|
}
|
|
@@ -330,7 +330,11 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
|
|
|
330
330
|
if (totalAvailableCapacity < requiredCapacity) {
|
|
331
331
|
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(formId, " \u5BB9\u91CF\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredCapacity, ", \u53EF\u7528 ").concat(totalAvailableCapacity));
|
|
332
332
|
return {
|
|
333
|
-
v:
|
|
333
|
+
v: {
|
|
334
|
+
success: false,
|
|
335
|
+
required: requiredCapacity,
|
|
336
|
+
available: totalAvailableCapacity
|
|
337
|
+
}
|
|
334
338
|
};
|
|
335
339
|
}
|
|
336
340
|
} else {
|
|
@@ -339,7 +343,8 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
|
|
|
339
343
|
resourcesInType.forEach(function (resource) {
|
|
340
344
|
// 过滤出在时间段内的资源时间片
|
|
341
345
|
var availableTimes = resource.times.filter(function (time) {
|
|
342
|
-
|
|
346
|
+
var _time$event_list;
|
|
347
|
+
return !dayjs(time.start_at).isAfter(dayjs(timeSlotStart), 'minute') && !dayjs(time.end_at).isBefore(dayjs(timeSlotEnd), 'minute') || dayjs(time.start_at).isBefore(dayjs(timeSlotEnd), 'minute') && dayjs(time.end_at).isAfter(dayjs(timeSlotStart), 'minute') && ((_time$event_list = time.event_list) === null || _time$event_list === void 0 ? void 0 : _time$event_list.length) === 0;
|
|
343
348
|
});
|
|
344
349
|
if (availableTimes.length > 0) {
|
|
345
350
|
availableResourceCount++;
|
|
@@ -349,7 +354,11 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
|
|
|
349
354
|
if (availableResourceCount < requiredCapacity) {
|
|
350
355
|
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(formId, " \u6570\u91CF\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredCapacity, ", \u53EF\u7528 ").concat(availableResourceCount));
|
|
351
356
|
return {
|
|
352
|
-
v:
|
|
357
|
+
v: {
|
|
358
|
+
success: false,
|
|
359
|
+
required: requiredCapacity,
|
|
360
|
+
available: availableResourceCount
|
|
361
|
+
}
|
|
353
362
|
};
|
|
354
363
|
}
|
|
355
364
|
}
|
|
@@ -360,5 +369,9 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
|
|
|
360
369
|
if (_ret === 0) continue;
|
|
361
370
|
if (_ret) return _ret.v;
|
|
362
371
|
}
|
|
363
|
-
return
|
|
372
|
+
return {
|
|
373
|
+
success: true,
|
|
374
|
+
required: 0,
|
|
375
|
+
available: 0
|
|
376
|
+
};
|
|
364
377
|
}
|
|
@@ -329,13 +329,20 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
329
329
|
* 参考 addProductToCart 方法的实现
|
|
330
330
|
*/
|
|
331
331
|
private convertProductToCartItem;
|
|
332
|
-
checkMaxDurationCapacityForDetailNums(
|
|
332
|
+
checkMaxDurationCapacityForDetailNums({ product, date, account, }: {
|
|
333
|
+
product: ProductData;
|
|
334
|
+
date?: {
|
|
335
|
+
startTime: string;
|
|
336
|
+
endTime: string;
|
|
337
|
+
} | null;
|
|
338
|
+
account?: Account | null;
|
|
339
|
+
}): {
|
|
333
340
|
success: boolean;
|
|
334
341
|
minAvailableCount: number;
|
|
335
342
|
};
|
|
336
343
|
setOtherData(key: string, value: any): void;
|
|
337
344
|
getOtherData(key: string): any;
|
|
338
|
-
getProductTypeById(id: number): Promise<"
|
|
345
|
+
getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
|
|
339
346
|
/**
|
|
340
347
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
341
348
|
*
|
|
@@ -636,7 +636,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
636
636
|
addItemParams.account = account;
|
|
637
637
|
}
|
|
638
638
|
this.addProductCheck({ date });
|
|
639
|
-
if (addItemParams.quantity > 1) {
|
|
639
|
+
if (addItemParams.quantity > 1 && !(0, import_utils5.isNormalProduct)(productData.origin)) {
|
|
640
640
|
for (let i = 0; i < addItemParams.quantity; i++) {
|
|
641
641
|
const newAddItemParams = (0, import_lodash_es.cloneDeep)(addItemParams);
|
|
642
642
|
newAddItemParams.quantity = 1;
|
|
@@ -2118,7 +2118,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2118
2118
|
}
|
|
2119
2119
|
});
|
|
2120
2120
|
});
|
|
2121
|
-
|
|
2121
|
+
const { success, required, available } = (0, import_capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot);
|
|
2122
|
+
if (!success) {
|
|
2122
2123
|
const minAvailableCount2 = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
2123
2124
|
return { success: false, minAvailableCount: minAvailableCount2 };
|
|
2124
2125
|
}
|
|
@@ -2130,7 +2131,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2130
2131
|
* 将 ProductData 转换为 CartItem,但不添加到购物车
|
|
2131
2132
|
* 参考 addProductToCart 方法的实现
|
|
2132
2133
|
*/
|
|
2133
|
-
convertProductToCartItem(
|
|
2134
|
+
convertProductToCartItem({
|
|
2135
|
+
product,
|
|
2136
|
+
date,
|
|
2137
|
+
account
|
|
2138
|
+
}) {
|
|
2134
2139
|
const {
|
|
2135
2140
|
bundle,
|
|
2136
2141
|
options,
|
|
@@ -2140,13 +2145,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2140
2145
|
} = product || {};
|
|
2141
2146
|
const productData = { ...origin, product_variant_id };
|
|
2142
2147
|
const processedProduct = (0, import_utils.handleVariantProduct)(productData);
|
|
2148
|
+
if (!account) {
|
|
2149
|
+
const activeAccount = this.getActiveAccount();
|
|
2150
|
+
if (activeAccount) {
|
|
2151
|
+
account = activeAccount;
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2143
2154
|
const cartItem = {
|
|
2144
2155
|
_id: (0, import_utils.getUniqueId)("temp_"),
|
|
2145
2156
|
_origin: (0, import_utils.createCartItemOrigin)(),
|
|
2146
2157
|
_productOrigin: processedProduct,
|
|
2147
2158
|
_productInit: product
|
|
2148
2159
|
};
|
|
2149
|
-
const activeAccount = this.getActiveAccount();
|
|
2150
2160
|
(0, import_utils.formatProductToCartItem)({
|
|
2151
2161
|
cartItem,
|
|
2152
2162
|
product: processedProduct,
|
|
@@ -2155,12 +2165,28 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2155
2165
|
product_variant_id,
|
|
2156
2166
|
quantity
|
|
2157
2167
|
});
|
|
2168
|
+
if (date) {
|
|
2169
|
+
(0, import_utils.formatDateToCartItem)({
|
|
2170
|
+
cartItem,
|
|
2171
|
+
date
|
|
2172
|
+
});
|
|
2173
|
+
}
|
|
2174
|
+
if (account) {
|
|
2175
|
+
(0, import_utils.formatAccountToCartItem)({
|
|
2176
|
+
cartItem,
|
|
2177
|
+
account
|
|
2178
|
+
});
|
|
2179
|
+
}
|
|
2158
2180
|
return cartItem;
|
|
2159
2181
|
}
|
|
2160
|
-
checkMaxDurationCapacityForDetailNums(
|
|
2182
|
+
checkMaxDurationCapacityForDetailNums({
|
|
2183
|
+
product,
|
|
2184
|
+
date,
|
|
2185
|
+
account
|
|
2186
|
+
}) {
|
|
2161
2187
|
var _a, _b;
|
|
2162
2188
|
const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
2163
|
-
const currentCartItem = this.convertProductToCartItem(
|
|
2189
|
+
const currentCartItem = this.convertProductToCartItem({ product, date, account });
|
|
2164
2190
|
cartItems.push(currentCartItem);
|
|
2165
2191
|
if (cartItems.length === 0)
|
|
2166
2192
|
return { success: true, minAvailableCount: 0 };
|
|
@@ -2339,7 +2365,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2339
2365
|
const timeSlotEnd = `${endDate} ${endTime}`;
|
|
2340
2366
|
const allResourcesForTimeSlot = [];
|
|
2341
2367
|
const resourcesIdSet = /* @__PURE__ */ new Set();
|
|
2342
|
-
const dateRange = this.store.date.getDateRange();
|
|
2343
2368
|
const resourcesDates = this.store.date.getDateList();
|
|
2344
2369
|
const targetResourceDate = resourcesDates.find((n) => n.date === startDate);
|
|
2345
2370
|
if (!targetResourceDate)
|
|
@@ -2356,9 +2381,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2356
2381
|
}
|
|
2357
2382
|
});
|
|
2358
2383
|
});
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
return { success: false, minAvailableCount:
|
|
2384
|
+
const { success, required, available } = (0, import_capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot);
|
|
2385
|
+
if (!success) {
|
|
2386
|
+
return { success: false, minAvailableCount: available };
|
|
2362
2387
|
}
|
|
2363
2388
|
}
|
|
2364
2389
|
const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
@@ -68,4 +68,8 @@ export declare function getResourcesIdsByProduct(product: any): number[];
|
|
|
68
68
|
/**
|
|
69
69
|
* 检查特定时间段的容量是否足够
|
|
70
70
|
*/
|
|
71
|
-
export declare function checkTimeSlotCapacity(timeSlotStart: string, timeSlotEnd: string, cartItems: CartItem[], allResources: ResourceItem[]):
|
|
71
|
+
export declare function checkTimeSlotCapacity(timeSlotStart: string, timeSlotEnd: string, cartItems: CartItem[], allResources: ResourceItem[]): {
|
|
72
|
+
success: boolean;
|
|
73
|
+
required: number;
|
|
74
|
+
available: number;
|
|
75
|
+
};
|
|
@@ -76,12 +76,12 @@ var getSumCapacity = ({ capacity, num = 1 }) => {
|
|
|
76
76
|
return sum * num;
|
|
77
77
|
};
|
|
78
78
|
function getCapacityInfoByCartItem(targetCartItem) {
|
|
79
|
-
var _a
|
|
79
|
+
var _a;
|
|
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, num: (
|
|
84
|
+
const currentCapacity = getSumCapacity({ capacity: formatCapacity, num: (targetCartItem == null ? void 0 : targetCartItem.num) || 1 });
|
|
85
85
|
return {
|
|
86
86
|
formatCapacity,
|
|
87
87
|
currentCapacity
|
|
@@ -194,7 +194,7 @@ function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, allResourc
|
|
|
194
194
|
);
|
|
195
195
|
if (needsThisResourceType) {
|
|
196
196
|
if (selectType === "single") {
|
|
197
|
-
requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + 1;
|
|
197
|
+
requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + ((cartItem == null ? void 0 : cartItem.num) || 1);
|
|
198
198
|
} else {
|
|
199
199
|
requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
|
|
200
200
|
}
|
|
@@ -238,13 +238,18 @@ function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, allResourc
|
|
|
238
238
|
console.log(`capacity.ts - 资源类型 ${formId} 多个预约检查: 总容量 ${totalAvailableCapacity}, 需求 ${requiredCapacity}`);
|
|
239
239
|
if (totalAvailableCapacity < requiredCapacity) {
|
|
240
240
|
console.log(`资源类型 ${formId} 容量不足: 需要 ${requiredCapacity}, 可用 ${totalAvailableCapacity}`);
|
|
241
|
-
return
|
|
241
|
+
return {
|
|
242
|
+
success: false,
|
|
243
|
+
required: requiredCapacity,
|
|
244
|
+
available: totalAvailableCapacity
|
|
245
|
+
};
|
|
242
246
|
}
|
|
243
247
|
} else {
|
|
244
248
|
let availableResourceCount = 0;
|
|
245
249
|
resourcesInType.forEach((resource) => {
|
|
246
250
|
const availableTimes = resource.times.filter((time) => {
|
|
247
|
-
|
|
251
|
+
var _a2;
|
|
252
|
+
return !(0, import_dayjs.default)(time.start_at).isAfter((0, import_dayjs.default)(timeSlotStart), "minute") && !(0, import_dayjs.default)(time.end_at).isBefore((0, import_dayjs.default)(timeSlotEnd), "minute") || (0, import_dayjs.default)(time.start_at).isBefore((0, import_dayjs.default)(timeSlotEnd), "minute") && (0, import_dayjs.default)(time.end_at).isAfter((0, import_dayjs.default)(timeSlotStart), "minute") && ((_a2 = time.event_list) == null ? void 0 : _a2.length) === 0;
|
|
248
253
|
});
|
|
249
254
|
if (availableTimes.length > 0) {
|
|
250
255
|
availableResourceCount++;
|
|
@@ -253,11 +258,19 @@ function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, allResourc
|
|
|
253
258
|
console.log(`capacity.ts - 资源类型 ${formId} 单个预约检查: 可用资源数 ${availableResourceCount}, 需求 ${requiredCapacity}`);
|
|
254
259
|
if (availableResourceCount < requiredCapacity) {
|
|
255
260
|
console.log(`资源类型 ${formId} 数量不足: 需要 ${requiredCapacity}, 可用 ${availableResourceCount}`);
|
|
256
|
-
return
|
|
261
|
+
return {
|
|
262
|
+
success: false,
|
|
263
|
+
required: requiredCapacity,
|
|
264
|
+
available: availableResourceCount
|
|
265
|
+
};
|
|
257
266
|
}
|
|
258
267
|
}
|
|
259
268
|
}
|
|
260
|
-
return
|
|
269
|
+
return {
|
|
270
|
+
success: true,
|
|
271
|
+
required: 0,
|
|
272
|
+
available: 0
|
|
273
|
+
};
|
|
261
274
|
}
|
|
262
275
|
// Annotate the CommonJS export names for ESM import in node:
|
|
263
276
|
0 && (module.exports = {
|