Commit 363a6997 by shuhu.hou@freemud.cn

Merge branch 'feature/20200513_添加购物车校验库存'

parents d5be5561 ad39b11e
...@@ -9,7 +9,11 @@ import cn.freemud.entities.dto.activity.ShareDiscountActivityDto; ...@@ -9,7 +9,11 @@ import cn.freemud.entities.dto.activity.ShareDiscountActivityDto;
import cn.freemud.entities.dto.shoppingCart.ShoppingCartGoodsDto; import cn.freemud.entities.dto.shoppingCart.ShoppingCartGoodsDto;
import cn.freemud.entities.vo.*; import cn.freemud.entities.vo.*;
import cn.freemud.enums.ActivityTypeEnum; import cn.freemud.enums.ActivityTypeEnum;
import cn.freemud.enums.ResponseResult;
import cn.freemud.interceptor.ServiceException;
import cn.freemud.service.IPromotionService; import cn.freemud.service.IPromotionService;
import com.freemud.application.sdk.api.productcenter.domain.ProductBeanDTO;
import com.freemud.sdk.api.assortment.shoppingcart.service.impl.ShoppingCartBaseServiceImpl;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.ObjectUtils;
...@@ -41,6 +45,10 @@ public class BuySendPromotionService implements IPromotionService { ...@@ -41,6 +45,10 @@ public class BuySendPromotionService implements IPromotionService {
@Autowired @Autowired
ShoppingCartConvertAdapter shoppingCartConvertAdapter; ShoppingCartConvertAdapter shoppingCartConvertAdapter;
@Autowired
private AssortmentSdkService assortmentSdkService;
@Autowired
private ShoppingCartBaseServiceImpl shoppingCartBaseService;
@Override @Override
public void updateShoppingCartGoodsDiscount(CouponPromotionVO couponPromotionVO, ActivityQueryDto activityQueryDto, ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult, List<CartGoods> cartGoodsList, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo, UserLoginInfoDto userLoginInfoDto, ShoppingCartInfoRequestVo shoppingCartInfoRequestVo) { public void updateShoppingCartGoodsDiscount(CouponPromotionVO couponPromotionVO, ActivityQueryDto activityQueryDto, ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult, List<CartGoods> cartGoodsList, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo, UserLoginInfoDto userLoginInfoDto, ShoppingCartInfoRequestVo shoppingCartInfoRequestVo) {
...@@ -76,6 +84,8 @@ public class BuySendPromotionService implements IPromotionService { ...@@ -76,6 +84,8 @@ public class BuySendPromotionService implements IPromotionService {
putNewCartGoodsList(sendGoodsMap, cartGood, newCartGoodsList, false); putNewCartGoodsList(sendGoodsMap, cartGood, newCartGoodsList, false);
} }
} }
//更新商品详情信息
updateSendGooodsInfo(newCartGoodsList,activityQueryDto,shoppingCartInfoRequestVo);
//价格从低到高筛选出maxNum个,并将价格设置为0 //价格从低到高筛选出maxNum个,并将价格设置为0
newCartGoodsList.sort(Comparator.comparing(CartGoods::getOriginalPrice)); newCartGoodsList.sort(Comparator.comparing(CartGoods::getOriginalPrice));
// 优惠商品总包装费 // 优惠商品总包装费
...@@ -215,4 +225,28 @@ public class BuySendPromotionService implements IPromotionService { ...@@ -215,4 +225,28 @@ public class BuySendPromotionService implements IPromotionService {
newCartGoodsList.add(cartGoods); newCartGoodsList.add(cartGoods);
} }
/**
* 更新赠品信息
* 例如:weight、unit字段
* @param newCartGoodsList
*/
private void updateSendGooodsInfo(List<CartGoods> newCartGoodsList,ActivityQueryDto activityQueryDto,ShoppingCartInfoRequestVo shoppingCartInfoRequestVo){
List<String> goodsIds = newCartGoodsList.stream().map(CartGoods::getGoodsId).collect(Collectors.toList());
List<ProductBeanDTO> productBeanList = assortmentSdkService.getProductsInfoSdk(activityQueryDto.getPartnerId()
, activityQueryDto.getStoreId(), goodsIds, shoppingCartInfoRequestVo==null?null:shoppingCartInfoRequestVo.getMenuType() ,shoppingCartBaseService);
if (CollectionUtils.isEmpty(productBeanList)) {
throw new ServiceException(ResponseResult.SHOPPING_CART_GIFTS_PRODUCT_NOT_EXIST);
}
for (CartGoods cartGoods :newCartGoodsList) {
Optional<ProductBeanDTO> productBeanDTO = productBeanList.stream().filter(productBean -> ObjectUtils.equals(productBean.getPid(), cartGoods.getGoodsId())).findFirst();
if (!productBeanDTO.isPresent()) {
continue;
}
cartGoods.setUnit(productBeanDTO.get().getUnit());
cartGoods.setWeight(productBeanDTO.get().getWeight());
}
}
} }
...@@ -1197,6 +1197,8 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -1197,6 +1197,8 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
cartGoods.setAmount(0L); cartGoods.setAmount(0L);
cartGoods.setPackPrice(productBeanListSpuClass.get(0).getPackPrice()); cartGoods.setPackPrice(productBeanListSpuClass.get(0).getPackPrice());
cartGoods.setPic(productBeanListSpuClass.get(0).getPicture()); cartGoods.setPic(productBeanListSpuClass.get(0).getPicture());
cartGoods.setWeight(productBeanListSpuClass.get(0).getWeight());
cartGoods.setUnit(productBeanListSpuClass.get(0).getUnit());
List<String> goodsIds = allCartGoodsList.parallelStream().map(CartGoods::getGoodsId).collect(Collectors.toList()); List<String> goodsIds = allCartGoodsList.parallelStream().map(CartGoods::getGoodsId).collect(Collectors.toList());
boolean hasSpecialGoods = hasSpecialGoods(addShoppingCartGoodsRequestVo.getPartnerId(), addShoppingCartGoodsRequestVo.getShopId(), userId, addShoppingCartGoodsRequestVo.getAppId(), goodsIds, addShoppingCartGoodsRequestVo.getOrderType()); boolean hasSpecialGoods = hasSpecialGoods(addShoppingCartGoodsRequestVo.getPartnerId(), addShoppingCartGoodsRequestVo.getShopId(), userId, addShoppingCartGoodsRequestVo.getAppId(), goodsIds, addShoppingCartGoodsRequestVo.getOrderType());
...@@ -1241,7 +1243,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -1241,7 +1243,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
} }
if (availableStocks != null && ResponseCodeConstant.RESPONSE_SUCCESS_STR.equals(availableStocks.getCode()) && if (availableStocks != null && ResponseCodeConstant.RESPONSE_SUCCESS_STR.equals(availableStocks.getCode()) &&
(CollectionUtils.isEmpty(availableStocks.getResult()) || availableStocks.getResult().get(0).getQty() == null (CollectionUtils.isEmpty(availableStocks.getResult()) || availableStocks.getResult().get(0).getQty() == null
|| availableStocks.getResult().get(0).getQty() <= qty)) { || availableStocks.getResult().get(0).getQty() < qty)) {
throw new ServiceException(ResponseResult.SHOPPING_CART_STOCK_NOT_HAVE); throw new ServiceException(ResponseResult.SHOPPING_CART_STOCK_NOT_HAVE);
} }
} }
......
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