| | |
| | | private final ScenicPricingMapper pricingMapper; |
| | | private final GuideUserMapper guideUserMapper; |
| | | private final PlatformSettingsService platformSettingsService; |
| | | private final GuideOrderMatchingService matchingService; |
| | | private final GuideNotificationService notificationService; |
| | | private final OrderRefundService orderRefundService; |
| | | |
| | | public MiniTourOrderCommandService(TourOrderMapper orderMapper, |
| | | MiniUserService miniUserService, |
| | |
| | | ScenicPricingMapper pricingMapper, |
| | | GuideUserMapper guideUserMapper, |
| | | PlatformSettingsService platformSettingsService, |
| | | GuideOrderMatchingService matchingService, |
| | | GuideNotificationService notificationService) { |
| | | GuideNotificationService notificationService, |
| | | OrderRefundService orderRefundService) { |
| | | this.orderMapper = orderMapper; |
| | | this.miniUserService = miniUserService; |
| | | this.scenicSpotMapper = scenicSpotMapper; |
| | |
| | | this.pricingMapper = pricingMapper; |
| | | this.guideUserMapper = guideUserMapper; |
| | | this.platformSettingsService = platformSettingsService; |
| | | this.matchingService = matchingService; |
| | | this.notificationService = notificationService; |
| | | this.orderRefundService = orderRefundService; |
| | | } |
| | | |
| | | @Transactional |
| | |
| | | return TourOrderResponse.from(order); |
| | | } |
| | | |
| | | /** |
| | | * 确认游客订单支付成功,并将订单流转到等待导游接单状态。 |
| | | * 当前小程序尚未接入微信支付回调,因此由待支付页面在支付动作成功后调用; |
| | | * 正式接入微信支付后应由服务端支付回调触发本方法对应的领域逻辑。 |
| | | */ |
| | | @Transactional |
| | | public TourOrderResponse confirmPayment(Long visitorId, Long orderId) { |
| | | TourOrder order = requireVisitorOrder(visitorId, orderId); |
| | | if (!OrderStatus.PENDING_PAYMENT.matches(order.getStatus())) { |
| | | throw new BusinessException(409, "当前订单状态不支持支付"); |
| | | } |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | order.setPaymentMethod("WECHAT"); |
| | | order.setPaymentOrderNo("LOCAL" + order.getOrderNo()); |
| | | order.setPaymentAmount(order.getAmount()); |
| | | order.setPaymentTime(now); |
| | | order.setStatus(OrderStatus.PENDING_ACCEPT.getCode()); |
| | | orderMapper.updateById(order); |
| | | matchingService.match(order.getId()); |
| | | return TourOrderResponse.from(orderMapper.selectById(order.getId())); |
| | | } |
| | | |
| | | public TourOrderResponse active(Long visitorId) { |
| | | miniUserService.findEnabledById(visitorId); |
| | | TourOrder order = orderMapper.selectOne( |
| | |
| | | |
| | | @Transactional |
| | | public TourOrderResponse cancel(Long visitorId, Long orderId) { |
| | | TourOrder order = requireVisitorOrder(visitorId, orderId); |
| | | TourOrder order = orderMapper.selectForUpdate(orderId); |
| | | if (order == null || visitorId == null || !visitorId.equals(order.getVisitorId())) { |
| | | throw new BusinessException(404, "订单不存在"); |
| | | } |
| | | if (OrderStatus.CANCELLED.matches(order.getStatus())) { |
| | | return TourOrderResponse.from(order); |
| | | } |
| | | boolean notifyGuide = OrderStatus.PENDING_MEETING.matches(order.getStatus()) && order.getGuideId() != null; |
| | | if (!OrderStatus.PENDING_PAYMENT.matches(order.getStatus()) |
| | | && !OrderStatus.PENDING_ACCEPT.matches(order.getStatus()) |
| | |
| | | throw new BusinessException(409, "当前订单状态不支持取消"); |
| | | } |
| | | order.setStatus(OrderStatus.CANCELLED.getCode()); |
| | | if (order.getPaymentTime() != null) { |
| | | order.setRefundStatus(RefundStatus.REFUNDED.getCode()); |
| | | order.setRefundAmount(order.getPaymentAmount()); |
| | | order.setRefundTime(LocalDateTime.now()); |
| | | order.setRefundOrderNo("RF" + generateOrderNo()); |
| | | order.setRefundMethod(order.getPaymentMethod()); |
| | | if (order.getPaymentTime() == null) { |
| | | orderMapper.updateById(order); |
| | | } else { |
| | | orderRefundService.requestRefund(order); |
| | | } |
| | | orderMapper.updateById(order); |
| | | if (notifyGuide) notificationService.notifyOrderCancelled(order); |
| | | if (notifyGuide) notificationService.notifyVisitorCancelledOrder(order); |
| | | return TourOrderResponse.from(order); |
| | | } |
| | | |