xin
2025-07-14 6d3f43aceecf5cb35c8440e8593263b0ca1bdcd6
订单流程
10 files modified
100 ■■■■■ changed files
oying-common/src/main/java/com/oying/utils/enums/OrderStatusEnum.java 1 ●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/hwc/service/impl/CallbackServiceImpl.java 3 ●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/sh/domain/vo/OrderResponse.java 2 ●●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/sh/mapper/OrderMapper.java 2 ●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/sh/service/OrderOperationLogService.java 12 ●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/sh/service/OrderService.java 3 ●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderOperationLogServiceImpl.java 45 ●●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderServiceImpl.java 25 ●●●●● patch | view | raw | blame | history
oying-system/src/main/resources/config/application.yml 2 ●●● patch | view | raw | blame | history
oying-system/src/main/resources/mapper/sh/OrderMapper.xml 5 ●●●●● patch | view | raw | blame | history
oying-common/src/main/java/com/oying/utils/enums/OrderStatusEnum.java
@@ -16,6 +16,7 @@
    SIX(6, "骑手已取货,正在送货"),
    SEVEN(7, "商品已送达"),
    EIGHT(8, "订单已完成"),
    NINE(9, "用户取消订单"),
    UNKNOWN(99, "未知枚举");
    private final Integer key;
oying-system/src/main/java/com/oying/modules/hwc/service/impl/CallbackServiceImpl.java
@@ -9,6 +9,7 @@
import com.oying.modules.sh.domain.vo.OrderResponse;
import com.oying.modules.sh.service.OrderReturnService;
import com.oying.modules.sh.service.OrderService;
import com.oying.utils.enums.OrderStatusEnum;
import com.oying.utils.enums.PayStateEnum;
import com.oying.utils.enums.PayTypeEnum;
import lombok.RequiredArgsConstructor;
@@ -61,7 +62,7 @@
                                    PayStateEnum stateEnum = PayStateEnum.NOTPAY;
                                    if ("0".equals(map.get("pay_result"))) {
                                        stateEnum = PayStateEnum.SUCCESS;
                                        orderService.operationLog(order);
                                        orderService.operationLog(order, OrderStatusEnum.TWO);
                                    }
                                    orderService.updatePayStatus(map.get("out_trade_no"), stateEnum, map.get("pay_info"), map.get("time_end"));
                                    // 处理成功
oying-system/src/main/java/com/oying/modules/sh/domain/vo/OrderResponse.java
@@ -3,6 +3,7 @@
import com.oying.modules.sh.domain.Order;
import com.oying.modules.sh.domain.OrderAddressSnapshot;
import com.oying.modules.sh.domain.OrderOperationLog;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
@@ -15,6 +16,7 @@
 */
@Getter
@Setter
@AllArgsConstructor
public class OrderResponse {
    private Order order;
oying-system/src/main/java/com/oying/modules/sh/mapper/OrderMapper.java
@@ -28,7 +28,7 @@
    void updatePayStatus(String orderNum, String payState, String payMessage, String payTime);
    void updateCloseStatus(String orderNum, String payState);
    void updateCloseStatus(String orderNum, String payState, String payMessage);
    void updateOrderStatus(String orderNum, Integer key, String value);
}
oying-system/src/main/java/com/oying/modules/sh/service/OrderOperationLogService.java
@@ -1,7 +1,5 @@
package com.oying.modules.sh.service;
import com.oying.modules.sh.domain.Order;
import com.oying.modules.sh.domain.OrderAddressSnapshot;
import com.oying.modules.sh.domain.OrderOperationLog;
import com.oying.modules.sh.domain.dto.OrderOperationLogQueryCriteria;
import java.util.List;
@@ -9,7 +7,9 @@
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.oying.modules.sh.domain.vo.OrderResponse;
import com.oying.utils.PageResult;
import com.oying.utils.enums.OrderStatusEnum;
/**
* @description 服务接口
@@ -34,15 +34,9 @@
    List<OrderOperationLog> queryAll(OrderOperationLogQueryCriteria criteria);
    /**
    * 创建
    * @param resources /
    */
    void create(OrderOperationLog resources);
    /**
     * 创建
     */
    void create(Order order, OrderAddressSnapshot addressSnapshot);
    void create(OrderResponse response, OrderStatusEnum statusEnum);
    /**
    * 编辑
oying-system/src/main/java/com/oying/modules/sh/service/OrderService.java
@@ -15,6 +15,7 @@
import com.oying.modules.sh.domain.vo.OrderInfo;
import com.oying.modules.sh.domain.vo.OrderResponse;
import com.oying.utils.PageResult;
import com.oying.utils.enums.OrderStatusEnum;
import com.oying.utils.enums.PayStateEnum;
/**
@@ -47,7 +48,7 @@
    OrderResponse getByOrderNum(String orderNum);
    void operationLog(OrderResponse order);
    void operationLog(OrderResponse order, OrderStatusEnum stateEnum);
    void updatePayStatus(String outTradeNo, PayStateEnum stateEnum, String payInfo, String timeEnd);
oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderOperationLogServiceImpl.java
@@ -1,8 +1,6 @@
package com.oying.modules.sh.service.impl;
import com.alibaba.fastjson2.JSON;
import com.oying.modules.sh.domain.Order;
import com.oying.modules.sh.domain.OrderAddressSnapshot;
import com.oying.modules.sh.domain.OrderOperationLog;
import com.oying.modules.sh.domain.vo.OrderResponse;
import com.oying.modules.sh.mapper.OrderMapper;
@@ -54,27 +52,40 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(OrderOperationLog resources) {
        orderOperationLogMapper.insert(resources);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(Order order, OrderAddressSnapshot addressSnapshot) {
        OrderResponse response = new OrderResponse();
        response.setOrder(order);
        response.setAddress(addressSnapshot);
    public void create(OrderResponse response, OrderStatusEnum statusEnum) {
        String userType = ConstantsKey.BUYER;
        switch (statusEnum) {
            case ZERO:
            case ONE:
            case EIGHT:
            case NINE:
                userType = ConstantsKey.BUYER;
                break;
            case TWO:
            case FOUR:
                userType = ConstantsKey.MERCHANT;
                break;
            case THREE:
            case FIVE:
            case SIX:
            case SEVEN:
                userType = ConstantsKey.RIDER;
                break;
            default:
        }
        String username = SecurityUtils.getCurrentUsername();
        Timestamp time = new Timestamp(System.currentTimeMillis());
        OrderOperationLog resources = new OrderOperationLog();
        resources.setOrderNum(order.getOrderNum());
        resources.setOrderNum(response.getOrder().getOrderNum());
        resources.setUsername(username);
        resources.setUserType(ConstantsKey.BUYER);
        resources.setOperation(OrderStatusEnum.ZERO.getKey());
        resources.setOperationDescribe(OrderStatusEnum.ZERO.getValue());
        resources.setRemark(username + ":" + time + ">" + OrderStatusEnum.ZERO.getValue() + ":" + order.getOrderNum());
        resources.setUserType(userType);
        resources.setOperation(statusEnum.getKey());
        resources.setOperationDescribe(statusEnum.getValue());
        resources.setRemark(username + ":" + time + ">" + statusEnum.getValue() + ":" + response.getOrder().getOrderNum());
        resources.setSnapshotData(JSON.toJSONString(response));
        resources.setOperationTime(time);
        orderOperationLogMapper.insert(resources);
        orderMapper.updateOrderStatus(response.getOrder().getOrderNum(), statusEnum.getKey(), statusEnum.getValue());
    }
    @Override
oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderServiceImpl.java
@@ -173,7 +173,9 @@
        productSnapshotService.saveBatch(snapshots);
        order.setProductSnapshots(new HashSet<>(snapshots));
        operationLogService.create(order, addressSnapshot);
        OrderResponse response = new OrderResponse(order, addressSnapshot, null);
        operationLogService.create(response, OrderStatusEnum.ZERO);
        return order;
    }
@@ -236,17 +238,15 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public OrderResponse getByOrderNum(String orderNum) {
        OrderResponse response = new OrderResponse();
        response.setOrder(orderMapper.getByOrderNum(orderNum));
        response.setAddress(addressSnapshotService.queryByOrderNum(orderNum));
        response.setOperation(operationLogService.getByOrderNum(orderNum));
        return response;
        return new OrderResponse(orderMapper.getByOrderNum(orderNum),
                addressSnapshotService.queryByOrderNum(orderNum),
                operationLogService.getByOrderNum(orderNum));
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void operationLog(OrderResponse order) {
        orderMapper.updateOrderStatus(order.getOrder().getOrderNum(), OrderStatusEnum.TWO.getKey(), OrderStatusEnum.TWO.getValue());
    public void operationLog(OrderResponse order, OrderStatusEnum stateEnum) {
        operationLogService.create(order, stateEnum);
    }
    @Override
@@ -258,9 +258,13 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void closeOrder(String orderNum) {
        Order order = orderMapper.getByOrderNum(orderNum);
        OrderResponse response = getByOrderNum(orderNum);
        Order order = response.getOrder();
        if (order == null) {
            throw new BadRequestException("订单不存在");
        }
        if (!SecurityUtils.getCurrentUserId().equals(order.getUserId())) {
            throw new BadRequestException("不能修改他人订单");
        }
        if (!order.getPayState().equals(PayStateEnum.NOTPAY.getKey())) {
            throw new BadRequestException(PayStateEnum.getValue(order.getPayState()));
@@ -276,7 +280,8 @@
                swiftPassService.closeOrder(orderNum, anEnum);
                break;
        }
        orderMapper.updateCloseStatus(orderNum, PayStateEnum.CLOSED.getKey());
        operationLogService.create(response, OrderStatusEnum.NINE);
        orderMapper.updateCloseStatus(orderNum, PayStateEnum.CLOSED.getKey(), PayStateEnum.CLOSED.getValue());
    }
    @Override
oying-system/src/main/resources/config/application.yml
@@ -34,7 +34,7 @@
  redis:
    #数据库索引
    database: 0
    host: 192.168.18.13
    host: 127.0.0.1
    port: 6379
    password:
    #连接超时时间
oying-system/src/main/resources/mapper/sh/OrderMapper.xml
@@ -136,13 +136,14 @@
    <update id="updateCloseStatus">
        update sh_order
        set pay_state = #{payState}
        set pay_state   = #{payState},
            pay_message = #{payMessage}
        where order_num = #{orderNum}
    </update>
    <update id="updateOrderStatus">
        update sh_order
        set order_status = #{key},
        set order_status          = #{key},
            order_status_describe = #{value}
        where order_num = #{orderNum}
    </update>