|
|
@@ -166,13 +166,14 @@ public class PaymentServiceImpl implements PaymentService {
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
- // 3. 校验订单状态(必须是已支付)
|
|
|
- if (!OrderConstants.PAY_STATUS_PAID.equals(order.getPayStatus())) {
|
|
|
+ // 3. 校验订单状态(已支付或部分退款均可继续退款)
|
|
|
+ if (!OrderConstants.PAY_STATUS_PAID.equals(order.getPayStatus())
|
|
|
+ && !OrderConstants.PAY_STATUS_PARTIAL_REFUND.equals(order.getPayStatus())) {
|
|
|
log.error("退款失败: 订单状态不正确, orderId={}, payStatus={}", orderId, order.getPayStatus());
|
|
|
return RefundResult.builder()
|
|
|
.success(false)
|
|
|
.errorCode("INVALID_ORDER_STATUS")
|
|
|
- .errorMsg("订单状态不正确,只有已支付订单可以退款")
|
|
|
+ .errorMsg("订单状态不正确,只有已支付或部分退款订单可以退款")
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
@@ -625,14 +626,17 @@ public class PaymentServiceImpl implements PaymentService {
|
|
|
order.setRefundTime(LocalDateTime.now());
|
|
|
order.setRefundReason(reason);
|
|
|
|
|
|
- // 仅当累计退款 >= 实付金额时,才标记为全部退款
|
|
|
+ // 仅当累计退款 >= 实付金额时,才标记为全额退款
|
|
|
BigDecimal paidAmount = order.getPaidAmount() != null ? order.getPaidAmount() : order.getTotalAmount();
|
|
|
if (cumulativeAmount.compareTo(paidAmount) >= 0) {
|
|
|
order.setPayStatus(OrderConstants.PAY_STATUS_REFUND);
|
|
|
- log.info("订单全部退款完成 - orderId={}, cumulativeAmount={}, paidAmount={}",
|
|
|
+ log.info("订单全额退款完成 - orderId={}, cumulativeAmount={}, paidAmount={}",
|
|
|
+ order.getId(), cumulativeAmount, paidAmount);
|
|
|
+ } else {
|
|
|
+ order.setPayStatus(OrderConstants.PAY_STATUS_PARTIAL_REFUND);
|
|
|
+ log.info("订单部分退款 - orderId={}, cumulativeAmount={}, paidAmount={}",
|
|
|
order.getId(), cumulativeAmount, paidAmount);
|
|
|
}
|
|
|
- // 部分退款时保持 payStatus = PAID,允许继续退款
|
|
|
|
|
|
orderService.updateById(order);
|
|
|
log.info("订单退款状态已更新 - orderId={}, refundAmount={}(累计), payStatus={}",
|