修复优惠券价格计算分摊问题
This commit is contained in:
parent
aa024c87b2
commit
eaf3aa2b2f
@ -58,7 +58,7 @@ public class RocketmqTimerTrigger implements TimeTrigger {
|
||||
log.info("add Redis key {} --------------------------", generateKey);
|
||||
log.info("定时执行在【" + DateUtil.toString(timeTriggerMsg.getTriggerTime(), "yyyy-MM-dd HH:mm:ss") + "】,消费【" + timeTriggerMsg.getParam().toString() + "】");
|
||||
} else {
|
||||
log.info("延时任务添加失败!");
|
||||
log.error("延时任务添加失败!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@ import cn.lili.modules.promotion.entity.dto.PromotionPriceParamDTO;
|
||||
import cn.lili.modules.promotion.entity.dto.StorePromotionPriceDTO;
|
||||
import cn.lili.modules.promotion.service.PromotionGoodsService;
|
||||
import cn.lili.modules.promotion.service.PromotionPriceService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -27,6 +26,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -151,29 +151,26 @@ public class SkuPromotionRender implements CartRenderStep {
|
||||
|
||||
for (CartVO cartVO : tradeDTO.getCartList()) {
|
||||
// 根据店铺分配店铺价格计算结果
|
||||
List<StorePromotionPriceDTO> collect = promotionPrice.getStorePromotionPriceList().parallelStream().map(i -> i.getStoreId().equals(cartVO.getStoreId()) ? i : null).collect(Collectors.toList());
|
||||
if (!collect.isEmpty() && collect.get(0) != null) {
|
||||
StorePromotionPriceDTO storePromotionPriceDTO = collect.get(0);
|
||||
Optional<StorePromotionPriceDTO> storePromotionPriceDTOOptional = promotionPrice.getStorePromotionPriceList().parallelStream().filter(i -> i.getStoreId().equals(cartVO.getStoreId())).findAny();
|
||||
if (storePromotionPriceDTOOptional.isPresent()) {
|
||||
StorePromotionPriceDTO storePromotionPriceDTO = storePromotionPriceDTOOptional.get();
|
||||
// 根据商品分配商品结果计算结果
|
||||
this.distributionSkuPromotionPrice(cartVO.getSkuList(), storePromotionPriceDTO);
|
||||
|
||||
if (storePromotionPriceDTO != null) {
|
||||
PriceDetailDTO sSpd = new PriceDetailDTO();
|
||||
PriceDetailVO sPd = new PriceDetailVO();
|
||||
sSpd.setGoodsPrice(storePromotionPriceDTO.getTotalOriginPrice());
|
||||
sSpd.setDiscountPrice(storePromotionPriceDTO.getTotalDiscountPrice());
|
||||
sSpd.setCouponPrice(storePromotionPriceDTO.getTotalCouponPrice());
|
||||
sSpd.setPayPoint(storePromotionPriceDTO.getTotalPoints().intValue());
|
||||
|
||||
sPd.setOriginalPrice(storePromotionPriceDTO.getTotalOriginPrice());
|
||||
sPd.setFinalePrice(storePromotionPriceDTO.getTotalFinalePrice());
|
||||
sPd.setDiscountPrice(storePromotionPriceDTO.getTotalDiscountPrice());
|
||||
sPd.setPayPoint(storePromotionPriceDTO.getTotalPoints().intValue());
|
||||
cartVO.setPriceDetailDTO(sSpd);
|
||||
cartVO.setPriceDetailVO(sPd);
|
||||
cartVO.setWeight(storePromotionPriceDTO.getTotalWeight());
|
||||
}
|
||||
PriceDetailDTO sSpd = new PriceDetailDTO();
|
||||
PriceDetailVO sPd = new PriceDetailVO();
|
||||
sSpd.setGoodsPrice(storePromotionPriceDTO.getTotalOriginPrice());
|
||||
sSpd.setDiscountPrice(storePromotionPriceDTO.getTotalDiscountPrice());
|
||||
sSpd.setCouponPrice(storePromotionPriceDTO.getTotalCouponPrice());
|
||||
sSpd.setPayPoint(storePromotionPriceDTO.getTotalPoints().intValue());
|
||||
|
||||
sPd.setOriginalPrice(storePromotionPriceDTO.getTotalOriginPrice());
|
||||
sPd.setFinalePrice(storePromotionPriceDTO.getTotalFinalePrice());
|
||||
sPd.setDiscountPrice(storePromotionPriceDTO.getTotalDiscountPrice());
|
||||
sPd.setPayPoint(storePromotionPriceDTO.getTotalPoints().intValue());
|
||||
cartVO.setPriceDetailDTO(sSpd);
|
||||
cartVO.setPriceDetailVO(sPd);
|
||||
cartVO.setWeight(storePromotionPriceDTO.getTotalWeight());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,6 +269,9 @@ public class CartServiceImpl implements CartService {
|
||||
}
|
||||
}
|
||||
cartSkuVOS.removeAll(deleteVos);
|
||||
// 清除选择的优惠券
|
||||
tradeDTO.setPlatformCoupon(null);
|
||||
tradeDTO.setStoreCoupons(null);
|
||||
// 清除添加过的备注
|
||||
tradeDTO.setStoreRemark(null);
|
||||
cache.put(this.getOriginKey(tradeDTO.getCartTypeEnum()), tradeDTO);
|
||||
|
@ -126,6 +126,10 @@ public class PromotionPriceServiceImpl implements PromotionPriceService {
|
||||
if (platformCoupons != null && !platformCoupons.isEmpty()) {
|
||||
// 计算平台优惠券活动
|
||||
couponTotalPrice = CurrencyUtil.add(couponTotalPrice, this.calculationCoupon(platformCoupons, priceDTOList));
|
||||
for (StorePromotionPriceDTO storePromotionPriceDTO : storePromotionPriceList) {
|
||||
Double couponPrice = storePromotionPriceDTO.getGoodsSkuPromotionPriceList().parallelStream().mapToDouble(GoodsSkuPromotionPriceDTO::getCouponPrice).sum();
|
||||
storePromotionPriceDTO.setTotalCouponPrice(couponPrice);
|
||||
}
|
||||
}
|
||||
promotionPrice.setStorePromotionPriceList(storePromotionPriceList);
|
||||
promotionPrice.setTotalCouponPrice(couponTotalPrice);
|
||||
@ -290,17 +294,14 @@ public class PromotionPriceServiceImpl implements PromotionPriceService {
|
||||
// 合计优惠券范围内的所有商品的原价
|
||||
double totalPrice = conformCollect.parallelStream().mapToDouble(GoodsSkuPromotionPriceDTO::getOriginalPrice).sum();
|
||||
|
||||
double discountPrice = 0;
|
||||
// 根据优惠券优惠类型,判断是否满足条件
|
||||
if (CouponTypeEnum.PRICE.name().equals(coupon.getCouponType()) && coupon.getConsumeThreshold() <= totalPrice) {
|
||||
couponTotalPrice = CurrencyUtil.add(couponTotalPrice, coupon.getPrice());
|
||||
discountPrice = coupon.getPrice();
|
||||
} else if (CouponTypeEnum.DISCOUNT.name().equals(coupon.getCouponType())) {
|
||||
double fullRate = coupon.getDiscount() >= 10 ? coupon.getDiscount() / 100 : coupon.getDiscount() / 10;
|
||||
double discountRatePrice = CurrencyUtil.sub(totalPrice, CurrencyUtil.mul(totalPrice, fullRate));
|
||||
|
||||
couponTotalPrice = CurrencyUtil.add(couponTotalPrice, discountRatePrice);
|
||||
discountPrice = discountRatePrice;
|
||||
// 消费限额判断
|
||||
// if (coupon.getConsumeThreshold() >= discountRatePrice) {
|
||||
// couponTotalPrice = CurrencyUtil.add(couponTotalPrice, discountRatePrice);
|
||||
@ -312,14 +313,15 @@ public class PromotionPriceServiceImpl implements PromotionPriceService {
|
||||
}
|
||||
|
||||
// 分配到每个商品的优惠券金额
|
||||
double distributePrice = CurrencyUtil.div(discountPrice, conformCollect.size());
|
||||
for (GoodsSkuPromotionPriceDTO goodsSkuPromotionPriceDTO : conformCollect) {
|
||||
double rate = CurrencyUtil.div(goodsSkuPromotionPriceDTO.getFinalePrice(), totalPrice, 5);
|
||||
double distributeCouponPrice = CurrencyUtil.mul(couponTotalPrice, rate);
|
||||
if (goodsSkuPromotionPriceDTO.getFinalePrice() != null) {
|
||||
goodsSkuPromotionPriceDTO.setFinalePrice(CurrencyUtil.sub(goodsSkuPromotionPriceDTO.getFinalePrice(), distributePrice));
|
||||
goodsSkuPromotionPriceDTO.setFinalePrice(CurrencyUtil.sub(goodsSkuPromotionPriceDTO.getFinalePrice(), distributeCouponPrice));
|
||||
} else {
|
||||
goodsSkuPromotionPriceDTO.setFinalePrice(CurrencyUtil.sub(goodsSkuPromotionPriceDTO.getOriginalPrice(), distributePrice));
|
||||
goodsSkuPromotionPriceDTO.setFinalePrice(CurrencyUtil.sub(goodsSkuPromotionPriceDTO.getOriginalPrice(), distributeCouponPrice));
|
||||
}
|
||||
goodsSkuPromotionPriceDTO.setCouponPrice(distributePrice);
|
||||
goodsSkuPromotionPriceDTO.setCouponPrice(distributeCouponPrice);
|
||||
goodsSkuPromotionPriceDTO.setTotalFinalePrice(CurrencyUtil.mul(goodsSkuPromotionPriceDTO.getFinalePrice(), goodsSkuPromotionPriceDTO.getNumber()));
|
||||
BasePromotion basePromotion = new BasePromotion();
|
||||
basePromotion.setId(coupon.getId());
|
||||
|
@ -257,7 +257,11 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
private NativeSearchQueryBuilder createSearchQueryBuilder(EsGoodsSearchDTO searchDTO, PageVO pageVo, boolean isAggregation) {
|
||||
NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder();
|
||||
if (pageVo != null) {
|
||||
Pageable pageable = PageRequest.of(pageVo.getPageNumber(), pageVo.getPageSize());
|
||||
Integer pageNumber = pageVo.getPageNumber() - 1;
|
||||
if (pageNumber < 0) {
|
||||
pageNumber = 0;
|
||||
}
|
||||
Pageable pageable = PageRequest.of(pageNumber, pageVo.getPageSize());
|
||||
//分页
|
||||
nativeSearchQueryBuilder.withPageable(pageable);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user