This commit is contained in:
2026-02-04 16:38:29 +08:00
parent 624abd31b4
commit 257977a000
4 changed files with 13 additions and 16 deletions

View File

@@ -150,9 +150,10 @@ public class OrderPayment implements Serializable {
return orderPayment;
}
public static OrderPayment refund(@NonNull Long shopId, @NonNull Long sourceId, @NotBlank String sourceType,
public static OrderPayment refund(@NonNull String channel,@NonNull Long shopId, @NonNull Long sourceId, @NotBlank String sourceType,
@NotBlank String orderNo, @NonNull BigDecimal amount, Long relatedId, String platformType) {
OrderPayment orderPayment = getInstance(shopId, sourceId, sourceType, orderNo, amount, null, relatedId);
orderPayment.setChannel(channel);
orderPayment.setPayType(PayTypeConstants.PayType.REFUND);
orderPayment.setPayStatus(PayTypeConstants.PayStatus.INIT);
orderPayment.setPlatformType(platformType);

View File

@@ -375,10 +375,7 @@ public class OrderPayServiceImpl implements OrderPayService {
if (orderInfo.getStatus().equals(OrderStatusEnums.CANCELLED.getCode())) {
throw new CzgException("订单已过期不可退单");
}
boolean isFirstRefund = true;
if (orderInfo.getRefundAmount().compareTo(BigDecimal.ZERO) != 0) {
isFirstRefund = false;
}
boolean isFirstRefund = orderInfo.getRefundAmount().compareTo(BigDecimal.ZERO) == 0;
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId());
Map<String, BigDecimal> returnProMap = new HashMap<>();
boolean isPay = true;
@@ -437,9 +434,8 @@ public class OrderPayServiceImpl implements OrderPayService {
returnProMap.put(Convert.toStr(orderDetail.getProductId()), refundDetail.getNum());
}
}
long count = orderDetailService.queryChain()
.eq(OrderDetail::getOrderId, orderInfo.getId())
.ne(OrderDetail::getStatus, OrderStatusEnums.REFUND.getCode()).count();
long count = orderDetailService.count(QueryWrapper.create().eq(OrderDetail::getOrderId, orderInfo.getId())
.ne(OrderDetail::getStatus, OrderStatusEnums.REFUND.getCode()));
if (count > 0 && isPay) {
orderInfo.setStatus(OrderStatusEnums.PART_REFUND.getCode());
} else if (isPay) {
@@ -447,10 +443,9 @@ public class OrderPayServiceImpl implements OrderPayService {
}
} else {
orderInfo.setStatus(OrderStatusEnums.REFUND.getCode());
List<OrderDetail> orderDetails = orderDetailService.queryChain()
.select(OrderDetail::getId, OrderDetail::getProductId, OrderDetail::getNum, OrderDetail::getReturnNum, OrderDetail::getPackAmount, OrderDetail::getReturnNum)
.eq(OrderDetail::getOrderId, orderInfo.getId())
.list();
List<OrderDetail> orderDetails = orderDetailService.list(
QueryWrapper.create().select(OrderDetail::getId, OrderDetail::getProductId, OrderDetail::getNum, OrderDetail::getReturnNum, OrderDetail::getPackAmount, OrderDetail::getReturnNum)
.eq(OrderDetail::getOrderId, orderInfo.getId()));
for (OrderDetail orderDetail : orderDetails) {
if (isPay) {
if (orderDetail.getProductId() != null && orderDetail.getProductId() > 0) {
@@ -517,7 +512,7 @@ public class OrderPayServiceImpl implements OrderPayService {
@NonNull String refundReason, @NonNull BigDecimal refundAmount) {
OrderPayment payment = paymentService.getById(payOrderId);
AssertUtil.isNull(payment, "退款失败支付记录不存在");
Long refundId = payService.initPayment(OrderPayment.refund(shopId, orderId, PayTypeConstants.SourceType.ORDER,
Long refundId = payService.initPayment(OrderPayment.refund(payment.getChannel(), shopId, orderId, PayTypeConstants.SourceType.ORDER,
refPayOrderNo, refundAmount, payment.getId(), payment.getPlatformType()));
CzgResult<RefundRespDTO> refund = payService.refund(shopId, new CzgRefundReq(refPayOrderNo, refundReason, refundAmount.multiply(PayService.MONEY_RATE).longValue(),
@@ -529,6 +524,7 @@ public class OrderPayServiceImpl implements OrderPayService {
throw new CzgException(refund.getMsg());
} else {
OrderPayment upPayment = new OrderPayment();
upPayment.setPayStatus(PayTypeConstants.PayStatus.SUCCESS);
upPayment.setPayTime(LocalDateTimeUtil.parse(refund.getData().getRefundTime()));
upPayment.setTradeNumber(refund.getData().getThirdRefundNo());
upPayment.setRespJson(refund.getData().getOriginalData());

View File

@@ -108,7 +108,7 @@ public class PayServiceImpl implements PayService {
@NonNull String refundReason, @NonNull BigDecimal refundAmount) {
OrderPayment payment = paymentService.getById(payOrderId);
AssertUtil.isNull(payment, "退款失败,支付记录不存在");
Long refundId = initPayment(OrderPayment.refund(shopId, sourceId, payment.getSourceType(), refPayOrderNo, refundAmount, payment.getId(), payment.getPlatformType()));
Long refundId = initPayment(OrderPayment.refund(payment.getChannel(), shopId, sourceId, payment.getSourceType(), refPayOrderNo, refundAmount, payment.getId(), payment.getPlatformType()));
CzgResult<RefundRespDTO> refund = refund(shopId, new CzgRefundReq(refPayOrderNo, refundReason, refundAmount.multiply(MONEY_RATE).longValue(),
payment.getAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getOrderNo(), "", payment.getPlatformType()));
OrderPayment uOrderPayment = new OrderPayment();

View File

@@ -314,7 +314,7 @@ public class ShopUserServiceImpl implements ShopUserPayService {
return CzgResult.failure("退款失败,该充值记录不存在");
}
String refPayOrderNo = "REFVIP" + IdUtil.getSnowflakeNextId();
refPaymentId = payService.initPayment(OrderPayment.refund(refPayParam.getShopId(), shopUser.getId(), PayTypeConstants.SourceType.MEMBER_IN,
refPaymentId = payService.initPayment(OrderPayment.refund(payment.getChannel(), refPayParam.getShopId(), shopUser.getId(), PayTypeConstants.SourceType.MEMBER_IN,
refPayOrderNo, refPayParam.getRefAmount(), inFlow.getId(), payment.getPlatformType()));
CzgResult<RefundRespDTO> refund = payService.refund(refPayParam.getShopId(), new CzgRefundReq(refPayOrderNo, refPayParam.getRemark(),
refPayParam.getRefAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getAmount().multiply(PayService.MONEY_RATE).longValue(),