| | |
| | | <script> |
| | | select count(*) |
| | | from ( |
| | | select case |
| | | when #{periodType} = 'MONTH' then date_format(coalesce(v.verify_time, o.updated_at, o.created_at), '%Y-%m') |
| | | else date_format(coalesce(v.verify_time, o.updated_at, o.created_at), '%Y-%m-%d') |
| | | end as period_key, |
| | | o.merchant_id |
| | | from benefit_order o |
| | | join merchant m on m.id = o.merchant_id and m.deleted = 0 |
| | | left join ( |
| | | select order_id, max(verify_time) as verify_time |
| | | from verify_record |
| | | where status = 1 |
| | | group by order_id |
| | | ) v on v.order_id = o.id |
| | | where o.deleted = 0 |
| | | and o.order_status = 1 |
| | | and o.verify_status = 1 |
| | | <if test="merchantId != null">and o.merchant_id = #{merchantId}</if> |
| | | <if test="merchantType != null and merchantType != ''">and m.merchant_type_code = #{merchantType}</if> |
| | | <if test="startTime != null">and coalesce(v.verify_time, o.updated_at, o.created_at) >= #{startTime}</if> |
| | | <if test="endTime != null">and coalesce(v.verify_time, o.updated_at, o.created_at) < #{endTime}</if> |
| | | group by period_key, o.merchant_id |
| | | select base.period_key, base.merchant_id |
| | | from ( |
| | | select case |
| | | when #{periodType} = 'MONTH' then date_format(coalesce(v.verify_time, o.updated_at, o.created_at), '%Y-%m') |
| | | else date_format(coalesce(v.verify_time, o.updated_at, o.created_at), '%Y-%m-%d') |
| | | end as period_key, |
| | | o.merchant_id |
| | | from benefit_order o |
| | | join merchant m on m.id = o.merchant_id and m.deleted = 0 |
| | | left join ( |
| | | select order_id, max(verify_time) as verify_time |
| | | from verify_record |
| | | where status = 1 |
| | | group by order_id |
| | | ) v on v.order_id = o.id |
| | | where o.deleted = 0 |
| | | and o.order_status = 1 |
| | | and o.verify_status = 1 |
| | | <if test="merchantId != null">and o.merchant_id = #{merchantId}</if> |
| | | <if test="merchantType != null and merchantType != ''">and m.merchant_type_code = #{merchantType}</if> |
| | | <if test="startTime != null">and coalesce(v.verify_time, o.updated_at, o.created_at) >= #{startTime}</if> |
| | | <if test="endTime != null">and coalesce(v.verify_time, o.updated_at, o.created_at) < #{endTime}</if> |
| | | union all |
| | | select case |
| | | when #{periodType} = 'MONTH' then date_format(r.verify_time, '%Y-%m') |
| | | else date_format(r.verify_time, '%Y-%m-%d') |
| | | end as period_key, |
| | | r.merchant_id |
| | | from verify_record r |
| | | join merchant m on m.id = r.merchant_id and m.deleted = 0 |
| | | where r.status = 1 |
| | | and r.order_id is null |
| | | and upper(r.verify_type) = 'HOTEL_FREE' |
| | | <if test="merchantId != null">and r.merchant_id = #{merchantId}</if> |
| | | <if test="merchantType != null and merchantType != ''">and m.merchant_type_code = #{merchantType}</if> |
| | | <if test="startTime != null">and r.verify_time >= #{startTime}</if> |
| | | <if test="endTime != null">and r.verify_time < #{endTime}</if> |
| | | ) base |
| | | group by base.period_key, base.merchant_id |
| | | ) grouped |
| | | </script> |
| | | """) |