Browse Source

支付、提现功能

pengcheng 1 day ago
parent
commit
b2d6b9ce93

+ 0 - 8
ruoyi-newwxpay/pom.xml

@@ -22,13 +22,5 @@
             <groupId>com.github.wechatpay-apiv3</groupId>
             <artifactId>wechatpay-java</artifactId>
         </dependency>
-        <dependency>
-            <groupId>com.ruoyi</groupId>
-            <artifactId>ruoyi-shop</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.ruoyi</groupId>
-            <artifactId>ruoyi-shop</artifactId>
-        </dependency>
     </dependencies>
 </project>

+ 2 - 3
ruoyi-newwxpay/src/main/java/com/ruoyi/newwxpay/transfer/service/TransferService.java

@@ -1,12 +1,11 @@
 package com.ruoyi.newwxpay.transfer.service;
 
-import com.ruoyi.newwxpay.transfer.InitiateSingleTransferResponse;
 import com.ruoyi.newwxpay.transfer.bo.TransferToUser;
 import com.ruoyi.newwxpay.transfer.bo.WxTransferDataDTO;
-import com.ruoyi.shop.distribution.domain.bo.WithdrawBo;
 
 import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.security.GeneralSecurityException;
 
 public interface TransferService {
@@ -16,7 +15,7 @@ public interface TransferService {
      * @return
      * @throws Exception
      */
-    public TransferToUser.TransferToUserResponse transferBills(WithdrawBo withdrawBo);
+    public TransferToUser.TransferToUserResponse transferBills(String outBillNo, String openid, BigDecimal amount);
 
     /**
      * 转账回调

+ 4 - 9
ruoyi-newwxpay/src/main/java/com/ruoyi/newwxpay/transfer/service/impl/TransferServiceImpl.java

@@ -14,15 +14,11 @@ import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.ValidatorUtils;
 import com.ruoyi.newwxpay.config.NewWxPayProperties;
 import com.ruoyi.newwxpay.transfer.*;
-import com.ruoyi.newwxpay.transfer.bo.TransferToUser;
-import com.ruoyi.newwxpay.transfer.bo.WxCallbackResourceDTO;
-import com.ruoyi.newwxpay.transfer.bo.WxTransferDataDTO;
-import com.ruoyi.newwxpay.transfer.bo.WxTransferV3CallbackDTO;
+import com.ruoyi.newwxpay.transfer.bo.*;
 import com.ruoyi.newwxpay.transfer.service.TransferService;
 import com.ruoyi.newwxpay.util.AesUtil;
 import com.ruoyi.newwxpay.util.RequestUtil;
 import com.ruoyi.newwxpay.util.WXPayUtility;
-import com.ruoyi.shop.distribution.domain.bo.WithdrawBo;
 import com.wechat.pay.java.core.Config;
 import com.wechat.pay.java.core.RSAAutoCertificateConfig;
 import com.wechat.pay.java.core.RSAPublicKeyConfig;
@@ -60,7 +56,7 @@ public class TransferServiceImpl implements TransferService {
      * @param withdrawBo
      * @return
      */
-    public TransferToUser.TransferToUserResponse transferBills(WithdrawBo withdrawBo) {
+    public TransferToUser.TransferToUserResponse transferBills(String outBillNo,String openid,BigDecimal amount) {
 
         TransferToUser client = new TransferToUser(
             newWxPayProperties.getMerchant().getMchId(),                    // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756
@@ -72,11 +68,10 @@ public class TransferServiceImpl implements TransferService {
 
         TransferToUser.TransferToUserRequest request = new TransferToUser.TransferToUserRequest();
         request.appid = newWxPayProperties.getMerchant().getAppId();
-        request.outBillNo = withdrawBo.getBusinessCode();
+        request.outBillNo = outBillNo;
         request.transferSceneId = "1005";
-        request.openid = withdrawBo.getOpenid();
+        request.openid = openid;
         // request.userName = client.encrypt("user_name");
-        BigDecimal amount = withdrawBo.getMoney();
         request.transferAmount = amount.multiply(new BigDecimal("100")).longValue();
         request.transferRemark = "佣金报酬";
         request.notifyUrl = newWxPayProperties.getMerchant().getTransferNotifyUrl();

+ 3 - 1
ruoyi-shop/src/main/java/com/ruoyi/shop/distribution/exception/WithdrawExceptionEnum.java

@@ -13,7 +13,9 @@ public enum WithdrawExceptionEnum implements IIntegerEnum {
     Withdraw_IS_NOT_EXISTS(700001, "提现列不存在"),
 
     MEMBER_WITHDRAW_INSUFFICIENT_FUND( 700002, "会员提现额度不足"),
-    MEMBER_WITHDRAW_WAIT_REMIT(700003, "会员还有提现待处理");
+    MEMBER_WITHDRAW_WAIT_REMIT(700003, "会员还有提现待处理"),
+    WITDRAW_OPENID_SUBMIT_ERROR(700004, "提现openid提交错误");
+
 
 
     private Integer code;

+ 15 - 1
ruoyi-shop/src/main/java/com/ruoyi/shop/distribution/service/impl/WithdrawServiceImpl.java

@@ -27,7 +27,10 @@ import com.ruoyi.shop.distribution.enums.WithdrawType;
 import com.ruoyi.shop.distribution.service.IDistributionUserOrderGainsService;
 import com.ruoyi.shop.distribution.service.IUserBillService;
 import com.ruoyi.user.domain.User;
+import com.ruoyi.user.domain.UserThirdIdentity;
+import com.ruoyi.user.enums.UserThirdType;
 import com.ruoyi.user.service.IUserService;
+import com.ruoyi.user.service.IUserThirdIdentityService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
@@ -83,6 +86,11 @@ public class WithdrawServiceImpl implements IWithdrawService {
     @Resource
     private TransferService transferService;
 
+    @Lazy
+    @Resource
+    private IUserThirdIdentityService userThirdIdentityService;
+
+
 
     /**
      * 查询提现列分页
@@ -172,6 +180,7 @@ public class WithdrawServiceImpl implements IWithdrawService {
         boolean flag = baseMapper.insert(add) > 0;
         if (flag) {
             bo.setWithdrawId(add.getWithdrawId());
+            bo.setBusinessCode(add.getBusinessCode());
         }
         return add;
     }
@@ -228,6 +237,11 @@ public class WithdrawServiceImpl implements IWithdrawService {
             case Wechat:
                 //微信
                 //查询用户是否绑定微信
+                UserThirdIdentity wechat = userThirdIdentityService.loadByUserId(user.getId(), UserThirdType.WX_MINI_PROGRAM, true);
+                if (ObjectUtil.isNull(wechat)) {
+                    throw new ServiceException(WithdrawExceptionEnum.WITDRAW_OPENID_SUBMIT_ERROR);
+                }
+                bo.setOpenid(wechat.getIdentityCode());
                 bo.setVerifyStatus(AuditStatus.AUDIT_PASS);
                 this.insertByBo(bo);
                 //TODO 开始打款
@@ -242,7 +256,7 @@ public class WithdrawServiceImpl implements IWithdrawService {
             default:
                 break;
         }
-        return transferService.transferBills(bo);
+        return transferService.transferBills(bo.getBusinessCode(), bo.getOpenid(),bo.getMoney());
 
     }