@pisell/pisellos 0.0.149 → 0.0.151
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/Discount/types.d.ts +7 -0
- package/dist/modules/Rules/index.js +117 -64
- package/dist/modules/Rules/types.d.ts +3 -0
- package/dist/solution/BookingByStep/index.js +2 -1
- package/dist/solution/ShopDiscount/index.js +9 -2
- package/lib/modules/Discount/types.d.ts +7 -0
- package/lib/modules/Rules/index.js +73 -44
- package/lib/modules/Rules/types.d.ts +3 -0
- package/lib/solution/BookingByStep/index.js +3 -1
- package/lib/solution/ShopDiscount/index.js +11 -2
- package/package.json +1 -1
|
@@ -28,6 +28,13 @@ interface ApplicableProductDetails {
|
|
|
28
28
|
title: string;
|
|
29
29
|
original_amount: string;
|
|
30
30
|
num: number;
|
|
31
|
+
discount?: {
|
|
32
|
+
product_id?: number;
|
|
33
|
+
original_amount?: string;
|
|
34
|
+
percent?: string;
|
|
35
|
+
resource_id?: number;
|
|
36
|
+
title?: string;
|
|
37
|
+
};
|
|
31
38
|
}
|
|
32
39
|
export interface Discount {
|
|
33
40
|
id: number;
|
|
@@ -200,13 +200,33 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
200
200
|
}
|
|
201
201
|
});
|
|
202
202
|
|
|
203
|
-
//
|
|
203
|
+
// const newProductList = [];
|
|
204
|
+
//
|
|
205
|
+
// productList.forEach(item => {
|
|
206
|
+
// const product = this.hooks.getProduct(item);
|
|
207
|
+
// if (product.quantity > 1) {
|
|
208
|
+
// for (let i = 1; i < product.quantity; i++) {
|
|
209
|
+
// newProductList.push(product)
|
|
210
|
+
// }
|
|
211
|
+
// } else {
|
|
212
|
+
// newProductList.push(item)
|
|
213
|
+
// }
|
|
214
|
+
// })
|
|
215
|
+
|
|
216
|
+
// 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
|
|
204
217
|
var sortedProductList = _toConsumableArray(productList).sort(function (a, b) {
|
|
205
218
|
var aProduct = _this3.hooks.getProduct(a);
|
|
206
219
|
var bProduct = _this3.hooks.getProduct(b);
|
|
207
220
|
var priceA = new Decimal(aProduct.price || '0');
|
|
208
221
|
var priceB = new Decimal(bProduct.price || '0');
|
|
209
|
-
|
|
222
|
+
if (priceA.toNumber() === priceB.toNumber()) {
|
|
223
|
+
if (aProduct.quantity === bProduct.quantity) {
|
|
224
|
+
var _bProduct$discount_li, _aProduct$discount_li;
|
|
225
|
+
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);
|
|
226
|
+
}
|
|
227
|
+
return aProduct.quantity - bProduct.quantity;
|
|
228
|
+
}
|
|
229
|
+
return priceB.toNumber() - priceA.toNumber();
|
|
210
230
|
});
|
|
211
231
|
|
|
212
232
|
// 标记已使用的优惠券
|
|
@@ -242,7 +262,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
242
262
|
|
|
243
263
|
// 编辑的商品 使用了优惠券不可用
|
|
244
264
|
var isAvailableProduct = !(product !== null && product !== void 0 && product.booking_id && product !== null && product !== void 0 && (_product$discount_lis = product.discount_list) !== null && _product$discount_lis !== void 0 && _product$discount_lis.length && product !== null && product !== void 0 && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.every(function (discount) {
|
|
245
|
-
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.type);
|
|
265
|
+
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
246
266
|
}));
|
|
247
267
|
|
|
248
268
|
// 判断优惠券是否适用于该商品
|
|
@@ -255,12 +275,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
255
275
|
var applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
256
276
|
applicableProducts.push({
|
|
257
277
|
amount: product.price,
|
|
258
|
-
type: discount.tag,
|
|
278
|
+
type: discount.tag || discount.type,
|
|
279
|
+
tag: discount.tag || discount.type,
|
|
259
280
|
discount: {
|
|
260
281
|
resource_id: discount.id,
|
|
261
282
|
title: discount.format_title,
|
|
262
283
|
original_amount: product.origin_total,
|
|
263
|
-
pre_value: discount.par_value
|
|
284
|
+
pre_value: discount.par_value,
|
|
285
|
+
product_id: originProduct.id
|
|
264
286
|
},
|
|
265
287
|
num: product.num || 1
|
|
266
288
|
});
|
|
@@ -268,15 +290,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
268
290
|
}
|
|
269
291
|
});
|
|
270
292
|
});
|
|
293
|
+
console.log(sortedProductList, 'sortedProductListsortedProductList');
|
|
271
294
|
|
|
272
295
|
// 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
|
|
273
|
-
sortedProductList.forEach(function (originProduct) {
|
|
296
|
+
sortedProductList.forEach(function (originProduct, i) {
|
|
274
297
|
var _product$discount_lis3, _product$discount_lis4, _product$discount_lis5, _product$discount_lis6, _product$discount_lis7;
|
|
275
298
|
var product = _this3.hooks.getProduct(originProduct);
|
|
276
299
|
if (product !== null && product !== void 0 && product.booking_id && (_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.length && product !== null && product !== void 0 && (_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.every(function (discount) {
|
|
277
|
-
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.type);
|
|
300
|
+
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
278
301
|
})) {
|
|
279
|
-
processedProductsMap.set(product._id, originProduct);
|
|
302
|
+
processedProductsMap.set(product._id, [originProduct]);
|
|
280
303
|
return;
|
|
281
304
|
}
|
|
282
305
|
|
|
@@ -286,7 +309,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
286
309
|
if (Number(product.price) === 0 || !product.price) return false;
|
|
287
310
|
// 如果优惠券已被使用,则跳过
|
|
288
311
|
var targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
289
|
-
if (targetUsedDiscounts && discount.type === 'good_pass') return false;
|
|
312
|
+
if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
|
|
290
313
|
var limitedData = discount.limited_relation_product_data;
|
|
291
314
|
|
|
292
315
|
// 判断优惠券是否适用于该商品
|
|
@@ -307,14 +330,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
307
330
|
})));
|
|
308
331
|
|
|
309
332
|
// 勾选时覆盖手动折扣
|
|
310
|
-
if (options !== null && options !== void 0 && options.discountId && (
|
|
333
|
+
if (options !== null && options !== void 0 && options.discountId && product.discount_list.some(function (item) {
|
|
334
|
+
var _item$discount;
|
|
335
|
+
return ((_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) === options.discountId;
|
|
336
|
+
})) {
|
|
311
337
|
isManualDiscount = false;
|
|
312
338
|
}
|
|
313
339
|
|
|
314
340
|
// 如果没有适用的优惠券,或者手动折扣,则不适用优惠券
|
|
315
341
|
if (applicableDiscounts.length === 0 || isManualDiscount) {
|
|
316
342
|
if (product.isClient) {
|
|
317
|
-
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
343
|
+
processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
318
344
|
origin_total: getProductOriginTotalPrice({
|
|
319
345
|
product: {
|
|
320
346
|
original_price: product.original_price
|
|
@@ -332,14 +358,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
332
358
|
price: product.price
|
|
333
359
|
}), {}, {
|
|
334
360
|
discount_list: []
|
|
335
|
-
})));
|
|
361
|
+
}))]);
|
|
336
362
|
} else {
|
|
337
|
-
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
363
|
+
processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
364
|
+
_id: product._id.split('___')[0] + '___' + i,
|
|
338
365
|
total: product.origin_total || product.total,
|
|
339
366
|
price: product.price
|
|
340
367
|
}), {}, {
|
|
341
368
|
discount_list: []
|
|
342
|
-
})));
|
|
369
|
+
}))]);
|
|
343
370
|
}
|
|
344
371
|
return;
|
|
345
372
|
}
|
|
@@ -347,60 +374,84 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
347
374
|
return;
|
|
348
375
|
}
|
|
349
376
|
|
|
350
|
-
//
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
//
|
|
354
|
-
var
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
product_id: selectedDiscount.product_id,
|
|
364
|
-
percent: selectedDiscount.par_value
|
|
365
|
-
},
|
|
366
|
-
num: product.num || 1
|
|
367
|
-
};
|
|
368
|
-
appliedProducts.push(discountDetail);
|
|
369
|
-
appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
|
|
370
|
-
|
|
371
|
-
// 记录应用了优惠券的商品
|
|
372
|
-
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
373
|
-
if (product.isClient) {
|
|
374
|
-
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
|
|
375
|
-
discount_list: [discountDetail],
|
|
376
|
-
price: new Decimal(targetProductPrice).toNumber(),
|
|
377
|
-
origin_total: getProductOriginTotalPrice({
|
|
378
|
-
product: {
|
|
379
|
-
original_price: product.original_price
|
|
380
|
-
},
|
|
381
|
-
bundle: product.bundle,
|
|
382
|
-
options: product.options
|
|
383
|
-
}),
|
|
384
|
-
total: getProductTotalPrice({
|
|
385
|
-
product: {
|
|
386
|
-
price: targetProductPrice
|
|
387
|
-
},
|
|
388
|
-
bundle: product.bundle,
|
|
389
|
-
options: product.options
|
|
390
|
-
})
|
|
391
|
-
}));
|
|
392
|
-
} else {
|
|
393
|
-
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
|
|
394
|
-
discount_list: [discountDetail],
|
|
395
|
-
price: new Decimal(targetProductPrice).toNumber(),
|
|
396
|
-
total: new Decimal(product.origin_total || product.total || 0).minus(new Decimal(product.price || 0).minus(new Decimal(targetProductPrice))).toNumber(),
|
|
397
|
-
origin_total: product.origin_total || product.total
|
|
377
|
+
// 是否需要拆分
|
|
378
|
+
var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
|
|
379
|
+
|
|
380
|
+
// 需要拆分出来的数量
|
|
381
|
+
var splitCount = isNeedSplit ? Math.min(product.quantity, applicableDiscounts.filter(function (item) {
|
|
382
|
+
return (item.tag || item.type) === 'good_pass';
|
|
383
|
+
}).length) : 1;
|
|
384
|
+
var arr = [];
|
|
385
|
+
if (splitCount < product.quantity && isNeedSplit) {
|
|
386
|
+
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
387
|
+
discount_list: [],
|
|
388
|
+
quantity: product.quantity - splitCount,
|
|
389
|
+
_id: product._id.split('___')[0]
|
|
398
390
|
}));
|
|
399
391
|
}
|
|
392
|
+
for (var _i = 0; _i < splitCount; _i++) {
|
|
393
|
+
var _selectedDiscount = applicableDiscounts[_i];
|
|
394
|
+
// 标记优惠券为已使用
|
|
395
|
+
usedDiscounts.set(_selectedDiscount.id, true);
|
|
396
|
+
|
|
397
|
+
// 记录实际应用了优惠券的商品信息
|
|
398
|
+
var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
|
|
399
|
+
var targetProductPrice = _selectedDiscount.tag === 'good_pass' ? '0' : new Decimal(100).minus(_selectedDiscount.par_value || 0).div(100).mul(new Decimal(product.price || 0)).toFixed(2);
|
|
400
|
+
var discountDetail = {
|
|
401
|
+
amount: _selectedDiscount.tag === 'product_discount_card' ? new Decimal(product.price || 0).minus(new Decimal(targetProductPrice)).toNumber() : product.price,
|
|
402
|
+
type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount.tag,
|
|
403
|
+
discount: {
|
|
404
|
+
resource_id: _selectedDiscount.id,
|
|
405
|
+
title: _selectedDiscount.format_title,
|
|
406
|
+
original_amount: product.origin_total,
|
|
407
|
+
product_id: originProduct.id,
|
|
408
|
+
percent: _selectedDiscount.par_value
|
|
409
|
+
},
|
|
410
|
+
num: product.num || 1
|
|
411
|
+
};
|
|
412
|
+
appliedProducts.push(discountDetail);
|
|
413
|
+
appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
|
|
414
|
+
|
|
415
|
+
// 记录应用了优惠券的商品
|
|
416
|
+
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
417
|
+
if (product.isClient) {
|
|
418
|
+
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
419
|
+
discount_list: [discountDetail],
|
|
420
|
+
price: new Decimal(targetProductPrice).toNumber(),
|
|
421
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
422
|
+
origin_total: getProductOriginTotalPrice({
|
|
423
|
+
product: {
|
|
424
|
+
original_price: product.original_price
|
|
425
|
+
},
|
|
426
|
+
bundle: product.bundle,
|
|
427
|
+
options: product.options
|
|
428
|
+
}),
|
|
429
|
+
total: getProductTotalPrice({
|
|
430
|
+
product: {
|
|
431
|
+
price: targetProductPrice
|
|
432
|
+
},
|
|
433
|
+
bundle: product.bundle,
|
|
434
|
+
options: product.options
|
|
435
|
+
})
|
|
436
|
+
}));
|
|
437
|
+
} else {
|
|
438
|
+
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
439
|
+
discount_list: [discountDetail],
|
|
440
|
+
_id: product._id.split('___')[0] + "___" + _selectedDiscount.id,
|
|
441
|
+
price: new Decimal(targetProductPrice).toNumber(),
|
|
442
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
443
|
+
total: new Decimal(product.origin_total || product.total || 0).minus(new Decimal(product.price || 0).minus(new Decimal(targetProductPrice))).toNumber(),
|
|
444
|
+
origin_total: product.origin_total || product.total
|
|
445
|
+
}));
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
console.log(arr, 'arrarrarr');
|
|
449
|
+
processedProductsMap.set(product._id, arr);
|
|
400
450
|
});
|
|
401
451
|
|
|
402
452
|
// 按原始顺序构建处理后的商品列表
|
|
403
|
-
var processedProductList =
|
|
453
|
+
var processedProductList = [];
|
|
454
|
+
productList.forEach(function (originProduct) {
|
|
404
455
|
var product = _this3.hooks.getProduct(originProduct);
|
|
405
456
|
var getDefaultProduct = function getDefaultProduct() {
|
|
406
457
|
if (product.isClient) {
|
|
@@ -431,7 +482,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
431
482
|
});
|
|
432
483
|
}
|
|
433
484
|
};
|
|
434
|
-
|
|
485
|
+
var arr = processedProductsMap.get(product._id);
|
|
486
|
+
arr !== null && arr !== void 0 && arr.length ? processedProductList.push.apply(processedProductList, _toConsumableArray(arr)) : processedProductList.push(getDefaultProduct());
|
|
435
487
|
});
|
|
436
488
|
|
|
437
489
|
// 按原始顺序更新优惠券列表,标记已使用和可用的优惠券
|
|
@@ -494,6 +546,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
494
546
|
appliedProductDetails: []
|
|
495
547
|
});
|
|
496
548
|
});
|
|
549
|
+
console.log(processedProductList, 'processedProductList');
|
|
497
550
|
return {
|
|
498
551
|
productList: processedProductList,
|
|
499
552
|
discountList: [].concat(editModeDiscount, _toConsumableArray(updatedDiscountList))
|
|
@@ -38,14 +38,17 @@ type ProductDetail = {
|
|
|
38
38
|
bundle?: any[];
|
|
39
39
|
original_price?: number | string;
|
|
40
40
|
num?: number;
|
|
41
|
+
quantity: number;
|
|
41
42
|
};
|
|
42
43
|
export interface RulesParamsHooks {
|
|
43
44
|
getProduct: (product: Record<string, any>) => ProductDetail;
|
|
44
45
|
setProduct: (product: Record<string, any>, values: {
|
|
46
|
+
_id?: string;
|
|
45
47
|
total?: number;
|
|
46
48
|
discount_list: any[];
|
|
47
49
|
origin_total?: number;
|
|
48
50
|
price?: number;
|
|
51
|
+
quantity?: number;
|
|
49
52
|
}) => Record<string, any>;
|
|
50
53
|
}
|
|
51
54
|
export {};
|
|
@@ -2242,7 +2242,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2242
2242
|
break;
|
|
2243
2243
|
}
|
|
2244
2244
|
dateRange = this.store.date.getDateRange(); // 如果不是先选日期的流程 duration 商品就啥也不做
|
|
2245
|
-
if (dateRange.length) {
|
|
2245
|
+
if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
|
|
2246
2246
|
_context25.next = 15;
|
|
2247
2247
|
break;
|
|
2248
2248
|
}
|
|
@@ -2876,6 +2876,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2876
2876
|
}, {
|
|
2877
2877
|
key: "isTargetNormalProduct",
|
|
2878
2878
|
value: function isTargetNormalProduct(product) {
|
|
2879
|
+
if (!product) return false;
|
|
2879
2880
|
return isNormalProduct(product);
|
|
2880
2881
|
}
|
|
2881
2882
|
}, {
|
|
@@ -444,7 +444,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
444
444
|
if (discount.id && ['good_pass', 'discount_card'].includes(discount.type)) {
|
|
445
445
|
var index = editModeDiscountList.findIndex(function (n) {
|
|
446
446
|
var _discount$discount;
|
|
447
|
-
return n.id === ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id;
|
|
447
|
+
return n.id === (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id);
|
|
448
448
|
});
|
|
449
449
|
if (index !== -1) {
|
|
450
450
|
editModeDiscountList[index] = _objectSpread(_objectSpread({}, editModeDiscountList[index]), {}, {
|
|
@@ -453,6 +453,9 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
453
453
|
});
|
|
454
454
|
} else {
|
|
455
455
|
var _discount$discount2, _discount$discount3, _discount$discount4;
|
|
456
|
+
if (discount.type && !discount.tag) {
|
|
457
|
+
discount.tag = discount.type;
|
|
458
|
+
}
|
|
456
459
|
editModeDiscountList.push(_objectSpread(_objectSpread({}, discount), {}, {
|
|
457
460
|
isEditMode: true,
|
|
458
461
|
limited_relation_product_data: {},
|
|
@@ -473,7 +476,11 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
473
476
|
return !item.isDisabled;
|
|
474
477
|
})));
|
|
475
478
|
var allUsedProductIds = newDiscountList.map(function (n) {
|
|
476
|
-
|
|
479
|
+
var _n$appliedProductDeta;
|
|
480
|
+
return n.isSelected ? (_n$appliedProductDeta = n.appliedProductDetails) === null || _n$appliedProductDeta === void 0 ? void 0 : _n$appliedProductDeta.map(function (n) {
|
|
481
|
+
var _n$discount;
|
|
482
|
+
return (_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.product_id;
|
|
483
|
+
}) : [];
|
|
477
484
|
}).flat();
|
|
478
485
|
newDiscountList.forEach(function (item) {
|
|
479
486
|
var _item$applicableProdu;
|
|
@@ -28,6 +28,13 @@ interface ApplicableProductDetails {
|
|
|
28
28
|
title: string;
|
|
29
29
|
original_amount: string;
|
|
30
30
|
num: number;
|
|
31
|
+
discount?: {
|
|
32
|
+
product_id?: number;
|
|
33
|
+
original_amount?: string;
|
|
34
|
+
percent?: string;
|
|
35
|
+
resource_id?: number;
|
|
36
|
+
title?: string;
|
|
37
|
+
};
|
|
31
38
|
}
|
|
32
39
|
export interface Discount {
|
|
33
40
|
id: number;
|
|
@@ -143,11 +143,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
143
143
|
}
|
|
144
144
|
});
|
|
145
145
|
const sortedProductList = [...productList].sort((a, b) => {
|
|
146
|
+
var _a, _b;
|
|
146
147
|
const aProduct = this.hooks.getProduct(a);
|
|
147
148
|
const bProduct = this.hooks.getProduct(b);
|
|
148
149
|
const priceA = new import_decimal.default(aProduct.price || "0");
|
|
149
150
|
const priceB = new import_decimal.default(bProduct.price || "0");
|
|
150
|
-
|
|
151
|
+
if (priceA.toNumber() === priceB.toNumber()) {
|
|
152
|
+
if (aProduct.quantity === bProduct.quantity) {
|
|
153
|
+
return ((_a = bProduct.discount_list) == null ? void 0 : _a.length) - ((_b = aProduct.discount_list) == null ? void 0 : _b.length);
|
|
154
|
+
}
|
|
155
|
+
return aProduct.quantity - bProduct.quantity;
|
|
156
|
+
}
|
|
157
|
+
return priceB.toNumber() - priceA.toNumber();
|
|
151
158
|
});
|
|
152
159
|
const usedDiscounts = /* @__PURE__ */ new Map();
|
|
153
160
|
const discountApplicability = /* @__PURE__ */ new Map();
|
|
@@ -164,18 +171,20 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
164
171
|
var _a, _b, _c;
|
|
165
172
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
166
173
|
const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
|
|
167
|
-
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.type))));
|
|
174
|
+
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))));
|
|
168
175
|
if (isAvailableProduct && isLimitedProduct) {
|
|
169
176
|
(_c = discountApplicability.get(discount.id)) == null ? void 0 : _c.push(product.id);
|
|
170
177
|
const applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
171
178
|
applicableProducts.push({
|
|
172
179
|
amount: product.price,
|
|
173
|
-
type: discount.tag,
|
|
180
|
+
type: discount.tag || discount.type,
|
|
181
|
+
tag: discount.tag || discount.type,
|
|
174
182
|
discount: {
|
|
175
183
|
resource_id: discount.id,
|
|
176
184
|
title: discount.format_title,
|
|
177
185
|
original_amount: product.origin_total,
|
|
178
|
-
pre_value: discount.par_value
|
|
186
|
+
pre_value: discount.par_value,
|
|
187
|
+
product_id: originProduct.id
|
|
179
188
|
},
|
|
180
189
|
num: product.num || 1
|
|
181
190
|
});
|
|
@@ -183,18 +192,19 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
183
192
|
}
|
|
184
193
|
});
|
|
185
194
|
});
|
|
186
|
-
|
|
195
|
+
console.log(sortedProductList, "sortedProductListsortedProductList");
|
|
196
|
+
sortedProductList.forEach((originProduct, i) => {
|
|
187
197
|
var _a, _b, _c, _d, _e;
|
|
188
198
|
const product = this.hooks.getProduct(originProduct);
|
|
189
|
-
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.type)))) {
|
|
190
|
-
processedProductsMap.set(product._id, originProduct);
|
|
199
|
+
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)))) {
|
|
200
|
+
processedProductsMap.set(product._id, [originProduct]);
|
|
191
201
|
return;
|
|
192
202
|
}
|
|
193
203
|
const applicableDiscounts = sortedDiscountList.filter((discount) => {
|
|
194
204
|
if (Number(product.price) === 0 || !product.price)
|
|
195
205
|
return false;
|
|
196
206
|
const targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
197
|
-
if (targetUsedDiscounts && discount.type === "good_pass")
|
|
207
|
+
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
|
|
198
208
|
return false;
|
|
199
209
|
const limitedData = discount.limited_relation_product_data;
|
|
200
210
|
if (limitedData.type === "product_all") {
|
|
@@ -206,14 +216,17 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
206
216
|
});
|
|
207
217
|
const selectedDiscount = applicableDiscounts[0];
|
|
208
218
|
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")));
|
|
209
|
-
if ((options == null ? void 0 : options.discountId) && (
|
|
219
|
+
if ((options == null ? void 0 : options.discountId) && product.discount_list.some((item) => {
|
|
220
|
+
var _a2;
|
|
221
|
+
return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
|
|
222
|
+
})) {
|
|
210
223
|
isManualDiscount = false;
|
|
211
224
|
}
|
|
212
225
|
if (applicableDiscounts.length === 0 || isManualDiscount) {
|
|
213
226
|
if (product.isClient) {
|
|
214
227
|
processedProductsMap.set(
|
|
215
228
|
product._id,
|
|
216
|
-
this.hooks.setProduct(originProduct, {
|
|
229
|
+
[this.hooks.setProduct(originProduct, {
|
|
217
230
|
...isManualDiscount ? {} : {
|
|
218
231
|
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
219
232
|
product: {
|
|
@@ -232,18 +245,19 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
232
245
|
price: product.price
|
|
233
246
|
},
|
|
234
247
|
discount_list: []
|
|
235
|
-
})
|
|
248
|
+
})]
|
|
236
249
|
);
|
|
237
250
|
} else {
|
|
238
251
|
processedProductsMap.set(
|
|
239
252
|
product._id,
|
|
240
|
-
this.hooks.setProduct(originProduct, {
|
|
253
|
+
[this.hooks.setProduct(originProduct, {
|
|
241
254
|
...isManualDiscount ? {} : {
|
|
255
|
+
_id: product._id.split("___")[0] + "___" + i,
|
|
242
256
|
total: product.origin_total || product.total,
|
|
243
257
|
price: product.price
|
|
244
258
|
},
|
|
245
259
|
discount_list: []
|
|
246
|
-
})
|
|
260
|
+
})]
|
|
247
261
|
);
|
|
248
262
|
}
|
|
249
263
|
return;
|
|
@@ -251,29 +265,40 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
251
265
|
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan)) {
|
|
252
266
|
return;
|
|
253
267
|
}
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
268
|
+
const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
|
|
269
|
+
const splitCount = isNeedSplit ? Math.min(product.quantity, applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length) : 1;
|
|
270
|
+
const arr = [];
|
|
271
|
+
if (splitCount < product.quantity && isNeedSplit) {
|
|
272
|
+
arr.push(this.hooks.setProduct(originProduct, {
|
|
273
|
+
discount_list: [],
|
|
274
|
+
quantity: product.quantity - splitCount,
|
|
275
|
+
_id: product._id.split("___")[0]
|
|
276
|
+
}));
|
|
277
|
+
}
|
|
278
|
+
for (let i2 = 0; i2 < splitCount; i2++) {
|
|
279
|
+
const selectedDiscount2 = applicableDiscounts[i2];
|
|
280
|
+
usedDiscounts.set(selectedDiscount2.id, true);
|
|
281
|
+
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
282
|
+
const targetProductPrice = selectedDiscount2.tag === "good_pass" ? "0" : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(product.price || 0)).toFixed(2);
|
|
283
|
+
const discountDetail = {
|
|
284
|
+
amount: selectedDiscount2.tag === "product_discount_card" ? new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice)).toNumber() : product.price,
|
|
285
|
+
type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
|
|
286
|
+
discount: {
|
|
287
|
+
resource_id: selectedDiscount2.id,
|
|
288
|
+
title: selectedDiscount2.format_title,
|
|
289
|
+
original_amount: product.origin_total,
|
|
290
|
+
product_id: originProduct.id,
|
|
291
|
+
percent: selectedDiscount2.par_value
|
|
292
|
+
},
|
|
293
|
+
num: product.num || 1
|
|
294
|
+
};
|
|
295
|
+
appliedProducts.push(discountDetail);
|
|
296
|
+
appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
|
|
297
|
+
if (product.isClient) {
|
|
298
|
+
arr.push(this.hooks.setProduct(originProduct, {
|
|
275
299
|
discount_list: [discountDetail],
|
|
276
300
|
price: new import_decimal.default(targetProductPrice).toNumber(),
|
|
301
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
277
302
|
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
278
303
|
product: {
|
|
279
304
|
original_price: product.original_price
|
|
@@ -288,21 +313,23 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
288
313
|
bundle: product.bundle,
|
|
289
314
|
options: product.options
|
|
290
315
|
})
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
processedProductsMap.set(
|
|
295
|
-
product._id,
|
|
296
|
-
this.hooks.setProduct(originProduct, {
|
|
316
|
+
}));
|
|
317
|
+
} else {
|
|
318
|
+
arr.push(this.hooks.setProduct(originProduct, {
|
|
297
319
|
discount_list: [discountDetail],
|
|
320
|
+
_id: product._id.split("___")[0] + "___" + selectedDiscount2.id,
|
|
298
321
|
price: new import_decimal.default(targetProductPrice).toNumber(),
|
|
322
|
+
quantity: isNeedSplit ? 1 : product.quantity,
|
|
299
323
|
total: new import_decimal.default(product.origin_total || product.total || 0).minus(new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice))).toNumber(),
|
|
300
324
|
origin_total: product.origin_total || product.total
|
|
301
|
-
})
|
|
302
|
-
|
|
325
|
+
}));
|
|
326
|
+
}
|
|
303
327
|
}
|
|
328
|
+
console.log(arr, "arrarrarr");
|
|
329
|
+
processedProductsMap.set(product._id, arr);
|
|
304
330
|
});
|
|
305
|
-
const processedProductList =
|
|
331
|
+
const processedProductList = [];
|
|
332
|
+
productList.forEach((originProduct) => {
|
|
306
333
|
const product = this.hooks.getProduct(originProduct);
|
|
307
334
|
const getDefaultProduct = () => {
|
|
308
335
|
if (product.isClient) {
|
|
@@ -333,7 +360,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
333
360
|
});
|
|
334
361
|
}
|
|
335
362
|
};
|
|
336
|
-
|
|
363
|
+
const arr = processedProductsMap.get(product._id);
|
|
364
|
+
(arr == null ? void 0 : arr.length) ? processedProductList.push(...arr) : processedProductList.push(getDefaultProduct());
|
|
337
365
|
});
|
|
338
366
|
const updatedDiscountList = addModeDiscount.map((discount) => {
|
|
339
367
|
const applicableProducts = discountApplicability.get(discount.id) || [];
|
|
@@ -386,6 +414,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
386
414
|
appliedProductDetails: []
|
|
387
415
|
};
|
|
388
416
|
});
|
|
417
|
+
console.log(processedProductList, "processedProductList");
|
|
389
418
|
return {
|
|
390
419
|
productList: processedProductList,
|
|
391
420
|
discountList: [...editModeDiscount, ...updatedDiscountList]
|
|
@@ -38,14 +38,17 @@ type ProductDetail = {
|
|
|
38
38
|
bundle?: any[];
|
|
39
39
|
original_price?: number | string;
|
|
40
40
|
num?: number;
|
|
41
|
+
quantity: number;
|
|
41
42
|
};
|
|
42
43
|
export interface RulesParamsHooks {
|
|
43
44
|
getProduct: (product: Record<string, any>) => ProductDetail;
|
|
44
45
|
setProduct: (product: Record<string, any>, values: {
|
|
46
|
+
_id?: string;
|
|
45
47
|
total?: number;
|
|
46
48
|
discount_list: any[];
|
|
47
49
|
origin_total?: number;
|
|
48
50
|
price?: number;
|
|
51
|
+
quantity?: number;
|
|
49
52
|
}) => Record<string, any>;
|
|
50
53
|
}
|
|
51
54
|
export {};
|
|
@@ -1562,7 +1562,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1562
1562
|
targetProduct.setOtherParams("schedule", newScheduleArr);
|
|
1563
1563
|
} else if (targetProductData.duration) {
|
|
1564
1564
|
const dateRange = this.store.date.getDateRange();
|
|
1565
|
-
if (!dateRange.length)
|
|
1565
|
+
if (!(dateRange == null ? void 0 : dateRange.length))
|
|
1566
1566
|
return;
|
|
1567
1567
|
this.getAvailableDate({
|
|
1568
1568
|
startDate: dateRange[0].date,
|
|
@@ -2034,6 +2034,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2034
2034
|
});
|
|
2035
2035
|
}
|
|
2036
2036
|
isTargetNormalProduct(product) {
|
|
2037
|
+
if (!product)
|
|
2038
|
+
return false;
|
|
2037
2039
|
return (0, import_utils4.isNormalProduct)(product);
|
|
2038
2040
|
}
|
|
2039
2041
|
isTargetCartIdNormalProduct(id) {
|
|
@@ -289,7 +289,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
289
289
|
if (discount.id && ["good_pass", "discount_card"].includes(discount.type)) {
|
|
290
290
|
const index = editModeDiscountList.findIndex((n) => {
|
|
291
291
|
var _a4;
|
|
292
|
-
return n.id === ((_a4 = discount.discount) == null ? void 0 : _a4.resource_id) || discount.id;
|
|
292
|
+
return n.id === (((_a4 = discount.discount) == null ? void 0 : _a4.resource_id) || discount.id);
|
|
293
293
|
});
|
|
294
294
|
if (index !== -1) {
|
|
295
295
|
editModeDiscountList[index] = {
|
|
@@ -298,6 +298,9 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
298
298
|
savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.num) || 1).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
|
|
299
299
|
};
|
|
300
300
|
} else {
|
|
301
|
+
if (discount.type && !discount.tag) {
|
|
302
|
+
discount.tag = discount.type;
|
|
303
|
+
}
|
|
301
304
|
editModeDiscountList.push({
|
|
302
305
|
...discount,
|
|
303
306
|
isEditMode: true,
|
|
@@ -319,7 +322,13 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
319
322
|
...editModeDiscountList,
|
|
320
323
|
...discountList.filter((item) => !item.isDisabled)
|
|
321
324
|
];
|
|
322
|
-
const allUsedProductIds = newDiscountList.map((n) =>
|
|
325
|
+
const allUsedProductIds = newDiscountList.map((n) => {
|
|
326
|
+
var _a2;
|
|
327
|
+
return n.isSelected ? (_a2 = n.appliedProductDetails) == null ? void 0 : _a2.map((n2) => {
|
|
328
|
+
var _a3;
|
|
329
|
+
return (_a3 = n2.discount) == null ? void 0 : _a3.product_id;
|
|
330
|
+
}) : [];
|
|
331
|
+
}).flat();
|
|
323
332
|
newDiscountList.forEach((item) => {
|
|
324
333
|
var _a2;
|
|
325
334
|
const isAllProductUsed = (_a2 = item.applicableProductIds) == null ? void 0 : _a2.every((id) => {
|