ifnull(select count(*) from tb_user ac inner join artificer aa on a.user_id = aa.user_id where ac.bl_jjr_code = y.invitation_code,0) as artificerCount,
ifnull(select count(*) from tb_user ac inner join artificer aa on a.user_id = aa.user_id where ac.bl_jjr_code = y.invitation_code,0) as artificerCount,
ifnull(select count(*) from tb_user ac inner join artificer aa on a.user_id = aa.user_id
where ac.bl_jjr_code = y.invitation_code and date_format(aa.create_time, '%Y-%m-%d') = date_format(now(),'%Y-%m-%d'),0) as curArtificerCount,
ifnull(t1.ordersCount,0) as ordersCount,
ifnull(t2.ordersCount,0) as curOrdersCount,
ifnull(t3.money,0) as money
from bl_jjr_apply x
inner join tb_user y on x.user_id = y.user_id
left join (
select count(*) as ordersCount, aa.user_id, bb.bl_jjr_code
from (
select o1.orders_id,a.user_id
from orders o1
left join orders o2 on o1.old_orders_id = o2.orders_id and o2.status != 4
left join orders o3 on o2.old_orders_id = o3.orders_id and o3.status != 4
left join artificer a on a.artificer_id=o1.artificer_id
where o1.old_orders_id is not null
and o1.status in (3,5)
union all
select o1.orders_id,a.user_id
from orders o1
left join artificer a on a.artificer_id=o1.artificer_id
where o1.parent_id = 0
and o1.old_orders_id is null
and o1.orders_id not in (
select orders_id from orders
where old_orders_id is not null
and status != 4
)
and o1.orders_id not in (
select old_orders_id from orders
where old_orders_id is not null
and status != 4
)
and o1.status in (3,5)
) aa inner join tb_user bb on aa.user_id = bb.user_id
group by aa.user_id, bb.bl_jjr_code
) t1 on t1.bl_jjr_code = y.invitation_code
left join (
select count(*) as ordersCount, aa.user_id, bb.bl_jjr_code
from (
select o1.orders_id,a.user_id
from orders o1
left join orders o2 on o1.old_orders_id = o2.orders_id and o2.status != 4
left join orders o3 on o2.old_orders_id = o3.orders_id and o3.status != 4
left join artificer a on a.artificer_id=o1.artificer_id
where o1.old_orders_id is not null
and o1.status in (3,5)
and date_format(o1.serve_time, '%Y-%m-%d') = date_format(now(),'%Y-%m-%d')
union all
select o1.orders_id,a.user_id
from orders o1
left join artificer a on a.artificer_id=o1.artificer_id
where o1.parent_id = 0
and o1.old_orders_id is null
and o1.orders_id not in (
select orders_id from orders
where old_orders_id is not null
and status != 4
)
and o1.orders_id not in (
select old_orders_id from orders
where old_orders_id is not null
and status != 4
)
and o1.status in (3,5)
and date_format(o1.serve_time, '%Y-%m-%d') = date_format(now(),'%Y-%m-%d')
) aa inner join tb_user bb on aa.user_id = bb.user_id