@pisell/pisellos 0.0.393 → 0.0.395
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/Product/index.d.ts +1 -1
- package/dist/modules/Rules/index.js +29 -18
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/ShopDiscount/utils.d.ts +3 -2
- package/dist/solution/ShopDiscount/utils.js +64 -9
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Rules/index.js +13 -5
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/ShopDiscount/utils.d.ts +3 -2
- package/lib/solution/ShopDiscount/utils.js +45 -6
- package/package.json +1 -1
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "duration" | "session" | "normal";
|
|
53
53
|
}
|
|
@@ -412,8 +412,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
412
412
|
|
|
413
413
|
// 对扁平化后的列表按价格降序排序(用于应用优惠券时优先选择高价商品)
|
|
414
414
|
var sortedFlattenedList = flattenedList.sort(function (a, b) {
|
|
415
|
-
var
|
|
416
|
-
|
|
415
|
+
var _ref3, _a$original_price, _ref4, _b$original_price;
|
|
416
|
+
// 子商品优先使用 original_price,主商品使用 price
|
|
417
|
+
var priceA = new Decimal(a.type === 'bundle' ? (_ref3 = (_a$original_price = a.original_price) !== null && _a$original_price !== void 0 ? _a$original_price : a.price) !== null && _ref3 !== void 0 ? _ref3 : '0' : a.price || '0');
|
|
418
|
+
var priceB = new Decimal(b.type === 'bundle' ? (_ref4 = (_b$original_price = b.original_price) !== null && _b$original_price !== void 0 ? _b$original_price : b.price) !== null && _ref4 !== void 0 ? _ref4 : '0' : b.price || '0');
|
|
417
419
|
if (priceA.equals(priceB)) {
|
|
418
420
|
// 价格相同时,主商品优先
|
|
419
421
|
if (a.type !== b.type) {
|
|
@@ -581,11 +583,20 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
581
583
|
var _flatItem$parentProdu2;
|
|
582
584
|
// 🔥 对于 bundle 子商品,quantity 需要乘以主商品的购买数量
|
|
583
585
|
var quantity = flatItem.type === 'main' ? product.quantity || 1 : (product.num || 1) * (((_flatItem$parentProdu2 = flatItem.parentProduct) === null || _flatItem$parentProdu2 === void 0 ? void 0 : _flatItem$parentProdu2.quantity) || 1);
|
|
584
|
-
|
|
586
|
+
|
|
587
|
+
// 🔥 传递 parentQuantity 用于差值处理时判断是否是真正的"数量为1"
|
|
588
|
+
var productData = {
|
|
585
589
|
productId: flatItem._id,
|
|
586
590
|
amount: Number(product.price || 0),
|
|
587
591
|
quantity: quantity
|
|
588
|
-
}
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
// 子商品需要传递主商品数量
|
|
595
|
+
if (flatItem.type === 'bundle') {
|
|
596
|
+
var _flatItem$parentProdu3;
|
|
597
|
+
productData.parentQuantity = ((_flatItem$parentProdu3 = flatItem.parentProduct) === null || _flatItem$parentProdu3 === void 0 ? void 0 : _flatItem$parentProdu3.quantity) || 1;
|
|
598
|
+
}
|
|
599
|
+
applicableProducts.push(productData);
|
|
589
600
|
}
|
|
590
601
|
});
|
|
591
602
|
|
|
@@ -611,10 +622,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
611
622
|
product = flatItem.product;
|
|
612
623
|
originProduct = flatItem.originProduct;
|
|
613
624
|
} else {
|
|
614
|
-
var _flatItem$
|
|
625
|
+
var _flatItem$parentProdu4;
|
|
615
626
|
// bundle子商品:构造虚拟商品对象
|
|
616
627
|
product = {
|
|
617
|
-
startDate: flatItem === null || flatItem === void 0 || (_flatItem$
|
|
628
|
+
startDate: flatItem === null || flatItem === void 0 || (_flatItem$parentProdu4 = flatItem.parentProduct) === null || _flatItem$parentProdu4 === void 0 ? void 0 : _flatItem$parentProdu4.startDate,
|
|
618
629
|
_id: flatItem._id,
|
|
619
630
|
id: flatItem.id,
|
|
620
631
|
price: flatItem.price,
|
|
@@ -699,10 +710,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
699
710
|
product = flatItem.product;
|
|
700
711
|
originProduct = flatItem.originProduct;
|
|
701
712
|
} else {
|
|
702
|
-
var _flatItem$
|
|
713
|
+
var _flatItem$parentProdu5, _flatItem$bundleItem3, _flatItem$bundleItem4, _flatItem$bundleItem5;
|
|
703
714
|
// bundle子商品
|
|
704
715
|
product = {
|
|
705
|
-
startDate: flatItem === null || flatItem === void 0 || (_flatItem$
|
|
716
|
+
startDate: flatItem === null || flatItem === void 0 || (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate,
|
|
706
717
|
_id: flatItem._id,
|
|
707
718
|
id: flatItem.id,
|
|
708
719
|
price: flatItem.price,
|
|
@@ -817,8 +828,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
817
828
|
var _product$discount_lis5, _product11, _product11$every;
|
|
818
829
|
// 主商品:判断自身是否手动折扣
|
|
819
830
|
isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
|
|
820
|
-
var
|
|
821
|
-
return !((
|
|
831
|
+
var _ref5;
|
|
832
|
+
return !((_ref5 = item.discount_list || []) !== null && _ref5 !== void 0 && _ref5.length);
|
|
822
833
|
}) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product11 = product) === null || _product11 === void 0 || (_product11 = _product11.discount_list) === null || _product11 === void 0 || (_product11$every = _product11.every) === null || _product11$every === void 0 ? void 0 : _product11$every.call(_product11, function (item) {
|
|
823
834
|
return item.type === 'product';
|
|
824
835
|
})));
|
|
@@ -828,8 +839,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
828
839
|
if (parentProduct) {
|
|
829
840
|
var _parentProduct$discou, _parentProduct$discou2, _parentProduct$discou3;
|
|
830
841
|
isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
|
|
831
|
-
var
|
|
832
|
-
return !((
|
|
842
|
+
var _ref6;
|
|
843
|
+
return !((_ref6 = item.discount_list || []) !== null && _ref6 !== void 0 && _ref6.length);
|
|
833
844
|
}) && (!((_parentProduct$discou = parentProduct.discount_list) !== null && _parentProduct$discou !== void 0 && _parentProduct$discou.length) || (parentProduct === null || parentProduct === void 0 || (_parentProduct$discou2 = parentProduct.discount_list) === null || _parentProduct$discou2 === void 0 || (_parentProduct$discou3 = _parentProduct$discou2.every) === null || _parentProduct$discou3 === void 0 ? void 0 : _parentProduct$discou3.call(_parentProduct$discou2, function (item) {
|
|
834
845
|
return item.type === 'product';
|
|
835
846
|
})));
|
|
@@ -848,11 +859,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
848
859
|
}
|
|
849
860
|
// bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
|
|
850
861
|
if (flatItem.type === 'bundle') {
|
|
851
|
-
var _product$discount_lis7, _flatItem$
|
|
862
|
+
var _product$discount_lis7, _flatItem$parentProdu6;
|
|
852
863
|
if ((_product$discount_lis7 = product.discount_list) !== null && _product$discount_lis7 !== void 0 && _product$discount_lis7.some(function (item) {
|
|
853
864
|
var _item$discount2;
|
|
854
865
|
return ((_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.resource_id) === options.discountId;
|
|
855
|
-
}) || (_flatItem$
|
|
866
|
+
}) || (_flatItem$parentProdu6 = flatItem.parentProduct) !== null && _flatItem$parentProdu6 !== void 0 && (_flatItem$parentProdu6 = _flatItem$parentProdu6.discount_list) !== null && _flatItem$parentProdu6 !== void 0 && _flatItem$parentProdu6.some(function (item) {
|
|
856
867
|
var _item$discount3;
|
|
857
868
|
return ((_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.resource_id) === options.discountId;
|
|
858
869
|
})) {
|
|
@@ -874,14 +885,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
874
885
|
}
|
|
875
886
|
// bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
|
|
876
887
|
if (flatItem.type === 'bundle') {
|
|
877
|
-
var _product$discount_lis9, _flatItem$
|
|
888
|
+
var _product$discount_lis9, _flatItem$parentProdu7;
|
|
878
889
|
if ((_product$discount_lis9 = product.discount_list) !== null && _product$discount_lis9 !== void 0 && _product$discount_lis9.some(function (item) {
|
|
879
890
|
var _options$selectedList2;
|
|
880
891
|
return options === null || options === void 0 || (_options$selectedList2 = options.selectedList) === null || _options$selectedList2 === void 0 ? void 0 : _options$selectedList2.some(function (n) {
|
|
881
892
|
var _item$discount5;
|
|
882
893
|
return n.discountId === ((_item$discount5 = item.discount) === null || _item$discount5 === void 0 ? void 0 : _item$discount5.resource_id);
|
|
883
894
|
});
|
|
884
|
-
}) || (_flatItem$
|
|
895
|
+
}) || (_flatItem$parentProdu7 = flatItem.parentProduct) !== null && _flatItem$parentProdu7 !== void 0 && (_flatItem$parentProdu7 = _flatItem$parentProdu7.discount_list) !== null && _flatItem$parentProdu7 !== void 0 && _flatItem$parentProdu7.some(function (item) {
|
|
885
896
|
var _options$selectedList3;
|
|
886
897
|
return options === null || options === void 0 || (_options$selectedList3 = options.selectedList) === null || _options$selectedList3 === void 0 ? void 0 : _options$selectedList3.some(function (n) {
|
|
887
898
|
var _item$discount6;
|
|
@@ -1162,7 +1173,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1162
1173
|
}));
|
|
1163
1174
|
}
|
|
1164
1175
|
} else {
|
|
1165
|
-
var _selectedDiscount3$me, _flatItem$
|
|
1176
|
+
var _selectedDiscount3$me, _flatItem$parentProdu8;
|
|
1166
1177
|
// 折扣卡:不拆分数量,直接应用
|
|
1167
1178
|
var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
|
|
1168
1179
|
usedDiscounts.set(_selectedDiscount3.id, true);
|
|
@@ -1214,7 +1225,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1214
1225
|
product_discount_difference: _productDiscountDifference
|
|
1215
1226
|
}),
|
|
1216
1227
|
config: _selectedDiscount3 === null || _selectedDiscount3 === void 0 ? void 0 : _selectedDiscount3.config,
|
|
1217
|
-
_num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$
|
|
1228
|
+
_num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu8 = flatItem.parentProduct) === null || _flatItem$parentProdu8 === void 0 ? void 0 : _flatItem$parentProdu8.num) || 1)
|
|
1218
1229
|
};
|
|
1219
1230
|
|
|
1220
1231
|
// 记录实际应用的折扣
|
|
@@ -308,7 +308,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
308
308
|
date: string;
|
|
309
309
|
status: string;
|
|
310
310
|
week: string;
|
|
311
|
-
weekNum: 0 | 2 | 1 | 3 |
|
|
311
|
+
weekNum: 0 | 2 | 1 | 3 | 5 | 4 | 6;
|
|
312
312
|
}[]>;
|
|
313
313
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
314
314
|
private getScheduleDataByIds;
|
|
@@ -123,7 +123,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
123
123
|
* 获取当前的客户搜索条件
|
|
124
124
|
* @returns 当前搜索条件
|
|
125
125
|
*/
|
|
126
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
126
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
|
|
127
127
|
/**
|
|
128
128
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
129
129
|
* @returns 客户状态
|
|
@@ -74,16 +74,17 @@ export declare const isOrderLevelFixedAmountDiscount: (discount: Discount) => bo
|
|
|
74
74
|
/**
|
|
75
75
|
* 计算订单级别固定金额折扣卡的分摊结果
|
|
76
76
|
* @param discount 折扣卡
|
|
77
|
-
* @param applicableProducts 适用商品列表 { productId, amount, quantity }
|
|
77
|
+
* @param applicableProducts 适用商品列表 { productId, amount, quantity, parentQuantity }
|
|
78
78
|
* @returns 分摊结果 Map<productId, { discountAmount, difference }>
|
|
79
79
|
* 注意:
|
|
80
80
|
* - discountAmount 是单价折扣金额(不是总折扣金额)
|
|
81
|
-
* - difference
|
|
81
|
+
* - difference(总差值)优先直接加到数量为1的单商品折扣上,如果没有则存储在metadata中
|
|
82
82
|
*/
|
|
83
83
|
export declare const calculateOrderLevelDiscountAllocation: (discount: Discount, applicableProducts: Array<{
|
|
84
84
|
productId: string | number;
|
|
85
85
|
amount: number;
|
|
86
86
|
quantity: number;
|
|
87
|
+
parentQuantity?: number;
|
|
87
88
|
}>) => Map<string | number, {
|
|
88
89
|
discountAmount: number;
|
|
89
90
|
difference: number;
|
|
@@ -498,11 +498,11 @@ export var isOrderLevelFixedAmountDiscount = function isOrderLevelFixedAmountDis
|
|
|
498
498
|
/**
|
|
499
499
|
* 计算订单级别固定金额折扣卡的分摊结果
|
|
500
500
|
* @param discount 折扣卡
|
|
501
|
-
* @param applicableProducts 适用商品列表 { productId, amount, quantity }
|
|
501
|
+
* @param applicableProducts 适用商品列表 { productId, amount, quantity, parentQuantity }
|
|
502
502
|
* @returns 分摊结果 Map<productId, { discountAmount, difference }>
|
|
503
503
|
* 注意:
|
|
504
504
|
* - discountAmount 是单价折扣金额(不是总折扣金额)
|
|
505
|
-
* - difference
|
|
505
|
+
* - difference(总差值)优先直接加到数量为1的单商品折扣上,如果没有则存储在metadata中
|
|
506
506
|
*/
|
|
507
507
|
export var calculateOrderLevelDiscountAllocation = function calculateOrderLevelDiscountAllocation(discount, applicableProducts) {
|
|
508
508
|
var result = new Map();
|
|
@@ -543,16 +543,71 @@ export var calculateOrderLevelDiscountAllocation = function calculateOrderLevelD
|
|
|
543
543
|
allocatedTotal = allocatedTotal.plus(new Decimal(discountAmountPerItem).mul(product.quantity));
|
|
544
544
|
});
|
|
545
545
|
|
|
546
|
-
// 🔥
|
|
546
|
+
// 🔥 计算总差值
|
|
547
547
|
// 总差值 = 固定金额 - 所有商品的 (单价折扣 × 数量) 之和
|
|
548
548
|
var totalDifference = new Decimal(actualDiscountTotal).minus(allocatedTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
549
549
|
if (totalDifference > 0) {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
550
|
+
// 🔥 判断商品是否是真正的"数量为1"
|
|
551
|
+
// 主商品:quantity === 1
|
|
552
|
+
// 子商品:quantity === 1 且 parentQuantity === 1
|
|
553
|
+
var isSingleQuantity = function isSingleQuantity(product) {
|
|
554
|
+
if (product.parentQuantity !== undefined) {
|
|
555
|
+
// 子商品:需要同时满足自身数量为1且主商品数量为1
|
|
556
|
+
return product.quantity === 1 && product.parentQuantity === 1;
|
|
557
|
+
}
|
|
558
|
+
// 主商品:只需要自身数量为1
|
|
559
|
+
return product.quantity === 1;
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
// 🔥 筛选出数量为1的商品
|
|
563
|
+
var singleQuantityProducts = applicableProducts.filter(isSingleQuantity);
|
|
564
|
+
if (singleQuantityProducts.length > 0) {
|
|
565
|
+
// 🔥 优先级1:找到有足够剩余空间且金额最大的商品
|
|
566
|
+
// 剩余空间 = 商品价格 - 当前折扣金额 >= 差值
|
|
567
|
+
var productsWithEnoughSpace = singleQuantityProducts.filter(function (product) {
|
|
568
|
+
var allocation = result.get(product.productId);
|
|
569
|
+
if (!allocation) return false;
|
|
570
|
+
var remainingSpace = new Decimal(product.amount).minus(allocation.discountAmount).toNumber();
|
|
571
|
+
return remainingSpace >= totalDifference;
|
|
572
|
+
});
|
|
573
|
+
if (productsWithEnoughSpace.length > 0) {
|
|
574
|
+
// 按金额降序排序,选择金额最大的
|
|
575
|
+
productsWithEnoughSpace.sort(function (a, b) {
|
|
576
|
+
return b.amount - a.amount;
|
|
577
|
+
});
|
|
578
|
+
var targetProduct = productsWithEnoughSpace[0];
|
|
579
|
+
var targetAllocation = result.get(targetProduct.productId);
|
|
580
|
+
if (targetAllocation) {
|
|
581
|
+
// 差值直接加到折扣金额上
|
|
582
|
+
result.set(targetProduct.productId, {
|
|
583
|
+
discountAmount: new Decimal(targetAllocation.discountAmount).plus(totalDifference).toNumber(),
|
|
584
|
+
difference: 0 // 不需要存储差值
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
} else {
|
|
588
|
+
// 🔥 优先级2:所有数量为1的商品都没有足够剩余空间
|
|
589
|
+
// 选择金额最大的商品,差值存储在metadata中
|
|
590
|
+
singleQuantityProducts.sort(function (a, b) {
|
|
591
|
+
return b.amount - a.amount;
|
|
592
|
+
});
|
|
593
|
+
var _targetProduct = singleQuantityProducts[0];
|
|
594
|
+
var _targetAllocation = result.get(_targetProduct.productId);
|
|
595
|
+
if (_targetAllocation) {
|
|
596
|
+
result.set(_targetProduct.productId, _objectSpread(_objectSpread({}, _targetAllocation), {}, {
|
|
597
|
+
difference: totalDifference
|
|
598
|
+
}));
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
} else {
|
|
602
|
+
// 🔥 优先级3:没有数量为1的商品,走原有逻辑
|
|
603
|
+
// 差值存储在最后一个商品的metadata中
|
|
604
|
+
var lastProduct = applicableProducts[applicableProducts.length - 1];
|
|
605
|
+
var lastProductAllocation = result.get(lastProduct.productId);
|
|
606
|
+
if (lastProductAllocation) {
|
|
607
|
+
result.set(lastProduct.productId, _objectSpread(_objectSpread({}, lastProductAllocation), {}, {
|
|
608
|
+
difference: totalDifference
|
|
609
|
+
}));
|
|
610
|
+
}
|
|
556
611
|
}
|
|
557
612
|
}
|
|
558
613
|
return result;
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "duration" | "session" | "normal";
|
|
53
53
|
}
|
|
@@ -294,8 +294,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
294
294
|
const flattenedList = flattenProductsWithBundle(productList);
|
|
295
295
|
const sortedFlattenedList = flattenedList.sort((a, b) => {
|
|
296
296
|
var _a, _b;
|
|
297
|
-
const priceA = new import_decimal.default(
|
|
298
|
-
|
|
297
|
+
const priceA = new import_decimal.default(
|
|
298
|
+
a.type === "bundle" ? a.original_price ?? a.price ?? "0" : a.price || "0"
|
|
299
|
+
);
|
|
300
|
+
const priceB = new import_decimal.default(
|
|
301
|
+
b.type === "bundle" ? b.original_price ?? b.price ?? "0" : b.price || "0"
|
|
302
|
+
);
|
|
299
303
|
if (priceA.equals(priceB)) {
|
|
300
304
|
if (a.type !== b.type) {
|
|
301
305
|
return a.type === "main" ? -1 : 1;
|
|
@@ -369,7 +373,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
369
373
|
}
|
|
370
374
|
const applicableProducts = [];
|
|
371
375
|
sortedFlattenedList.forEach((flatItem) => {
|
|
372
|
-
var _a, _b, _c, _d, _e, _f;
|
|
376
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
373
377
|
let product;
|
|
374
378
|
if (flatItem.type === "main") {
|
|
375
379
|
product = flatItem.product;
|
|
@@ -401,11 +405,15 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
401
405
|
const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
|
|
402
406
|
if (isLimitedProduct && isBundleAvailable) {
|
|
403
407
|
const quantity = flatItem.type === "main" ? product.quantity || 1 : (product.num || 1) * (((_f = flatItem.parentProduct) == null ? void 0 : _f.quantity) || 1);
|
|
404
|
-
|
|
408
|
+
const productData = {
|
|
405
409
|
productId: flatItem._id,
|
|
406
410
|
amount: Number(product.price || 0),
|
|
407
411
|
quantity
|
|
408
|
-
}
|
|
412
|
+
};
|
|
413
|
+
if (flatItem.type === "bundle") {
|
|
414
|
+
productData.parentQuantity = ((_g = flatItem.parentProduct) == null ? void 0 : _g.quantity) || 1;
|
|
415
|
+
}
|
|
416
|
+
applicableProducts.push(productData);
|
|
409
417
|
}
|
|
410
418
|
});
|
|
411
419
|
if (applicableProducts.length > 0) {
|
|
@@ -308,7 +308,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
308
308
|
date: string;
|
|
309
309
|
status: string;
|
|
310
310
|
week: string;
|
|
311
|
-
weekNum: 0 | 2 | 1 | 3 |
|
|
311
|
+
weekNum: 0 | 2 | 1 | 3 | 5 | 4 | 6;
|
|
312
312
|
}[]>;
|
|
313
313
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
314
314
|
private getScheduleDataByIds;
|
|
@@ -123,7 +123,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
123
123
|
* 获取当前的客户搜索条件
|
|
124
124
|
* @returns 当前搜索条件
|
|
125
125
|
*/
|
|
126
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
126
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
|
|
127
127
|
/**
|
|
128
128
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
129
129
|
* @returns 客户状态
|
|
@@ -74,16 +74,17 @@ export declare const isOrderLevelFixedAmountDiscount: (discount: Discount) => bo
|
|
|
74
74
|
/**
|
|
75
75
|
* 计算订单级别固定金额折扣卡的分摊结果
|
|
76
76
|
* @param discount 折扣卡
|
|
77
|
-
* @param applicableProducts 适用商品列表 { productId, amount, quantity }
|
|
77
|
+
* @param applicableProducts 适用商品列表 { productId, amount, quantity, parentQuantity }
|
|
78
78
|
* @returns 分摊结果 Map<productId, { discountAmount, difference }>
|
|
79
79
|
* 注意:
|
|
80
80
|
* - discountAmount 是单价折扣金额(不是总折扣金额)
|
|
81
|
-
* - difference
|
|
81
|
+
* - difference(总差值)优先直接加到数量为1的单商品折扣上,如果没有则存储在metadata中
|
|
82
82
|
*/
|
|
83
83
|
export declare const calculateOrderLevelDiscountAllocation: (discount: Discount, applicableProducts: Array<{
|
|
84
84
|
productId: string | number;
|
|
85
85
|
amount: number;
|
|
86
86
|
quantity: number;
|
|
87
|
+
parentQuantity?: number;
|
|
87
88
|
}>) => Map<string | number, {
|
|
88
89
|
discountAmount: number;
|
|
89
90
|
difference: number;
|
|
@@ -345,13 +345,52 @@ var calculateOrderLevelDiscountAllocation = (discount, applicableProducts) => {
|
|
|
345
345
|
});
|
|
346
346
|
const totalDifference = new import_decimal.default(actualDiscountTotal).minus(allocatedTotal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
|
|
347
347
|
if (totalDifference > 0) {
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
348
|
+
const isSingleQuantity = (product) => {
|
|
349
|
+
if (product.parentQuantity !== void 0) {
|
|
350
|
+
return product.quantity === 1 && product.parentQuantity === 1;
|
|
351
|
+
}
|
|
352
|
+
return product.quantity === 1;
|
|
353
|
+
};
|
|
354
|
+
const singleQuantityProducts = applicableProducts.filter(isSingleQuantity);
|
|
355
|
+
if (singleQuantityProducts.length > 0) {
|
|
356
|
+
const productsWithEnoughSpace = singleQuantityProducts.filter((product) => {
|
|
357
|
+
const allocation = result.get(product.productId);
|
|
358
|
+
if (!allocation)
|
|
359
|
+
return false;
|
|
360
|
+
const remainingSpace = new import_decimal.default(product.amount).minus(allocation.discountAmount).toNumber();
|
|
361
|
+
return remainingSpace >= totalDifference;
|
|
354
362
|
});
|
|
363
|
+
if (productsWithEnoughSpace.length > 0) {
|
|
364
|
+
productsWithEnoughSpace.sort((a, b) => b.amount - a.amount);
|
|
365
|
+
const targetProduct = productsWithEnoughSpace[0];
|
|
366
|
+
const targetAllocation = result.get(targetProduct.productId);
|
|
367
|
+
if (targetAllocation) {
|
|
368
|
+
result.set(targetProduct.productId, {
|
|
369
|
+
discountAmount: new import_decimal.default(targetAllocation.discountAmount).plus(totalDifference).toNumber(),
|
|
370
|
+
difference: 0
|
|
371
|
+
// 不需要存储差值
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
} else {
|
|
375
|
+
singleQuantityProducts.sort((a, b) => b.amount - a.amount);
|
|
376
|
+
const targetProduct = singleQuantityProducts[0];
|
|
377
|
+
const targetAllocation = result.get(targetProduct.productId);
|
|
378
|
+
if (targetAllocation) {
|
|
379
|
+
result.set(targetProduct.productId, {
|
|
380
|
+
...targetAllocation,
|
|
381
|
+
difference: totalDifference
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
} else {
|
|
386
|
+
const lastProduct = applicableProducts[applicableProducts.length - 1];
|
|
387
|
+
const lastProductAllocation = result.get(lastProduct.productId);
|
|
388
|
+
if (lastProductAllocation) {
|
|
389
|
+
result.set(lastProduct.productId, {
|
|
390
|
+
...lastProductAllocation,
|
|
391
|
+
difference: totalDifference
|
|
392
|
+
});
|
|
393
|
+
}
|
|
355
394
|
}
|
|
356
395
|
}
|
|
357
396
|
return result;
|