| | |
| | | import com.tourguide.modules.order.dto.TourOrderResponse; |
| | | import com.tourguide.modules.order.entity.TourOrder; |
| | | import com.tourguide.modules.order.mapper.TourOrderMapper; |
| | | import com.tourguide.modules.system.service.GuideNotificationService; |
| | | import com.tourguide.modules.user.entity.MiniUser; |
| | | import com.tourguide.modules.user.entity.GuideUser; |
| | | import com.tourguide.modules.user.mapper.GuideUserMapper; |
| | |
| | | private final ScenicPricingMapper pricingMapper; |
| | | private final GuideUserMapper guideUserMapper; |
| | | private final PlatformSettingsService platformSettingsService; |
| | | private final GuideOrderMatchingService matchingService; |
| | | private final GuideNotificationService notificationService; |
| | | |
| | | public MiniTourOrderCommandService(TourOrderMapper orderMapper, |
| | | MiniUserService miniUserService, |
| | |
| | | ScenicMeetingPointMapper meetingPointMapper, |
| | | ScenicPricingMapper pricingMapper, |
| | | GuideUserMapper guideUserMapper, |
| | | PlatformSettingsService platformSettingsService) { |
| | | PlatformSettingsService platformSettingsService, |
| | | GuideOrderMatchingService matchingService, |
| | | GuideNotificationService notificationService) { |
| | | this.orderMapper = orderMapper; |
| | | this.miniUserService = miniUserService; |
| | | this.scenicSpotMapper = scenicSpotMapper; |
| | |
| | | this.pricingMapper = pricingMapper; |
| | | this.guideUserMapper = guideUserMapper; |
| | | this.platformSettingsService = platformSettingsService; |
| | | this.matchingService = matchingService; |
| | | this.notificationService = notificationService; |
| | | } |
| | | |
| | | @Transactional |
| | |
| | | order.setVisitorId(visitor.getId()); |
| | | order.setVisitorNickname(visitor.getNickname()); |
| | | order.setVisitorMobile(visitor.getMobile()); |
| | | order.setScenicSpotId(scenicSpot.getId()); |
| | | order.setScenicName(scenicSpot.getScenicName()); |
| | | order.setMeetingPointId(meetingPoint.getId()); |
| | | order.setMeetingPointName(meetingPoint.getPointName()); |
| | | order.setPackageName(packageName(pricing.getServiceType())); |
| | | order.setServicePackageId(pricing.getId()); |
| | | order.setOrderType(pricing.getServiceType()); |
| | | order.setPeopleCount(request.getPeopleCount()); |
| | | order.setUnitPrice(discountUnitPrice); |
| | |
| | | order.setPaymentTime(now); |
| | | order.setStatus(OrderStatus.PENDING_ACCEPT.getCode()); |
| | | orderMapper.updateById(order); |
| | | return TourOrderResponse.from(order); |
| | | matchingService.match(order.getId()); |
| | | return TourOrderResponse.from(orderMapper.selectById(order.getId())); |
| | | } |
| | | |
| | | public TourOrderResponse active(Long visitorId) { |
| | |
| | | @Transactional |
| | | public TourOrderResponse cancel(Long visitorId, Long orderId) { |
| | | TourOrder order = requireVisitorOrder(visitorId, orderId); |
| | | boolean notifyGuide = OrderStatus.PENDING_MEETING.matches(order.getStatus()) && order.getGuideId() != null; |
| | | if (!OrderStatus.PENDING_PAYMENT.matches(order.getStatus()) |
| | | && !OrderStatus.PENDING_ACCEPT.matches(order.getStatus()) |
| | | && !OrderStatus.PENDING_MEETING.matches(order.getStatus())) { |
| | |
| | | order.setRefundMethod(order.getPaymentMethod()); |
| | | } |
| | | orderMapper.updateById(order); |
| | | if (notifyGuide) notificationService.notifyOrderCancelled(order); |
| | | return TourOrderResponse.from(order); |
| | | } |
| | | |