...
|
...
|
@@ -65,6 +65,7 @@ import java.util.Date; |
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.function.BiFunction;
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
import static com.yohoufo.order.common.TransferCase.EARNEST_MONEY_TO_BUYER;
|
|
|
import static com.yohoufo.order.utils.ServiceExceptions.throwServiceException;
|
...
|
...
|
@@ -1306,29 +1307,24 @@ public class PaymentServiceImpl implements IPaymentService { |
|
|
AbstractOrderPaymentService orderPaymentService = getOrderPaymentService(codeMeta, orderCode);
|
|
|
OrderInfo orderInfo = orderPaymentService.getOrderInfo(orderCode);
|
|
|
|
|
|
Function<Object, String> exceptionMessage = appendMessage -> String.format("订单[%s],%s!", orderCode, appendMessage);
|
|
|
|
|
|
// 获取支付成功记录
|
|
|
OrdersPay ordersPay = ordersPayMapper.selectOrdersPay(orderInfo.getOrderCode(), orderInfo.getUid());
|
|
|
|
|
|
if (!ObjectUtils.allNotNull(ordersPay, ordersPay.getAmount(), ordersPay.getPayment())) {
|
|
|
logger.warn("manual refund paid record not exist.orderCode is {}", orderCode);
|
|
|
ServiceExceptions.throwServiceException(400,"订单[" + orderCode + "],尚未支付!");
|
|
|
}
|
|
|
|
|
|
if(!CollectionUtils.isEmpty(ordersPayRefundMapper.selectByOrderCode(orderCode))) {
|
|
|
logger.warn("manual refund has success before .orderCode is {}", orderCode);
|
|
|
throwServiceException(400, "订单[" + orderCode + "],已经退款成功过!");
|
|
|
}
|
|
|
throwServiceExceptionIf(!ObjectUtils.allNotNull(ordersPay, ordersPay.getAmount(), ordersPay.getPayment()), exceptionMessage.apply("尚未支付"));
|
|
|
|
|
|
// 退款金额大于支付金额
|
|
|
if (ordersPay.getAmount().compareTo(amount) < 0) {
|
|
|
logger.warn("manual refund refundAmount {} > amount {}, orderCode is {}",
|
|
|
ordersPay.getAmount(), amount, orderCode);
|
|
|
throwServiceException("订单[" + orderCode + "],退款金额大于支付金额!");
|
|
|
}
|
|
|
throwServiceExceptionIf(CollectionUtils.isNotEmpty(ordersPayRefundMapper.selectByOrderCode(orderCode)), exceptionMessage.apply("已经退款成功过"));
|
|
|
|
|
|
throwServiceExceptionIf(ordersPay.getAmount().compareTo(amount) < 0, exceptionMessage.apply("退款金额大于支付金额"));
|
|
|
|
|
|
throwServiceExceptionIf(Objects.isNull(orderInfo.getPayment()), exceptionMessage.apply("退款渠道不存在"));
|
|
|
|
|
|
// 退款
|
|
|
AbstractPayService payService = getPayService(orderInfo.getPayment());
|
|
|
|
|
|
throwServiceExceptionIf(Objects.isNull(payService), exceptionMessage.apply("未找到合适的退款渠道"));
|
|
|
|
|
|
PayRefundBo payRefundBo = new PayRefundBo();
|
|
|
payRefundBo.setOrderCode(String.valueOf(orderCode));
|
|
|
payRefundBo.setPayOrderCode(ordersPay.getPayOrderCode());
|
...
|
...
|
|