| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | |
| | | /** 小程序讲解订单创建及状态流转服务。 */ |
| | | @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; |
| | |
| | | private final PlatformSettingsService platformSettingsService; |
| | | private final GuideNotificationService notificationService; |
| | | private final OrderRefundService orderRefundService; |
| | | private final GuideOrderMatchingService matchingService; |
| | | private final boolean skipPayment; |
| | | |
| | | public MiniTourOrderCommandService(TourOrderMapper orderMapper, |
| | | MiniUserService miniUserService, |
| | |
| | | GuideUserMapper guideUserMapper, |
| | | PlatformSettingsService platformSettingsService, |
| | | GuideNotificationService notificationService, |
| | | OrderRefundService orderRefundService) { |
| | | OrderRefundService orderRefundService, |
| | | GuideOrderMatchingService matchingService, |
| | | @Value("${tourguide.order.skip-payment:false}") boolean skipPayment) { |
| | | this.orderMapper = orderMapper; |
| | | this.miniUserService = miniUserService; |
| | | this.scenicSpotMapper = scenicSpotMapper; |
| | |
| | | this.platformSettingsService = platformSettingsService; |
| | | this.notificationService = notificationService; |
| | | this.orderRefundService = orderRefundService; |
| | | this.matchingService = matchingService; |
| | | this.skipPayment = skipPayment; |
| | | } |
| | | |
| | | @Transactional |
| | |
| | | order.setAmount(subtotalAmount); |
| | | order.setPlacedAt(now); |
| | | order.setMeetingPointCount(1); |
| | | order.setStatus(OrderStatus.PENDING_PAYMENT.getCode()); |
| | | Integer settlementDays = platformSettingsService.getSettings().getSettlementDays(); |
| | | order.setSettlementDays(settlementDays == null ? 1 : Math.max(0, settlementDays)); |
| | | 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); |
| | | } |
| | | |
| | |
| | | .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()); |
| | | } |
| | |
| | | throw new BusinessException(409, "当前订单状态不支持取消"); |
| | | } |
| | | order.setStatus(OrderStatus.CANCELLED.getCode()); |
| | | order.setCancelledAt(LocalDateTime.now()); |
| | | if (order.getPaymentTime() == null) { |
| | | orderMapper.updateById(order); |
| | | } else { |