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;
}
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;
}
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;
}
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);
}
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);
}
}
Aggregations