Search in sources :

Example 1 with CartVo

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);
}
Also used : CartVo(com.paascloud.provider.model.vo.CartVo) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with 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;
}
Also used : CartProductVo(com.paascloud.provider.model.vo.CartProductVo) MdcBizException(com.paascloud.provider.exceptions.MdcBizException) CartVo(com.paascloud.provider.model.vo.CartVo) OmcCart(com.paascloud.provider.model.domain.OmcCart) BigDecimal(java.math.BigDecimal) ProductDto(com.paascloud.provider.model.dto.ProductDto)

Aggregations

CartVo (com.paascloud.provider.model.vo.CartVo)2 MdcBizException (com.paascloud.provider.exceptions.MdcBizException)1 OmcCart (com.paascloud.provider.model.domain.OmcCart)1 ProductDto (com.paascloud.provider.model.dto.ProductDto)1 CartProductVo (com.paascloud.provider.model.vo.CartProductVo)1 ApiOperation (io.swagger.annotations.ApiOperation)1 BigDecimal (java.math.BigDecimal)1