|
|
@@ -0,0 +1,164 @@
|
|
|
+<?xml version="1.0" encoding="UTF-8"?>
|
|
|
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
+<mapper namespace="com.yc.ship.module.trade.dal.mysql.report.DistributorBalanceMapper">
|
|
|
+
|
|
|
+ <!-- 分页查询预存款余额表 -->
|
|
|
+ <!--
|
|
|
+ 业务说明:
|
|
|
+ 1. 以分销商(ota_distributor)为主表
|
|
|
+ 2. 累计充值金额 = 后台充值(ota_distributor_recharge) + 自助充值(ota_distributor_self_recharge) 在日期范围内的成功金额
|
|
|
+ 3. 累计消费金额 = ota_trade_log 中消费类型(trade_mode=2)在日期范围内的交易金额
|
|
|
+ 4. 余额 = 分销商当前余额(balance)
|
|
|
+ -->
|
|
|
+ <select id="selectDistributorBalancePage"
|
|
|
+ resultType="com.yc.ship.module.trade.controller.admin.report.vo.DistributorBalanceRespVO">
|
|
|
+ SELECT * FROM (
|
|
|
+ SELECT
|
|
|
+ d.id,
|
|
|
+ d.name AS travelAgency,
|
|
|
+ IFNULL(recharge.total_recharge, 0) AS totalRechargeAmount,
|
|
|
+ IFNULL(consume.total_consume, 0) AS totalConsumeAmount,
|
|
|
+ IFNULL(d.balance, 0) AS balance
|
|
|
+ FROM ota_distributor d
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ distributor_id,
|
|
|
+ SUM(recharge_amount) AS total_recharge
|
|
|
+ FROM (
|
|
|
+ SELECT
|
|
|
+ r.distributor_id,
|
|
|
+ SUM(tl.trade_amount) AS recharge_amount
|
|
|
+ FROM ota_distributor_recharge r
|
|
|
+ INNER JOIN ota_trade_log tl ON r.recharge_log_id = tl.id AND tl.deleted = 0 AND tl.trade_type = 1
|
|
|
+ WHERE r.deleted = 0
|
|
|
+ AND r.status = 1
|
|
|
+ AND tl.trade_mode = 1
|
|
|
+ AND tl.trade_type = 1
|
|
|
+ <if test="vo.startDate != null">
|
|
|
+ AND DATE(tl.trade_time) >= #{vo.startDate}
|
|
|
+ </if>
|
|
|
+ <if test="vo.endDate != null">
|
|
|
+ AND DATE(tl.trade_time) <= #{vo.endDate}
|
|
|
+ </if>
|
|
|
+ GROUP BY r.distributor_id
|
|
|
+ UNION ALL
|
|
|
+ SELECT
|
|
|
+ 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) >= #{vo.startDate}
|
|
|
+ </if>
|
|
|
+ <if test="vo.endDate != null">
|
|
|
+ AND DATE(tl.trade_time) <= #{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) >= #{vo.startDate}
|
|
|
+ </if>
|
|
|
+ <if test="vo.endDate != null">
|
|
|
+ AND DATE(tl.trade_time) <= #{vo.endDate}
|
|
|
+ </if>
|
|
|
+ GROUP BY tl.distributor_id
|
|
|
+ ) consume ON d.id = consume.distributor_id
|
|
|
+ WHERE d.deleted = 0
|
|
|
+ <if test="vo.travelAgency != null and vo.travelAgency != ''">
|
|
|
+ AND d.name LIKE CONCAT('%', #{vo.travelAgency}, '%')
|
|
|
+ </if>
|
|
|
+ ) temp
|
|
|
+ WHERE (totalRechargeAmount <![CDATA[>]]> 0 OR totalConsumeAmount <![CDATA[>]]> 0 OR balance <![CDATA[>]]> 0)
|
|
|
+ ORDER BY id DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 导出查询(与分页查询条件一致,不分页) -->
|
|
|
+ <select id="selectDistributorBalanceExportList"
|
|
|
+ resultType="com.yc.ship.module.trade.controller.admin.report.vo.DistributorBalanceRespVO">
|
|
|
+ SELECT * FROM (
|
|
|
+ SELECT
|
|
|
+ d.id,
|
|
|
+ d.name AS travelAgency,
|
|
|
+ IFNULL(recharge.total_recharge, 0) AS totalRechargeAmount,
|
|
|
+ IFNULL(consume.total_consume, 0) AS totalConsumeAmount,
|
|
|
+ IFNULL(d.balance, 0) AS balance
|
|
|
+ FROM ota_distributor d
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ distributor_id,
|
|
|
+ SUM(recharge_amount) AS total_recharge
|
|
|
+ FROM (
|
|
|
+ SELECT
|
|
|
+ r.distributor_id,
|
|
|
+ SUM(tl.trade_amount) AS recharge_amount
|
|
|
+ FROM ota_distributor_recharge r
|
|
|
+ INNER JOIN ota_trade_log tl ON r.recharge_log_id = tl.id AND tl.deleted = 0 AND tl.trade_type = 1
|
|
|
+ WHERE r.deleted = 0
|
|
|
+ AND r.status = 1
|
|
|
+ AND tl.trade_mode = 1
|
|
|
+ AND tl.trade_type = 1
|
|
|
+ <if test="vo.startDate != null">
|
|
|
+ AND DATE(tl.trade_time) >= #{vo.startDate}
|
|
|
+ </if>
|
|
|
+ <if test="vo.endDate != null">
|
|
|
+ AND DATE(tl.trade_time) <= #{vo.endDate}
|
|
|
+ </if>
|
|
|
+ GROUP BY r.distributor_id
|
|
|
+ UNION ALL
|
|
|
+ SELECT
|
|
|
+ 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) >= #{vo.startDate}
|
|
|
+ </if>
|
|
|
+ <if test="vo.endDate != null">
|
|
|
+ AND DATE(tl.trade_time) <= #{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) >= #{vo.startDate}
|
|
|
+ </if>
|
|
|
+ <if test="vo.endDate != null">
|
|
|
+ AND DATE(tl.trade_time) <= #{vo.endDate}
|
|
|
+ </if>
|
|
|
+ GROUP BY tl.distributor_id
|
|
|
+ ) consume ON d.id = consume.distributor_id
|
|
|
+ WHERE d.deleted = 0
|
|
|
+ <if test="vo.travelAgency != null and vo.travelAgency != ''">
|
|
|
+ AND d.name LIKE CONCAT('%', #{vo.travelAgency}, '%')
|
|
|
+ </if>
|
|
|
+ ) temp
|
|
|
+ WHERE (totalRechargeAmount <![CDATA[>]]> 0 OR totalConsumeAmount <![CDATA[>]]> 0 OR balance <![CDATA[>]]> 0)
|
|
|
+ ORDER BY id DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+</mapper>
|