fix: 问题修复

This commit is contained in:
2025-10-13 11:19:26 +08:00
parent b4b87218d1
commit cd351be6d0
7 changed files with 80 additions and 65 deletions

View File

@@ -181,8 +181,15 @@ export function returnCouponCanUse(args) {
};
}
}
// 商品兑换券,第二件半价和买一送一判断是否有可用商品
if ([2, 4, 5].includes(coupon.type)) {
if (coupon.type == 2 && fullAmount < coupon.fullAmount) {
return {
canUse: false,
reason: `${coupon.fullAmount}元可用,当前可参与金额${fullAmount}`,
};
}
// 没有符合条件的商品
if (isDikouAll && canDikouGoodsArr.length === 0) {
return {
@@ -265,12 +272,14 @@ export function calcDiscountGoodsArrPrice(discountGoodsArr, discountNum, user, s
const shengyuNum = discountNum - hasCountNum;
const num = Math.min(goods.num, shengyuNum);
discountPrice += returnGoodsPrice(goods, user, shopInfo) * num;
hasCountNum += num;
hasDiscountGoodsArr.push({
...goods,
num,
});
}
return {
discountPrice,
hasDiscountGoodsArr,
@@ -330,7 +339,6 @@ export function returnCouponZhekouDiscount(
// 将商品订单价格转换为BigNumber并减去优惠券折扣
const adjustedGoodsOrderPrice = new BigNumber(goodsOrderPrice).minus(goodsCouponDiscount);
console.log("adjustedGoodsOrderPrice", adjustedGoodsOrderPrice.toNumber());
// 计算优惠比例:(100 - 折扣率) / 100
const discountAmountRatio = new BigNumber(100).minus(discountRate).dividedBy(100);
@@ -366,9 +374,7 @@ export function returnCouponProductDiscount(canDikouGoodsArr, coupon, user, shop
//抵扣全部商品
if (useFoods.length === 0) {
if (useRule == "price_asc") {
discountGoodsArr = canDikouGoodsArr
.slice(canDikouGoodsArr.length - discountNum, canDikouGoodsArr.length)
.reverse();
discountGoodsArr = canDikouGoodsArr.slice(discountNum * -1).reverse();
} else {
discountGoodsArr = canDikouGoodsArr.slice(0, discountNum);
}
@@ -378,9 +384,7 @@ export function returnCouponProductDiscount(canDikouGoodsArr, coupon, user, shop
useFoods.find((food) => food.id == v.productId)
);
if (useRule == "price_asc") {
discountGoodsArr = discountSelGoodsArr
.slice(discountSelGoodsArr.length - discountNum, discountSelGoodsArr.length)
.reverse();
discountGoodsArr = discountSelGoodsArr.slice(discountNum * -1).reverse();
} else {
discountGoodsArr = discountSelGoodsArr.slice(0, discountNum);
}

View File

@@ -1707,12 +1707,17 @@ export function calculateOrderCostSummary(
}
// 5. 最终实付金额计算(整合所有费用)
const finalPayAmount = new BigNumber(goodsOriginalAmount) // 商品原价总和
// 先计算减去所有折扣后的金额并确保最小值为0
const discountedAmount = new BigNumber(goodsOriginalAmount) // 商品原价总和
.minus(goodsDiscountAmount) // 减去商品折扣
.minus(couponDeductionAmount) // 减去优惠券抵扣
.minus(newUserDiscount) // 新客立减
.minus(pointDeductionAmount) // 减去积分抵扣
.minus(merchantReductionActualAmount) // 减去商家实际减免金额
.minus(merchantReductionActualAmount); // 减去商家实际减免金额
// 确保折扣后金额不小于0再加上后续费用
const nonNegativeAmount = discountedAmount.gt(0) ? discountedAmount : new BigNumber(0);
const finalPayAmount = nonNegativeAmount
.plus(seatFee) // 加上餐位费(不参与减免)
.plus(packFee) // 加上打包费(不参与减免)
.plus(additionalFee); // 加上附加费