示例#1
0
 /**
  * wifi链接详情数据
  */
 public function wifidataAction()
 {
     $data = reqstr('data');
     if (!$data) {
         return;
     }
     $page = reqnum('page', 1);
     $pagesize = 10;
     $data = urldecode($data);
     $info = array();
     parse_str($data, $info);
     $date = (int) $info['date'] ? (int) $info['date'] : 7;
     //默认是查出7天的数据
     $sdate = trim($info['sdate']) ? trim($info['sdate']) : '';
     $edate = trim($info['edate']) ? trim($info['edate']) : '';
     // $station = (int)$info['station']?(int)$info['station']:0; // 0 表示查询出所有车站
     $station = empty($info['station']) ? 0 : implode(',', $info['station']);
     // echo $station;
     if (!$sdate || !$edate) {
         $edate = date('Y-m-d');
         $sdate = date('Y-m-d', strtotime("-{$date} day"));
     }
     if ($sdate < '2015-02-01') {
         $sdate = '2015-02-01';
     }
     //如果时间区间大于30天则按照30天计算
     /*$date_area = abs(strtotime($edate) - strtotime($sdate)) / 86400;
     		if ($date_area > 30) {
     			$sdate = date('Y-m-d',strtotime("-30 day"));
     		}*/
     $nt = new Psys_StationModel();
     $tabledata = $nt->wifidata($sdate, $edate, $station, $page, $pagesize);
     //分页
     $paging = $this->paging($tabledata['allnum'], $page, $pagesize, count($tabledata['allrow']));
     //wifi连接统计图
     $graphdata = $nt->wifidata($sdate, $edate, $station, $page, $pagesize, 1);
     // print_r($graphdata);
     //注册统计图
     $regdata = $nt->RegData($sdate, $edate, $station);
     // print_r($regdata);
     $stations = $nt->station();
     if ($station) {
         $stationname = $this->getstationname($stations, $station);
     } else {
         $stationname = '所有车站';
     }
     $datas[0]['name'] = 'wifi连接数';
     $datas[1]['name'] = '注册数';
     //拼接统计图数据格式
     $nts = new Psys_ResourceModel();
     $dates = array(str_replace('-', '_', $sdate), str_replace('-', '_', $edate));
     // $flag = 0;
     foreach ($graphdata['allrow'] as $k => $v) {
         //生成补位判断数据
         $graph_date[] = 'reg' . str_replace('-', '_', $v['date']);
         $x_date = $result['x_cat'][] = date('m/d', strtotime($v['date']));
         $flags = 'a' . str_replace('-', '_', $v['date']);
         if ($station) {
             $eventrecordinfo = $nts->EventRecordInfo(str_replace('-', '_', $v['date']), 0, $station);
             //返回特殊点的提示信息
             if (!empty($eventrecordinfo)) {
                 $title = '';
                 $descript = '';
                 if (is_numeric($station)) {
                     $title = $eventrecordinfo['title'];
                     $descript = $eventrecordinfo['descript'];
                 } else {
                     foreach ($eventrecordinfo as $info) {
                         $infodate = str_replace('_', '-', $info['date']);
                         $infodates = date('m/d', strtotime($infodate));
                         if ($infodates == $x_date) {
                             //去掉重复的标题和描述
                             if (!stristr($title, $info['title'])) {
                                 $title .= '<br /><b>' . $info['title'] . '</b><br />' . $info['descript'] . '<br />';
                                 $descript .= '<br />';
                             }
                             $flag['a' . $info['date']] = 1;
                         } else {
                             $flag['a' . $info['date']] = 0;
                         }
                     }
                 }
             } else {
                 $title = '';
                 $descript = '';
             }
         } else {
             $eventrecordinfo = $nts->EventRecordInfo($dates, 0, $station, true);
             //返回特殊点的提示信息
             if (!empty($eventrecordinfo)) {
                 $title = '';
                 $descript = '';
                 foreach ($eventrecordinfo as $info) {
                     $infodate = str_replace('_', '-', $info['date']);
                     $infodates = date('m/d', strtotime($infodate));
                     if ($infodates == $x_date) {
                         $title .= $info['title'];
                         $descript .= $info['descript'];
                         $flag['a' . $info['date']] = 1;
                     } else {
                         $flag['a' . $info['date']] = 0;
                     }
                 }
             }
         }
         $datas[0]['infos']['date' . $x_date]['title'] = $title;
         $datas[0]['infos']['date' . $x_date]['descript'] = $descript;
         if ($station) {
             if (is_numeric($station)) {
                 if (empty($eventrecordinfo)) {
                     $datas[0]['data'][] = (int) $v['num'];
                 } else {
                     $datas[0]['data'][] = array('y' => (int) $v['num'], 'marker' => array('fillColor' => '#FF0000', 'lineColor' => '#FF0000', 'states' => array('hover' => array('fillColor' => '#FF0000', 'lineColor' => '#FF0000'))));
                     //设置当前点鼠标经过的颜色
                 }
             } else {
                 if (!$flag[$flags]) {
                     $datas[0]['data'][] = (int) $v['num'];
                 } else {
                     $datas[0]['data'][] = array('y' => (int) $v['num'], 'marker' => array('fillColor' => '#FF0000', 'lineColor' => '#FF0000', 'states' => array('hover' => array('fillColor' => '#FF0000', 'lineColor' => '#FF0000'))));
                     //设置当前点鼠标经过的颜色
                 }
             }
         } else {
             if (!$flag[$flags]) {
                 $datas[0]['data'][] = (int) $v['num'];
             } else {
                 $datas[0]['data'][] = array('y' => (int) $v['num'], 'marker' => array('fillColor' => '#FF0000', 'lineColor' => '#FF0000', 'states' => array('hover' => array('fillColor' => '#FF0000', 'lineColor' => '#FF0000'))));
                 //设置当前点鼠标经过的颜色
             }
         }
     }
     //整理注册数据
     foreach ($regdata as $reg) {
         $register['reg' . $reg['date']]['num'] = $reg['num'];
         $register['reg' . $reg['date']]['stationid'] = $station;
     }
     foreach ($graph_date as $g_date) {
         if (!isset($register[$g_date]['num']) || !$register[$g_date]['num']) {
             $register[$g_date]['num'] = 0;
             $register[$g_date]['stationid'] = $station;
         }
     }
     ksort($register);
     foreach ($register as $k1 => $v1) {
         $tmpdate = str_replace(array('reg', '_'), array('', '-'), $k1);
         $x_date = date('m/d', strtotime($tmpdate));
         $da = str_replace('reg', '', $k1);
         $flags = 'a' . $da;
         if ($v1['stationid']) {
             $eventrecordinfo = $nts->EventRecordInfo($da, 0, $v1['stationid']);
             //返回特殊点的提示信息
             if (!empty($eventrecordinfo)) {
                 $title = '';
                 $descript = '';
                 if (is_numeric($station)) {
                     $title = $eventrecordinfo['title'];
                     $descript = $eventrecordinfo['descript'];
                 } else {
                     foreach ($eventrecordinfo as $info) {
                         $infodate = str_replace('_', '-', $info['date']);
                         $infodates = date('m/d', strtotime($infodate));
                         if ($infodates == $x_date) {
                             //去掉重复的标题和描述
                             if (!stristr($title, $info['title'])) {
                                 $title .= '<br /><b>' . $info['title'] . '</b><br />' . $info['descript'] . '<br />';
                                 $descript .= '<br />';
                             }
                             $flag['a' . $info['date']] = 1;
                         } else {
                             $flag['a' . $info['date']] = 0;
                         }
                     }
                 }
             } else {
                 $title = '';
                 $descript = '';
             }
         } else {
             $eventrecordinfo = $nts->EventRecordInfo($dates, 0, $v1['stationid'], true);
             //返回特殊点的提示信息
             if (!empty($eventrecordinfo)) {
                 $title = '';
                 $descript = '';
                 foreach ($eventrecordinfo as $info) {
                     $infodate = str_replace('_', '-', $info['date']);
                     $infodates = date('m/d', strtotime($infodate));
                     if ($infodates == $x_date) {
                         $title .= $info['title'];
                         $descript .= $info['descript'];
                         $flag['a' . $info['date']] = 1;
                     } else {
                         $flag['a' . $info['date']] = 0;
                     }
                 }
             }
         }
         $datas[1]['infos']['date' . $x_date]['title'] = $title;
         $datas[1]['infos']['date' . $x_date]['descript'] = $descript;
         if ($station) {
             if (is_numeric($station)) {
                 if (empty($eventrecordinfo)) {
                     $datas[1]['data'][] = (int) $v1['num'];
                 } else {
                     $datas[1]['data'][] = array('y' => (int) $v1['num'], 'marker' => array('fillColor' => '#FF0000', 'lineColor' => '#FF0000', 'states' => array('hover' => array('fillColor' => '#FF0000', 'lineColor' => '#FF0000'))));
                     //设置当前点鼠标经过的颜色
                 }
             } else {
                 if (!$flag[$flags]) {
                     $datas[1]['data'][] = (int) $v1['num'];
                 } else {
                     $datas[1]['data'][] = array('y' => (int) $v1['num'], 'marker' => array('fillColor' => '#FF0000', 'lineColor' => '#FF0000', 'states' => array('hover' => array('fillColor' => '#FF0000', 'lineColor' => '#FF0000'))));
                     //设置当前点鼠标经过的颜色
                 }
             }
         } else {
             if (!$flag[$flags]) {
                 $datas[1]['data'][] = (int) $v1['num'];
             } else {
                 $datas[1]['data'][] = array('y' => (int) $v1['num'], 'marker' => array('fillColor' => '#FF0000', 'lineColor' => '#FF0000', 'states' => array('hover' => array('fillColor' => '#FF0000', 'lineColor' => '#FF0000'))));
                 //设置当前点鼠标经过的颜色
             }
         }
     }
     $result['y_data'] = $datas;
     $isbaifenbi = reqnum('baifenbi', 0);
     if ($isbaifenbi) {
         $baifenbis[0]['name'] = '注册连接百分比';
         foreach ($datas[0]['data'] as $k1 => $connect1) {
             foreach ($datas[1]['data'] as $k2 => $reg1) {
                 if ($k1 == $k2) {
                     if (is_numeric($reg1) && is_numeric($connect1)) {
                         $b = $reg1 / $connect1 * 100;
                     } else {
                         $b = $reg1['y'] / $connect1['y'] * 100;
                     }
                     $baifenbis[0]['data'][] = (double) round($b, 2);
                 }
             }
         }
         $result['baifenbi'] = $baifenbis;
     }
     return array('table' => $tabledata['allrow'], 'graph' => $result, 'paging' => $paging);
 }