From 75a2623173bcc4a235aa1f99f7ef28519186160b Mon Sep 17 00:00:00 2001
From: yanghb <yanghb>
Date: 星期五, 21 四月 2023 11:24:25 +0800
Subject: [PATCH] 代码调整

---
 UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/WithdrawalServiceImpl.java |   77 ++++++++++++++++++++++++++++++--------
 1 files changed, 60 insertions(+), 17 deletions(-)

diff --git a/UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/WithdrawalServiceImpl.java b/UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/WithdrawalServiceImpl.java
index 2cacd4e..9dc5918 100644
--- a/UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/WithdrawalServiceImpl.java
+++ b/UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/WithdrawalServiceImpl.java
@@ -2,13 +2,14 @@
 
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
 import com.stylefeng.guns.modular.system.dao.WithdrawalMapper;
+import com.stylefeng.guns.modular.system.model.BankCard;
 import com.stylefeng.guns.modular.system.model.Driver;
 import com.stylefeng.guns.modular.system.model.UserInfo;
 import com.stylefeng.guns.modular.system.model.Withdrawal;
+import com.stylefeng.guns.modular.system.service.IBankCardService;
 import com.stylefeng.guns.modular.system.service.IUserInfoService;
 import com.stylefeng.guns.modular.system.service.IWithdrawalService;
 import com.stylefeng.guns.modular.system.util.ICBCPayUtil;
-import com.stylefeng.guns.modular.system.util.PayMoneyUtil;
 import com.stylefeng.guns.modular.system.util.ResultUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -35,7 +36,7 @@
     private ICBCPayUtil icbcPayUtil;
 
     @Autowired
-    private PayMoneyUtil payMoneyUtil;
+    private IBankCardService bankCardService;
 
     private Map<String, Timer> timerMap = new HashMap<>();
 
@@ -51,7 +52,7 @@
      * @throws Exception
      */
     @Override
-    public ResultUtil withdrawal(Double money, String bankName, String code, String name, Integer uid) throws Exception {
+    public ResultUtil withdrawal(Double money, String code, String name, Integer uid) throws Exception {
         if(money.compareTo(0D) <= 0){
             return ResultUtil.error("提现金额必须大于0");
         }
@@ -65,7 +66,6 @@
 
         Withdrawal withdrawal = new Withdrawal();
         withdrawal.setBalance(userInfo.getBalance());
-        withdrawal.setBankName(bankName);
         withdrawal.setCode(code);
         withdrawal.setFlag(1);
         withdrawal.setInsertTime(new Date());
@@ -74,14 +74,51 @@
         withdrawal.setState(1);
         withdrawal.setUserId(uid);
         withdrawal.setUserType(1);
+
+        ResultUtil<String> transfer = icbcPayUtil.transfer(Double.valueOf(withdrawal.getMoney() * 100).longValue(), withdrawal.getCode(), withdrawal.getName());
+        if(transfer.getCode() != 200){
+            return transfer;
+        }
+        withdrawal.setSerialNo(transfer.getData());
         this.insert(withdrawal);
 
-        double v = new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(withdrawal.getMoney())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        double v = new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
         userInfo.setBalance(v);
         userInfoService.updateById(userInfo);
         return ResultUtil.success();
     }
 
+    @Override
+    public ResultUtil withdrawal1(Double money, String acctName, Integer bankCardId, Integer uid) throws Exception {
+        if(money.compareTo(0D) <= 0){
+            return ResultUtil.error("提现金额必须大于0");
+        }
+        UserInfo userInfo = userInfoService.selectById(uid);
+        if(null == userInfo.getBalance()){
+            return ResultUtil.error("账户没有余额,不能提现");
+        }
+        if(userInfo.getBalance().compareTo(money) < 0){
+            return ResultUtil.error("提现金额必须小于账户余额");
+        }
+
+        BankCard bankCard = bankCardService.selectById(bankCardId);
+        Withdrawal withdrawal = new Withdrawal();
+        withdrawal.setBalance(userInfo.getBalance());
+        withdrawal.setCode(bankCard.getCode());
+        withdrawal.setFlag(1);
+        withdrawal.setInsertTime(new Date());
+        withdrawal.setMoney(money);
+        withdrawal.setName(acctName);
+        withdrawal.setState(1);
+        withdrawal.setUserId(uid);
+        withdrawal.setUserType(1);
+        this.insert(withdrawal);
+
+        double v = new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+        userInfo.setBalance(v);
+        userInfoService.updateById(userInfo);
+        return ResultUtil.success();
+    }
 
     /**
      * 获取历史提交数
@@ -118,26 +155,28 @@
             TimerTask timerTask = new TimerTask() {
                 @Override
                 public void run() {
-                    try {
-                        Map<String, String> map = payMoneyUtil.wxPayBank("用户提现", withdrawal.getMoney().toString(), withdrawal.getId().toString(), withdrawal.getCode(), withdrawal.getName(), withdrawal.getBankName());
-                        if("SUCCESS".equals(map.get("return_code"))){
-                            withdrawal.setSerialNo(map.get("payment_no"));
-                            withdrawal.setState(2);
+                    Integer integer = icbcPayUtil.queryTransfer(withdrawal.getSerialNo());
+                    if(integer == 0){//交易成功
+                        withdrawal.setState(2);
+                        WithdrawalServiceImpl.this.updateById(withdrawal);
+
+                        Timer timer = timerMap.get(withdrawal.getSerialNo());
+                        timer.cancel();
+                    }
+                    if(integer == 2){//交易拒绝/失败
+                        //还原余额
+                        if(withdrawal.getUserType() == 1){//用户
+                            withdrawal.setState(3);
                             WithdrawalServiceImpl.this.updateById(withdrawal);
-                            Timer timer = timerMap.get(withdrawal.getSerialNo());
-                            timer.cancel();
-                        }else{
+
                             UserInfo userInfo = userInfoService.selectById(withdrawal.getUserId());
                             userInfo.setBalance(new BigDecimal(userInfo.getBalance()).add(new BigDecimal(withdrawal.getMoney())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                             userInfoService.updateById(userInfo);
-                            withdrawal.setState(3);
-                            WithdrawalServiceImpl.this.updateById(withdrawal);
 
                             Timer timer = timerMap.get(withdrawal.getSerialNo());
                             timer.cancel();
                         }
-                    }catch (Exception e){
-                        e.printStackTrace();
+
                     }
                 }
             };
@@ -146,6 +185,10 @@
             timerMap.put(withdrawal.getSerialNo(), timer);
         }
         if(state == 2){//审核拒绝
+            UserInfo userInfo = userInfoService.selectById(withdrawal.getUserId());
+            userInfo.setBalance(new BigDecimal(userInfo.getBalance()).add(new BigDecimal(withdrawal.getMoney())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+            userInfoService.updateById(userInfo);
+
             withdrawal.setState(3);
             this.updateById(withdrawal);
         }

--
Gitblit v1.7.1