@pisell/pisellos 3.0.65 → 3.0.66
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 +16 -4
- package/dist/solution/BookingByStep/index.js +702 -110
- package/dist/solution/BookingByStep/utils/capacity.d.ts +23 -0
- package/dist/solution/BookingByStep/utils/capacity.js +230 -1
- package/dist/solution/BookingByStep/utils/resources.d.ts +15 -0
- package/dist/solution/BookingByStep/utils/resources.js +1 -1
- package/dist/solution/BookingByStep/utils/stock.d.ts +29 -0
- package/dist/solution/BookingByStep/utils/stock.js +126 -0
- package/lib/solution/BookingByStep/index.d.ts +16 -4
- package/lib/solution/BookingByStep/index.js +387 -9
- package/lib/solution/BookingByStep/utils/capacity.d.ts +23 -0
- package/lib/solution/BookingByStep/utils/capacity.js +166 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +15 -0
- package/lib/solution/BookingByStep/utils/resources.js +2 -0
- package/lib/solution/BookingByStep/utils/stock.d.ts +29 -0
- package/lib/solution/BookingByStep/utils/stock.js +89 -0
- package/package.json +1 -1
|
@@ -45,3 +45,26 @@ export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void
|
|
|
45
45
|
* @returns 如果资源可以容纳额外的容量则返回 true
|
|
46
46
|
*/
|
|
47
47
|
export declare const checkResourceCanUseByCapacity: (currentCapacity: number, requiredCapacity: number, maxCapacity: number) => boolean;
|
|
48
|
+
/**
|
|
49
|
+
* 计算按资源类型分组的容量占用情况
|
|
50
|
+
*
|
|
51
|
+
* @param {CartItem[]} cartItems 购物车商品列表
|
|
52
|
+
* @param {string} timeSlotStart 时间段开始时间
|
|
53
|
+
* @param {string} timeSlotEnd 时间段结束时间
|
|
54
|
+
* @param {ResourceItem[]} allProductResources 当前商品的所有资源列表
|
|
55
|
+
* @return {Record<string, number>} 返回每种资源类型(form_id)的容量占用
|
|
56
|
+
*/
|
|
57
|
+
export declare function calculateCartItemsCapacityUsageByResourceType({ cartItems, timeSlotStart, timeSlotEnd, allProductResources }: {
|
|
58
|
+
cartItems: CartItem[];
|
|
59
|
+
timeSlotStart: string;
|
|
60
|
+
timeSlotEnd: string;
|
|
61
|
+
allProductResources: ResourceItem[];
|
|
62
|
+
}): Record<string, number>;
|
|
63
|
+
/**
|
|
64
|
+
* 获取商品的资源ID列表
|
|
65
|
+
*/
|
|
66
|
+
export declare function getResourcesIdsByProduct(product: any): number[];
|
|
67
|
+
/**
|
|
68
|
+
* 检查特定时间段的容量是否足够
|
|
69
|
+
*/
|
|
70
|
+
export declare function checkTimeSlotCapacity(timeSlotStart: string, timeSlotEnd: string, cartItems: CartItem[], allResources: ResourceItem[]): boolean;
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
4
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
5
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
6
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
8
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
1
9
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
10
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
11
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
+
import dayjs from 'dayjs';
|
|
13
|
+
|
|
4
14
|
/**
|
|
5
15
|
* @title: 基于选择的商品格式化容量
|
|
6
16
|
* @description:
|
|
@@ -129,4 +139,223 @@ export var checkResourceCanUseByCapacity = function checkResourceCanUseByCapacit
|
|
|
129
139
|
return false;
|
|
130
140
|
}
|
|
131
141
|
return currentCapacity + requiredCapacity <= maxCapacity;
|
|
132
|
-
};
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 计算按资源类型分组的容量占用情况
|
|
146
|
+
*
|
|
147
|
+
* @param {CartItem[]} cartItems 购物车商品列表
|
|
148
|
+
* @param {string} timeSlotStart 时间段开始时间
|
|
149
|
+
* @param {string} timeSlotEnd 时间段结束时间
|
|
150
|
+
* @param {ResourceItem[]} allProductResources 当前商品的所有资源列表
|
|
151
|
+
* @return {Record<string, number>} 返回每种资源类型(form_id)的容量占用
|
|
152
|
+
*/
|
|
153
|
+
export function calculateCartItemsCapacityUsageByResourceType(_ref3) {
|
|
154
|
+
var cartItems = _ref3.cartItems,
|
|
155
|
+
timeSlotStart = _ref3.timeSlotStart,
|
|
156
|
+
timeSlotEnd = _ref3.timeSlotEnd,
|
|
157
|
+
allProductResources = _ref3.allProductResources;
|
|
158
|
+
// 按 form_id 分组当前商品的资源
|
|
159
|
+
var resourceTypeMap = {};
|
|
160
|
+
allProductResources.forEach(function (resource) {
|
|
161
|
+
var _resource$form_id;
|
|
162
|
+
var formId = ((_resource$form_id = resource.form_id) === null || _resource$form_id === void 0 ? void 0 : _resource$form_id.toString()) || 'default';
|
|
163
|
+
if (!resourceTypeMap[formId]) {
|
|
164
|
+
resourceTypeMap[formId] = [];
|
|
165
|
+
}
|
|
166
|
+
resourceTypeMap[formId].push(resource);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// 计算每种资源类型的容量占用
|
|
170
|
+
var capacityUsageByType = {};
|
|
171
|
+
Object.keys(resourceTypeMap).forEach(function (formId) {
|
|
172
|
+
var totalUsage = 0;
|
|
173
|
+
var resourcesInThisType = resourceTypeMap[formId];
|
|
174
|
+
var resourceIdsInThisType = resourcesInThisType.map(function (r) {
|
|
175
|
+
return r.id;
|
|
176
|
+
});
|
|
177
|
+
cartItems.forEach(function (cartItem) {
|
|
178
|
+
// 检查该商品是否已经选定了时间
|
|
179
|
+
if (!cartItem.start_time || !cartItem.end_time) return;
|
|
180
|
+
|
|
181
|
+
// 构建该商品的时间段
|
|
182
|
+
var itemStart = "".concat(cartItem.start_date, " ").concat(cartItem.start_time);
|
|
183
|
+
var itemEnd = "".concat(cartItem.end_date || cartItem.start_date, " ").concat(cartItem.end_time);
|
|
184
|
+
|
|
185
|
+
// 检查时间段是否有重叠
|
|
186
|
+
var hasTimeOverlap = !(dayjs(itemEnd).isBefore(dayjs(timeSlotStart)) || dayjs(itemStart).isAfter(dayjs(timeSlotEnd)));
|
|
187
|
+
if (!hasTimeOverlap) return;
|
|
188
|
+
|
|
189
|
+
// 检查该商品的资源配置中是否需要这种类型的资源
|
|
190
|
+
// 由于购物车商品只选定了时间,没有选定具体资源,我们需要看商品的资源配置
|
|
191
|
+
var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
192
|
+
var hasResourceTypeOverlap = productResourceIds.some(function (id) {
|
|
193
|
+
return resourceIdsInThisType.includes(id);
|
|
194
|
+
});
|
|
195
|
+
if (!hasResourceTypeOverlap) return;
|
|
196
|
+
|
|
197
|
+
// 计算该商品的容量占用
|
|
198
|
+
var _getCapacityInfoByCar = getCapacityInfoByCartItem(cartItem),
|
|
199
|
+
currentCapacity = _getCapacityInfoByCar.currentCapacity;
|
|
200
|
+
totalUsage += currentCapacity;
|
|
201
|
+
});
|
|
202
|
+
capacityUsageByType[formId] = totalUsage;
|
|
203
|
+
});
|
|
204
|
+
return capacityUsageByType;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* 获取商品的资源ID列表
|
|
209
|
+
*/
|
|
210
|
+
export function getResourcesIdsByProduct(product) {
|
|
211
|
+
var _product$product_reso, _product$product_reso2;
|
|
212
|
+
var tempResourceIds = [];
|
|
213
|
+
product === null || product === void 0 || (_product$product_reso = product.product_resource) === null || _product$product_reso === void 0 || (_product$product_reso = _product$product_reso.resources) === null || _product$product_reso === void 0 || (_product$product_reso2 = _product$product_reso.forEach) === null || _product$product_reso2 === void 0 || _product$product_reso2.call(_product$product_reso, function (resource) {
|
|
214
|
+
if ((resource === null || resource === void 0 ? void 0 : resource.status) == 1) {
|
|
215
|
+
var _resource$default_res, _resource$optional_re;
|
|
216
|
+
if (resource !== null && resource !== void 0 && (_resource$default_res = resource.default_resource) !== null && _resource$default_res !== void 0 && _resource$default_res.length) {
|
|
217
|
+
tempResourceIds.push.apply(tempResourceIds, _toConsumableArray(resource === null || resource === void 0 ? void 0 : resource.default_resource));
|
|
218
|
+
} else if (resource !== null && resource !== void 0 && (_resource$optional_re = resource.optional_resource) !== null && _resource$optional_re !== void 0 && _resource$optional_re.length) {
|
|
219
|
+
tempResourceIds.push.apply(tempResourceIds, _toConsumableArray(resource === null || resource === void 0 ? void 0 : resource.optional_resource));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
return tempResourceIds;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* 检查特定时间段的容量是否足够
|
|
228
|
+
*/
|
|
229
|
+
export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, allResources) {
|
|
230
|
+
// 按资源类型分组
|
|
231
|
+
var resourceTypeMap = {};
|
|
232
|
+
allResources.forEach(function (resource) {
|
|
233
|
+
var _resource$form_id2;
|
|
234
|
+
var formId = ((_resource$form_id2 = resource.form_id) === null || _resource$form_id2 === void 0 ? void 0 : _resource$form_id2.toString()) || 'default';
|
|
235
|
+
if (!resourceTypeMap[formId]) {
|
|
236
|
+
resourceTypeMap[formId] = [];
|
|
237
|
+
}
|
|
238
|
+
resourceTypeMap[formId].push(resource);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// 计算每种资源类型需要的总容量
|
|
242
|
+
var requiredCapacityByType = {};
|
|
243
|
+
cartItems.forEach(function (cartItem) {
|
|
244
|
+
var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
245
|
+
var _getCapacityInfoByCar2 = getCapacityInfoByCartItem(cartItem),
|
|
246
|
+
currentCapacity = _getCapacityInfoByCar2.currentCapacity;
|
|
247
|
+
Object.keys(resourceTypeMap).forEach(function (formId) {
|
|
248
|
+
var _cartItem$_productOri;
|
|
249
|
+
var resourcesInType = resourceTypeMap[formId];
|
|
250
|
+
var resourceIdsInType = resourcesInType.map(function (r) {
|
|
251
|
+
return r.id;
|
|
252
|
+
});
|
|
253
|
+
var selectType = (_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 || (_cartItem$_productOri = _cartItem$_productOri.product_resource) === null || _cartItem$_productOri === void 0 || (_cartItem$_productOri = _cartItem$_productOri.resources) === null || _cartItem$_productOri === void 0 || (_cartItem$_productOri = _cartItem$_productOri.find(function (r) {
|
|
254
|
+
var _r$id;
|
|
255
|
+
return ((_r$id = r.id) === null || _r$id === void 0 ? void 0 : _r$id.toString()) === formId;
|
|
256
|
+
})) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.type;
|
|
257
|
+
|
|
258
|
+
// 检查该商品是否需要这种类型的资源
|
|
259
|
+
var needsThisResourceType = productResourceIds.some(function (id) {
|
|
260
|
+
return resourceIdsInType.includes(id);
|
|
261
|
+
});
|
|
262
|
+
if (needsThisResourceType) {
|
|
263
|
+
// 需要判断是单个预约还是多个预约,如果是单个预约,不用加 capacity,只用+1
|
|
264
|
+
if (selectType === 'single') {
|
|
265
|
+
requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + 1;
|
|
266
|
+
} else {
|
|
267
|
+
requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
|
|
268
|
+
}
|
|
269
|
+
// requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// 检查每种资源类型是否有足够的容量
|
|
275
|
+
var _loop = function _loop() {
|
|
276
|
+
var _resourceTypeConfig, _resourceTypeConfig2;
|
|
277
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
278
|
+
formId = _Object$entries$_i[0],
|
|
279
|
+
requiredCapacity = _Object$entries$_i[1];
|
|
280
|
+
var resourcesInType = resourceTypeMap[formId];
|
|
281
|
+
if (resourcesInType.length === 0) return 0; // continue
|
|
282
|
+
|
|
283
|
+
// 从购物车商品中获取正确的资源类型配置
|
|
284
|
+
var resourceTypeConfig = null;
|
|
285
|
+
var _iterator2 = _createForOfIteratorHelper(cartItems),
|
|
286
|
+
_step2;
|
|
287
|
+
try {
|
|
288
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
289
|
+
var _cartItem$_productOri2;
|
|
290
|
+
var cartItem = _step2.value;
|
|
291
|
+
if ((_cartItem$_productOri2 = cartItem._productOrigin) !== null && _cartItem$_productOri2 !== void 0 && (_cartItem$_productOri2 = _cartItem$_productOri2.product_resource) !== null && _cartItem$_productOri2 !== void 0 && _cartItem$_productOri2.resources) {
|
|
292
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
|
|
293
|
+
var _r$id2;
|
|
294
|
+
return ((_r$id2 = r.id) === null || _r$id2 === void 0 ? void 0 : _r$id2.toString()) === formId && r.status === 1;
|
|
295
|
+
});
|
|
296
|
+
if (resourceTypeConfig) break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// 确定这种资源类型的预约类型
|
|
301
|
+
} catch (err) {
|
|
302
|
+
_iterator2.e(err);
|
|
303
|
+
} finally {
|
|
304
|
+
_iterator2.f();
|
|
305
|
+
}
|
|
306
|
+
var isMultipleBooking = ((_resourceTypeConfig = resourceTypeConfig) === null || _resourceTypeConfig === void 0 ? void 0 : _resourceTypeConfig.type) === 'multiple';
|
|
307
|
+
console.log("capacity.ts - \u8D44\u6E90\u7C7B\u578B ".concat(formId, " \u914D\u7F6E:"), {
|
|
308
|
+
resourceTypeConfig: resourceTypeConfig,
|
|
309
|
+
type: (_resourceTypeConfig2 = resourceTypeConfig) === null || _resourceTypeConfig2 === void 0 ? void 0 : _resourceTypeConfig2.type,
|
|
310
|
+
isMultipleBooking: isMultipleBooking,
|
|
311
|
+
requiredCapacity: requiredCapacity
|
|
312
|
+
});
|
|
313
|
+
if (isMultipleBooking) {
|
|
314
|
+
// 多个预约:计算总可用容量
|
|
315
|
+
var totalAvailableCapacity = 0;
|
|
316
|
+
resourcesInType.forEach(function (resource) {
|
|
317
|
+
// 过滤出在时间段内的资源时间片
|
|
318
|
+
var availableTimes = resource.times.filter(function (time) {
|
|
319
|
+
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');
|
|
320
|
+
});
|
|
321
|
+
if (availableTimes.length > 0) {
|
|
322
|
+
// 简化逻辑:如果资源在时间段内有可用时间,就计算其容量
|
|
323
|
+
totalAvailableCapacity += resource.capacity || 0;
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
console.log("capacity.ts - \u8D44\u6E90\u7C7B\u578B ".concat(formId, " \u591A\u4E2A\u9884\u7EA6\u68C0\u67E5: \u603B\u5BB9\u91CF ").concat(totalAvailableCapacity, ", \u9700\u6C42 ").concat(requiredCapacity));
|
|
327
|
+
if (totalAvailableCapacity < requiredCapacity) {
|
|
328
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(formId, " \u5BB9\u91CF\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredCapacity, ", \u53EF\u7528 ").concat(totalAvailableCapacity));
|
|
329
|
+
return {
|
|
330
|
+
v: false
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
} else {
|
|
334
|
+
// 单个预约:计算可用资源数量
|
|
335
|
+
var availableResourceCount = 0;
|
|
336
|
+
resourcesInType.forEach(function (resource) {
|
|
337
|
+
// 过滤出在时间段内的资源时间片
|
|
338
|
+
var availableTimes = resource.times.filter(function (time) {
|
|
339
|
+
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');
|
|
340
|
+
});
|
|
341
|
+
if (availableTimes.length > 0) {
|
|
342
|
+
availableResourceCount++;
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
console.log("capacity.ts - \u8D44\u6E90\u7C7B\u578B ".concat(formId, " \u5355\u4E2A\u9884\u7EA6\u68C0\u67E5: \u53EF\u7528\u8D44\u6E90\u6570 ").concat(availableResourceCount, ", \u9700\u6C42 ").concat(requiredCapacity));
|
|
346
|
+
if (availableResourceCount < requiredCapacity) {
|
|
347
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(formId, " \u6570\u91CF\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredCapacity, ", \u53EF\u7528 ").concat(availableResourceCount));
|
|
348
|
+
return {
|
|
349
|
+
v: false
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
_ret;
|
|
355
|
+
for (var _i = 0, _Object$entries = Object.entries(requiredCapacityByType); _i < _Object$entries.length; _i++) {
|
|
356
|
+
_ret = _loop();
|
|
357
|
+
if (_ret === 0) continue;
|
|
358
|
+
if (_ret) return _ret.v;
|
|
359
|
+
}
|
|
360
|
+
return true;
|
|
361
|
+
}
|
|
@@ -20,6 +20,21 @@ export interface ResourceItem {
|
|
|
20
20
|
interface BookingItem {
|
|
21
21
|
[key: string]: any;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* @title: 判断两个时间段是否有重叠
|
|
25
|
+
* @description:
|
|
26
|
+
* @param {object} event
|
|
27
|
+
* @param {object} current
|
|
28
|
+
* @return {*}
|
|
29
|
+
* @Author: zhiwei.Wang
|
|
30
|
+
*/
|
|
31
|
+
export declare const isConflict: (event: {
|
|
32
|
+
start_at: DateType;
|
|
33
|
+
end_at: DateType;
|
|
34
|
+
}, current: {
|
|
35
|
+
start_at: DateType;
|
|
36
|
+
end_at?: DateType;
|
|
37
|
+
}) => boolean;
|
|
23
38
|
/**
|
|
24
39
|
* @title: 获取时间切片是否可用
|
|
25
40
|
* @description: 根据时间切片、资源、当前预约量判断时间切片是否可用
|
|
@@ -42,7 +42,7 @@ var getUseableEventCount = function getUseableEventCount(eventList, current) {
|
|
|
42
42
|
* @return {*}
|
|
43
43
|
* @Author: zhiwei.Wang
|
|
44
44
|
*/
|
|
45
|
-
var isConflict = function isConflict(event, current) {
|
|
45
|
+
export var isConflict = function isConflict(event, current) {
|
|
46
46
|
var eventStart = dayjs(event.start_at);
|
|
47
47
|
var eventEnd = dayjs(event.end_at);
|
|
48
48
|
var currentStart = dayjs(current.start_at);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CartItem } from '../../../modules';
|
|
2
|
+
/**
|
|
3
|
+
* 检测商品库存是否足够
|
|
4
|
+
*
|
|
5
|
+
* 只有同时满足以下条件时才会进行库存检测:
|
|
6
|
+
* - is_track 开启(值为 1 或 true)
|
|
7
|
+
* - over_sold 为 0(不允许超卖)
|
|
8
|
+
*
|
|
9
|
+
* 对于多规格商品:
|
|
10
|
+
* - 如果有 product_variant_id,则从 productData.variant 数组中查找对应规格
|
|
11
|
+
* - 使用规格的 is_track, over_sold, stock_quantity 而不是主商品的
|
|
12
|
+
*
|
|
13
|
+
* @param productData 商品数据(需包含 is_track, over_sold, stock_quantity 字段,多规格商品需包含 variant 数组)
|
|
14
|
+
* @param product_variant_id 商品变体ID,如果存在则为多规格商品
|
|
15
|
+
* @param quantity 需要添加的数量
|
|
16
|
+
* @param bundle 套餐配置(子商品需包含 is_track, over_sold, stock_quantity 字段)
|
|
17
|
+
* @param currentCartItems 当前购物车商品列表
|
|
18
|
+
* @returns 库存检测结果
|
|
19
|
+
*/
|
|
20
|
+
export declare function checkProductStock({ productData, product_variant_id, quantity, bundle, currentCartItems }: {
|
|
21
|
+
productData: any;
|
|
22
|
+
product_variant_id?: any;
|
|
23
|
+
quantity: number;
|
|
24
|
+
bundle?: any[];
|
|
25
|
+
currentCartItems: CartItem[];
|
|
26
|
+
}): {
|
|
27
|
+
success: boolean;
|
|
28
|
+
errorCode?: string;
|
|
29
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
4
|
+
/**
|
|
5
|
+
* 检测商品库存是否足够
|
|
6
|
+
*
|
|
7
|
+
* 只有同时满足以下条件时才会进行库存检测:
|
|
8
|
+
* - is_track 开启(值为 1 或 true)
|
|
9
|
+
* - over_sold 为 0(不允许超卖)
|
|
10
|
+
*
|
|
11
|
+
* 对于多规格商品:
|
|
12
|
+
* - 如果有 product_variant_id,则从 productData.variant 数组中查找对应规格
|
|
13
|
+
* - 使用规格的 is_track, over_sold, stock_quantity 而不是主商品的
|
|
14
|
+
*
|
|
15
|
+
* @param productData 商品数据(需包含 is_track, over_sold, stock_quantity 字段,多规格商品需包含 variant 数组)
|
|
16
|
+
* @param product_variant_id 商品变体ID,如果存在则为多规格商品
|
|
17
|
+
* @param quantity 需要添加的数量
|
|
18
|
+
* @param bundle 套餐配置(子商品需包含 is_track, over_sold, stock_quantity 字段)
|
|
19
|
+
* @param currentCartItems 当前购物车商品列表
|
|
20
|
+
* @returns 库存检测结果
|
|
21
|
+
*/
|
|
22
|
+
export function checkProductStock(_ref) {
|
|
23
|
+
var productData = _ref.productData,
|
|
24
|
+
product_variant_id = _ref.product_variant_id,
|
|
25
|
+
quantity = _ref.quantity,
|
|
26
|
+
bundle = _ref.bundle,
|
|
27
|
+
currentCartItems = _ref.currentCartItems;
|
|
28
|
+
// 1. 检测主商品库存
|
|
29
|
+
// 处理多规格商品:如果有product_variant_id,则从variant数组中查找对应的规格配置
|
|
30
|
+
var mainProductConfig = productData;
|
|
31
|
+
if (product_variant_id && productData.variant && Array.isArray(productData.variant)) {
|
|
32
|
+
var variant = productData.variant.find(function (v) {
|
|
33
|
+
return v.id === product_variant_id;
|
|
34
|
+
});
|
|
35
|
+
if (variant) {
|
|
36
|
+
mainProductConfig = variant; // 使用规格的配置替换主商品配置
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 只有开启库存控制且不允许超卖时才需要检测主商品库存
|
|
41
|
+
var isMainProductTrackingEnabled = mainProductConfig.is_track === 1 || mainProductConfig.is_track === true;
|
|
42
|
+
var isMainProductOverSoldDisabled = mainProductConfig.over_sold === 0;
|
|
43
|
+
if (isMainProductTrackingEnabled && isMainProductOverSoldDisabled) {
|
|
44
|
+
var existingQuantity = currentCartItems.reduce(function (total, cartItem) {
|
|
45
|
+
var _cartItem$_productOri, _cartItem$_productOri2, _cartItem$_productOri3;
|
|
46
|
+
// 检查是否为相同商品(比较商品ID和变体ID)
|
|
47
|
+
var isSameProduct = ((_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.id) === productData.id;
|
|
48
|
+
var isSameVariant = !product_variant_id && !((_cartItem$_productOri2 = cartItem._productOrigin) !== null && _cartItem$_productOri2 !== void 0 && _cartItem$_productOri2.product_variant_id) || ((_cartItem$_productOri3 = cartItem._productOrigin) === null || _cartItem$_productOri3 === void 0 ? void 0 : _cartItem$_productOri3.product_variant_id) === product_variant_id;
|
|
49
|
+
if (isSameProduct && isSameVariant) {
|
|
50
|
+
return total + (cartItem.num || 0);
|
|
51
|
+
}
|
|
52
|
+
return total;
|
|
53
|
+
}, 0);
|
|
54
|
+
var totalQuantity = existingQuantity + quantity;
|
|
55
|
+
var stockQuantity = mainProductConfig.stock_quantity;
|
|
56
|
+
|
|
57
|
+
// 检查主商品库存是否足够
|
|
58
|
+
if (stockQuantity !== undefined && stockQuantity !== null && totalQuantity > stockQuantity) {
|
|
59
|
+
return {
|
|
60
|
+
success: false,
|
|
61
|
+
errorCode: 'not_enough_stock'
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 2. 检测套餐商品库存
|
|
67
|
+
if (bundle && Array.isArray(bundle)) {
|
|
68
|
+
// 直接遍历套餐商品数组
|
|
69
|
+
var _iterator = _createForOfIteratorHelper(bundle),
|
|
70
|
+
_step;
|
|
71
|
+
try {
|
|
72
|
+
var _loop = function _loop() {
|
|
73
|
+
var bundleItem = _step.value;
|
|
74
|
+
var bundleProductId = bundleItem.bundle_product_id;
|
|
75
|
+
var bundleStockQuantity = bundleItem.stock_quantity;
|
|
76
|
+
var bundleRequiredQuantity = (bundleItem.num || 1) * quantity; // 子商品需求数量 = 子商品配置数量 * 主商品购买数量
|
|
77
|
+
|
|
78
|
+
// 检查套餐子商品是否需要进行库存控制
|
|
79
|
+
var isBundleTrackingEnabled = bundleItem.is_track === 1 || bundleItem.is_track === true;
|
|
80
|
+
var isBundleOverSoldDisabled = bundleItem.over_sold === 0;
|
|
81
|
+
|
|
82
|
+
// 跳过没有开启库存控制或允许超卖的子商品
|
|
83
|
+
if (!isBundleTrackingEnabled || !isBundleOverSoldDisabled) return 0; // continue
|
|
84
|
+
|
|
85
|
+
// 跳过没有库存配置的子商品
|
|
86
|
+
if (bundleStockQuantity === undefined || bundleStockQuantity === null) return 0; // continue
|
|
87
|
+
|
|
88
|
+
// 计算购物车中已有的相同子商品数量
|
|
89
|
+
var existingBundleQuantity = currentCartItems.reduce(function (total, cartItem) {
|
|
90
|
+
// 检查购物车中商品的套餐配置
|
|
91
|
+
if (!cartItem._bundleOrigin || !Array.isArray(cartItem._bundleOrigin)) return total;
|
|
92
|
+
cartItem._bundleOrigin.forEach(function (cartBundleItem) {
|
|
93
|
+
if (cartBundleItem.bundle_product_id === bundleProductId) {
|
|
94
|
+
total += (cartBundleItem.num || 1) * (cartItem.num || 1);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return total;
|
|
98
|
+
}, 0);
|
|
99
|
+
var totalBundleQuantity = existingBundleQuantity + bundleRequiredQuantity;
|
|
100
|
+
|
|
101
|
+
// 检查子商品库存是否足够
|
|
102
|
+
if (totalBundleQuantity > bundleStockQuantity) {
|
|
103
|
+
return {
|
|
104
|
+
v: {
|
|
105
|
+
success: false,
|
|
106
|
+
errorCode: 'not_enough_stock'
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
_ret;
|
|
112
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
113
|
+
_ret = _loop();
|
|
114
|
+
if (_ret === 0) continue;
|
|
115
|
+
if (_ret) return _ret.v;
|
|
116
|
+
}
|
|
117
|
+
} catch (err) {
|
|
118
|
+
_iterator.e(err);
|
|
119
|
+
} finally {
|
|
120
|
+
_iterator.f();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
success: true
|
|
125
|
+
};
|
|
126
|
+
}
|
|
@@ -180,7 +180,10 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
180
180
|
* @param {ProductData} productData
|
|
181
181
|
* @memberof BookingByStepImpl
|
|
182
182
|
*/
|
|
183
|
-
storeProduct(productData: ProductData):
|
|
183
|
+
storeProduct(productData: ProductData): {
|
|
184
|
+
success: boolean;
|
|
185
|
+
errorCode?: string;
|
|
186
|
+
};
|
|
184
187
|
/**
|
|
185
188
|
* 往购物车加商品数据
|
|
186
189
|
*
|
|
@@ -203,7 +206,10 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
203
206
|
endTime: string;
|
|
204
207
|
} | null;
|
|
205
208
|
account?: Account | null;
|
|
206
|
-
}):
|
|
209
|
+
}): {
|
|
210
|
+
success: boolean;
|
|
211
|
+
errorCode?: string;
|
|
212
|
+
};
|
|
207
213
|
/**
|
|
208
214
|
* 添加完购物车以后做的一些检测,比如日期是否在同一天
|
|
209
215
|
*
|
|
@@ -294,8 +300,6 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
294
300
|
};
|
|
295
301
|
getTimeSlotByAllResources(resources_code: string): any[];
|
|
296
302
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
297
|
-
clearCache(): void;
|
|
298
|
-
clearCacheByModule(module: string): void;
|
|
299
303
|
private getScheduleDataByIds;
|
|
300
304
|
openProductDetail(productId: number): Promise<void>;
|
|
301
305
|
closeProductDetail(): void;
|
|
@@ -312,6 +316,14 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
312
316
|
count: number;
|
|
313
317
|
left: number;
|
|
314
318
|
}[];
|
|
319
|
+
/**
|
|
320
|
+
* 找到多个资源的公共可用时间段
|
|
321
|
+
*/
|
|
322
|
+
private findCommonAvailableTimeSlots;
|
|
323
|
+
checkMaxDurationCapacity(): {
|
|
324
|
+
success: boolean;
|
|
325
|
+
minAvailableCount: number;
|
|
326
|
+
};
|
|
315
327
|
setOtherData(key: string, value: any): void;
|
|
316
328
|
getOtherData(key: string): any;
|
|
317
329
|
getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
|