后台统计添加了按用户统计的功能,并可以输出csv下载
This commit is contained in:
parent
6823b582d5
commit
6ee39b2908
|
@ -163,8 +163,7 @@ class Admin_StatController extends Zend_Controller_Action
|
|||
->setBody($content);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
$this->view->units = $units;
|
||||
|
@ -172,6 +171,75 @@ class Admin_StatController extends Zend_Controller_Action
|
|||
|
||||
}//分单位统计
|
||||
|
||||
//按用户统计
|
||||
function userAction(){
|
||||
|
||||
$ac = $this->_getParam('ac');
|
||||
|
||||
if($ac == "get")
|
||||
{
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
include_once("Stat.php");
|
||||
$stat = new Stat($this->db);
|
||||
|
||||
$rows = $stat->UserDataorder();
|
||||
|
||||
$down = $this->_getParam('down');
|
||||
if(empty($down))
|
||||
{
|
||||
$this->jsonexit(array("aaData"=>$rows));
|
||||
return true;
|
||||
}
|
||||
|
||||
if($down == "csv")
|
||||
{
|
||||
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
if(strpos($_SERVER["HTTP_USER_AGENT"],"Windows"))
|
||||
{
|
||||
$content = "\xEF\xBB\xBF";
|
||||
}else{
|
||||
$content = "";
|
||||
}
|
||||
$content .= "id,姓名,离线申请次数,在线申请次数,总申请次数"."\r\n";
|
||||
|
||||
foreach($rows as $k=>$v)
|
||||
{
|
||||
if(strpos($k,","))
|
||||
{
|
||||
$k = str_replace(",",",",$k);
|
||||
}
|
||||
$content .= $v['userid'].",".$v['realname'].",".$v['offline'].",".$v['online'].",".$v['total']."\r\n";
|
||||
}
|
||||
|
||||
$this->csvDownload($content);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}//userAction()
|
||||
|
||||
function csvDownload($content){
|
||||
$this->getResponse()->setHeader('Content-Type', 'text/csv')
|
||||
->setHeader('Content-Disposition','attachment; filename="westdc-download-status.csv"')
|
||||
->setHeader('Content-Length', strlen($content))
|
||||
->setHeader('Content-Type','application/force-download')
|
||||
->setHeader('Content-Type','application/download')
|
||||
->setHeader('Content-Description','File Transfer')
|
||||
->setHeader('Content-Transfer-Encoding','binary')
|
||||
->setHeader('Expires',0)
|
||||
->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0')
|
||||
->setHeader('Pragma','public')
|
||||
->setBody($content);
|
||||
}
|
||||
|
||||
function monthAction(){
|
||||
|
||||
$y = (int)$this->_request->getParam('y');
|
||||
|
@ -341,7 +409,10 @@ class Admin_StatController extends Zend_Controller_Action
|
|||
|
||||
}//WATER项目
|
||||
|
||||
|
||||
public function jsonexit($data){
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK));
|
||||
return true;
|
||||
}//jsonexit() 退出并返回json数据
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<ul>
|
||||
<li class="title">信息统计</li>
|
||||
<li><a href="/admin/stat/">统计概况</a></li>
|
||||
<li><a href="/admin/stat/unit">分单位统计</a></li>
|
||||
<li><a href="/admin/stat/month">分月统计</a></li>
|
||||
<li><a href="/admin/stat/">统计概况</a></li>
|
||||
<li><a href="/admin/stat/unit">分单位统计</a></li>
|
||||
<li><a href="/admin/stat/month">分月统计</a></li>
|
||||
<li><a href="/admin/stat/user">按用户统计</a></li>
|
||||
<li><a href="/admin/stat/awstatsweb">awstats web统计</a></li>
|
||||
<li><a href="/admin/stat/awstatsftp">awstats ftp统计</a></li>
|
||||
<li><a href="/admin/stat/webalizer">webalizer统计</a></li>
|
||||
|
|
|
@ -48,10 +48,13 @@
|
|||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<?php if(!empty($this->y)) {
|
||||
$url_param = "y=".$this->y;
|
||||
}?>
|
||||
<a href="/admin/stat/unit/ac/out">导出csv格式</a>
|
||||
<?php
|
||||
$url_param = "";
|
||||
if(!empty($this->y)) {
|
||||
$url_param = "?y=".$this->y;
|
||||
}
|
||||
?>
|
||||
<a href="/admin/stat/unit/ac/out<?= $url_param ?>">导出csv格式</a>
|
||||
</li>
|
||||
</div>
|
||||
<div id="unitdata">
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* Stat 统计
|
||||
*/
|
||||
|
||||
class Stat
|
||||
{
|
||||
|
||||
private $db;//传入PDO对象
|
||||
|
||||
//使用到的公共变量
|
||||
public $tbl_dataorder = "dataorder";
|
||||
|
||||
function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
|
||||
}
|
||||
|
||||
//获得dataorder中的所有用户
|
||||
public function UserDataorder(){
|
||||
|
||||
$dataorder = $this->tbl_dataorder;
|
||||
$sql = "SELECT d.userid,u.realname,count(d.id) as total
|
||||
,(SELECT count(dd.id) as offline FROM $dataorder dd WHERE dd.userid=d.userid AND (dd.offlineappid > 0 AND dd.onlineappid < 0) GROUP BY dd.userid) as offline
|
||||
,(SELECT count(dd.id) as online FROM $dataorder dd WHERE dd.userid=d.userid AND (dd.offlineappid < 0 AND dd.onlineappid > 0) GROUP BY dd.userid) as online
|
||||
FROM $dataorder d
|
||||
LEFT JOIN users u ON u.id=d.userid
|
||||
WHERE (d.offlineappid > 0 OR d.onlineappid > 0)
|
||||
GROUP BY d.userid,u.realname
|
||||
ORDER BY total DESC";
|
||||
$sth = $this->db->query($sql);
|
||||
return $sth->fetchAll();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -34,4 +34,11 @@
|
|||
.dTableR {width:100% !important}
|
||||
|
||||
.table-striped tbody tr:nth-child(2n) td, .table-striped tbody tr:nth-child(2n) th {background: #fff}
|
||||
.table_vam th, .table_vam td {vertical-align: middle}
|
||||
.table_vam th, .table_vam td {vertical-align: middle}
|
||||
|
||||
.dataTables_info{width:100%;height:30px;line-height:30px;padding:0px;}
|
||||
.dataTables_paginate{height:30px;width:100%;overflow:hidden;margin-top:5px;padding-top:5px; }
|
||||
.paging_full_numbers{overflow:hidden;margin:3px 0px;padding:0px;}
|
||||
.dataTables_paginate a.paginate_button{margin:2px 3px;padding:3px;border:1px solid #444;}
|
||||
.dataTables_paginate a.paginate_button:hover{background:#444;color:#FFF;}
|
||||
.dataTables_paginate a.paginate_active{background:#433;color:#FFF;margin:2px 3px;padding:3px;}
|
Loading…
Reference in New Issue