From 9962366ab95ef9a9db60409f28f86110e607249a Mon Sep 17 00:00:00 2001 From: chenzhi Date: Mon, 2 Dec 2019 14:18:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/StatisticsController.class.php | 349 ++++++++++-------- 1 file changed, 191 insertions(+), 158 deletions(-) diff --git a/Application/Admin/Controller/StatisticsController.class.php b/Application/Admin/Controller/StatisticsController.class.php index 3cbe143f7..c88a33012 100644 --- a/Application/Admin/Controller/StatisticsController.class.php +++ b/Application/Admin/Controller/StatisticsController.class.php @@ -8,7 +8,7 @@ use User\Api\UserApi as UserApi; * @author 麦当苗儿 */ class StatisticsController extends ThinkController { - const COUNTLIMIT = 15; + const COUNTLIMIT = 10; public function overview(){ $shuju = json_decode(M('IndexChart','tab_')->field("all_count")->order('`date` desc')->find()["all_count"],true); $this->assign('shuju',$shuju); @@ -43,8 +43,8 @@ class StatisticsController extends ThinkController { default: $promote_data = $this->promote_data_order2($today,$yesterday); } - - $this->assign('zhuce',$list_data['zhuce']); + dump($list_data);die(); + $this->assign('zhuce',$list_data['reg']); $this->assign('active',$list_data['active']); $this->assign('pay',$list_data['pay']); $this->assign('game_chart',$list_data['chart']); @@ -338,41 +338,7 @@ class StatisticsController extends ThinkController { } - //设置排名 - public function setRand($randdata,$oldrand) - { - //数据是否为空 - $rcount = count($randdata); - if($rcount < 1){return [];} - //判断是否有旧排名 - $isold = true; - $ocount = count($oldrand); - if($ocount < 1){ - $isold = false; - }else{ - $oldrand = array_column($oldrand,"promote_id"); - $oldrand=array_flip($oldrand);//反转数组 - } - - for ($i=0; $i <$rcount; $i++) { - $rand = $i+1; - $randdata[$i]['rand'] =$rand; - if($isold){ - if(empty($oldrand[$randdata[$i]['promote_id']])){ - $randdata[$i]['change'] = 0; - }else{ - $randdata[$i]['change'] = $oldrand[$randdata[$i]['promote_id']] - $rand; - } - - }else{ - $randdata[$i]['change'] = 0; - } - - } - return $randdata; - # code... - } /** * 排行榜(推广员) * @param string $nowtime 现在时间段(between 开始时间戳 and 结束时间戳) @@ -500,91 +466,124 @@ class StatisticsController extends ThinkController { } return $data; } + /** + * 获取游戏排行 + * @param [type] $starttime 当前时间 + * @param [type] $endtime 比较时间 + * @return void + */ + private function data_order($starttime,$endtime){ + $GameCount = M("GameCount","tab_"); + $data = array(); + //注册排行 + //1.获取注册前十名 + $new_user_count = $GameCount->field("game_id,game_name,sum(new_user_count) cg")->where("`date` {$starttime}")->group("game_id")->order("cg desc")->limit(self::COUNTLIMIT)->select(); + $old_user_count = $GameCount->field("game_id,game_name,sum(new_user_count) cg")->where("`date` {$endtime}")->group("game_id")->order("cg desc")->limit(self::COUNTLIMIT)->select(); + //2.设置排名 + $data["reg"] = $this->setRand($new_user_count,$old_user_count); + + //活跃排行 + //1.获取注册前十名 + $new_active_count = $GameCount->field("game_id,game_name,sum(active_user_count) cg")->where("`date` {$starttime}")->group("game_id")->order("cg desc")->limit(self::COUNTLIMIT)->select(); + $old_active_count = $GameCount->field("game_id,game_name,sum(active_user_count) cg")->where("`date` {$endtime}")->group("game_id")->order("cg desc")->limit(self::COUNTLIMIT)->select(); + //2.设置排名 + $data["active"] = $this->setRand($new_active_count,$old_active_count); + + //支付排行 + //1.获取注册前十名 + $new_money_count = $GameCount->field("game_id,game_name,sum(pay_money_count) cg")->where("`date` {$starttime}")->group("game_id")->order("cg desc")->limit(self::COUNTLIMIT)->select(); + $old_money_count = $GameCount->field("game_id,game_name,sum(pay_money_count) cg")->where("`date` {$endtime}")->group("game_id")->order("cg desc")->limit(self::COUNTLIMIT)->select(); + //2.设置排名 + $data["pay"] = $this->setRand($new_money_count,$old_money_count); + + //设置chart + $char = array(); - - /** - * 排行榜(游戏) - * @param string $nowtime 现在时间段(between 开始时间戳 and 结束时间戳) - * @param string $othertime 过去时间段(between 开始时间戳 and 结束时间戳) - * @return array 结果集 - * @author lwx edit - */ - private function data_order($nowtime,$othertime){ + foreach ($data as $key => $value) { + for ($i=0; $i < count($value); $i++) { + $t = $value[$i]; + if(empty($char[$t['game_id']])){ + //不存在 + $char[$t['game_id']] = array( + // "promote_id" =>$t['promote_id'], + "game_name" =>$t['game_name'], + "reg" => 0, + "active"=>0, + "pay"=>0 + ); + } + $char[$t['promote_id']][$key] = $t['cg']; + } + } + foreach ($char as $key => $value) { + $data["chart"]["game_name"] .= ("\"".$value['game_name']."\","); + $data["chart"]["reg"] .= ( $value['reg'].","); + $data["chart"]["active"] .= ( $value['active'].","); + $data["chart"]["pay"] .= ( $value['pay'].","); + } + $data["chart"]["game_name"] = \rtrim($data["chart"]["game_name"],","); + $data["chart"]["reg"] = \rtrim($data["chart"]["reg"],","); + $data["chart"]["active"] = \rtrim($data["chart"]["active"],","); + $data["chart"]["pay"] = \rtrim($data["chart"]["pay"],","); + return $data; + + } + /** + * 排行榜(游戏) + * @param string $nowtime 现在时间段(between 开始时间戳 and 结束时间戳) + * @param string $othertime 过去时间段(between 开始时间戳 and 结束时间戳) + * @return array 结果集 + * @author lwx edit + */ + private function data_order2($nowtime,$othertime){ $user = M("User","tab_"); $spend = M('Spend',"tab_"); - $chart1 = []; - $chart2 = []; - $chart3 = []; - - //今日注册排行 - /* $ri_ug_order=$user->field('fgame_id as game_id,fgame_name as game_name,count(tab_user.id) as cg') - ->where(array('register_time'.$nowtime,'fgame_id'=>array('gt',0),'puid'=>0)) - ->group('fgame_id')->order('cg desc')->limit(10)->select(false); - $ri_ug_order=$user->field('a.*,@rank:=@rank+1 as rank_no')->table('(' .$ri_ug_order. ') as a,(SELECT @rank:= 0) b')->select(); - - $regids = array_column($ri_ug_order,'game_id'); - if($regids) { - $yes_ug_order=$user->field('fgame_id as game_id,fgame_name as game_name,count(tab_user.id) as cg') - ->where([array('register_time'.$othertime,'fgame_id'=>array('gt',0),'puid'=>0),array('register_time'.$othertime,'fgame_id'=>array('in',$regids),'puid'=>0),'_logic'=>'or']) - ->group('fgame_id')->order('cg desc')->select(false); - $yes_ug_order=$user->field('a.*,@rank:=@rank+1 as rank_no')->table('(' .$yes_ug_order. ') as a,(SELECT @rank:= 0) b')->select(); + $chart1 = []; + $chart2 = []; + $chart3 = []; - foreach ($ri_ug_order as $key => $value) { - $ri_ug_order[$key]['change']=0; - $chart1['g'.$value['game_id']] = $value; - foreach ($yes_ug_order as $k => $v) { - if($value['game_id']==$v['game_id']){ - $ri_ug_order[$key]['change']=$value['rank_no']-$v['rank_no'];break; - } - } - if($ri_ug_order[$key]['change']==0) { - $ri_ug_order[$key]['change'] = $value['rank_no']-count($ri_ug_order)-1; - } - } - - } */ - $ri_ug_order=$user->field('fgame_id as game_id,fgame_name as game_name,count(tab_user.id) as cg') - ->where(array('register_time'.$nowtime,'fgame_id'=>array('gt',0),'puid'=>0)) - ->group('fgame_id')->order('cg desc')->limit(10)->select(); - $ri_ug_order=array_order($ri_ug_order); - $regids = array_column($ri_ug_order,'game_id'); - if($regids) { - $yes_ug_order=$user->field('fgame_id as game_id,fgame_name as game_name,count(tab_user.id) as cg') - ->where([array('register_time'.$othertime,'fgame_id'=>array('gt',0),'puid'=>0),array('register_time'.$othertime,'fgame_id'=>array('in',$regids),'puid'=>0),'_logic'=>'or']) - ->group('fgame_id')->order('cg desc')->select(); - $yes_ug_order=array_order($yes_ug_order); - foreach ($ri_ug_order as $key => $value) { - $ri_ug_order[$key]['change'] = $value['rand']-count($ri_ug_order)-1; - $chart1['g'.$value['game_id']] = $value; - foreach ($yes_ug_order as $k => $v) { - if($value['game_id']==$v['game_id']){ - $ri_ug_order[$key]['change']=$value['rand']-$v['rand'];break; - } + $ri_ug_order=$user->field('fgame_id as game_id,fgame_name as game_name,count(tab_user.id) as cg') + ->where(array('register_time'.$nowtime,'fgame_id'=>array('gt',0),'puid'=>0)) + ->group('fgame_id')->order('cg desc')->limit(10)->select(); + $ri_ug_order=array_order($ri_ug_order); + $regids = array_column($ri_ug_order,'game_id'); + if($regids) { + $yes_ug_order=$user->field('fgame_id as game_id,fgame_name as game_name,count(tab_user.id) as cg') + ->where([array('register_time'.$othertime,'fgame_id'=>array('gt',0),'puid'=>0),array('register_time'.$othertime,'fgame_id'=>array('in',$regids),'puid'=>0),'_logic'=>'or']) + ->group('fgame_id')->order('cg desc')->select(); + $yes_ug_order=array_order($yes_ug_order); + foreach ($ri_ug_order as $key => $value) { + $ri_ug_order[$key]['change'] = $value['rand']-count($ri_ug_order)-1; + $chart1['g'.$value['game_id']] = $value; + foreach ($yes_ug_order as $k => $v) { + if($value['game_id']==$v['game_id']){ + $ri_ug_order[$key]['change']=$value['rand']-$v['rand'];break; } } - - } + } + + } // //今日活跃排行 - $duser = D('User'); - $ri_active_order = $duser->activeRankOnGame($nowtime,'cg'); - $ri_active_order=array_order($ri_active_order); - $activeids = array_column($ri_active_order,'game_id'); -if($activeids) { - $yes_active = $duser->activeRankOnGame($othertime,'cg',$activeids); - $yes_active=array_order($yes_active); - foreach ($ri_active_order as $key => $value) { - $ri_active_order[$key]['change'] = $value['rand']-count($ri_active_order)-1; - $chart2['g'.$value['game_id']] = $value; - foreach ($yes_active as $k => $v) { - if($value['game_id']==$v['game_id']){ - $ri_active_order[$key]['change']=$value['rand']-$v['rand'];break; - } - } - } - -} + $duser = D('User'); + $ri_active_order = $duser->activeRankOnGame($nowtime,'cg'); + $ri_active_order=array_order($ri_active_order); + $activeids = array_column($ri_active_order,'game_id'); + if($activeids) { + $yes_active = $duser->activeRankOnGame($othertime,'cg',$activeids); + $yes_active=array_order($yes_active); + foreach ($ri_active_order as $key => $value) { + $ri_active_order[$key]['change'] = $value['rand']-count($ri_active_order)-1; + $chart2['g'.$value['game_id']] = $value; + foreach ($yes_active as $k => $v) { + if($value['game_id']==$v['game_id']){ + $ri_active_order[$key]['change']=$value['rand']-$v['rand'];break; + } + } + } + + } // //充值排行 //spend @@ -592,60 +591,94 @@ if($activeids) { ->where(array('pay_time'.$nowtime,'game_id'=>array('gt',0),'pay_status'=>1)) ->group('game_id')->order('cg desc')->limit(10)->select(); $ri_spay_order=array_order($ri_spay_order); - $payids = array_column($ri_spay_order,'game_id'); -if ($payids) { - $yes_spay=$spend->field('game_id,game_name,sum(pay_amount) as cg') - ->where([array('pay_status'=>1,'pay_time'.$othertime,'game_id'=>array('gt',0)),array('pay_time'.$othertime,'game_id'=>array('in',$payids)),'_logic'=>'or']) - ->group('game_id')->order('cg desc')->select(); - $yes_spay=array_order($yes_spay); - foreach ($ri_spay_order as $key => $value) { - $ri_spay_order[$key]['change'] = $value['rand']-count($ri_spay_order)-1; - $chart3['g'.$value['game_id']] = $value; - foreach ($yes_spay as $k => $v) { - if($value['game_id']==$v['game_id']){ - $ri_spay_order[$key]['change']=$value['rand']-$v['rand']; - } - } - } - -} + $payids = array_column($ri_spay_order,'game_id'); + if ($payids) { + $yes_spay=$spend->field('game_id,game_name,sum(pay_amount) as cg') + ->where([array('pay_status'=>1,'pay_time'.$othertime,'game_id'=>array('gt',0)),array('pay_time'.$othertime,'game_id'=>array('in',$payids)),'_logic'=>'or']) + ->group('game_id')->order('cg desc')->select(); + $yes_spay=array_order($yes_spay); + foreach ($ri_spay_order as $key => $value) { + $ri_spay_order[$key]['change'] = $value['rand']-count($ri_spay_order)-1; + $chart3['g'.$value['game_id']] = $value; + foreach ($yes_spay as $k => $v) { + if($value['game_id']==$v['game_id']){ + $ri_spay_order[$key]['change']=$value['rand']-$v['rand']; + } + } + } + + } $data['zhuce']=$ri_ug_order; $data['active']=$ri_active_order; $data['pay']=$ri_spay_order; - $chart4 = array_merge($chart1,$chart2,$chart3); - foreach($chart4 as $k => $v) { - $chart['game'][$k] = $v['game_name']; - foreach($chart1 as $c) { - $chart['reg'][$k] = 0; - if ($v['game_id'] == $c['game_id']) { - $chart['reg'][$k] = (integer)$c['cg'];break; - } - } - foreach($chart2 as $c) { - $chart['active'][$k] = 0; - if ($v['game_id'] == $c['game_id']) { - $chart['active'][$k] = (integer)$c['cg'];break; - } - } - foreach($chart3 as $c) { - $chart['pay'][$k] = 0; - if ($v['game_id'] == $c['game_id']) { - $chart['pay'][$k] = $c['cg'];break; - } - } + $chart4 = array_merge($chart1,$chart2,$chart3); + foreach($chart4 as $k => $v) { + $chart['game'][$k] = $v['game_name']; + foreach($chart1 as $c) { + $chart['reg'][$k] = 0; + if ($v['game_id'] == $c['game_id']) { + $chart['reg'][$k] = (integer)$c['cg'];break; } - - foreach($chart as $k => $v) { - if ($k == 'game') - $data['chart'][$k] = '"'.implode('","',$v).'"'; - else - $data['chart'][$k] = implode(',',$v); + } + foreach($chart2 as $c) { + $chart['active'][$k] = 0; + if ($v['game_id'] == $c['game_id']) { + $chart['active'][$k] = (integer)$c['cg'];break; } - + } + foreach($chart3 as $c) { + $chart['pay'][$k] = 0; + if ($v['game_id'] == $c['game_id']) { + $chart['pay'][$k] = $c['cg'];break; + } + } + } + + foreach($chart as $k => $v) { + if ($k == 'game') + $data['chart'][$k] = '"'.implode('","',$v).'"'; + else + $data['chart'][$k] = implode(',',$v); + } + echo "
";dump($data);die();
         return $data;
     }
+	//设置排名
+	public function setRand($randdata,$oldrand)
+	{
+		//数据是否为空
+		$rcount =  count($randdata);
+		if($rcount < 1){return [];}
+		//判断是否有旧排名
+		$isold = true;
+		$ocount = count($oldrand);
+		if($ocount < 1){
+			$isold = false;
+		}else{
+			$oldrand = array_column($oldrand,"promote_id");
+			$oldrand=array_flip($oldrand);//反转数组
+		}
+		
+		for ($i=0; $i <$rcount; $i++) { 
+			$rand = $i+1;
+
+			$randdata[$i]['rand'] =$rand;
+			if($isold){
+				if(empty($oldrand[$randdata[$i]['promote_id']])){
+					$randdata[$i]['change'] = 0;
+				}else{
+					$randdata[$i]['change'] = $oldrand[$randdata[$i]['promote_id']] - $rand;
+				}
+
+			}else{
+				$randdata[$i]['change'] = 0;
+			}
 
+		}
+		return $randdata;
+		# code...
+	}
     public function zhexian(){
         $day=$this->every_day(7);
         $time=$this->total(9);