fix(订单): 修复退款逻辑和支付方式设置

修复订单退款逻辑,增加对支付方式的判断,避免对余额支付的订单进行退款操作。同时,优化退款异常处理,返回更详细的错误信息。在创建订单时,增加支付方式的设置。
This commit is contained in:
dzq 2025-04-10 10:31:40 +08:00
parent 38cb4a1595
commit 7e06c9f73f
4 changed files with 25 additions and 13 deletions

View File

@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import javax.validation.Valid; import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
/** /**
@ -63,6 +64,9 @@ public class ApprovalApiController {
try { try {
if (command.getStatus() == 2) { if (command.getStatus() == 2) {
if (command.getReturnAmount() == null || command.getReturnAmount().compareTo(BigDecimal.ZERO) <= 0) {
return ResponseDTO.fail(new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "归还金额不能为空或小于等于0"));
}
approvalApplicationService.approveApproval(command); approvalApplicationService.approveApproval(command);
} else if (command.getStatus() == 3) { } else if (command.getStatus() == 3) {
approvalApplicationService.rejectApproval(command); approvalApplicationService.rejectApproval(command);

View File

@ -96,7 +96,10 @@ public class OrderController extends BaseController {
log.info("退款结果:{}", refundVO); log.info("退款结果:{}", refundVO);
return ResponseDTO.ok(refundVO); return ResponseDTO.ok(refundVO);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); RefundVO refundVO = new RefundVO();
refundVO.setSuccess(false);
refundVO.setMsg(e.getMessage());
return ResponseDTO.fail(refundVO);
} }
} }
} }

View File

@ -25,9 +25,11 @@ import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
@ -119,6 +121,7 @@ public class ReturnApprovalApplicationService {
throw new IllegalArgumentException("退款金额不能超过订单总额"); throw new IllegalArgumentException("退款金额不能超过订单总额");
} }
if (!Objects.equals(orderModel.getPaymentMethod(), "balance")) {
RefundVO refundVO = null; RefundVO refundVO = null;
try { try {
refundVO = paymentApplicationService.refund( refundVO = paymentApplicationService.refund(
@ -132,6 +135,7 @@ public class ReturnApprovalApplicationService {
if (null == refundVO || !refundVO.getSuccess()) { if (null == refundVO || !refundVO.getSuccess()) {
throw new RuntimeException("退款失败"); throw new RuntimeException("退款失败");
} }
}
model.validateApprovalStatus(); model.validateApprovalStatus();
model.setAuditImages(command.getAuditImages()); model.setAuditImages(command.getAuditImages());

View File

@ -127,6 +127,7 @@ public class OrderApplicationService {
orderModel.setStatus(1); orderModel.setStatus(1);
orderModel.generateOrderNumber(); orderModel.generateOrderNumber();
orderModel.setTotalAmount(BigDecimal.valueOf(0)); orderModel.setTotalAmount(BigDecimal.valueOf(0));
orderModel.setPaymentMethod(command.getPaymentType());
orderModel.insert(); orderModel.insert();
processOrderGoods(orderModel, goodsList); processOrderGoods(orderModel, goodsList);