From 016ddc332273c36e437a6f3b5f0a25574d5b7b78 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期五, 05 九月 2025 09:12:43 +0800
Subject: [PATCH] bug修改

---
 ManagementZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/TIncomeController.java |  267 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 261 insertions(+), 6 deletions(-)

diff --git a/ManagementZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/TIncomeController.java b/ManagementZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/TIncomeController.java
index 35b8d36..4a24e18 100644
--- a/ManagementZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/TIncomeController.java
+++ b/ManagementZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/TIncomeController.java
@@ -1,6 +1,7 @@
 package com.stylefeng.guns.modular.system.controller;
 
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.mapper.Wrapper;
 import com.baomidou.mybatisplus.plugins.Page;
 import com.stylefeng.guns.core.base.controller.BaseController;
 import com.stylefeng.guns.core.common.constant.factory.PageFactory;
@@ -8,8 +9,8 @@
 import com.stylefeng.guns.core.util.DateUtil;
 import com.stylefeng.guns.core.util.ExcelExportUtil;
 import com.stylefeng.guns.core.util.SinataUtil;
-import com.stylefeng.guns.modular.system.model.Income;
-import com.stylefeng.guns.modular.system.service.IIncomeService;
+import com.stylefeng.guns.modular.system.model.*;
+import com.stylefeng.guns.modular.system.service.*;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
@@ -21,10 +22,10 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 控制器
@@ -40,6 +41,14 @@
 
     @Autowired
     private IIncomeService tIncomeService;
+    @Autowired
+    private ITOrderPrivateCarService orderPrivateCarService;
+    @Autowired
+    private ITPubTransactionDetailsService pubTransactionDetailsService;
+    @Autowired
+    private ITPubWithdrawalService pubWithdrawalService;
+    @Autowired
+    private ITDriverService driverService;
 
     /**
      * 跳转到首页
@@ -48,6 +57,11 @@
     public String index(Integer id, Model model) {
         model.addAttribute("id", id);
         return PREFIX + "tIncome.html";
+    }
+    @RequestMapping("/balance")
+    public String balance(Integer id, Model model) {
+        model.addAttribute("id", id);
+        return PREFIX + "balance.html";
     }
 
     @RequestMapping("driverWork")
@@ -101,6 +115,247 @@
         page.setRecords(tIncomeService.getList(page,id));
         return super.packForBT(page);
     }
+
+
+    /**
+     * 司机余额修改
+     */
+    @RequestMapping(value = "/changeMoney")
+    @ResponseBody
+    public Object oneChange(Integer id ,Integer type,String mount,String remark) {
+        TDriver tDriver = driverService.selectById(id);
+        TPubTransactionDetails tPubTransactionDetails = new TPubTransactionDetails();
+        tPubTransactionDetails.setUserId(tDriver.getId());
+        tPubTransactionDetails.setInsertTime(new Date());
+        tPubTransactionDetails.setRemark(remark);
+        tPubTransactionDetails.setMoney(new BigDecimal(mount));
+        tPubTransactionDetails.setState(type);
+        tPubTransactionDetails.setType(1);
+        tPubTransactionDetails.setUserType(2);
+        switch ( type){
+            case 1:
+                tPubTransactionDetails.setOrderType(6);
+                break;
+            case 2:
+                tPubTransactionDetails.setOrderType(7);
+                break;
+        }
+        // type=1增加 type=2减少
+        switch (type){
+            case 1:
+                BigDecimal bigDecimal = new BigDecimal(mount);
+
+                BigDecimal add = tDriver.getBalance().add(bigDecimal);
+                tDriver.setBalance(add);
+                BigDecimal laveBusinessMoney = new BigDecimal(tDriver.getLaveBusinessMoney()).add(bigDecimal);
+                tDriver.setLaveBusinessMoney(laveBusinessMoney.doubleValue());
+                break;
+            case 2:
+                BigDecimal bigDecimal1 = new BigDecimal(mount);
+                BigDecimal subtract = tDriver.getBalance().subtract(bigDecimal1);
+                int comparisonResult = subtract.compareTo(BigDecimal.ZERO);
+                // 小于0 设置为0 不要为负数
+                if (comparisonResult>0){
+                    tDriver.setBalance(subtract);
+                }
+                BigDecimal laveBusinessMoney1 = new BigDecimal(tDriver.getLaveBusinessMoney()).subtract(bigDecimal1);
+                int comparisonResult1 = laveBusinessMoney1.compareTo(BigDecimal.ZERO);
+                if (comparisonResult1>0){
+                    tDriver.setLaveBusinessMoney(laveBusinessMoney1.doubleValue());
+                }
+                break;
+        }
+        driverService.updateById(tDriver);
+        tPubTransactionDetails.setDriverBalance(tDriver.getLaveBusinessMoney());
+        pubTransactionDetailsService.insert(tPubTransactionDetails);
+        return SUCCESS_TIP;
+    }
+    /**
+     * 余额明细列表
+     */
+    @RequestMapping(value = "/listBalance")
+    @ResponseBody
+    public Object list(Integer id,String insertTime ,Integer handleType) {
+        String beginTime = null;
+        String endTime = null;
+        if (SinataUtil.isNotEmpty(insertTime)){
+            String[] timeArray = insertTime.split(" - ");
+            beginTime = timeArray[0];
+            endTime = timeArray[1];
+        }
+        List<TOrderPrivateCar> tOrderPrivateCars = orderPrivateCarService.selectList(null);
+
+        List<Map<String, Object>> res = new ArrayList<>();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+        // 跑单收入
+        if (handleType == null || handleType == 1){
+            Wrapper<Income> eq = new EntityWrapper<Income>()
+                    .eq("objectId", id)
+                    .eq("type", 2)
+                    .eq("userType", 2);
+            if (beginTime!=null){
+                eq.ge("insertTime", beginTime);
+                eq.le("insertTime", endTime);
+            }
+            List<Income> incomes = tIncomeService.selectList(eq);
+            for (Income income : incomes) {
+                Map<String, Object> temp = new HashMap<>();
+                String times = simpleDateFormat.format(income.getInsertTime());
+                if (income.getIncomeId()!=null){
+                    TOrderPrivateCar tOrderPrivateCar = tOrderPrivateCars.stream().filter(e -> e.getId()
+                            .equals(income.getIncomeId())).findFirst().orElse(null);
+                    temp.put("orderNumber",tOrderPrivateCar==null?null:tOrderPrivateCar.getOrderNum());
+                    temp.put("remark",tOrderPrivateCar.getRemark());
+                }
+                temp.put("times",times);
+                temp.put("handleType","车费收入");
+                temp.put("amount",income.getMoney());
+                temp.put("withType","订单号");
+                // todo 新增收入明细时 需要存储当前账户余额
+                temp.put("balance",income.getDriverBalance());
+                res.add(temp);
+            }
+        }
+        // 司机专车订单ids
+        List<Integer> orderIds = orderPrivateCarService.selectList(new EntityWrapper<TOrderPrivateCar>()
+                        .eq("driverId", id)).stream()
+                .map(TOrderPrivateCar::getId).collect(Collectors.toList());
+        if (orderIds.isEmpty()){
+            orderIds.add(-1);
+        }
+        // 车费平台手续费扣除
+        if (handleType == null || handleType == 2){
+            Wrapper<Income> eq = new EntityWrapper<Income>()
+                    .eq("type", 2)
+                    .in("incomeId",orderIds)
+                    .eq("userType", 1);
+            if (beginTime!=null){
+                eq.ge("insertTime", beginTime);
+                eq.le("insertTime", endTime);
+            }
+            List<Income> incomes = tIncomeService.selectList(eq);
+            for (Income income : incomes) {
+                Map<String, Object> temp = new HashMap<>();
+                String times = simpleDateFormat.format(income.getInsertTime());
+                if (income.getIncomeId()!=null){
+                    TOrderPrivateCar tOrderPrivateCar = tOrderPrivateCars.stream().filter(e -> e.getId()
+                            .equals(income.getIncomeId())).findFirst().orElse(null);
+                    temp.put("orderNumber",tOrderPrivateCar==null?null:tOrderPrivateCar.getOrderNum());
+                    temp.put("remark",tOrderPrivateCar==null?"":tOrderPrivateCar.getRemark());
+                }
+                temp.put("times",times);
+                temp.put("handleType","车费平台手续费扣除");
+                temp.put("amount",income.getMoney());
+                temp.put("withType","订单号");
+                // todo 新增收入明细时 需要存储当前账户余额
+                temp.put("balance",income.getDriverBalance());
+                res.add(temp);
+            }
+        }
+        // 充值
+        if (handleType == null || handleType == 3){
+            Wrapper<TPubTransactionDetails> eq = new EntityWrapper<TPubTransactionDetails>()
+                    .eq("userId", id)
+                    .eq("orderType", 5)
+                    .eq("userType", 2);
+            if (beginTime!=null){
+                eq.ge("insertTime", beginTime);
+                eq.le("insertTime", endTime);
+            }
+            List<TPubTransactionDetails> pubTransactionDetails = pubTransactionDetailsService.selectList(eq);
+            for (TPubTransactionDetails details : pubTransactionDetails) {
+                Map<String, Object> temp = new HashMap<>();
+                String times = simpleDateFormat.format(details.getInsertTime());
+                    temp.put("orderNumber","");
+                    temp.put("remark","");
+                temp.put("times",times);
+                temp.put("handleType","充值");
+                temp.put("amount",details.getMoney());
+                temp.put("withType","交易流水号");
+                // todo 新增收入明细时 需要存储当前账户余额
+                temp.put("balance",details.getDriverBalance());
+                res.add(temp);
+            }
+        }
+        // 提现
+        if (handleType == null || handleType == 4){
+            Wrapper<TPubWithdrawal> eq = new EntityWrapper<TPubWithdrawal>()
+                    .eq("userId", id)
+                    .eq("state", 2)
+                    .eq("userType", 2);
+            if (beginTime!=null){
+                eq.ge("insertTime", beginTime);
+                eq.le("insertTime", endTime);
+            }
+            List<TPubWithdrawal> pubTransactionDetails = pubWithdrawalService.selectList(eq);
+            for (TPubWithdrawal details : pubTransactionDetails) {
+                Map<String, Object> temp = new HashMap<>();
+                String times = simpleDateFormat.format(details.getInsertTime());
+                    temp.put("orderNumber",details.getOrderNumber());
+                    temp.put("remark",details.getRemark());
+                temp.put("times",times);
+                temp.put("handleType","提现");
+                temp.put("amount",details.getMoney());
+                temp.put("withType","交易流水号");
+                // todo 新增收入明细时 需要存储当前账户余额
+                temp.put("balance",details.getDriverBalance());
+                res.add(temp);
+            }
+        }
+        // 平台充值
+        if (handleType == null || handleType == 6){
+            Wrapper<TPubTransactionDetails> eq = new EntityWrapper<TPubTransactionDetails>()
+                    .eq("userId", id)
+                    .eq("orderType", 6)
+                    .eq("userType", 2);
+            if (beginTime!=null){
+                eq.ge("insertTime", beginTime);
+                eq.le("insertTime", endTime);
+            }
+            List<TPubTransactionDetails> pubTransactionDetails = pubTransactionDetailsService.selectList(eq);
+            for (TPubTransactionDetails details : pubTransactionDetails) {
+                Map<String, Object> temp = new HashMap<>();
+                String times = simpleDateFormat.format(details.getInsertTime());
+                    temp.put("orderNumber","");
+                    temp.put("remark","");
+                temp.put("times",times);
+                temp.put("handleType","平台充值");
+                temp.put("amount",details.getMoney());
+                temp.put("withType","无");
+                // todo 新增收入明细时 需要存储当前账户余额
+                temp.put("balance",details.getDriverBalance());
+                res.add(temp);
+            }
+        }
+        // 平台扣除
+        if (handleType == null || handleType == 7){
+            Wrapper<TPubTransactionDetails> eq = new EntityWrapper<TPubTransactionDetails>()
+                    .eq("userId", id)
+                    .eq("orderType", 7)
+                    .eq("userType", 2);
+            if (beginTime!=null){
+                eq.ge("insertTime", beginTime);
+                eq.le("insertTime", endTime);
+            }
+            List<TPubTransactionDetails> pubTransactionDetails = pubTransactionDetailsService.selectList(eq);
+            for (TPubTransactionDetails details : pubTransactionDetails) {
+                Map<String, Object> temp = new HashMap<>();
+                String times = simpleDateFormat.format(details.getInsertTime());
+
+                    temp.put("orderNumber","");
+                    temp.put("remark","");
+                temp.put("times",times);
+                temp.put("handleType","平台扣除");
+                temp.put("amount",details.getMoney());
+                temp.put("withType","无");
+                // todo 新增收入明细时 需要存储当前账户余额
+                temp.put("balance",details.getDriverBalance());
+                res.add(temp);
+            }
+        }
+        return res;
+    }
     @RequestMapping("/getExcel")
     @ResponseBody
     public void getExcel(

--
Gitblit v1.7.1