Browse Source

委托服务费用

master
张彭杰 2 weeks ago
parent
commit
92c8fe0b42
8 changed files with 156 additions and 11 deletions
  1. 4
      dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/ora/constant/RefundOrderTypeEnum.java
  2. 7
      dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/eso/entity/EntrustServiceOrder.java
  3. 7
      dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/eso/user/EntrustServiceOrderUserCommandController.java
  4. 29
      dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/eso/user/request/request/UserRefundEntrustServiceOrderDto.java
  5. 7
      dating-agency-mall-server/src/main/java/com/qniao/dam/application/handler/ora/OrderRefundApplicationEventHandler.java
  6. 79
      dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/eso/EntrustServiceOrderApplicationService.java
  7. 8
      dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/ora/OrderRefundApplicationApplicationService.java
  8. 26
      dating-agency-mall-server/src/main/java/com/qniao/dam/domain/service/eso/RefundEntrustServiceOrderDomainService.java

4
dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/ora/constant/RefundOrderTypeEnum.java

@ -10,7 +10,9 @@ import lombok.Getter;
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum RefundOrderTypeEnum {
MARRIAGE_BOUNTY(1, "悬赏招亲");
MARRIAGE_BOUNTY(1, "悬赏招亲"),
ENTRUST_SERVICE(2, "委托服务");
@EnumValue
@JsonValue

7
dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/eso/entity/EntrustServiceOrder.java

@ -52,8 +52,8 @@ public class EntrustServiceOrder extends Entity<EntrustServiceOrder> {
@ApiModelProperty("状态")
private EntrustServiceStatusEnum status;
@ApiModelProperty("原始状态")
private EntrustServiceStatusEnum originalStatus;
// @ApiModelProperty("原始状态")
// private EntrustServiceStatusEnum originalStatus;
@ApiModelProperty("付款状态")
private EntrustServicePaymentStatusEnum paymentStatus;
@ -61,6 +61,9 @@ public class EntrustServiceOrder extends Entity<EntrustServiceOrder> {
@ApiModelProperty("接收时间")
private LocalDateTime acceptedTime;
@ApiModelProperty("退款原因")
private String refundReason;
@ApiModelProperty("备注")
private String remark;
}

7
dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/eso/user/EntrustServiceOrderUserCommandController.java

@ -1,6 +1,7 @@
package com.qniao.dam.api.command.eso.user;
import com.qniao.dam.api.command.eso.user.request.UserAcceptEntrustServiceOrderDto;
import com.qniao.dam.api.command.eso.user.request.request.UserRefundEntrustServiceOrderDto;
import com.qniao.dam.application.service.eso.EntrustServiceOrderApplicationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -24,5 +25,11 @@ public class EntrustServiceOrderUserCommandController {
entrustServiceOrderApplicationService.accept(dto.trans2Domain(), dto.getIsAccept());
}
@ApiOperation("用户发起委托服务订单退款")
@PostMapping("/refund/entrust-service-order")
public void refundEntrustServiceOrder(@RequestBody @Validated UserRefundEntrustServiceOrderDto dto,
@RequestParam Long userId) {
entrustServiceOrderApplicationService.refundApply(dto.trans2Domain());
}
}

29
dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/eso/user/request/request/UserRefundEntrustServiceOrderDto.java

@ -0,0 +1,29 @@
package com.qniao.dam.api.command.eso.user.request.request;
import com.qniao.dam.domain.aggregate.eso.entity.EntrustServiceOrder;
import com.qniao.domain.Trans2DomainAssembler;
import com.qniao.framework.utils.TypeConvertUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@Data
public class UserRefundEntrustServiceOrderDto implements Trans2DomainAssembler<EntrustServiceOrder> {
@ApiModelProperty("唯一标识")
@NotNull(message = "唯一标识不能为空")
private Long id;
@ApiModelProperty("退款原因")
@NotNull(message = "退款原因不能为空")
@Size(max = 100,min = 1, message = "退款原因不超过100个字符")
private String refundReason;
@Override
public EntrustServiceOrder trans2Domain() {
return TypeConvertUtils.convert(this, EntrustServiceOrder.class);
}
}

7
dating-agency-mall-server/src/main/java/com/qniao/dam/application/handler/ora/OrderRefundApplicationEventHandler.java

@ -1,6 +1,7 @@
package com.qniao.dam.application.handler.ora;
import com.google.common.eventbus.Subscribe;
import com.qniao.dam.application.service.eso.EntrustServiceOrderApplicationService;
import com.qniao.dam.application.service.marriagebounty.MarriageBountyOrderApplicationService;
import com.qniao.dam.domain.aggregate.ora.entity.OrderRefundApplication;
import com.qniao.dam.domian.aggregate.ora.constant.OrderRefundApplicationStatus;
@ -20,6 +21,8 @@ public class OrderRefundApplicationEventHandler extends BaseApplicationService {
@Resource
private MarriageBountyOrderApplicationService marriageBountyOrderApplicationService;
@Resource
private EntrustServiceOrderApplicationService entrustServiceOrderApplicationService;
@Resource
private OrderRefundApplicationDao orderRefundApplicationDao;
@Subscribe
@ -28,7 +31,9 @@ public class OrderRefundApplicationEventHandler extends BaseApplicationService {
OrderRefundApplication orderRefundApplication = orderRefundApplicationDao.selectById(event.getId());
if (orderRefundApplication.getStatus().equals(OrderRefundApplicationStatus.APPROVED)) {
if (orderRefundApplication.getRefundOrderType().equals(RefundOrderTypeEnum.MARRIAGE_BOUNTY)) {
marriageBountyOrderApplicationService.refund(orderRefundApplication.getOrderId(),true);
marriageBountyOrderApplicationService.refund(orderRefundApplication.getOrderId(), true);
} else if (orderRefundApplication.getRefundOrderType().equals(RefundOrderTypeEnum.ENTRUST_SERVICE)) {
entrustServiceOrderApplicationService.refundConfirm(orderRefundApplication.getOrderId());
}
}
} catch (Exception e) {

79
dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/eso/EntrustServiceOrderApplicationService.java

@ -1,12 +1,23 @@
package com.qniao.dam.application.service.eso;
import com.qniao.dam.application.service.paymentorderrefund.PaymentOrderRefundApplicationService;
import com.qniao.dam.domain.aggregate.eso.EntrustServiceOrderAggregate;
import com.qniao.dam.domain.aggregate.eso.entity.EntrustServiceOrder;
import com.qniao.dam.domain.aggregate.ora.entity.OrderRefundApplication;
import com.qniao.dam.domain.aggregate.paymentchannelorder.entity.PaymentChannelOrder;
import com.qniao.dam.domain.aggregate.paymentorder.entity.PaymentOrder;
import com.qniao.dam.domain.aggregate.paymentorderrefund.entity.PaymentOrderRefund;
import com.qniao.dam.domain.service.eso.RefundEntrustServiceOrderDomainService;
import com.qniao.dam.domian.aggregate.eso.constant.EntrustServicePaymentStatusEnum;
import com.qniao.dam.domian.aggregate.eso.constant.EntrustServiceStatusEnum;
import com.qniao.dam.domian.aggregate.ora.constant.OrderRefundApplicationStatus;
import com.qniao.dam.domian.aggregate.ora.constant.RefundOrderTypeEnum;
import com.qniao.dam.domian.aggregate.paymentorder.constant.PaymentOrderStatusEnum;
import com.qniao.dam.infrastructure.persistent.dao.eso.EntrustServiceOrderDao;
import com.qniao.dam.query.eso.EntrustServiceOrderQueryService;
import com.qniao.dam.query.matchmakermarriage.MatchmakerMarriageInformationQueryService;
import com.qniao.dam.query.paymentchannelorder.PaymentChannelOrderQueryService;
import com.qniao.dam.query.paymentorder.PaymentOrderQueryService;
import com.qniao.das.domian.aggregate.matchmakermarriage.MatchmakerMarriageInformation;
import com.qniao.domain.BaseApplicationService;
import com.qniao.domain.BaseDomainEvent;
@ -14,8 +25,10 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@Service
@ -29,6 +42,14 @@ public class EntrustServiceOrderApplicationService extends BaseApplicationServic
private MatchmakerMarriageInformationQueryService matchmakerMarriageInformationQueryService;
@Resource
private EntrustServiceOrderDao entrustServiceOrderDao;
@Resource
private RefundEntrustServiceOrderDomainService refundEntrustServiceOrderDomainService;
@Resource
private PaymentOrderQueryService paymentOrderQueryService;
@Resource
private PaymentChannelOrderQueryService paymentChannelOrderQueryService;
@Resource
private PaymentOrderRefundApplicationService paymentOrderRefundApplicationService;
@Value("${default_marriage_bounty_matchmaker_id}")
private Long defaultMatchmakerId;
@ -73,12 +94,64 @@ public class EntrustServiceOrderApplicationService extends BaseApplicationServic
entrustServiceOrderAggregate.edit(entrustServiceOrder);
} else {
//红娘拒接单
entrustServiceOrder.setStatus(EntrustServiceStatusEnum.CANCELED);
entrustServiceOrder.setOriginalStatus(EntrustServiceStatusEnum.PENDING_ACCEPT);
entrustServiceOrder.setRemark("红娘拒接单");
BaseDomainEvent event = entrustServiceOrderAggregate.refuse(existEntrustServiceOrder);
this.sendEvent(event);
}
}
}
public void refundApply(EntrustServiceOrder entrustServiceOrder) {
//状态判断 退款时间要求
EntrustServiceOrder existEntrustServiceOrder = entrustServiceOrderDao.selectById(entrustServiceOrder.getId());
checkRefundPossible(existEntrustServiceOrder);
entrustServiceOrder.setStatus(EntrustServiceStatusEnum.CANCELED);
entrustServiceOrder.setPaymentStatus(EntrustServicePaymentStatusEnum.BEING_REFUNDED);
OrderRefundApplication orderRefundApplication = OrderRefundApplication.build(entrustServiceOrder.getId(), RefundOrderTypeEnum.ENTRUST_SERVICE,
existEntrustServiceOrder.getPaidAmount(), existEntrustServiceOrder.getPaidAmount());
orderRefundApplication.setOperationStatus(OrderRefundApplicationStatus.UNAUDITED);
orderRefundApplication.setStatus(OrderRefundApplicationStatus.UNAUDITED);
refundEntrustServiceOrderDomainService.handle(entrustServiceOrder, orderRefundApplication);
}
private void checkRefundPossible(EntrustServiceOrder entrustServiceOrder) {
if (Objects.nonNull(entrustServiceOrder)) {
if ((entrustServiceOrder.getStatus().equals(EntrustServiceStatusEnum.PENDING_ACCEPT) ||
entrustServiceOrder.getStatus().equals(EntrustServiceStatusEnum.ACCEPTED))) {
if (!entrustServiceOrder.getPaymentStatus().equals(EntrustServicePaymentStatusEnum.PAID)) {
throw new RuntimeException("请不要重复发起退款");
}
} else {
throw new RuntimeException("无法发起退款");
}
}
}
/**
* 确定退款
*/
public void refundConfirm(Long id) {
EntrustServiceOrder entrustServiceOrder = entrustServiceOrderDao.selectById(id);
List<PaymentOrder> paymentOrderList = paymentOrderQueryService.listByOrderId(Collections.singletonList(entrustServiceOrder.getAssociateOrderId()), PaymentOrderStatusEnum.PAID);
List<PaymentOrderRefund> paymentOrderRefundList = new ArrayList<>();
for (PaymentOrder paymentOrder : paymentOrderList) {
PaymentOrderRefund paymentOrderRefund = new PaymentOrderRefund();
PaymentChannelOrder paymentChannelOrder = paymentChannelOrderQueryService.queryByTxnOrderId(paymentOrder.getId());
paymentOrderRefund.setTradeOrderId(paymentOrder.getOrderId());
paymentOrderRefund.setPaymentOrderId(paymentOrder.getId());
paymentOrderRefund.setPaymentChannelOrder(paymentChannelOrder.getId());
paymentOrderRefund.setPaymentMethod(paymentOrder.getPaymentMethod());
paymentOrderRefund.setTransactionId(paymentChannelOrder.getExtOrderNo());
paymentOrderRefund.setOrderAmount(paymentChannelOrder.getAmount());
paymentOrderRefund.setRefundAmount(paymentChannelOrder.getAmount());
paymentOrderRefundList.add(paymentOrderRefund);
}
entrustServiceOrder.setStatus(EntrustServiceStatusEnum.CANCELED);
entrustServiceOrder.setPaymentStatus(EntrustServicePaymentStatusEnum.REFUNDED);
entrustServiceOrderAggregate.edit(entrustServiceOrder);
//发起微信退款
paymentOrderRefundApplicationService.refund(paymentOrderRefundList);
}
}

8
dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/ora/OrderRefundApplicationApplicationService.java

@ -30,16 +30,16 @@ public class OrderRefundApplicationApplicationService extends BaseApplicationSer
private OrderRefundApplicationDao orderRefundApplicationDao;
public void refundMarriageBountyOrder(Long order, boolean management) {
UserGetMarriageBountyOrderPreRefundInfoVo preRefundInfoVo = marriageBountyOrderQueryService.getMarriageBountyOrderPreRefundInfo(order, management);
public void refundMarriageBountyOrder(Long orderId, boolean management) {
UserGetMarriageBountyOrderPreRefundInfoVo preRefundInfoVo = marriageBountyOrderQueryService.getMarriageBountyOrderPreRefundInfo(orderId, management);
//补充退款申请如果发生退款申请则不能再次发起
if (orderRefundApplicationQueryService.hasApplied(order)) {
if (orderRefundApplicationQueryService.hasApplied(orderId)) {
preRefundInfoVo.setRefundable(false);
}
if (!preRefundInfoVo.getRefundable()) {
throw new BizException("不能发起退款");
}
OrderRefundApplication application = OrderRefundApplication.build(order, RefundOrderTypeEnum.MARRIAGE_BOUNTY,
OrderRefundApplication application = OrderRefundApplication.build(orderId, RefundOrderTypeEnum.MARRIAGE_BOUNTY,
preRefundInfoVo.getRefundableMeetingFee().add(preRefundInfoVo.getRefundableResultGift()), preRefundInfoVo.getPaidMount());
application.setOperationStatus(OrderRefundApplicationStatus.UNAUDITED);
application.setStatus(OrderRefundApplicationStatus.UNAUDITED);

26
dating-agency-mall-server/src/main/java/com/qniao/dam/domain/service/eso/RefundEntrustServiceOrderDomainService.java

@ -0,0 +1,26 @@
package com.qniao.dam.domain.service.eso;
import com.qniao.dam.domain.aggregate.eso.EntrustServiceOrderAggregate;
import com.qniao.dam.domain.aggregate.eso.entity.EntrustServiceOrder;
import com.qniao.dam.domain.aggregate.ora.OrderRefundApplicationAggregate;
import com.qniao.dam.domain.aggregate.ora.entity.OrderRefundApplication;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
@Service
public class RefundEntrustServiceOrderDomainService {
@Resource
private EntrustServiceOrderAggregate entrustServiceOrderAggregate;
@Resource
private OrderRefundApplicationAggregate orderRefundApplicationAggregate;
@Transactional(rollbackFor = Exception.class)
public void handle(EntrustServiceOrder entrustServiceOrder,
OrderRefundApplication orderRefundApplication) {
entrustServiceOrderAggregate.edit(entrustServiceOrder);
orderRefundApplicationAggregate.create(orderRefundApplication);
}
}
Loading…
Cancel
Save