From 2f37e69bd8ae241a00c0a75b95bef44be8ce8af5 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期五, 01 九月 2023 09:23:23 +0800
Subject: [PATCH] 修改bug

---
 ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TPubWithdrawalController.java |  160 ++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 116 insertions(+), 44 deletions(-)

diff --git a/ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TPubWithdrawalController.java b/ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TPubWithdrawalController.java
index 1bf6156..537ee8b 100644
--- a/ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TPubWithdrawalController.java
+++ b/ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TPubWithdrawalController.java
@@ -1,5 +1,7 @@
 package com.stylefeng.guns.modular.system.controller.general;
 
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.plugins.Page;
 import com.stylefeng.guns.core.base.controller.BaseController;
 import com.stylefeng.guns.core.common.constant.factory.PageFactory;
@@ -8,19 +10,28 @@
 import com.stylefeng.guns.core.util.ExcelExportUtil;
 import com.stylefeng.guns.core.util.SinataUtil;
 import com.stylefeng.guns.core.util.ToolUtil;
+import com.stylefeng.guns.modular.system.util.Tingg.model.*;
+import com.stylefeng.guns.modular.system.model.TDriver;
 import com.stylefeng.guns.modular.system.model.TPubWithdrawal;
 import com.stylefeng.guns.modular.system.model.TSystemNotice;
+import com.stylefeng.guns.modular.system.model.TUser;
+import com.stylefeng.guns.modular.system.service.ITDriverService;
 import com.stylefeng.guns.modular.system.service.ITPubWithdrawalService;
 import com.stylefeng.guns.modular.system.service.ITSystemNoticeService;
-import com.stylefeng.guns.modular.system.util.HttpRequestUtil;
-import com.stylefeng.guns.modular.system.util.PushURL;
+import com.stylefeng.guns.modular.system.service.ITUserService;
+import com.stylefeng.guns.modular.system.util.ResultUtil;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.*;
+import com.stylefeng.guns.modular.system.util.Tingg.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.SimpleDateFormat;
 import java.util.*;
 
 /**
@@ -39,6 +50,22 @@
 
     @Autowired
     private ITSystemNoticeService tSystemNoticeService;
+
+    @Autowired
+    private TinggPayoutUtil tinggPayoutUtil;
+
+    @Autowired
+    private ITUserService userService;
+
+    @Autowired
+    private ITDriverService driverService;
+
+    @Value("${callbackPath}")
+    private String callbackPath;
+
+
+
+
 
     /**
      * 跳转到提现列表首页
@@ -117,23 +144,56 @@
     public Object immediately(@RequestParam Integer id,@RequestParam Integer state,@RequestParam String remark) {
         TPubWithdrawal tPubWithdrawal = tPubWithdrawalService.selectById(id);
         if (SinataUtil.isNotEmpty(tPubWithdrawal)){
-//            tPubWithdrawal.setState(state);  //调用接口修改状态
             tPubWithdrawal.setRemark(remark);
-            tPubWithdrawal.setHandleTime(new Date());
 
-            Integer stateObj = 1;
-            if (2 == state){   //同意提现
-                stateObj = 1;
-            }else if (3 == state){  //拒绝提现
-                stateObj = 2;
+            String serviceCode = "";
+            String phone = "";
+            String narration = "";
+            if(tPubWithdrawal.getUserType() == 1){
+                TUser tUser = userService.selectById(tPubWithdrawal.getUserId());
+                serviceCode = tUser.getPhoneOperator();
+                phone = tUser.getPhone();
+                narration = "用户提现";
+            }else{
+                TDriver tDriver = driverService.selectById(tPubWithdrawal.getUserId());
+                serviceCode = tDriver.getPhoneOperator();
+                phone = tDriver.getPhone();
+                narration = "司机提现";
+            }
+            if(2 == state){
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+                String payerTransactionID = sdf.format(new Date()) + tPubWithdrawal.getId();
+                PayoutResponse payoutResponse = tinggPayoutUtil.sendPayout(serviceCode, "+" + phone, payerTransactionID, tPubWithdrawal.getMoney().doubleValue(), callbackPath + "/tPubWithdrawal/base/withdrawalCallback", narration);
+                AuthStatus authStatus = payoutResponse.getAuthStatus();
+                Results results = payoutResponse.getResults().get(0);
+                String statusCode = results.getStatusCode();
+                if(!"131".equals(authStatus.getAuthStatusCode())){
+                    return ResultUtil.error(authStatus.getAuthStatusDescription());
+                }
+                if(!"139".equals(statusCode)){
+                    return ResultUtil.error(results.getStatusDescription());
+                }
+                tPubWithdrawal.setSerialNo(results.getBeepTransactionID());
+            }else{//回退金额
+                tPubWithdrawal.setHandleTime(new Date());
+                tPubWithdrawal.setState(state);
+                if(tPubWithdrawal.getUserType() == 1){
+                    TUser tUser = userService.selectById(tPubWithdrawal.getUserId());
+                    tUser.setBalance(tUser.getBalance().add(tPubWithdrawal.getMoney()));
+                    userService.updateById(tUser);
+                }else{
+                    TDriver tDriver = driverService.selectById(tPubWithdrawal.getUserId());
+                    tDriver.setBalance(tDriver.getBalance().add(tPubWithdrawal.getMoney()));
+                    if(tPubWithdrawal.getType() == 1){//活动提现
+                        tDriver.setLaveActivityMoney(new BigDecimal(tDriver.getLaveActivityMoney()).add(tPubWithdrawal.getMoney()).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
+                    }else{//业务提现
+                        tDriver.setLaveBusinessMoney(new BigDecimal(tDriver.getLaveBusinessMoney()).add(tPubWithdrawal.getMoney()).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
+                    }
+                    driverService.updateById(tDriver);
+                }
             }
             tPubWithdrawalService.updateById(tPubWithdrawal);
 
-            Map<String,String> map = new HashMap<>();
-            map.put("id", String.valueOf(tPubWithdrawal.getId()));
-            map.put("state", String.valueOf(stateObj));
-            String result = HttpRequestUtil.postRequest(PushURL.withdraw_auth_url, map);
-            System.out.println("提现审核接口 :【recordId="+tPubWithdrawal.getId().toString()+"】,调用接口:"+result);
 
             //增加系统消息
             TSystemNotice notice = new TSystemNotice();
@@ -147,6 +207,40 @@
         }
         return SUCCESS_TIP;
     }
+
+
+    @ResponseBody
+    @PostMapping("/base/withdrawalCallback")
+    public PayoutCallbackResponse tinggPayoutCallback(@RequestBody PayoutCallbackRequest request){
+        System.err.println("转账回调>>>>" + JSON.toJSONString(request));
+        PayoutCallbackResponse payoutCallbackResponse = new PayoutCallbackResponse();
+        AuthStatus authStatus = new AuthStatus();
+        authStatus.setAuthStatusCode(131);
+        authStatus.setAuthStatusDescription("Authentication was successful");
+        payoutCallbackResponse.setAuthStatus(authStatus);
+        Results results = new Results();
+        PayoutPacket packet = request.getPayload().getPacket();
+        String statusCode = packet.getStatusCode();
+        String beepTransactionID = packet.getBeepTransactionID();
+        String payerTransactionID = packet.getPayerTransactionID();
+
+        String id = payerTransactionID.substring(17);
+        TPubWithdrawal tPubWithdrawal = tPubWithdrawalService.selectById(id);
+        tPubWithdrawal.setState(2);
+        tPubWithdrawal.setHandleTime(new Date());
+        tPubWithdrawal.setSerialNo(beepTransactionID);
+        tPubWithdrawalService.updateById(tPubWithdrawal);
+
+        results.setBeepTransactionID(beepTransactionID);
+        results.setPayerTransactionID(payerTransactionID);
+        results.setStatusCode("188");
+        results.setStatusDescription("Response was received");
+        payoutCallbackResponse.setResults(results);
+        return payoutCallbackResponse;
+    }
+
+
+
 
     /**
      * 修改提现列表
@@ -194,13 +288,11 @@
         List<String> shellList = new ArrayList<String>();
         shellList.add("申请时间");
         shellList.add("提现人");
-        shellList.add("银行卡号");
-        shellList.add("开户行");
-        shellList.add("提现方式");
+        shellList.add("提现手机号");
         shellList.add("账户类型");
+        shellList.add("提现金额");
         shellList.add("提现类型");
         shellList.add("账户余额");
-        shellList.add("提现金额");
         shellList.add("联系人");
         shellList.add("联系电话");
         shellList.add("备注");
@@ -224,26 +316,6 @@
             }else{
                 shellList.add("-");
             }
-            if(SinataUtil.isNotEmpty(map.get("bankName"))){
-                shellList.add(map.get("bankName").toString());
-            }else{
-                shellList.add("-");
-            }
-            //withdrawalType
-            if(SinataUtil.isNotEmpty(map.get("withdrawalType"))){
-                switch (map.get("withdrawalType").toString()){
-                    case "1":
-                        shellList.add("银行卡");
-                        break;
-                    case "2":
-                        shellList.add("线下");
-                        break;
-                    default:
-                        shellList.add("-");
-                }
-            }else{
-                shellList.add("-");
-            }
             //userType
             if(SinataUtil.isNotEmpty(map.get("userType"))){
                 switch (map.get("userType").toString()){
@@ -256,6 +328,12 @@
                     default:
                         shellList.add("-");
                 }
+            }else{
+                shellList.add("-");
+            }
+            //money
+            if(SinataUtil.isNotEmpty(map.get("money"))){
+                shellList.add(map.get("money").toString());
             }else{
                 shellList.add("-");
             }
@@ -277,12 +355,6 @@
             //balance
             if(SinataUtil.isNotEmpty(map.get("balance"))){
                 shellList.add(map.get("balance").toString());
-            }else{
-                shellList.add("-");
-            }
-            //money
-            if(SinataUtil.isNotEmpty(map.get("money"))){
-                shellList.add(map.get("money").toString());
             }else{
                 shellList.add("-");
             }

--
Gitblit v1.7.1