orders aggs_biz_ding_piao_rpt, ding search all

This commit is contained in:
qianhy
2022-12-20 12:04:37 +08:00
committed by lccsw
parent 65436186a6
commit f2ca56e3e4
+64 -4
View File
@@ -814,10 +814,10 @@ class Orders_v2_entity{
if (!$today_start || !$today_end || !$total_start || !$total_end){
return array();
}
# biz_type
# biz_type(已下订)
$sql = "
SELECT b.type as biz_type, o.biz_id, o.brand_id,ab.`name` as brand_name, o.s_id, s.`name` as series_name,
count(if(o.order_time >= '$today_start' AND o.order_time < '$today_end', o.id, null)) as doc_ding_today,
count(if(o.order_time >= '$today_start' AND o.order_time < '$today_end', o.id, null)) as doc_ding_today,
count(o.id) as doc_ding
FROM lc_receiver_orders_v2 o JOIN
(select o_id from lc_receiver_order_status where pid_status = '0' AND `status` in (1,2) GROUP BY o_id HAVING count(status) >= 1 ) os ON os.o_id = o.id
@@ -831,12 +831,12 @@ class Orders_v2_entity{
group by b.type, o.biz_id, o.brand_id, ab.`name`, o.s_id, s.`name`
order by b.type, o.biz_id, o.brand_id, o.s_id
";
# 只统计品牌店,合伙店,代理店,其中代理店按城市
# 只统计品牌店,合伙店,代理店,其中代理店按城市(已下订)
$sql = "
SELECT b.type as biz_type,
if(b.type in (3), b.city_id, o.biz_id) as biz_id,
o.brand_id,ab.`name` as brand_name, o.s_id, s.`name` as series_name,
count(if(o.order_time >= '$today_start' AND o.order_time < '$today_end', o.id, null)) as doc_ding_today,
count(if(o.order_time >= '$today_start' AND o.order_time < '$today_end', o.id, null)) as doc_ding_today,
count(o.id) as doc_ding
FROM lc_receiver_orders_v2 o JOIN
(select o_id from lc_receiver_order_status where pid_status = '0' AND `status` in (1,2) GROUP BY o_id HAVING count(status) >= 1 ) os ON os.o_id = o.id
@@ -852,6 +852,24 @@ class Orders_v2_entity{
group by b.type, if(b.type in (3), b.city_id, o.biz_id), o.brand_id, ab.`name`, o.s_id, s.`name`
order by b.type, if(b.type in (3), b.city_id, o.biz_id), o.brand_id, o.s_id
";
# 只统计品牌店,合伙店,代理店,其中代理店按城市(全部)
$sql = "
SELECT b.type as biz_type,
if(b.type in (3), b.city_id, o.biz_id) as biz_id,
o.brand_id, if(ab.`name` is null, '-', ab.`name`) as brand_name, o.s_id, if(s.`name` is null, '-', s.`name`) as series_name,
count(if(o.order_time >= '$today_start' AND o.order_time < '$today_end', o.id, null)) as doc_ding_today,
count(o.id) as doc_ding
FROM lc_receiver_orders_v2 o
left join lc_biz b on o.biz_id = b.id
left join lc_auto_brand ab on o.brand_id = ab.id
left join lc_auto_series s on o.s_id = s.id
left join lc_sys_city c on b.city_id = c.city_id
WHERE o.`status` >= 0
AND o.order_time >= '$total_start' AND o.order_time < '$total_end'
AND b.type in (1, 2, 3)
group by b.type, if(b.type in (3), b.city_id, o.biz_id), o.brand_id, ab.`name`, o.s_id, s.`name`
order by b.type, if(b.type in (3), b.city_id, o.biz_id), o.brand_id, o.s_id
";
return $this->ci->db->query($sql)->result_array();
}
@@ -1001,6 +1019,48 @@ class Orders_v2_entity{
group by biz_type, biz_id, biz_name
order by biz_type, biz_id
";
# 只统计品牌店,合伙店,代理店,其中代理店按城市(全部)
$sql = "
select biz_type, biz_id, biz_name,
if(sum(doc_ding_today)=0,null,sum(doc_ding_today)) as doc_ding_today,
if(sum(doc_ding)=0,null,sum(doc_ding)) as doc_ding,
if(sum(doc_piao_today)=0,null,sum(doc_piao_today)) as doc_piao_today,
if(sum(doc_piao)=0,null,sum(doc_piao)) as doc_piao
from
(
SELECT b.type as biz_type,
if(b.type in (3), b.city_id, o.biz_id) as biz_id,
if(b.type in (3), if(c.`name` is null, b.city_id, replace(concat(c.`name`, '渠道'), '市渠道', '渠道')), b.biz_name) as biz_name,
count(if(o.order_time >= '$today_start' AND o.order_time < '$today_end', o.id, null)) as doc_ding_today,
count(o.id) as doc_ding, null as doc_piao_today, null as doc_piao
FROM lc_receiver_orders_v2 o
left join lc_biz b on o.biz_id = b.id
left join lc_sys_city c on b.city_id = c.city_id
WHERE o.`status` >= 0
AND o.order_time >= '$total_start' AND o.order_time < '$total_end'
AND b.type in (1, 2, 3)
group by b.type, if(b.type in (3), b.city_id, o.biz_id), if(b.type in (3), if(c.`name` is null, b.city_id, c.`name`), b.biz_name)
union all
SELECT b.type as biz_type,
if(b.type in (3), b.city_id, o.biz_id) as biz_id,
if(b.type in (3), if(c.`name` is null, b.city_id, replace(concat(c.`name`, '渠道'), '市渠道', '渠道')), b.biz_name) as biz_name,
null as doc_ding_today, null as doc_ding,
count(if(o.bill_time >= '$today_start' AND o.bill_time < '$today_end', o.id, null)) as doc_piao_today,
count(o.id) as doc_piao
FROM lc_receiver_orders_v2 o JOIN
(select o_id from lc_receiver_order_status where pid_status = '3' AND `status` in (1,2) GROUP BY o_id HAVING count(status) = 1 ) os ON os.o_id = o.id
left join lc_biz b on o.biz_id = b.id
left join lc_sys_city c on b.city_id = c.city_id
WHERE o.`status` >= 0
AND o.bill_time >= '$total_start' AND o.bill_time < '$total_end'
AND o.brand_id > 0
AND o.`status` <> 2
AND b.type in (1, 2, 3)
group by b.type, if(b.type in (3), b.city_id, o.biz_id), if(b.type in (3), if(c.`name` is null, b.city_id, c.`name`), b.biz_name)
) u
group by biz_type, biz_id, biz_name
order by biz_type, biz_id
";
return $this->ci->db->query($sql)->result_array();
}