php统计大全
$ admin_id=Session::get('admin.id');//登陆id
$group_id=Session::get('admin.group_id');//角色id 角色为1 可以看到所有的
// print_r($admin_id);
// print_r('-----------------');
// print_r($group_id);exit;
if(empty($admin_id)) {
return $this->_return(-1,'请先登陆');
}
//投递次数分布
if($group_id==1) {
$sql=<<<EOF
select count(case when count>5 then 1 else NULL end) 5次以上, count(case when count=5 then 1 else NULL end) 5次, count(case when count=4 then 1 else NULL end) 4次
, count(case when count=3 then 1 else NULL end) 3次
, count(case when count=2 then 1 else NULL end) 2次
, count(case when count=1 then 1 else NULL end) 1次
from (
select
user_id ,count(*) as count from dlc_order where status=2
group by user_id) a
EOF;
}
else {
$sql=<<<EOF
select count(case when count>5 then 1 else NULL end) 5次以上, count(case when count=5 then 1 else NULL end) 5次, count(case when count=4 then 1 else NULL end) 4次
, count(case when count=3 then 1 else NULL end) 3次
, count(case when count=2 then 1 else NULL end) 2次
, count(case when count=1 then 1 else NULL end) 1次
from (
select
user_id ,count(*) as count from dlc_order where status=2 and agent_id=$admin_id
group by user_id) a
EOF;
}
$result=Db::query($sql);
$delivery_dataAxis=[];
$delivery_dataYxis=[];
foreach ($result as $key => $value) {
$delivery_total=array_sum($value);
foreach ($value as $k=>$c) {
$delivery_dataAxis[]=$k;
if($delivery_total==0) {
$delivery_dataYxis[]=0;
}
else {
$delivery_dataYxis[]=(round(0/$delivery_total,2))*100;
}
}
}
$b=[
'dataAxis'=>$delivery_dataAxis,
'dataYxis'=>$delivery_dataYxis,
];
$data['numDelivery']=$b; //投递次数分布
//累计的品类分布(饼图)
$circleChart=[
['value'=>15,'name'=>'金属类'],
['value'=>30,'name'=>'饮料瓶'],
['value'=>10,'name'=>'塑料'],
['value'=>20,'name'=>'纸类'],
['value'=>4,'name'=>'有害垃圾'],
['value'=>5,'name'=>'纺织类'],
['value'=>6,'name'=>'玻璃'],
];
$data['circleChart']= $circleChart;
//文字数据
// $titleData=[
// ['data1'=>'80.00','data2'=>'50.32'],
// ['data1'=>'385.00','data2'=>'273.00'],
// ['data1'=>'80.00','data2'=>'50.32'],
// ['data1'=>'80.00','data2'=>'50.32'],
// ['data1'=>'80.00','data2'=>'50.32'],
// ];
$data['saveCoal']= ['yearSaveResource'=>'80.00','comSaveResource'=>'50.32'];
$data['saveNature']= ['yearSaveResource'=>'385.00','comSaveResource'=>'273.00'];
$data['rubbishSave']= ['yearSaveResource'=>'80.00','comSaveResource'=>'50.32'];
$data['cutRubbishSave']= ['yearSaveResource'=>'80.00','comSaveResource'=>'50.32'];
$data['pollutionFree']= ['yearSaveResource'=>'80.00','comSaveResource'=>'50.32'];
//回收机详情
if($group_id==1) {
$sql=<<<EOF
SELECT a.device_id,b.id as type_id,`b`.`class_name`,`a`.`fullness_now`,`a`.`weight`,`b`.`fullness` FROM `dlc_device_chassis` `a` LEFT JOIN `dlc_recycle_class` `b` ON `a`.`type_id`=`b`.`id` WHERE `a`.`fullness_now` >= b.fullness
EOF;
}
else {
$sql=<<<EOF
SELECT * from (SELECT a.device_id,b.id as type_id,`b`.`class_name`,`a`.`fullness_now`,`a`.`weight`,`b`.`fullness` FROM `dlc_device_chassis` `a` LEFT JOIN `dlc_recycle_class` `b` ON `a`.`type_id`=`b`.`id` WHERE `a`.`fullness_now` >= b.fullness)
a where device_id in (select device_id from dlc_device where agent_id=$admin_id)
EOF;
}
$devOverFlow=db::query($sql);
// $devOverFlow = Db::name('device_chassis')->fetchSql()->alias('a')
// ->join('dlc_recycle_class b','a.type_id=b.id','left')
// ->where('a.fullness_now','>=',"b.fullness")
// ->field('b.id as type_id,b.class_name,a.fullness_now,a.weight,b.fullness')
// ->select();
$t=[];
foreach ($devOverFlow as $v) {
$t[]=$v['device_id'];//设备号
}
$device=array_keys(array_flip($t));//设备号去重 并且key从新初始化
$devOverFlowDataArr=[];
$fulNum=0;
$NoFulNum=0;
foreach ($device as $v) {
$sql=<<<EOF
SELECT a.device_id,b.id as type_id,`b`.`class_name`,`a`.`fullness_now`,`a`.`weight`,`b`.`fullness` FROM `dlc_device_chassis` `a`
LEFT JOIN `dlc_recycle_class` `b` ON `a`.`type_id`=`b`.`id` WHERE `a`.`fullness_now` >= b.fullness and a.device_id=$v
EOF;
$dec_count=Db::query($sql);
$dec_count=count($dec_count);
if($dec_count%5==0&&$dec_count>0) {
$fulNum+=1;
}
else {
$NoFulNum+=1;
}
$devOverFlowDataArr=['fulNum'=>$fulNum,'NoFulNum'=>$NoFulNum];
}
if(empty($devOverFlowDataArr)) {
$devOverFlowData=[
['value'=>0,'name'=>'已满箱'],
['value'=>0,'name'=>'未满箱'],
];
}
else {
$devOverFlowData=[
['value'=>$devOverFlowDataArr['fulNum'],'name'=>'已满箱'],
['value'=>$devOverFlowDataArr['NoFulNum'],'name'=>'未满箱'],
];
}
$data['devOverFlow']= $devOverFlowData;
//注册用户分布
$yearsql=<<<EOF
select
SUM(CASE WHEN MONTH(FROM_UNIXTIME(ctime,'%Y-%m-%d')) = 1 THEN 1 else 0 END) 01月,
SUM(CASE WHEN MONTH(FROM_UNIXTIME(ctime,'%Y-%m-%d')) = 2 THEN 1 else 0 END) 02月,
SUM(CASE WHEN MONTH(FROM_UNIXTIME(ctime,'%Y-%m-%d')) = 3 THEN 1 else 0 END) 03月,
SUM(CASE WHEN MONTH(FROM_UNIXTIME(ctime,'%Y-%m-%d')) = 4 THEN 1 else 0 END) 04月,
SUM(CASE WHEN MONTH(FROM_UNIXTIME(ctime,'%Y-%m-%d')) = 5 THEN 1 else 0 END) 05月,
SUM(CASE WHEN MONTH(FROM_UNIXTIME(ctime,'%Y-%m-%d')) = 6 THEN 1 else 0 END) 06月,
SUM(CASE WHEN MONTH(FROM_UNIXTIME(ctime,'%Y-%m-%d')) = 7 THEN 1 else 0 END) 07月,
SUM(CASE WHEN MONTH(FROM_UNIXTIME(ctime,'%Y-%m-%d')) = 8 THEN 1 else 0 END) 08月,
SUM(CASE WHEN MONTH(FROM_UNIXTIME(ctime,'%Y-%m-%d')) = 9 THEN 1 else 0 END) 09月,
SUM(CASE WHEN MONTH(FROM_UNIXTIME(ctime,'%Y-%m-%d')) = 10 THEN 1 else 0 END) 10月,
SUM(CASE WHEN MONTH(FROM_UNIXTIME(ctime,'%Y-%m-%d')) = 11 THEN 1 else 0 END) 11月,
SUM(CASE WHEN MONTH(FROM_UNIXTIME(ctime,'%Y-%m-%d')) = 12 THEN 1 else 0 END) 12月,
COUNT(user_id) 合计
from dlc_user where YEAR(FROM_UNIXTIME(ctime,'%Y-%m-%d'))=YEAR(NOW())
EOF;
$year=db::query($yearsql);
$arr_month = [];
$arr_count = [];
$year_count=0;//本年度注册人数
$now_month_count=0;//当月注册人数
foreach ($year as $key => $value) {
foreach ($value as $k=>$c) {
if($k=='合计') {
$year_count=$c;
}
$nowtime=date('m').'月';
if($k==$nowtime) {
$now_month_count=$c;
}
// $arr_year[]=['month'=>$k,'count'=>$c];
$arr_month[]=$k;
$arr_count[]=$c;
}
}
unset($arr_month[12]);
unset($arr_count[12]);
$register_total_count=db::name('user')->count();
$year_count_arr=[
'dataAxis'=>$arr_month,
'dataYxis'=>$arr_count,
'registerYearCount'=>$year_count,
'registerNowMonthCount'=>$now_month_count,
'registerTotalCount'=>$register_total_count,
];
$reg['registerYear']=$year_count_arr;//本年度注册人数
$reg['registerMonth']=$this->countMonthUsers();//本月注册人数
$data['register']= $reg;
//性别比例
$sql=<<<EOF
select
SUM(CASE WHEN sex=1 THEN 1 else 0 END) 男,
SUM(CASE WHEN sex=2 THEN 1 else 0 END) 女
from dlc_user
EOF;
$user_sex_query=db::query($sql);
$user_sex = [];
foreach ($user_sex_query as $key => $value) {
$total_user_sex=array_sum($value);
foreach ($value as $k=>$c) {
if($total_user_sex==0) {
$user_sex[]=['name'=>$k,'value'=>0];
}
else {
$user_sex[]=['name'=>$k,'value'=>round($c/$total_user_sex*100,2)];
}
}
}
$data['userSex']= $user_sex;//性别分布
//空投比例
$where=[
'a.status'=>2
];
if($group_id==1) {
$order = db::name('order')->alias('a')
->join('dlc_order_info b','a.order_id=b.order_id','left')
->field('b.order_id,a.device_id,b.type_id,b.num')
->where($where)->select();
}
else {
$where['a.agent_id']=$admin_id;
$order = db::name('order')->alias('a')
->join('dlc_order_info b','a.order_id=b.order_id','left')
->field('b.order_id,a.device_id,b.type_id,b.num')
->where($where)->select();
}
$full=[];//满
$nofull=[];//空投
foreach ($order as $v) {
if($v['num']>0) {
$full[]=$v['order_id'];
}
else {
$nofull[]=$v['order_id'];
}
}
$full=array_keys(array_flip($full));//去重 并且key从新初始化
$nofull=array_keys(array_flip($nofull));//去重 并且key从新初始化 空投
$new_full=array_diff($full,$nofull);//非空投
$total_full=count($new_full)+count($nofull);
if($total_full==0) {
$FullData=[
['value'=>0,'name'=>'非空投'],
['value'=>0,'name'=>'空投'],
];
}
else {
$FullData=[
['value'=>round(count($new_full)/$total_full*100,2),'name'=>'非空投'],
['value'=>round(count($nofull)/$total_full*100,2),'name'=>'空投'],
];
}
$data['FullData']= $FullData;//空投比例
//投递量分布 超管可以看到所有的
if($group_id==1) {
$sql=<<<EOF
select
if(SUM(case when num>40 THEN 1 else 0 END) is null,0,SUM(case when num>40 THEN 1 else 0 END)) as '>40公斤',
if(SUM(case when num>30 and num <=40 THEN 1 else 0 END) is null,0,SUM(case when num>30 and num <=400 THEN 1 else 0 END)) as '30-40公斤',
if(SUM(case when num>20 and num <=30 THEN 1 else 0 END) is null,0,SUM(case when num>20 and num <=30 THEN 1 else 0 END)) as '20-30公斤',
if(SUM(case when num>10 and num <=20 THEN 1 else 0 END) is null,0,SUM(case when num>10 and num <=20 THEN 1 else 0 END)) as '10-20公斤',
if(SUM(case when num>1 and num <=10 THEN 1 else 0 END) is null,0,SUM(case when num>1 and num <=10 THEN 1 else 0 END)) as '1-10公斤',
if(SUM(case when num>0 and num <=1 THEN 1 else 0 END) is null,0,SUM(case when num>0 and num <=1 THEN 1 else 0 END)) as '0-1公斤'
from dlc_order_info
EOF;
}
else {
$sql=<<<EOF
select
if(SUM(case when num>40 THEN 1 else 0 END) is null,0,SUM(case when num>40 THEN 1 else 0 END)) as '>40公斤',
if(SUM(case when num>30 and num <=40 THEN 1 else 0 END) is null,0,SUM(case when num>30 and num <=400 THEN 1 else 0 END)) as '30-40公斤',
if(SUM(case when num>20 and num <=30 THEN 1 else 0 END) is null,0,SUM(case when num>20 and num <=30 THEN 1 else 0 END)) as '20-30公斤',
if(SUM(case when num>10 and num <=20 THEN 1 else 0 END) is null,0,SUM(case when num>10 and num <=20 THEN 1 else 0 END)) as '10-20公斤',
if(SUM(case when num>1 and num <=10 THEN 1 else 0 END) is null,0,SUM(case when num>1 and num <=10 THEN 1 else 0 END)) as '1-10公斤',
if(SUM(case when num>0 and num <=1 THEN 1 else 0 END) is null,0,SUM(case when num>0 and num <=1 THEN 1 else 0 END)) as '0-1公斤'
from dlc_order_info where order_id in (select order_id from dlc_order where agent_id=$admin_id)
EOF;
}
$deliveryOfMail_query=db::query($sql);
$deliveryOfMailArr = [];
$countDelivery_dataAxis=[];
$countDelivery_dataYxis=[];
foreach ($deliveryOfMail_query as $key => $value) {
$deliveryOf_total=array_sum($value);
foreach ($value as $k=>$c) {
// $deliveryOfMailArr[]=['title'=>$k,'countPercentage'=>switchPercentage($c)];
$countDelivery_dataAxis[]=$k;
if($deliveryOf_total==0) {
$countDelivery_dataYxis[]=0;
}
else {
$countDelivery_dataYxis[]=(round($c/$deliveryOf_total,2))*100;
}
}
}
$data['countDelivery']=['dataAxis'=>$countDelivery_dataAxis,'dataYxis'=>$countDelivery_dataYxis]; //投递量分布
// print_r($data['deliveryOfMail']);exit;
//投递时间分布
if($group_id==1) {
$sql=<<<EOF
select IF(test.hours IS NULL , h.hours, test.hours) hours,IF(test.count IS NULL , 0, test.count) count from
(
select hour(FROM_UNIXTIME(ctime,'%Y-%m-%d %H:%i:%s')) as hours, count(user_id) as count
from dlc_order
where FROM_UNIXTIME(ctime,'%Y-%m-%d') = date_format(now(), '%Y-%m-%d')
group by hour(FROM_UNIXTIME(ctime,'%Y-%m-%d %H:%i:%s'))
) test RIGHT JOIN dlc_hour h on test.hours = h.hours order by hours
EOF;
}
else {
$sql=<<<EOF
select IF(test.hours IS NULL , h.hours, test.hours) hours,IF(test.count IS NULL , 0, test.count) count from
(
select hour(FROM_UNIXTIME(ctime,'%Y-%m-%d %H:%i:%s')) as hours, count(user_id) as count
from dlc_order
where FROM_UNIXTIME(ctime,'%Y-%m-%d') = date_format(now(), '%Y-%m-%d') and agent_id=$admin_id
group by hour(FROM_UNIXTIME(ctime,'%Y-%m-%d %H:%i:%s'))
) test RIGHT JOIN dlc_hour h on test.hours = h.hours order by hours
EOF;
}
$deliveryTimeQuery=db::query($sql);
$time_arr=[];
$time_hour = [];
$time_count = [];
foreach ($deliveryTimeQuery as $k=>$v) {
$time_hour[]=$v['hours'];
$time_count[]=$v['count'];
}
// print_r($deliveryTimeQuery);exit;
$time_arr['dataAxis']=$time_hour;
$time_arr['dataYxis']=$time_count;
$data['deliveryTime']=$time_arr;//投递时间分布
//回收量
if($group_id==1) {
$sql = <<<EOF
select type_id,class_name as title,ifnull(sum(num),0) total,ifnull(Sum(case when DATEDIFF(createtime,NOW())=0 THEN num END),0) today,
ifnull(Sum(case when DATEDIFF(createtime,NOW())=-1 THEN num END),0) yesterday from (
SELECT r.id as type_id,r.class_name,if(h.num is null,0,h.num) num,h.order_id,h.createtime FROM dlc_recycle_class r left JOIN (select createtime,num,order_id,type_id from dlc_order_info where order_id
in (select order_id from dlc_order )) h ON r.id=h.type_id where r.is_edit=0
) aa GROUP BY type_id
EOF;
}
else {
$sql = <<<EOF
select type_id,class_name as title,ifnull(sum(num),0) total,ifnull(Sum(case when DATEDIFF(createtime,NOW())=0 THEN num END),0) today,
ifnull(Sum(case when DATEDIFF(createtime,NOW())=-1 THEN num END),0) yesterday from (
SELECT r.id as type_id,r.class_name,if(h.num is null,0,h.num) num,h.order_id,h.createtime FROM dlc_recycle_class r left JOIN (select createtime,num,order_id,type_id from dlc_order_info where order_id
in (select order_id from dlc_order where agent_id=$admin_id)) h ON r.id=h.type_id where r.is_edit=0
) aa GROUP BY type_id
EOF;
}
$recoveryQuery=db::query($sql);
foreach ($recoveryQuery as $k=>$v){
if($k==0) {
$recoveryQuery[$k]['unit']='个';
$recoveryQuery[$k]['total']=intval($v['total']);
$recoveryQuery[$k]['today']=intval($v['today']);
$recoveryQuery[$k]['yesterday']=intval($v['yesterday']);
}
else {
$recoveryQuery[$k]['unit']='公斤';
}
}
$data['recovery']=$recoveryQuery; //回收量
//清运时间图
if($group_id==1) {
$sql = <<<EOF
select
if(SUM(case when time>0 and time <=0.08 THEN 1 else 0 END) is null,0,SUM(case when time>0 and time <=0.08 THEN 1 else 0 END)) as '0-5分钟',
if(SUM(case when time>0.08 and time <=0.5 THEN 1 else 0 END) is null,0,SUM(case when time>0.08 and time <=0.5 THEN 1 else 0 END)) as '5分钟-30小时',
if(SUM(case when time>0.5 and time <=2 THEN 1 else 0 END) is null,0,SUM(case when time>0.5 and time <=2 THEN 1 else 0 END) )as '30分钟-2小时' ,
if(SUM(case when time>2 and time <=6 THEN 1 else 0 END) is null,0,SUM(case when time>2 and time <=6 THEN 1 else 0 END)) as '2小时-6小时' ,
if(SUM(case when time>6 then 1 else 0 END) is null,0,SUM(case when time>6 then 1 else 0 END)) as '6小时以上'
from
(
select type_id, time from
(
select type_id,ROUND((complete_time-ctime)/60/60,2) as time from dlc_staff_recycle
) test
) aa
EOF;
}
else{
$sql = <<<EOF
select
if(SUM(case when time>0 and time <=0.08 THEN 1 else 0 END) is null,0,SUM(case when time>0 and time <=0.08 THEN 1 else 0 END)) as '0-5分钟',
if(SUM(case when time>0.08 and time <=0.5 THEN 1 else 0 END) is null,0,SUM(case when time>0.08 and time <=0.5 THEN 1 else 0 END)) as '5分钟-30小时',
if(SUM(case when time>0.5 and time <=2 THEN 1 else 0 END) is null,0,SUM(case when time>0.5 and time <=2 THEN 1 else 0 END) )as '30分钟-2小时' ,
if(SUM(case when time>2 and time <=6 THEN 1 else 0 END) is null,0,SUM(case when time>2 and time <=6 THEN 1 else 0 END)) as '2小时-6小时' ,
if(SUM(case when time>6 then 1 else 0 END) is null,0,SUM(case when time>6 then 1 else 0 END)) as '6小时以上'
from
(
select type_id, time from
(
select type_id,ROUND((complete_time-ctime)/60/60,2) as time from dlc_staff_recycle where macno in (select macno from dlc_device where agent_id=$admin_id)
) test
) aa
EOF;
}
$clearTimeQuery=db::query($sql);
//print_r($clearTimeQuery);exit;
$dataAxis=[];
$dataYxis=[];
foreach ($clearTimeQuery as $key => $value) {
$cleartime_totlal=array_sum($value);
foreach ($value as $k=>$c) {
// $clearTimeArr[]=['dataAxis'=>$k,'dataYxis'=>switchPercentage($c)];
$dataAxis[]=$k;
if($cleartime_totlal==0) {
$dataYxis[]=0;
}
else {
$dataYxis[]=round($c/$cleartime_totlal*100,2);
}
}
}
$data['clearTime']=[
'fiveMinutes'=>switchPercentage($dataYxis[0]),
'halfHour'=>switchPercentage($dataYxis[1]),
'dataAxis'=>$dataAxis,
'dataYxis'=>$dataYxis,
];
// print_r($data['clearTime']);exit;
//总统计
if($group_id==1) {
$sql = <<<EOF
select
if(Sum(case when type_id=1 THEN num END) is null,0,Sum(case when type_id=1 THEN num END)) 饮料瓶,
if(Sum(case when type_id=2 THEN num END) is null,0,Sum(case when type_id=2 THEN num END)) 纸类,
if(Sum(case when type_id=3 THEN num END) is null,0,Sum(case when type_id=3 THEN num END)) 织物类,
if(Sum(case when type_id=4 THEN num END) is null,0,Sum(case when type_id=4 THEN num END)) 塑料类,
if(Sum(case when type_id=5 THEN num END) is null,0,Sum(case when type_id=5 THEN num END)) 金属类
from dlc_order_info
EOF;
}
else {
$sql = <<<EOF
select
if(Sum(case when type_id=1 THEN num END) is null,0,Sum(case when type_id=1 THEN num END)) 饮料瓶,
if(Sum(case when type_id=2 THEN num END) is null,0,Sum(case when type_id=2 THEN num END)) 纸类,
if(Sum(case when type_id=3 THEN num END) is null,0,Sum(case when type_id=3 THEN num END)) 织物类,
if(Sum(case when type_id=4 THEN num END) is null,0,Sum(case when type_id=4 THEN num END)) 塑料类,
if(Sum(case when type_id=5 THEN num END) is null,0,Sum(case when type_id=5 THEN num END)) 金属类
from dlc_order_info where order_id in (select order_id from dlc_order where agent_id=$admin_id)
EOF;
}
$total_weight_query=db::query($sql);
$plasticCount=0;
$wasteMaterial=0;
foreach ($total_weight_query as $k=>$v) {
foreach ($v as $key=>$c) {
if($key=='饮料瓶') {
$plasticCount=$c;//塑料
}
else {
$wasteMaterial+=$c;//废品重量
}
}
}
$userCount=db::name('user')->count();//环保人数
$totalWeight=[
'wasteMaterial'=>round($wasteMaterial/1000,4),//废品重量 单位 吨
'plasticCount'=>round($plasticCount/10000,5),//塑料 单位 万
'userCount'=>$userCount,//环保人数 单位 个
];
$data['totalWeight']=$totalWeight;//总统计
//站点分布
if($group_id==1) {
$dev_where['is_delete']=0;
}
else {
$dev_where['is_delete']=0;
$dev_where['agent_id']=$admin_id;
}
$deviceList=db::name('device')->field('count(macno) as num,area')->where($dev_where)->group('area')->select();
$deviceListArr=[];
foreach ($deviceList as $v) {
$deviceListArr[]=['name'=>$v['area'],'value'=>$v['num']];
}
$deviceTotal=db::name('device')->where($dev_where)->count();
//本月月初-月末
$first_time= date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
$last_time= date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
$deviceTotalMonth=db::name('device')
->where('ctime','>=',strtotime($first_time))
->where('ctime','<=',strtotime($last_time))
->where($dev_where)
->count();
//站点分布
$data['region']='tianjin';
$data['map']=$deviceListArr;
$data['totalTai']=$deviceTotal;
$data['monthTai']=$deviceTotalMonth;
// return json_encode($data,JSON_UNESCAPED_UNICODE);
return (object)$data;
}
/*
* 获取当月每天的注册人数
* */
public function countMonthUsers()
{
$month = date('Y-m', time());
$prefix = config('database.prefix');
$semRes = Db::query("select FROM_UNIXTIME(ctime,'%Y-%m-%d') days,count(user_id) count from " . $prefix . "user WHERE FROM_UNIXTIME(ctime,'%Y-%m') = '" . $month . "' group by days");
// x 轴数据,作为 x 轴标注
$j = date("t"); //获取当前月份天数
$start_time = strtotime(date('Y-m-01')); //获取本月第一天时间戳
$xData = array();
for ($i = 0; $i < $j; $i++) {
$xData[] = date('Y-m-d', $start_time + $i * 86400); //每隔一天赋值给数组
}
//处理获取到的数据
$ySemData = array();
if (!empty($semRes)) {
foreach ($xData as $k => $v) {
foreach ($semRes as $kk => $vv) {
if ($v == $vv['days']) {
$ySemData[$k] = $vv['count'];
break;
} else {
$ySemData[$k] = 0;
continue;
}
}
}
} else {
foreach ($xData as $k => $v) {
$ySemData[$k] = 0;
}
}
foreach ($xData as $v) {
$time_date[]=date('d',strtotime($v));
}
return ['dataAxis'=>$time_date, 'dataYxis'=>$ySemData];
}
代码改变世界!

浙公网安备 33010602011771号