From 00a073709ebd4e9f38eb313079801cf8c76da0d7 Mon Sep 17 00:00:00 2001 From: zhh Date: Tue, 28 Aug 2018 11:15:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E4=BF=83=E9=94=80?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall/portal/domain/CartPromotionItem.java | 11 +---------- .../service/impl/OmsPromotionServiceImpl.java | 17 ++++++++++------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/mall-portal/src/main/java/com/macro/mall/portal/domain/CartPromotionItem.java b/mall-portal/src/main/java/com/macro/mall/portal/domain/CartPromotionItem.java index 7a6dbfa..6fda2a4 100644 --- a/mall-portal/src/main/java/com/macro/mall/portal/domain/CartPromotionItem.java +++ b/mall-portal/src/main/java/com/macro/mall/portal/domain/CartPromotionItem.java @@ -8,21 +8,12 @@ import java.math.BigDecimal; * Created by macro on 2018/8/27. * 购物车中促销信息的封装 */ -public class CartPromotionItem { - private OmsCartItem cartItem; +public class CartPromotionItem extends OmsCartItem{ //促销活动信息 private String promotionMessage; //促销活动减去的金额,针对每个商品 private BigDecimal reduceAmount; - public OmsCartItem getCartItem() { - return cartItem; - } - - public void setCartItem(OmsCartItem cartItem) { - this.cartItem = cartItem; - } - public String getPromotionMessage() { return promotionMessage; } diff --git a/mall-portal/src/main/java/com/macro/mall/portal/service/impl/OmsPromotionServiceImpl.java b/mall-portal/src/main/java/com/macro/mall/portal/service/impl/OmsPromotionServiceImpl.java index 737e505..c1b9331 100644 --- a/mall-portal/src/main/java/com/macro/mall/portal/service/impl/OmsPromotionServiceImpl.java +++ b/mall-portal/src/main/java/com/macro/mall/portal/service/impl/OmsPromotionServiceImpl.java @@ -8,10 +8,12 @@ import com.macro.mall.portal.dao.PortalProductDao; import com.macro.mall.portal.domain.CartPromotionItem; import com.macro.mall.portal.domain.PromotionProduct; import com.macro.mall.portal.service.OmsPromotionService; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; /** @@ -40,7 +42,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService { //单品促销 for (OmsCartItem item : itemList) { CartPromotionItem cartPromotionItem = new CartPromotionItem(); - cartPromotionItem.setCartItem(item); + BeanUtils.copyProperties(item,cartPromotionItem); cartPromotionItem.setPromotionMessage("单品促销"); //商品原价-促销价 cartPromotionItem.setReduceAmount(getOriginalPrice(promotionProduct, item.getProductSkuId()).subtract(getSinglePromotionPrice(promotionProduct, item.getProductSkuId()))); @@ -53,7 +55,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService { if(ladder!=null){ for (OmsCartItem item : itemList) { CartPromotionItem cartPromotionItem = new CartPromotionItem(); - cartPromotionItem.setCartItem(item); + BeanUtils.copyProperties(item,cartPromotionItem); String message = getLadderPromotionMessage(ladder); cartPromotionItem.setPromotionMessage(message); //商品原价-折扣金额*商品原价 @@ -72,11 +74,12 @@ public class OmsPromotionServiceImpl implements OmsPromotionService { if(fullReduction!=null){ for (OmsCartItem item : itemList) { CartPromotionItem cartPromotionItem = new CartPromotionItem(); - cartPromotionItem.setCartItem(item); + BeanUtils.copyProperties(item,cartPromotionItem); String message = getFullReductionPromotionMessage(fullReduction); cartPromotionItem.setPromotionMessage(message); //(商品原价/总价)*满减金额 - BigDecimal reduceAmount = (getOriginalPrice(promotionProduct,item.getProductSkuId()).divide(totalAmount)).multiply(fullReduction.getReducePrice()); + BigDecimal originalPrice = getOriginalPrice(promotionProduct, item.getProductSkuId()); + BigDecimal reduceAmount = originalPrice.divide(totalAmount,RoundingMode.HALF_EVEN).multiply(fullReduction.getReducePrice()); cartPromotionItem.setReduceAmount(reduceAmount); cartPromotionItemList.add(cartPromotionItem); } @@ -108,7 +111,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService { private Map> groupCartItemBySpu(List cartItemList) { Map> productCartMap = new TreeMap<>(); for (OmsCartItem cartItem : cartItemList) { - List productCartItemList = productCartMap.get(cartItem.getId()); + List productCartItemList = productCartMap.get(cartItem.getProductId()); if (productCartItemList == null) { productCartItemList = new ArrayList<>(); productCartItemList.add(cartItem); @@ -141,7 +144,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService { private void handleNoReduce(List cartPromotionItemList, List itemList) { for (OmsCartItem item : itemList) { CartPromotionItem cartPromotionItem = new CartPromotionItem(); - cartPromotionItem.setCartItem(item); + BeanUtils.copyProperties(item,cartPromotionItem); cartPromotionItem.setPromotionMessage("无优惠"); cartPromotionItem.setReduceAmount(new BigDecimal(0)); cartPromotionItemList.add(cartPromotionItem); @@ -228,7 +231,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService { */ private BigDecimal getSinglePromotionPrice(PromotionProduct promotionProduct, Long productSkuId) { for (PmsSkuStock skuStock : promotionProduct.getSkuStockList()) { - if (productSkuId == skuStock.getId()) { + if (productSkuId.equals(skuStock.getId()) ) { return skuStock.getPromotionPrice(); } }