Commit f852f9a9 by xiaoer.li

加料均摊

parent a4888c28
...@@ -134,7 +134,8 @@ public class ShoppingCartConvertAdapter { ...@@ -134,7 +134,8 @@ public class ShoppingCartConvertAdapter {
|| ObjectUtils.equals(ActivityTypeEnum.TYPE_62.getCode(), cartGoods.getActivityType())) { || ObjectUtils.equals(ActivityTypeEnum.TYPE_62.getCode(), cartGoods.getActivityType())) {
cartGoodsDetailDto.setTotalDiscountAmount(cartGoods.getOriginalAmount().intValue() - cartGoods.getAmount().intValue()); cartGoodsDetailDto.setTotalDiscountAmount(cartGoods.getOriginalAmount().intValue() - cartGoods.getAmount().intValue());
} else { } else {
List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> collect = apportionGoodsList.stream().filter(a -> ObjectUtils.equals(cartGoods.getSkuId(), a.getGoodsId()) || ObjectUtils.equals(cartGoods.getSpuId(), a.getGoodsId())).collect(Collectors.toList()); List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> collect = apportionGoodsList.stream().filter(a -> ObjectUtils.equals(cartGoods.getCartGoodsUid(), a.getCartGoodsUid())).collect(Collectors.toList());
//List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> collect = apportionGoodsList.stream().filter(a -> ObjectUtils.equals(cartGoods.getSkuId(), a.getGoodsId()) || ObjectUtils.equals(cartGoods.getSpuId(), a.getGoodsId())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(collect)) { if (CollectionUtils.isNotEmpty(collect)) {
setTotalDiscountAndSalePrice(collect, cartGoodsDetailDto, duplicateGoodsMap); setTotalDiscountAndSalePrice(collect, cartGoodsDetailDto, duplicateGoodsMap);
// 设置商品行,优惠活动均摊 // 设置商品行,优惠活动均摊
...@@ -172,6 +173,7 @@ public class ShoppingCartConvertAdapter { ...@@ -172,6 +173,7 @@ public class ShoppingCartConvertAdapter {
} }
/** /**
* 活动级别的促销均摊
* 获取当前商品的售后价格 * 获取当前商品的售后价格
* *
* @param apportionGoodsList 促销均摊列表 * @param apportionGoodsList 促销均摊列表
...@@ -187,19 +189,19 @@ public class ShoppingCartConvertAdapter { ...@@ -187,19 +189,19 @@ public class ShoppingCartConvertAdapter {
for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods apportionGoods : apportionGoodsList) { for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods apportionGoods : apportionGoodsList) {
//折扣=所有折扣和*百分比(当前行商品数量/购物车总商品数量) //折扣=所有折扣和*百分比(当前行商品数量/购物车总商品数量)
discountPrice += apportionGoods.getApportionDetails().stream().filter(d -> ObjectUtils.notEqual(ActivityTypeEnum.TYPE_32.getCode(), d.getActivityType()) discountPrice += apportionGoods.getApportionDetails().stream().filter(d -> ObjectUtils.notEqual(ActivityTypeEnum.TYPE_32.getCode(), d.getActivityType())
&& ObjectUtils.notEqual(ActivityTypeEnum.TYPE_104.getCode(), d.getActivityType()) && ObjectUtils.notEqual(ActivityTypeEnum.TYPE_104.getCode(), d.getActivityType()) //X件Y折
&& ObjectUtils.notEqual(ActivityTypeEnum.TYPE_2.getCode(), d.getActivityType()) && ObjectUtils.notEqual(ActivityTypeEnum.TYPE_2.getCode(), d.getActivityType()) //单品特价
&& ObjectUtils.notEqual(ActivityTypeEnum.TYPE_21.getCode(), d.getActivityType()) && ObjectUtils.notEqual(ActivityTypeEnum.TYPE_21.getCode(), d.getActivityType())//单品折扣
).mapToLong(t -> t.getActivityApportionAmount() * apportionGoods.getGoodsQuantity()).sum() * cartGoodsDetailDto.getQty() / goodsTotalQty; ).mapToLong(t -> t.getActivityApportionAmount() * apportionGoods.getGoodsQuantity()).sum() * cartGoodsDetailDto.getQty() / goodsTotalQty;
} }
String currentGoodsIdMap = duplicateGoodsMap.get(cartGoodsDetailDto.getSkuId()); String currentGoodsIdMap = duplicateGoodsMap.get(cartGoodsDetailDto.getCartGoodsUid());
if (currentGoodsIdMap != null) { if (currentGoodsIdMap != null) {
String[] value = currentGoodsIdMap.split(","); String[] value = currentGoodsIdMap.split(",");
//不是最后一行商品,折扣为discountPrice //不是最后一行商品,折扣为discountPrice
if (Integer.parseInt(value[0]) > 1) { if (Integer.parseInt(value[0]) > 1) {
int totalDiscountPrice = Integer.parseInt(value[1]) + discountPrice.intValue(); int totalDiscountPrice = Integer.parseInt(value[1]) + discountPrice.intValue();
int index = Integer.parseInt(value[0]) - 1; int index = Integer.parseInt(value[0]) - 1;
duplicateGoodsMap.put(cartGoodsDetailDto.getSkuId(), String.format("%s,%s", index, totalDiscountPrice)); duplicateGoodsMap.put(cartGoodsDetailDto.getCartGoodsUid(), String.format("%s,%s", index, totalDiscountPrice));
} else { } else {
//最后一行 //最后一行
Long totalDiscountAmount = 0L; Long totalDiscountAmount = 0L;
...@@ -443,4 +445,9 @@ public class ShoppingCartConvertAdapter { ...@@ -443,4 +445,9 @@ public class ShoppingCartConvertAdapter {
String skuId = StringUtils.isNotBlank(addShoppingCartGoodsRequestVo.getSkuId()) ? addShoppingCartGoodsRequestVo.getSkuId() : ""; String skuId = StringUtils.isNotBlank(addShoppingCartGoodsRequestVo.getSkuId()) ? addShoppingCartGoodsRequestVo.getSkuId() : "";
addShoppingCartGoodsRequestVo.setSkuId(skuId); addShoppingCartGoodsRequestVo.setSkuId(skuId);
} }
}
public String jointPk(String a, String b) {
StringBuffer stringBuffer = new StringBuffer();
return stringBuffer.append(a).append(b).toString();
}
}
\ No newline at end of file
...@@ -86,7 +86,7 @@ public class DefaultPromotionService implements IPromotionService { ...@@ -86,7 +86,7 @@ public class DefaultPromotionService implements IPromotionService {
calculationDiscountResult == null ? new ArrayList<>() : calculationDiscountResult.getApportionGoods(); calculationDiscountResult == null ? new ArrayList<>() : calculationDiscountResult.getApportionGoods();
Map<String, String> duplicateGoodsMap = new HashMap<>(); Map<String, String> duplicateGoodsMap = new HashMap<>();
cartGoodsList.stream().collect(Collectors.groupingBy(CartGoods::getGoodsId, Collectors.counting())).forEach((goodsId, count) -> { cartGoodsList.stream().collect(Collectors.groupingBy(CartGoods::getCartGoodsUid, Collectors.counting())).forEach((goodsId, count) -> {
duplicateGoodsMap.put(goodsId,String.format("%s,0", count)); duplicateGoodsMap.put(goodsId,String.format("%s,0", count));
}); });
for (int i = 0, len = cartGoodsList.size(); i < len; i++) { for (int i = 0, len = cartGoodsList.size(); i < len; i++) {
......
package cn.freemud.service.impl; package cn.freemud.service.impl;
import cn.freemud.adapter.ShoppingCartConvertAdapter;
import cn.freemud.entities.dto.ActivityCalculationDiscountResponseDto; import cn.freemud.entities.dto.ActivityCalculationDiscountResponseDto;
import cn.freemud.entities.dto.UserLoginInfoDto; import cn.freemud.entities.dto.UserLoginInfoDto;
import cn.freemud.entities.dto.activity.ActivityDiscountsDto; import cn.freemud.entities.dto.activity.ActivityDiscountsDto;
...@@ -10,6 +11,7 @@ import cn.freemud.enums.GoodsTypeEnum; ...@@ -10,6 +11,7 @@ import cn.freemud.enums.GoodsTypeEnum;
import cn.freemud.service.IPromotionService; import cn.freemud.service.IPromotionService;
import lombok.Data; import lombok.Data;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -28,7 +30,8 @@ import java.util.List; ...@@ -28,7 +30,8 @@ import java.util.List;
*/ */
@Service("MaterialPromotionService") @Service("MaterialPromotionService")
public class MaterialPromotionService implements IPromotionService { public class MaterialPromotionService implements IPromotionService {
@Autowired
private ShoppingCartConvertAdapter shoppingCartConvertAdapter;
/** /**
* 总优惠和总原价促进已经计算过了,这里只需要累积行记录 * 总优惠和总原价促进已经计算过了,这里只需要累积行记录
* 加料优惠金额 * 加料优惠金额
...@@ -96,7 +99,7 @@ public class MaterialPromotionService implements IPromotionService { ...@@ -96,7 +99,7 @@ public class MaterialPromotionService implements IPromotionService {
for (ShoppingCartGoodsDto.CartGoodsDetailDto product : products) { for (ShoppingCartGoodsDto.CartGoodsDetailDto product : products) {
if (CollectionUtils.isEmpty(product.getMaterialList())) continue; if (CollectionUtils.isEmpty(product.getMaterialList())) continue;
for (ShoppingCartGoodsDto.CartGoodsDetailDto.MaterialGoods materialGoods : product.getMaterialList()) { for (ShoppingCartGoodsDto.CartGoodsDetailDto.MaterialGoods materialGoods : product.getMaterialList()) {
pk = this.jointPk(product.getCartGoodsUid(), materialGoods.getSpuId()); pk = shoppingCartConvertAdapter.jointPk(product.getCartGoodsUid(), materialGoods.getSpuId());
MaterialApportion material = map.get(pk); MaterialApportion material = map.get(pk);
if (material != null && material.getApportionAmount().intValue() == 0) continue; if (material != null && material.getApportionAmount().intValue() == 0) continue;
//设置行记录参加的活动及总优惠 //设置行记录参加的活动及总优惠
...@@ -109,7 +112,8 @@ public class MaterialPromotionService implements IPromotionService { ...@@ -109,7 +112,8 @@ public class MaterialPromotionService implements IPromotionService {
activityDiscountsDtoList.add(activityDiscountsDto); activityDiscountsDtoList.add(activityDiscountsDto);
materialGoods.setActivityDiscountsDtos(activityDiscountsDtoList); materialGoods.setActivityDiscountsDtos(activityDiscountsDtoList);
materialGoods.setTotalDiscountAmount((materialGoods.getOriginalPrice().intValue() - materialGoods.getSalePrice().intValue()) * product.getQty()); //materialGoods.setTotalDiscountAmount((materialGoods.getOriginalPrice().intValue() - materialGoods.getSalePrice().intValue()) * product.getQty());
materialGoods.setTotalDiscountAmount(material.getTotalDiscountAmount());
product.setProductType(GoodsTypeEnum.MATERIAL.getGoodsType()); product.setProductType(GoodsTypeEnum.MATERIAL.getGoodsType());
} }
} }
...@@ -144,13 +148,14 @@ public class MaterialPromotionService implements IPromotionService { ...@@ -144,13 +148,14 @@ public class MaterialPromotionService implements IPromotionService {
for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods.Material material : apportionGood.getSmallMaterial()) { for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods.Material material : apportionGood.getSmallMaterial()) {
if (material.getApportionAmount() == 0) continue; if (material.getApportionAmount() == 0) continue;
pk = this.jointPk(material.getCartGoodsUid(), material.getGoodsId()); pk = shoppingCartConvertAdapter.jointPk(material.getCartGoodsUid(), material.getGoodsId());
if (mApportion.get(pk) == null) { if (mApportion.get(pk) == null) {
MaterialApportion materialApportion = new MaterialApportion(); MaterialApportion materialApportion = new MaterialApportion();
materialApportion.setSalePrice(material.getNowPrice()); materialApportion.setSalePrice(material.getNowPrice());
materialApportion.setAmount(material.getNowPrice() * material.getGoodsQuantity()); materialApportion.setAmount(material.getNowPrice() * material.getGoodsQuantity());
materialApportion.setApportionAmount(material.getApportionAmount() * material.getGoodsQuantity()); materialApportion.setApportionAmount(material.getApportionAmount() * material.getGoodsQuantity());
materialApportion.setGoodsId(material.getGoodsId()); materialApportion.setGoodsId(material.getGoodsId());
materialApportion.setTotalDiscountAmount(material.getApportionAmount()*material.getGoodsQuantity());
materialApportion.setPk(pk); materialApportion.setPk(pk);
ApportionDetails apportionDetails = new ApportionDetails(); ApportionDetails apportionDetails = new ApportionDetails();
if (CollectionUtils.isNotEmpty(material.getApportionDetails())) { if (CollectionUtils.isNotEmpty(material.getApportionDetails())) {
...@@ -166,23 +171,21 @@ public class MaterialPromotionService implements IPromotionService { ...@@ -166,23 +171,21 @@ public class MaterialPromotionService implements IPromotionService {
apportion.setSalePrice(apportion.getSalePrice() + material.getNowPrice()); apportion.setSalePrice(apportion.getSalePrice() + material.getNowPrice());
apportion.setAmount(apportion.getAmount() + material.getNowPrice() * material.getGoodsQuantity()); apportion.setAmount(apportion.getAmount() + material.getNowPrice() * material.getGoodsQuantity());
apportion.setApportionAmount(apportion.getApportionAmount() + material.getApportionAmount() * material.getGoodsQuantity()); apportion.setApportionAmount(apportion.getApportionAmount() + material.getApportionAmount() * material.getGoodsQuantity());
apportion.setTotalDiscountAmount(apportion.getTotalDiscountAmount()+material.getApportionAmount()*material.getGoodsQuantity());
mApportion.put(pk, apportion); mApportion.put(pk, apportion);
} }
} }
return mApportion; return mApportion;
} }
private String jointPk(String a, String b) {
StringBuffer stringBuffer = new StringBuffer();
return stringBuffer.append(a).append(b).toString();
}
@Data @Data
private class MaterialApportion { private class MaterialApportion {
private String goodsId; private String goodsId;
private Long salePrice; private Long salePrice;
private Long amount; private Long amount;
private Integer apportionAmount; private Integer apportionAmount;
//优惠金额
private Integer totalDiscountAmount;
private ApportionDetails details; private ApportionDetails details;
private String pk; private String pk;
} }
......
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