提现转账优化

This commit is contained in:
墨大叔 2024-08-12 19:14:35 +08:00
parent 57e507e70a
commit babd77042e
5 changed files with 45 additions and 33 deletions

View File

@ -1,6 +1,7 @@
package com.ruoyi.common.pay.wx.service;
import com.ruoyi.common.config.WxPayConfig;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.pay.wx.domain.BatchTransferAble;
import com.ruoyi.common.pay.wx.domain.request.MyInitiateBatchTransferRequest;
import com.wechat.pay.java.service.transferbatch.TransferBatchService;
@ -34,7 +35,11 @@ public class WxTransferService {
request.setTotalNum(batchTransferAble.transferDetailList().size());
request.setTransferDetailList(batchTransferAble.transferDetailList());
request.setNotifyUrl(wxPayConfig.getTransferNotifyUrl());
return transferBatchService.initiateBatchTransfer(request);
try {
return transferBatchService.initiateBatchTransfer(request);
} catch (com.wechat.pay.java.core.exception.ServiceException e) {
throw new ServiceException(String.format("微信发起转账到零钱出错:%s", e.getErrorMessage()));
}
}
/** 通过微信批次单号查询批次单 */

View File

@ -100,7 +100,7 @@ public class SmBusinessRecordServiceImpl implements ISmBusinessRecordService
/**
* 修改经营记录
*
* @param smBusinessRecord 经营记录
* @param smBusinessRecord 经营记录d
* @return 结果
*/
@Override
@ -154,7 +154,7 @@ public class SmBusinessRecordServiceImpl implements ISmBusinessRecordService
@Override
public BriefVo selectBrief() {
BriefVo brief = redisCache.getCacheObject(CacheConstants.BRIEF);
// if (brief == null ) {
if (brief == null ) {
brief = new BriefVo();
Date now = DateUtils.getNowDate();
@ -223,11 +223,11 @@ public class SmBusinessRecordServiceImpl implements ISmBusinessRecordService
// 今日月费
monthQuery.setBillDate(LocalDate.now());
brief.setTodayMonthAmount(receiveBillService.selectSumOfAmount(monthQuery));
BigDecimal todayMonthAmount = receiveBillService.selectSumOfAmount(monthQuery);
brief.setTodayMonthAmount(todayMonthAmount == null ? BigDecimal.ZERO : todayMonthAmount);
redisCache.setCacheObject(CacheConstants.BRIEF, brief, 30, TimeUnit.MINUTES);
// }
}
return brief;
}

View File

@ -1147,8 +1147,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
* 转账成功后
*/
@Override
public int onTransferSuccess(Long bstId) {
if (bstId == null) {
public int onTransferSuccess(TransferVO transfer) {
if (transfer == null || transfer.getBstId() == null) {
return 0;
}
@ -1158,7 +1158,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
data.setStatus(TransactionBillStatus.WITHDRAW_SUCCESS.getStatus());
TransactionBillQuery query = new TransactionBillQuery();
query.setStatus(TransactionBillStatus.WITHDRAW_PAYING.getStatus());
query.setBillId(bstId);
query.setBillId(transfer.getBstId());
int update = this.updateByQuery(data, query);
ServiceUtil.assertion(update != 1, "修改提现状态失败,提现状态已发生改变");
return update;
@ -1171,29 +1171,28 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
* 转账失败后
*/
@Override
public int onTransferFail(Long bstId) {
if (bstId == null) {
public int onTransferFail(TransferVO transfer) {
if (transfer == null || transfer.getBstId() == null) {
return 0;
}
TransactionBillVO withdraw = this.selectWithdrawById(bstId);
TransactionBillVO withdraw = this.selectWithdrawById(transfer.getBstId());
if (withdraw == null) {
return 0;
}
Integer result = transactionTemplate.execute(status -> {
// 修改提现状态
TransactionBill data = new TransactionBill();
data.setStatus(TransactionBillStatus.WITHDRAW_FAIL.getStatus());
TransactionBillQuery query = new TransactionBillQuery();
query.setStatus(TransactionBillStatus.WITHDRAW_PAYING.getStatus());
query.setBillId(bstId);
query.setBillId(transfer.getBstId());
int update = this.updateByQuery(data, query);
ServiceUtil.assertion(update != 1, "修改提现状态失败,提现状态已发生改变");
// 将提现金额退回用户
userService.addBalance(withdraw.getUserId(), withdraw.getMoney(), String.format("提现%s打款失败", withdraw.getBillNo()), RecordBalanceBstType.WITHDRAW, bstId);
userService.addBalance(withdraw.getUserId(), withdraw.getMoney(), String.format("提现%s打款失败", withdraw.getBillNo()), RecordBalanceBstType.WITHDRAW, transfer.getBstId());
return update;
});

View File

@ -1,5 +1,7 @@
package com.ruoyi.ss.transfer.interfaces;
import com.ruoyi.ss.transfer.domain.TransferVO;
/**
* 转账结束后处理
* @author wjh
@ -7,10 +9,10 @@ package com.ruoyi.ss.transfer.interfaces;
*/
public interface AfterTransfer {
int onTransferSuccess(Long bstId);
int onTransferSuccess(TransferVO transfer);
default int onTransferPartSuccess(Long bstId) {return 1;}
default int onTransferPartSuccess(TransferVO transfer) {return 1;}
int onTransferFail(Long bstId);
int onTransferFail(TransferVO transfer);
}

View File

@ -314,24 +314,30 @@ public class TransferServiceImpl implements TransferService
// 修改业务信息
TransferBstType bstType = TransferBstType.parse(transfer.getBstType());
ServiceUtil.assertion(bstType == null, "业务类型不存在");
ServiceUtil.assertion(bstType.getAfterTransfer() == null, "业务处理器不存在");
if (bstType.getAfterTransfer() != null) {
// 业务处理器
AfterTransfer afterTransfer = SpringUtils.getBean(bstType.getAfterTransfer());
AfterTransfer afterTransfer = SpringUtils.getBean(bstType.getAfterTransfer());
// 查询最新的转账信息
TransferVO dbTransfer = selectTransferByBatchId(transfer.getBatchId());
transferAssembler.assembleDetail(Collections.singletonList(dbTransfer));
// 成功
int bstResult = 0;
if (TransferStatus.TRANSFER_SUCCESS.getStatus().equals(data.getStatus())) {
bstResult = afterTransfer.onTransferSuccess(transfer.getBstId());
// 业务返回值
int bstResult = 0;
// 成功
if (TransferStatus.TRANSFER_SUCCESS.getStatus().equals(data.getStatus())) {
bstResult = afterTransfer.onTransferSuccess(dbTransfer);
}
// 部分成功
else if (TransferStatus.TRANSFER_PART_SUCCESS.getStatus().equals(data.getStatus())) {
bstResult = afterTransfer.onTransferPartSuccess(dbTransfer);
}
// 失败
else if (TransferStatus.TRANSFER_FAIL.getStatus().equals(data.getStatus())) {
bstResult = afterTransfer.onTransferFail(dbTransfer);
}
ServiceUtil.assertion(bstResult == 0, "业务执行失败");
}
// 部分成功
else if (TransferStatus.TRANSFER_PART_SUCCESS.getStatus().equals(data.getStatus())) {
bstResult = afterTransfer.onTransferPartSuccess(transfer.getBstId());
}
// 失败
else if (TransferStatus.TRANSFER_FAIL.getStatus().equals(data.getStatus())) {
bstResult = afterTransfer.onTransferFail(transfer.getBstId());
}
ServiceUtil.assertion(bstResult == 0, "业务执行失败");
return update;
});