IFNULL(round((select count(o.id) from wx_order o where o.tenant_id = #{tenantId} and o.product_id = c.id and o.order_status = 1)/
(select count(op.id) from wx_order_press op where op.`tenant_id` = #{tenantId} and op.`coupon_id` = c.`id` and op.first = 1 )*100,2),0) change_rate,
(select count(op.id) from wx_order_press op
where op.`tenant_id` = #{tenantId} and op.first = 1 and op.coupon_id = c.id) as press_count,
(select count(o.id) from wx_order o
where o.`tenant_id` = #{tenantId} and o.product_id = c.id and o.order_status = 1) as press_succ_count,
(select count(op.id) from wx_order_press op
where op.`tenant_id` = #{tenantId} and op.`coupon_id` = c.`id`) as join_count,
IFNULL(round((select count(wco.id) xcount from wx_coupon_order wco
where wco.`tenant_id` = #{tenantId} and wco.coupon_id = c.id and wco.coupon_order_status = 1
)/(select count(op.id) from wx_order_press op
where op.`tenant_id` = #{tenantId} and op.`coupon_id` = c.`id` and op.first = 1)
*100,2),0) as payment_rate
from wx_coupon c where c.type = 8
ifnull(op.press_count,0) as press_count,
ifnull(o.press_succ_count,0) as press_succ_count,
ifnull(op2.join_count,0) as join_count,
ifnull(round(o.press_succ_count/op.press_count*100,2),0) as change_rate,
ifnull(round(cop.xCount/op.press_count*100,2),0) as payment_rate
FROM wx_coupon c
left join (SELECT count(id) as press_count, coupon_id FROM wx_order_press WHERE `tenant_id` = #{tenantId} AND `first` = 1 group by coupon_id) op on op.coupon_id = c.id
left join (SELECT count(id) as press_succ_count, product_id FROM wx_order WHERE `tenant_id` = #{tenantId} AND order_status = 1 group by product_id) o on o.product_id = c.id
left join (SELECT count(id) as join_count, coupon_id FROM wx_order_press op WHERE `tenant_id` = #{tenantId} group by coupon_id) op2 on op2.coupon_id = c.id
left join (SELECT count(id) as xCount, coupon_id FROM wx_coupon_order WHERE `tenant_id` = #{tenantId} AND coupon_order_status = 1) cop on cop.coupon_id = c.id
where c.type = 8
<if test="tenantId != null">
<if test="tenantId != null">
and c.tenant_id=#{tenantId}
and c.tenant_id=#{tenantId}
</if>
</if>
@@ -683,6 +677,7 @@
<if test=" null != startdate and null!=enddate">
<if test=" null != startdate and null!=enddate">
and c.`create_date` between #{startdate} and #{enddate}
and c.`create_date` between #{startdate} and #{enddate}
</if>
</if>
<if test=" null != sortColumns">order by ${sortColumns}</if>
<if test=" null != sortColumns">order by ${sortColumns}</if>
<if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>
<if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>