use of com.paascloud.provider.model.vo.CartVo in project paascloud-master by paascloud.
the class MallCartQueryFeignClient method getCartVo.
@Override
@ApiOperation(httpMethod = "POST", value = "获取购物车信息")
public Wrapper<CartVo> getCartVo(@RequestParam("userId") Long userId) {
logger.info("getCartVo - 获取购物车信息. userId={}", userId);
CartVo cartVo = omcCartService.getCarVo(userId);
return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, cartVo);
}
use of com.paascloud.provider.model.vo.CartVo in project paascloud-master by paascloud.
the class OmcCartServiceImpl method getCarVo.
@Override
public CartVo getCarVo(Long userId) {
logger.info("getCarVo - 获取购物车列表 -- userId={}", userId);
CartVo cartVo = new CartVo();
List<OmcCart> cartList = this.selectCartListByUserId(userId);
List<CartProductVo> cartProductVoList = Lists.newArrayList();
BigDecimal cartTotalPrice = new BigDecimal("0");
if (PublicUtil.isNotEmpty(cartList)) {
for (OmcCart cartItem : cartList) {
CartProductVo cartProductVo = new CartProductVo();
cartProductVo.setId(cartItem.getId());
cartProductVo.setUserId(userId);
cartProductVo.setProductId(cartItem.getProductId());
ProductDto product = mdcProductService.selectById(cartItem.getProductId());
if (product == null) {
throw new MdcBizException(ErrorCodeEnum.MDC10021004, cartItem.getProductId());
}
cartProductVo.setProductMainImage(product.getMainImage());
cartProductVo.setProductName(product.getName());
cartProductVo.setProductSubtitle(product.getSubtitle());
cartProductVo.setProductStatus(product.getStatus());
cartProductVo.setProductPrice(product.getPrice());
cartProductVo.setProductStock(product.getStock());
// 判断库存
int buyLimitCount;
if (product.getStock() >= cartItem.getQuantity()) {
// 库存充足的时候
buyLimitCount = cartItem.getQuantity();
cartProductVo.setLimitQuantity(OmcApiConstant.Cart.LIMIT_NUM_SUCCESS);
} else {
buyLimitCount = product.getStock();
cartProductVo.setLimitQuantity(OmcApiConstant.Cart.LIMIT_NUM_FAIL);
// 购物车中更新有效库存
OmcCart cartForQuantity = new OmcCart();
cartForQuantity.setId(cartItem.getId());
cartForQuantity.setQuantity(buyLimitCount);
omcCartMapper.updateByPrimaryKeySelective(cartForQuantity);
}
cartProductVo.setQuantity(buyLimitCount);
// 计算总价
cartProductVo.setProductTotalPrice(BigDecimalUtil.mul(product.getPrice().doubleValue(), cartProductVo.getQuantity()));
cartProductVo.setChecked(cartItem.getChecked());
if (cartItem.getChecked() == OmcApiConstant.Cart.CHECKED) {
// 如果已经勾选,增加到整个的购物车总价中
cartTotalPrice = BigDecimalUtil.add(cartTotalPrice.doubleValue(), cartProductVo.getProductTotalPrice().doubleValue());
}
cartProductVoList.add(cartProductVo);
}
}
cartVo.setCartTotalPrice(cartTotalPrice);
cartVo.setCartProductVoList(cartProductVoList);
cartVo.setAllChecked(this.getAllCheckedStatus(userId));
return cartVo;
}
Aggregations