use of com.paascloud.provider.model.vo.CartProductVo 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;
}
use of com.paascloud.provider.model.vo.CartProductVo in project paascloud-master by paascloud.
the class OmcCartServiceImpl method updateCartList.
@Override
public int updateCartList(List<CartProductVo> cartProductVoList) {
logger.info("updateCartList - 更新购物车集合 cartProductVoList={}", cartProductVoList);
LoginAuthDto loginUser = new LoginAuthDto();
loginUser.setLoginName(GlobalConstant.Sys.SUPER_MANAGER_LOGIN_NAME);
loginUser.setUserId(1L);
for (CartProductVo cartProductVo : cartProductVoList) {
Integer quantity = cartProductVo.getQuantity();
Integer productChecked = cartProductVo.getChecked();
Long productId = cartProductVo.getProductId();
ProductDto productDto = mdcProductService.selectById(productId);
if (PublicUtil.isEmpty(productDto)) {
throw new MdcBizException(ErrorCodeEnum.MDC10021004, productId);
}
OmcCart omcCart = new OmcCart();
omcCart.setUserId(loginUser.getUserId());
omcCart.setQuantity(quantity);
omcCart.setChecked(productChecked);
omcCart.setProductId(productId);
omcCart.setQuantity(quantity);
this.saveCart(omcCart, loginUser);
}
return 1;
}
use of com.paascloud.provider.model.vo.CartProductVo in project paascloud-master by paascloud.
the class MallCartController method mergeUserCart.
/**
* 登录成功合并购物车.
*
* @param cartListQuery the cart list query
*
* @return the wrapper
*/
@PostMapping(value = "mergeUserCart")
@ApiOperation(httpMethod = "POST", value = "登录成功合并购物车")
public Wrapper<CartVo> mergeUserCart(@RequestBody CartListQuery cartListQuery) {
List<CartProductVo> cartProductVoList = cartListQuery.getCartProductVoList();
LoginAuthDto loginAuthDto = getLoginAuthDto();
// 1.更新购物车数据
if (PublicUtil.isNotEmpty(cartProductVoList)) {
for (CartProductVo cartProductVo : cartProductVoList) {
cartProductVo.setUserId(loginAuthDto.getUserId());
}
mallCartFeignApi.updateCartList(cartProductVoList);
}
return mallCartQueryFeignApi.getCartVo(loginAuthDto.getUserId());
}
Aggregations