From f58cca364b731eac2d60a440ffaa804be3cd43fd Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期五, 30 六月 2023 10:32:28 +0800
Subject: [PATCH] 修改bug

---
 management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/dao/mapping/TRevenueMapper.xml |  107 ++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 77 insertions(+), 30 deletions(-)

diff --git a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/dao/mapping/TRevenueMapper.xml b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/dao/mapping/TRevenueMapper.xml
index 4410ba6..7c16af5 100644
--- a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/dao/mapping/TRevenueMapper.xml
+++ b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/dao/mapping/TRevenueMapper.xml
@@ -127,25 +127,47 @@
             cw.type = 2 AND cw.businessType = #{type} AND cw.code = #{code}
     </select>
     <select id="getDataStatisticsIncomeOrCommission" resultType="com.stylefeng.guns.modular.system.controller.resp.PerformanceTableResp">
-        SELECT date_format(r.createTime, '%Y-%m') AS monthTime,SUM(r.amount) AS amount,d.userName
-        FROM t_revenue r
-        LEFT JOIN (SELECT id,name AS userName from t_driver) d ON r.userId = d.id
-        LEFT JOIN t_order o ON r.orderId = o.id
-        <where>
+        <if test="type == 1">
+            select aa.monthTime,aa.userName,sum(aa.amount) as amount from (
+            select
+            DATE_FORMAT(a.createTime, '%Y-%m') as monthTime,
+            b.id as driverId,
+            a.payMoney as amount,
+            b.`name` as userName
+            from t_order a
+            left join t_driver b on (a.driverId = b.id)
+            where a.payMoney > 0
             <if test="agentId != null">
-                AND o.agentId = #{agentId}
+                and a.agentId = #{agentId}
             </if>
             <if test="monthDate != null and monthDate != ''">
-                AND date_format(r.createTime, '%Y-%m') LIKE concat('',#{monthDate},'%')
+                AND date_format(a.createTime, '%Y-%m') LIKE concat('',#{monthDate},'%')
             </if>
-            <if test="type != null">
-                AND r.type = #{type}
-            </if>
-            AND r.userType = 2
-        </where>
-        GROUP BY monthTime,userName
-        ORDER BY amount DESC
-        LIMIT 10
+            ) as aa GROUP BY aa.monthTime,aa.driverId
+            ORDER BY amount DESC
+            LIMIT 10
+        </if>
+        <if test="2 == type">
+            SELECT date_format(r.createTime, '%Y-%m') AS monthTime,SUM(r.amount) AS amount,d.userName
+            FROM t_revenue r
+            LEFT JOIN (SELECT id,name AS userName from t_driver) d ON r.userId = d.id
+            LEFT JOIN t_order o ON r.orderId = o.id
+            <where>
+                <if test="agentId != null">
+                    AND o.agentId = #{agentId}
+                </if>
+                <if test="monthDate != null and monthDate != ''">
+                    AND date_format(r.createTime, '%Y-%m') LIKE concat('',#{monthDate},'%')
+                </if>
+                <if test="type != null">
+                    AND r.type = #{type}
+                </if>
+                AND r.userType = 2
+            </where>
+            GROUP BY monthTime,userName
+            ORDER BY amount DESC
+            LIMIT 10
+        </if>
     </select>
 
     <select id="getDataStatisticsCommission" resultType="com.stylefeng.guns.modular.system.controller.resp.PerformanceTableResp">
@@ -169,28 +191,53 @@
         ORDER BY amount DESC
     </select>
     <select id="getDataStatisticsIncomeOrCommissionByIds" resultType="com.stylefeng.guns.modular.system.controller.resp.PerformanceTableResp">
-        SELECT date_format(r.createTime, '%Y-%m') AS monthTime,SUM(r.amount) AS amount,d.userName
-        FROM t_revenue r
-        LEFT JOIN (SELECT id,name AS userName from t_driver) d ON r.userId = d.id
-        LEFT JOIN t_order o ON r.orderId = o.id
-        <where>
+        <if test="type == 1">
+            select aa.monthTime,aa.userName,sum(aa.amount) as amount from (
+            select
+            DATE_FORMAT(a.createTime, '%Y-%m') as monthTime,
+            b.id as driverId,
+            a.payMoney as amount,
+            b.`name` as userName
+            from t_order a
+            left join t_driver b on (a.driverId = b.id)
+            where a.payMoney > 0
             <if test="ids != null and ids.size() > 0">
-                AND o.agentId IN
+                AND a.agentId IN
                 <foreach collection="ids" close=")" open="(" item="id" separator=",">
                     #{id}
                 </foreach>
             </if>
             <if test="monthDate != null and monthDate != ''">
-                AND date_format(r.createTime, '%Y-%m') LIKE concat('',#{monthDate},'%')
+                AND date_format(a.createTime, '%Y-%m') LIKE concat('',#{monthDate},'%')
             </if>
-            <if test="type != null">
-                AND r.type = #{type}
-            </if>
-            AND r.userType = 2
-        </where>
-        GROUP BY monthTime,userName
-        ORDER BY amount DESC
-        LIMIT 10
+            ) as aa GROUP BY aa.monthTime,aa.driverId
+            ORDER BY amount DESC
+            LIMIT 10
+        </if>
+        <if test="type == 2">
+            SELECT date_format(r.createTime, '%Y-%m') AS monthTime,SUM(r.amount) AS amount,d.userName
+            FROM t_revenue r
+            LEFT JOIN (SELECT id,name AS userName from t_driver) d ON r.userId = d.id
+            LEFT JOIN t_order o ON r.orderId = o.id
+            <where>
+                <if test="ids != null and ids.size() > 0">
+                    AND o.agentId IN
+                    <foreach collection="ids" close=")" open="(" item="id" separator=",">
+                        #{id}
+                    </foreach>
+                </if>
+                <if test="monthDate != null and monthDate != ''">
+                    AND date_format(r.createTime, '%Y-%m') LIKE concat('',#{monthDate},'%')
+                </if>
+                <if test="type != null">
+                    AND r.type = #{type}
+                </if>
+                AND r.userType = 2
+            </where>
+            GROUP BY monthTime,userName
+            ORDER BY amount DESC
+            LIMIT 10
+        </if>
     </select>
 
 </mapper>

--
Gitblit v1.7.1