diff --git a/Application/Admin/Controller/StatController.class.php b/Application/Admin/Controller/StatController.class.php index 46d416787..196aea1f8 100644 --- a/Application/Admin/Controller/StatController.class.php +++ b/Application/Admin/Controller/StatController.class.php @@ -1384,10 +1384,14 @@ class StatController extends ThinkController $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])]); } 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); } 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); } else if ($type == 5) { $return = second_to_duration(($model->where(['time'=>$todaystart])->sum('duration7'))); @@ -1397,7 +1401,35 @@ class StatController extends ThinkController $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 开始时间 @@ -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)); diff --git a/Application/Admin/Controller/TimingController.class.php b/Application/Admin/Controller/TimingController.class.php index 4fef0fa9c..473541f30 100644 --- a/Application/Admin/Controller/TimingController.class.php +++ b/Application/Admin/Controller/TimingController.class.php @@ -81,21 +81,17 @@ class TimingController extends AdminController { echo $data['active_device'].' '; $data['time'] = $startTime; $data['version'] = 2; - echo 0; $data['today_new_device'] =json_encode($this->news_on_time(['create_time'=>['between',[$startTime,$startTime+86399]]],'news',5,'time,version','time',2)); // echo M('device_record','tab_')->_sql();die(); - echo 1; $data['today_active_device'] =json_encode($this->active_on_time(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>2],'active',5,'time,version')); - echo 2; $data['today_model_device'] = json_encode($this->model(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>2])); - echo 3; $data['model'] = json_encode($this->modelDevice(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>2])); // $duration = $this->duration(['create_time'=>array('between',[$startTime-86400*7,$startTime-1]),'version'=>2]); // $data['duration7'] = ($duration/M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime-86400*7,$startTime-1])])->order('create_time')->count())/7; $data['duration7'] = 0; - echo 4; + $getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->find(); echo "\n"; if (!$getStatistics) { @@ -104,6 +100,57 @@ class TimingController extends AdminController { M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->save($data); } + } + + } + + public function caculateTodayDevice() { + + $start = 1569686400; + $end = time(); + + if (I('time')) { + $start = strtotime(I('time')); + $end = $start+1; + } + + if (I('start')) { + $start = strtotime(I('start')); + } + + ini_set('memory_limit','1024M'); +// $device = D('DeviceRecord'); +// echo 1; + for($startTime = $start;$startTime<$end;$startTime=$startTime+86400) { + echo date("Y-m-d",$startTime).' 安卓 '; + //当日新增设备 + $newSql = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->where(['version'=>1])->group('unique_code')->select(false); + $data['new_device'] = M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime,$startTime+86399])])->order('create_time')->count(); + + echo $data['new_device'].' '; + + $getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>1])->find(); + echo "\n"; + if (!$getStatistics) { + M('device_statistics','tab_')->add($data); + } else { + M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>1])->save($data); + } + + echo date("Y-m-d",$startTime).' 苹果 '; + //当日新增设备 + $newSql = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->where(['version'=>2])->group('unique_code')->select(false); + $data['new_device'] = M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime,$startTime+86399])])->order('create_time')->count(); + + echo $data['new_device'].' '; + + $getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->find(); + echo "\n"; + if (!$getStatistics) { + M('device_statistics','tab_')->add($data); + } else { + M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->save($data); + } }