|
|
@@ -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);
|