优化脚本

master
chenzhi 5 years ago
parent 37d8f72c6d
commit 04c5f17790

@ -27,7 +27,7 @@ class IndexChartSetController extends AdminController {
public $PromoteModel;
public $addid;
public $adddata;
public $continue=false;
public $reset=false;
public function _initialize(){
//初始化
@ -37,53 +37,51 @@ class IndexChartSetController extends AdminController {
$this->LoginModel =M("user_login_record","tab_");
$this->SpendModel =M("spend","tab_");
$this->PromoteModel =M("promote","tab_");
$this->nowdata =time();
$this->nowdata =time();
if(I("reset")) $this->reset = true;
}
/**
* 更新某月数据
* 每日更新接口
*/
public function setChartCount()
{
// $month = I("count_date");
// if(empty($month)) die("参数错误");
$date = I("date");
$this->date = $date;
$tarry = explode('-',$date);
$this->beginTime=mktime(0,0,0,$tarry[1],$tarry[2],$tarry[0]);
$this->endTime=mktime(0,0,0,$tarry[1],$tarry[2]-0+1,$tarry[0])-1;
set_time_limit(0);
$t1 = microtime(true);
$this->newUser();
$this->activeUser();
$this->payUser();
$this->payMoney();
$this->promoteNew();
$this->allCount();
$this->createDb();
$t2 = microtime(true);
die("success runtime:".round($t2-$t1,3).'s');
$begin = date("Y-m-d",strtotime("-1 day"));
$this->setDateCount($begin);
}
public function setMonth($month)
public function setFreeDateCount($begin,$end='')
{
if($month == 11){
$j = date("d");
if($end == '') $end = $begin;
//判断日期格式
$patten = "/^\d{4}[\-](0?[1-9]|1[012])[\-](0?[1-9]|[12][0-9]|3[01])$/";
if (!preg_match($patten, $begin)) {
die("开始时间格式错误");
}
if (!preg_match($patten, $end)) {
die("结束时间格式错误");
}
if(strtotime($end) < strtotime($begin)){
die("结束时间不能比开始时间小");
}
if(strtotime($end)+86399 > time()){
die("结束时间不能包含今日");
}
if($begin == $end){
$this->setDateCount($begin);
}else{
$j = date("t",strtotime("2019-{$month}-1"));
$starttime = $begin?strtotime($begin):mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endtime = $end?strtotime($end)+86399:$starttime+86399;
$datelist = get_date_list($starttime,$endtime,1);
$countdate = count($datelist);
for($i=0;$i<$countdate;$i++){
$this->setDateCount($datelist[$i]);
}
}
$start_time = strtotime(date("Y-{$month}-01"));
for($i=0;$i<$j;$i++){
$date = date('Y-m-d',$start_time+$i*86400);
$this->setMonthCount($date);
}
}
//
public function setMonthCount($date)
public function setDateCount($date)
{
$this->date = $date;
$tarry = explode('-',$date);
@ -92,7 +90,20 @@ class IndexChartSetController extends AdminController {
set_time_limit(0);
$t1 = microtime(true);
//判断是否存在
$res = $this->ChartModel->where("date = '{$this->beginTime}'")->find();
$reset='';
if(!empty($res)){
if($this->reset){
$this->ChartModel->where("date = '{$this->beginTime}'")->delete();
$reset = "reset and creat ";
}else{
echo ("{$this->date} 已统计,请勿重复 ".PHP_EOL);
return;
}
}
$this->newUser();
$this->activeUser();
$this->payUser();
@ -102,18 +113,12 @@ class IndexChartSetController extends AdminController {
$this->createDb();
$t2 = microtime(true);
echo ("{$this->date} success runtime:".round($t2-$t1,3).'s'.PHP_EOL);
echo ("{$this->date} {$reset}success runtime:".round($t2-$t1,3).'s'.PHP_EOL);
# code...
}
//获取每日的增长用户
public function newUser()
{
//获取当天的数据
// $userdata =array(
// "date"=>$this->beginTime,
// "create_time"=>$this->nowdata
// );
$map = ['register_time'=>['between',[$this->beginTime,$this->endTime]],"puid"=>0];//0不是小号
$hoursnews = $this->UserModel->field('FROM_UNIXTIME(register_time, "%H") as time,COUNT(1) AS news')
->where($map)
@ -156,11 +161,6 @@ class IndexChartSetController extends AdminController {
}
$this->adddata["active_user_hours"] = serialize($user_hours);
unset($user_hours);
// $activeCount = $this->LoginModel->field('count(DISTINCT user_id) count')
// ->where($map)
// ->find();
//$this->adddata["active_user_count"] = $activeCount['count'];
//获取活跃用户列表
$activeCount = $this->LoginModel->field('user_id')
->where($map)
@ -191,10 +191,6 @@ class IndexChartSetController extends AdminController {
}
$this->adddata["pay_user_hours"] = serialize($user_hours);
unset($user_hours);
// $activeCount = $this->LoginModel->field('count(DISTINCT user_id) payuser')
// ->where($map)
// ->find();
// $this->adddata["pay_user_count"] = $activeCount['payuser'];
$activeCount = $this->SpendModel->field('user_id')
->where($map)
->group('user_id')
@ -203,7 +199,6 @@ class IndexChartSetController extends AdminController {
$this->adddata["pay_user_count"] = count($activeCount);
$this->adddata["pay_user_list"] = serialize(array_column($activeCount,'user_id'));
unset($activeCount);
// $res = $this->ChartModel->save($savedata);
}
/**
* 充值金额计算
@ -285,7 +280,6 @@ class IndexChartSetController extends AdminController {
{
$this->adddata['date']=$this->beginTime;
$this->adddata['create_time']=$this->nowdata;
// dump($this->adddata);
$this->ChartModel->add($this->adddata);
}

@ -16,18 +16,9 @@ use Base\Repository\UserRepository;
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
class IndexController extends AdminController {
public function test()
{
$content = 'MDAwMDAwMDAwMJndsKKZZYuXeqCgy324cpebidDdi6mplZy2vKCFdqeagKewp5CKas6JaJ3Nec6fnYWvzM59qK2im5OfZZGrq2d9zqeig3aD0IqNYs6IlnarmnzR0HrP0puGt7B2hqysdoLe0n-FeIKUfnqCl33edZ2DeK_VlJacnJvPvJycebiXlpewpJGLg9eVjWLOk815aoCfqs59qK2skrqwZpKKrJeW0aytkYaCmHqfetV50oaukY2vy5K8tJuHy69nhXWrpH3StKSYZHKUi4573JG7aamAn9TOfs6spYHQuKScedqdfc7VopBlctZ9pJnSipeGrpF82NqVrbmlmpSbopGfqKeOq6yvj2Sxk3-NhtqKqqhlha-ymYrR22OG3L9ohnjaYoKWvKKFZLGTf32Gln-3mJebiczei8_PlZy2v2eHibCUmLjJsoV3oNJ6n6jLiZZpn5GIrpt6z6ibhKWwq5ufzpuOt69vhHZt2X6JqMuJ0oKpkGee2JOYrJuHy6-thYmrqY67r6KDdoPcimiZzpK7hZ2Gnq-Zi5ilpZG6uKGaZayll5a4q4CcsMuLaHfWirppq5l8q5qLva2Yms-sqJKFq2d9za-sgKBqzX-MatyRu5SpgJ_Uzn-svZyRz79phpyknI64p2mRnZyXio2G3H2onKGRn8nQgLy8qYXPv6uGrKeagKewpZx7i86To4LLf816rpGNr5eLva18kqaWrp56uKuOvLCDkXdp2n56dtqT3n6rhZ-mmYC5vWqbqrCqknq4m5ip0qSHh37bfoqGlH7ehWiFr77dgKispYHPrJ6RZJtiltK3ooacg5KLjn-Sfbh5roV5upd6ztqbkpSsqJKIm6aNu5elgJ2oy4l-hpOKuHafj326mH7fy5uQqrtnhpzJYYysu2yRioKViX6Gkoq4l2mCe92WgKmtn4e43mWGnMVmjZXeaoWtgpKAeZzLfKd6pJlos8uV0rmrm5TSqpqbq2d9zquuhHZt2XqfqMuTq3Zpj2ee3ousuauQlJtlmomsnZfNr2-An4ezibB62X24m6uGiaaVfrnGqYWmq2iPnLB3jt2vrIChe8qWjGrclKt2ZJuNss6Az6SlgdConJ2Im2SNvNGihp2c1Xqkf9mKu2Wfj2fR3HrP0puGttGphoa7poG4p66FrYrLl4dunw';
$request=json_decode(think_decrypt($content),true);
var_dump($request);
}
/**
* 后台首页
* @author cz
*
*/
public function index()
{
@ -51,7 +42,7 @@ class IndexController extends AdminController {
// 日历
$this->calendar();
$this->foldLineDiagramNew($_REQUEST['start'],$_REQUEST['end'],$_REQUEST['num']);
$this->foldLineDiagram($_REQUEST['start'],$_REQUEST['end'],$_REQUEST['num']);
$tm =strtotime(date("Y-m-d",strtotime("-1 day")));
$allcount = M("IndexChart","tab_")->field("all_count")->where("`date` = '{$tm}'")->find();
@ -64,12 +55,16 @@ class IndexController extends AdminController {
$this->assign('promote_sum',$allcount['promote_sum']);
//累计统计
$this->display();
# code...
}
//获取一天信息
public function foldLineDiagramNew($start='',$end='',$num='',$flag=false)
/*
* 折线图
* @param integer $start 开始时间
* @param integer $end 结束时间
* @param boolean $flag 是否ajax返回
* @author 鹿文学
*/
public function foldLineDiagram($start='',$end='',$num='',$flag=false)
{
$starttime = $start?strtotime($start):mktime(0,0,0,date('m'),date('d')-1,date('Y'));
@ -116,7 +111,6 @@ class IndexController extends AdminController {
} else {
$datelist = get_date_list($starttime,$endtime,$num==7?4:1);
dump($datelist);
$data['date'] = $datelist;
$data['hours'] = 0;
$map = array(
@ -186,10 +180,10 @@ class IndexController extends AdminController {
foreach($ydbdata as $k => $v) {
$active_user_list += unserialize($v['active_user_list']);
unset($v['active_user_list']);
unset($dbdata[$k]['active_user_list']);
unset($ydbdata[$k]['active_user_list']);
$pay_user_list += unserialize($v['pay_user_list']);
unset($v['pay_user_list']);
unset($dbdata[$k]['pay_user_list']);
unset($ydbdata[$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'];
@ -266,419 +260,88 @@ class IndexController extends AdminController {
return $rate;
}
/**
* 后台首页
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function indexBack(){
if(session('user_auth.uid')){
$data=M('Member')
->field('uid,nickname,username,us.last_login_time,us.last_login_ip,login')
->join('sys_ucenter_member as us on sys_member.uid = us.id')
->where(array('uid'=>session('user_auth.uid')))
->find();
header("Content-type: text/html; charset=utf-8");
if(is_administrator()){
$data['group']='超级管理员';
}else{
$data['group'] = get_auth_group_name($data['uid']);
}
}
$this->assign('data',$data);
$this->indextt();
/*
* 日历
* @param integer $start 开始时间(2018-04)
* @param integer $end 结束时间(2018-05)
* @param boolean $flag 是否ajax返回
* @author 鹿文学
*/
public function calendar($start='',$end='',$flag=false) {
$this->meta_title = '管理首页';
// 日历
$this->calendar();
// 折线图
$this->foldLineDiagram($_REQUEST['start'],$_REQUEST['end'],$_REQUEST['num']);
$start = $start?$start:date('Y-m',strtotime('-1 month'));
$end = $end?$end:date('Y-m');
// $userRepository = new UserRepository();
// $activeCount = $userRepository->getActiveUserCountRecently(7);
if ($start == $end) {$start = date('Y-m',strtotime('-1 month',$end));}
if (strtotime($start)>strtotime($end)) {$temp = $end;$end = $start;$start = $temp;}
if (strtotime($end) > strtotime(date('Y-m'))) {$end = date('Y-m');$start = date('Y-m',strtotime('-1 month'));}
$iscurrent = $end != date('Y-m')?1:0; // 默认是当前月,不可进入下一个月
// 累计数据
$user = D('User');
$spend = D('Spend');
$promote = D('Promote');
$this->assign('user_count', $user->old());
$this->assign('active_count', $user->active(['tab_user_login_record.login_time'=>['between',[mktime(0,0,0,date('m'),date('d')-7,date('Y')),mktime(0,0,0,date('m'),date('d'),date('Y'))-1]]]));
// $this->assign('active_count', $activeCount);
$this->assign('player_count', $spend->player());
$this->assign('money_sum', $spend->totalAmount());
$this->assign('promote_sum', $promote->total());
$this->display();
}
$stime = strtotime($start);
$etime = strtotime($end);
/*
* 日历
* @param integer $start 开始时间(2018-04)
* @param integer $end 结束时间(2018-05)
* @param boolean $flag 是否ajax返回
* @author 鹿文学
*/
public function calendar($start='',$end='',$flag=false) {
$start = $start?$start:date('Y-m',strtotime('-1 month'));
$end = $end?$end:date('Y-m');
if ($start == $end) {$start = date('Y-m',strtotime('-1 month',$end));}
if (strtotime($start)>strtotime($end)) {$temp = $end;$end = $start;$start = $temp;}
if (strtotime($end) > strtotime(date('Y-m'))) {$end = date('Y-m');$start = date('Y-m',strtotime('-1 month'));}
$iscurrent = $end != date('Y-m')?1:0; // 默认是当前月,不可进入下一个月
$stime = strtotime($start);
$etime = strtotime($end);
$sw = date('w',$stime); // 周几
$ew = date('w',$etime);
$sw = $sw == 0? 6:(integer)$sw-1;
$ew = $ew == 0? 6:(integer)$ew-1;
$st = date('t',$stime); // 天数
$et = date('t',$etime);
$sf = $ef = $sr = $er = 1; // 行数 ,日期起始值
for($i=0;$i<7;$i++) {
if ($i<$sw)
$first[$sr][$i] = ['value'=>''];
else {
$first[$sr][$i] = ['value'=>set_date_day_format($sf),'full'=>$start.'-'.set_date_day_format($sf)];$sf++;
}
$sw = date('w',$stime); // 周几
$ew = date('w',$etime);
$sw = $sw == 0? 6:(integer)$sw-1;
$ew = $ew == 0? 6:(integer)$ew-1;
$st = date('t',$stime); // 天数
$et = date('t',$etime);
$sf = $ef = $sr = $er = 1; // 行数 ,日期起始值
for($i=0;$i<7;$i++) {
if ($i<$sw)
$first[$sr][$i] = ['value'=>''];
else {
$first[$sr][$i] = ['value'=>set_date_day_format($sf),'full'=>$start.'-'.set_date_day_format($sf)];$sf++;
}
for($i=0;$i<7;$i++) {
if ($i<$ew)
$last[$er][$i] = ['value'=>''];
else {
$eday = set_date_day_format($ef);
if (strtotime($end.'-'.$eday)>strtotime(date('Y-m-d'))){
$last[$er][$i] = ['value'=>$eday,'full'=>$end.'-'.$eday,'no'=>1];$ef++;
}else{
$last[$er][$i] = ['value'=>$eday,'full'=>$end.'-'.$eday];$ef++;
}
}
for($i=0;$i<7;$i++) {
if ($i<$ew)
$last[$er][$i] = ['value'=>''];
else {
$eday = set_date_day_format($ef);
if (strtotime($end.'-'.$eday)>strtotime(date('Y-m-d'))){
$last[$er][$i] = ['value'=>$eday,'full'=>$end.'-'.$eday,'no'=>1];$ef++;
}else{
$last[$er][$i] = ['value'=>$eday,'full'=>$end.'-'.$eday];$ef++;
}
}
}
$sn = $en = 0; // 列数
for ($i=$sf;$i<=$st;$i++) {
if (count($first[$sr])==7){$sr++;$sn=0;}
$sday = set_date_day_format($i);
$first[$sr][$sn] = ['value'=>$sday,'full'=>$start.'-'.$sday];
$sn++;
}
for ($i=$ef;$i<=$et;$i++) {
if (count($last[$er])==7){$er++;$en=0;}
$eday = set_date_day_format($i);
if (strtotime($end.'-'.$eday)>strtotime(date('Y-m-d'))){$last[$er][$en] = ['value'=>$eday,'full'=>$end.'-'.$eday,'no'=>1];} else{$last[$er][$en] = ['value'=>$eday,'full'=>$end.'-'.$eday];}
$sn = $en = 0; // 列数
for ($i=$sf;$i<=$st;$i++) {
if (count($first[$sr])==7){$sr++;$sn=0;}
$sday = set_date_day_format($i);
$first[$sr][$sn] = ['value'=>$sday,'full'=>$start.'-'.$sday];
$sn++;
}
for ($i=$ef;$i<=$et;$i++) {
if (count($last[$er])==7){$er++;$en=0;}
$eday = set_date_day_format($i);
if (strtotime($end.'-'.$eday)>strtotime(date('Y-m-d'))){$last[$er][$en] = ['value'=>$eday,'full'=>$end.'-'.$eday,'no'=>1];} else{$last[$er][$en] = ['value'=>$eday,'full'=>$end.'-'.$eday];}
$en++;
}
$prev = date('Y-m',strtotime('-1 month',$stime)).','.$start;
$next = $end.','.date('Y-m',strtotime('+1 month',$etime));
$calendar = ['first'=>$first,'last'=>$last,'prev'=>$prev,'next'=>$next,'iscurrent'=>$iscurrent,'ftitle'=>date('Y年m月',$stime),'ltitle'=>date('Y年m月',$etime),'today'=>date('Y-m-d')];
if ($flag) {
echo json_encode($calendar);
} else {
$this->assign('calendar',$calendar);
}
$en++;
}
$prev = date('Y-m',strtotime('-1 month',$stime)).','.$start;
$next = $end.','.date('Y-m',strtotime('+1 month',$etime));
/*
* 折线图
* @param integer $start 开始时间
* @param integer $end 结束时间
* @param boolean $flag 是否ajax返回
* @author 鹿文学
*/
public function foldLineDiagram($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;}
$hours = ['00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23'];
$data['date'] = [$start];
$data['hours'] = 1;
foreach($hours as $v) {
$data['news'][$v] = 0;
$data['active'][$v] = 0;
$data['player'][$v] = 0;
$data['money'][$v] = 0;
}
// 新增用户
$hoursnews = $user->newsAdd(['register_time'=>['between',[$starttime,$endtime]]],'news','time',5);
// 活跃用户
$hoursactive = $user->totalPlayerByGroup($hours,['tab_user_login_record.login_time'=>['between',[$starttime,$endtime]]],'active','time',5);
// 付费用户
$hoursplayer = $spend->totalPlayerByGroup(['pay_time'=>['between',[$starttime,$endtime]]],'player','time',5);
// 充值金额
$hoursmoney = $spend->totalAmountByGroup(['pay_time'=>['between',[$starttime,$endtime]]],'money','time',5);
foreach($hours as $v) {
foreach($hoursnews as $h) {
$time = explode(' ',$h['time']);
if ($time[1] == $v){
$data['news'][$v] = (integer)$h['news'];break;
}
}
foreach($hoursactive as $h) {
if ($h['time'] == $v){
$data['active'][$v] = (integer)$h['active'];break;
}
}
foreach($hoursplayer as $h) {
$time = explode(' ',$h['time']);
if ($time[1] == $v){
$data['player'][$v] = (integer)$h['player'];break;
}
}
foreach($hoursmoney as $h) {
$time = explode(' ',$h['time']);
if ($time[1] == $v){
$data['money'][$v] = $h['money'];break;
}
}
}
// 新
$between = ['between',[$starttime-86400,$endtime]];
$cnewslist = $user->newsAdd(['register_time'=>$between],'count','time',1,'time desc');
$cnews['count'] = $cnewslist[0]['count']?$cnewslist[0]['count']:0;
$cnews['rate'] = $cnewslist[0] && $cnewslist[1]? round(($cnewslist[0]['count']/$cnewslist[1]['count']-1)*100,2):($cnewslist[0]&&!$cnewslist[1]?(100):(!$cnewslist[0]&&$cnewslist[1]?(-100):0));
// 活
$cactivelist = $user->totalPlayerByGroup([date('Y-m-d',$starttime-86400),$end],['tab_user_login_record.login_time'=>$between],'count','time',1,'time desc');
$cactive['count'] = $cactivelist[0]['count']?$cactivelist[0]['count']:0;
$cactive['rate'] = $cactivelist[0] && $cactivelist[1]? round(($cactivelist[0]['count']/$cactivelist[1]['count']-1)*100,2):($cactivelist[0]&&!$cactivelist[1]?(100):(!$cactivelist[0]&&$cactivelist[1]?(-100):0));
// 付
$cplayerlist = $spend->totalPlayerByGroup(['pay_time'=>$between],'count','time',1,'time desc');
$cplayer['count'] = $cplayerlist[0]['count']?$cplayerlist[0]['count']:0;
$cplayer['rate'] = $cplayerlist[0] && $cplayerlist[1]? round(($cplayerlist[0]['count']/$cplayerlist[1]['count']-1)*100,2):($cplayerlist[0]&&!$cplayerlist[1]?(100):(!$cplayerlist[0]&&$cplayerlist[1]?(-100):0));
// 充
$cmoneylist = $spend->totalAmountByGroup(['pay_time'=>$between],'count','time',1,'time desc');
$cmoney['count'] = $cmoneylist[0]['count']?$cmoneylist[0]['count']:0;
$cmoney['rate'] = $cmoneylist[0] && $cmoneylist[1]? round(($cmoneylist[0]['count']/$cmoneylist[1]['count']-1)*100,2):($cmoneylist[0]&&!$cmoneylist[1]?(100):(!$cmoneylist[0]&&$cmoneylist[1]?(-100):0));
// 渠
$cpromotelist = $promote->newsAdd(['create_time'=>$between],'count','time',1,'time desc');
$cpromote['count'] = $cpromotelist[0]['count']?$cpromotelist[0]['count']:0;
$cpromote['rate'] = $cpromotelist[0] && $cpromotelist[1]? round(($cpromotelist[0]['count']/$cpromotelist[1]['count']-1)*100,2):($cpromotelist[0]&&!$cpromotelist[1]?(100):(!$cpromotelist[0]&&$cpromotelist[1]?(-100):0));
} else {
$datelist = get_date_list($starttime,$endtime,$num==7?4:1);
$data['date'] = $datelist;
$data['hours'] = 0;
foreach($datelist as $k => $v) {
$data['news'][$v] = 0;
$data['active'][$v] = 0;
$data['player'][$v] = 0;
$data['money'][$v] = 0;
}
// 新增用户
$news = $user->newsAdd(['register_time'=>['between',[$starttime,$endtime]]],'news','time',$num==7?2:1);
// 活跃用户
$active = $user->totalPlayerByGroup($datelist,['tab_user_login_record.login_time'=>['between',[$starttime,$endtime]]],'active','time',$num==7?2:1);
// 付费用户
$player = $spend->totalPlayerByGroup(['pay_time'=>['between',[$starttime,$endtime]]],'player','time',$num==7?2:1);
// 充值金额
$money = $spend->totalAmountByGroup(['pay_time'=>['between',[$starttime,$endtime]]],'money','time',$num==7?2:1);
foreach($datelist as $v) {
foreach($news as $h) {
if ($v == $h['time']) {
$data['news'][$v] = (integer)$h['news'];break;
}
}
foreach($active as $h) {
if ($v == $h['time']) {
$data['active'][$v] = (integer)$h['active'];break;
}
}
foreach($player as $h) {
if ($v == $h['time']) {
$data['player'][$v] = (integer)$h['player'];break;
}
}
foreach($money as $h) {
if ($v == $h['time']) {
$data['money'][$v] = $h['money'];break;
}
}
}
// 新
$cnewslist1 = $user->old(['register_time'=>['between',[$starttime,$endtime]]]);
// 活
$cactivelist1 = $user->active(['tab_user_login_record.login_time'=>['between',[$starttime,$endtime]]]);
// 付
$cplayerlist1 = $spend->player(['pay_time'=>['between',[$starttime,$endtime]]]);
// 充
$cmoneylist1 = $spend->totalAmount(['pay_time'=>['between',[$starttime,$endtime]]]);
// 渠
$cpromotelist1 = $promote->total(['create_time'=>['between',[$starttime,$endtime]]]);
switch($num) {
case 3:{
$between = ['between',[strtotime('-7 day',$starttime),strtotime('-7 day',$endtime)]];
$cnewslist2 = $user->old(['register_time'=>$between]);
$cactivelist2 = $user->active(['tab_user_login_record.login_time'=>$between]);
$cplayerlist2 = $spend->player(['pay_time'=>$between]);
$cmoneylist2 = $spend->totalAmount(['pay_time'=>$between]);
$cpromotelist2 = $promote->total(['create_time'=>$between]);
};break;
case 4:{
$temp = strtotime('-1 month',$starttime);
$between = ['between',[$temp,mktime(0,0,0,date('m',$temp)+1,1,date('Y',$temp))-1]];
$cnewslist2 = $user->old(['register_time'=>$between]);
$cactivelist2 = $user->active(['tab_user_login_record.login_time'=>$between]);
$cplayerlist2 = $spend->player(['pay_time'=>$between]);
$cmoneylist2 = $spend->totalAmount(['pay_time'=>$between]);
$cpromotelist2 = $promote->total(['create_time'=>$between]);
};break;
case 5:{
$between = ['between',[strtotime('-7 day',$starttime),strtotime('-7 day',$endtime)]];
$cnewslist2 = $user->old(['register_time'=>$between]);
$cactivelist2 = $user->active(['tab_user_login_record.login_time'=>$between]);
$cplayerlist2 = $spend->player(['pay_time'=>$between]);
$cmoneylist2 = $spend->totalAmount(['pay_time'=>$between]);
$cpromotelist2 = $promote->total(['create_time'=>$between]);
};break;
case 6:{
$between = ['between',[strtotime('-30 day',$starttime),strtotime('-30 day',$endtime)]];
$cnewslist2 = $user->old(['register_time'=>$between]);
$cactivelist2 = $user->active(['tab_user_login_record.login_time'=>$between]);
$cplayerlist2 = $spend->player(['pay_time'=>$between]);
$cmoneylist2 = $spend->totalAmount(['pay_time'=>$between]);
$cpromotelist2 = $promote->total(['create_time'=>$between]);
};break;
case 7:{
$between = ['between',[strtotime('-365 day',$starttime),strtotime('-365 day',$endtime)]];
$cnewslist2 = $user->old(['register_time'=>$between]);
$cactivelist2 = $user->active(['tab_user_login_record.login_time'=>$between]);
$cplayerlist2 = $spend->player(['pay_time'=>$between]);
$cmoneylist2 = $spend->totalAmount(['pay_time'=>$between]);
$cpromotelist2 = $promote->total(['create_time'=>$between]);
};break;
default:{
$day_num = count($datelist);
$between = ['between',[strtotime('-'.$day_num.' day',$starttime),strtotime('-'.$day_num.' day',$endtime)]];
$cnewslist2 = $user->old(['register_time'=>$between]);
$cactivelist2 = $user->active(['tab_user_login_record.login_time'=>$between]);
$cplayerlist2 = $spend->player(['pay_time'=>$between]);
$cmoneylist2 = $spend->totalAmount(['pay_time'=>$between]);
$cpromotelist2 = $promote->total(['create_time'=>$between]);
};
}
$cnews['count'] = $cnewslist1?$cnewslist1:0;
$cnews['rate'] = $cnewslist1 && $cnewslist2? round(($cnewslist1/$cnewslist2-1)*100,2):($cnewslist1&&!$cnewslist2?(100):(!$cnewslist1&&$cnewslist2?(-100):0));
$cactive['count'] = $cactivelist1?$cactivelist1:0;
$cactive['rate'] = $cactivelist1 && $cactivelist2? round(($cactivelist1/$cactivelist2-1)*100,2):($cactivelist1&&!$cactivelist2?(100):(!$cactivelist1&&$cactivelist2?(-100):0));
$cplayer['count'] = $cplayerlist1?$cplayerlist1:0;
$cplayer['rate'] = $cplayerlist1 && $cplayerlist2? round(($cplayerlist1/$cplayerlist2-1)*100,2):($cplayerlist1&&!$cplayerlist2?(100):(!$cplayerlist1&&$cplayerlist2?(-100):0));
$cmoney['count'] = $cmoneylist1?$cmoneylist1:0;
$cmoney['rate'] = $cmoneylist1 && $cmoneylist2? round(($cmoneylist1/$cmoneylist2-1)*100,2):($cmoneylist1&&!$cmoneylist2?(100):(!$cmoneylist1&&$cmoneylist2?(-100):0));
$cpromote['count'] = $cpromotelist1?$cpromotelist1:0;
$cpromote['rate'] = $cpromotelist1 && $cpromotelist2? round(($cpromotelist1/$cpromotelist2-1)*100,2):($cpromotelist1&&!$cpromotelist2?(100):(!$cpromotelist1&&$cpromotelist2?(-100):0));
}
$calendar = ['first'=>$first,'last'=>$last,'prev'=>$prev,'next'=>$next,'iscurrent'=>$iscurrent,'ftitle'=>date('Y年m月',$stime),'ltitle'=>date('Y年m月',$etime),'today'=>date('Y-m-d')];
if ($flag) {
foreach($data as $k => $v) {
if (is_array($v)) {
if ($k == 'date')
$data[$k] = '"'.implode('","',$v).'"';
else
$data[$k] = implode(',',$v);
}
}
echo json_encode($calendar);
$data['compare']['news'] = $cnews;
$data['compare']['active'] = $cactive;
$data['compare']['player'] = $cplayer;
$data['compare']['money'] = $cmoney;
$data['compare']['promote'] = $cpromote;
} else {
if ($flag) {
echo json_encode($data);
} else {
$this->assign('foldline',$data);
$this->assign('num',$num);
}
$this->assign('calendar',$calendar);
}
}
public function indextt(){
$user = M("User","tab_");

@ -386,9 +386,12 @@
});
}
}
//执行日期的选择
function chartdata(start,end,parent) {
var index = layer.load(1, {
shade: [0.3,'#000'] //0.1透明度的白色背景
});
// var index = layer.load(2, {shade: false});
var href = '{:U("index")}';
end = end?end:start;
var tb = $.trim($('.tab_head a.current').attr('href')).replace('#','');

Loading…
Cancel
Save