Helius
2021-06-26 27748ad0d623313cfd8064f329f65c4c4d0af238
add score order
1 files added
8 files modified
223 ■■■■■ changed files
gc-core/src/main/java/com/xzx/gc/entity/ScoreOrderDetails.java 2 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/controller/ApiGoodsController.java 13 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/controller/ApiOrderController.java 42 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/mapper/ScoreOrderDetailsMapper.java 5 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/mapper/ScoreOrderMapper.java 5 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/service/OrderService.java 68 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/vo/XcxOrderDetailsVo.java 62 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/resources/mapper/shop/ScoreOrderDetailsMapper.xml 3 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/resources/mapper/shop/ScoreOrderMapper.xml 23 ●●●●● patch | view | raw | blame | history
gc-core/src/main/java/com/xzx/gc/entity/ScoreOrderDetails.java
@@ -30,5 +30,7 @@
    private Long goodsId;
    private Long skuId;
    private Long orderId;
}
gc-shop/src/main/java/com/xzx/gc/shop/controller/ApiGoodsController.java
@@ -62,17 +62,4 @@
        return JsonResult.success(goodsService.findGoodsDetails(id));
    }
    @ApiOperation("积分商城下单")
    @PostMapping(value = "/goods/order/add")
    public Result<String> addOrder(@RequestBody AddGoodsOrderDto addGoodsOrderDto, HttpServletRequest request) {
        String userId = getUserId(request);
        addGoodsOrderDto.setUserId(userId);
        orderService.addOrder(addGoodsOrderDto);
        Result<String> result = Result.success();
        result.setMsg("下单成功");
        return result;
    }
}
gc-shop/src/main/java/com/xzx/gc/shop/controller/ApiOrderController.java
@@ -2,10 +2,13 @@
import com.github.pagehelper.PageInfo;
import com.xzx.gc.common.Result;
import com.xzx.gc.common.request.BaseController;
import com.xzx.gc.model.JsonResult;
import com.xzx.gc.shop.dto.AddGoodsOrderDto;
import com.xzx.gc.shop.dto.XcxOrderListDto;
import com.xzx.gc.shop.service.OrderService;
import com.xzx.gc.shop.vo.XcxOrderDetailsVo;
import com.xzx.gc.shop.vo.XcxOrderListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -13,6 +16,7 @@
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@@ -27,6 +31,19 @@
    @Autowired
    private OrderService orderService;
    @ApiOperation("积分商城下单")
    @PostMapping(value = "/goods/order/add")
    public Result<String> addOrder(@RequestBody AddGoodsOrderDto addGoodsOrderDto, HttpServletRequest request) {
        String userId = getUserId(request);
        addGoodsOrderDto.setUserId(userId);
        orderService.addOrder(addGoodsOrderDto);
        Result<String> result = Result.success();
        result.setMsg("下单成功");
        return result;
    }
    @ApiOperation("我的订单列表")
    @ApiResponses(
            @ApiResponse(code = 200, message = "success", response = XcxOrderListVo.class)
@@ -37,4 +54,29 @@
        xcxOrderListDto.setUserId(userId);
        return JsonResult.success(orderService.orderList(xcxOrderListDto));
    }
    @ApiOperation("确认收货")
    @PostMapping(value = "/order/confirm/{id}")
    public Result<String> confirmOrder (@PathVariable("id") Long id, HttpServletRequest request) {
        orderService.confirmOrder(id, getUserId(request));
        return Result.success();
    }
    @ApiOperation("取消订单")
    @PostMapping(value = "/order/cancel/{id}")
    public Result<String> cancelOrder(@PathVariable("id") Long id, HttpServletRequest request) {
        orderService.cancelOrder(id, getUserId(request));
        return Result.success();
    }
    @ApiOperation("订单详情")
    @ApiResponses({
            @ApiResponse(code = 200, message = "success", response = XcxOrderDetailsVo.class)
    })
    @PostMapping(value = "/order/details/{id}")
    public JsonResult<XcxOrderDetailsVo> orderDetails(@PathVariable("id") Long id) {
        return JsonResult.success(orderService.orderDetails(id));
    }
}
gc-shop/src/main/java/com/xzx/gc/shop/mapper/ScoreOrderDetailsMapper.java
@@ -2,6 +2,11 @@
import com.xzx.gc.entity.ScoreOrderDetails;
import com.xzx.gc.util.GcMapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ScoreOrderDetailsMapper extends GcMapper<ScoreOrderDetails> {
    List<ScoreOrderDetails> selectOrderDetailsByOrderId(@Param("orderId") Long orderId);
}
gc-shop/src/main/java/com/xzx/gc/shop/mapper/ScoreOrderMapper.java
@@ -4,6 +4,7 @@
import com.xzx.gc.shop.dto.QueryOrderListDto;
import com.xzx.gc.shop.dto.XcxOrderListDto;
import com.xzx.gc.shop.vo.QueryOrderListVo;
import com.xzx.gc.shop.vo.XcxOrderDetailsVo;
import com.xzx.gc.shop.vo.XcxOrderListVo;
import com.xzx.gc.util.GcMapper;
import org.apache.ibatis.annotations.Param;
@@ -20,4 +21,8 @@
                                          @Param("createdTimeEnd")Date createdTimeEnd);
    List<XcxOrderListVo> selectXcxOrderList(@Param("record") XcxOrderListDto xcxOrderListDto);
    XcxOrderDetailsVo selectXcxOrderDetails(@Param("id") Long id);
    int updateOrderStatus(@Param("id") Long id, @Param("status") Integer status, @Param("userId") String userId);
}
gc-shop/src/main/java/com/xzx/gc/shop/service/OrderService.java
@@ -15,10 +15,7 @@
import com.xzx.gc.entity.*;
import com.xzx.gc.shop.dto.*;
import com.xzx.gc.shop.mapper.*;
import com.xzx.gc.shop.vo.ExpressInfoVo;
import com.xzx.gc.shop.vo.QueryOrderListVo;
import com.xzx.gc.shop.vo.ViewOrderVo;
import com.xzx.gc.shop.vo.XcxOrderListVo;
import com.xzx.gc.shop.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -246,6 +243,10 @@
        scoreDetails.setCurrentScore(remianScore);
        scoreDetails.setChangeScore(totalPrice);
        scoreDetailsMapper.insert(scoreDetails);
        sku.setStock(sku.getStock() - addGoodsOrderDto.getCnt());
        sku.setQuantity(sku.getQuantity() - addGoodsOrderDto.getCnt());
        scoreGoodsSkuMapper.updateByPrimaryKey(sku);
    }
    public Long cancelOrder(CancelOrderDto model) {
@@ -264,4 +265,63 @@
        List<XcxOrderListVo> data = scoreOrderMapper.selectXcxOrderList(xcxOrderListDto);
        return new PageInfo<>(data);
    }
    public XcxOrderDetailsVo orderDetails(Long id) {
        return scoreOrderMapper.selectXcxOrderDetails(id);
    }
    public void confirmOrder(Long id, String userId) {
        ScoreOrder order = scoreOrderMapper.selectByPrimaryKey(id);
        if (order == null) {
            throw new RestException(-3, "订单不存在");
        }
        if (!order.getUserId().equals(userId)) {
            throw new RestException(-3, "订单不存在");
        }
        if (!ScoreOrder.STATUS_ON.equals(order.getStatus())) {
            throw new RestException(-3, "暂不能确认收货");
        }
        scoreOrderMapper.updateOrderStatus(id, ScoreOrder.STATUS_DOING, userId);
    }
    public void cancelOrder(Long id, String userId) {
        ScoreOrder order = scoreOrderMapper.selectByPrimaryKey(id);
        if (order == null) {
            throw new RestException(-3, "订单不存在");
        }
        if (!order.getUserId().equals(userId)) {
            throw new RestException(-3, "订单不存在");
        }
        if (!ScoreOrder.STATUS_READY.equals(order.getStatus())) {
            throw new RestException(-3, "订单不能取消");
        }
        scoreOrderMapper.updateOrderStatus(id, ScoreOrder.STATUS_CANCEL, userId);
        // 退积分
        AccountInfo accountInfo = accountInfoMapper.selectAccountInfoByUserId(userId);
        BigDecimal score = new BigDecimal(accountInfo.getCollectScore()).add(order.getTotalPrice()).setScale(0, BigDecimal.ROUND_DOWN);
        accountInfo.setCollectScore(score.toString());
        accountInfoMapper.updateByPrimaryKey(accountInfo);
        // 减销量 加库存
        List<ScoreOrderDetails> details = scoreOrderDetailsMapper.selectOrderDetailsByOrderId(order.getId());
        if (CollUtil.isNotEmpty(details)) {
            for (ScoreOrderDetails detail : details) {
                ScoreGoodsSku sku = scoreGoodsSkuMapper.selectByPrimaryKey(detail.getSkuId());
                if (sku == null) {
                    continue;
                }
                sku.setQuantity(sku.getQuantity() - detail.getCnt());
                sku.setStock(sku.getStock() + detail.getCnt());
                scoreGoodsSkuMapper.updateByPrimaryKey(sku);
            }
        }
    }
}
gc-shop/src/main/java/com/xzx/gc/shop/vo/XcxOrderDetailsVo.java
New file
@@ -0,0 +1,62 @@
package com.xzx.gc.shop.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
@Data
@ApiModel(value = "XcxOrderDetailsVo", description = "小程序订单详情返回参数类")
public class XcxOrderDetailsVo {
    @ApiModelProperty(value = "订单编号")
    private String orderNo;
    @ApiModelProperty(value = "下单时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;
    @ApiModelProperty(value = "缩略图")
    private String thumb;
    @ApiModelProperty(value = "商品名称")
    private String goodsName;
    @ApiModelProperty(value = "样式名称")
    private String style;
    @ApiModelProperty(value = "sku名称")
    private String sku;
    @ApiModelProperty(value = "数量")
    private Integer cnt;
    @ApiModelProperty(value = "状态 1-待发货 2-待收货 3-已收货 4-已完成 6-已取消")
    private Integer status;
    @ApiModelProperty(value = "总价")
    private BigDecimal totalPrice;
    @ApiModelProperty(value = "单价")
    private BigDecimal unitPrice;
    @ApiModelProperty(value = "快递单号")
    private String expressNo;
    @ApiModelProperty(value = "快递公司")
    private String expressCompany;
    @ApiModelProperty(value = "地址")
    private String address;
    @ApiModelProperty(value = "姓名")
    private String username;
    @ApiModelProperty(value = "手机号")
    private String phone;
}
gc-shop/src/main/resources/mapper/shop/ScoreOrderDetailsMapper.xml
@@ -2,4 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xzx.gc.shop.mapper.ScoreOrderDetailsMapper">
    <select id="selectOrderDetailsByOrderId" resultType="com.xzx.gc.entity.ScoreOrderDetails">
        select * from xzx_score_order_details where order_id=#{orderId}
    </select>
</mapper>
gc-shop/src/main/resources/mapper/shop/ScoreOrderMapper.xml
@@ -59,4 +59,27 @@
        order by a.created_time desc
    </select>
    <select id="selectXcxOrderDetails" resultType="com.xzx.gc.shop.vo.XcxOrderDetailsVo">
        select
            a.*
             ,b.style
             ,b.sku
             ,b.thumb
             ,b.unit_price
             ,c.address
             ,c.phone
             ,c.username
             ,c.express_com expressCompany
             ,c.express_no
        from xzx_score_order a
         inner join xzx_score_order_details b on a.id=b.order_id
         inner join xzx_score_express_info c on a.id=c.order_id
        where a.id=#{id}
    </select>
    <update id="updateOrderStatus">
        update xzx_score_order
        set status=#{status}
        where id=#{id} and user_id=#{userId}
    </update>
</mapper>