Search in sources :

Example 6 with CartProduct

use of cn.exrick.manager.dto.front.CartProduct in project xmall by Exrick.

the class DtoUtil method TbItem2CartProduct.

public static CartProduct TbItem2CartProduct(TbItem tbItem) {
    CartProduct cartProduct = new CartProduct();
    cartProduct.setProductId(tbItem.getId());
    cartProduct.setProductName(tbItem.getTitle());
    cartProduct.setSalePrice(tbItem.getPrice());
    cartProduct.setProductImg(tbItem.getImages()[0]);
    if (tbItem.getLimitNum() == null) {
        cartProduct.setLimitNum(Long.valueOf(tbItem.getNum()));
    } else if (tbItem.getLimitNum() < 0 && tbItem.getNum() < 0) {
        cartProduct.setLimitNum((long) 10);
    } else {
        cartProduct.setLimitNum(Long.valueOf(tbItem.getLimitNum()));
    }
    return cartProduct;
}
Also used : CartProduct(cn.exrick.manager.dto.front.CartProduct)

Example 7 with CartProduct

use of cn.exrick.manager.dto.front.CartProduct in project xmall by Exrick.

the class DtoUtil method TbOrderItem2CartProduct.

public static CartProduct TbOrderItem2CartProduct(TbOrderItem tbOrderItem) {
    CartProduct cartProduct = new CartProduct();
    cartProduct.setProductId(Long.valueOf(tbOrderItem.getItemId()));
    cartProduct.setProductName(tbOrderItem.getTitle());
    cartProduct.setSalePrice(tbOrderItem.getPrice());
    cartProduct.setProductNum(Long.valueOf(tbOrderItem.getNum()));
    cartProduct.setProductImg(tbOrderItem.getPicPath());
    return cartProduct;
}
Also used : CartProduct(cn.exrick.manager.dto.front.CartProduct)

Example 8 with CartProduct

use of cn.exrick.manager.dto.front.CartProduct in project xmall by Exrick.

the class OrderServiceImpl method getOrderList.

@Override
public PageOrder getOrderList(Long userId, int page, int size) {
    // 分页
    if (page <= 0) {
        page = 1;
    }
    PageHelper.startPage(page, size);
    PageOrder pageOrder = new PageOrder();
    List<Order> list = new ArrayList<>();
    TbOrderExample example = new TbOrderExample();
    TbOrderExample.Criteria criteria = example.createCriteria();
    criteria.andUserIdEqualTo(userId);
    example.setOrderByClause("create_time DESC");
    List<TbOrder> listOrder = tbOrderMapper.selectByExample(example);
    for (TbOrder tbOrder : listOrder) {
        judgeOrder(tbOrder);
        Order order = new Order();
        // orderId
        order.setOrderId(Long.valueOf(tbOrder.getOrderId()));
        // orderStatus
        order.setOrderStatus(String.valueOf(tbOrder.getStatus()));
        // createDate
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String date = formatter.format(tbOrder.getCreateTime());
        order.setCreateDate(date);
        // address
        TbOrderShipping tbOrderShipping = tbOrderShippingMapper.selectByPrimaryKey(tbOrder.getOrderId());
        TbAddress address = new TbAddress();
        address.setUserName(tbOrderShipping.getReceiverName());
        address.setStreetName(tbOrderShipping.getReceiverAddress());
        address.setTel(tbOrderShipping.getReceiverPhone());
        order.setAddressInfo(address);
        // orderTotal
        if (tbOrder.getPayment() == null) {
            order.setOrderTotal(new BigDecimal(0));
        } else {
            order.setOrderTotal(tbOrder.getPayment());
        }
        // goodsList
        TbOrderItemExample exampleItem = new TbOrderItemExample();
        TbOrderItemExample.Criteria criteriaItem = exampleItem.createCriteria();
        criteriaItem.andOrderIdEqualTo(tbOrder.getOrderId());
        List<TbOrderItem> listItem = tbOrderItemMapper.selectByExample(exampleItem);
        List<CartProduct> listProduct = new ArrayList<>();
        for (TbOrderItem tbOrderItem : listItem) {
            CartProduct cartProduct = DtoUtil.TbOrderItem2CartProduct(tbOrderItem);
            listProduct.add(cartProduct);
        }
        order.setGoodsList(listProduct);
        list.add(order);
    }
    PageInfo<Order> pageInfo = new PageInfo<>(list);
    pageOrder.setTotal(getMemberOrderCount(userId));
    pageOrder.setData(list);
    return pageOrder;
}
Also used : Order(cn.exrick.manager.dto.front.Order) PageOrder(cn.exrick.manager.dto.front.PageOrder) PageOrder(cn.exrick.manager.dto.front.PageOrder) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) PageInfo(com.github.pagehelper.PageInfo) CartProduct(cn.exrick.manager.dto.front.CartProduct) SimpleDateFormat(java.text.SimpleDateFormat)

Example 9 with CartProduct

use of cn.exrick.manager.dto.front.CartProduct in project xmall by Exrick.

the class OrderServiceImpl method createOrder.

@Override
public Long createOrder(OrderInfo orderInfo) {
    TbMember member = tbMemberMapper.selectByPrimaryKey(Long.valueOf(orderInfo.getUserId()));
    if (member == null) {
        throw new XmallException("获取下单用户失败");
    }
    TbOrder order = new TbOrder();
    // 生成订单ID
    Long orderId = IDUtil.getRandomId();
    order.setOrderId(String.valueOf(orderId));
    order.setUserId(Long.valueOf(orderInfo.getUserId()));
    order.setBuyerNick(member.getUsername());
    order.setPayment(orderInfo.getOrderTotal());
    order.setCreateTime(new Date());
    order.setUpdateTime(new Date());
    // 0、未付款,1、已付款,2、未发货,3、已发货,4、交易成功,5、交易关闭
    order.setStatus(0);
    if (tbOrderMapper.insert(order) != 1) {
        throw new XmallException("生成订单失败");
    }
    List<CartProduct> list = orderInfo.getGoodsList();
    for (CartProduct cartProduct : list) {
        TbOrderItem orderItem = new TbOrderItem();
        // 生成订单商品ID
        Long orderItemId = IDUtil.getRandomId();
        orderItem.setId(String.valueOf(orderItemId));
        orderItem.setItemId(String.valueOf(cartProduct.getProductId()));
        orderItem.setOrderId(String.valueOf(orderId));
        orderItem.setNum(Math.toIntExact(cartProduct.getProductNum()));
        orderItem.setPrice(cartProduct.getSalePrice());
        orderItem.setTitle(cartProduct.getProductName());
        orderItem.setPicPath(cartProduct.getProductImg());
        orderItem.setTotalFee(cartProduct.getSalePrice().multiply(BigDecimal.valueOf(cartProduct.getProductNum())));
        if (tbOrderItemMapper.insert(orderItem) != 1) {
            throw new XmallException("生成订单商品失败");
        }
        // 删除购物车中含该订单的商品
        try {
            List<String> jsonList = jedisClient.hvals(CART_PRE + ":" + orderInfo.getUserId());
            for (String json : jsonList) {
                CartProduct cart = new Gson().fromJson(json, CartProduct.class);
                if (cart.getProductId().equals(cartProduct.getProductId())) {
                    jedisClient.hdel(CART_PRE + ":" + orderInfo.getUserId(), cart.getProductId() + "");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // 物流表
    TbOrderShipping orderShipping = new TbOrderShipping();
    orderShipping.setOrderId(String.valueOf(orderId));
    orderShipping.setReceiverName(orderInfo.getUserName());
    orderShipping.setReceiverAddress(orderInfo.getStreetName());
    orderShipping.setReceiverPhone(orderInfo.getTel());
    orderShipping.setCreated(new Date());
    orderShipping.setUpdated(new Date());
    if (tbOrderShippingMapper.insert(orderShipping) != 1) {
        throw new XmallException("生成物流信息失败");
    }
    return orderId;
}
Also used : Gson(com.google.gson.Gson) XmallException(cn.exrick.common.exception.XmallException) Date(java.util.Date) XmallException(cn.exrick.common.exception.XmallException) CartProduct(cn.exrick.manager.dto.front.CartProduct)

Aggregations

CartProduct (cn.exrick.manager.dto.front.CartProduct)9 Gson (com.google.gson.Gson)5 ArrayList (java.util.ArrayList)3 XmallException (cn.exrick.common.exception.XmallException)2 Order (cn.exrick.manager.dto.front.Order)2 PageOrder (cn.exrick.manager.dto.front.PageOrder)2 BigDecimal (java.math.BigDecimal)2 SimpleDateFormat (java.text.SimpleDateFormat)2 TbItem (cn.exrick.manager.pojo.TbItem)1 PageInfo (com.github.pagehelper.PageInfo)1 Date (java.util.Date)1