orders aggs rpt group by city_id
This commit is contained in:
@@ -871,6 +871,29 @@ class Orders_v2_entity{
|
||||
";
|
||||
return $this->ci->db->query($sql)->result_array();
|
||||
}
|
||||
public function aggs_biz_brand_ding_cityid($today_start='', $today_end='', $total_start='', $total_end=''){
|
||||
if (!$today_start || !$today_end || !$total_start || !$total_end){
|
||||
return array();
|
||||
}
|
||||
$sql = "
|
||||
SELECT b.city_id as biz_type,
|
||||
if(b.type in (2, 3), b.type, 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.city_id, if(b.type in (2, 3), b.type, o.biz_id), o.brand_id, ab.`name`, o.s_id, s.`name`
|
||||
order by b.city_id, FIELD(b.type,1,2,3), if(b.type in (2, 3), b.type, o.biz_id), o.brand_id, o.s_id
|
||||
";
|
||||
return $this->ci->db->query($sql)->result_array();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按“商家-品牌”开票统计
|
||||
@@ -924,6 +947,32 @@ class Orders_v2_entity{
|
||||
";
|
||||
return $this->ci->db->query($sql)->result_array();
|
||||
}
|
||||
public function aggs_biz_brand_piao_cityid($today_start='', $today_end='', $total_start='', $total_end=''){
|
||||
if (!$today_start || !$today_end || !$total_start || !$total_end){
|
||||
return array();
|
||||
}
|
||||
$sql = "
|
||||
SELECT b.city_id as biz_type,
|
||||
if(b.type in (2, 3), b.type, 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.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_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.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.city_id, if(b.type in (2, 3), b.type, o.biz_id), o.brand_id, ab.`name`, o.s_id, s.`name`
|
||||
order by b.city_id, FIELD(b.type,1,2,3), if(b.type in (2, 3), b.type, o.biz_id), o.brand_id, o.s_id
|
||||
";
|
||||
return $this->ci->db->query($sql)->result_array();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按“商家”下定+开票统计
|
||||
@@ -1062,9 +1111,58 @@ class Orders_v2_entity{
|
||||
";
|
||||
return $this->ci->db->query($sql)->result_array();
|
||||
}
|
||||
public function aggs_biz_ding_piao_cityid($today_start='', $today_end='', $total_start='', $total_end=''){
|
||||
if (!$today_start || !$today_end || !$total_start || !$total_end){
|
||||
return array();
|
||||
}
|
||||
$sql = "
|
||||
select biz_type, city_name, 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.city_id as biz_type,
|
||||
c.`name` as city_name,
|
||||
if(b.type in (2, 3), b.type, o.biz_id) as biz_id,
|
||||
case when b.type=2 then '合伙店' when b.type=3 then '渠道店' else b.biz_name end 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.city_id, c.`name`, if(b.type in (2, 3), b.type, o.biz_id), case when b.type=2 then '合伙店' when b.type=3 then '渠道店' else b.biz_name end
|
||||
union all
|
||||
SELECT b.city_id as biz_type,
|
||||
c.`name` as city_name,
|
||||
if(b.type in (2, 3), b.type, o.biz_id) as biz_id,
|
||||
case when b.type=2 then '合伙店' when b.type=3 then '渠道店' else b.biz_name end 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.city_id, c.`name`, if(b.type in (2, 3), b.type, o.biz_id), case when b.type=2 then '合伙店' when b.type=3 then '渠道店' else b.biz_name end
|
||||
) u
|
||||
group by biz_type, city_name, biz_id, biz_name
|
||||
order by biz_type, biz_id desc
|
||||
";
|
||||
return $this->ci->db->query($sql)->result_array();
|
||||
}
|
||||
|
||||
/**
|
||||
* 商家下定+开票统计
|
||||
* 商家下定+开票统计:按店铺类型,品牌拆分为系列,支持订单与开票独立图片
|
||||
* @param $today_start
|
||||
* @param $today_end
|
||||
* @param $total_start
|
||||
@@ -1078,6 +1176,341 @@ class Orders_v2_entity{
|
||||
* @return array
|
||||
*/
|
||||
public function aggs_biz_ding_piao_rpt($today_start='', $today_end='', $total_start='', $total_end='',
|
||||
$title_today='', $title_ding_today='', $title_ding='', $title_piao_today='', $title_piao='', $create_table_image=false, $title='日期'){
|
||||
!$today_start && $today_start = date('Y-m-d 00:00:00');
|
||||
!$today_end && $today_end = date('Y-m-d 00:00:00', strtotime('+1 day'));
|
||||
!$total_start && $total_start = date('Y-m-01 00:00:00');
|
||||
!$total_end && $total_end = date('Y-m-01 00:00:00', strtotime('+1 month'));
|
||||
!$title_today && $title_today = date('m月d日');
|
||||
!$title_ding_today && $title_ding_today = '当日订单';
|
||||
!$title_ding && $title_ding = '月累计订单';
|
||||
!$title_piao_today && $title_piao_today = '当日开票';
|
||||
!$title_piao && $title_piao = '月累计开票';
|
||||
|
||||
$ding = $this->aggs_biz_brand_ding_cityid($today_start, $today_end, $total_start, $total_end);
|
||||
$piao = $this->aggs_biz_brand_piao_cityid($today_start, $today_end, $total_start, $total_end);
|
||||
$biz = $this->aggs_biz_ding_piao_cityid($today_start, $today_end, $total_start, $total_end);
|
||||
#var_dump($today_start);var_dump($today_end);var_dump($total_start);var_dump($total_end);var_dump($ding); var_dump($piao);var_dump($biz);
|
||||
if (!$biz){
|
||||
return array();
|
||||
}
|
||||
|
||||
# 生成品牌arr
|
||||
$brand_names = array_unique(array_merge(array_column($ding, 'brand_name'), array_column($piao, 'brand_name')));
|
||||
sort($brand_names);
|
||||
|
||||
# 生成品牌对应的车系arr
|
||||
$series_names = array();
|
||||
foreach ($ding as $k => $v){
|
||||
$series_name = $v['series_name'];
|
||||
$key = $v['brand_name'];
|
||||
if (!$series_names[$key]){
|
||||
$series_names[$key][] = $series_name;
|
||||
continue;
|
||||
}
|
||||
if (!in_array($series_name, $series_names[$key])){
|
||||
$series_names[$key][] = $series_name;
|
||||
}
|
||||
}
|
||||
foreach ($piao as $k => $v){
|
||||
$series_name = $v['series_name'];
|
||||
$key = $v['brand_name'];
|
||||
if (!$series_names[$key]){
|
||||
$series_names[$key][] = $series_name;
|
||||
continue;
|
||||
}
|
||||
if (!in_array($series_name, $series_names[$key])){
|
||||
$series_names[$key][] = $series_name;
|
||||
}
|
||||
}
|
||||
#var_dump($brand_names); var_dump($series_names);
|
||||
|
||||
# 生成表头
|
||||
$indexs_total = array();
|
||||
$indexs_total[] = 'doc_ding';
|
||||
$indexs_total[] = 'doc_piao';
|
||||
$arr1 = array('city_name'=>$title, 'biz_name'=>$title_today, 'doc_ding_today'=>$title_ding_today);
|
||||
/*foreach ($brand_names as $k => $v){
|
||||
foreach ($v as $k1 => $v1){
|
||||
$arr1[$k.'_'.$v1.'_ding_today'] = $k.'_'.$v1;
|
||||
}
|
||||
$arr1[$k.'_ding_today'] = $k;
|
||||
}*/
|
||||
$arr1 = array_merge($arr1, array('doc_ding'=>$title_ding));
|
||||
/*foreach ($series_names as $k => $v){
|
||||
$indexs_total[] = $k.'_ding';
|
||||
$arr1[$k.'_ding'] = $k; # 品牌在系列前
|
||||
foreach ($v as $k1 => $v1){
|
||||
#$arr1[$k.'_'.$v1.'_ding'] = $k.'_'.$v1;
|
||||
$arr1[$k.'_'.$v1.'_ding'] = ' '.$v1; # 系列简写
|
||||
}
|
||||
}*/
|
||||
foreach ($brand_names as $brand_name){
|
||||
if ($v = $series_names[$brand_name]){
|
||||
$k = $brand_name;
|
||||
sort($v);
|
||||
$indexs_total[] = $k.'_ding';
|
||||
$arr1[$k.'_ding'] = $k; # 品牌在系列前
|
||||
foreach ($v as $k1 => $v1){
|
||||
#$arr1[$k.'_'.$v1.'_ding'] = $k.'_'.$v1;
|
||||
$arr1[$k.'_'.$v1.'_ding'] = ' '.$v1; # 系列简写
|
||||
}
|
||||
}
|
||||
}
|
||||
$arr3 = array('doc_piao_today'=>$title_piao_today);
|
||||
/*foreach ($brand_names as $k => $v){
|
||||
foreach ($v as $k1 => $v1){
|
||||
$arr3[$k.'_'.$v1.'_piao_today'] = $k.'_'.$v1;
|
||||
}
|
||||
$arr3[$k.'_piao_today'] = $k;
|
||||
}*/
|
||||
/*$arr3 = array_merge($arr3, array('doc_piao'=>$title_piao));
|
||||
foreach ($series_names as $k => $v){
|
||||
$indexs_total[] = $k.'_piao';
|
||||
$arr3[$k.'_piao'] = $k; # 品牌在系列前
|
||||
foreach ($v as $k1 => $v1){
|
||||
#$arr3[$k.'_'.$v1.'_piao'] = $k.'_'.$v1;
|
||||
$arr3[$k.'_'.$v1.'_piao'] = ' '.$v1; # 系列简写
|
||||
}
|
||||
}*/
|
||||
foreach ($brand_names as $brand_name){
|
||||
if ($v = $series_names[$brand_name]) {
|
||||
$k = $brand_name;
|
||||
sort($v);
|
||||
$indexs_total[] = $k.'_piao';
|
||||
$arr3[$k.'_piao'] = $k; # 品牌在系列前
|
||||
foreach ($v as $k1 => $v1){
|
||||
#$arr3[$k.'_'.$v1.'_piao'] = $k.'_'.$v1;
|
||||
$arr3[$k.'_'.$v1.'_piao'] = ' '.$v1; # 系列简写
|
||||
}
|
||||
}
|
||||
}
|
||||
$indexs = array_merge($arr1, $arr3); #var_dump($indexs);
|
||||
|
||||
# $ding, $piao 行转kv,生成xj小记与hj合计: 1 _1_东风EV_doc_ding 7; 1 _东风EV_doc_ding 9; 东风EV_doc_ding 9
|
||||
$kv = array();
|
||||
foreach (array_merge($ding, $piao) as $k => $v){
|
||||
$key_ding = $v['biz_type'].'_'.$v['biz_id'].'_'.$v['brand_name'].'_doc_ding';
|
||||
$key_ding_xj = $v['biz_type'].'_'.$v['brand_name'].'_doc_ding';
|
||||
$key_ding_hj = $v['brand_name'].'_doc_ding';
|
||||
$key_ding_series = $v['biz_type'].'_'.$v['biz_id'].'_'.$v['brand_name'].'_'.$v['series_name'].'_doc_ding';
|
||||
$key_ding_series_xj = $v['biz_type'].'_'.$v['brand_name'].'_'.$v['series_name'].'_doc_ding';
|
||||
$key_ding_series_hj = $v['brand_name'].'_'.$v['series_name'].'_doc_ding';
|
||||
|
||||
$key_piao = $v['biz_type'].'_'.$v['biz_id'].'_'.$v['brand_name'].'_doc_piao';
|
||||
$key_piao_xj = $v['biz_type'].'_'.$v['brand_name'].'_doc_piao';
|
||||
$key_piao_hj = $v['brand_name'].'_doc_piao';
|
||||
$key_piao_series = $v['biz_type'].'_'.$v['biz_id'].'_'.$v['brand_name'].'_'.$v['series_name'].'_doc_piao';
|
||||
$key_piao_series_xj = $v['biz_type'].'_'.$v['brand_name'].'_'.$v['series_name'].'_doc_piao';
|
||||
$key_piao_series_hj = $v['brand_name'].'_'.$v['series_name'].'_doc_piao';
|
||||
|
||||
if ($temp = intval($v['doc_ding'])){
|
||||
$kv[$key_ding_series] = $temp;
|
||||
$kv[$key_ding_series_xj] = $kv[$key_ding_series_xj] ? $kv[$key_ding_series_xj] + $temp: $temp;
|
||||
$kv[$key_ding_series_hj] = $kv[$key_ding_series_hj] ? $kv[$key_ding_series_hj] + $temp: $temp;
|
||||
$kv[$key_ding] = $kv[$key_ding] ? $kv[$key_ding] + $temp: $temp;
|
||||
$kv[$key_ding_xj] = $kv[$key_ding_xj] ? $kv[$key_ding_xj] + $temp: $temp;
|
||||
$kv[$key_ding_hj] = $kv[$key_ding_hj] ? $kv[$key_ding_hj] + $temp: $temp;
|
||||
}
|
||||
|
||||
if ($temp = intval($v['doc_piao'])){
|
||||
$kv[$key_piao_series] = $temp;
|
||||
$kv[$key_piao_series_xj] = $kv[$key_piao_series_xj] ? $kv[$key_piao_series_xj] + $temp: $temp;
|
||||
$kv[$key_piao_series_hj] = $kv[$key_piao_series_hj] ? $kv[$key_piao_series_hj] + $temp: $temp;
|
||||
$kv[$key_piao] = $kv[$key_piao] ? $kv[$key_piao] + $temp: $temp;
|
||||
$kv[$key_piao_xj] = $kv[$key_piao_xj] ? $kv[$key_piao_xj] + $temp: $temp;
|
||||
$kv[$key_piao_hj] = $kv[$key_piao_hj] ? $kv[$key_piao_hj] + $temp: $temp;
|
||||
}
|
||||
}
|
||||
|
||||
$biz_type = $city_name = $biz_id = $biz_name = null;
|
||||
$doc_ding_today = $doc_ding = $doc_piao_today = $doc_piao = 0;
|
||||
$doc_ding_today_ = $doc_ding_ = $doc_piao_today_ = $doc_piao_ = 0;
|
||||
$biz_aggs = array();
|
||||
foreach ($biz as $k1 => $v1){
|
||||
!$biz_type && $biz_type = $v1['biz_type'];
|
||||
!$city_name && $city_name = $v1['city_name'];
|
||||
$biz_id = $v1['biz_id'];
|
||||
$biz_name = $v1['biz_name'];
|
||||
|
||||
$doc_ding_today_ += $v1['doc_ding_today'] ? $v1['doc_ding_today'] : 0;
|
||||
$doc_ding_ += $v1['doc_ding'] ? $v1['doc_ding'] : 0;
|
||||
$doc_piao_today_ += $v1['doc_piao_today'] ? $v1['doc_piao_today'] : 0;
|
||||
$doc_piao_ += $v1['doc_piao'] ? $v1['doc_piao'] : 0;
|
||||
|
||||
if ($biz_type <> $v1['biz_type']){
|
||||
#$biz_type_ary = $this->ci->biz_model->type_ary();
|
||||
#$biz_type_name = $biz_type_ary[$biz_type] ? '('.$biz_type_ary[$biz_type].')' : ''; # 'biz_name'=>$biz_type_name.'小计'
|
||||
$arr1 = array('city_name'=>'', 'biz_type'=>$biz_type, 'biz_id'=>'', 'biz_name'=>'小计', 'doc_ding_today'=>$doc_ding_today ? $doc_ding_today : '', 'doc_ding'=>$doc_ding ? $doc_ding : '');
|
||||
foreach ($brand_names as $k2 => $v2){
|
||||
# 生成车型列
|
||||
$key_ding_xj = $biz_type.'_'.$v2.'_doc_ding';
|
||||
$arr1[$v2.'_ding'] = $kv[$key_ding_xj] ? $kv[$key_ding_xj] : '';
|
||||
|
||||
# 生成车系列
|
||||
foreach ($series_names[$v2] as $ks => $vs){
|
||||
$key_ding_series_xj = $biz_type.'_'.$v2.'_'.$vs.'_doc_ding';
|
||||
$arr1[$v2.'_'.$vs.'_ding'] = $kv[$key_ding_series_xj] ? $kv[$key_ding_series_xj] : '';
|
||||
}
|
||||
}
|
||||
$arr3 = array('doc_piao_today'=>$doc_piao_today ? $doc_piao_today : '', 'doc_piao'=>$doc_piao ? $doc_piao : '');
|
||||
foreach ($brand_names as $k2 => $v2){
|
||||
$key_piao_xj = $biz_type.'_'.$v2.'_doc_piao';
|
||||
$arr3[$v2.'_piao'] = $kv[$key_piao_xj] ? $kv[$key_piao_xj] : '';
|
||||
|
||||
foreach ($series_names[$v2] as $ks => $vs){
|
||||
$key_piao_series_xj = $biz_type.'_'.$v2.'_'.$vs.'_doc_piao';
|
||||
$arr3[$v2.'_'.$vs.'_piao'] = $kv[$key_piao_series_xj] ? $kv[$key_piao_series_xj] : '';
|
||||
}
|
||||
}
|
||||
$biz_aggs[] = array_merge($arr1, $arr3);
|
||||
|
||||
$biz_type = $v1['biz_type'];
|
||||
$city_name = $v1['city_name'];
|
||||
$doc_ding_today = $doc_ding = $doc_piao_today = $doc_piao = 0;
|
||||
}
|
||||
|
||||
$doc_ding_today += $v1['doc_ding_today'] ? $v1['doc_ding_today'] : 0;
|
||||
$doc_ding += $v1['doc_ding'] ? $v1['doc_ding'] : 0;
|
||||
$doc_piao_today += $v1['doc_piao_today'] ? $v1['doc_piao_today'] : 0;
|
||||
$doc_piao += $v1['doc_piao'] ? $v1['doc_piao'] : 0;
|
||||
|
||||
$arr1 = array('city_name'=>$city_name, 'biz_type'=>$biz_type, 'biz_id'=>$biz_id, 'biz_name'=>$biz_name, 'doc_ding_today'=>$v1['doc_ding_today'] ? $v1['doc_ding_today'] : '', 'doc_ding'=>$v1['doc_ding'] ? $v1['doc_ding'] : '');
|
||||
foreach ($brand_names as $k2 => $v2){
|
||||
$key_ding = $v1['biz_type'].'_'.$v1['biz_id'].'_'.$v2.'_doc_ding';
|
||||
$arr1[$v2.'_ding'] = $kv[$key_ding] ? $kv[$key_ding] : '';
|
||||
|
||||
foreach ($series_names[$v2] as $ks => $vs){
|
||||
$key_ding_series = $v1['biz_type'].'_'.$v1['biz_id'].'_'.$v2.'_'.$vs.'_doc_ding';
|
||||
$arr1[$v2.'_'.$vs.'_ding'] = $kv[$key_ding_series] ? $kv[$key_ding_series] : '';
|
||||
}
|
||||
}
|
||||
$arr3 = array('doc_piao_today'=>$v1['doc_piao_today'] ? $v1['doc_piao_today'] : '', 'doc_piao'=>$v1['doc_piao'] ? $v1['doc_piao'] : '');
|
||||
foreach ($brand_names as $k2 => $v2){
|
||||
$key_piao = $v1['biz_type'].'_'.$v1['biz_id'].'_'.$v2.'_doc_piao';
|
||||
$arr3[$v2.'_piao'] = $kv[$key_piao] ? $kv[$key_piao] : '';
|
||||
|
||||
foreach ($series_names[$v2] as $ks => $vs){
|
||||
$key_piao_series = $v1['biz_type'].'_'.$v1['biz_id'].'_'.$v2.'_'.$vs.'_doc_piao';
|
||||
$arr3[$v2.'_'.$vs.'_piao'] = $kv[$key_piao_series] ? $kv[$key_piao_series] : '';
|
||||
}
|
||||
}
|
||||
$biz_aggs[] = array_merge($arr1, $arr3);
|
||||
}
|
||||
|
||||
# 最后一个小计
|
||||
#$biz_type_ary = $this->ci->biz_model->type_ary();
|
||||
#$biz_type_name = $biz_type_ary[$biz_type] ? '('.$biz_type_ary[$biz_type].')' : ''; # 'biz_name'=>$biz_type_name.'小计'
|
||||
$arr1 = array('city_name'=>'', 'biz_type'=>$biz_type, 'biz_id'=>'', 'biz_name'=>'小计', 'doc_ding_today'=>$doc_ding_today ? $doc_ding_today : '', 'doc_ding'=>$doc_ding ? $doc_ding : '');
|
||||
foreach ($brand_names as $k2 => $v2){
|
||||
$key_ding_xj = $biz_type.'_'.$v2.'_doc_ding';
|
||||
$arr1[$v2.'_ding'] = $kv[$key_ding_xj] ? $kv[$key_ding_xj] : '';
|
||||
|
||||
foreach ($series_names[$v2] as $ks => $vs){
|
||||
$key_ding_series_xj = $biz_type.'_'.$v2.'_'.$vs.'_doc_ding';
|
||||
$arr1[$v2.'_'.$vs.'_ding'] = $kv[$key_ding_series_xj] ? $kv[$key_ding_series_xj] : '';
|
||||
}
|
||||
}
|
||||
$arr3 = array('doc_piao_today'=>$doc_piao_today ? $doc_piao_today : '', 'doc_piao'=>$doc_piao ? $doc_piao : '');
|
||||
foreach ($brand_names as $k2 => $v2){
|
||||
$key_piao_xj = $biz_type.'_'.$v2.'_doc_piao';
|
||||
$arr3[$v2.'_piao'] = $kv[$key_piao_xj] ? $kv[$key_piao_xj] : '';
|
||||
|
||||
foreach ($series_names[$v2] as $ks => $vs){
|
||||
$key_piao_series_xj = $biz_type.'_'.$v2.'_'.$vs.'_doc_piao';
|
||||
$arr3[$v2.'_'.$vs.'_piao'] = $kv[$key_piao_series_xj] ? $kv[$key_piao_series_xj] : '';
|
||||
}
|
||||
}
|
||||
$biz_aggs[] = array_merge($arr1, $arr3);
|
||||
|
||||
# 合计
|
||||
$arr1 = array('city_name'=>'', 'biz_type'=>'', 'biz_id'=>'', 'biz_name'=>'合计', 'doc_ding_today'=>$doc_ding_today_ ? $doc_ding_today_ : '', 'doc_ding'=>$doc_ding_ ? $doc_ding_ : '');
|
||||
foreach ($brand_names as $k2 => $v2){
|
||||
$key_ding_hj = $v2.'_doc_ding';
|
||||
$arr1[$v2.'_ding'] = $kv[$key_ding_hj] ? $kv[$key_ding_hj] : '';
|
||||
|
||||
foreach ($series_names[$v2] as $ks => $vs){
|
||||
$key_ding_series_hj = $v2.'_'.$vs.'_doc_ding';
|
||||
$arr1[$v2.'_'.$vs.'_ding'] = $kv[$key_ding_series_hj] ? $kv[$key_ding_series_hj] : '';
|
||||
}
|
||||
}
|
||||
$arr3 = array('doc_piao_today'=>$doc_piao_today_ ? $doc_piao_today_ : '', 'doc_piao'=>$doc_piao_ ? $doc_piao_ : '');
|
||||
foreach ($brand_names as $k2 => $v2){
|
||||
$key_piao_hj = $v2.'_doc_piao';
|
||||
$arr3[$v2.'_piao'] = $kv[$key_piao_hj] ? $kv[$key_piao_hj] : '';
|
||||
|
||||
foreach ($series_names[$v2] as $ks => $vs){
|
||||
$key_ding_series_hj = $v2.'_'.$vs.'_doc_piao';
|
||||
$arr3[$v2.'_'.$vs.'_piao'] = $kv[$key_ding_series_hj] ? $kv[$key_ding_series_hj] : '';
|
||||
}
|
||||
}
|
||||
$biz_aggs[] = array_merge($arr1, $arr3);#var_dump($indexs);var_dump($biz_aggs);
|
||||
|
||||
$img_path = $img_path_ding = $img_path_piao = '';
|
||||
if ($create_table_image){
|
||||
$data = $biz_aggs;
|
||||
foreach ($data as $k => $v){
|
||||
unset($data[$k]['biz_type']);
|
||||
unset($data[$k]['biz_id']);
|
||||
$data[$k]['biz_name'] = mb_strlen ($data[$k]['biz_name']) > 9 ? mb_substr($data[$k]['biz_name'], 0, 9).'..' : $data[$k]['biz_name'];
|
||||
}
|
||||
$data_ding = $data_piao = $data;
|
||||
foreach ($data_ding as $k => $v){
|
||||
foreach ($data_ding[$k] as $kd => $vd){
|
||||
if (strpos($kd,'_piao') !== false){
|
||||
unset($data_ding[$k][$kd]);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($data_ding as $k => $v){
|
||||
foreach ($data_ding[$k] as $kd => $vd){
|
||||
if (strpos($kd,'_ding') !== false){
|
||||
unset($data_piao[$k][$kd]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$index_img = $indexs;
|
||||
$index_img_ding = $index_img_piao = array();
|
||||
foreach ($index_img as $k => $v){
|
||||
#$k != 'biz_name' && $index_img[$k] = mb_strlen ($v) > 8 ? mb_substr($v, -8, 8) : $v;
|
||||
if ($k != 'biz_name'){
|
||||
/*if (strpos($k,'_') !== false){
|
||||
$index_img[$k] = mb_strlen ($v) > 8 ? mb_substr($v, 0, 2).'..'.mb_substr(array_slice(explode('_', $v), -1)[0], -5, 5) : str_replace('_', ' ', $v);
|
||||
}
|
||||
else{
|
||||
$index_img[$k] = mb_strlen ($v) > 5 ? mb_substr($v, 0, 5) : $v;
|
||||
}*/
|
||||
$index_img[$k] = $v; # 讲话车系后直接显示全部
|
||||
}
|
||||
if (strpos($k,'_ding') !== false){
|
||||
$index_img_ding[$k] = $index_img[$k];
|
||||
}
|
||||
elseif (strpos($k,'_piao') !== false){
|
||||
$index_img_piao[$k] = $index_img[$k];
|
||||
}
|
||||
else{
|
||||
$index_img_ding[$k] = $index_img[$k];
|
||||
$index_img_piao[$k] = $index_img[$k];
|
||||
}
|
||||
}
|
||||
|
||||
# 去掉空列与空行
|
||||
$this->clear_null_column_line($biz_aggs, $indexs);
|
||||
$this->clear_null_column_line($data, $index_img);
|
||||
$this->clear_null_column_line($data_ding, $index_img_ding);
|
||||
$this->clear_null_column_line($data_piao, $index_img_piao);
|
||||
#var_dump($data_piao);var_dump('<br>');var_dump($index_img_piao);var_dump('<br>');var_dump($indexs_total);
|
||||
|
||||
#var_dump($biz_aggs[0]);var_dump($data[0]);var_dump($index_img);var_dump($data_ding[0]);var_dump($index_img_ding);var_dump($data_piao[0]);var_dump($index_img_piao);;
|
||||
$img_path = $this->create_table_image($data, $index_img, $indexs_total, '小狸播报', 'aggs_biz_rpt.png');
|
||||
$img_path_ding = $this->create_table_image($data_ding, $index_img_ding, $indexs_total, '小狸播报 - 订单', 'aggs_biz_rpt_ding.png');
|
||||
$img_path_piao = $this->create_table_image($data_piao, $index_img_piao, $indexs_total, '小狸播报 - 开票', 'aggs_biz_rpt_piao.png');
|
||||
}
|
||||
return array('biz_aggs'=>$biz_aggs, 'indexs'=>$indexs, 'img_path'=>$img_path, 'img_path_ding'=>$img_path_ding, 'img_path_piao'=>$img_path_piao, 'brand_names'=>$brand_names, 'series_names'=>$series_names);
|
||||
}
|
||||
// 商家下定+开票统计 simple:按店铺类型,拆分品牌的系列
|
||||
public function aggs_biz_ding_piao_rpt_series($today_start='', $today_end='', $total_start='', $total_end='',
|
||||
$title_today='', $title_ding_today='', $title_ding='', $title_piao_today='', $title_piao='', $create_table_image=false){
|
||||
!$today_start && $today_start = date('Y-m-d 00:00:00');
|
||||
!$today_end && $today_end = date('Y-m-d 00:00:00', strtotime('+1 day'));
|
||||
@@ -1099,6 +1532,7 @@ class Orders_v2_entity{
|
||||
|
||||
# 生成品牌arr
|
||||
$brand_names = array_unique(array_merge(array_column($ding, 'brand_name'), array_column($piao, 'brand_name')));
|
||||
sort($brand_names);
|
||||
|
||||
# 生成品牌对应的车系arr
|
||||
$series_names = array();
|
||||
@@ -1138,13 +1572,25 @@ class Orders_v2_entity{
|
||||
$arr1[$k.'_ding_today'] = $k;
|
||||
}*/
|
||||
$arr1 = array_merge($arr1, array('doc_ding'=>$title_ding));
|
||||
foreach ($series_names as $k => $v){
|
||||
/*foreach ($series_names as $k => $v){
|
||||
$indexs_total[] = $k.'_ding';
|
||||
$arr1[$k.'_ding'] = $k; # 品牌在系列前
|
||||
foreach ($v as $k1 => $v1){
|
||||
#$arr1[$k.'_'.$v1.'_ding'] = $k.'_'.$v1;
|
||||
$arr1[$k.'_'.$v1.'_ding'] = ' '.$v1; # 系列简写
|
||||
}
|
||||
}*/
|
||||
foreach ($brand_names as $brand_name){
|
||||
if ($v = $series_names[$brand_name]){
|
||||
$k = $brand_name;
|
||||
sort($v);
|
||||
$indexs_total[] = $k.'_ding';
|
||||
$arr1[$k.'_ding'] = $k; # 品牌在系列前
|
||||
foreach ($v as $k1 => $v1){
|
||||
#$arr1[$k.'_'.$v1.'_ding'] = $k.'_'.$v1;
|
||||
$arr1[$k.'_'.$v1.'_ding'] = ' '.$v1; # 系列简写
|
||||
}
|
||||
}
|
||||
}
|
||||
$arr3 = array('doc_piao_today'=>$title_piao_today);
|
||||
/*foreach ($brand_names as $k => $v){
|
||||
@@ -1154,13 +1600,25 @@ class Orders_v2_entity{
|
||||
$arr3[$k.'_piao_today'] = $k;
|
||||
}*/
|
||||
$arr3 = array_merge($arr3, array('doc_piao'=>$title_piao));
|
||||
foreach ($series_names as $k => $v){
|
||||
/*foreach ($series_names as $k => $v){
|
||||
$indexs_total[] = $k.'_piao';
|
||||
$arr3[$k.'_piao'] = $k; # 品牌在系列前
|
||||
foreach ($v as $k1 => $v1){
|
||||
#$arr3[$k.'_'.$v1.'_piao'] = $k.'_'.$v1;
|
||||
$arr3[$k.'_'.$v1.'_piao'] = ' '.$v1; # 系列简写
|
||||
}
|
||||
}*/
|
||||
foreach ($brand_names as $brand_name){
|
||||
if ($v = $series_names[$brand_name]) {
|
||||
$k = $brand_name;
|
||||
sort($v);
|
||||
$indexs_total[] = $k.'_piao';
|
||||
$arr3[$k.'_piao'] = $k; # 品牌在系列前
|
||||
foreach ($v as $k1 => $v1){
|
||||
#$arr3[$k.'_'.$v1.'_piao'] = $k.'_'.$v1;
|
||||
$arr3[$k.'_'.$v1.'_piao'] = ' '.$v1; # 系列简写
|
||||
}
|
||||
}
|
||||
}
|
||||
$indexs = array_merge($arr1, $arr3); #var_dump($indexs);
|
||||
|
||||
@@ -1385,7 +1843,7 @@ class Orders_v2_entity{
|
||||
return array('biz_aggs'=>$biz_aggs, 'indexs'=>$indexs, 'img_path'=>$img_path, 'img_path_ding'=>$img_path_ding, 'img_path_piao'=>$img_path_piao, 'brand_names'=>$brand_names, 'series_names'=>$series_names);
|
||||
}
|
||||
|
||||
// 商家下定+开票统计 simple, 只拆分品牌列
|
||||
// 商家下定+开票统计 simple:按店铺类型,只拆分品牌列
|
||||
public function aggs_biz_ding_piao_rpt_simple($today_start='', $today_end='', $total_start='', $total_end='',
|
||||
$title_today='', $title_ding_today='', $title_ding='', $title_piao_today='', $title_piao='', $create_table_image=false){
|
||||
!$today_start && $today_start = date('Y-m-d 00:00:00');
|
||||
@@ -1534,8 +1992,8 @@ class Orders_v2_entity{
|
||||
return array('biz_aggs'=>$biz_aggs, 'indexs'=>$indexs, 'img_path'=>$img_path);
|
||||
}
|
||||
|
||||
private function clear_null_column_line(&$data, &$indexs, $index_ignore_column=array('biz_type', 'biz_id', 'biz_name', 'doc_ding_today', 'doc_ding', 'doc_piao_today', 'doc_piao'),
|
||||
$index_ignore_line=array('biz_type', 'biz_id', 'biz_name')){
|
||||
private function clear_null_column_line(&$data, &$indexs, $index_ignore_column=array('biz_type', 'city_name', 'biz_id', 'biz_name', 'doc_ding_today', 'doc_ding', 'doc_piao_today', 'doc_piao'),
|
||||
$index_ignore_line=array('biz_type', 'city_name', 'biz_id', 'biz_name')){
|
||||
# $biz_aggs去掉除列(biz_type, biz_id, biz_name, doc_ding_today, doc_ding, doc_piao_today, doc_piao)外为空的空列 + $indexs 去掉列名
|
||||
$columns = array();
|
||||
foreach ($data as $k => $v){
|
||||
@@ -1622,6 +2080,7 @@ class Orders_v2_entity{
|
||||
'row_hight' => 30,//每行数据行高
|
||||
'filed_id_width' => 60,//序号列的宽度
|
||||
'filed_name_width' => 200,//玩家名称的宽度
|
||||
'filed_name_columns' => 1, //非数据列数据,也可传参数来控制
|
||||
'filed_data_width' => 90,//数据列的宽度
|
||||
'table_header' => array('序号', '昵称', '数据1', '数据2', '数据3', '数据4', '数据5', '数据6'),//表头文字
|
||||
'column_text_offset_arr' => array(50, 180, 70, 70, 70, 70, 70, 70),//表头文字左偏移量
|
||||
@@ -1629,22 +2088,30 @@ class Orders_v2_entity{
|
||||
);
|
||||
|
||||
// $base替换start
|
||||
if (in_array('city_name', array_keys($indexs))) {
|
||||
$base['filed_name_columns'] = 2;
|
||||
}
|
||||
$base['table_header'] = array_merge(array('序号'), array_values($indexs));
|
||||
$column = count($base['table_header']);
|
||||
$column_data = $column - 2;
|
||||
$offset_arr = array(50, 180);
|
||||
$offset_arr_left = array(50); # 序号列
|
||||
for ($i=0; $i<$base['filed_name_columns']; $i++){
|
||||
$offset_arr_left[] = 180;
|
||||
}
|
||||
$offset_arr = array();
|
||||
$column_data = $column - $base['filed_name_columns'] -1;
|
||||
for ($i=0; $i<$column_data; $i++){
|
||||
$offset_arr[] = 88;
|
||||
}
|
||||
$base['column_text_offset_arr'] = $offset_arr;
|
||||
$offset_arr = array(50, 180);
|
||||
for ($i=1; $i<=$column_data; $i++){
|
||||
$base['column_text_offset_arr'] = array_merge($offset_arr_left, $offset_arr);
|
||||
$offset_arr = array();
|
||||
for ($i=0; $i<$column_data; $i++){
|
||||
$offset_arr[] = 40;
|
||||
}
|
||||
$base['row_text_offset_arr'] = $offset_arr;
|
||||
$base['row_text_offset_arr'] = array_merge($offset_arr_left, $offset_arr);
|
||||
#var_dump(array_keys($indexs));var_dump('<br>');var_dump($base['column_text_offset_arr']);var_dump('<br>');var_dump($base['row_text_offset_arr']);var_dump('<br>');
|
||||
// $base替换end
|
||||
|
||||
$base['img_width'] = $base['filed_id_width'] + $base['filed_name_width'] + $base['filed_data_width'] * $column_data + $base['border'] * 2;//图片宽度
|
||||
$base['img_width'] = $base['filed_id_width'] + $base['filed_name_width'] * $base['filed_name_columns'] + $base['filed_data_width'] * $column_data + $base['border'] * 2;//图片宽度
|
||||
$base['img_height'] = $params['row'] * $base['row_hight'] + $base['border'] * 2 + $base['title_height'];//图片高度
|
||||
$border_top = $base['border'] + $base['title_height'];//表格顶部高度
|
||||
$border_bottom = $base['img_height'] - $base['border'];//表格底部高度
|
||||
@@ -1652,10 +2119,12 @@ class Orders_v2_entity{
|
||||
// $base['column_x_arr'] 动态计算
|
||||
$base['column_x_arr'] = array(
|
||||
$base['border'] + $base['filed_id_width'],//第一列边框线x轴像素 70/2+10
|
||||
$base['border'] + $base['filed_id_width'] + $base['filed_name_width'],//第二列边框线x轴像素 190
|
||||
);
|
||||
for ($i=1; $i<=$base['filed_name_columns']; $i++){
|
||||
$base['column_x_arr'][] = $base['border'] + $base['filed_id_width'] + $base['filed_name_width'] * $i; //第二列边框线x轴像素 190
|
||||
}
|
||||
for ($i=1; $i<=$column_data; $i++){
|
||||
$base['column_x_arr'][] = $base['border'] + $base['filed_id_width'] + $base['filed_name_width'] + $base['filed_data_width'] * $i;
|
||||
$base['column_x_arr'][] = $base['border'] + $base['filed_id_width'] + $base['filed_name_width'] * $base['filed_name_columns'] + $base['filed_data_width'] * $i;
|
||||
}
|
||||
|
||||
$img = imagecreatetruecolor($base['img_width'], $base['img_height']);//创建指定尺寸图片
|
||||
|
||||
Reference in New Issue
Block a user