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; 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) { @NotBlank String orderNo, @NonNull BigDecimal amount, Long relatedId, String platformType) {
OrderPayment orderPayment = getInstance(shopId, sourceId, sourceType, orderNo, amount, null, relatedId); OrderPayment orderPayment = getInstance(shopId, sourceId, sourceType, orderNo, amount, null, relatedId);
orderPayment.setChannel(channel);
orderPayment.setPayType(PayTypeConstants.PayType.REFUND); orderPayment.setPayType(PayTypeConstants.PayType.REFUND);
orderPayment.setPayStatus(PayTypeConstants.PayStatus.INIT); orderPayment.setPayStatus(PayTypeConstants.PayStatus.INIT);
orderPayment.setPlatformType(platformType); orderPayment.setPlatformType(platformType);

View File

@@ -358,7 +358,7 @@ public class OrderPayServiceImpl implements OrderPayService {
orderInfoCustomService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(), orderInfoCustomService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
LocalDateTime.now(), paymentId, PayEnums.BACK_SCAN); LocalDateTime.now(), paymentId, PayEnums.BACK_SCAN);
// 事务成功提交后执行消息发送 // 事务成功提交后执行消息发送
String printParam = orderInfo.getId() + "_" + (!"after-pay".equals( orderInfo.getPayMode()) ? 1 : 0) + "_1"; String printParam = orderInfo.getId() + "_" + (!"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0) + "_1";
rabbitPublisher.sendOrderPrintMsg(printParam, orderInfo.getIsPrint() == 1, "事务环境打印"); rabbitPublisher.sendOrderPrintMsg(printParam, orderInfo.getIsPrint() == 1, "事务环境打印");
} else { } else {
upOrderPayInfo(orderInfo.getId(), PayEnums.BACK_SCAN, paymentId, upOrderPayInfo(orderInfo.getId(), PayEnums.BACK_SCAN, paymentId,
@@ -375,10 +375,7 @@ public class OrderPayServiceImpl implements OrderPayService {
if (orderInfo.getStatus().equals(OrderStatusEnums.CANCELLED.getCode())) { if (orderInfo.getStatus().equals(OrderStatusEnums.CANCELLED.getCode())) {
throw new CzgException("订单已过期不可退单"); throw new CzgException("订单已过期不可退单");
} }
boolean isFirstRefund = true; boolean isFirstRefund = orderInfo.getRefundAmount().compareTo(BigDecimal.ZERO) == 0;
if (orderInfo.getRefundAmount().compareTo(BigDecimal.ZERO) != 0) {
isFirstRefund = false;
}
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId()); ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId());
Map<String, BigDecimal> returnProMap = new HashMap<>(); Map<String, BigDecimal> returnProMap = new HashMap<>();
boolean isPay = true; boolean isPay = true;
@@ -437,9 +434,8 @@ public class OrderPayServiceImpl implements OrderPayService {
returnProMap.put(Convert.toStr(orderDetail.getProductId()), refundDetail.getNum()); returnProMap.put(Convert.toStr(orderDetail.getProductId()), refundDetail.getNum());
} }
} }
long count = orderDetailService.queryChain() long count = orderDetailService.count(QueryWrapper.create().eq(OrderDetail::getOrderId, orderInfo.getId())
.eq(OrderDetail::getOrderId, orderInfo.getId()) .ne(OrderDetail::getStatus, OrderStatusEnums.REFUND.getCode()));
.ne(OrderDetail::getStatus, OrderStatusEnums.REFUND.getCode()).count();
if (count > 0 && isPay) { if (count > 0 && isPay) {
orderInfo.setStatus(OrderStatusEnums.PART_REFUND.getCode()); orderInfo.setStatus(OrderStatusEnums.PART_REFUND.getCode());
} else if (isPay) { } else if (isPay) {
@@ -447,10 +443,9 @@ public class OrderPayServiceImpl implements OrderPayService {
} }
} else { } else {
orderInfo.setStatus(OrderStatusEnums.REFUND.getCode()); orderInfo.setStatus(OrderStatusEnums.REFUND.getCode());
List<OrderDetail> orderDetails = orderDetailService.queryChain() List<OrderDetail> orderDetails = orderDetailService.list(
.select(OrderDetail::getId, OrderDetail::getProductId, OrderDetail::getNum, OrderDetail::getReturnNum, OrderDetail::getPackAmount, OrderDetail::getReturnNum) QueryWrapper.create().select(OrderDetail::getId, OrderDetail::getProductId, OrderDetail::getNum, OrderDetail::getReturnNum, OrderDetail::getPackAmount, OrderDetail::getReturnNum)
.eq(OrderDetail::getOrderId, orderInfo.getId()) .eq(OrderDetail::getOrderId, orderInfo.getId()));
.list();
for (OrderDetail orderDetail : orderDetails) { for (OrderDetail orderDetail : orderDetails) {
if (isPay) { if (isPay) {
if (orderDetail.getProductId() != null && orderDetail.getProductId() > 0) { if (orderDetail.getProductId() != null && orderDetail.getProductId() > 0) {
@@ -517,7 +512,7 @@ public class OrderPayServiceImpl implements OrderPayService {
@NonNull String refundReason, @NonNull BigDecimal refundAmount) { @NonNull String refundReason, @NonNull BigDecimal refundAmount) {
OrderPayment payment = paymentService.getById(payOrderId); OrderPayment payment = paymentService.getById(payOrderId);
AssertUtil.isNull(payment, "退款失败支付记录不存在"); 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())); refPayOrderNo, refundAmount, payment.getId(), payment.getPlatformType()));
CzgResult<RefundRespDTO> refund = payService.refund(shopId, new CzgRefundReq(refPayOrderNo, refundReason, refundAmount.multiply(PayService.MONEY_RATE).longValue(), 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()); throw new CzgException(refund.getMsg());
} else { } else {
OrderPayment upPayment = new OrderPayment(); OrderPayment upPayment = new OrderPayment();
upPayment.setPayStatus(PayTypeConstants.PayStatus.SUCCESS);
upPayment.setPayTime(LocalDateTimeUtil.parse(refund.getData().getRefundTime())); upPayment.setPayTime(LocalDateTimeUtil.parse(refund.getData().getRefundTime()));
upPayment.setTradeNumber(refund.getData().getThirdRefundNo()); upPayment.setTradeNumber(refund.getData().getThirdRefundNo());
upPayment.setRespJson(refund.getData().getOriginalData()); upPayment.setRespJson(refund.getData().getOriginalData());

View File

@@ -108,7 +108,7 @@ public class PayServiceImpl implements PayService {
@NonNull String refundReason, @NonNull BigDecimal refundAmount) { @NonNull String refundReason, @NonNull BigDecimal refundAmount) {
OrderPayment payment = paymentService.getById(payOrderId); OrderPayment payment = paymentService.getById(payOrderId);
AssertUtil.isNull(payment, "退款失败,支付记录不存在"); 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(), 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())); payment.getAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getOrderNo(), "", payment.getPlatformType()));
OrderPayment uOrderPayment = new OrderPayment(); OrderPayment uOrderPayment = new OrderPayment();

View File

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