@ -1384,10 +1384,14 @@ class StatController extends ThinkController
$return = $model->where(['time'=>array('between',[$todaystart-86400,$todaystart-1])])->sum('new_device');
$return = $model->where(['time'=>array('between',[$todaystart-86400,$todaystart-1])])->sum('new_device');
// $return = $device->total_device(['create_time'=>array('between',[$todaystart-86400,$todaystart-1])]);
// $return = $device->total_device(['create_time'=>array('between',[$todaystart-86400,$todaystart-1])]);
} else if($type == 3) {
} else if($type == 3) {
$return = $model->where(['time'=>array('between',[$todaystart-86400*7,$todaystart-1])])->sum('active_device');
// $return = $model->where(['time'=>array('between',[$todaystart-86400*7,$todaystart-1])])->sum('active_device');
$return = $this->getActiveDeviceNum(['time'=>['between',[$todaystart-86400*7,$todaystart-1]]]);
// $return = $device->total_device(['create_time'=>array('between',[$todaystart-86400*7,$todaystart-1])],1);
// $return = $device->total_device(['create_time'=>array('between',[$todaystart-86400*7,$todaystart-1])],1);
} else if($type == 4) {
} else if($type == 4) {
$return = $model->where(['time'=>array('between',[$todaystart-86400*30,$todaystart-1])])->sum('active_device');
// $return = $model->where(['time'=>array('between',[$todaystart-86400*30,$todaystart-1])])->sum('active_device');
$return = $this->getActiveDeviceNum(['time'=>array('between',[$todaystart-86400*30,$todaystart-1])]);
// $return = $device->total_device(['create_time'=>array('between',[$todaystart-86400*30,$todaystart-1])],1);
// $return = $device->total_device(['create_time'=>array('between',[$todaystart-86400*30,$todaystart-1])],1);
} else if ($type == 5) {
} else if ($type == 5) {
$return = second_to_duration(($model->where(['time'=>$todaystart])->sum('duration7')));
$return = second_to_duration(($model->where(['time'=>$todaystart])->sum('duration7')));
@ -1397,7 +1401,35 @@ class StatController extends ThinkController
$this->ajaxReturn($return?$return:0) ;
$this->ajaxReturn($return?$return:0) ;
}
}
public function getActiveDeviceNum($map) {
$modelData = M('device_statistics','tab_')
->field("model")
->where($map)
->select();
$modelNew = 0;
$unique_code = [];
foreach($modelData as $key => $value) {
$resolveData = json_decode($value['model'],true);
// dump($resolveData);
foreach($resolveData as $k => $v) {
// if (!isset($modelNew[$v['model']][$v['version']])) {
// $modelNew = 1;
// $unique_code[$v['unique_code']] = 1;
// }
// else
if(!$unique_code[$v['unique_code']]){
$modelNew++;
$unique_code[$v['unique_code']] = 1;
// array_push($unique_code,$v['unique_code']);
}
}
}
return $modelNew;
}
/*
/*
* 折线图
* 折线图
* @param integer $start 开始时间
* @param integer $start 开始时间
@ -1634,6 +1666,13 @@ class StatController extends ThinkController
}
}
}
}
if ($start != $end) {
$table['sum']['active'] = $this->getActiveDeviceNum(['time'=>array('between',[$starttime,$endtime])]);
$table['average']['active'] = number_format($table['sum']['active']/(((($endtime+1)-$starttime)/86400)),2,'.','');
// var_dump($endtime-$starttime);die();
}
@file_put_contents(dirname(__FILE__).'/device_data_foldline.txt',json_encode($export));
@file_put_contents(dirname(__FILE__).'/device_data_foldline.txt',json_encode($export));