From a8fe4bb1a6f993d79e2be2a303a727c616180266 Mon Sep 17 00:00:00 2001 From: wangqx Date: Fri, 26 Sep 2025 10:24:52 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=E4=BF=AE=E6=94=B9=E6=8F=90=E7=8E=B0?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/dromara/common/core/domain/R.java | 2 +- .../controller/WithdrawController.java | 44 +++++++++++++++++ .../transaction/service/IWithdrawService.java | 2 +- .../service/impl/WithdrawServiceImpl.java | 49 +++++-------------- .../service/impl/WxPayService.java | 8 +-- 5 files changed, 59 insertions(+), 46 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/R.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/R.java index 4d5eafc84..94c383beb 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/R.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/R.java @@ -40,7 +40,7 @@ public class R implements Serializable { return restResult(null, SUCCESS, "操作成功"); } public static R notLogin() { - return restResult(null, FAIL, "用户未登录"); + return restResult(null, ResultCode.USER_CONNECT_LOGIN_ERROR.code(),ResultCode.USER_CONNECT_LOGIN_ERROR.message()); } public static R ok(T data) { diff --git a/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/controller/WithdrawController.java b/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/controller/WithdrawController.java index 1502b76b0..cc4c6b584 100644 --- a/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/controller/WithdrawController.java +++ b/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/controller/WithdrawController.java @@ -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 remove(@PathVariable Long id) { return R.ok(service.removeById(id)); } + + + /** + * 微信商户零线转账 - 回调通知 + * + * @return + * @Context注解 把HTTP请求上下文对象注入进来,HttpServletRequest、HttpServletResponse、UriInfo 等 + */ + @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 cancel(@PathVariable Long id) { + return R.ok(service.removeById(id)); + } + } diff --git a/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/service/IWithdrawService.java b/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/service/IWithdrawService.java index 4d1a07fad..ea420c09f 100644 --- a/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/service/IWithdrawService.java +++ b/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/service/IWithdrawService.java @@ -8,7 +8,7 @@ import com.wzj.soopin.transaction.domain.po.Withdraw; public interface IWithdrawService extends IService { boolean audit(WithdrawBO bo); - boolean withdrawCallback(WithdrawBO withdraw); + boolean withdrawCallback(Long id); InitiateBatchTransferResponseNew withdraw (Withdraw withdraw); diff --git a/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/service/impl/WithdrawServiceImpl.java b/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/service/impl/WithdrawServiceImpl.java index ec6e471a9..da784522c 100644 --- a/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/service/impl/WithdrawServiceImpl.java +++ b/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/service/impl/WithdrawServiceImpl.java @@ -54,15 +54,6 @@ import java.util.*; public class WithdrawServiceImpl extends ServiceImpl 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 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 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 i withdraw = Withdraw.builder().id(withdraw.getId()) .auditReason(withdraw.getAuditReason()) .auditTime(LocalDateTime.now()) - .auditStatus(withdraw.getAuditStatus()) + .status(WithdrawStatus.PENDING.getCode()) .build(); this.updateById(withdraw); diff --git a/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/service/impl/WxPayService.java b/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/service/impl/WxPayService.java index 906b47459..a1a60a762 100644 --- a/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/service/impl/WxPayService.java +++ b/ruoyi-modules/ruoyi-transaction/src/main/java/com/wzj/soopin/transaction/service/impl/WxPayService.java @@ -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);