westdc-zf1/application/module/Statistics/User.php

131 lines
2.4 KiB
PHP
Raw Normal View History

<?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;
}
}