205 lines
6.7 KiB
PHP
205 lines
6.7 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 缓存更新 数据统计 [ WE CAN DO IT JUST THINK IT ]
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\admin\controller;
|
|
use app\common\controller\Admin;
|
|
use think\Cache;
|
|
use think\Controller;
|
|
|
|
class Userstatisticscache extends Controller{
|
|
|
|
//更新数据统计缓存
|
|
public function index(){
|
|
$data = $this->UserCoutData();
|
|
$a = Cache::store('redis')->set('Userstatisticscache-data',$data,300);
|
|
$info = $this->updateUserinfodata();
|
|
Cache::store('redis')->set('Userstatisticscache-info-30',$info,300);
|
|
echo '更新缓存成功';
|
|
echo $a;
|
|
}
|
|
|
|
public function UserCoutData(){
|
|
$dataSection = $this->dataSection();
|
|
$dataSection['all'] = array(
|
|
'Start'=>0,
|
|
'End'=>0,
|
|
);
|
|
foreach($dataSection as $k=>$v){
|
|
//新增
|
|
$data[$k."newUser"] = $this ->newUser($v['Start'],$v['End']);
|
|
$data[$k."newUserNum"] = $this ->userTypeCount($v['Start'],$v['End'],0);
|
|
$data[$k."lowUserNum"] = $this ->userTypeCount($v['Start'],$v['End'],11);
|
|
$data[$k."firstUserNum"] = $this ->userTypeCount($v['Start'],$v['End'],12);
|
|
$data[$k."inUserNum"] = $this ->userTypeCount($v['Start'],$v['End'],13);
|
|
$data[$k."highUserNum"] = $this ->userTypeCount($v['Start'],$v['End'],14);
|
|
$data[$k."hiddenUserNum"] = $this ->userTypeCount($v['Start'],$v['End'],1);
|
|
$data[$k."invalidNum"] = $this ->userTypeCount($v['Start'],$v['End'],8);
|
|
$data[$k."invalidNewUserNum"] = $this ->userTypeCount($v['Start'],$v['End'],7);
|
|
|
|
//付费笔数
|
|
$data[$k."newUserNumPay"] = $this ->userTypeNum($v['Start'],$v['End'],0);
|
|
$data[$k."lowUserNumPay"] = $this ->userTypeNum($v['Start'],$v['End'],11);
|
|
$data[$k."firstUserNumPay"] = $this ->userTypeNum($v['Start'],$v['End'],12);
|
|
$data[$k."inUserNumPay"] = $this ->userTypeNum($v['Start'],$v['End'],13);
|
|
$data[$k."highUserNumPay"] = $this ->userTypeNum($v['Start'],$v['End'],14);
|
|
$data[$k."hiddenUserNumPay"] = $this ->userTypeNum($v['Start'],$v['End'],1);
|
|
$data[$k."invalidNumPay"] = $this ->userTypeNum($v['Start'],$v['End'],8);
|
|
$data[$k."invalidNewUserNumPay"] = $this ->userTypeNum($v['Start'],$v['End'],7);
|
|
//渠道充值笔数
|
|
$data[$k."PayNum"] = $this ->statistics($v['Start'],$v['End'],1);
|
|
//客户端充值笔数
|
|
$data[$k."clientPayNum"] = $this ->statistics($v['Start'],$v['End'],1,2);
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
public function updateUserinfodata(){
|
|
$nowday= date('Y-m-d');
|
|
$info=array();
|
|
for($i=30;$i>=1;$i--) {
|
|
$date=strtotime($nowday)-(30-$i)*24*3600;
|
|
$info[date('Y-m-d',$date)] = array(
|
|
"newUser"=> $this ->newUser($date,$date+86399),
|
|
"PayNum" => $this ->statistics($date,$date+86399,1),
|
|
"hiddenUserNumPay" => $this ->userTypeNum($date,$date+86399,1),
|
|
"invalidNumPay" => $this ->userTypeNum($date,$date+86399,8),
|
|
"clientPayNum" => $this ->statistics($date,$date+86399,1,2),
|
|
);
|
|
}
|
|
return $info;
|
|
}
|
|
|
|
public function newUser($startData,$endData) {
|
|
$map['status'] = 1;
|
|
if($startData && $endData){
|
|
$map['reg_time'] = array(array('gt',$startData),array('lt',$endData)) ;
|
|
}
|
|
$sum = db('member')->where($map)->count('uid');
|
|
return $sum;
|
|
}
|
|
|
|
/**
|
|
* statistics [新增人数分类型]
|
|
**/
|
|
protected function userTypeCount($startData,$endData,$t) {
|
|
if($startData && $endData){
|
|
$map['reg_time'] = array(array('gt',$startData),array('lt',$endData));
|
|
}
|
|
if($t==1){
|
|
$map['userType'] = array('in','4,5,6');
|
|
}elseif($t==8){
|
|
$map['userType'] = array('in','8');
|
|
}elseif($t==11){
|
|
$map['userType'] = $t;
|
|
}elseif($t==12){
|
|
$map['userType'] = $t;
|
|
}elseif($t==13){
|
|
$map['userType'] = $t;
|
|
}elseif($t==14){
|
|
$map['userType'] = $t;
|
|
}elseif($t===0){
|
|
$map['userType'] = $t;
|
|
}elseif($t==7){
|
|
$map['userType'] = $t;
|
|
}
|
|
$num = db('member')->where($map)->count();
|
|
return $num;
|
|
}
|
|
|
|
/**
|
|
* statistics [充值人数]
|
|
**/
|
|
protected function payNum($startData,$endData) {
|
|
if($startData && $endData){
|
|
$map['create_time'] = array(array('gt',$startData),array('lt',$endData));
|
|
}
|
|
$map['status'] = 1;
|
|
$map['is_complex'] = 1;
|
|
$total = db('order')->where('iscontrol',0)->where($map)->count('distinct(uid)');
|
|
return $total;
|
|
}
|
|
|
|
/**
|
|
* statistics [用户类型充值笔数]
|
|
**/
|
|
public function userTypeNum($startData,$endData,$t=1){
|
|
if($startData && $endData){
|
|
$map['create_time'] = array(array('gt',$startData),array('lt',$endData)) ;
|
|
}
|
|
$map['channel'] = array('neq',0);
|
|
if($t==1){
|
|
$map['hidden'] = 1;
|
|
$map['userType'] = array('in','4,5,6');
|
|
}elseif($t==8){
|
|
$map['hidden'] = 1;
|
|
$map['userType'] = $t;
|
|
}elseif($t==11){
|
|
$map['userType'] = $t;
|
|
}elseif($t==12){
|
|
$map['userType'] = $t;
|
|
}elseif($t==13){
|
|
$map['userType'] = $t;
|
|
}elseif($t==14){
|
|
$map['userType'] = $t;
|
|
}elseif($t===0){
|
|
$map['userType'] = $t;
|
|
}elseif($t==7){
|
|
$map['userType'] = $t;
|
|
}
|
|
$map['status'] = 1;
|
|
$total = db('order')->where($map)->count();
|
|
return $total;
|
|
}
|
|
|
|
/**
|
|
* statistics [充值笔数]
|
|
**/
|
|
protected function statistics($startData,$endData,$status,$type=1,$complex=1) {
|
|
if($startData && $endData){
|
|
$map['create_time'] = array(array('gt',$startData),array('lt',$endData)) ;
|
|
}
|
|
$map['status'] = $status;
|
|
if($type=='2'){
|
|
$map['channel'] = 0;
|
|
}else{
|
|
$map['channel'] = array('neq',0);
|
|
}
|
|
if($complex==1){
|
|
$map['is_complex'] = 1;
|
|
}elseif($complex==2){
|
|
$map['is_complex'] = array('>',1);
|
|
}
|
|
$map['hidden'] = 0;
|
|
$total = db('order')->where($map)->count();
|
|
return $total;
|
|
}
|
|
|
|
/**
|
|
* dataSection [今天/昨天/月/时间区间]
|
|
*
|
|
* @return type
|
|
**/
|
|
protected function dataSection() {
|
|
|
|
$result['today']['Start'] = strtotime(date('Y-m-d 00:00:00'));
|
|
$result['today']['End'] = time();
|
|
|
|
$result['yesterday']['Start'] = mktime(0, 0, 0, date('m'), date('d')-1, date('Y'));
|
|
$result['yesterday']['End'] = mktime(0, 0, 0, date('m'), date('d'), date('Y'))-1;
|
|
|
|
$result['month']['Start'] =mktime(0, 0, 0, date("m"), 1, date("Y"));
|
|
$result['month']['End'] =mktime(23, 59, 59, date("m"), date("t"), date("Y"));
|
|
|
|
$result['begin']['Start'] = strtotime(date('Y-m-01 00:00:00',strtotime('-1 month')));
|
|
$result['begin']['End'] = strtotime(date("Y-m-d 23:59:59", strtotime(-date('d').'day')));
|
|
|
|
$result['suotime']['Start'] = strtotime(date('2000-1-1 00:00:00',strtotime('-1 month')));
|
|
$result['suotime']['End'] = time();
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
} |