From 82a8bc62d5b9d5d607f6952329952b17eda2f0a0 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期一, 14 九月 2026 15:44:34 +0800
Subject: [PATCH] update

---
 backend/src/main/java/com/tourguide/modules/order/service/MiniTourOrderCommandService.java |   33 +++++++++++++++++++++++++++++++--
 1 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/backend/src/main/java/com/tourguide/modules/order/service/MiniTourOrderCommandService.java b/backend/src/main/java/com/tourguide/modules/order/service/MiniTourOrderCommandService.java
index 8114c54..ed94927 100644
--- a/backend/src/main/java/com/tourguide/modules/order/service/MiniTourOrderCommandService.java
+++ b/backend/src/main/java/com/tourguide/modules/order/service/MiniTourOrderCommandService.java
@@ -10,6 +10,7 @@
 import com.tourguide.modules.operation.mapper.ScenicPricingMapper;
 import com.tourguide.modules.operation.service.PlatformSettingsService;
 import com.tourguide.modules.order.domain.OrderStatus;
+import com.tourguide.modules.order.domain.PaymentMethod;
 import com.tourguide.modules.order.domain.RefundStatus;
 import com.tourguide.modules.order.dto.MiniOrderCreateRequest;
 import com.tourguide.modules.order.dto.TourOrderResponse;
@@ -20,6 +21,7 @@
 import com.tourguide.modules.user.entity.GuideUser;
 import com.tourguide.modules.user.mapper.GuideUserMapper;
 import com.tourguide.modules.user.service.MiniUserService;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -31,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;
@@ -40,6 +43,9 @@
     private final PlatformSettingsService platformSettingsService;
     private final GuideNotificationService notificationService;
     private final OrderRefundService orderRefundService;
+    private final GuideOrderMatchingService matchingService;
+    private final GuideSessionTransitionService sessionTransitionService;
+    private final boolean skipPayment;
 
     public MiniTourOrderCommandService(TourOrderMapper orderMapper,
                                        MiniUserService miniUserService,
@@ -49,7 +55,10 @@
                                        GuideUserMapper guideUserMapper,
                                        PlatformSettingsService platformSettingsService,
                                        GuideNotificationService notificationService,
-                                       OrderRefundService orderRefundService) {
+                                       OrderRefundService orderRefundService,
+                                       GuideOrderMatchingService matchingService,
+                                       GuideSessionTransitionService sessionTransitionService,
+                                       @Value("${tourguide.order.skip-payment:false}") boolean skipPayment) {
         this.orderMapper = orderMapper;
         this.miniUserService = miniUserService;
         this.scenicSpotMapper = scenicSpotMapper;
@@ -59,6 +68,9 @@
         this.platformSettingsService = platformSettingsService;
         this.notificationService = notificationService;
         this.orderRefundService = orderRefundService;
+        this.matchingService = matchingService;
+        this.sessionTransitionService = sessionTransitionService;
+        this.skipPayment = skipPayment;
     }
 
     @Transactional
@@ -103,9 +115,20 @@
         order.setMeetingPointCount(1);
         Integer settlementDays = platformSettingsService.getSettings().getSettlementDays();
         order.setSettlementDays(settlementDays == null ? 1 : Math.max(0, settlementDays));
-        order.setStatus(OrderStatus.PENDING_PAYMENT.getCode());
+        if (skipPayment) {
+            order.setPaymentMethod(PaymentMethod.TEMPORARY_BYPASS.getCode());
+            order.setPaymentOrderNo("TEMP" + order.getOrderNo());
+            order.setPaymentAmount(subtotalAmount);
+            order.setPaymentTime(now);
+            order.setStatus(OrderStatus.PENDING_ACCEPT.getCode());
+        } else {
+            order.setStatus(OrderStatus.PENDING_PAYMENT.getCode());
+        }
         order.setRefundStatus(RefundStatus.NONE.getCode());
         orderMapper.insert(order);
+        if (skipPayment) {
+            matchingService.match(order.getId());
+        }
         return TourOrderResponse.from(order);
     }
 
@@ -140,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());
     }
@@ -162,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);
     }

--
Gitblit v1.7.1