xin
2025-07-15 d264c42bfbdad92d0af17833482cdb84b1c4bcf9
oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderServiceImpl.java
@@ -12,16 +12,14 @@
import com.oying.modules.sh.domain.*;
import com.oying.modules.sh.domain.request.GeneratorOrder;
import com.oying.modules.sh.domain.request.ProductOrder;
import com.oying.modules.sh.domain.request.StatusOrder;
import com.oying.modules.sh.domain.request.SubmitOrder;
import com.oying.modules.sh.domain.vo.OrderInfo;
import com.oying.modules.sh.domain.vo.OrderResponse;
import com.oying.modules.sh.domain.vo.ProductInfo;
import com.oying.modules.sh.service.*;
import com.oying.utils.*;
import com.oying.utils.enums.GenerateEnum;
import com.oying.utils.enums.OrderStatusEnum;
import com.oying.utils.enums.PayStateEnum;
import com.oying.utils.enums.PayTypeEnum;
import com.oying.utils.enums.*;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -132,12 +130,16 @@
        order.setOrderStatusDescribe(OrderStatusEnum.ZERO.getValue());
        order.setOrderRemark(submit.getRemark() != null ? submit.getRemark() : "");
        order.setOrderTime(submit.getDateTime());
        order.setSendPrice(store.getDeliveryFee());
        order.setSendType(SendTypeEnum.LY.getKey());
        order.setUserId(SecurityUtils.getCurrentUserId());
        order.setUsername(SecurityUtils.getCurrentUsername());
        order.setStoreId(submit.getStoreId());
        order.setStoreName(store.getStoreName());
        order.setStoreLogo(store.getLogoImageUrl());
        order.setSendPrice(store.getDeliveryFee());
        order.setStoreAddress(store.getAddress());
        order.setStoreLongitude(BigDecimal.valueOf(store.getLongitude()));
        order.setStoreLatitude(BigDecimal.valueOf(store.getLatitude()));
        order.setOrderDescribe(DESCRIBE + submit.getStoreId());
        order.setOriginalPrice(amount);
        order.setPaidPrice(amount);
@@ -168,12 +170,15 @@
        UserAddress address = userAddressService.getById(submit.getAddressId());
        OrderAddressSnapshot addressSnapshot = getOrderAddressSnapshot(orderNum, address);
        addressSnapshotService.save(addressSnapshot);
        orderMapper.insert(order);
        productSnapshotService.saveBatch(snapshots);
        order.setProductSnapshots(new HashSet<>(snapshots));
        operationLogService.create(order, addressSnapshot);
        OrderResponse response = new OrderResponse(order, addressSnapshot, null);
        operationLogService.create(response, OrderStatusEnum.ZERO, null);
        return order;
    }
@@ -235,18 +240,22 @@
    @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;
    public void statusOrder(StatusOrder statusOrder) {
        operationLog(getByOrderNum(statusOrder.getOrderNum()), statusOrder.getStatus());
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void operationLog(OrderResponse order) {
        orderMapper.updateOrderStatus(order.getOrder().getOrderNum(), OrderStatusEnum.TWO.getKey(), OrderStatusEnum.TWO.getValue());
    public OrderResponse getByOrderNum(String orderNum) {
        return new OrderResponse(orderMapper.getByOrderNum(orderNum),
                addressSnapshotService.queryByOrderNum(orderNum),
                operationLogService.getByOrderNum(orderNum));
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void operationLog(OrderResponse order, OrderStatusEnum stateEnum) {
        operationLogService.create(order, stateEnum, null);
    }
    @Override
@@ -258,9 +267,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 +289,8 @@
                swiftPassService.closeOrder(orderNum, anEnum);
                break;
        }
        orderMapper.updateCloseStatus(orderNum, PayStateEnum.CLOSED.getKey());
        operationLogService.create(response, OrderStatusEnum.NINE, null);
        orderMapper.updateCloseStatus(orderNum, PayStateEnum.CLOSED.getKey(), PayStateEnum.CLOSED.getValue());
    }
    @Override