@ -144,17 +144,23 @@
</select>
-->
<!-- 优化后的SQL语句 -->
<!--
优化后的SQL语句
在之前的SQL语句中, 与transaction表内连接时加了and (t.transaction_type = 'Credit' or t.refund_id is not null)这个条件
是因为在transaction_type = 'Debit'的记录中, 有的并没有refund_id, 所以剔除这些记录
优化后的SQL语句去掉了这个条件, 而是在需要的字段中天健t.refund_id IS NOT NULL这一条件
-->
<select id= "listPartnersTradeAmount" resultType= "com.alibaba.fastjson.JSONObject" >
< ![CDATA[
SELECT
p.client_moniker,
p.short_name,
ifnull(sum(if(t.transaction_type = 'Credit', t.clearing_amount, 0)), 0) aud_fee,
count(DISTINCT t.order_id) orders,
max(t.clearing_amount) max_order,
ifnull(sum(if(t.refund_id is not null, if(t.transaction_type='Debit', t.clearing_amount, -t.clearing_amount), 0)), 0) refund_amount,
ifnull(sum(if(t.refund_id is not null and t.transaction_type='Debit', 1, 0)), 0)refund_orders, max(if(t.refund_id is not null and t.transaction_type='Debit', t.clearing_amount, 0)) max_refund
p.short_name,
p.client_moniker,
COUNT(t.refund_id) refund_orders,
COUNT(DISTINCT t.order_id) orders,
IFNULL(MAX(t.clearing_amount), 0) max_order,
MAX(IF(t.refund_id IS NOT NULL, t.clearing_amount, 0)) max_refund,
SUM(IF(t.refund_id IS NOT NULL, t.clearing_amount, 0)) refund_amount,
IFNULL(SUM(IF(t.transaction_type = 'Credit', t.clearing_amount, 0)), 0) aud_fee
FROM sys_clients p
INNER JOIN pmt_transactions t
ON t.client_id = p.client_id
@ -162,34 +168,36 @@
AND t.create_time < = #{end}
]]>
<if test= "org_id != null and org_ids == null" >
and p.org_id = #{org_id}
AND p.org_id = #{org_id}
</if>
<if test= "org_ids != null" >
and p.org_id in
AND p.org_id IN
<foreach collection= "org_ids" item= "org_id" open= "(" close= ")" separator= "," >
#{org_id}
</foreach>
</if>
<if test= "bd_group != null" >
and p.client_id in (
SELECT b.client_id FROM sys_client_bd b
AND p.client_id IN (
SELECT b.client_id
FROM sys_client_bd b
INNER JOIN financial_bd_config c
ON c.manager_id = b.bd_id
where b.is_valid = 1
and b.start_date < = now()
and (b.end_date is null or b.end_date > = now())
AND (c.bd_group = #{bd_group} or c.manager_id = #{bd_group})
WHERE b.is_valid = 1
AND b.start_date < = now()
AND (b.end_date IS NULL OR b.end_date > = now())
AND (c.bd_group = #{bd_group} OR c.manager_id = #{bd_group})
<if test= "bd_group_bd" >
and c.manager_id = #{bd_group_bd}
AND c.manager_id = #{bd_group_bd}
</if>
)
</if>
GROUP BY p.client_id
ORDER BY #{rankType} DESC
<if test= "rankType != null" >
ORDER BY ${rankType} DESC
</if>
<if test= "limit != null" >
limit ${limit}
LIMIT ${limit}
</if>
</select>