Commit bb5760ba by weijiguang

fix orig_discount bug

parent 90d99a2b
package com.soss.system.service.impl; package com.soss.system.service.impl;
import com.alibaba.fastjson.JSON;
import com.soss.common.enums.CouponCategoryType; import com.soss.common.enums.CouponCategoryType;
import com.soss.common.enums.CouponState; import com.soss.common.enums.CouponState;
import com.soss.common.enums.CouponUserType; import com.soss.common.enums.CouponUserType;
...@@ -22,6 +23,7 @@ import org.springframework.util.CollectionUtils; ...@@ -22,6 +23,7 @@ import org.springframework.util.CollectionUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -190,6 +192,9 @@ public class CouponUserServiceImpl implements ICouponUserService { ...@@ -190,6 +192,9 @@ public class CouponUserServiceImpl implements ICouponUserService {
BigDecimal orderTotalAmount = orderDetails.stream().map(OrderDetail::getAmountShould).reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal orderTotalAmount = orderDetails.stream().map(OrderDetail::getAmountShould).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal orderTotalOrigDiscount = orderDetails.stream().map(OrderDetail::getOrigDiscount).reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal orderTotalOrigDiscount = orderDetails.stream().map(OrderDetail::getOrigDiscount).reduce(BigDecimal.ZERO, BigDecimal::add);
log.info("orderTotalAmount:{}, orderTotalOrigDiscount:{}", orderTotalAmount, orderTotalOrigDiscount); log.info("orderTotalAmount:{}, orderTotalOrigDiscount:{}", orderTotalAmount, orderTotalOrigDiscount);
if (!CollectionUtils.isEmpty(couponVos)) {
orderDetails.forEach(x -> x.setAmountShould(x.getOrigDiscount()));
}
couponVos.stream().filter(couponVo -> StringUtils.isEmpty(couponVo.getNotFitableDesc())).forEach(couponVo -> { couponVos.stream().filter(couponVo -> StringUtils.isEmpty(couponVo.getNotFitableDesc())).forEach(couponVo -> {
/** 可用饮品范围的判断 */ /** 可用饮品范围的判断 */
List<Long> fitCouponGoodsIdList = goods.stream().filter(good -> List<Long> fitCouponGoodsIdList = goods.stream().filter(good ->
...@@ -206,11 +211,27 @@ public class CouponUserServiceImpl implements ICouponUserService { ...@@ -206,11 +211,27 @@ public class CouponUserServiceImpl implements ICouponUserService {
} }
/** 券价值的判断 */ /** 券价值的判断 */
if (couponVo.getType().equals(CouponCategoryType.DEDUCTION.getType())) { // 抵扣 if (couponVo.getType().equals(CouponCategoryType.DEDUCTION.getType())) { // 抵扣
if (couponVo.getPriceLimit() != null && couponVo.getPriceLimit().compareTo(BigDecimal.ZERO) != 0 && couponVo.getPriceLimit().compareTo(orderTotalAmount) > 0) { if (couponVo.getPriceLimit() != null && couponVo.getPriceLimit().compareTo(BigDecimal.ZERO) != 0 && couponVo.getPriceLimit().compareTo(orderTotalOrigDiscount) > 0) {
couponVo.setNotFitableDesc("未达到满减要求"); couponVo.setNotFitableDesc("未达到满减要求");
return; return;
} }
couponVo.setCouponAmount(couponVo.getPriceDiscount().min(orderTotalOrigDiscount)); couponVo.setCouponAmount(couponVo.getPriceDiscount().min(orderTotalOrigDiscount));
AtomicReference<Integer> nums = new AtomicReference<>(0);
orderDetails.forEach(x -> nums.updateAndGet(v -> v + x.getNum()));
log.info("nums:{}", nums);
if (nums.get() <= 1) {
OrderDetail orderDetail = orderDetails.get(0);
orderDetail.setCouponAmount(couponVo.getCouponAmount().negate());
orderDetail.setRealAmount(orderDetail.getAmountShould().add(orderDetail.getCouponAmount()));
} else {
orderDetails.forEach(orderDetail -> {
BigDecimal rate = orderDetail.getAmountShould().divide(orderTotalOrigDiscount, 2, BigDecimal.ROUND_HALF_UP);;
orderDetail.setCouponAmount(couponVo.getCouponAmount().negate().multiply(rate));
orderDetail.setRealAmount(orderDetail.getAmountShould().add(orderDetail.getCouponAmount()));
log.info("rate:{},detail:{}", rate, JSON.toJSON(orderDetail));
});
}
} else { } else {
List<OrderDetail> fitOrderDetails = orderDetails.stream().filter(orderDetail -> fitCouponGoodsIdList.contains(orderDetail.getGoodsId())).collect(Collectors.toList()); List<OrderDetail> fitOrderDetails = orderDetails.stream().filter(orderDetail -> fitCouponGoodsIdList.contains(orderDetail.getGoodsId())).collect(Collectors.toList());
BigDecimal fitGoodsAmount = fitOrderDetails.stream().map(OrderDetail::getAmountShould).reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal fitGoodsAmount = fitOrderDetails.stream().map(OrderDetail::getAmountShould).reduce(BigDecimal.ZERO, BigDecimal::add);
...@@ -261,7 +282,7 @@ public class CouponUserServiceImpl implements ICouponUserService { ...@@ -261,7 +282,7 @@ public class CouponUserServiceImpl implements ICouponUserService {
orderDetail.setOriAmount(skuNum.multiply(sku.getPrice())); orderDetail.setOriAmount(skuNum.multiply(sku.getPrice()));
orderDetail.setUnitPrice(sku.getDiscount()); orderDetail.setUnitPrice(sku.getDiscount());
orderDetail.setAmountShould(skuNum.multiply(sku.getDiscount())); orderDetail.setAmountShould(skuNum.multiply(sku.getDiscount()));
orderDetail.setOrigDiscount(sku.getOrigDiscount()); orderDetail.setOrigDiscount(skuNum.multiply(sku.getOrigDiscount()));
}); });
return goodsSkus; return goodsSkus;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment