$instance
$instance : object
Reference to the CI singleton
报告统计
This class object is the super class that every library in CodeIgniter will be assigned to.
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* 报告统计
* */
class reportcount extends CI_Controller
{
private static $data = array();
public function __construct()
{
parent::__construct();
$this->load->model('Public_model', 'public');
$this->load->model('Webcommon_model', 'common');
self::$data['header'] = $this->public->header('');
self::$data['left'] = $this->public->leftmenu('');
self::$data['footer'] = $this->public->footer();
$this->load->library('Session');
$this->public->authentication();
$this->load->model('User_model', 'user');
$this->load->model('Agency_model', 'agency');//机构表
$this->load->model('Report_model', 'report');
$this->load->model('Userinfo_model', 'userinfo');//用户信息
$this->load->model('Photo_model', 'photo');//照片
$this->load->model('Symptom_model', 'symptom');//体质表
}
//地区分布
public function areacount()
{
if ($_POST) {
$where = "id>0 ";
if (isset($_POST['stime']) && $_POST['stime'] != '') {
date_default_timezone_set('PRC');
$stime = strtotime($_POST['stime']);
date_default_timezone_set('UTC');
$stime = date('Y-m-d H:i:s', $stime);
$where .= " AND time >='" . $stime . "'";
}
//状态查询
if (isset($_POST['etime']) && $_POST['etime'] != '') {
date_default_timezone_set('PRC');
$etime = strtotime($_POST['etime']);
date_default_timezone_set('UTC');
$etime = date('Y-m-d H:i:s', $etime);
$where .= " AND time <='" . $etime . "'";
}
$sql = 'select count(id),city from report where ' . $where . 'group by city';
$total = $this->common->getdevsqldata($sql);
$ages = array();
foreach ($total as $user) {
$ages[] = $user['count(id)'];
}
array_multisort($ages, SORT_DESC, $total);
self::$data['areainfo'] = $total;
$areainfo = $this->load->view('admincp/reportcount/areaphoto', self::$data, true);
$res['num'] = 0;
$res['data'] = $areainfo;
echo json_encode($res);
exit;
} else {
$sql = 'select count(id),city from report group by city';
$total = $this->common->getdevsqldata($sql);
$ages = array();
foreach ($total as $user) {
$ages[] = $user['count(id)'];
}
array_multisort($ages, SORT_DESC, $total);
self::$data['areainfo'] = $total;
$areainfo = $this->load->view('admincp/reportcount/areaphoto', self::$data, true);
self::$data['areaphoto'] = $areainfo;
$this->load->view('admincp/reportcount/area', self::$data);
}
}
//地区分布
public function wxareacount($a = 10)
{
set_time_limit(0);
$report_sql = "select ip,id,city from report where city is null limit 0,1000";
$list = $this->common->getwxsqldata($report_sql);
foreach ($list as $value) {
$city = $this->getCity($value['ip']);
$sql = 'UPDATE report SET city = \'' . $city . '\' WHERE id =' . $value['id'];
$this->common->getwxsqlupdata($sql);
}
if ($_POST) {
$where = "id>0 ";
if (isset($_POST['stime']) && $_POST['stime'] != '') {
date_default_timezone_set('PRC');
$stime = strtotime($_POST['stime']);
date_default_timezone_set('UTC');
$stime = date('Y-m-d H:i:s', $stime);
$where .= " AND time >='" . $stime . "'";
}
//状态查询
if (isset($_POST['etime']) && $_POST['etime'] != '') {
date_default_timezone_set('PRC');
$etime = strtotime($_POST['etime']);
date_default_timezone_set('UTC');
$etime = date('Y-m-d H:i:s', $etime);
$where .= " AND time <='" . $etime . "'";
}
$sql = 'select count(id),city from report where ' . $where . 'group by city';
$total = $this->common->getwxsqldata($sql);
$ages = array();
foreach ($total as $user) {
$ages[] = $user['count(id)'];
}
array_multisort($ages, SORT_DESC, $total);
self::$data['areainfo'] = $total;
$areainfo = $this->load->view('admincp/reportcount/areaphoto', self::$data, true);
$res['num'] = 0;
$res['data'] = $areainfo;
echo json_encode($res);
exit;
} else {
$sql = 'select count(id),city from report group by city';
$total = $this->common->getwxsqldata($sql);
$ages = array();
foreach ($total as $user) {
$ages[] = $user['count(id)'];
}
array_multisort($ages, SORT_DESC, $total);
self::$data['areainfo'] = $total;
$areainfo = $this->load->view('admincp/reportcount/areaphoto', self::$data, true);
self::$data['areaphoto'] = $areainfo;
$this->load->view('admincp/reportcount/area', self::$data);
}
}
function getCity($ip)
{
// $memcache = new Memcache; //创建一个memcache对象
// $memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器
// $get_value = $memcache->get($ip);
// if($get_value){
// return $get_value;
// }else{
$url = "http://ip.taobao.com/service/getIpInfo.php?ip=" . $ip;
$ipinfo = json_decode(file_get_contents($url));
if ($ipinfo->code == '1') {
return false;
}
$city = $ipinfo->data->city;
// $memcache->set($ip, $city);
if ($city == 'XX') {
return $ipinfo->data->country;
}
return $city;
// }
}
public function symptom()
{
if ($_POST) {
$where = "id>0 ";
if (isset($_POST['stime']) && $_POST['stime'] != '') {
date_default_timezone_set('PRC');
$stime = strtotime($_POST['stime']);
date_default_timezone_set('UTC');
$stime = date('Y-m-d H:i:s', $stime);
$where .= " AND r.time >='" . $stime . "'";
}
//状态查询
if (isset($_POST['etime']) && $_POST['etime'] != '') {
date_default_timezone_set('PRC');
$etime = strtotime($_POST['etime']);
date_default_timezone_set('UTC');
$etime = date('Y-m-d H:i:s', $etime);
$where .= " AND time <='" . $etime . "'";
}
$sql = 'select count(id),s.name from report as r
left join (
select report_id,name,max(score) from symptom group by report_id
) as s on r.id=s.report_id where ' . $where . ' group by s.name';
$total = $this->common->getdevsqldata($sql);
$total[0]['name'] = '健康';
self::$data['areainfo'] = $total;
$areainfo = $this->load->view('admincp/reportcount/symptomphoto', self::$data, true);
$res['num'] = 0;
$res['data'] = $areainfo;
echo json_encode($res);
exit;
} else {
$sql = 'select count(id),s.name from report as r
left join (
select report_id,name,max(score) from symptom group by report_id
) as s on r.id=s.report_id group by s.name';
$total = $this->common->getdevsqldata($sql);
$total[0]['name'] = '健康';
self::$data['areainfo'] = $total;
$areainfo = $this->load->view('admincp/reportcount/symptomphoto', self::$data, true);
self::$data['areaphoto'] = $areainfo;
$this->load->view('admincp/reportcount/symptom', self::$data);
}
}
public function wxsymptom()
{
if ($_POST) {
$where = "id>0 ";
if (isset($_POST['stime']) && $_POST['stime'] != '') {
date_default_timezone_set('PRC');
$stime = strtotime($_POST['stime']);
date_default_timezone_set('UTC');
$stime = date('Y-m-d H:i:s', $stime);
$where .= " AND r.time >='" . $stime . "'";
}
//状态查询
if (isset($_POST['etime']) && $_POST['etime'] != '') {
date_default_timezone_set('PRC');
$etime = strtotime($_POST['etime']);
date_default_timezone_set('UTC');
$etime = date('Y-m-d H:i:s', $etime);
$where .= " AND time <='" . $etime . "'";
}
$sql = 'select count(id),s.name from report as r
left join (
select report_id,name,max(score) from symptom group by report_id
) as s on r.id=s.report_id where ' . $where . ' group by s.name';
$total = $this->common->getwxsqldata($sql);
$total[0]['name'] = '健康';
self::$data['areainfo'] = $total;
$areainfo = $this->load->view('admincp/reportcount/symptomphoto', self::$data, true);
$res['num'] = 0;
$res['data'] = $areainfo;
echo json_encode($res);
exit;
} else {
$sql = 'select count(id),s.name from report as r
left join (
select report_id,name,max(score) from symptom group by report_id
) as s on r.id=s.report_id group by s.name';
$total = $this->common->getwxsqldata($sql);
$total[0]['name'] = '健康';
self::$data['areainfo'] = $total;
$areainfo = $this->load->view('admincp/reportcount/symptomphoto', self::$data, true);
self::$data['areaphoto'] = $areainfo;
$this->load->view('admincp/reportcount/symptom', self::$data);
}
}
}