多次退款
This commit is contained in:
parent
2d4f601816
commit
45e1dca5be
|
@ -38,4 +38,9 @@ public enum PayBillStatus {
|
|||
public static List<String> payedList() {
|
||||
return asList(PAY_SUCCESS, REFUNDING, REFUNDED);
|
||||
}
|
||||
|
||||
// 允许退款的状态
|
||||
public static List<String> canRefund() {
|
||||
return asList(PAY_SUCCESS, REFUNDING, REFUNDED);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,19 +6,16 @@ import com.ruoyi.common.domain.vo.LocalDateDecimalVO;
|
|||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.pay.PayApi;
|
||||
import com.ruoyi.common.pay.ali.service.AliPayService;
|
||||
import com.ruoyi.common.pay.syb.enums.SybTrxStatus;
|
||||
import com.ruoyi.common.pay.syb.service.SybPayService;
|
||||
import com.ruoyi.common.pay.tm.TmPayService;
|
||||
import com.ruoyi.common.pay.tm.enums.TmPayStatus;
|
||||
import com.ruoyi.common.pay.tm.vo.TmTradeInfo;
|
||||
import com.ruoyi.common.pay.wx.service.WxPayService;
|
||||
import com.ruoyi.common.pay.wx.util.WxPayUtil;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.ServiceUtil;
|
||||
import com.ruoyi.common.utils.SnowFlakeUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.ss.channel.domain.enums.ChannelEnum;
|
||||
import com.ruoyi.ss.payBill.domain.PayBill;
|
||||
import com.ruoyi.ss.payBill.domain.PayBillQuery;
|
||||
import com.ruoyi.ss.payBill.domain.PayBillVO;
|
||||
|
@ -36,8 +33,6 @@ import com.ruoyi.ss.payBill.service.PayBillService;
|
|||
import com.ruoyi.ss.refund.domain.RefundVO;
|
||||
import com.ruoyi.ss.refund.service.RefundConverter;
|
||||
import com.ruoyi.ss.refund.service.RefundService;
|
||||
import com.ruoyi.ss.channel.domain.enums.ChannelEnum;
|
||||
import com.wechat.pay.java.service.payments.model.Transaction;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -47,7 +42,6 @@ import java.math.BigDecimal;
|
|||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -388,17 +382,19 @@ public class PayBillServiceImpl implements PayBillService
|
|||
|
||||
BigDecimal totalRefundAmount = dto.getRefundAmount().add(bill.getRefundAmount()).add(bill.getRefundingAmount());
|
||||
ServiceUtil.assertion(totalRefundAmount.compareTo(bill.getAmount()) > 0, "总退款金额不允许大于订单金额");
|
||||
ServiceUtil.assertion(!PayBillStatus.PAY_SUCCESS.getStatus().equals(bill.getStatus()), "当前状态不允许退款");
|
||||
ServiceUtil.assertion(!PayBillStatus.canRefund().contains(bill.getStatus()), "当前状态不允许退款");
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
// 修改订单状态
|
||||
PayBill data = new PayBill();
|
||||
data.setStatus(PayBillStatus.REFUNDING.getStatus());
|
||||
PayBillQuery billQuery = new PayBillQuery();
|
||||
billQuery.setPayId(dto.getPayId());
|
||||
billQuery.setStatus(PayBillStatus.PAY_SUCCESS.getStatus());
|
||||
int updateBill = this.updateByQuery(data, billQuery);
|
||||
ServiceUtil.assertion(updateBill != 1, "修改支付订单状态失败");
|
||||
if (PayBillStatus.PAY_SUCCESS.getStatus().equals(bill.getStatus())) {
|
||||
PayBill data = new PayBill();
|
||||
data.setStatus(PayBillStatus.REFUNDED.getStatus());
|
||||
PayBillQuery billQuery = new PayBillQuery();
|
||||
billQuery.setPayId(dto.getPayId());
|
||||
billQuery.setStatusList(PayBillStatus.canRefund());
|
||||
int updateBill = this.updateByQuery(data, billQuery);
|
||||
ServiceUtil.assertion(updateBill != 1, "修改支付订单状态失败");
|
||||
}
|
||||
|
||||
// 增加退款中金额
|
||||
int addRefunding = payBillMapper.addRefundingAmount(dto.getPayId(), dto.getRefundAmount());
|
||||
|
@ -408,7 +404,7 @@ public class PayBillServiceImpl implements PayBillService
|
|||
int refund = refundService.createRefund(refundConverter.toPo(bo));
|
||||
ServiceUtil.assertion(refund != 1, "申请退款失败");
|
||||
|
||||
return updateBill;
|
||||
return refund;
|
||||
});
|
||||
|
||||
return result == null ? 0 : result;
|
||||
|
@ -422,13 +418,13 @@ public class PayBillServiceImpl implements PayBillService
|
|||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
// 修改支付订单状态
|
||||
PayBill data = new PayBillVO();
|
||||
data.setStatus(PayBillStatus.REFUNDED.getStatus());
|
||||
PayBillQuery query = new PayBillQuery();
|
||||
query.setPayId(refund.getBillId());
|
||||
query.setStatus(PayBillStatus.REFUNDING.getStatus());
|
||||
int update = this.updateByQuery(data, query);
|
||||
ServiceUtil.assertion(update != 1, "支付订单状态已发生变化,请刷新后重试");
|
||||
// PayBill data = new PayBillVO();
|
||||
// data.setStatus(PayBillStatus.REFUNDED.getStatus());
|
||||
// PayBillQuery query = new PayBillQuery();
|
||||
// query.setPayId(refund.getBillId());
|
||||
// query.setStatus(PayBillStatus.REFUNDING.getStatus());
|
||||
// int update = this.updateByQuery(data, query);
|
||||
// ServiceUtil.assertion(update != 1, "支付订单状态已发生变化,请刷新后重试");
|
||||
|
||||
// 记录已退款金额,并修改状态
|
||||
int recordAmount = payBillMapper.recordRefundAmount(refund.getBillId(), refund.getAmount());
|
||||
|
@ -446,7 +442,7 @@ public class PayBillServiceImpl implements PayBillService
|
|||
ServiceUtil.assertion(bstResult != 1, "退款业务修改失败");
|
||||
}
|
||||
|
||||
return update;
|
||||
return recordAmount;
|
||||
});
|
||||
|
||||
return result == null ? 0 : result;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.ruoyi.ss.transactionBill.domain.enums;
|
||||
|
||||
import com.ruoyi.common.enums.UserType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
|
@ -93,4 +92,11 @@ public enum TransactionBillStatus {
|
|||
public static List<String> income() {
|
||||
return asList(SUCCESS, REFUNDING, REFUNDED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 允许退款的状态
|
||||
*/
|
||||
public static List<String> canRefund() {
|
||||
return asList(SUCCESS, REFUNDED);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.ruoyi.ss.transactionBill.mapper;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.common.domain.vo.CommonCountVO;
|
||||
import com.ruoyi.dashboard.domain.vo.BillCountVo;
|
||||
import com.ruoyi.ss.transactionBill.domain.TransactionBill;
|
||||
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
|
||||
|
@ -160,14 +159,9 @@ public interface TransactionBillMapper
|
|||
* 添加退款金额
|
||||
* @param billId 订单ID
|
||||
* @param refundAmount 退款金额
|
||||
* @param refundMchAmount 商户退款金额
|
||||
* @param refundServiceAmount 服务费退款金额
|
||||
*/
|
||||
int addRefundAmount(@Param("billId") Long billId,
|
||||
@Param("refundAmount") BigDecimal refundAmount,
|
||||
@Param("refundMchAmount") BigDecimal refundMchAmount,
|
||||
@Param("refundServiceAmount") BigDecimal refundServiceAmount
|
||||
);
|
||||
@Param("refundAmount") BigDecimal refundAmount);
|
||||
|
||||
/**
|
||||
* 批量更新套餐结束时间
|
||||
|
|
|
@ -640,9 +640,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
|
||||
<update id="addRefundAmount">
|
||||
update sm_transaction_bill
|
||||
set refund_amount = refund_amount + #{refundAmount},
|
||||
refund_mch_amount = refund_mch_amount + #{refundMchAmount},
|
||||
refund_service_amount = refund_service_amount + #{refundServiceAmount}
|
||||
set refund_amount = refund_amount + #{refundAmount}
|
||||
where bill_id = #{billId}
|
||||
</update>
|
||||
|
||||
|
|
|
@ -6,12 +6,18 @@ import com.ruoyi.ss.device.domain.vo.DeviceVO;
|
|||
import com.ruoyi.ss.payBill.domain.vo.DoPayVO;
|
||||
import com.ruoyi.ss.transactionBill.domain.TransactionBill;
|
||||
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
|
||||
import com.ruoyi.ss.transactionBill.domain.bo.*;
|
||||
import com.ruoyi.ss.transactionBill.domain.dto.RechargePayBO;
|
||||
import com.ruoyi.ss.transactionBill.domain.vo.*;
|
||||
import com.ruoyi.ss.transactionBill.domain.bo.EndUseBO;
|
||||
import com.ruoyi.ss.transactionBill.domain.bo.RechargeBO;
|
||||
import com.ruoyi.ss.transactionBill.domain.bo.RechargePayDepositBO;
|
||||
import com.ruoyi.ss.transactionBill.domain.bo.WithdrawBO;
|
||||
import com.ruoyi.ss.transactionBill.domain.dto.BillRefundDTO;
|
||||
import com.ruoyi.ss.transactionBill.domain.dto.RechargePayBO;
|
||||
import com.ruoyi.ss.transactionBill.domain.dto.WithdrawApprovalDTO;
|
||||
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus;
|
||||
import com.ruoyi.ss.transactionBill.domain.vo.TransactionAmountVO;
|
||||
import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO;
|
||||
import com.ruoyi.ss.transactionBill.domain.vo.TransactionDailyAmountVO;
|
||||
import com.ruoyi.ss.transactionBill.domain.vo.UserWithdrawServiceVO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -207,12 +213,10 @@ public interface TransactionBillService
|
|||
/**
|
||||
* 增加订单退款金额
|
||||
*
|
||||
* @param billId 订单ID
|
||||
* @param refundAmount 退款金额
|
||||
* @param refundMchAmount 商户退款金额
|
||||
* @param refundServiceAmount 退款手续费
|
||||
* @param billId 订单ID
|
||||
* @param refundAmount 退款金额
|
||||
*/
|
||||
int addRefundAmount(Long billId, BigDecimal refundAmount, BigDecimal refundMchAmount, BigDecimal refundServiceAmount);
|
||||
int addRefundAmount(Long billId, BigDecimal refundAmount);
|
||||
|
||||
/**
|
||||
* 查询用户正在使用中的订单
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.ruoyi.ss.payBill.domain.dto.PayBillRefundDTO;
|
|||
import com.ruoyi.ss.payBill.interfaces.AfterPay;
|
||||
import com.ruoyi.ss.payBill.interfaces.AfterRefund;
|
||||
import com.ruoyi.ss.payBill.service.PayBillService;
|
||||
import com.ruoyi.ss.refund.domain.RefundVO;
|
||||
import com.ruoyi.ss.suit.domain.enums.SuitFeeType;
|
||||
import com.ruoyi.ss.transactionBill.domain.TransactionBill;
|
||||
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
|
||||
|
@ -227,17 +228,28 @@ public class RechargePayHandler implements AfterPay, AfterRefund {
|
|||
@Override
|
||||
public int onRefundSuccess(RefundSuccessBO bo) {
|
||||
PayBillVO pay = bo.getPay();
|
||||
RefundVO refund = bo.getRefund();
|
||||
|
||||
TransactionBillVO bill = transactionBillService.selectSmTransactionBillByBillId(pay.getBstId());
|
||||
ServiceUtil.assertion(bill == null, "ID为%s的订单不存在", pay.getBstId());
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
TransactionBill billData = new TransactionBill();
|
||||
billData.setStatus(TransactionBillStatus.REFUNDED.getStatus());
|
||||
TransactionBillQuery billQuery = new TransactionBillQuery();
|
||||
billQuery.setBillId(pay.getBstId());
|
||||
billQuery.setStatus(TransactionBillStatus.REFUNDING.getStatus());
|
||||
int updateBill = transactionBillService.updateByQuery(billData, billQuery);
|
||||
ServiceUtil.assertion(updateBill != 1, "修改原订单状态失败");
|
||||
// 修改原订单状态
|
||||
if (!TransactionBillStatus.REFUNDED.getStatus().equals(bill.getStatus())) {
|
||||
TransactionBill billData = new TransactionBill();
|
||||
billData.setStatus(TransactionBillStatus.REFUNDED.getStatus());
|
||||
TransactionBillQuery billQuery = new TransactionBillQuery();
|
||||
billQuery.setBillId(pay.getBstId());
|
||||
billQuery.setStatusList(TransactionBillStatus.canRefund());
|
||||
int updateBill = transactionBillService.updateByQuery(billData, billQuery);
|
||||
ServiceUtil.assertion(updateBill != 1, "修改原订单状态失败");
|
||||
}
|
||||
|
||||
return updateBill;
|
||||
// 修改原订单的已退款金额
|
||||
int updateRefundAmount = transactionBillService.addRefundAmount(pay.getBstId(), refund.getAmount());
|
||||
ServiceUtil.assertion(updateRefundAmount != 1, "修改原订单的退款金额失败");
|
||||
|
||||
return updateRefundAmount;
|
||||
});
|
||||
|
||||
return result == null ? 0 : result;
|
||||
|
|
|
@ -1555,31 +1555,32 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
public int refund(BillRefundDTO dto) {
|
||||
// 校验订单
|
||||
TransactionBillVO bill = this.selectSmTransactionBillByBillId(dto.getBillId());
|
||||
ServiceUtil.assertion(bill == null, "待退款的订单不存在");
|
||||
ServiceUtil.assertion(dto.getRefundAmount().compareTo(bill.getMoney()) > 0, "退款金额不允许大于订单金额");
|
||||
ServiceUtil.assertion(!TransactionBillStatus.SUCCESS.getStatus().equals(bill.getStatus()), "当前订单状态不允许退款");
|
||||
ServiceUtil.assertion(bill == null, "ID为%s的订单不存在", dto.getBillId());
|
||||
ServiceUtil.assertion(dto.getRefundAmount().compareTo(bill.getMoney()) > 0, "订单编号为%s的订单退款金额不允许大于订单金额", bill.getBillNo());
|
||||
ServiceUtil.assertion(!TransactionBillStatus.canRefund().contains(bill.getStatus()), "订单编号为%s的订单状态不允许退款", bill.getBillNo());
|
||||
|
||||
// 是否判断订单已完成
|
||||
if (dto.getCheckFinish() != null && dto.getCheckFinish()) {
|
||||
ServiceUtil.assertion(bill.getIsFinished() == null || !bill.getIsFinished(), "当前订单未完成,不允许退款");
|
||||
ServiceUtil.assertion(bill.getIsFinished() == null || !bill.getIsFinished(), "订单编号为%s的订单未完成,不允许退款", bill.getBillNo());
|
||||
}
|
||||
|
||||
// 拼接分成列表
|
||||
transactionAssembler.assembleBonusList(bill);
|
||||
List<BonusVO> bonusList = bill.getBonusList();
|
||||
ServiceUtil.assertion(CollectionUtils.isEmptyElement(bonusList), "当前订单没有收益信息,无法退款");
|
||||
ServiceUtil.assertion(CollectionUtils.isEmptyElement(bonusList), "订单编号为%s的订单没有收益信息,无法退款", bill.getBillNo());
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
// 修改订单状态
|
||||
TransactionBill data = new TransactionBill();
|
||||
data.setStatus(TransactionBillStatus.REFUNDING.getStatus());
|
||||
TransactionBillQuery billQuery = new TransactionBillQuery();
|
||||
billQuery.setBillId(dto.getBillId());
|
||||
billQuery.setStatus(TransactionBillStatus.SUCCESS.getStatus());
|
||||
if (dto.getCheckFinish() != null && dto.getCheckFinish()) {
|
||||
billQuery.setIsFinished(true);
|
||||
}
|
||||
int updateBill = this.updateByQuery(data, billQuery);
|
||||
ServiceUtil.assertion(updateBill != 1, "退款时修改订单状态失败,订单状态已发生改变,请刷新后重试");
|
||||
// TransactionBill data = new TransactionBill();
|
||||
// data.setStatus(TransactionBillStatus.REFUNDING.getStatus());
|
||||
// TransactionBillQuery billQuery = new TransactionBillQuery();
|
||||
// billQuery.setBillId(dto.getBillId());
|
||||
// billQuery.setStatusList(TransactionBillStatus.canRefund());
|
||||
// if (dto.getCheckFinish() != null && dto.getCheckFinish()) {
|
||||
// billQuery.setIsFinished(true);
|
||||
// }
|
||||
// int updateBill = this.updateByQuery(data, billQuery);
|
||||
// ServiceUtil.assertion(updateBill != 1, "退款时修改订单状态失败,订单状态已发生改变,请刷新后重试");
|
||||
|
||||
// 分成方余额按照比例扣减
|
||||
// 按比例计算退款金额
|
||||
|
@ -1587,10 +1588,6 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
int updateRefundBonus = this.updateRefundBonus(bonusList, refundAmount, bill.getMoney());
|
||||
ServiceUtil.assertion(updateRefundBonus != bonusList.size(), "商户余额更新失败");
|
||||
|
||||
// 修改原订单的退款金额
|
||||
int updateRefundAmount = this.addRefundAmount(bill.getBillId(), refundAmount, BigDecimal.ZERO, BigDecimal.ZERO);
|
||||
ServiceUtil.assertion(updateRefundAmount != 1, "修改原订单的退款金额失败");
|
||||
|
||||
// 发起退款
|
||||
PayBillRefundDTO refundDto = new PayBillRefundDTO();
|
||||
refundDto.setPayId(bill.getPayId());
|
||||
|
@ -1599,7 +1596,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
int refund = payBillService.refund(refundDto);
|
||||
ServiceUtil.assertion(refund != 1, "退款失败");
|
||||
|
||||
return updateBill;
|
||||
return refund;
|
||||
});
|
||||
|
||||
return result == null ? 0 : result;
|
||||
|
@ -1716,11 +1713,11 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
}
|
||||
|
||||
@Override
|
||||
public int addRefundAmount(Long billId, BigDecimal refundAmount, BigDecimal refundMchAmount, BigDecimal refundServiceAmount) {
|
||||
public int addRefundAmount(Long billId, BigDecimal refundAmount) {
|
||||
if (billId == null) {
|
||||
return 0;
|
||||
}
|
||||
return transactionBillMapper.addRefundAmount(billId, refundAmount, refundMchAmount, refundServiceAmount);
|
||||
return transactionBillMapper.addRefundAmount(billId, refundAmount);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue
Block a user