购物车促销信息优化
This commit is contained in:
parent
5790bb6480
commit
00a073709e
@ -8,21 +8,12 @@ import java.math.BigDecimal;
|
|||||||
* Created by macro on 2018/8/27.
|
* Created by macro on 2018/8/27.
|
||||||
* 购物车中促销信息的封装
|
* 购物车中促销信息的封装
|
||||||
*/
|
*/
|
||||||
public class CartPromotionItem {
|
public class CartPromotionItem extends OmsCartItem{
|
||||||
private OmsCartItem cartItem;
|
|
||||||
//促销活动信息
|
//促销活动信息
|
||||||
private String promotionMessage;
|
private String promotionMessage;
|
||||||
//促销活动减去的金额,针对每个商品
|
//促销活动减去的金额,针对每个商品
|
||||||
private BigDecimal reduceAmount;
|
private BigDecimal reduceAmount;
|
||||||
|
|
||||||
public OmsCartItem getCartItem() {
|
|
||||||
return cartItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCartItem(OmsCartItem cartItem) {
|
|
||||||
this.cartItem = cartItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPromotionMessage() {
|
public String getPromotionMessage() {
|
||||||
return promotionMessage;
|
return promotionMessage;
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,12 @@ import com.macro.mall.portal.dao.PortalProductDao;
|
|||||||
import com.macro.mall.portal.domain.CartPromotionItem;
|
import com.macro.mall.portal.domain.CartPromotionItem;
|
||||||
import com.macro.mall.portal.domain.PromotionProduct;
|
import com.macro.mall.portal.domain.PromotionProduct;
|
||||||
import com.macro.mall.portal.service.OmsPromotionService;
|
import com.macro.mall.portal.service.OmsPromotionService;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,7 +42,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
|
|||||||
//单品促销
|
//单品促销
|
||||||
for (OmsCartItem item : itemList) {
|
for (OmsCartItem item : itemList) {
|
||||||
CartPromotionItem cartPromotionItem = new CartPromotionItem();
|
CartPromotionItem cartPromotionItem = new CartPromotionItem();
|
||||||
cartPromotionItem.setCartItem(item);
|
BeanUtils.copyProperties(item,cartPromotionItem);
|
||||||
cartPromotionItem.setPromotionMessage("单品促销");
|
cartPromotionItem.setPromotionMessage("单品促销");
|
||||||
//商品原价-促销价
|
//商品原价-促销价
|
||||||
cartPromotionItem.setReduceAmount(getOriginalPrice(promotionProduct, item.getProductSkuId()).subtract(getSinglePromotionPrice(promotionProduct, item.getProductSkuId())));
|
cartPromotionItem.setReduceAmount(getOriginalPrice(promotionProduct, item.getProductSkuId()).subtract(getSinglePromotionPrice(promotionProduct, item.getProductSkuId())));
|
||||||
@ -53,7 +55,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
|
|||||||
if(ladder!=null){
|
if(ladder!=null){
|
||||||
for (OmsCartItem item : itemList) {
|
for (OmsCartItem item : itemList) {
|
||||||
CartPromotionItem cartPromotionItem = new CartPromotionItem();
|
CartPromotionItem cartPromotionItem = new CartPromotionItem();
|
||||||
cartPromotionItem.setCartItem(item);
|
BeanUtils.copyProperties(item,cartPromotionItem);
|
||||||
String message = getLadderPromotionMessage(ladder);
|
String message = getLadderPromotionMessage(ladder);
|
||||||
cartPromotionItem.setPromotionMessage(message);
|
cartPromotionItem.setPromotionMessage(message);
|
||||||
//商品原价-折扣金额*商品原价
|
//商品原价-折扣金额*商品原价
|
||||||
@ -72,11 +74,12 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
|
|||||||
if(fullReduction!=null){
|
if(fullReduction!=null){
|
||||||
for (OmsCartItem item : itemList) {
|
for (OmsCartItem item : itemList) {
|
||||||
CartPromotionItem cartPromotionItem = new CartPromotionItem();
|
CartPromotionItem cartPromotionItem = new CartPromotionItem();
|
||||||
cartPromotionItem.setCartItem(item);
|
BeanUtils.copyProperties(item,cartPromotionItem);
|
||||||
String message = getFullReductionPromotionMessage(fullReduction);
|
String message = getFullReductionPromotionMessage(fullReduction);
|
||||||
cartPromotionItem.setPromotionMessage(message);
|
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);
|
cartPromotionItem.setReduceAmount(reduceAmount);
|
||||||
cartPromotionItemList.add(cartPromotionItem);
|
cartPromotionItemList.add(cartPromotionItem);
|
||||||
}
|
}
|
||||||
@ -108,7 +111,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
|
|||||||
private Map<Long, List<OmsCartItem>> groupCartItemBySpu(List<OmsCartItem> cartItemList) {
|
private Map<Long, List<OmsCartItem>> groupCartItemBySpu(List<OmsCartItem> cartItemList) {
|
||||||
Map<Long, List<OmsCartItem>> productCartMap = new TreeMap<>();
|
Map<Long, List<OmsCartItem>> productCartMap = new TreeMap<>();
|
||||||
for (OmsCartItem cartItem : cartItemList) {
|
for (OmsCartItem cartItem : cartItemList) {
|
||||||
List<OmsCartItem> productCartItemList = productCartMap.get(cartItem.getId());
|
List<OmsCartItem> productCartItemList = productCartMap.get(cartItem.getProductId());
|
||||||
if (productCartItemList == null) {
|
if (productCartItemList == null) {
|
||||||
productCartItemList = new ArrayList<>();
|
productCartItemList = new ArrayList<>();
|
||||||
productCartItemList.add(cartItem);
|
productCartItemList.add(cartItem);
|
||||||
@ -141,7 +144,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
|
|||||||
private void handleNoReduce(List<CartPromotionItem> cartPromotionItemList, List<OmsCartItem> itemList) {
|
private void handleNoReduce(List<CartPromotionItem> cartPromotionItemList, List<OmsCartItem> itemList) {
|
||||||
for (OmsCartItem item : itemList) {
|
for (OmsCartItem item : itemList) {
|
||||||
CartPromotionItem cartPromotionItem = new CartPromotionItem();
|
CartPromotionItem cartPromotionItem = new CartPromotionItem();
|
||||||
cartPromotionItem.setCartItem(item);
|
BeanUtils.copyProperties(item,cartPromotionItem);
|
||||||
cartPromotionItem.setPromotionMessage("无优惠");
|
cartPromotionItem.setPromotionMessage("无优惠");
|
||||||
cartPromotionItem.setReduceAmount(new BigDecimal(0));
|
cartPromotionItem.setReduceAmount(new BigDecimal(0));
|
||||||
cartPromotionItemList.add(cartPromotionItem);
|
cartPromotionItemList.add(cartPromotionItem);
|
||||||
@ -228,7 +231,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
|
|||||||
*/
|
*/
|
||||||
private BigDecimal getSinglePromotionPrice(PromotionProduct promotionProduct, Long productSkuId) {
|
private BigDecimal getSinglePromotionPrice(PromotionProduct promotionProduct, Long productSkuId) {
|
||||||
for (PmsSkuStock skuStock : promotionProduct.getSkuStockList()) {
|
for (PmsSkuStock skuStock : promotionProduct.getSkuStockList()) {
|
||||||
if (productSkuId == skuStock.getId()) {
|
if (productSkuId.equals(skuStock.getId()) ) {
|
||||||
return skuStock.getPromotionPrice();
|
return skuStock.getPromotionPrice();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user