select res.*,IFNULL(round(sum_payment/sale_count*100,2),0) as payment_rate from (
select c.*,
IFNULL(round((select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and wco.coupon_order_status = 1 and wc.id = c.id)/(select count(wco.id) from wx_coupon_order wco where wco.coupon_id = c.id)*100,2),0) payment_rate,
(select count(wco.id) from wx_coupon_order wco where wco.coupon_id = c.id) as sale_count,
(select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and wco.coupon_order_status = 1 and wc.id = c.id) as sum_payment,
(select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and wco.coupon_order_status = 3 and wc.id = c.id) as backpay_count,
@@ -589,30 +590,60 @@
left join wx_coupon_order wo on wo.coupon_id = wc.id
left join wx_merchant_subsidy sc on sc.coupon_order_id = wo.id
where wc.id = c.id) as sum_subsidy
from wx_coupon c where c.type not in(8,9,100)
) res
) la
<if test=" 1 == type ">
and la.sale_price > 0
and c.sale_price > 0
</if>
<if test=" 2 == type ">
and la.sale_price = 0
and c.sale_price = 0
</if>
<if test="title != null and title != ''">
and la.title like concat('%', #{title},'%')
and c.title like concat('%', #{title},'%')
</if>
<if test="id != null">
and la.id = #{id}
and c.id = #{id}
</if>
<if test=" null != sortColumns">order by ${sortColumns}</if>
<if test=" null == sortColumns">order by la.status asc,la.create_date desc</if>
<if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>
(select count(wco.id) from wx_coupon_order wco where wco.coupon_id = c.id) as sale_count,
(select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and wco.coupon_order_status = 1 and wc.id = c.id) as sum_payment,
(select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and wco.coupon_order_status = 3 and wc.id = c.id) as backpay_count,
(select sum(sc.subsidy) from wx_coupon wc
left join wx_coupon_order wo on wo.coupon_id = wc.id
left join wx_merchant_subsidy sc on sc.coupon_order_id = wo.id
where wc.id = c.id) as sum_subsidy
from wx_coupon c where c.type not in(8,9,100)
<if test=" 1 == type ">
and c.sale_price > 0
</if>
<if test=" 2 == type ">
and c.sale_price = 0
</if>
<if test="title != null and title != ''">
and c.title like concat('%', #{title},'%')
</if>
<if test="id != null">
and c.id = #{id}
</if>
<if test=" null != sortColumns"> order by ${sortColumns} </if>
<if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>