guomengjiao дней назад: 6
Родитель
Сommit
ca5bd1539d

+ 49 - 0
renren-admin/src/main/java/io/renren/modules/qyh/api/ApiWithdrawController.java

@@ -1,19 +1,28 @@
 package io.renren.modules.qyh.api;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import io.renren.common.annotation.RepeatSubmit;
+import io.renren.common.enums.WithdrawAuditStateEnum;
+import io.renren.common.enums.WithdrawPaymentTermEnum;
 import io.renren.common.utils.Constant;
 import io.renren.common.utils.PageUtils;
 import io.renren.common.utils.R;
+import io.renren.modules.qmgj.wxpayutil.NewWxPayUtil;
 import io.renren.modules.qyh.entity.WithdrawInfoEntity;
 import io.renren.modules.qyh.model.vo.MyWalletVO;
 import io.renren.modules.qyh.service.MemberWalletService;
 import io.renren.modules.qyh.service.WithdrawInfoService;
+import io.renren.modules.wechat.entity.TransferNotification;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
 import java.util.Map;
 
 /**
@@ -30,6 +39,9 @@ public class ApiWithdrawController {
     @Autowired
     private MemberWalletService memberWalletService;
 
+    @Autowired
+    private NewWxPayUtil wxPayUtil;
+
     /**
      * 我的钱包
      */
@@ -61,4 +73,41 @@ public class ApiWithdrawController {
         return R.ok().put("page", page);
     }
 
+    /**
+     * 转账回调
+     */
+    @PostMapping(value = "transferCallback", produces = MediaType.APPLICATION_JSON_VALUE)
+    @ResponseBody
+    @RepeatSubmit()
+    public String transferCallback(HttpServletRequest request) {
+        try {
+            // 1. 验签并解析通知
+            TransferNotification notification = wxPayUtil.transferNotify(request);
+            // 2. 根据业务单号查询提现记录
+            String outBatchNo = notification.getOutBatchNo();
+            WithdrawInfoEntity entity = withdrawInfoService.getOne(
+                    new LambdaQueryWrapper<WithdrawInfoEntity>()
+                            .eq(WithdrawInfoEntity::getBusinessCode, outBatchNo));
+            if (entity == null) {
+                return "{\"code\":\"FAIL\",\"message\":\"订单不存在\"}";
+            }
+            if (!entity.getPaymentTerm().equals(WithdrawPaymentTermEnum.WECHAT.value())) {
+                return "{\"code\":\"FAIL\",\"message\":\"订单类型不是微信支付\"}";
+            }
+            if (!entity.getAuditState().equals(WithdrawAuditStateEnum.AUDIT_PASS.value())) {
+                return "{\"code\":\"FAIL\",\"message\":\"订单状态不是审核通过\"}";
+            }
+            // 微信回调返回的金额单位是分,需要转换为元后比较
+            BigDecimal successAmountYuan = new BigDecimal(notification.getSuccessAmount())
+                    .divide(new BigDecimal("100"), 2, BigDecimal.ROUND_HALF_UP);
+            if (entity.getMoney().compareTo(successAmountYuan) != 0) {
+                return "{\"code\":\"FAIL\",\"message\":\"金额不一致\"}";
+            }
+            // 处理提现状态
+            withdrawInfoService.handleTransferStatus(entity, notification.getBatchStatus(), notification.getBatchId());
+            return "{\"code\":\"SUCCESS\",\"message\":\"成功\"}";
+        } catch (Exception e) {
+            return "{\"code\":\"FAIL\",\"message\":\"处理失败\"}";
+        }
+    }
 }

+ 5 - 0
renren-admin/src/main/java/io/renren/modules/qyh/service/WithdrawInfoService.java

@@ -34,4 +34,9 @@ public interface WithdrawInfoService extends IService<WithdrawInfoEntity> {
     Map<String, BigDecimal> getWithdrawStatistics(Map<String, Object> params);
 
     WithdrawInfoVO info(Long id);
+
+    /**
+     * 处理转账状态
+     */
+    void handleTransferStatus(WithdrawInfoEntity entity, String batchStatus, String batchId);
 }

+ 25 - 17
renren-admin/src/main/java/io/renren/modules/qyh/service/impl/WithdrawInfoServiceImpl.java

@@ -140,6 +140,7 @@ public class WithdrawInfoServiceImpl extends ServiceImpl<WithdrawInfoMapper, Wit
         entity.setAuditExplain(dto.getAuditExplain());
         entity.setAuditPer(dto.getAuditPer());
         entity.setAuditTime(LocalDateTime.now());
+        baseMapper.updateById(entity);
         // 审核通过
         if (auditState.equals(WithdrawAuditStateEnum.AUDIT_PASS.value())) {
             // 这里调用微信接口进行打款
@@ -150,7 +151,6 @@ public class WithdrawInfoServiceImpl extends ServiceImpl<WithdrawInfoMapper, Wit
         } else {
             throw new RRException("审核状态不正确");
         }
-        baseMapper.updateById(entity);
     }
 
     private void wxTransfer(WithdrawInfoEntity entity) {
@@ -193,27 +193,14 @@ public class WithdrawInfoServiceImpl extends ServiceImpl<WithdrawInfoMapper, Wit
         log.info("微信转账响应:{}", JSONUtil.toJsonStr(response));
         // 4. 处理转账结果
         if (response != null) {
-            String batchStatus = response.getBatchStatus();
-            // FINISHED(已完成)表示成功
-            if (BatchStatusEnum.FINISHED.value().equals(batchStatus)) {
-                // 保存微信批次单号
-                entity.setThirdTransactionNo(response.getBatchId());
-                entity.setRemitTime(LocalDateTime.now());
-                entity.setAuditState(WithdrawAuditStateEnum.REMIT_SUCCESS.value());
-                //扣余额
-                memberWalletService.deductBalance(entity.getMemberId(), entity.getMoney());
-            } else if (BatchStatusEnum.CLOSED.value().equals(batchStatus)) {
-                // 转账失败,退回余额
-                memberWalletService.unfreezeAndRefund(entity.getMemberId(), entity.getMoney());
-                entity.setAuditState(WithdrawAuditStateEnum.AUDIT_REFUSE.value());
-                entity.setAuditExplain("打款失败:" + batchStatus);
-                entity.setThirdTransactionNo(response.getBatchId());
-            }
+            handleTransferStatus(entity, response.getBatchStatus(), response.getBatchId());
         } else {
             throw new RRException("微信转账失败");
         }
     }
 
+
+
     @Override
     public Map<String, BigDecimal> getWithdrawStatistics(Map<String, Object> params) {
         return baseMapper.getWithdrawStatistics(params);
@@ -236,4 +223,25 @@ public class WithdrawInfoServiceImpl extends ServiceImpl<WithdrawInfoMapper, Wit
         withdrawInfoVO.setAvailableAmount(myWallet.getAvailableAmount());
         return withdrawInfoVO;
     }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void handleTransferStatus(WithdrawInfoEntity entity, String batchStatus, String batchId) {
+        // FINISHED(已完成)表示成功
+        if (BatchStatusEnum.FINISHED.value().equals(batchStatus)) {
+            // 保存微信批次单号
+            entity.setThirdTransactionNo(batchId);
+            entity.setRemitTime(LocalDateTime.now());
+            entity.setAuditState(WithdrawAuditStateEnum.REMIT_SUCCESS.value());
+            //扣余额
+            memberWalletService.deductBalance(entity.getMemberId(), entity.getMoney());
+        } else if (BatchStatusEnum.CLOSED.value().equals(batchStatus)) {
+            // 转账失败,退回余额
+            memberWalletService.unfreezeAndRefund(entity.getMemberId(), entity.getMoney());
+            entity.setAuditState(WithdrawAuditStateEnum.AUDIT_REFUSE.value());
+            entity.setAuditExplain("打款失败:" + batchStatus);
+            entity.setThirdTransactionNo(batchId);
+        }
+        baseMapper.updateById(entity);
+    }
 }

+ 8 - 8
renren-admin/src/main/java/io/renren/modules/wechat/entity/TransferNotification.java

@@ -15,9 +15,9 @@ public class TransferNotification {
     @SerializedName("total_num")
     private Integer totalNum;
     @SerializedName("total_amount")
-    private Integer totalAmount;
+    private Long totalAmount;
     @SerializedName("success_amount")
-    private Integer successAmount;
+    private Long successAmount;
     @SerializedName("success_num")
     private Integer successNum;
     @SerializedName("update_time")
@@ -57,19 +57,19 @@ public class TransferNotification {
         this.totalNum = totalNum;
     }
 
-    public Integer getTotalAmount() {
+    public Long getTotalAmount() {
         return totalAmount;
     }
 
-    public void setTotalAmount(Integer totalAmount) {
+    public void setTotalAmount(Long totalAmount) {
         this.totalAmount = totalAmount;
     }
 
-    public Integer getSuccessAmount() {
+    public Long getSuccessAmount() {
         return successAmount;
     }
 
-    public void setSuccessAmount(Integer successAmount) {
+    public void setSuccessAmount(Long successAmount) {
         this.successAmount = successAmount;
     }
 
@@ -116,11 +116,11 @@ public class TransferNotification {
             notification.totalNum = totalNum;
             return this;
         }
-        public Builder totalAmount(Integer totalAmount) {
+        public Builder totalAmount(Long totalAmount) {
             notification.totalAmount = totalAmount;
             return this;
         }
-        public Builder successAmount(Integer successAmount) {
+        public Builder successAmount(Long successAmount) {
             notification.successAmount = successAmount;
             return this;
         }

+ 1 - 1
renren-admin/src/main/resources/pay.properties

@@ -14,7 +14,7 @@ pay.notify.meet.url=https://qingyunhui.songlanyun.com/qyh/api/order/meetPayCallb
 ## 活动支付回调地址
 pay.notify.activity.url=https://qingyunhui.songlanyun.com/qyh/api/act/register/wx/back
 pay.notify.enterprise.url=https://qingyunhui.songlanyun.com/qyh/api/enterprise/enterprisePaysCallback
-pay.notify.transfer.url=https://frp.songlanyun.com/qyh/api/transfer/notify
+pay.notify.transfer.url=https://frp.songlanyun.com/qyh/api/withdraw/transferCallback
 
 
 # 本地 退款P12文件目录