@pisell/pisellos 3.0.65 → 3.0.67
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/ProductList/index.js +10 -2
- package/dist/solution/BookingByStep/index.d.ts +32 -4
- package/dist/solution/BookingByStep/index.js +1147 -112
- package/dist/solution/BookingByStep/utils/capacity.d.ts +29 -1
- package/dist/solution/BookingByStep/utils/capacity.js +249 -4
- 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/dist/solution/ShopDiscount/index.js +27 -9
- package/lib/modules/ProductList/index.js +9 -1
- package/lib/solution/BookingByStep/index.d.ts +32 -4
- package/lib/solution/BookingByStep/index.js +694 -44
- package/lib/solution/BookingByStep/utils/capacity.d.ts +29 -1
- package/lib/solution/BookingByStep/utils/capacity.js +182 -3
- 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/lib/solution/ShopDiscount/index.js +9 -0
- package/package.json +1 -1
|
@@ -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
|
|
@@ -45,3 +46,30 @@ export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void
|
|
|
45
46
|
* @returns 如果资源可以容纳额外的容量则返回 true
|
|
46
47
|
*/
|
|
47
48
|
export declare const checkResourceCanUseByCapacity: (currentCapacity: number, requiredCapacity: number, maxCapacity: number) => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* 计算按资源类型分组的容量占用情况
|
|
51
|
+
*
|
|
52
|
+
* @param {CartItem[]} cartItems 购物车商品列表
|
|
53
|
+
* @param {string} timeSlotStart 时间段开始时间
|
|
54
|
+
* @param {string} timeSlotEnd 时间段结束时间
|
|
55
|
+
* @param {ResourceItem[]} allProductResources 当前商品的所有资源列表
|
|
56
|
+
* @return {Record<string, number>} 返回每种资源类型(form_id)的容量占用
|
|
57
|
+
*/
|
|
58
|
+
export declare function calculateCartItemsCapacityUsageByResourceType({ cartItems, timeSlotStart, timeSlotEnd, allProductResources }: {
|
|
59
|
+
cartItems: CartItem[];
|
|
60
|
+
timeSlotStart: string;
|
|
61
|
+
timeSlotEnd: string;
|
|
62
|
+
allProductResources: ResourceItem[];
|
|
63
|
+
}): Record<string, number>;
|
|
64
|
+
/**
|
|
65
|
+
* 获取商品的资源ID列表
|
|
66
|
+
*/
|
|
67
|
+
export declare function getResourcesIdsByProduct(product: any): number[];
|
|
68
|
+
/**
|
|
69
|
+
* 检查特定时间段的容量是否足够
|
|
70
|
+
*/
|
|
71
|
+
export declare function checkTimeSlotCapacity(timeSlotStart: string, timeSlotEnd: string, cartItems: CartItem[], allResources: ResourceItem[]): {
|
|
72
|
+
success: boolean;
|
|
73
|
+
required: number;
|
|
74
|
+
available: number;
|
|
75
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,18 +16,30 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
|
|
19
29
|
// src/solution/BookingByStep/utils/capacity.ts
|
|
20
30
|
var capacity_exports = {};
|
|
21
31
|
__export(capacity_exports, {
|
|
32
|
+
calculateCartItemsCapacityUsageByResourceType: () => calculateCartItemsCapacityUsageByResourceType,
|
|
22
33
|
checkResourceCanUseByCapacity: () => checkResourceCanUseByCapacity,
|
|
23
34
|
checkSubResourcesCapacity: () => checkSubResourcesCapacity,
|
|
35
|
+
checkTimeSlotCapacity: () => checkTimeSlotCapacity,
|
|
24
36
|
formatDefaultCapacitys: () => formatDefaultCapacitys,
|
|
25
37
|
getCapacityInfoByCartItem: () => getCapacityInfoByCartItem,
|
|
38
|
+
getResourcesIdsByProduct: () => getResourcesIdsByProduct,
|
|
26
39
|
getSumCapacity: () => getSumCapacity
|
|
27
40
|
});
|
|
28
41
|
module.exports = __toCommonJS(capacity_exports);
|
|
42
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
29
43
|
var formatDefaultCapacitys = ({
|
|
30
44
|
capacity,
|
|
31
45
|
product_bundle
|
|
@@ -54,12 +68,12 @@ var formatDefaultCapacitys = ({
|
|
|
54
68
|
}
|
|
55
69
|
return [{ id: 0, value: 1, name: "" }];
|
|
56
70
|
};
|
|
57
|
-
var getSumCapacity = ({ capacity }) => {
|
|
71
|
+
var getSumCapacity = ({ capacity, num = 1 }) => {
|
|
58
72
|
let sum = 0;
|
|
59
73
|
for (let item of capacity || []) {
|
|
60
74
|
sum += item.value;
|
|
61
75
|
}
|
|
62
|
-
return sum;
|
|
76
|
+
return sum * num;
|
|
63
77
|
};
|
|
64
78
|
function getCapacityInfoByCartItem(targetCartItem) {
|
|
65
79
|
var _a;
|
|
@@ -67,7 +81,7 @@ function getCapacityInfoByCartItem(targetCartItem) {
|
|
|
67
81
|
capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
68
82
|
product_bundle: targetCartItem._origin.product.product_bundle
|
|
69
83
|
});
|
|
70
|
-
const currentCapacity = getSumCapacity({ capacity: formatCapacity });
|
|
84
|
+
const currentCapacity = getSumCapacity({ capacity: formatCapacity, num: (targetCartItem == null ? void 0 : targetCartItem.num) || 1 });
|
|
71
85
|
return {
|
|
72
86
|
formatCapacity,
|
|
73
87
|
currentCapacity
|
|
@@ -96,11 +110,176 @@ var checkResourceCanUseByCapacity = (currentCapacity, requiredCapacity, maxCapac
|
|
|
96
110
|
}
|
|
97
111
|
return currentCapacity + requiredCapacity <= maxCapacity;
|
|
98
112
|
};
|
|
113
|
+
function calculateCartItemsCapacityUsageByResourceType({
|
|
114
|
+
cartItems,
|
|
115
|
+
timeSlotStart,
|
|
116
|
+
timeSlotEnd,
|
|
117
|
+
allProductResources
|
|
118
|
+
}) {
|
|
119
|
+
const resourceTypeMap = {};
|
|
120
|
+
allProductResources.forEach((resource) => {
|
|
121
|
+
var _a;
|
|
122
|
+
const formId = ((_a = resource.form_id) == null ? void 0 : _a.toString()) || "default";
|
|
123
|
+
if (!resourceTypeMap[formId]) {
|
|
124
|
+
resourceTypeMap[formId] = [];
|
|
125
|
+
}
|
|
126
|
+
resourceTypeMap[formId].push(resource);
|
|
127
|
+
});
|
|
128
|
+
const capacityUsageByType = {};
|
|
129
|
+
Object.keys(resourceTypeMap).forEach((formId) => {
|
|
130
|
+
let totalUsage = 0;
|
|
131
|
+
const resourcesInThisType = resourceTypeMap[formId];
|
|
132
|
+
const resourceIdsInThisType = resourcesInThisType.map((r) => r.id);
|
|
133
|
+
cartItems.forEach((cartItem) => {
|
|
134
|
+
if (!cartItem.start_time || !cartItem.end_time)
|
|
135
|
+
return;
|
|
136
|
+
const itemStart = `${cartItem.start_date} ${cartItem.start_time}`;
|
|
137
|
+
const itemEnd = `${cartItem.end_date || cartItem.start_date} ${cartItem.end_time}`;
|
|
138
|
+
const hasTimeOverlap = !((0, import_dayjs.default)(itemEnd).isBefore((0, import_dayjs.default)(timeSlotStart)) || (0, import_dayjs.default)(itemStart).isAfter((0, import_dayjs.default)(timeSlotEnd)));
|
|
139
|
+
if (!hasTimeOverlap)
|
|
140
|
+
return;
|
|
141
|
+
const productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
142
|
+
const hasResourceTypeOverlap = productResourceIds.some(
|
|
143
|
+
(id) => resourceIdsInThisType.includes(id)
|
|
144
|
+
);
|
|
145
|
+
if (!hasResourceTypeOverlap)
|
|
146
|
+
return;
|
|
147
|
+
const { currentCapacity } = getCapacityInfoByCartItem(cartItem);
|
|
148
|
+
totalUsage += currentCapacity;
|
|
149
|
+
});
|
|
150
|
+
capacityUsageByType[formId] = totalUsage;
|
|
151
|
+
});
|
|
152
|
+
return capacityUsageByType;
|
|
153
|
+
}
|
|
154
|
+
function getResourcesIdsByProduct(product) {
|
|
155
|
+
var _a, _b, _c;
|
|
156
|
+
const tempResourceIds = [];
|
|
157
|
+
(_c = (_b = (_a = product == null ? void 0 : product.product_resource) == null ? void 0 : _a.resources) == null ? void 0 : _b.forEach) == null ? void 0 : _c.call(_b, (resource) => {
|
|
158
|
+
var _a2, _b2;
|
|
159
|
+
if ((resource == null ? void 0 : resource.status) == 1) {
|
|
160
|
+
if ((_a2 = resource == null ? void 0 : resource.default_resource) == null ? void 0 : _a2.length) {
|
|
161
|
+
tempResourceIds.push(...resource == null ? void 0 : resource.default_resource);
|
|
162
|
+
} else if ((_b2 = resource == null ? void 0 : resource.optional_resource) == null ? void 0 : _b2.length) {
|
|
163
|
+
tempResourceIds.push(...resource == null ? void 0 : resource.optional_resource);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
return tempResourceIds;
|
|
168
|
+
}
|
|
169
|
+
function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, allResources) {
|
|
170
|
+
var _a, _b;
|
|
171
|
+
const resourceTypeMap = {};
|
|
172
|
+
allResources.forEach((resource) => {
|
|
173
|
+
var _a2;
|
|
174
|
+
const formId = ((_a2 = resource.form_id) == null ? void 0 : _a2.toString()) || "default";
|
|
175
|
+
if (!resourceTypeMap[formId]) {
|
|
176
|
+
resourceTypeMap[formId] = [];
|
|
177
|
+
}
|
|
178
|
+
resourceTypeMap[formId].push(resource);
|
|
179
|
+
});
|
|
180
|
+
const requiredCapacityByType = {};
|
|
181
|
+
cartItems.forEach((cartItem) => {
|
|
182
|
+
const productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
183
|
+
const { currentCapacity } = getCapacityInfoByCartItem(cartItem);
|
|
184
|
+
Object.keys(resourceTypeMap).forEach((formId) => {
|
|
185
|
+
var _a2, _b2, _c, _d;
|
|
186
|
+
const resourcesInType = resourceTypeMap[formId];
|
|
187
|
+
const resourceIdsInType = resourcesInType.map((r) => r.id);
|
|
188
|
+
const selectType = (_d = (_c = (_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c.find((r) => {
|
|
189
|
+
var _a3;
|
|
190
|
+
return ((_a3 = r.id) == null ? void 0 : _a3.toString()) === formId;
|
|
191
|
+
})) == null ? void 0 : _d.type;
|
|
192
|
+
const needsThisResourceType = productResourceIds.some(
|
|
193
|
+
(id) => resourceIdsInType.includes(id)
|
|
194
|
+
);
|
|
195
|
+
if (needsThisResourceType) {
|
|
196
|
+
if (selectType === "single") {
|
|
197
|
+
requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + ((cartItem == null ? void 0 : cartItem.num) || 1);
|
|
198
|
+
} else {
|
|
199
|
+
requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
for (const [formId, requiredCapacity] of Object.entries(requiredCapacityByType)) {
|
|
205
|
+
const resourcesInType = resourceTypeMap[formId];
|
|
206
|
+
if (resourcesInType.length === 0)
|
|
207
|
+
continue;
|
|
208
|
+
let resourceTypeConfig = null;
|
|
209
|
+
for (const cartItem of cartItems) {
|
|
210
|
+
if ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) {
|
|
211
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(
|
|
212
|
+
(r) => {
|
|
213
|
+
var _a2;
|
|
214
|
+
return ((_a2 = r.id) == null ? void 0 : _a2.toString()) === formId && r.status === 1;
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
if (resourceTypeConfig)
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const isMultipleBooking = (resourceTypeConfig == null ? void 0 : resourceTypeConfig.type) === "multiple";
|
|
222
|
+
console.log(`capacity.ts - 资源类型 ${formId} 配置:`, {
|
|
223
|
+
resourceTypeConfig,
|
|
224
|
+
type: resourceTypeConfig == null ? void 0 : resourceTypeConfig.type,
|
|
225
|
+
isMultipleBooking,
|
|
226
|
+
requiredCapacity
|
|
227
|
+
});
|
|
228
|
+
if (isMultipleBooking) {
|
|
229
|
+
let totalAvailableCapacity = 0;
|
|
230
|
+
resourcesInType.forEach((resource) => {
|
|
231
|
+
const availableTimes = resource.times.filter((time) => {
|
|
232
|
+
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");
|
|
233
|
+
});
|
|
234
|
+
if (availableTimes.length > 0) {
|
|
235
|
+
totalAvailableCapacity += resource.capacity || 0;
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
console.log(`capacity.ts - 资源类型 ${formId} 多个预约检查: 总容量 ${totalAvailableCapacity}, 需求 ${requiredCapacity}`);
|
|
239
|
+
if (totalAvailableCapacity < requiredCapacity) {
|
|
240
|
+
console.log(`资源类型 ${formId} 容量不足: 需要 ${requiredCapacity}, 可用 ${totalAvailableCapacity}`);
|
|
241
|
+
return {
|
|
242
|
+
success: false,
|
|
243
|
+
required: requiredCapacity,
|
|
244
|
+
available: totalAvailableCapacity
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
let availableResourceCount = 0;
|
|
249
|
+
resourcesInType.forEach((resource) => {
|
|
250
|
+
const availableTimes = resource.times.filter((time) => {
|
|
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;
|
|
253
|
+
});
|
|
254
|
+
if (availableTimes.length > 0) {
|
|
255
|
+
availableResourceCount++;
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
console.log(`capacity.ts - 资源类型 ${formId} 单个预约检查: 可用资源数 ${availableResourceCount}, 需求 ${requiredCapacity}`);
|
|
259
|
+
if (availableResourceCount < requiredCapacity) {
|
|
260
|
+
console.log(`资源类型 ${formId} 数量不足: 需要 ${requiredCapacity}, 可用 ${availableResourceCount}`);
|
|
261
|
+
return {
|
|
262
|
+
success: false,
|
|
263
|
+
required: requiredCapacity,
|
|
264
|
+
available: availableResourceCount
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
success: true,
|
|
271
|
+
required: 0,
|
|
272
|
+
available: 0
|
|
273
|
+
};
|
|
274
|
+
}
|
|
99
275
|
// Annotate the CommonJS export names for ESM import in node:
|
|
100
276
|
0 && (module.exports = {
|
|
277
|
+
calculateCartItemsCapacityUsageByResourceType,
|
|
101
278
|
checkResourceCanUseByCapacity,
|
|
102
279
|
checkSubResourcesCapacity,
|
|
280
|
+
checkTimeSlotCapacity,
|
|
103
281
|
formatDefaultCapacitys,
|
|
104
282
|
getCapacityInfoByCartItem,
|
|
283
|
+
getResourcesIdsByProduct,
|
|
105
284
|
getSumCapacity
|
|
106
285
|
});
|
|
@@ -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: 根据时间切片、资源、当前预约量判断时间切片是否可用
|
|
@@ -43,6 +43,7 @@ __export(resources_exports, {
|
|
|
43
43
|
getTimeSlicesByResource: () => getTimeSlicesByResource,
|
|
44
44
|
getTimeSlicesByResources: () => getTimeSlicesByResources,
|
|
45
45
|
getTimesIntersection: () => getTimesIntersection,
|
|
46
|
+
isConflict: () => isConflict,
|
|
46
47
|
mergeSubResourcesTimeSlices: () => mergeSubResourcesTimeSlices,
|
|
47
48
|
sortCombinedResources: () => sortCombinedResources
|
|
48
49
|
});
|
|
@@ -636,6 +637,7 @@ function checkTwoResourcesIntersection(resource1, resource2) {
|
|
|
636
637
|
getTimeSlicesByResource,
|
|
637
638
|
getTimeSlicesByResources,
|
|
638
639
|
getTimesIntersection,
|
|
640
|
+
isConflict,
|
|
639
641
|
mergeSubResourcesTimeSlices,
|
|
640
642
|
sortCombinedResources
|
|
641
643
|
});
|
|
@@ -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,89 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/solution/BookingByStep/utils/stock.ts
|
|
20
|
+
var stock_exports = {};
|
|
21
|
+
__export(stock_exports, {
|
|
22
|
+
checkProductStock: () => checkProductStock
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(stock_exports);
|
|
25
|
+
function checkProductStock({
|
|
26
|
+
productData,
|
|
27
|
+
product_variant_id,
|
|
28
|
+
quantity,
|
|
29
|
+
bundle,
|
|
30
|
+
currentCartItems
|
|
31
|
+
}) {
|
|
32
|
+
let mainProductConfig = productData;
|
|
33
|
+
if (product_variant_id && productData.variant && Array.isArray(productData.variant)) {
|
|
34
|
+
const variant = productData.variant.find((v) => v.id === product_variant_id);
|
|
35
|
+
if (variant) {
|
|
36
|
+
mainProductConfig = variant;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const isMainProductTrackingEnabled = mainProductConfig.is_track === 1 || mainProductConfig.is_track === true;
|
|
40
|
+
const isMainProductOverSoldDisabled = mainProductConfig.over_sold === 0;
|
|
41
|
+
if (isMainProductTrackingEnabled && isMainProductOverSoldDisabled) {
|
|
42
|
+
const existingQuantity = currentCartItems.reduce((total, cartItem) => {
|
|
43
|
+
var _a, _b, _c;
|
|
44
|
+
const isSameProduct = ((_a = cartItem._productOrigin) == null ? void 0 : _a.id) === productData.id;
|
|
45
|
+
const isSameVariant = !product_variant_id && !((_b = cartItem._productOrigin) == null ? void 0 : _b.product_variant_id) || ((_c = cartItem._productOrigin) == null ? void 0 : _c.product_variant_id) === product_variant_id;
|
|
46
|
+
if (isSameProduct && isSameVariant) {
|
|
47
|
+
return total + (cartItem.num || 0);
|
|
48
|
+
}
|
|
49
|
+
return total;
|
|
50
|
+
}, 0);
|
|
51
|
+
const totalQuantity = existingQuantity + quantity;
|
|
52
|
+
const stockQuantity = mainProductConfig.stock_quantity;
|
|
53
|
+
if (stockQuantity !== void 0 && stockQuantity !== null && totalQuantity > stockQuantity) {
|
|
54
|
+
return { success: false, errorCode: "not_enough_stock" };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (bundle && Array.isArray(bundle)) {
|
|
58
|
+
for (const bundleItem of bundle) {
|
|
59
|
+
const bundleProductId = bundleItem.bundle_product_id;
|
|
60
|
+
const bundleStockQuantity = bundleItem.stock_quantity;
|
|
61
|
+
const bundleRequiredQuantity = (bundleItem.num || 1) * quantity;
|
|
62
|
+
const isBundleTrackingEnabled = bundleItem.is_track === 1 || bundleItem.is_track === true;
|
|
63
|
+
const isBundleOverSoldDisabled = bundleItem.over_sold === 0;
|
|
64
|
+
if (!isBundleTrackingEnabled || !isBundleOverSoldDisabled)
|
|
65
|
+
continue;
|
|
66
|
+
if (bundleStockQuantity === void 0 || bundleStockQuantity === null)
|
|
67
|
+
continue;
|
|
68
|
+
const existingBundleQuantity = currentCartItems.reduce((total, cartItem) => {
|
|
69
|
+
if (!cartItem._bundleOrigin || !Array.isArray(cartItem._bundleOrigin))
|
|
70
|
+
return total;
|
|
71
|
+
cartItem._bundleOrigin.forEach((cartBundleItem) => {
|
|
72
|
+
if (cartBundleItem.bundle_product_id === bundleProductId) {
|
|
73
|
+
total += (cartBundleItem.num || 1) * (cartItem.num || 1);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return total;
|
|
77
|
+
}, 0);
|
|
78
|
+
const totalBundleQuantity = existingBundleQuantity + bundleRequiredQuantity;
|
|
79
|
+
if (totalBundleQuantity > bundleStockQuantity) {
|
|
80
|
+
return { success: false, errorCode: "not_enough_stock" };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { success: true };
|
|
85
|
+
}
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
checkProductStock
|
|
89
|
+
});
|
|
@@ -225,6 +225,15 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
225
225
|
isScan: true
|
|
226
226
|
};
|
|
227
227
|
});
|
|
228
|
+
const currentSelectedDiscountList = this.getDiscountList().filter((n) => n.isSelected);
|
|
229
|
+
if (currentSelectedDiscountList.length && currentSelectedDiscountList.some((n) => withScanList.some((m) => m.id === n.id))) {
|
|
230
|
+
return {
|
|
231
|
+
type: "clientCalc",
|
|
232
|
+
isAvailable: true,
|
|
233
|
+
productList: this.store.productList || [],
|
|
234
|
+
discountList: this.getDiscountList()
|
|
235
|
+
};
|
|
236
|
+
}
|
|
228
237
|
const {
|
|
229
238
|
productList: newProductList,
|
|
230
239
|
discountList: newDiscountList,
|