Sfoglia il codice sorgente

fix bug 微信支付回调余额更新

skyline 2 anni fa
parent
commit
6d0cca10cf

+ 2 - 2
miniapp/src/main/java/com/kym/miniapp/aspect/AppLogAspect.java

@@ -1,7 +1,7 @@
 package com.kym.miniapp.aspect;
 
 import cn.dev33.satoken.stp.StpUtil;
-import com.google.gson.Gson;
+import com.alibaba.fastjson2.JSON;
 import com.kym.common.annotation.ApiLog;
 import com.kym.common.utils.HttpContextUtils;
 import com.kym.common.utils.IDGenerator;
@@ -76,7 +76,7 @@ public class AppLogAspect {
         Object[] args = joinPoint.getArgs();
 
         if (!apiLog.ignoreParams()) {
-            String params = new Gson().toJson(args);
+            String params = JSON.toJSON(args).toString();
             appLog.setRequestParam(params);
         }
         //获取request

+ 12 - 1
service/src/main/java/com/kym/service/wechat/impl/WxPayServiceImpl.java

@@ -8,8 +8,10 @@ import com.kym.common.config.WxPayConfig;
 import com.kym.common.constant.ResponseEnum;
 import com.kym.common.exception.BusinessException;
 import com.kym.common.utils.OrderUtils;
+import com.kym.entity.miniapp.Account;
 import com.kym.entity.miniapp.PayLog;
 import com.kym.entity.miniapp.WalletDetail;
+import com.kym.service.miniapp.AccountService;
 import com.kym.service.miniapp.PayLogService;
 import com.kym.service.miniapp.WalletDetailService;
 import com.kym.service.wechat.WxPayService;
@@ -32,6 +34,7 @@ import org.springframework.core.io.ClassPathResource;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -60,10 +63,13 @@ public class WxPayServiceImpl implements WxPayService {
 
     private final PayLogService payLogService;
 
-    public WxPayServiceImpl(WxPayConfig conf, WalletDetailService walletDetailService, PayLogService payLogService) {
+    private final AccountService accountService;
+
+    public WxPayServiceImpl(WxPayConfig conf, WalletDetailService walletDetailService, PayLogService payLogService, AccountService accountService) {
         this.conf = conf;
         this.walletDetailService = walletDetailService;
         this.payLogService = payLogService;
+        this.accountService = accountService;
     }
 
     /**
@@ -162,6 +168,7 @@ public class WxPayServiceImpl implements WxPayService {
 
     @SneakyThrows
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public ResponseEntity.BodyBuilder wxNotify(HttpServletRequest request) {
         var no = RandomUtil.randomInt(1000, 9999);
         var signature = request.getHeader("Wechatpay-Signature");
@@ -232,6 +239,10 @@ public class WxPayServiceImpl implements WxPayService {
                 payLog.setPayerCurrency(transaction.getAmount().getPayerCurrency());
                 payLogService.save(payLog);
                 LOGGER.info("微信支付回调{}:业务处理结束", no);
+                // 更新余额
+                accountService.lambdaUpdate().setSql("balance = (balance+%d)".formatted(transaction.getAmount().getTotal()))
+                        .eq(Account::getUserId, walletDetail.getUserId()).update();
+
             } else {
                 LOGGER.error("微信支付通知处理异常,资金流水为空,回调信息:{}", transaction);
                 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR);