소스 검색

财务报表修改

caotao 1 주 전
부모
커밋
65fd09c2f0

+ 23 - 3
ship-module-ota/ship-module-ota-biz/src/main/resources/mapper/distributor/DistributorMapper.xml

@@ -137,9 +137,29 @@
     </select>
 
     <select id="queryDistributorMoneyTotal" resultType="com.yc.ship.module.ota.controller.admin.distributor.vo.DistributorRespVO">
-        SELECT sum(IF(recharge_type = 1, money, 0.00)) balanceTotal, sum(IF(recharge_type = 2, money, 0.00)) payCreditTotal
-        FROM ota_distributor_recharge
-        WHERE `status` = 1 and deleted = 0 and distributor_id = #{distributorId}
+
+        SELECT
+            t1.payCreditTotal,
+            t1.balanceTotal + IFNULL(t2.amount, 0) AS balanceTotal
+        FROM (
+                 SELECT
+                     SUM(IF(recharge_type = 1, money, 0.00)) balanceTotal,
+                     SUM(IF(recharge_type = 2, money, 0.00)) payCreditTotal
+                 FROM ota_distributor_recharge
+                 WHERE
+                     `status` = 1
+                   AND deleted = 0
+                   AND distributor_id = #{distributorId}
+             ) t1
+                 LEFT JOIN (
+            SELECT
+                SUM(sr.money) AS amount
+            FROM ota_distributor_self_recharge sr
+            WHERE
+                sr.deleted = 0
+              AND sr.recharge_state = 1
+              AND sr.distributor_id = #{distributorId}
+        ) t2 ON 1 = 1;
     </select>
 
     <select id="getPlatTenantId" resultType="com.yc.ship.module.ota.dal.dataobject.distributor.DistributorDO">

+ 2 - 0
ship-module-trade/ship-module-trade-biz/src/main/java/com/yc/ship/module/trade/service/business/DailyBusinessStatisticsServiceImpl.java

@@ -3,6 +3,7 @@ package com.yc.ship.module.trade.service.business;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.yc.ship.framework.common.pojo.PageResult;
+import com.yc.ship.framework.tenant.core.aop.TenantIgnore;
 import com.yc.ship.module.trade.controller.admin.business.vo.DailyBusinessStatisticsReqVO;
 import com.yc.ship.module.trade.controller.admin.business.vo.DailyBusinessStatisticsRespVO;
 import com.yc.ship.module.trade.dal.mysql.order.TradeOrderMapper;
@@ -20,6 +21,7 @@ public class DailyBusinessStatisticsServiceImpl implements DailyBusinessStatisti
     private TradeOrderMapper tradeOrderMapper;
 
     @Override
+    @TenantIgnore
     public PageResult<DailyBusinessStatisticsRespVO> getDailyBusinessStatisticsPage(DailyBusinessStatisticsReqVO pageReqVO) {
         IPage<DailyBusinessStatisticsRespVO> page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
         IPage<DailyBusinessStatisticsRespVO> resultPage = tradeOrderMapper.getDailyBusinessStatisticsPage(page, pageReqVO);

+ 36 - 24
ship-module-trade/ship-module-trade-biz/src/main/resources/mapper/order/TradeOrderMapper.xml

@@ -462,38 +462,50 @@
 
     <select id="getDailyBusinessStatisticsPage"
             resultType="com.yc.ship.module.trade.controller.admin.business.vo.DailyBusinessStatisticsRespVO">
-        SELECT
-            td.source_id AS sourceId,
-            td.source_name as sourceName,
-            IFNULL(tot.free_num, 0) AS freeNum,
-            0 AS freeCount,
-            IFNULL(topay.actual_amount, 0) AS actualAmount,
-            COUNT(1) AS totalCount,
-            SUM(CASE WHEN tv.type IN ('adultPlus', 'adultTake') THEN 1 ELSE 0 END) AS adultCount,
-            SUM(CASE WHEN tv.type IN ('childTake','childPlus','childNonTake') THEN 1 ELSE 0 END) AS childCount,
-            SUM(CASE WHEN tv.type = 'with' THEN 1 ELSE 0 END) AS withCount,
-            SUM(CASE WHEN tv.type = 'leader' THEN 1 ELSE 0 END) AS leaderCount,
-            SUM(CASE WHEN tv.type IN ('babyTake','babyPlus','babyNonTake') THEN 1 ELSE 0 END) AS infantCount,
-            COUNT(1) - IFNULL(tot.free_num, 0) AS validCount
+        select  t.sourceId,
+        t.sourceName,
+        sum(t.freeNum) as freeNum,
+        sum(t.freeCount) as freeCount,
+        sum(t.actualAmount) as actualAmount,
+        sum(t.totalCount) as totalCount,
+        SUM(t.adultCount) AS adultCount,
+        SUM(t.childCount) AS childCount,
+        SUM(t.withCount) AS withCount,
+        SUM(t.leaderCount) AS leaderCount,
+        SUM(t.infantCount) AS infantCount,
+        sum(t.validCount) as validCount from (SELECT
+        DISTINCT td.id,
+        td.source_id AS sourceId,
+        td.source_name as sourceName,
+        IFNULL(tot.free_num, 0) AS freeNum,
+        0 AS freeCount,
+        IFNULL(topay.actual_amount, 0) AS actualAmount,
+        COUNT(1) AS totalCount,
+        SUM(CASE WHEN tv.type IN ('adultPlus', 'adultTake') THEN 1 ELSE 0 END) AS adultCount,
+        SUM(CASE WHEN tv.type IN ('childTake','childPlus','childNonTake') THEN 1 ELSE 0 END) AS childCount,
+        SUM(CASE WHEN tv.type = 'with' THEN 1 ELSE 0 END) AS withCount,
+        SUM(CASE WHEN tv.type = 'leader' THEN 1 ELSE 0 END) AS leaderCount,
+        SUM(CASE WHEN tv.type IN ('babyTake','babyPlus','babyNonTake') THEN 1 ELSE 0 END) AS infantCount,
+        COUNT(1) - IFNULL(tot.free_num, 0) AS validCount
         FROM trade_order td
-                 INNER JOIN trade_order_user tou ON td.id = tou.order_id AND tou.deleted = 0
-                 LEFT JOIN trade_detail tdl ON td.id = tdl.order_id AND tdl.deleted = 0
-                 LEFT JOIN trade_visitor tv ON tdl.id = tv.detail_id AND tv.deleted = 0
-                 left join trade_order_total tot on td.id = tot.old_order_id and tot.deleted = 0
-                 LEFT JOIN (SELECT order_id, SUM(pay_amount) AS actual_amount
-                            FROM trade_order_pay
-                            WHERE pay_status = 1 GROUP BY order_id) topay ON td.id = topay.order_id
+        INNER JOIN trade_order_user tou ON td.id = tou.order_id AND tou.deleted = 0
+        LEFT JOIN trade_detail tdl ON td.id = tdl.order_id AND tdl.deleted = 0
+        LEFT JOIN trade_visitor tv ON tdl.id = tv.detail_id AND tv.deleted = 0
+        left join trade_order_total tot on td.id = tot.old_order_id and tot.deleted = 0
+        LEFT JOIN (SELECT order_id, SUM(pay_amount) AS actual_amount
+        FROM trade_order_pay
+        WHERE pay_status = 1 and deleted=0 GROUP BY order_id) topay ON td.id = topay.order_id
         WHERE
-            td.deleted = 0
-            AND tv.type IS NOT NULL
-            AND td.order_status > 0
+        td.deleted = 0
+        AND tv.type IS NOT NULL
+        AND td.order_status > 0
         <if test="vo.voyageId != null and vo.voyageId != ''">
             AND td.voyage_id = #{vo.voyageId}
         </if>
         <if test="vo.routeId != null and vo.routeId != ''">
             AND exists (select 1 from product_voyage top where top.id = td.voyage_id and top.route_id = #{vo.routeId})
         </if>
-        GROUP BY td.source_id;
+        GROUP BY td.id) t GROUP BY t.sourceId;
 
     </select>
 

+ 21 - 21
ship-module-trade/ship-module-trade-biz/src/main/resources/mapper/report/DistributorBalanceMapper.xml

@@ -17,7 +17,7 @@
                 d.id,
                 d.name AS travelAgency,
                 IFNULL(recharge.total_recharge, 0) AS totalRechargeAmount,
-                IFNULL(consume.total_consume, 0) AS totalConsumeAmount,
+                IFNULL(topay.actual_amount, 0) AS totalConsumeAmount,
                 IFNULL(d.balance, 0) AS balance
             FROM ota_distributor d
             LEFT JOIN (
@@ -46,36 +46,36 @@
                         sr.distributor_id,
                         SUM(sr.money) AS recharge_amount
                     FROM ota_distributor_self_recharge sr
-                    INNER JOIN ota_trade_log tl ON tl.id = sr.recharge_log_id AND tl.deleted = 0
                     WHERE sr.deleted = 0
                       AND sr.recharge_state = 1
-                      AND tl.trade_type = 1
                     <if test="vo.startDate != null">
-                        AND DATE(tl.trade_time) &gt;= #{vo.startDate}
+                        AND DATE(sr.create_time) &gt;= #{vo.startDate}
                     </if>
                     <if test="vo.endDate != null">
-                        AND DATE(tl.trade_time) &lt;= #{vo.endDate}
+                        AND DATE(sr.create_time) &lt;= #{vo.endDate}
                     </if>
                     GROUP BY sr.distributor_id
                 ) t
                 GROUP BY distributor_id
             ) recharge ON d.id = recharge.distributor_id
-            LEFT JOIN (
-                SELECT 
-                    tl.distributor_id,
-                    SUM(tl.trade_amount) AS total_consume
-                FROM ota_trade_log tl
-                WHERE tl.deleted = 0
-                  AND tl.trade_mode = 2
-                  AND tl.trade_type = 1
-                <if test="vo.startDate != null">
-                    AND DATE(tl.trade_time) &gt;= #{vo.startDate}
-                </if>
-                <if test="vo.endDate != null">
-                    AND DATE(tl.trade_time) &lt;= #{vo.endDate}
-                </if>
-                GROUP BY tl.distributor_id
-            ) consume ON d.id = consume.distributor_id
+
+            LEFT JOIN (SELECT
+                        td.source_id,
+                        SUM( tp.pay_amount ) AS actual_amount
+                    FROM
+                    trade_order_pay tp
+                    LEFT JOIN trade_order td ON td.id = tp.order_id
+                    AND td.deleted = 0
+                    where
+                    tp.pay_status = 1
+                    AND tp.deleted = 0
+                    <if test="vo.startDate != null">
+                        AND DATE(tp.payment_date) &gt;= #{vo.startDate}
+                    </if>
+                    <if test="vo.endDate != null">
+                        AND DATE(tp.payment_date) &lt;= #{vo.endDate}
+                    </if>
+                GROUP BY td.source_id) topay ON d.id = topay.source_id
             WHERE d.deleted = 0
             <if test="vo.travelAgency != null and vo.travelAgency != ''">
                 AND d.name LIKE CONCAT('%', #{vo.travelAgency}, '%')