• 极客专栏正式上线!欢迎访问 https://www.jikewenku.com/topic.html
  • 极客专栏正式上线!欢迎访问 https://www.jikewenku.com/topic.html

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

项目实战 Geekerstar 10个月前 (06-25) 567次浏览 已收录 0个评论 扫描二维码
文章目录[隐藏]

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<String> cancel(Integer userId, Long orderNo);

ServerResponse getOrderCartProduct(Integer userId);

OrderServiceImpl

public ServerResponse<String> 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<Cart> cartList = cartMapper.selectCheckedCartByUserId(userId);
    ServerResponse serverResponse = this.getCartOrderItem(userId, cartList);

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

    List<OrderItemVo> 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<OrderItemVo> orderItemVoList;
    private BigDecimal productTotalPrice;
    private String imageHost;

    public List<OrderItemVo> getOrderItemVoList() {
        return orderItemVoList;
    }

    public void setOrderItemVoList(List<OrderItemVo> 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;
    }
}

喜欢 (0)
[247507792@qq.com]
分享 (0)
Geekerstar
关于作者:
本站技术支持

您必须 登录 才能发表评论!

  • 精品技术教程
  • 编程资源分享
  • 问答交流社区
  • 极客文库知识库

客服QQ


QQ:2248886839


工作时间:09:00-23:00