|
|
|
@ -34,10 +34,16 @@ import com.qniao.dam.query.matchmaker.MatchmakerQueryService; |
|
|
|
import com.qniao.dam.query.order.OrderQueryService; |
|
|
|
import com.qniao.dam.query.product.ProductQueryService; |
|
|
|
import com.qniao.dam.query.right.RightQueryService; |
|
|
|
import com.qniao.das.application.DatingAgencyServiceApplicationService; |
|
|
|
import com.qniao.das.application.request.CalculateSiteActivityFeeDto; |
|
|
|
import com.qniao.das.application.response.CalculateSiteActivityFeeVo; |
|
|
|
import com.qniao.das.domian.aggregate.marriageinformation.MarriageInformation; |
|
|
|
import com.qniao.das.domian.aggregate.marriageinformation.constant.GenderEnum; |
|
|
|
import com.qniao.das.domian.aggregate.siteactivity.SiteActivity; |
|
|
|
import com.qniao.das.domian.aggregate.vip.VIPEnum; |
|
|
|
import com.qniao.dau.domain.aggregate.matchmaker.entity.Matchmaker; |
|
|
|
import com.qniao.domain.BaseApplicationService; |
|
|
|
import com.qniao.domain.BaseDomainEvent; |
|
|
|
import com.qniao.framework.exception.BizException; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -50,7 +56,7 @@ import java.util.List; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class OrderApplicationService { |
|
|
|
public class OrderApplicationService extends BaseApplicationService { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private SubmitOrderDomainService submitOrderDomainService; |
|
|
|
@ -79,9 +85,9 @@ public class OrderApplicationService { |
|
|
|
@Resource |
|
|
|
private SiteActivityDao siteActivityDao; |
|
|
|
@Resource |
|
|
|
private ActivityRepository activityRepository; |
|
|
|
@Resource |
|
|
|
private RightQueryService rightQueryService; |
|
|
|
@Resource |
|
|
|
private DatingAgencyServiceApplicationService datingAgencyServiceApplicationService; |
|
|
|
|
|
|
|
@Value("${marriage_bounty_meeting_quantity:5}") |
|
|
|
private Integer marriageBountyMeetingQuantity; |
|
|
|
@ -96,13 +102,13 @@ public class OrderApplicationService { |
|
|
|
//1. 填充订单信息 + 同类型权益,不同规格,限制购买和提醒 |
|
|
|
fillOrderInfo(order); |
|
|
|
//2. 订单金额计算 |
|
|
|
countOrderAmount(order); |
|
|
|
countOrderAmount(order, false); |
|
|
|
//3. 设置订单号 |
|
|
|
order.setOrderCode(snowFlakeUtil.getSnowflakeOrderCode()); |
|
|
|
//4. 组织付款单信息 |
|
|
|
PaymentOrder paymentOrder = makePaymentOrder(order); |
|
|
|
submitOrderDomainService.handle(order, paymentOrder); |
|
|
|
return new UserSubmitOrderVo(order.getId(), paymentOrder.getId()); |
|
|
|
return new UserSubmitOrderVo(order.getId(), paymentOrder.getId(), false); |
|
|
|
} |
|
|
|
|
|
|
|
public PaymentOrder makePaymentOrder(Order order) { |
|
|
|
@ -113,7 +119,7 @@ public class OrderApplicationService { |
|
|
|
return paymentOrder; |
|
|
|
} |
|
|
|
|
|
|
|
public void countOrderAmount(Order order) { |
|
|
|
public void countOrderAmount(Order order, Boolean allowFree) { |
|
|
|
if (CollUtil.isNotEmpty(order.getOrderItemList())) { |
|
|
|
BigDecimal totalSettlementAmount = BigDecimal.ZERO; |
|
|
|
for (OrderItem orderItem : order.getOrderItemList()) { |
|
|
|
@ -121,13 +127,13 @@ public class OrderApplicationService { |
|
|
|
totalSettlementAmount = totalSettlementAmount.add(orderItem.getSettlementAmount()); |
|
|
|
} |
|
|
|
order.setSettlementAmount(totalSettlementAmount); |
|
|
|
if (order.getSettlementAmount().compareTo(BigDecimal.ZERO) <= 0) { |
|
|
|
if (!allowFree && order.getSettlementAmount().compareTo(BigDecimal.ZERO) <= 0) { |
|
|
|
throw new BizException("订单金额应该大于0"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void fillOrderInfo(Order order) { |
|
|
|
public void fillOrderInfo(Order order) { |
|
|
|
order.setOrderType(OrderTypeEnum.NORMAL); |
|
|
|
if (CollUtil.isNotEmpty(order.getOrderItemList())) { |
|
|
|
for (OrderItem orderItem : order.getOrderItemList()) { |
|
|
|
@ -180,13 +186,13 @@ public class OrderApplicationService { |
|
|
|
//2. 填充订单信息 |
|
|
|
fillMarriageBountyOrderInfo(order, productList); |
|
|
|
//3. 订单金额计算 |
|
|
|
countOrderAmount(order); |
|
|
|
countOrderAmount(order, false); |
|
|
|
//4. 设置订单号 |
|
|
|
order.setOrderCode(snowFlakeUtil.getSnowflakeOrderCode()); |
|
|
|
//5. 组装付款单信息 |
|
|
|
PaymentOrder paymentOrder = makePaymentOrder(order); |
|
|
|
submitOrderDomainService.handle(order, paymentOrder); |
|
|
|
return new UserSubmitOrderVo(order.getId(), paymentOrder.getId()); |
|
|
|
return new UserSubmitOrderVo(order.getId(), paymentOrder.getId(), false); |
|
|
|
} |
|
|
|
|
|
|
|
private void handleProduct(Product product, |
|
|
|
@ -270,41 +276,49 @@ public class OrderApplicationService { |
|
|
|
SiteActivity siteActivity = siteActivityDao.selectById(dto.getSiteActivityId()); |
|
|
|
Order order = null; |
|
|
|
PaymentOrder paymentOrder = null; |
|
|
|
if (dto.getOpenVip()) { |
|
|
|
//开通会员送活动 |
|
|
|
order = new Order(); |
|
|
|
order.setUserId(userId); |
|
|
|
order.setMiId(dto.getMiId()); |
|
|
|
order.setActivityId(siteActivity.getVipActivityId()); |
|
|
|
order.setGroupType(1); |
|
|
|
Activity activity = activityRepository.load(siteActivity.getVipActivityId()); |
|
|
|
List<OrderItem> orderItemList = new ArrayList<>(); |
|
|
|
activity.getActivityProductList().forEach(activityProduct -> { |
|
|
|
OrderItem orderItem = new OrderItem(); |
|
|
|
orderItem.setProductSpecId(activityProduct.getProductSpecId()); |
|
|
|
orderItem.setQuantity(1); |
|
|
|
orderItemList.add(orderItem); |
|
|
|
}); |
|
|
|
order.setOrderItemList(orderItemList); |
|
|
|
//1. 填充订单信息 + 同类型权益,不同规格,限制购买和提醒 |
|
|
|
fillOrderInfo(order); |
|
|
|
} else { |
|
|
|
//是否vip |
|
|
|
boolean vip = rightQueryService.checkUserVipRight(userId, dto.getMiId()).getVip(); |
|
|
|
//报名参加活动 |
|
|
|
order = Order.build(userId, dto.getMiId(), OrderBelongingEnum.CUSTOMER, marriageInformation.getNickName(), OrderTypeEnum.NORMAL); |
|
|
|
ProductSpec productSpec = product.getProductSpecList().get(0); |
|
|
|
OrderItem orderItem = OrderItem.build(productSpec.getProductId(), productSpec.getId(), product.getProductType(), product.getMainCategory(), product.getSubCategory(), |
|
|
|
product.getProductTitle(), siteActivity.calculateFee(GenderEnum.get(marriageInformation.getGenderCode()), vip), 1); |
|
|
|
order.setOrderItemList(Collections.singletonList(orderItem)); |
|
|
|
// if (dto.getOpenVip()) { |
|
|
|
// //开通会员送活动 |
|
|
|
// order = new Order(); |
|
|
|
// order.setUserId(userId); |
|
|
|
// order.setMiId(dto.getMiId()); |
|
|
|
// order.setActivityId(siteActivity.getVipActivityId()); |
|
|
|
// order.setGroupType(1); |
|
|
|
// Activity activity = activityRepository.load(siteActivity.getVipActivityId()); |
|
|
|
// List<OrderItem> orderItemList = new ArrayList<>(); |
|
|
|
// activity.getActivityProductList().forEach(activityProduct -> { |
|
|
|
// OrderItem orderItem = new OrderItem(); |
|
|
|
// orderItem.setProductSpecId(activityProduct.getProductSpecId()); |
|
|
|
// orderItem.setQuantity(1); |
|
|
|
// orderItemList.add(orderItem); |
|
|
|
// }); |
|
|
|
// order.setOrderItemList(orderItemList); |
|
|
|
// //1. 填充订单信息 + 同类型权益,不同规格,限制购买和提醒 |
|
|
|
// fillOrderInfo(order); |
|
|
|
// } else { |
|
|
|
//是否vip |
|
|
|
boolean vip = rightQueryService.checkUserVipRight(userId, dto.getMiId()).getVip(); |
|
|
|
//报名参加活动 |
|
|
|
order = Order.build(userId, dto.getMiId(), OrderBelongingEnum.CUSTOMER, marriageInformation.getNickName(), OrderTypeEnum.NORMAL); |
|
|
|
ProductSpec productSpec = product.getProductSpecList().get(0); |
|
|
|
//todo feign 获取活动应付金额 |
|
|
|
CalculateSiteActivityFeeDto calculateDto = new CalculateSiteActivityFeeDto(dto.getSiteActivityId(), userId, |
|
|
|
dto.getMiId(), vip ? VIPEnum.YES.getValue() : VIPEnum.NO.getValue()); |
|
|
|
CalculateSiteActivityFeeVo calculateVo = datingAgencyServiceApplicationService.calculateSiteActivityFeeBySdk(calculateDto); |
|
|
|
if (calculateVo.getUnitOriginalPrice().compareTo(BigDecimal.ZERO) <= 0) { |
|
|
|
throw new BizException("下单异常"); |
|
|
|
} |
|
|
|
OrderItem orderItem = OrderItem.build(productSpec.getProductId(), productSpec.getId(), product.getProductType(), product.getMainCategory(), product.getSubCategory(), |
|
|
|
product.getProductTitle(), calculateVo.getUnitSettlementPrice(), 1); |
|
|
|
order.setOrderItemList(Collections.singletonList(orderItem)); |
|
|
|
// } |
|
|
|
//2. 订单金额计算 |
|
|
|
countOrderAmount(order); |
|
|
|
countOrderAmount(order, true); |
|
|
|
//3. 设置订单号 |
|
|
|
order.setOrderCode(snowFlakeUtil.getSnowflakeOrderCode()); |
|
|
|
//4. 组织付款单信息 |
|
|
|
paymentOrder = makePaymentOrder(order); |
|
|
|
submitSiteActivityOrderDomainService.handle(order, paymentOrder, dto.getSiteActivityId(), dto.getOpenVip()); |
|
|
|
return new UserSubmitOrderVo(order.getId(), paymentOrder.getId()); |
|
|
|
List<BaseDomainEvent> eventList = submitSiteActivityOrderDomainService.handle(order, paymentOrder, dto.getSiteActivityId()); |
|
|
|
this.sendEvent(eventList); |
|
|
|
return new UserSubmitOrderVo(order.getId(), paymentOrder.getId(), Objects.isNull(paymentOrder.getId())); |
|
|
|
} |
|
|
|
} |