[fix]修改提现逻辑

This commit is contained in:
wangqx 2025-09-26 10:24:52 +08:00
parent 94e891a510
commit a8fe4bb1a6
5 changed files with 59 additions and 46 deletions

View File

@ -40,7 +40,7 @@ public class R<T> implements Serializable {
return restResult(null, SUCCESS, "操作成功");
}
public static <T> R<T> notLogin() {
return restResult(null, FAIL, "用户未登录");
return restResult(null, ResultCode.USER_CONNECT_LOGIN_ERROR.code(),ResultCode.USER_CONNECT_LOGIN_ERROR.message());
}
public static <T> R<T> ok(T data) {

View File

@ -6,17 +6,29 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.member.annotation.MemberFillMethod;
import com.wzj.soopin.transaction.convert.WithdrawConvert;
import com.wzj.soopin.transaction.domain.bo.WithdrawBO;
import com.wzj.soopin.transaction.domain.entity.TransferDetailEntityNew;
import com.wzj.soopin.transaction.domain.po.Withdraw;
import com.wzj.soopin.transaction.domain.vo.WithdrawVO;
import com.wzj.soopin.transaction.enums.WithdrawStatus;
import com.wzj.soopin.transaction.service.IWithdrawService;
import com.wzj.soopin.transaction.service.impl.WxPayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.mapstruct.Context;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
/**
* 用户封禁
*/
@ -24,10 +36,12 @@ import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/trans/withdraw")
@RequiredArgsConstructor
@Slf4j
public class WithdrawController {
private final IWithdrawService service;
private final WithdrawConvert convert;
private final WxPayService wxPayService;
@Operation(summary = "查询提现列表")
@PostMapping("/list")
@ -65,4 +79,34 @@ public class WithdrawController {
public R<Object> remove(@PathVariable Long id) {
return R.ok(service.removeById(id));
}
/**
* 微信商户零线转账 - 回调通知
*
* @return
* @Context注解 把HTTP请求上下文对象注入进来HttpServletRequestHttpServletResponseUriInfo
*/
@Operation(summary = "微信商户零线转账 - 回调通知")
@RequestMapping(value = "/callback", method = {RequestMethod.GET, RequestMethod.POST})
@Log(title = "微信商户零线转账 - 回调通知", businessType = BusinessType.INSERT)
public R wxPayCallback(@Context HttpServletRequest request) {
log.info("微信商户零线转账 - 回调通知 /wxpay/callback");
TransferDetailEntityNew transferDetailEntityNew = wxPayService.wxPaySuccessCallback(request);
//获取提现的id
Long id = Long.valueOf(transferDetailEntityNew.getOutBillNo());
//更新提现状态
service.withdrawCallback(id);
return R.ok();
}
@Operation(summary = "撤销转账")
@Log(title = "撤销转账", businessType = BusinessType.DELETE)
@DeleteMapping("/cancel{id}")
public R<Object> cancel(@PathVariable Long id) {
return R.ok(service.removeById(id));
}
}

View File

@ -8,7 +8,7 @@ import com.wzj.soopin.transaction.domain.po.Withdraw;
public interface IWithdrawService extends IService<Withdraw> {
boolean audit(WithdrawBO bo);
boolean withdrawCallback(WithdrawBO withdraw);
boolean withdrawCallback(Long id);
InitiateBatchTransferResponseNew withdraw (Withdraw withdraw);

View File

@ -54,15 +54,6 @@ import java.util.*;
public class WithdrawServiceImpl extends ServiceImpl<WithdrawMapper, Withdraw> implements IWithdrawService {
private final IMemberAccountService memberAccountService;
private final ISysTenantAccountService sysTenantAccountService;
/**
* 易生账户充值服务
*/
private final IEasypayService easypayService;
private final IAccountBillService accountBillService;
private final WxPayService wxPayService;
@ -100,19 +91,12 @@ public class WithdrawServiceImpl extends ServiceImpl<WithdrawMapper, Withdraw> i
}
//sender
//receiver
//object
//action
private InitiateBatchTransferRequestNew buildWechatPayParam(Withdraw withdraw) {
InitiateBatchTransferRequestNew request = new InitiateBatchTransferRequestNew();
//商户AppID
request.setAppid(wechatPayConfig.getAppId());
//商户单号
request.setOutBillNo(withdraw.getCode());
request.setOutBillNo(withdraw.getId()+"");
request.setTransferAmount(withdraw.getMoney().multiply(BigDecimal.valueOf(100)).intValue());
//转账场景ID
// /** 转账场景ID 说明:该批次转账使用的转账场景,如不填写则使用商家的默认场景,如无默认场景可为空,可前往“商家转账到零钱-前往功能”中申请。 如1001-现金营销 */
@ -147,26 +131,17 @@ public class WithdrawServiceImpl extends ServiceImpl<WithdrawMapper, Withdraw> i
}
@Override
public boolean withdrawCallback(WithdrawBO withdraw) {
MemberAccount memberAccount = memberAccountService.getMemberAccount(withdraw.getMemberId());
BigDecimal balance = memberAccount.getWallet();
////提现成功后更新会员账户余额
//从易生取别用自己计算的
//// TODO: 2025/6/21 测试的时候用计算的 测试完用易生的
BigDecimal finalBalance = balance.subtract(withdraw.getMoney());
EasypayAccountVO easypayAccountVO = easypayService.getEasypayAccount(withdraw.getMemberId());
memberAccountService.updateById(memberAccount.toBuilder().wallet(finalBalance).build());
//生成账户变动记录bh
AccountBill memberAccountChangeRecord = AccountBill.builder()
.accountId(withdraw.getMemberId())
.moneyBalance(finalBalance)
.beforeBalance(balance)
.afterBalance(easypayAccountVO.getBalance())
.changeType(AccountBillChangeTypeEnum.OUT.getCode())
.changeDesc("提现")
.source(AccountBillSourceEnum.WITHDRAW.getCode()).build();
accountBillService.save(memberAccountChangeRecord);
public boolean withdrawCallback(Long id) {
Withdraw withdraw = getById(id);
if (withdraw == null) {
throw new RuntimeException("提现申请不存在");
}
if (!Objects.equals(WithdrawStatus.PENDING.getCode(), withdraw.getStatus())) {
throw new RuntimeException("提现申请已处理");
}
withdraw.setStatus(WithdrawStatus.SUCCESS.getCode());
updateById(withdraw);
return true;
}
@ -233,7 +208,7 @@ public class WithdrawServiceImpl extends ServiceImpl<WithdrawMapper, Withdraw> i
withdraw = Withdraw.builder().id(withdraw.getId())
.auditReason(withdraw.getAuditReason())
.auditTime(LocalDateTime.now())
.auditStatus(withdraw.getAuditStatus())
.status(WithdrawStatus.PENDING.getCode())
.build();
this.updateById(withdraw);

View File

@ -169,15 +169,9 @@ public class WxPayService {
.body(requestBody)
.build();
// 2. 构建Config RSAAutoCertificateConfig
Config config = new RSAAutoCertificateConfig.Builder()
.merchantId(WechatPayConfig.getMchId())
.privateKeyFromPath(WechatPayConfig.getPrivateKeyPath())
.merchantSerialNumber(WechatPayConfig.getMchSerialNo())
.apiV3Key(WechatPayConfig.getApiV3Key())
.build();
logger.info("WxPayService.wxPaySuccessCallback request : wechatPaySerial is [{}] , wechatSignature is [{}] , wechatTimestamp is [{}] , wechatpayNonce is [{}] , requestBody is [{}]",wechatPaySerial,wechatSignature,wechatTimestamp,wechatpayNonce,requestBody);
// 3. 初始化 NotificationParser
NotificationParser parser = new NotificationParser((NotificationConfig) config);
NotificationParser parser = new NotificationParser( config);
try {
TransferDetailEntityNew entity = parser.parse(requestParam, TransferDetailEntityNew.class);
logger.info("WxPayService.wxPaySuccessCallback responseBody: {}", entity != null ? JSON.toJSONString(entity) : null);