从零到企业级SSM电商项目实战教程(四十一)取消订单,获取购物车中商品信息功能开发

OrderController.java

@RequestMapping("cancel.do")
public ServerResponse cancel(HttpSession session, Long orderNo) {
    User user = (User) session.getAttribute(Const.CURRENT_USER);
    if (user == null) {
        return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), ResponseCode.NEED_LOGIN.getDesc());
    }

    return iOrderService.cancel(user.getId(), orderNo);
}

@RequestMapping("get_order_cart_product.do")
public ServerResponse getOrderCartProduct(HttpSession session) {
    User user = (User) session.getAttribute(Const.CURRENT_USER);
    if (user == null) {
        return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), ResponseCode.NEED_LOGIN.getDesc());
    }

    return iOrderService.getOrderCartProduct(user.getId());
}

IOrderService.java

ServerResponse cancel(Integer userId, Long orderNo);

ServerResponse getOrderCartProduct(Integer userId);

OrderServiceImpl

public ServerResponse cancel(Integer userId, Long orderNo) {
    Order order = orderMapper.selectByUserIdAndOrderNo(userId, orderNo);
    if (order == null) {
        return ServerResponse.createByErrorMessage("订单不存在!");
    }
    if (order.getStatus() != Const.OrderStatusEnum.NO_PAY.getCode()) {
        return ServerResponse.createByErrorMessage("已经付款,无法取消订单!");
    }
    Order updateOrder = new Order();
    updateOrder.setId(order.getId());
    updateOrder.setStatus(Const.OrderStatusEnum.CANCELED.getCode());

    int row = orderMapper.updateByPrimaryKeySelective(updateOrder);
    if (row > 0) {
        return ServerResponse.createBySuccess();
    }
    return ServerResponse.createByError();
}

public ServerResponse getOrderCartProduct(Integer userId) {
    OrderProductVo orderProductVo = new OrderProductVo();

    List cartList = cartMapper.selectCheckedCartByUserId(userId);
    ServerResponse serverResponse = this.getCartOrderItem(userId, cartList);

    if (!serverResponse.isSuccess()) {
        return serverResponse;
    }
    List orderItemList = (List) serverResponse.getData();

    List orderItemVoList = Lists.newArrayList();

    BigDecimal payment = new BigDecimal("0");
    for (OrderItem orderItem : orderItemList) {
        payment = BigDecimalUtil.add(payment.doubleValue(), orderItem.getTotalPrice().doubleValue());
        orderItemVoList.add(assembleOrderItemVo(orderItem));
    }
    orderProductVo.setProductTotalPrice(payment);
    orderProductVo.setOrderItemVoList(orderItemVoList);
    orderProductVo.setImageHost(PropertiesUtil.getProperty("ftp.server.http.prefix"));

    return ServerResponse.createBySuccess(orderProductVo);
}

OrderProductVo.java

package com.mmall.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Author: Geekerstar(jikewenku.com)
 * @Date: 2018/6/25 12:50
 * @Description:
 */
public class OrderProductVo {

    private List orderItemVoList;
    private BigDecimal productTotalPrice;
    private String imageHost;

    public List getOrderItemVoList() {
        return orderItemVoList;
    }

    public void setOrderItemVoList(List orderItemVoList) {
        this.orderItemVoList = orderItemVoList;
    }

    public BigDecimal getProductTotalPrice() {
        return productTotalPrice;
    }

    public void setProductTotalPrice(BigDecimal productTotalPrice) {
        this.productTotalPrice = productTotalPrice;
    }

    public String getImageHost() {
        return imageHost;
    }

    public void setImageHost(String imageHost) {
        this.imageHost = imageHost;
    }
}
本站所有文章均来自互联网,如有侵权,请联系站长删除。极客文库 » 从零到企业级SSM电商项目实战教程(四十一)取消订单,获取购物车中商品信息功能开发
分享到:
赞(0)

评论抢沙发

评论前必须登录!