From 92c8fe0b42e03eb3062c624801158aa1944b6dd5 Mon Sep 17 00:00:00 2001 From: Derran Date: Fri, 13 Mar 2026 18:06:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A7=94=E6=89=98=E6=9C=8D=E5=8A=A1=E8=B4=B9?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ora/constant/RefundOrderTypeEnum.java | 4 +- .../eso/entity/EntrustServiceOrder.java | 7 +- ...rustServiceOrderUserCommandController.java | 7 ++ .../UserRefundEntrustServiceOrderDto.java | 29 +++++++ .../OrderRefundApplicationEventHandler.java | 7 +- ...EntrustServiceOrderApplicationService.java | 79 ++++++++++++++++++- ...erRefundApplicationApplicationService.java | 8 +- ...efundEntrustServiceOrderDomainService.java | 26 ++++++ 8 files changed, 156 insertions(+), 11 deletions(-) create mode 100644 dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/eso/user/request/request/UserRefundEntrustServiceOrderDto.java create mode 100644 dating-agency-mall-server/src/main/java/com/qniao/dam/domain/service/eso/RefundEntrustServiceOrderDomainService.java diff --git a/dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/ora/constant/RefundOrderTypeEnum.java b/dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/ora/constant/RefundOrderTypeEnum.java index 436c7b7..18fb8b6 100644 --- a/dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/ora/constant/RefundOrderTypeEnum.java +++ b/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 diff --git a/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/eso/entity/EntrustServiceOrder.java b/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/eso/entity/EntrustServiceOrder.java index 9ecc095..83eceef 100644 --- a/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/eso/entity/EntrustServiceOrder.java +++ b/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 { @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 { @ApiModelProperty("接收时间") private LocalDateTime acceptedTime; + @ApiModelProperty("退款原因") + private String refundReason; + @ApiModelProperty("备注") private String remark; } diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/eso/user/EntrustServiceOrderUserCommandController.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/eso/user/EntrustServiceOrderUserCommandController.java index 7eafe78..326eff3 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/eso/user/EntrustServiceOrderUserCommandController.java +++ b/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()); + } } diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/eso/user/request/request/UserRefundEntrustServiceOrderDto.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/eso/user/request/request/UserRefundEntrustServiceOrderDto.java new file mode 100644 index 0000000..f5092d6 --- /dev/null +++ b/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 { + + @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); + } + +} diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/handler/ora/OrderRefundApplicationEventHandler.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/handler/ora/OrderRefundApplicationEventHandler.java index 85ada82..8e33771 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/handler/ora/OrderRefundApplicationEventHandler.java +++ b/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) { diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/eso/EntrustServiceOrderApplicationService.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/eso/EntrustServiceOrderApplicationService.java index feee9d3..4d54d84 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/eso/EntrustServiceOrderApplicationService.java +++ b/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 paymentOrderList = paymentOrderQueryService.listByOrderId(Collections.singletonList(entrustServiceOrder.getAssociateOrderId()), PaymentOrderStatusEnum.PAID); + List 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); + } } \ No newline at end of file diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/ora/OrderRefundApplicationApplicationService.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/ora/OrderRefundApplicationApplicationService.java index 87d6a56..2563e16 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/ora/OrderRefundApplicationApplicationService.java +++ b/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); diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/service/eso/RefundEntrustServiceOrderDomainService.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/service/eso/RefundEntrustServiceOrderDomainService.java new file mode 100644 index 0000000..e8ef26e --- /dev/null +++ b/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); + } +}