liujie
2026-09-14 15defa991fcd30b9fa60bab17d2230b5929bf2a2
backend/src/main/java/com/tourguide/modules/order/service/MiniTourOrderCommandService.java
@@ -33,6 +33,7 @@
/** 小程序讲解订单创建及状态流转服务。 */
@Service
public class MiniTourOrderCommandService {
    private static final int DEFAULT_UNPAID_CANCEL_MINUTES = 15;
    private final TourOrderMapper orderMapper;
    private final MiniUserService miniUserService;
    private final OperationScenicSpotMapper scenicSpotMapper;
@@ -43,6 +44,7 @@
    private final GuideNotificationService notificationService;
    private final OrderRefundService orderRefundService;
    private final GuideOrderMatchingService matchingService;
    private final GuideSessionTransitionService sessionTransitionService;
    private final boolean skipPayment;
    public MiniTourOrderCommandService(TourOrderMapper orderMapper,
@@ -55,6 +57,7 @@
                                       GuideNotificationService notificationService,
                                       OrderRefundService orderRefundService,
                                       GuideOrderMatchingService matchingService,
                                       GuideSessionTransitionService sessionTransitionService,
                                       @Value("${tourguide.order.skip-payment:false}") boolean skipPayment) {
        this.orderMapper = orderMapper;
        this.miniUserService = miniUserService;
@@ -66,6 +69,7 @@
        this.notificationService = notificationService;
        this.orderRefundService = orderRefundService;
        this.matchingService = matchingService;
        this.sessionTransitionService = sessionTransitionService;
        this.skipPayment = skipPayment;
    }
@@ -159,8 +163,12 @@
                        .orderByDesc(ScenicPricing::getId)
                        .last("LIMIT 1"));
        GuideUser guide = order.getGuideId() == null ? null : guideUserMapper.selectById(order.getGuideId());
        int unpaidCancelMinutes = scenicSpot == null || scenicSpot.getUnpaidCancelMinutes() == null
                || scenicSpot.getUnpaidCancelMinutes() < 1
                ? DEFAULT_UNPAID_CANCEL_MINUTES : scenicSpot.getUnpaidCancelMinutes();
        return TourOrderResponse.from(order)
                .enrich(scenicSpot, meetingPoint, pricing, guide)
                .withUnpaidCancelMinutes(unpaidCancelMinutes)
                .withUnacceptedAutoRefundMinutes(
                        platformSettingsService.getSettings().getUnacceptedAutoRefundMinutes());
    }
@@ -181,11 +189,13 @@
            throw new BusinessException(409, "当前订单状态不支持取消");
        }
        order.setStatus(OrderStatus.CANCELLED.getCode());
        order.setCancelledAt(LocalDateTime.now());
        if (order.getPaymentTime() == null) {
            orderMapper.updateById(order);
        } else {
            orderRefundService.requestRefund(order);
        }
        if (notifyGuide) sessionTransitionService.restoreAfterOrderCancellation(order);
        if (notifyGuide) notificationService.notifyVisitorCancelledOrder(order);
        return TourOrderResponse.from(order);
    }