@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
|
@@ -27,6 +27,7 @@ import { BaseModule } from "../BaseModule";
|
|
|
27
27
|
import { RulesHooks } from "./types";
|
|
28
28
|
import { uniqueById } from "../../solution/ShopDiscount/utils";
|
|
29
29
|
import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
|
|
30
|
+
import Decimal from 'decimal.js';
|
|
30
31
|
export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
31
32
|
_inherits(RulesModule, _BaseModule);
|
|
32
33
|
var _super = _createSuper(RulesModule);
|
|
@@ -106,8 +107,24 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
106
107
|
};
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
//
|
|
110
|
-
|
|
110
|
+
// 编辑商品已有商品券
|
|
111
|
+
if (productList.every(function (item) {
|
|
112
|
+
var _product$discount_lis;
|
|
113
|
+
var product = _this2.hooks.getProduct(item);
|
|
114
|
+
return product.booking_id && (((_product$discount_lis = product.discount_list) === null || _product$discount_lis === void 0 ? void 0 : _product$discount_lis.length) || (newDiscountList[0].tag === 'good_pass' ? product.price == 0 : product.total == 0));
|
|
115
|
+
})) {
|
|
116
|
+
return {
|
|
117
|
+
isAvailable: false,
|
|
118
|
+
discountList: oldDiscountList,
|
|
119
|
+
productList: productList
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 合并新旧折扣列表,并计算折扣结果,注意,如果旧折扣里有 isEditMode 为 true 的优惠券,则不合并
|
|
124
|
+
var filteredOldDiscountList = oldDiscountList.filter(function (discount) {
|
|
125
|
+
return !discount.isEditMode && discount.tag !== 'good_pass';
|
|
126
|
+
});
|
|
127
|
+
var mergedDiscountList = uniqueById(uniqueById([].concat(_toConsumableArray(filteredOldDiscountList), _toConsumableArray(newDiscountList))), 'product_id');
|
|
111
128
|
var result = this.calcDiscount({
|
|
112
129
|
discountList: mergedDiscountList,
|
|
113
130
|
productList: _toConsumableArray(productList)
|
|
@@ -148,6 +165,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
148
165
|
var _this3 = this;
|
|
149
166
|
var discountList = _ref2.discountList,
|
|
150
167
|
productList = _ref2.productList;
|
|
168
|
+
// debugger
|
|
169
|
+
|
|
170
|
+
// 识别出来是不是在编辑的界面里又新增了商品
|
|
171
|
+
// 这种情况下,如果有可用的优惠券,也会自动勾选上
|
|
172
|
+
var isEditModeAddNewProduct = productList.find(function (n) {
|
|
173
|
+
return n.booking_id;
|
|
174
|
+
}) && productList.find(function (n) {
|
|
175
|
+
return !n.booking_id;
|
|
176
|
+
});
|
|
151
177
|
var editModeDiscount = [];
|
|
152
178
|
var addModeDiscount = [];
|
|
153
179
|
discountList.forEach(function (discount) {
|
|
@@ -163,24 +189,69 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
163
189
|
return !discount.isManualSelect;
|
|
164
190
|
});
|
|
165
191
|
|
|
166
|
-
//
|
|
192
|
+
// 优惠力度排序,传进来的数据里可能有商品券,也可能有优惠券
|
|
193
|
+
// 商品券(n.tag=good_pass)视为最优惠(免费),折扣券(n.tag=product_discount_card)按照n.par_value排序
|
|
194
|
+
// 如果最后拍出来商品券有多个,或者说没有商品券,但是有多个相同折扣的折扣券(比如 6 折券有 3张),则按照过期时间(n.expire_time)排序
|
|
167
195
|
var sortedDiscountList = _toConsumableArray(filteredDiscountList).sort(function (a, b) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
196
|
+
// 1. 商品券优先级最高
|
|
197
|
+
if (a.tag === 'good_pass' && b.tag !== 'good_pass') return -1;
|
|
198
|
+
if (b.tag === 'good_pass' && a.tag !== 'good_pass') return 1;
|
|
199
|
+
|
|
200
|
+
// 2. 如果都是商品券或都不是商品券,按照类型和折扣力度排序
|
|
201
|
+
if (a.tag === 'good_pass' && b.tag === 'good_pass') {
|
|
202
|
+
// 都是商品券,按照过期时间排序
|
|
203
|
+
return compareByExpireTime(a, b);
|
|
204
|
+
} else if (a.tag === 'product_discount_card' && b.tag === 'product_discount_card') {
|
|
205
|
+
// 都是折扣券,按照par_value排序(折扣越大越优先,即par_value越小越优先)
|
|
206
|
+
if (a.par_value !== b.par_value) {
|
|
207
|
+
var valueA = new Decimal(100).minus(a.par_value || 0);
|
|
208
|
+
var valueB = new Decimal(100).minus(b.par_value || 0);
|
|
209
|
+
return valueA.minus(valueB).toNumber();
|
|
210
|
+
}
|
|
211
|
+
// 相同折扣的情况下,按照过期时间排序
|
|
212
|
+
return compareByExpireTime(a, b);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 3. 其他情况按照过期时间排序
|
|
216
|
+
return compareByExpireTime(a, b);
|
|
217
|
+
function compareByExpireTime(itemA, itemB) {
|
|
218
|
+
if (itemA.expire_time && itemB.expire_time) {
|
|
219
|
+
var timeA = new Date(itemA.expire_time).getTime();
|
|
220
|
+
var timeB = new Date(itemB.expire_time).getTime();
|
|
221
|
+
return timeA - timeB;
|
|
222
|
+
}
|
|
223
|
+
// 有过期时间的优先级高于永久的
|
|
224
|
+
return itemA.expire_time ? -1 : itemB.expire_time ? 1 : 0;
|
|
172
225
|
}
|
|
173
|
-
// 有过期时间的优先级高于永久的
|
|
174
|
-
return a.expire_time ? -1 : b.expire_time ? 1 : 0;
|
|
175
226
|
});
|
|
176
227
|
|
|
177
|
-
//
|
|
228
|
+
// const newProductList = [];
|
|
229
|
+
//
|
|
230
|
+
// productList.forEach(item => {
|
|
231
|
+
// const product = this.hooks.getProduct(item);
|
|
232
|
+
// if (product.quantity > 1) {
|
|
233
|
+
// for (let i = 1; i < product.quantity; i++) {
|
|
234
|
+
// newProductList.push(product)
|
|
235
|
+
// }
|
|
236
|
+
// } else {
|
|
237
|
+
// newProductList.push(item)
|
|
238
|
+
// }
|
|
239
|
+
// })
|
|
240
|
+
|
|
241
|
+
// 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
|
|
178
242
|
var sortedProductList = _toConsumableArray(productList).sort(function (a, b) {
|
|
179
243
|
var aProduct = _this3.hooks.getProduct(a);
|
|
180
244
|
var bProduct = _this3.hooks.getProduct(b);
|
|
181
|
-
var priceA =
|
|
182
|
-
var priceB =
|
|
183
|
-
|
|
245
|
+
var priceA = new Decimal(aProduct.price || '0');
|
|
246
|
+
var priceB = new Decimal(bProduct.price || '0');
|
|
247
|
+
if (priceA.toNumber() === priceB.toNumber()) {
|
|
248
|
+
if (aProduct.quantity === bProduct.quantity) {
|
|
249
|
+
var _bProduct$discount_li, _aProduct$discount_li;
|
|
250
|
+
return ((_bProduct$discount_li = bProduct.discount_list) === null || _bProduct$discount_li === void 0 ? void 0 : _bProduct$discount_li.length) - ((_aProduct$discount_li = aProduct.discount_list) === null || _aProduct$discount_li === void 0 ? void 0 : _aProduct$discount_li.length);
|
|
251
|
+
}
|
|
252
|
+
return aProduct.quantity - bProduct.quantity;
|
|
253
|
+
}
|
|
254
|
+
return priceB.toNumber() - priceA.toNumber();
|
|
184
255
|
});
|
|
185
256
|
|
|
186
257
|
// 标记已使用的优惠券
|
|
@@ -208,15 +279,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
208
279
|
sortedProductList.forEach(function (originProduct) {
|
|
209
280
|
var product = _this3.hooks.getProduct(originProduct);
|
|
210
281
|
addModeDiscount.forEach(function (discount) {
|
|
211
|
-
var _product$
|
|
282
|
+
var _product$discount_lis2, _product$discount_lis3;
|
|
212
283
|
var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
|
|
213
284
|
|
|
214
285
|
// 是符合折扣的商品
|
|
215
286
|
var isLimitedProduct = limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id);
|
|
216
287
|
|
|
217
288
|
// 编辑的商品 使用了优惠券不可用
|
|
218
|
-
var isAvailableProduct = !(product !== null && product !== void 0 && product.booking_id && product !== null && product !== void 0 && (_product$
|
|
219
|
-
return discount.id && discount.
|
|
289
|
+
var isAvailableProduct = !(product !== null && product !== void 0 && product.booking_id && product !== null && product !== void 0 && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.length && product !== null && product !== void 0 && (_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.every(function (discount) {
|
|
290
|
+
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
220
291
|
}));
|
|
221
292
|
|
|
222
293
|
// 判断优惠券是否适用于该商品
|
|
@@ -229,33 +300,44 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
229
300
|
var applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
230
301
|
applicableProducts.push({
|
|
231
302
|
amount: product.price,
|
|
232
|
-
type: discount.tag,
|
|
303
|
+
type: discount.tag || discount.type,
|
|
304
|
+
tag: discount.tag || discount.type,
|
|
233
305
|
discount: {
|
|
234
306
|
resource_id: discount.id,
|
|
235
307
|
title: discount.format_title,
|
|
236
|
-
original_amount: product.origin_total
|
|
237
|
-
|
|
308
|
+
original_amount: product.origin_total,
|
|
309
|
+
pre_value: discount.par_value,
|
|
310
|
+
product_id: originProduct.id
|
|
311
|
+
},
|
|
312
|
+
num: product.num || 1
|
|
238
313
|
});
|
|
239
314
|
discountApplicableProducts.set(discount.id, applicableProducts);
|
|
240
315
|
}
|
|
241
316
|
});
|
|
242
317
|
});
|
|
318
|
+
console.log(sortedProductList, 'sortedProductListsortedProductList');
|
|
243
319
|
|
|
244
320
|
// 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
|
|
245
|
-
sortedProductList.forEach(function (originProduct) {
|
|
246
|
-
var _product$
|
|
321
|
+
sortedProductList.forEach(function (originProduct, i) {
|
|
322
|
+
var _product$discount_lis4, _product$discount_lis5, _product$discount_lis6, _product$discount_lis7, _product$discount_lis8, _product$discount_lis9;
|
|
247
323
|
var product = _this3.hooks.getProduct(originProduct);
|
|
248
|
-
if (product !== null && product !== void 0 && product.booking_id && (_product$
|
|
249
|
-
return discount.id && discount.
|
|
324
|
+
if (product !== null && product !== void 0 && product.booking_id && (_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.length && product !== null && product !== void 0 && (_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.every(function (discount) {
|
|
325
|
+
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
250
326
|
})) {
|
|
251
|
-
processedProductsMap.set(product._id, originProduct);
|
|
327
|
+
processedProductsMap.set(product._id, [originProduct]);
|
|
252
328
|
return;
|
|
253
329
|
}
|
|
254
330
|
|
|
255
331
|
// 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
|
|
256
332
|
var applicableDiscounts = sortedDiscountList.filter(function (discount) {
|
|
333
|
+
// 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
|
|
334
|
+
// 商品券时主商品价格为0不可用
|
|
335
|
+
if ((Number(product.price) === 0 || !product.price) && (discount.tag || discount.type) === 'good_pass') return false;
|
|
336
|
+
// 折扣卡时总价为0时不可用
|
|
337
|
+
if ((Number(product.total) === 0 || !product.total) && (discount.tag || discount.type) !== 'good_pass') return false;
|
|
257
338
|
// 如果优惠券已被使用,则跳过
|
|
258
|
-
|
|
339
|
+
var targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
340
|
+
if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
|
|
259
341
|
var limitedData = discount.limited_relation_product_data;
|
|
260
342
|
|
|
261
343
|
// 判断优惠券是否适用于该商品
|
|
@@ -268,22 +350,30 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
268
350
|
});
|
|
269
351
|
|
|
270
352
|
// 选择第一个适用的优惠券(已经按过期时间排序)
|
|
271
|
-
|
|
353
|
+
// 如果有 isScan 且 isSelected 的折扣卡,则优先选中,否则再选择第一个
|
|
354
|
+
// 用于处理:先手动扫描了一张折扣卡,扫描完以后带入客户信息,但是之前那张折扣卡不是最优惠的情况
|
|
355
|
+
var selectedDiscountCard = applicableDiscounts.find(function (n) {
|
|
356
|
+
return n.isScan && n.isSelected && (n.tag || n.type) !== 'good_pass';
|
|
357
|
+
});
|
|
358
|
+
var selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
|
|
272
359
|
|
|
273
360
|
// 如果是手动折扣,则不适用优惠券
|
|
274
|
-
var isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (!((_product$
|
|
361
|
+
var isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (!((_product$discount_lis6 = product.discount_list) !== null && _product$discount_lis6 !== void 0 && _product$discount_lis6.length) || (product === null || product === void 0 || (_product$discount_lis7 = product.discount_list) === null || _product$discount_lis7 === void 0 || (_product$discount_lis8 = _product$discount_lis7.every) === null || _product$discount_lis8 === void 0 ? void 0 : _product$discount_lis8.call(_product$discount_lis7, function (item) {
|
|
275
362
|
return item.type === 'product';
|
|
276
363
|
})));
|
|
277
364
|
|
|
278
365
|
// 勾选时覆盖手动折扣
|
|
279
|
-
if (options !== null && options !== void 0 && options.discountId && (
|
|
366
|
+
if (options !== null && options !== void 0 && options.discountId && (_product$discount_lis9 = product.discount_list) !== null && _product$discount_lis9 !== void 0 && _product$discount_lis9.some(function (item) {
|
|
367
|
+
var _item$discount;
|
|
368
|
+
return ((_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) === options.discountId;
|
|
369
|
+
})) {
|
|
280
370
|
isManualDiscount = false;
|
|
281
371
|
}
|
|
282
372
|
|
|
283
373
|
// 如果没有适用的优惠券,或者手动折扣,则不适用优惠券
|
|
284
374
|
if (applicableDiscounts.length === 0 || isManualDiscount) {
|
|
285
375
|
if (product.isClient) {
|
|
286
|
-
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
376
|
+
processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
287
377
|
origin_total: getProductOriginTotalPrice({
|
|
288
378
|
product: {
|
|
289
379
|
original_price: product.original_price
|
|
@@ -291,6 +381,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
291
381
|
bundle: product.bundle,
|
|
292
382
|
options: product.options
|
|
293
383
|
}),
|
|
384
|
+
variant: originProduct._productInit.variant,
|
|
385
|
+
original_price: originProduct._productInit.original_price,
|
|
294
386
|
total: getProductTotalPrice({
|
|
295
387
|
product: {
|
|
296
388
|
price: product.price
|
|
@@ -301,72 +393,111 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
301
393
|
price: product.price
|
|
302
394
|
}), {}, {
|
|
303
395
|
discount_list: []
|
|
304
|
-
})));
|
|
396
|
+
}))]);
|
|
305
397
|
} else {
|
|
306
|
-
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
398
|
+
processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
399
|
+
_id: product._id.split('___')[0] + '___' + i,
|
|
307
400
|
total: product.origin_total || product.total,
|
|
308
401
|
price: product.price
|
|
309
402
|
}), {}, {
|
|
310
403
|
discount_list: []
|
|
311
|
-
})));
|
|
404
|
+
}))]);
|
|
312
405
|
}
|
|
313
406
|
return;
|
|
314
407
|
}
|
|
315
|
-
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined' && !(options !== null && options !== void 0 && options.scan)) {
|
|
408
|
+
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined' && !(options !== null && options !== void 0 && options.scan) && !isEditModeAddNewProduct) {
|
|
316
409
|
return;
|
|
317
410
|
}
|
|
318
411
|
|
|
319
|
-
//
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
//
|
|
323
|
-
var
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
appliedProducts.push(discountDetail);
|
|
335
|
-
appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
|
|
336
|
-
|
|
337
|
-
// 记录应用了优惠券的商品
|
|
338
|
-
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
339
|
-
if (product.isClient) {
|
|
340
|
-
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
|
|
341
|
-
discount_list: [discountDetail],
|
|
342
|
-
price: 0,
|
|
343
|
-
origin_total: getProductOriginTotalPrice({
|
|
344
|
-
product: {
|
|
345
|
-
original_price: product.original_price
|
|
346
|
-
},
|
|
347
|
-
bundle: product.bundle,
|
|
348
|
-
options: product.options
|
|
349
|
-
}),
|
|
350
|
-
total: getProductTotalPrice({
|
|
351
|
-
product: {
|
|
352
|
-
price: '0'
|
|
353
|
-
},
|
|
354
|
-
bundle: product.bundle,
|
|
355
|
-
options: product.options
|
|
356
|
-
})
|
|
357
|
-
}));
|
|
358
|
-
} else {
|
|
359
|
-
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
|
|
360
|
-
discount_list: [discountDetail],
|
|
361
|
-
price: 0,
|
|
362
|
-
total: (product.origin_total || product.total) - product.price,
|
|
363
|
-
origin_total: product.origin_total || product.total
|
|
412
|
+
// 是否需要拆分
|
|
413
|
+
var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
|
|
414
|
+
|
|
415
|
+
// 需要拆分出来的数量
|
|
416
|
+
var splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, applicableDiscounts.filter(function (item) {
|
|
417
|
+
return (item.tag || item.type) === 'good_pass';
|
|
418
|
+
}).length) : 1;
|
|
419
|
+
var arr = [];
|
|
420
|
+
if (splitCount < product.quantity && isNeedSplit) {
|
|
421
|
+
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
422
|
+
discount_list: [],
|
|
423
|
+
quantity: product.quantity - splitCount,
|
|
424
|
+
_id: product._id.split('___')[0]
|
|
364
425
|
}));
|
|
365
426
|
}
|
|
427
|
+
for (var _i = 0; _i < splitCount; _i++) {
|
|
428
|
+
var _originProduct$_produ, _product$discount_lis10;
|
|
429
|
+
// 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
|
|
430
|
+
var _selectedDiscount = selectedDiscountCard || applicableDiscounts[_i];
|
|
431
|
+
// 标记优惠券为已使用
|
|
432
|
+
usedDiscounts.set(_selectedDiscount.id, true);
|
|
433
|
+
|
|
434
|
+
// 记录实际应用了优惠券的商品信息
|
|
435
|
+
var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
|
|
436
|
+
|
|
437
|
+
// 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
|
|
438
|
+
var productOriginTotal = product.origin_total || product.total || 0;
|
|
439
|
+
// 如果originProduct?._productInit?.original_price为 0,product.origin_total可能为空,此时取 product.total
|
|
440
|
+
if (Number((originProduct === null || originProduct === void 0 || (_originProduct$_produ = originProduct._productInit) === null || _originProduct$_produ === void 0 ? void 0 : _originProduct$_produ.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
|
|
441
|
+
productOriginTotal = product.total;
|
|
442
|
+
}
|
|
443
|
+
// 如果当前 product 有 discount_list,则必须从 origin_total 拿
|
|
444
|
+
if ((_product$discount_lis10 = product.discount_list) !== null && _product$discount_lis10 !== void 0 && _product$discount_lis10.length) {
|
|
445
|
+
productOriginTotal = product.origin_total;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// 计算使用折扣卡/商品券以后,单个商品的总 total
|
|
449
|
+
var targetProductTotal = _selectedDiscount.tag === 'good_pass' ? new Decimal(productOriginTotal).minus(new Decimal(product.price || 0)).toNumber() : new Decimal(100).minus(_selectedDiscount.par_value || 0).div(100).mul(new Decimal(productOriginTotal)).toNumber();
|
|
450
|
+
var discountDetail = {
|
|
451
|
+
amount: new Decimal(productOriginTotal).minus(new Decimal(targetProductTotal)).toNumber(),
|
|
452
|
+
type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount.tag,
|
|
453
|
+
discount: {
|
|
454
|
+
resource_id: _selectedDiscount.id,
|
|
455
|
+
title: _selectedDiscount.format_title,
|
|
456
|
+
original_amount: productOriginTotal,
|
|
457
|
+
product_id: originProduct.id,
|
|
458
|
+
percent: _selectedDiscount.par_value
|
|
459
|
+
},
|
|
460
|
+
num: product.num || 1
|
|
461
|
+
};
|
|
462
|
+
appliedProducts.push(discountDetail);
|
|
463
|
+
appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
|
|
464
|
+
|
|
465
|
+
// 记录应用了优惠券的商品
|
|
466
|
+
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
467
|
+
if (product.isClient) {
|
|
468
|
+
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
469
|
+
discount_list: [discountDetail],
|
|
470
|
+
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
471
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
472
|
+
origin_total: getProductOriginTotalPrice({
|
|
473
|
+
product: {
|
|
474
|
+
original_price: product.original_price
|
|
475
|
+
},
|
|
476
|
+
bundle: product.bundle,
|
|
477
|
+
options: product.options
|
|
478
|
+
}),
|
|
479
|
+
variant: originProduct._productInit.variant,
|
|
480
|
+
original_price: new Decimal(product.price || 0).toNumber(),
|
|
481
|
+
total: targetProductTotal
|
|
482
|
+
}));
|
|
483
|
+
} else {
|
|
484
|
+
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
485
|
+
discount_list: [discountDetail],
|
|
486
|
+
_id: product._id.split('___')[0] + "___" + _selectedDiscount.id,
|
|
487
|
+
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
488
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
489
|
+
total: targetProductTotal,
|
|
490
|
+
origin_total: productOriginTotal
|
|
491
|
+
}));
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
console.log(arr, 'arrarrarr');
|
|
495
|
+
processedProductsMap.set(product._id, arr);
|
|
366
496
|
});
|
|
367
497
|
|
|
368
498
|
// 按原始顺序构建处理后的商品列表
|
|
369
|
-
var processedProductList =
|
|
499
|
+
var processedProductList = [];
|
|
500
|
+
productList.forEach(function (originProduct) {
|
|
370
501
|
var product = _this3.hooks.getProduct(originProduct);
|
|
371
502
|
var getDefaultProduct = function getDefaultProduct() {
|
|
372
503
|
if (product.isClient) {
|
|
@@ -380,6 +511,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
380
511
|
bundle: product.bundle,
|
|
381
512
|
options: product.options
|
|
382
513
|
}),
|
|
514
|
+
variant: originProduct._productInit.variant,
|
|
515
|
+
original_price: originProduct._productInit.original_price,
|
|
383
516
|
total: getProductTotalPrice({
|
|
384
517
|
product: {
|
|
385
518
|
price: product.price
|
|
@@ -397,7 +530,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
397
530
|
});
|
|
398
531
|
}
|
|
399
532
|
};
|
|
400
|
-
|
|
533
|
+
var arr = processedProductsMap.get(product._id);
|
|
534
|
+
arr !== null && arr !== void 0 && arr.length ? processedProductList.push.apply(processedProductList, _toConsumableArray(arr)) : processedProductList.push(getDefaultProduct());
|
|
401
535
|
});
|
|
402
536
|
|
|
403
537
|
// 按原始顺序更新优惠券列表,标记已使用和可用的优惠券
|
|
@@ -430,6 +564,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
430
564
|
if (usedDiscounts.get(discount.id)) {
|
|
431
565
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
432
566
|
isSelected: true,
|
|
567
|
+
isManualSelect: options !== null && options !== void 0 && options.scan ? false : discount.isManualSelect,
|
|
433
568
|
// 标记为可用,因为它已被应用
|
|
434
569
|
isAvailable: true,
|
|
435
570
|
// 记录适用的商品IDs
|
|
@@ -452,6 +587,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
452
587
|
// 如果有适用的商品,标记为可用
|
|
453
588
|
isAvailable: isAvailable,
|
|
454
589
|
isSelected: isSelected,
|
|
590
|
+
// 如果是扫码进来的,要手动设置为手动选择:false
|
|
591
|
+
isManualSelect: options !== null && options !== void 0 && options.scan ? false : discount.isManualSelect,
|
|
455
592
|
// 记录适用的商品IDs
|
|
456
593
|
applicableProductIds: applicableProducts,
|
|
457
594
|
// 添加可抵扣的商品详情
|
|
@@ -460,6 +597,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
460
597
|
appliedProductDetails: []
|
|
461
598
|
});
|
|
462
599
|
});
|
|
600
|
+
console.log(processedProductList, 'processedProductList');
|
|
463
601
|
return {
|
|
464
602
|
productList: processedProductList,
|
|
465
603
|
discountList: [].concat(editModeDiscount, _toConsumableArray(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[];
|