优化首页展示

master
chenzhi 5 years ago
parent e1739209e3
commit 37d8f72c6d

@ -102,7 +102,7 @@ class IndexChartSetController extends AdminController {
$this->createDb();
$t2 = microtime(true);
echo ("{$this->date} success runtime:".round($t2-$t1,3).'s\n');
echo ("{$this->date} success runtime:".round($t2-$t1,3).'s'.PHP_EOL);
# code...
}
//获取每日的增长用户

@ -51,18 +51,222 @@ class IndexController extends AdminController {
// 日历
$this->calendar();
$this->foldLineDiagramNew($_REQUEST['start'],$_REQUEST['end'],$_REQUEST['num']);
$tm = strtotime("-1 day");
dump();
$tm =strtotime(date("Y-m-d",strtotime("-1 day")));
$allcount = M("IndexChart","tab_")->field("all_count")->where("`date` = '{$tm}'")->find();
dump($allcount);
$allcount = unserialize($allcount['all_count']);
$this->assign('user_count',$allcount['user_count']);
$this->assign('active_count', $allcount['active_count']);
$this->assign('player_count', $allcount['player_count']);
$this->assign('money_sum', $allcount['money_sum']);
$this->assign('promote_sum',$allcount['promote_sum']);
//累计统计
$this->display();
# code...
}
//获取一天信息
public function foldLineDiagramNew($start='',$end='',$num='',$flag=false)
{
$starttime = $start?strtotime($start):mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endtime = $end?strtotime($end)+86399:$starttime+86399;
$start = date('Y-m-d',$starttime);
$end = date('Y-m-d',$endtime);
$user = D('User');
$spend = D('Spend');
$promote = D('Promote');
if ($start == $end) { // 单天
if ($start == date('Y-m-d',strtotime('-1 day'))) {$num = 2;}
$data['date'] = [$start];
$data['hours'] = 1;
$tm = strtotime($start);
$dbdata = M("IndexChart","tab_")->field("new_user_count,new_user_hours,active_user_count,active_user_hours,pay_user_count,pay_user_hours,pay_money_count,pay_money_hours,promote_new_count")->where("`date` = '{$tm}'")->find();
$data['news'] = unserialize($dbdata["new_user_hours"]);
$data['active'] = unserialize($dbdata["active_user_hours"]);
$data['player']=unserialize($dbdata["pay_user_hours"]);
$data['money']=unserialize($dbdata["pay_money_hours"]);
//获取昨天
$ytm = $starttime-86400;
$ydbdata = M("IndexChart","tab_")->field("new_user_count,active_user_count,pay_user_count,pay_money_count,promote_new_count")->where("`date` = '{$ytm}'")->find();
//计算
$cnews['count'] = $dbdata['new_user_count'];
$cnews['rate'] = $this->setRate($dbdata['new_user_count'],$ydbdata['new_user_count']);
$cactive['count'] = $dbdata['active_user_count'];
$cactive['rate'] = $this->setRate($dbdata['active_user_count'],$ydbdata['active_user_count']);
$cplayer['count'] = $dbdata['pay_user_count'];
$cplayer['rate'] = $this->setRate($dbdata['pay_user_count'],$ydbdata['pay_user_count']);
$cmoney['count'] = $dbdata['pay_money_count'];
$cmoney['rate'] = $this->setRate($dbdata['pay_money_count'],$ydbdata['pay_money_count']);
$cpromote['count'] = $dbdata['promote_new_count'];
$cpromote['rate'] = $this->setRate($dbdata['promote_new_count'],$ydbdata['promote_new_count']);
} else {
$datelist = get_date_list($starttime,$endtime,$num==7?4:1);
dump($datelist);
$data['date'] = $datelist;
$data['hours'] = 0;
$map = array(
"date"=>['between',[$starttime,$endtime]]
);
//获取记录
$count1 = array();
$active_user_list = [];
$pay_user_list = [];
$dbdata = M("IndexChart","tab_")->field("new_user_count,active_user_count,active_user_list,pay_user_count,pay_user_list,pay_money_count,promote_new_count")
->where($map)->select();
foreach($dbdata as $k => $v) {
$data['news'][$k] = $v['new_user_count'];
$data['active'][$k] = $v['active_user_count'];
$data['player'][$k] = $v['pay_user_count'];
$data['money'][$k] = $v['pay_money_count'];
$active_user_list += unserialize($v['active_user_list']);
unset($v['active_user_list']);
unset($dbdata[$k]['active_user_list']);
$pay_user_list += unserialize($v['pay_user_list']);
unset($v['pay_user_list']);
unset($dbdata[$k]['pay_user_list']);
$count1['new_user_count'] += $v['new_user_count'];
$count1['pay_money_count'] += $v['pay_money_count'];
$count1['promote_new_count'] += $v['promote_new_count'];
}
unset($dbdata);
$count1['active_user_count'] = count(array_flip(array_flip($active_user_list)));
unset($active_user_list);
$count1['pay_user_count'] = count(array_flip(array_flip($pay_user_list)));
unset($active_user_list);
//获取前num的日志
switch($num) {
case 3:{
$between = ['between',[strtotime('-7 day',$starttime),strtotime('-7 day',$endtime)]];
};break;
case 4:{
$temp = strtotime('-1 month',$starttime);
$between = ['between',[$temp,mktime(0,0,0,date('m',$temp)+1,1,date('Y',$temp))-1]];
};break;
case 5:{
$between = ['between',[strtotime('-7 day',$starttime),strtotime('-7 day',$endtime)]];
};break;
case 6:{
$between = ['between',[strtotime('-30 day',$starttime),strtotime('-30 day',$endtime)]];
};break;
case 7:{
$between = ['between',[strtotime('-365 day',$starttime),strtotime('-365 day',$endtime)]];
};break;
default:{
$day_num = count($datelist);
$between = ['between',[strtotime('-'.$day_num.' day',$starttime),strtotime('-'.$day_num.' day',$endtime)]];
};
}
//获取前几天记录
$map1 = array(
"date"=>$between
);
$ydbdata = M("IndexChart","tab_")->field("new_user_count,active_user_count,active_user_list,pay_user_count,pay_user_list,pay_money_count,promote_new_count")
->where($map1)->select();
$active_user_list = [];
$pay_user_list = [];
$count2 = array();
foreach($ydbdata as $k => $v) {
$active_user_list += unserialize($v['active_user_list']);
unset($v['active_user_list']);
unset($dbdata[$k]['active_user_list']);
$pay_user_list += unserialize($v['pay_user_list']);
unset($v['pay_user_list']);
unset($dbdata[$k]['pay_user_list']);
$count2['new_user_count'] += $v['new_user_count'];
$count2['pay_money_count'] += $v['pay_money_count'];
$count2['promote_new_count'] += $v['promote_new_count'];
}
unset($ydbdata);
$count2['active_user_count'] = count(array_flip(array_flip($active_user_list)));
unset($active_user_list);
$count2['pay_user_count'] = count(array_flip(array_flip($pay_user_list)));
unset($active_user_list);
//比较
$cnews['count'] = $count1['new_user_count'];
$cnews['rate'] = $this->setRate($count1['new_user_count'],$count2['new_user_count']);
$cactive['count'] =$count1['active_user_count'];
$cactive['rate'] = $this->setRate($count1['active_user_count'],$count2['active_user_count']);
$cplayer['count'] =$count1['pay_user_count'];
$cplayer['rate'] = $this->setRate($count1['pay_user_count'],$count2['pay_user_count']);
$cmoney['count'] = $count1['pay_money_count'];
$cmoney['rate'] = $this->setRate($count1['pay_money_count'],$count2['pay_money_count']);
$cpromote['count'] = $count1['promote_new_count'];
$cpromote['rate'] = $this->setRate($count1['promote_new_count'],$count2['promote_new_count']);
}
foreach($data as $k => $v) {
// dump($k);
if (is_array($v)) {
if ($k == 'date')
$data[$k] = '"'.implode('","',$v).'"';
else
$data[$k] = implode(',',$v);
}
}
$data['compare']['news'] = $cnews;
$data['compare']['active'] = $cactive;
$data['compare']['player'] = $cplayer;
$data['compare']['money'] = $cmoney;
$data['compare']['promote'] = $cpromote;
if ($flag) {
echo json_encode($data);
} else {
$this->assign('foldline',$data);
$this->assign('num',$num);
}
# code...
}
public function setRate($d1,$d2)
{
$rate = 0;
if($d1>0){
if($d2 > 0){
$rate = round(($d1/$d2-1)*100,2);
}else{
$rate = 100;
}
}else if($d1 == 0 && $d2 == 0){
$rate = 0;
}else{
$rate = -100;
}
return $rate;
}
/**
* 后台首页
* @author 麦当苗儿 <zuojiazi@vip.qq.com>

@ -45,7 +45,7 @@
<li class="<eq name='num' value='4'>datapick_active</eq>"><a href="{:U('index',array('start'=>date('Y-m-d',mktime(0,0,0,date('m')-1,1,date('Y'))),'end'=>date('Y-m-d',mktime(0,0,0,date('m'),1,date('Y'))-1),'num'=>4))}">过去整月</a></li>
<li class="<eq name='num' value='5'>datapick_active</eq>"><a href="{:U('index',array('start'=>date('Y-m-d',strtotime('-7 day')),'end'=>date('Y-m-d',strtotime('-1 day')),'num'=>5))}">过去7天</a></li>
<li class="<eq name='num' value='6'>datapick_active</eq>"><a href="{:U('index',array('start'=>date('Y-m-d',strtotime('-30 day')),'end'=>date('Y-m-d',strtotime('-1 day')),'num'=>6))}">过去30天</a></li>
<li class="<eq name='num' value='7'>datapick_active</eq>"><a href="{:U('index',array('start'=>date('Y-m-d',strtotime('-365 day')),'end'=>date('Y-m-d',strtotime('-1 day')),'num'=>7))}">过去一年</a></li>
<!-- <li class="<eq name='num' value='7'>datapick_active</eq>"><a href="{:U('index',array('start'=>date('Y-m-d',strtotime('-365 day')),'end'=>date('Y-m-d',strtotime('-1 day')),'num'=>7))}">过去一年</a></li> -->
</ul>
<div class="range_inputs">
<button class="applyBtn pt-btn btn-success js_determine" type="button">确定</button>

Loading…
Cancel
Save