Search in sources :

Example 1 with CartItemVO

use of com.whoiszxl.entity.vo.CartItemVO in project shopzz by whoiszxl.

the class OrderServiceImpl method buildOrderItems.

/**
 * 创建订单详情条目列表
 * @param orderId
 * @return
 */
private List<OrderItem> buildOrderItems(long orderId) {
    // 获取当前选中的购物车item列表
    CartDetailVO cartDetail = cartService.getCartDetail();
    List<CartItemVO> cartItemVOList = cartDetail.getCartItemVOList();
    if (ObjectUtils.isEmpty(cartItemVOList)) {
        ExceptionCatcher.catchValidateEx(ResponseResult.buildError("购物车不存在选中商品"));
    }
    List<OrderItem> result = new ArrayList<>();
    for (CartItemVO item : cartItemVOList) {
        if (item.getChecked() == 1) {
            OrderItem orderItem = buildOrderItem(item);
            orderItem.setOrderId(orderId);
            orderItem.setOrderSn(orderId + "");
            result.add(orderItem);
        }
    }
    return result;
}
Also used : CartDetailVO(com.whoiszxl.entity.vo.CartDetailVO) OrderItem(com.whoiszxl.entity.OrderItem) ArrayList(java.util.ArrayList) CartItemVO(com.whoiszxl.entity.vo.CartItemVO)

Example 2 with CartItemVO

use of com.whoiszxl.entity.vo.CartItemVO in project shopzz by whoiszxl.

the class CartServiceImpl method cartAdd.

@Override
public Boolean cartAdd(SaveCartRequest addCartQuery) {
    // 0. 对sku进行有效性校验
    ResponseResult<SkuDTO> skuInfoResponse = productFeignClient.getSkuInfoBySkuId(addCartQuery.getSkuId());
    SkuDTO sku = skuInfoResponse.getData();
    if (sku == null || sku.getIsDeleted() == 1) {
        ExceptionCatcher.catchValidateEx(ResponseResult.buildError("商品无效"));
    }
    // 1. 判断redis中是否存在当前的购物车信息
    BoundHashOperations<String, Object, Object> cartHashOps = redisUtils.getHashOps(RedisKeyPrefixConstants.MEMBER_CART_PREFIX + StpUtil.getLoginIdAsString());
    String cartItemJson = (String) cartHashOps.get(addCartQuery.getSkuId().toString());
    if (StringUtils.isBlank(cartItemJson)) {
        CartItemVO cartItemVO = new CartItemVO();
        cartItemVO.setChecked(StatusEnum.OPEN.getCode());
        cartItemVO.setQuantity(addCartQuery.getQuantity());
        cartItemVO.setSkuPic(sku.getImgUrl());
        cartItemVO.setPrice(sku.getPromotionPrice() == null ? sku.getSalePrice() : sku.getPromotionPrice());
        cartItemVO.setSkuId(sku.getId());
        cartItemVO.setSkuName(sku.getSkuName());
        cartItemVO.setProductId(sku.getProductId());
        String jsonValue = JsonUtil.toJson(cartItemVO);
        cartHashOps.put(addCartQuery.getSkuId().toString(), jsonValue);
    } else {
        // 在原有购物车商品里累加
        CartItemVO cartItemVO = JsonUtil.fromJson(cartItemJson, CartItemVO.class);
        cartItemVO.setQuantity(cartItemVO.getQuantity() + addCartQuery.getQuantity());
        cartItemVO.setSkuPic(sku.getImgUrl());
        cartItemVO.setPrice(sku.getPromotionPrice() == null ? sku.getSalePrice() : sku.getPromotionPrice());
        cartItemVO.setSkuName(sku.getSkuName());
        cartItemVO.setProductId(sku.getProductId());
        String jsonValue = JsonUtil.toJson(cartItemVO);
        cartHashOps.put(addCartQuery.getSkuId().toString(), jsonValue);
    }
    // TODO 发送MQ,落库
    return true;
}
Also used : SkuDTO(com.whoiszxl.dto.SkuDTO) CartItemVO(com.whoiszxl.entity.vo.CartItemVO)

Aggregations

CartItemVO (com.whoiszxl.entity.vo.CartItemVO)2 SkuDTO (com.whoiszxl.dto.SkuDTO)1 OrderItem (com.whoiszxl.entity.OrderItem)1 CartDetailVO (com.whoiszxl.entity.vo.CartDetailVO)1 ArrayList (java.util.ArrayList)1