统计数据中的按用户统计添加了新用户统计功能

This commit is contained in:
Li Jianxuan 2014-01-10 09:21:13 +00:00
parent 8f8631ee2f
commit fd1a7260af
5 changed files with 815 additions and 508 deletions

View File

@ -1,437 +1,462 @@
<?php <?php
class Admin_StatController extends Zend_Controller_Action class Admin_StatController extends Zend_Controller_Action
{ {
function preDispatch() function preDispatch()
{ {
$this->db=Zend_Registry::get('db'); $this->db=Zend_Registry::get('db');
$this->view->config = Zend_Registry::get('config'); $this->view->config = Zend_Registry::get('config');
$this->messenger=$this->_helper->getHelper('FlashMessenger'); $this->messenger=$this->_helper->getHelper('FlashMessenger');
$this->view->messages = $this->messenger->getMessages(); $this->view->messages = $this->messenger->getMessages();
$this->view->theme = new Theme(); $this->view->theme = new Theme();
$this->_helper->layout->setLayout('administry'); $this->_helper->layout->setLayout('administry');
} }
function postDispatch() function postDispatch()
{ {
$this->view->messages = $this->messenger->getMessages(); $this->view->messages = $this->messenger->getMessages();
} }
function indexAction() function indexAction()
{ {
$sql="select (select count(id) from users) as alluser, $sql="select (select count(id) from users) as alluser,
(select count(id) from normalmetadata) as alldata, (select count(id) from normalmetadata) as alldata,
(select count(id) as num from dataorder where status=0) as onlinedown, (select count(id) as num from dataorder where status=0) as onlinedown,
(select count(id) as num from dataorder where status=5) as offlinedown, (select count(id) as num from dataorder where status=5) as offlinedown,
(select count(id) as num from offlineapp where ts_approved is not null) as offlinepass, (select count(id) as num from offlineapp where ts_approved is not null) as offlinepass,
(select count(id) as num from offlineapp where ts_approved is null) as offlineunfinished, (select count(id) as num from offlineapp where ts_approved is null) as offlineunfinished,
(select count(id) as num from dataorder where offlineappid>0 and status=-1) as offlinedenied, (select count(id) as num from dataorder where offlineappid>0 and status=-1) as offlinedenied,
(select count(id) as num from onlineapp) as onlineapp"; (select count(id) as num from onlineapp) as onlineapp";
$this->view->stat=$this->db->fetchRow($sql); $this->view->stat=$this->db->fetchRow($sql);
//下载量统计 //下载量统计
$sql = "select sum(num) as num from (select m.filesize/1024 as num,m.title,d.userid from dataorder d left join metadata m on d.uuid=m.uuid where (d.status=0 or d.status=5) and m.filesize>0 group by m.title,d.userid,m.filesize) as t"; $sql = "select sum(num) as num from (select m.filesize/1024 as num,m.title,d.userid from dataorder d left join metadata m on d.uuid=m.uuid where (d.status=0 or d.status=5) and m.filesize>0 group by m.title,d.userid,m.filesize) as t";
$res = $this->db->query($sql); $res = $this->db->query($sql);
$allsize = $res->fetch(); $allsize = $res->fetch();
$this->view->allsize = $allsize; $this->view->allsize = $allsize;
$sql = "select sum(num) as num from (select m.filesize/1024 as num,m.title,d.userid from dataorder d left join metadata m on d.uuid=m.uuid where d.status=5 and m.filesize>0 group by m.title,d.userid,m.filesize) as t"; $sql = "select sum(num) as num from (select m.filesize/1024 as num,m.title,d.userid from dataorder d left join metadata m on d.uuid=m.uuid where d.status=5 and m.filesize>0 group by m.title,d.userid,m.filesize) as t";
$res = $this->db->query($sql); $res = $this->db->query($sql);
$offlinesize = $res->fetch(); $offlinesize = $res->fetch();
$this->view->offlinesize = $offlinesize; $this->view->offlinesize = $offlinesize;
$sql = "select sum(num) as num from (select m.filesize/1024 as num,m.title,d.userid from dataorder d left join metadata m on d.uuid=m.uuid where d.status=0 and m.filesize>0 group by m.title,d.userid,m.filesize) as t"; $sql = "select sum(num) as num from (select m.filesize/1024 as num,m.title,d.userid from dataorder d left join metadata m on d.uuid=m.uuid where d.status=0 and m.filesize>0 group by m.title,d.userid,m.filesize) as t";
$res = $this->db->query($sql); $res = $this->db->query($sql);
$onlinesize = $res->fetch(); $onlinesize = $res->fetch();
$this->view->onlinesize = $onlinesize; $this->view->onlinesize = $onlinesize;
$sql="select sum(configvalue::real)/1024/1024/1024 as num from g6ftpusersettings where userid in (select id from g6ftpusers where name like 'westdc%' or name='newwestdc') and configname='StatsDownloaded'"; $sql="select sum(configvalue::real)/1024/1024/1024 as num from g6ftpusersettings where userid in (select id from g6ftpusers where name like 'westdc%' or name='newwestdc') and configname='StatsDownloaded'";
$res = $this->db->query($sql); $res = $this->db->query($sql);
$onlinesize = $res->fetch(); $onlinesize = $res->fetch();
$this->view->onlineg6size = $onlinesize; $this->view->onlineg6size = $onlinesize;
}//indexAction 首页 }//indexAction 首页
function unitAction() function unitAction()
{ {
$ac = $this->_getParam('ac'); $ac = $this->_getParam('ac');
$y = (int)$this->_request->getParam('y'); $y = (int)$this->_request->getParam('y');
if(!empty($y)) if(!empty($y))
{ {
$n = date("Y",time()); $n = date("Y",time());
if($y<2004 || $y>$n) if($y<2004 || $y>$n)
{ {
$y=$n; $y=$n;
} }
} }
$this->view->y = $y; $this->view->y = $y;
//各单位下载情况统计的离线申请数据条数需要有对应的dataorder记录 //各单位下载情况统计的离线申请数据条数需要有对应的dataorder记录
/*$sql = "select count(d.id) as num,o.unit from dataorder d /*$sql = "select count(d.id) as num,o.unit from dataorder d
left join offlineapp o on o.id=d.offlineappid left join offlineapp o on o.id=d.offlineappid
where d.offlineappid>0 and o.unit is not null and d.status>4";*/ where d.offlineappid>0 and o.unit is not null and d.status>4";*/
//各单位下载情况,统计的离线申请数据次数 //各单位下载情况,统计的离线申请数据次数
$sql = "select count(o.id) as num,o.unit from offlineapp o $sql = "select count(o.id) as num,o.unit from offlineapp o
where o.unit is not null "; where o.unit is not null ";
if ($y) if ($y)
$sql.=" and extract(year from o.ts_created)='$y'"; $sql.=" and extract(year from o.ts_created)='$y'";
$sql.=" group by o.unit"; $sql.=" group by o.unit";
$fe = $this->db->query($sql); $fe = $this->db->query($sql);
$unitoffline = $fe->fetchAll(); $unitoffline = $fe->fetchAll();
//各单位在线下载情况 //各单位在线下载情况
$sql = "select count(d.id) as num,o.unit from dataorder d $sql = "select count(d.id) as num,o.unit from dataorder d
left join onlineapp o on o.id=d.onlineappid left join onlineapp o on o.id=d.onlineappid
where d.onlineappid>0 and o.unit is not null"; where d.onlineappid>0 and o.unit is not null";
if ($y) if ($y)
$sql.=" and extract(year from o.ts_created)='$y'"; $sql.=" and extract(year from o.ts_created)='$y'";
$sql.=" group by o.unit"; $sql.=" group by o.unit";
$fe = $this->db->query($sql); $fe = $this->db->query($sql);
$unitonline = $fe->fetchAll(); $unitonline = $fe->fetchAll();
$units = array(); $units = array();
foreach($unitonline as $k=>$v) foreach($unitonline as $k=>$v)
{ {
if(isset($v['num'])) if(isset($v['num']))
{ {
$units[$v['unit']]['online'] = $v['num']; $units[$v['unit']]['online'] = $v['num'];
} }
} }
foreach($unitoffline as $k=>$v) foreach($unitoffline as $k=>$v)
{ {
if(isset($v['num'])) if(isset($v['num']))
{ {
$units[$v['unit']]['offline'] = $v['num']; $units[$v['unit']]['offline'] = $v['num'];
} }
} }
$index = 1; $index = 1;
foreach($units as $k=>$v) foreach($units as $k=>$v)
{ {
if(!isset($v['online'])) if(!isset($v['online']))
{ {
$units[$k]['online'] = 0; $units[$k]['online'] = 0;
} }
if(!isset($v['offline'])) if(!isset($v['offline']))
{ {
$units[$k]['offline'] = 0; $units[$k]['offline'] = 0;
} }
$units[$k]['total'] = $units[$k]['online'] + $units[$k]['offline']; $units[$k]['total'] = $units[$k]['online'] + $units[$k]['offline'];
$units[$k]['index'] = $index++; $units[$k]['index'] = $index++;
} }
if($ac == "out") if($ac == "out")
{ {
$type = $this->_getParam('type'); $type = $this->_getParam('type');
if(empty($type) || $type == "csv") if(empty($type) || $type == "csv")
{ {
$this->_helper->layout->disableLayout(); $this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(); $this->_helper->viewRenderer->setNoRender();
include_once("Stat.php"); include_once("Stat.php");
$stat = new Stat($this->db); $stat = new Stat($this->db);
$head = array("id","单位名称","离线申请次数","在线申请次数","总申请次数"); $head = array("id","单位名称","离线申请次数","在线申请次数","总申请次数");
$content = array(); $content = array();
foreach($units as $k=>$v) foreach($units as $k=>$v)
{ {
$content[] = array( $content[] = array(
$v['index'], $v['index'],
$k, $k,
$v['offline'], $v['offline'],
$v['online'], $v['online'],
$v['total'] $v['total']
); );
unset($units[$k]); unset($units[$k]);
} }
array_unshift($content,$head); array_unshift($content,$head);
$stat->Download("westdc-download-status.csv",$content,"csv"); $stat->Download("westdc-download-status.csv",$content,"csv");
exit(); exit();
} }
if($type == "json") if($type == "json")
{ {
$this->_helper->layout->disableLayout(); $this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(); $this->_helper->viewRenderer->setNoRender();
include_once("Stat.php"); include_once("Stat.php");
$stat = new Stat($this->db); $stat = new Stat($this->db);
$content = array(); $content = array();
foreach($units as $k=>$v) foreach($units as $k=>$v)
{ {
$content[] = array( $content[] = array(
'index'=>$v['index'], 'index'=>$v['index'],
'unit'=>$k, 'unit'=>$k,
'offline'=>$v['offline'], 'offline'=>$v['offline'],
'online'=>$v['online'], 'online'=>$v['online'],
'total'=>$v['total'] 'total'=>$v['total']
); );
unset($units[$k]); unset($units[$k]);
} }
$stat->Download("westdc-download-status.json",$content,"json"); $stat->Download("westdc-download-status.json",$content,"json");
exit(); exit();
} }
} }
$this->view->units = $units; $this->view->units = $units;
}//分单位统计 }//分单位统计
//按用户统计 //按用户统计
function userAction(){ function userAction(){
$ac = $this->_getParam('ac'); $this->view->ac = $ac = $this->_getParam('ac');
if($ac == "get") if($ac == "new")
{ {
$this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('user-new');
$this->_helper->viewRenderer->setNoRender(); $this->view->year = $year = !empty($this->_getParam('year')) ? $this->_getParam('year'):date("Y");
$this->view->by = $by = !empty($this->_getParam('by')) ? $this->_getParam('by'):"month";
include_once("Stat.php"); $userStatistics = new \Statistics\User();
$stat = new Stat($this->db);
if($by == "month")
$rows = $stat->UserDataorder(); {
$this->view->data = $userStatistics->getNewUsersByMonth($year);
$down = $this->_getParam('down'); }
if(empty($down))
{ if($by == "year")
$this->jsonexit(array("aaData"=>$rows)); {
return true; $this->view->data = $userStatistics->getNewUsersByYear($year);
} }
if($down == "csv") if($by == "monthavg")
{ {
$this->view->data = $userStatistics->getAverageSingupByMonth($year);
$this->_helper->layout->disableLayout(); }
$this->_helper->viewRenderer->setNoRender();
return true;
$head = array("id","姓名","离线申请次数","在线申请次数","总申请次数"); }
array_unshift($rows,$head); if($ac == "get")
{
$stat->Download("westdc-download-status.csv",$rows,"csv"); $this->_helper->layout->disableLayout();
exit(); $this->_helper->viewRenderer->setNoRender();
} include_once("Stat.php");
$stat = new Stat($this->db);
if($down == "json")
{ $rows = $stat->UserDataorder();
$this->_helper->layout->disableLayout(); $down = $this->_getParam('down');
$this->_helper->viewRenderer->setNoRender(); if(empty($down))
{
/* $this->jsonexit(array("aaData"=>$rows));
$head = array("id","姓名","离线申请次数","在线申请次数","总申请次数"); return true;
}
array_unshift($rows,$head);
*/ if($down == "csv")
{
$stat->Download("westdc-download-status.json",$rows,"json");
exit(); $this->_helper->layout->disableLayout();
} $this->_helper->viewRenderer->setNoRender();
} $head = array("id","姓名","离线申请次数","在线申请次数","总申请次数");
}//userAction() array_unshift($rows,$head);
function monthAction(){ $stat->Download("westdc-download-status.csv",$rows,"csv");
exit();
$y = (int)$this->_request->getParam('y');
}
if(!empty($y))
{ if($down == "json")
$n = date("Y",time()); {
if($y<2004 || $y>$n)
{ $this->_helper->layout->disableLayout();
$y=$n; $this->_helper->viewRenderer->setNoRender();
}
} /*
$this->view->y = $y; $head = array("id","姓名","离线申请次数","在线申请次数","总申请次数");
$sql = "select count(extract(month from ts_created)) as c,extract(month from ts_created) as m,extract(year from ts_created) as y from onlineapp
where id in (select distinct(onlineappid) from dataorder)"; array_unshift($rows,$head);
if ($y) */
$sql.=" and extract(year from ts_created)='$y' ";
$sql.=" group by extract(month from ts_created),extract(year from ts_created) $stat->Download("westdc-download-status.json",$rows,"json");
order by extract(year from ts_created),extract(month from ts_created)"; exit();
$rs = $this->db->query($sql); }
$rows = $rs->fetchAll();
}
$this->view->data = $rows;
}//userAction()
$sql = "select count(extract(month from ts_created)) as c,extract(month from ts_created) as m,extract(year from ts_created) as y from dataorder
where status=0"; function monthAction(){
if ($y)
$sql.=" and extract(year from ts_created)='$y' "; $y = (int)$this->_request->getParam('y');
$sql.=" group by extract(month from ts_created),extract(year from ts_created)
order by extract(year from ts_created),extract(month from ts_created)"; if(!empty($y))
$rs = $this->db->query($sql); {
$rows = $rs->fetchAll(); $n = date("Y",time());
$this->view->online = $rows; if($y<2004 || $y>$n)
{
$sql = "select count(extract(month from ts_created)) as c,extract(month from ts_created) as m,extract(year from ts_created) as y from offlineapp $y=$n;
where ts_approved is not null"; }
if ($y) }
$sql.=" and extract(year from ts_created)='$y' "; $this->view->y = $y;
$sql.=" group by extract(month from ts_created),extract(year from ts_created) $sql = "select count(extract(month from ts_created)) as c,extract(month from ts_created) as m,extract(year from ts_created) as y from onlineapp
order by extract(year from ts_created),extract(month from ts_created)"; where id in (select distinct(onlineappid) from dataorder)";
$rs = $this->db->query($sql); if ($y)
$rows = $rs->fetchAll(); $sql.=" and extract(year from ts_created)='$y' ";
$sql.=" group by extract(month from ts_created),extract(year from ts_created)
if(count($rows)<=0) order by extract(year from ts_created),extract(month from ts_created)";
{ $rs = $this->db->query($sql);
$this->view->offline=""; $rows = $rs->fetchAll();
}
$this->view->data = $rows;
$this->view->offline = $rows;
$sql = "select count(extract(month from ts_created)) as c,extract(month from ts_created) as m,extract(year from ts_created) as y from dataorder
$sql = "select count(extract(month from ts_created)) as c,extract(month from ts_created) as m,extract(year from ts_created) as y from users"; where status=0";
if ($y) if ($y)
$sql.=" where extract(year from ts_created)='$y' "; $sql.=" and extract(year from ts_created)='$y' ";
$sql.=" group by extract(month from ts_created),extract(year from ts_created) $sql.=" group by extract(month from ts_created),extract(year from ts_created)
order by extract(year from ts_created),extract(month from ts_created)"; order by extract(year from ts_created),extract(month from ts_created)";
$rs = $this->db->query($sql); $rs = $this->db->query($sql);
$rows = $rs->fetchAll(); $rows = $rs->fetchAll();
if(count($rows)<=0) $this->view->online = $rows;
{
$this->view->newuser=""; $sql = "select count(extract(month from ts_created)) as c,extract(month from ts_created) as m,extract(year from ts_created) as y from offlineapp
} where ts_approved is not null";
if ($y)
$this->view->newuser = $rows; $sql.=" and extract(year from ts_created)='$y' ";
$sql.=" group by extract(month from ts_created),extract(year from ts_created)
order by extract(year from ts_created),extract(month from ts_created)";
$rs = $this->db->query($sql);
}//按月份统计 $rows = $rs->fetchAll();
function awstatswebAction() if(count($rows)<=0)
{ {
$this->view->offline="";
}//awstats web 统计 }
function awstatsweb2Action() $this->view->offline = $rows;
{
$sql = "select count(extract(month from ts_created)) as c,extract(month from ts_created) as m,extract(year from ts_created) as y from users";
}//awstats web 统计 if ($y)
$sql.=" where extract(year from ts_created)='$y' ";
function awstatsftpAction() $sql.=" group by extract(month from ts_created),extract(year from ts_created)
{ order by extract(year from ts_created),extract(month from ts_created)";
$rs = $this->db->query($sql);
}//awstats ftp 统计 $rows = $rs->fetchAll();
if(count($rows)<=0)
function awstatsftp2Action() {
{ $this->view->newuser="";
}
}//awstats ftp 统计
$this->view->newuser = $rows;
function webalizerAction()
{
}//webalizer 统计 }//按月份统计
function waterAction() function awstatswebAction()
{ {
$sql="select count(k.keyword) as num,d.status,k.keyword from dataorder d left join metadata m on d.uuid=m.uuid }//awstats web 统计
left join keyword k on m.id=k.id
where (d.status=5 or d.status=-1) and m.source='0595169a-279e-4b95-819f-129d0ba4280d' function awstatsweb2Action()
and (k.keyword='航空遥感' or k.keyword='卫星遥感' or k.keyword='气象水文' or k.keyword='上游寒区水文试验区' or k.keyword='森林水文试验区' or k.keyword='中游干旱区水文试验区') {
group by k.keyword,d.status order by k.keyword desc,d.status desc";
}//awstats web 统计
$re =$this->db->query($sql);
$type =$re->fetchAll();//按分类 function awstatsftpAction()
{
$this->view->type = $type;
}//awstats ftp 统计
$sql="select count(extract(month from o.ts_created)) as c,extract(month from o.ts_created) as m,extract(year from o.ts_created) as y
from offlineapp o left join dataorder d on d.offlineappid=o.id left join metadata m on m.uuid=d.uuid function awstatsftp2Action()
where m.source='0595169a-279e-4b95-819f-129d0ba4280d' and (d.status=3 or d.status=5 or d.status=-1) {
group by extract(month from o.ts_created),extract(year from o.ts_created)
order by extract(year from o.ts_created),extract(month from o.ts_created)"; }//awstats ftp 统计
$re=$this->db->query($sql); function webalizerAction()
$month=$re->fetchAll(); {
$this->view->month = $month; }//webalizer 统计
$sql = "select function waterAction()
extract(year from o.ts_created) as y,extract(month from o.ts_created) as m, {
count(extract(month from o.ts_created)) as c
from $sql="select count(k.keyword) as num,d.status,k.keyword from dataorder d left join metadata m on d.uuid=m.uuid
(select distinct(o.id),o.ts_created left join keyword k on m.id=k.id
from offlineapp o where o.datalist like '%黑河综合遥感联合试验%') as o where (d.status=5 or d.status=-1) and m.source='0595169a-279e-4b95-819f-129d0ba4280d'
group by extract(month from o.ts_created),extract(year from o.ts_created) and (k.keyword='航空遥感' or k.keyword='卫星遥感' or k.keyword='气象水文' or k.keyword='上游寒区水文试验区' or k.keyword='森林水文试验区' or k.keyword='中游干旱区水文试验区')
order by extract(year from o.ts_created),extract(month from o.ts_created)"; group by k.keyword,d.status order by k.keyword desc,d.status desc";
$re=$this->db->query($sql); $re =$this->db->query($sql);
$order=$re->fetchAll(); $type =$re->fetchAll();//按分类
$this->view->order = $order; $this->view->type = $type;
$sql = "select (sum(m.filesize)/1024) as n from dataorder d left join metadata m on d.uuid=m.uuid $sql="select count(extract(month from o.ts_created)) as c,extract(month from o.ts_created) as m,extract(year from o.ts_created) as y
where d.status=5 and m.source='0595169a-279e-4b95-819f-129d0ba4280d'"; from offlineapp o left join dataorder d on d.offlineappid=o.id left join metadata m on m.uuid=d.uuid
where m.source='0595169a-279e-4b95-819f-129d0ba4280d' and (d.status=3 or d.status=5 or d.status=-1)
$re=$this->db->query($sql); group by extract(month from o.ts_created),extract(year from o.ts_created)
$num=$re->fetchAll(); order by extract(year from o.ts_created),extract(month from o.ts_created)";
$this->view->num=$num; $re=$this->db->query($sql);
$month=$re->fetchAll();
$sql = "select count(lower(o.unit)) as c,lower(o.unit) as u $this->view->month = $month;
from offlineapp o left join dataorder d on d.offlineappid=o.id left join metadata m on m.uuid=d.uuid
where m.source='0595169a-279e-4b95-819f-129d0ba4280d' and (d.status=5) $sql = "select
group by lower(o.unit) extract(year from o.ts_created) as y,extract(month from o.ts_created) as m,
order by lower(o.unit)"; count(extract(month from o.ts_created)) as c
from
$re=$this->db->query($sql); (select distinct(o.id),o.ts_created
$units=$re->fetchAll(); from offlineapp o where o.datalist like '%黑河综合遥感联合试验%') as o
group by extract(month from o.ts_created),extract(year from o.ts_created)
$this->view->units=$units; order by extract(year from o.ts_created),extract(month from o.ts_created)";
$re=$this->db->query($sql);
$sql = "select count(t.unit) as c,t.unit from $order=$re->fetchAll();
(select distinct(o.id),o.unit
from offlineapp o left join dataorder d on d.offlineappid=o.id left join metadata m on m.uuid=d.uuid $this->view->order = $order;
where m.source='0595169a-279e-4b95-819f-129d0ba4280d' and (d.status=5)
) as t $sql = "select (sum(m.filesize)/1024) as n from dataorder d left join metadata m on d.uuid=m.uuid
group by t.unit"; where d.status=5 and m.source='0595169a-279e-4b95-819f-129d0ba4280d'";
$re = $this->db->query($sql); $re=$this->db->query($sql);
$ounit= $re->fetchAll(); $num=$re->fetchAll();
$this->view->ounit = $ounit; $this->view->num=$num;
//water 项目按月统计下载量
$sql = "select (sum(m.filesize)/1024) as n,extract(month from d.ts_created) as m,extract(year from d.ts_created) as y from dataorder d left join metadata m on d.uuid=m.uuid $sql = "select count(lower(o.unit)) as c,lower(o.unit) as u
where d.status=5 and m.source='0595169a-279e-4b95-819f-129d0ba4280d' from offlineapp o left join dataorder d on d.offlineappid=o.id left join metadata m on m.uuid=d.uuid
group by extract(month from d.ts_created),extract(year from d.ts_created) where m.source='0595169a-279e-4b95-819f-129d0ba4280d' and (d.status=5)
order by extract(year from d.ts_created),extract(month from d.ts_created)"; group by lower(o.unit)
order by lower(o.unit)";
$re = $this->db->query($sql);
$dm = $re->fetchAll(); $re=$this->db->query($sql);
$units=$re->fetchAll();
$this->view->dm = $dm;
$this->view->units=$units;
}//WATER项目
$sql = "select count(t.unit) as c,t.unit from
public function jsonexit($data){ (select distinct(o.id),o.unit
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK)); from offlineapp o left join dataorder d on d.offlineappid=o.id left join metadata m on m.uuid=d.uuid
return true; where m.source='0595169a-279e-4b95-819f-129d0ba4280d' and (d.status=5)
}//jsonexit() 退出并返回json数据 ) as t
group by t.unit";
}
$re = $this->db->query($sql);
$ounit= $re->fetchAll();
$this->view->ounit = $ounit;
//water 项目按月统计下载量
$sql = "select (sum(m.filesize)/1024) as n,extract(month from d.ts_created) as m,extract(year from d.ts_created) as y from dataorder d left join metadata m on d.uuid=m.uuid
where d.status=5 and m.source='0595169a-279e-4b95-819f-129d0ba4280d'
group by extract(month from d.ts_created),extract(year from d.ts_created)
order by extract(year from d.ts_created),extract(month from d.ts_created)";
$re = $this->db->query($sql);
$dm = $re->fetchAll();
$this->view->dm = $dm;
}//WATER项目
public function jsonexit($data){
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK));
return true;
}//jsonexit() 退出并返回json数据
}

View File

@ -0,0 +1,4 @@
<ul class="nav nav-tabs">
<li <?= empty($this->ac) ? 'class="active"':"" ?>><a href="/admin/stat/user">概况</a></li>
<li <?= $this->ac == "new" ? 'class="active"':"" ?>><a href="/admin/stat/user/ac/new">新用户</a></li>
</ul>

View File

@ -0,0 +1,158 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->theme->AppendPlus($this,'jquery');
$this->theme->AppendPlus($this,'colorbox');
$this->headLink()->appendStylesheet('/css/jquery.jqplot.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin">后台首页</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<script language="javascript" type="text/javascript" src="/static/js/plot/jquery.jqplot.js"></script>
<script language="javascript" type="text/javascript" src="/static/js/plot/plugins/jqplot.barRenderer.js"></script>
<script language="javascript" type="text/javascript" src="/static/js/plot/plugins/jqplot.pieRenderer.js"></script>
<script language="javascript" type="text/javascript" src="/static/js/plot/plugins/jqplot.categoryAxisRenderer.js"></script>
<script language="javascript" type="text/javascript" src="/static/js/plot/plugins/jqplot.highlighter.js"></script>
<script language="javascript" type="text/javascript" src="/static/js/plot/plugins/jqplot.pointLabels.js"></script>
<div class="row-fluid">
<div class="span2">
<?= $this->partial('stat/left.phtml'); ?>
</div>
<div class="span10">
<?= $this->partial('stat/user-nav.phtml',array('ac'=>$this->ac)); ?>
<div class="cp">
方式:
<a href="/admin/stat/user/ac/new/by/month<?= $this->year ? "/year/".$this->year:"" ?>" class="btn btn-info <?= $this->by == "month" ? "disabled":"" ?>">按月</a>
<a href="/admin/stat/user/ac/new/by/year<?= $this->year ? "/year/".$this->year:"" ?>" class="btn btn-info <?= $this->by == "year" ? "disabled":"" ?>">按年</a>
<a href="/admin/stat/user/ac/new/by/monthavg<?= $this->year ? "/year/".$this->year:"" ?>" class="btn btn-info <?= $this->by == "monthavg" ? "disabled":"" ?>">月均值</a>
</div>
<div>
年份:
<?php if(in_array($this->by,array("year","monthavg") )) {?><a href="/admin/stat/user/ac/new/by/<?= $this->by ?>/year/-1" class="btn btn-info">所有</a><?php } ?>
<?php for($i = (int)date("Y");$i>=2004 ;$i--)
{
$active = $this->year == $i ? "disabled":"";
echo '<a href="/admin/stat/user/ac/new/by/'.$this->by.'/year/'.$i.'" class="btn btn-info '.$active.'">'.$i.'</a>';
}
?>
</div>
<?php if($this->by == 'month' && !empty($this->data)){ ?>
<hr />
<h4><?= $this->year ?>的按月新用户注册量统计</h4>
<div class="row-fluid">
<div class="span3">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>月份</th>
<th>增量</th>
</tr>
</thead>
<tbody>
<?php foreach($this->data as $k=>$v) {?>
<tr><td><?= $v['date_part'] ?></td><td><?= $v['count'] ?></td></tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="span9">
<!-- 统计图表 -->
</div>
</div>
<?php } ?>
<?php if($this->by == 'year' && !empty($this->data)){ ?>
<hr />
<h4><?= $this->year == -1 ? "所有":$this->year ?>的新用户注册量统计</h4>
<div class="row-fluid">
<div class="span3">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>年份</th>
<th>增量</th>
</tr>
</thead>
<tbody>
<?php foreach($this->data as $k=>$v) {?>
<tr><td><?= $v['date_part'] ?></td><td><?= $v['count'] ?></td></tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="span9">
<!-- 统计图表 -->
<script type="text/javascript">
$(function () {
<?php
$vars = array();
$month = array();
foreach ($this->data as $v)
{
$vars[] = $v['count'];
$month[]= "'".$v['date_part']."'";
}
?>
var s1 = [<?php echo join(',',$vars); ?>];
var ticks = [<?php echo join(',',$month); ?>];
plot1 = $.jqplot('chart_div_year_seq', [s1], {
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true }
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ticks
}
},
highlighter: { show: false }
});
});
</script>
<div class="content" id="chart_div_year_seq"></div>
</div>
</div>
<?php } ?>
<?php if($this->by == 'monthavg' && !empty($this->data)){ ?>
<hr />
<h4><?= $this->year ?>的月均用户注册量</h4>
<div class="row-fluid">
<div class="span3">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>年份</th>
<th>月均</th>
</tr>
</thead>
<tbody>
<?php foreach($this->data as $k=>$v) {?>
<tr><td><?= $v['date_part'] ?></td><td><?= $v['count'] ?></td></tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="span9">
<!-- 统计图表 -->
</div>
</div>
<?php } ?>
</div>
</div>

View File

@ -1,72 +1,62 @@
<?php <?php
$this->headTitle($this->config->title->site); $this->headTitle($this->config->title->site);
$this->headTitle('后台管理'); $this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - '); $this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/admin.css'); $this->headLink()->appendStylesheet('/css/admin.css');
$this->theme->AppendPlus($this,'jquery'); $this->theme->AppendPlus($this,'jquery');
$this->theme->AppendPlus($this,'colorbox'); $this->theme->AppendPlus($this,'colorbox');
$this->theme->AppendPlus($this,'datatable'); $this->theme->AppendPlus($this,'datatable');
$this->breadcrumb('<a href="/">首页</a>'); $this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin">后台首页</a>'); $this->breadcrumb('<a href="/admin">后台首页</a>');
$this->breadcrumb()->setSeparator(' > '); $this->breadcrumb()->setSeparator(' > ');
?> ?>
<style> <div class="row-fluid">
.charts{margin:30px 0px;} <div class="span2">
.charts .title{color:#003366;} <?= $this->partial('stat/left.phtml'); ?>
.cp {line-height:24px;} </div>
.cp ul li{float:left;margin:0px 0px;} <div class="span10">
.cp a{color:#4bb2c5;line-height:24px;padding:5px;}
.cp a.active,.cp a:hover{color:#FFF;background:#4bb2c5;} <?= $this->partial('stat/user-nav.phtml',array('ac'=>$this->ac)); ?>
</style>
<div id="leftPanel"> <div class="cp">
<?= $this->partial('stat/left.phtml'); ?> <a href="/admin/stat/user/ac/get/down/csv" class="btn btn-info">导出csv格式</a>
</div> <a href="/admin/stat/user/ac/get/down/json" class="btn btn-info">导出JSON格式</a>
<div id="rightPanel"> </div>
<div id="unitdata">
<div class="cp"> <b>点击列名进行排序</b>
<ul> </div>
<li> <div class="dataTables_wrapper">
<a href="/admin/stat/user/ac/get/down/csv">导出csv格式</a> <table id="datatable" class="table table-bordered table-striped table_vam dataTable">
</li> <thead>
<li> <tr>
<a href="/admin/stat/user/ac/get/down/json">导出JSON格式</a> <th>ID</th>
</li> <th>用户</th>
</ul> <th>离线申请次数</th>
</div> <th>在线申请次数</th>
<div id="unitdata"> <th>总申请次数</th>
<b>点击列名进行排序</b> </tr>
</div> </thead>
<div class="dataTables_wrapper"> <tbody>
<table id="datatable" class="table table-bordered table-striped table_vam dataTable">
<thead> </tbody>
<tr> </table>
<th>ID</th> </div>
<th>用户</th>
<th>离线申请次数</th> </div>
<th>在线申请次数</th> </div>
<th>总申请次数</th> <script>
</tr> $(document).ready(function() {
</thead> $('#datatable').dataTable( {
<tbody> "bProcessing": true,
"sAjaxSource": "/admin/stat/user/ac/get",
</tbody> "aoColumns": [
</table> { "mData": "userid" },
</div> { "mData": "realname" },
{ "mData": "offline" },
</div> { "mData": "online" },
<script> { "mData": "total" }
$(document).ready(function() { ],
$('#datatable').dataTable( { "sPaginationType": "full_numbers"
"bProcessing": true, });
"sAjaxSource": "/admin/stat/user/ac/get", } );
"aoColumns": [
{ "mData": "userid" },
{ "mData": "realname" },
{ "mData": "offline" },
{ "mData": "online" },
{ "mData": "total" }
],
"sPaginationType": "full_numbers"
});
} );
</script> </script>

View File

@ -0,0 +1,130 @@
<?php
namespace Statistics;
use \Helpers\View as view;
use \Helpers\dbh;
use \Files\Files;
class User
{
private $db; //传入PDO对象.
private $config; //站点设置
protected $events = NULL;
public $table;
public $keyword;
public $order;
public $sort = "DESC";
function __construct($db = NULL,$mail = NULL)
{
if(empty($db))
{
$this->db = \Zend_Registry::get('db');
}else{
$this->db = $db;
}
$this->config = \Zend_Registry::get('config');
$this->table = new \Helpers\Table();
}
public function ThisYear(){
return date("Y",time());
}
//按年统计新用户
public function getNewUsersByYear($year = 0)
{
if(empty($year))
{
$year = $this->ThisYear();
}
if($year == -1)
{
$sql = "select count(id),extract(year from ts_created)
from users
group by extract(year from ts_created)
order by date_part";
}else{
$sql = "select count(id),extract(year from ts_created)
from users
where extract(year from ts_created)='$year'
group by extract(year from ts_created)";
}
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
return $rows;
}
//按月统计新用户
public function getNewUsersByMonth($year = 0)
{
if(empty($year))
{
$year = $this->ThisYear();
}
$sql = "select count(id),extract(month from ts_created)
from users
where extract(year from ts_created)=$year
group by extract(month from ts_created)
order by date_part";
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
return $rows;
}
//月均注册量
public function getAverageSingupByMonth($year = 0)
{
if(empty($year))
{
$year = $this->ThisYear();
}
$sql = "select round(count(id)/12) as count,extract(year from ts_created)
from users
where extract(year from ts_created)='$year'
group by extract(year from ts_created)";
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
return $rows;
}
//总用户量
public function getTotal($year = 0)
{
if(empty($year))
{
$year = $this->ThisYear();
}
$sql = "";
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
return $rows;
}
//平均申请数
public function getAverageApplicationTimes($times = 1)
{
if(empty($year))
{
$times = 1;
}
$sql = "";
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
return $rows;
}
}