Search in sources :

Example 1 with OmcCart

use of com.paascloud.provider.model.domain.OmcCart in project paascloud-master by paascloud.

the class OmcCartServiceImpl method updateCart.

@Override
public int updateCart(Long userId, Long productId, int count) {
    logger.info("updateCart - 更新货品数量 userId={}, productId={}, count={}", userId, productId, count);
    Preconditions.checkArgument(userId != null, ErrorCodeEnum.UAC10011001.msg());
    Preconditions.checkArgument(productId != null, ErrorCodeEnum.MDC10021021.msg());
    int resultInt;
    OmcCart cart = this.getCartByUserIdAndProductId(userId, productId);
    if (cart == null) {
        logger.error("找不到商品信息, userId={}, productId={}", userId, productId);
        throw new MdcBizException(ErrorCodeEnum.MDC10021004, productId);
    }
    if (count == 0) {
        List<String> productList = Lists.newArrayList();
        productList.add(productId.toString());
        resultInt = omcCartMapper.deleteByUserIdProductIds(userId, productList);
    } else {
        cart.setQuantity(count);
        resultInt = omcCartMapper.updateByPrimaryKeySelective(cart);
    }
    return resultInt;
}
Also used : MdcBizException(com.paascloud.provider.exceptions.MdcBizException) OmcCart(com.paascloud.provider.model.domain.OmcCart)

Example 2 with OmcCart

use of com.paascloud.provider.model.domain.OmcCart in project paascloud-master by paascloud.

the class OmcCartServiceImpl method saveCart.

@Override
public int saveCart(Long userId, Long productId, int count) {
    logger.info("saveCart - 保存购物车记录 userId={}, productId={}, count={}", userId, productId, count);
    Preconditions.checkArgument(userId != null, ErrorCodeEnum.UAC10011001.msg());
    Preconditions.checkArgument(productId != null, ErrorCodeEnum.MDC10021021.msg());
    Preconditions.checkArgument(count != 0, "数量不符");
    int resultInt = 0;
    OmcCart cart = this.getCartByUserIdAndProductId(userId, productId);
    if (cart == null) {
        cart = new OmcCart();
        cart.setQuantity(count);
        cart.setChecked(OmcApiConstant.Cart.CHECKED);
        cart.setProductId(productId);
        cart.setUserId(userId);
        resultInt = omcCartMapper.insertSelective(cart);
    } else {
        count = cart.getQuantity() == null ? 0 : cart.getQuantity() + count;
        cart.setQuantity(count);
        omcCartMapper.updateByPrimaryKeySelective(cart);
    }
    return resultInt;
}
Also used : OmcCart(com.paascloud.provider.model.domain.OmcCart)

Example 3 with OmcCart

use of com.paascloud.provider.model.domain.OmcCart 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)

Example 4 with OmcCart

use of com.paascloud.provider.model.domain.OmcCart in project paascloud-master by paascloud.

the class OmcOrderServiceImpl method createOrderDoc.

@Override
@Transactional(rollbackFor = Exception.class)
public OrderVo createOrderDoc(LoginAuthDto loginAuthDto, Long shippingId) {
    Long userId = loginAuthDto.getUserId();
    // 从购物车中获取数据
    List<OmcCart> cartList = omcCartMapper.selectCheckedCartByUserId(userId);
    if (CollectionUtils.isEmpty(cartList)) {
        throw new OmcBizException(ErrorCodeEnum.OMC10031001, userId);
    }
    // 计算这个订单的总价
    List<OmcOrderDetail> omcOrderDetailList = omcCartService.getCartOrderItem(userId, cartList);
    if (CollectionUtils.isEmpty(omcOrderDetailList)) {
        throw new OmcBizException(ErrorCodeEnum.OMC10031001, userId);
    }
    BigDecimal payment = this.getOrderTotalPrice(omcOrderDetailList);
    // 生成订单
    OmcOrder order = this.assembleOrder(userId, shippingId, payment);
    if (order == null) {
        logger.error("生成订单失败, userId={}, shippingId={}, payment={}", userId, shippingId, payment);
        throw new OmcBizException(ErrorCodeEnum.OMC10031002);
    }
    order.setUpdateInfo(loginAuthDto);
    for (OmcOrderDetail orderDetail : omcOrderDetailList) {
        orderDetail.setUpdateInfo(loginAuthDto);
        orderDetail.setOrderNo(order.getOrderNo());
        orderDetail.setId(super.generateId());
        orderDetail.setUpdateInfo(loginAuthDto);
    }
    // mybatis 批量插入
    omcOrderDetailService.batchInsertOrderDetail(omcOrderDetailList);
    // 生成成功,我们要减少我们产品的库存
    this.reduceProductStock(omcOrderDetailList);
    // 清空一下购物车
    this.cleanCart(cartList);
    return assembleOrderVo(order, omcOrderDetailList);
}
Also used : OmcOrderDetail(com.paascloud.provider.model.domain.OmcOrderDetail) OmcCart(com.paascloud.provider.model.domain.OmcCart) OmcBizException(com.paascloud.provider.exceptions.OmcBizException) OmcOrder(com.paascloud.provider.model.domain.OmcOrder) BigDecimal(java.math.BigDecimal) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with OmcCart

use of com.paascloud.provider.model.domain.OmcCart in project paascloud-master by paascloud.

the class OmcOrderServiceImpl method cleanCart.

private void cleanCart(List<OmcCart> cartList) {
    List<Long> idList = Lists.newArrayList();
    for (OmcCart cart : cartList) {
        idList.add(cart.getId());
    }
    int deleteCount = omcCartMapper.batchDeleteCart(idList);
    if (deleteCount < idList.size()) {
        throw new OmcBizException(ErrorCodeEnum.OMC10031006);
    }
}
Also used : OmcCart(com.paascloud.provider.model.domain.OmcCart) OmcBizException(com.paascloud.provider.exceptions.OmcBizException)

Aggregations

OmcCart (com.paascloud.provider.model.domain.OmcCart)10 MdcBizException (com.paascloud.provider.exceptions.MdcBizException)4 OmcBizException (com.paascloud.provider.exceptions.OmcBizException)4 OmcOrderDetail (com.paascloud.provider.model.domain.OmcOrderDetail)3 ProductDto (com.paascloud.provider.model.dto.ProductDto)3 BigDecimal (java.math.BigDecimal)3 CartProductVo (com.paascloud.provider.model.vo.CartProductVo)2 LoginAuthDto (com.paascloud.base.dto.LoginAuthDto)1 OmcOrder (com.paascloud.provider.model.domain.OmcOrder)1 OptGetUrlRequest (com.paascloud.provider.model.dto.oss.OptGetUrlRequest)1 CartVo (com.paascloud.provider.model.vo.CartVo)1 OrderItemVo (com.paascloud.provider.model.vo.OrderItemVo)1 OrderProductVo (com.paascloud.provider.model.vo.OrderProductVo)1 Transactional (org.springframework.transaction.annotation.Transactional)1