| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?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(topay.actual_amount, 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
- WHERE sr.deleted = 0
- AND sr.recharge_state = 1
- <if test="vo.startDate != null">
- AND DATE(sr.create_time) >= #{vo.startDate}
- </if>
- <if test="vo.endDate != null">
- AND DATE(sr.create_time) <= #{vo.endDate}
- </if>
- GROUP BY sr.distributor_id
- ) t
- GROUP BY distributor_id
- ) recharge ON d.id = recharge.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) >= #{vo.startDate}
- </if>
- <if test="vo.endDate != null">
- AND DATE(tp.payment_date) <= #{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}, '%')
- </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>
|