@pisell/pisellos 3.0.41 → 3.0.43
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/AccountList/index.js +17 -12
- package/dist/modules/Cart/index.d.ts +14 -0
- package/dist/modules/Cart/index.js +38 -1
- package/dist/modules/Cart/utils/cartProduct.d.ts +3 -0
- package/dist/modules/Cart/utils/cartProduct.js +28 -8
- package/dist/modules/Cart/utils/changePrice.d.ts +3 -0
- package/dist/modules/Cart/utils/changePrice.js +104 -0
- package/dist/modules/Date/index.js +74 -10
- package/dist/modules/Date/types.d.ts +2 -0
- package/dist/modules/Discount/index.d.ts +1 -0
- package/dist/modules/Discount/index.js +13 -6
- package/dist/modules/Discount/types.d.ts +10 -0
- package/dist/modules/ProductList/index.d.ts +7 -0
- package/dist/modules/ProductList/index.js +102 -39
- package/dist/modules/Rules/index.js +218 -80
- package/dist/modules/Rules/types.d.ts +7 -1
- package/dist/modules/Schedule/index.d.ts +9 -1
- package/dist/modules/Schedule/index.js +122 -2
- package/dist/modules/Schedule/types.d.ts +13 -0
- package/dist/modules/Schedule/utils.js +4 -0
- package/dist/solution/BookingByStep/index.d.ts +121 -30
- package/dist/solution/BookingByStep/index.js +760 -1065
- package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
- package/dist/solution/BookingByStep/utils/capacity.js +132 -0
- package/dist/solution/BookingByStep/utils/resources.d.ts +21 -29
- package/dist/solution/BookingByStep/utils/resources.js +39 -95
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
- package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
- package/dist/solution/ShopDiscount/index.d.ts +2 -0
- package/dist/solution/ShopDiscount/index.js +119 -44
- package/lib/modules/AccountList/index.js +4 -0
- package/lib/modules/Cart/index.d.ts +14 -0
- package/lib/modules/Cart/index.js +34 -1
- package/lib/modules/Cart/utils/cartProduct.d.ts +3 -0
- package/lib/modules/Cart/utils/cartProduct.js +20 -8
- package/lib/modules/Cart/utils/changePrice.d.ts +3 -0
- package/lib/modules/Cart/utils/changePrice.js +78 -0
- package/lib/modules/Date/index.js +62 -5
- package/lib/modules/Date/types.d.ts +2 -0
- package/lib/modules/Discount/index.d.ts +1 -0
- package/lib/modules/Discount/index.js +17 -6
- package/lib/modules/Discount/types.d.ts +10 -0
- package/lib/modules/ProductList/index.d.ts +7 -0
- package/lib/modules/ProductList/index.js +45 -0
- package/lib/modules/Rules/index.js +154 -63
- package/lib/modules/Rules/types.d.ts +7 -1
- package/lib/modules/Schedule/index.d.ts +9 -1
- package/lib/modules/Schedule/index.js +79 -1
- package/lib/modules/Schedule/types.d.ts +13 -0
- package/lib/modules/Schedule/utils.js +4 -1
- package/lib/solution/BookingByStep/index.d.ts +121 -30
- package/lib/solution/BookingByStep/index.js +395 -585
- package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
- package/lib/solution/BookingByStep/utils/capacity.js +106 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +21 -29
- package/lib/solution/BookingByStep/utils/resources.js +21 -58
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
- package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
- package/lib/solution/ShopDiscount/index.d.ts +2 -0
- package/lib/solution/ShopDiscount/index.js +91 -19
- package/package.json +1 -1
|
@@ -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,6 +16,14 @@ 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/modules/Rules/index.ts
|
|
@@ -26,6 +36,7 @@ var import_BaseModule = require("../BaseModule");
|
|
|
26
36
|
var import_types = require("./types");
|
|
27
37
|
var import_utils = require("../../solution/ShopDiscount/utils");
|
|
28
38
|
var import_utils2 = require("../Cart/utils");
|
|
39
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
29
40
|
var RulesModule = class extends import_BaseModule.BaseModule {
|
|
30
41
|
constructor(name, version) {
|
|
31
42
|
super(name, version);
|
|
@@ -58,8 +69,20 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
58
69
|
productList
|
|
59
70
|
};
|
|
60
71
|
}
|
|
72
|
+
if (productList.every((item) => {
|
|
73
|
+
var _a;
|
|
74
|
+
const product = this.hooks.getProduct(item);
|
|
75
|
+
return product.booking_id && (((_a = product.discount_list) == null ? void 0 : _a.length) || (newDiscountList[0].tag === "good_pass" ? product.price == 0 : product.total == 0));
|
|
76
|
+
})) {
|
|
77
|
+
return {
|
|
78
|
+
isAvailable: false,
|
|
79
|
+
discountList: oldDiscountList,
|
|
80
|
+
productList
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const filteredOldDiscountList = oldDiscountList.filter((discount) => !discount.isEditMode && discount.tag !== "good_pass");
|
|
61
84
|
const mergedDiscountList = (0, import_utils.uniqueById)((0, import_utils.uniqueById)([
|
|
62
|
-
...
|
|
85
|
+
...filteredOldDiscountList,
|
|
63
86
|
...newDiscountList
|
|
64
87
|
]), "product_id");
|
|
65
88
|
const result = this.calcDiscount({
|
|
@@ -94,6 +117,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
94
117
|
discountList,
|
|
95
118
|
productList
|
|
96
119
|
}, options) {
|
|
120
|
+
const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
|
|
97
121
|
const editModeDiscount = [];
|
|
98
122
|
const addModeDiscount = [];
|
|
99
123
|
discountList.forEach((discount) => {
|
|
@@ -107,19 +131,43 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
107
131
|
return !discount.isManualSelect;
|
|
108
132
|
});
|
|
109
133
|
const sortedDiscountList = [...filteredDiscountList].sort((a, b) => {
|
|
110
|
-
if (a.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return
|
|
134
|
+
if (a.tag === "good_pass" && b.tag !== "good_pass")
|
|
135
|
+
return -1;
|
|
136
|
+
if (b.tag === "good_pass" && a.tag !== "good_pass")
|
|
137
|
+
return 1;
|
|
138
|
+
if (a.tag === "good_pass" && b.tag === "good_pass") {
|
|
139
|
+
return compareByExpireTime(a, b);
|
|
140
|
+
} else if (a.tag === "product_discount_card" && b.tag === "product_discount_card") {
|
|
141
|
+
if (a.par_value !== b.par_value) {
|
|
142
|
+
const valueA = new import_decimal.default(100).minus(a.par_value || 0);
|
|
143
|
+
const valueB = new import_decimal.default(100).minus(b.par_value || 0);
|
|
144
|
+
return valueA.minus(valueB).toNumber();
|
|
145
|
+
}
|
|
146
|
+
return compareByExpireTime(a, b);
|
|
147
|
+
}
|
|
148
|
+
return compareByExpireTime(a, b);
|
|
149
|
+
function compareByExpireTime(itemA, itemB) {
|
|
150
|
+
if (itemA.expire_time && itemB.expire_time) {
|
|
151
|
+
const timeA = new Date(itemA.expire_time).getTime();
|
|
152
|
+
const timeB = new Date(itemB.expire_time).getTime();
|
|
153
|
+
return timeA - timeB;
|
|
154
|
+
}
|
|
155
|
+
return itemA.expire_time ? -1 : itemB.expire_time ? 1 : 0;
|
|
114
156
|
}
|
|
115
|
-
return a.expire_time ? -1 : b.expire_time ? 1 : 0;
|
|
116
157
|
});
|
|
117
158
|
const sortedProductList = [...productList].sort((a, b) => {
|
|
159
|
+
var _a, _b;
|
|
118
160
|
const aProduct = this.hooks.getProduct(a);
|
|
119
161
|
const bProduct = this.hooks.getProduct(b);
|
|
120
|
-
const priceA =
|
|
121
|
-
const priceB =
|
|
122
|
-
|
|
162
|
+
const priceA = new import_decimal.default(aProduct.price || "0");
|
|
163
|
+
const priceB = new import_decimal.default(bProduct.price || "0");
|
|
164
|
+
if (priceA.toNumber() === priceB.toNumber()) {
|
|
165
|
+
if (aProduct.quantity === bProduct.quantity) {
|
|
166
|
+
return ((_a = bProduct.discount_list) == null ? void 0 : _a.length) - ((_b = aProduct.discount_list) == null ? void 0 : _b.length);
|
|
167
|
+
}
|
|
168
|
+
return aProduct.quantity - bProduct.quantity;
|
|
169
|
+
}
|
|
170
|
+
return priceB.toNumber() - priceA.toNumber();
|
|
123
171
|
});
|
|
124
172
|
const usedDiscounts = /* @__PURE__ */ new Map();
|
|
125
173
|
const discountApplicability = /* @__PURE__ */ new Map();
|
|
@@ -136,32 +184,42 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
136
184
|
var _a, _b, _c;
|
|
137
185
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
138
186
|
const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
|
|
139
|
-
const isAvailableProduct = !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && discount2.
|
|
187
|
+
const isAvailableProduct = !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.tag || discount2.type))));
|
|
140
188
|
if (isAvailableProduct && isLimitedProduct) {
|
|
141
189
|
(_c = discountApplicability.get(discount.id)) == null ? void 0 : _c.push(product.id);
|
|
142
190
|
const applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
143
191
|
applicableProducts.push({
|
|
144
192
|
amount: product.price,
|
|
145
|
-
type: discount.tag,
|
|
193
|
+
type: discount.tag || discount.type,
|
|
194
|
+
tag: discount.tag || discount.type,
|
|
146
195
|
discount: {
|
|
147
196
|
resource_id: discount.id,
|
|
148
197
|
title: discount.format_title,
|
|
149
|
-
original_amount: product.origin_total
|
|
150
|
-
|
|
198
|
+
original_amount: product.origin_total,
|
|
199
|
+
pre_value: discount.par_value,
|
|
200
|
+
product_id: originProduct.id
|
|
201
|
+
},
|
|
202
|
+
num: product.num || 1
|
|
151
203
|
});
|
|
152
204
|
discountApplicableProducts.set(discount.id, applicableProducts);
|
|
153
205
|
}
|
|
154
206
|
});
|
|
155
207
|
});
|
|
156
|
-
|
|
157
|
-
|
|
208
|
+
console.log(sortedProductList, "sortedProductListsortedProductList");
|
|
209
|
+
sortedProductList.forEach((originProduct, i) => {
|
|
210
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
158
211
|
const product = this.hooks.getProduct(originProduct);
|
|
159
|
-
if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && discount.
|
|
160
|
-
processedProductsMap.set(product._id, originProduct);
|
|
212
|
+
if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag || discount.type)))) {
|
|
213
|
+
processedProductsMap.set(product._id, [originProduct]);
|
|
161
214
|
return;
|
|
162
215
|
}
|
|
163
216
|
const applicableDiscounts = sortedDiscountList.filter((discount) => {
|
|
164
|
-
if (
|
|
217
|
+
if ((Number(product.price) === 0 || !product.price) && (discount.tag || discount.type) === "good_pass")
|
|
218
|
+
return false;
|
|
219
|
+
if ((Number(product.total) === 0 || !product.total) && (discount.tag || discount.type) !== "good_pass")
|
|
220
|
+
return false;
|
|
221
|
+
const targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
222
|
+
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
|
|
165
223
|
return false;
|
|
166
224
|
const limitedData = discount.limited_relation_product_data;
|
|
167
225
|
if (limitedData.type === "product_all") {
|
|
@@ -171,16 +229,20 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
171
229
|
}
|
|
172
230
|
return false;
|
|
173
231
|
});
|
|
174
|
-
const
|
|
232
|
+
const selectedDiscountCard = applicableDiscounts.find((n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass");
|
|
233
|
+
const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
|
|
175
234
|
let isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (!((_c = product.discount_list) == null ? void 0 : _c.length) || ((_e = (_d = product == null ? void 0 : product.discount_list) == null ? void 0 : _d.every) == null ? void 0 : _e.call(_d, (item) => item.type === "product")));
|
|
176
|
-
if ((options == null ? void 0 : options.discountId) && (
|
|
235
|
+
if ((options == null ? void 0 : options.discountId) && ((_f = product.discount_list) == null ? void 0 : _f.some((item) => {
|
|
236
|
+
var _a2;
|
|
237
|
+
return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
|
|
238
|
+
}))) {
|
|
177
239
|
isManualDiscount = false;
|
|
178
240
|
}
|
|
179
241
|
if (applicableDiscounts.length === 0 || isManualDiscount) {
|
|
180
242
|
if (product.isClient) {
|
|
181
243
|
processedProductsMap.set(
|
|
182
244
|
product._id,
|
|
183
|
-
this.hooks.setProduct(originProduct, {
|
|
245
|
+
[this.hooks.setProduct(originProduct, {
|
|
184
246
|
...isManualDiscount ? {} : {
|
|
185
247
|
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
186
248
|
product: {
|
|
@@ -189,6 +251,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
189
251
|
bundle: product.bundle,
|
|
190
252
|
options: product.options
|
|
191
253
|
}),
|
|
254
|
+
variant: originProduct._productInit.variant,
|
|
255
|
+
original_price: originProduct._productInit.original_price,
|
|
192
256
|
total: (0, import_utils2.getProductTotalPrice)({
|
|
193
257
|
product: {
|
|
194
258
|
price: product.price
|
|
@@ -199,45 +263,67 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
199
263
|
price: product.price
|
|
200
264
|
},
|
|
201
265
|
discount_list: []
|
|
202
|
-
})
|
|
266
|
+
})]
|
|
203
267
|
);
|
|
204
268
|
} else {
|
|
205
269
|
processedProductsMap.set(
|
|
206
270
|
product._id,
|
|
207
|
-
this.hooks.setProduct(originProduct, {
|
|
271
|
+
[this.hooks.setProduct(originProduct, {
|
|
208
272
|
...isManualDiscount ? {} : {
|
|
273
|
+
_id: product._id.split("___")[0] + "___" + i,
|
|
209
274
|
total: product.origin_total || product.total,
|
|
210
275
|
price: product.price
|
|
211
276
|
},
|
|
212
277
|
discount_list: []
|
|
213
|
-
})
|
|
278
|
+
})]
|
|
214
279
|
);
|
|
215
280
|
}
|
|
216
281
|
return;
|
|
217
282
|
}
|
|
218
|
-
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan)) {
|
|
283
|
+
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan) && !isEditModeAddNewProduct) {
|
|
219
284
|
return;
|
|
220
285
|
}
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
286
|
+
const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
|
|
287
|
+
const splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length) : 1;
|
|
288
|
+
const arr = [];
|
|
289
|
+
if (splitCount < product.quantity && isNeedSplit) {
|
|
290
|
+
arr.push(this.hooks.setProduct(originProduct, {
|
|
291
|
+
discount_list: [],
|
|
292
|
+
quantity: product.quantity - splitCount,
|
|
293
|
+
_id: product._id.split("___")[0]
|
|
294
|
+
}));
|
|
295
|
+
}
|
|
296
|
+
for (let i2 = 0; i2 < splitCount; i2++) {
|
|
297
|
+
const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[i2];
|
|
298
|
+
usedDiscounts.set(selectedDiscount2.id, true);
|
|
299
|
+
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
300
|
+
let productOriginTotal = product.origin_total || product.total || 0;
|
|
301
|
+
if (Number(((_g = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _g.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
|
|
302
|
+
productOriginTotal = product.total;
|
|
231
303
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
304
|
+
if ((_h = product.discount_list) == null ? void 0 : _h.length) {
|
|
305
|
+
productOriginTotal = product.origin_total;
|
|
306
|
+
}
|
|
307
|
+
const targetProductTotal = selectedDiscount2.tag === "good_pass" ? new import_decimal.default(productOriginTotal).minus(new import_decimal.default(product.price || 0)).toNumber() : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(productOriginTotal)).toNumber();
|
|
308
|
+
const discountDetail = {
|
|
309
|
+
amount: new import_decimal.default(productOriginTotal).minus(new import_decimal.default(targetProductTotal)).toNumber(),
|
|
310
|
+
type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
|
|
311
|
+
discount: {
|
|
312
|
+
resource_id: selectedDiscount2.id,
|
|
313
|
+
title: selectedDiscount2.format_title,
|
|
314
|
+
original_amount: productOriginTotal,
|
|
315
|
+
product_id: originProduct.id,
|
|
316
|
+
percent: selectedDiscount2.par_value
|
|
317
|
+
},
|
|
318
|
+
num: product.num || 1
|
|
319
|
+
};
|
|
320
|
+
appliedProducts.push(discountDetail);
|
|
321
|
+
appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
|
|
322
|
+
if (product.isClient) {
|
|
323
|
+
arr.push(this.hooks.setProduct(originProduct, {
|
|
239
324
|
discount_list: [discountDetail],
|
|
240
|
-
price: 0,
|
|
325
|
+
price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
|
|
326
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
241
327
|
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
242
328
|
product: {
|
|
243
329
|
original_price: product.original_price
|
|
@@ -245,28 +331,26 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
245
331
|
bundle: product.bundle,
|
|
246
332
|
options: product.options
|
|
247
333
|
}),
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
})
|
|
255
|
-
})
|
|
256
|
-
);
|
|
257
|
-
} else {
|
|
258
|
-
processedProductsMap.set(
|
|
259
|
-
product._id,
|
|
260
|
-
this.hooks.setProduct(originProduct, {
|
|
334
|
+
variant: originProduct._productInit.variant,
|
|
335
|
+
original_price: new import_decimal.default(product.price || 0).toNumber(),
|
|
336
|
+
total: targetProductTotal
|
|
337
|
+
}));
|
|
338
|
+
} else {
|
|
339
|
+
arr.push(this.hooks.setProduct(originProduct, {
|
|
261
340
|
discount_list: [discountDetail],
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
341
|
+
_id: product._id.split("___")[0] + "___" + selectedDiscount2.id,
|
|
342
|
+
price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
|
|
343
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
344
|
+
total: targetProductTotal,
|
|
345
|
+
origin_total: productOriginTotal
|
|
346
|
+
}));
|
|
347
|
+
}
|
|
267
348
|
}
|
|
349
|
+
console.log(arr, "arrarrarr");
|
|
350
|
+
processedProductsMap.set(product._id, arr);
|
|
268
351
|
});
|
|
269
|
-
const processedProductList =
|
|
352
|
+
const processedProductList = [];
|
|
353
|
+
productList.forEach((originProduct) => {
|
|
270
354
|
const product = this.hooks.getProduct(originProduct);
|
|
271
355
|
const getDefaultProduct = () => {
|
|
272
356
|
if (product.isClient) {
|
|
@@ -280,6 +364,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
280
364
|
bundle: product.bundle,
|
|
281
365
|
options: product.options
|
|
282
366
|
}),
|
|
367
|
+
variant: originProduct._productInit.variant,
|
|
368
|
+
original_price: originProduct._productInit.original_price,
|
|
283
369
|
total: (0, import_utils2.getProductTotalPrice)({
|
|
284
370
|
product: {
|
|
285
371
|
price: product.price
|
|
@@ -297,7 +383,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
297
383
|
});
|
|
298
384
|
}
|
|
299
385
|
};
|
|
300
|
-
|
|
386
|
+
const arr = processedProductsMap.get(product._id);
|
|
387
|
+
(arr == null ? void 0 : arr.length) ? processedProductList.push(...arr) : processedProductList.push(getDefaultProduct());
|
|
301
388
|
});
|
|
302
389
|
const updatedDiscountList = addModeDiscount.map((discount) => {
|
|
303
390
|
const applicableProducts = discountApplicability.get(discount.id) || [];
|
|
@@ -321,6 +408,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
321
408
|
return {
|
|
322
409
|
...discount,
|
|
323
410
|
isSelected: true,
|
|
411
|
+
isManualSelect: (options == null ? void 0 : options.scan) ? false : discount.isManualSelect,
|
|
324
412
|
// 标记为可用,因为它已被应用
|
|
325
413
|
isAvailable: true,
|
|
326
414
|
// 记录适用的商品IDs
|
|
@@ -342,6 +430,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
342
430
|
// 如果有适用的商品,标记为可用
|
|
343
431
|
isAvailable,
|
|
344
432
|
isSelected,
|
|
433
|
+
// 如果是扫码进来的,要手动设置为手动选择:false
|
|
434
|
+
isManualSelect: (options == null ? void 0 : options.scan) ? false : discount.isManualSelect,
|
|
345
435
|
// 记录适用的商品IDs
|
|
346
436
|
applicableProductIds: applicableProducts,
|
|
347
437
|
// 添加可抵扣的商品详情
|
|
@@ -350,6 +440,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
350
440
|
appliedProductDetails: []
|
|
351
441
|
};
|
|
352
442
|
});
|
|
443
|
+
console.log(processedProductList, "processedProductList");
|
|
353
444
|
return {
|
|
354
445
|
productList: processedProductList,
|
|
355
446
|
discountList: [...editModeDiscount, ...updatedDiscountList]
|
|
@@ -37,14 +37,20 @@ type ProductDetail = {
|
|
|
37
37
|
options?: any[];
|
|
38
38
|
bundle?: any[];
|
|
39
39
|
original_price?: number | string;
|
|
40
|
+
num?: number;
|
|
41
|
+
quantity: number;
|
|
40
42
|
};
|
|
41
43
|
export interface RulesParamsHooks {
|
|
42
44
|
getProduct: (product: Record<string, any>) => ProductDetail;
|
|
43
45
|
setProduct: (product: Record<string, any>, values: {
|
|
46
|
+
_id?: string;
|
|
44
47
|
total?: number;
|
|
45
48
|
discount_list: any[];
|
|
46
49
|
origin_total?: number;
|
|
47
|
-
price?: number;
|
|
50
|
+
price?: string | number;
|
|
51
|
+
variant?: any[];
|
|
52
|
+
original_price?: number;
|
|
53
|
+
quantity?: number;
|
|
48
54
|
}) => Record<string, any>;
|
|
49
55
|
}
|
|
50
56
|
export {};
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { Module, PisellCore, ModuleOptions } from '../../types';
|
|
2
2
|
import { BaseModule } from '../BaseModule';
|
|
3
|
-
import { ScheduleModuleAPI, ScheduleAvailabilityDateItem, ScheduleItem } from './types';
|
|
3
|
+
import { ScheduleModuleAPI, ScheduleAvailabilityDateItem, ScheduleItem, LoadScheduleAvailableDateParams } from './types';
|
|
4
4
|
export declare class ScheduleModule extends BaseModule implements Module, ScheduleModuleAPI {
|
|
5
5
|
protected defaultName: string;
|
|
6
6
|
protected defaultVersion: string;
|
|
7
|
+
private request;
|
|
7
8
|
private store;
|
|
8
9
|
private cacheId;
|
|
9
10
|
private openCache;
|
|
10
11
|
private fatherModule;
|
|
11
12
|
constructor(name?: string, version?: string);
|
|
12
13
|
initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* 加载当前店铺下所有 schedule
|
|
16
|
+
*
|
|
17
|
+
* @memberof ScheduleModule
|
|
18
|
+
*/
|
|
19
|
+
loadAllSchedule(): Promise<void>;
|
|
13
20
|
setScheduleList(list: ScheduleItem[]): void;
|
|
21
|
+
loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel, }: LoadScheduleAvailableDateParams): Promise<import("../Date/types").ITime[]>;
|
|
14
22
|
getScheduleListByIds(ids: number[]): ScheduleItem[];
|
|
15
23
|
setAvailabilityScheduleDateList(list: ScheduleAvailabilityDateItem[]): void;
|
|
16
24
|
getAvailabilityScheduleDateList(): ScheduleAvailabilityDateItem[];
|
|
@@ -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,6 +16,14 @@ 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/modules/Schedule/index.ts
|
|
@@ -24,6 +34,12 @@ __export(Schedule_exports, {
|
|
|
24
34
|
module.exports = __toCommonJS(Schedule_exports);
|
|
25
35
|
var import_lodash_es = require("lodash-es");
|
|
26
36
|
var import_BaseModule = require("../BaseModule");
|
|
37
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
38
|
+
var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
|
|
39
|
+
var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
|
|
40
|
+
var import_utils = require("../Date/utils");
|
|
41
|
+
import_dayjs.default.extend(import_isSameOrBefore.default);
|
|
42
|
+
import_dayjs.default.extend(import_isSameOrAfter.default);
|
|
27
43
|
var ScheduleModule = class extends import_BaseModule.BaseModule {
|
|
28
44
|
constructor(name, version) {
|
|
29
45
|
super(name, version);
|
|
@@ -35,6 +51,10 @@ var ScheduleModule = class extends import_BaseModule.BaseModule {
|
|
|
35
51
|
async initialize(core, options) {
|
|
36
52
|
var _a, _b;
|
|
37
53
|
this.core = core;
|
|
54
|
+
this.request = core.getPlugin("request");
|
|
55
|
+
if (!this.request) {
|
|
56
|
+
throw new Error("ScheduleModule 需要 request 插件支持");
|
|
57
|
+
}
|
|
38
58
|
this.store = options == null ? void 0 : options.store;
|
|
39
59
|
if (options.initialState) {
|
|
40
60
|
this.store.scheduleList = options.initialState.scheduleList;
|
|
@@ -51,9 +71,67 @@ var ScheduleModule = class extends import_BaseModule.BaseModule {
|
|
|
51
71
|
this.fatherModule = options.otherParams.fatherModule;
|
|
52
72
|
}
|
|
53
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* 加载当前店铺下所有 schedule
|
|
76
|
+
*
|
|
77
|
+
* @memberof ScheduleModule
|
|
78
|
+
*/
|
|
79
|
+
async loadAllSchedule() {
|
|
80
|
+
var _a;
|
|
81
|
+
const scheduleList = await this.request.get(
|
|
82
|
+
`/schedule`,
|
|
83
|
+
{ num: 999 },
|
|
84
|
+
{ useCache: true }
|
|
85
|
+
);
|
|
86
|
+
this.setScheduleList(((_a = scheduleList.data) == null ? void 0 : _a.list) || []);
|
|
87
|
+
}
|
|
54
88
|
setScheduleList(list) {
|
|
55
89
|
this.store.scheduleList = list;
|
|
56
90
|
}
|
|
91
|
+
async loadScheduleAvailableDate({
|
|
92
|
+
startDate,
|
|
93
|
+
endDate,
|
|
94
|
+
custom_page_id,
|
|
95
|
+
channel
|
|
96
|
+
}) {
|
|
97
|
+
var _a, _b, _c;
|
|
98
|
+
if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day")) {
|
|
99
|
+
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
100
|
+
}
|
|
101
|
+
let dates = (0, import_utils.generateMonthDates)(startDate, endDate);
|
|
102
|
+
dates = (0, import_utils.disableAllDates)(dates);
|
|
103
|
+
if ((0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
|
|
104
|
+
return dates;
|
|
105
|
+
}
|
|
106
|
+
const res = await this.request.get(
|
|
107
|
+
`/schedule/product/availability/v2`,
|
|
108
|
+
{
|
|
109
|
+
start_date: startDate,
|
|
110
|
+
end_date: endDate,
|
|
111
|
+
custom_page_id,
|
|
112
|
+
channel
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
this.setAvailabilityScheduleDateList(res.data.date_list);
|
|
116
|
+
this.setOtherProductsIds(res.data.other_product_ids || []);
|
|
117
|
+
if (!((_a = res.data.date_list) == null ? void 0 : _a.length) && !((_b = res.data.other_product_ids) == null ? void 0 : _b.length) || (0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
|
|
118
|
+
return dates;
|
|
119
|
+
}
|
|
120
|
+
if ((_c = res.data.other_product_ids) == null ? void 0 : _c.length) {
|
|
121
|
+
dates.forEach((n) => {
|
|
122
|
+
n.status = "available";
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
res.data.date_list.forEach((n) => {
|
|
126
|
+
const index = dates.findIndex((m) => m.date === n.date);
|
|
127
|
+
if (index !== -1) {
|
|
128
|
+
dates[index].status = "available";
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
dates = (0, import_utils.disableDatesBeforeOneDay)(dates);
|
|
133
|
+
return dates;
|
|
134
|
+
}
|
|
57
135
|
getScheduleListByIds(ids) {
|
|
58
136
|
return this.store.scheduleList.filter((n) => ids.includes(n.id));
|
|
59
137
|
}
|
|
@@ -76,7 +154,7 @@ var ScheduleModule = class extends import_BaseModule.BaseModule {
|
|
|
76
154
|
cacheId: this.cacheId,
|
|
77
155
|
fatherModule: this.fatherModule,
|
|
78
156
|
store,
|
|
79
|
-
cacheKey: ["scheduleList", "availabilityDateList"]
|
|
157
|
+
cacheKey: ["scheduleList", "availabilityDateList", "otherProductsIds"]
|
|
80
158
|
});
|
|
81
159
|
}
|
|
82
160
|
}
|
|
@@ -9,6 +9,19 @@ export type ScheduleAvailabilityDateItem = {
|
|
|
9
9
|
schedule_id: number[];
|
|
10
10
|
product_ids: number[];
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* 加载日程可用日期参数接口
|
|
14
|
+
*/
|
|
15
|
+
export interface LoadScheduleAvailableDateParams {
|
|
16
|
+
/** 开始日期 */
|
|
17
|
+
startDate: string;
|
|
18
|
+
/** 结束日期 */
|
|
19
|
+
endDate: string;
|
|
20
|
+
/** 自定义页面ID */
|
|
21
|
+
custom_page_id?: number;
|
|
22
|
+
/** 渠道 */
|
|
23
|
+
channel?: string;
|
|
24
|
+
}
|
|
12
25
|
export interface ScheduleModuleAPI {
|
|
13
26
|
}
|
|
14
27
|
export type ScheduleItem = {
|
|
@@ -140,7 +140,10 @@ var getDaysByRepeatWeek = (params, isGetRange) => {
|
|
|
140
140
|
for (let i = 0; i < frequency_date.length; i++) {
|
|
141
141
|
const item = frequency_date[i];
|
|
142
142
|
const _start = startTmp.day(item);
|
|
143
|
-
|
|
143
|
+
let _end = _start.add(scheduleDiff, "second");
|
|
144
|
+
if (_end.isAfter(deadline, "day")) {
|
|
145
|
+
_end = deadline;
|
|
146
|
+
}
|
|
144
147
|
if (isGetRange) {
|
|
145
148
|
if (excludedDaysMap.has(_start.format("YYYY-MM-DD"))) {
|
|
146
149
|
startTmp = startTmp.day(1).add(frequency, "day");
|