From 68d23b469cb96dc0bda100d268a090168b70e7f2 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Tue, 3 Dec 2019 14:11:41 +0800 Subject: [PATCH] 123 --- .../Controller/StatisticsController.class.php | 212 +++++------------- 1 file changed, 59 insertions(+), 153 deletions(-) diff --git a/Application/Admin/Controller/StatisticsController.class.php b/Application/Admin/Controller/StatisticsController.class.php index 98ab40d7f..4249c9774 100644 --- a/Application/Admin/Controller/StatisticsController.class.php +++ b/Application/Admin/Controller/StatisticsController.class.php @@ -27,7 +27,7 @@ class StatisticsController extends ThinkController { // 游戏排行 $type=$_REQUEST['type']; if($type==1 || $type==''){ - $list_data=$this->data_order2($today,$yesterday); + $list_data=$this->data_order($today,$yesterday,true); }elseif($type==2){ $list_data=$this->data_order($thisweek,$lastweek); }elseif($type==3){ @@ -41,7 +41,7 @@ class StatisticsController extends ThinkController { case 3:{$promote_data = $this->promote_data_order($thismounth,$lastmounth);};break; case 4:{$promote_data = $this->promote_data_order($thisyear,$lastyear);};break; default: - $promote_data = $this->promote_data_order2($today,$yesterday); + $promote_data = $this->promote_data_order($today,$yesterday,true); } $this->assign('zhuce',$list_data['reg']); $this->assign('active',$list_data['active']); @@ -278,13 +278,18 @@ class StatisticsController extends ThinkController { * @param [type] $endtime 比较时间 * @return void */ - private function promote_data_order($starttime,$endtime){ + private function promote_data_order($starttime,$endtime,$today =false){ $PromoteCount = M("PromoteCount","tab_"); $data = array(); //注册排行 //1.获取注册前十名 - $new_user_count = $PromoteCount->field("promote_id,promote_account,sum(new_user_count) cg")->where("`date` {$starttime}")->group("promote_id")->order("cg desc")->limit(self::COUNTLIMIT)->select(); + if($today){ + $map = ["puid"=>0,"fgame_id"=>["gt",0]];//0不是小号 + $new_user_count = M("User","tab_")->field('COUNT(1) AS cg,promote_id,promote_account')->where($map)->where("register_time {$starttime}")->group("promote_id")->order("cg desc")->limit(self::COUNTLIMIT)->select(); + }else{ + $new_user_count = $PromoteCount->field("promote_id,promote_account,sum(new_user_count) cg")->where("`date` {$starttime}")->group("promote_id")->order("cg desc")->limit(self::COUNTLIMIT)->select(); + } $old_user_count = $PromoteCount->field("promote_id,promote_account,sum(new_user_count) cg")->where("`date` {$endtime}")->group("promote_id")->order("cg desc")->limit(self::COUNTLIMIT)->select(); //2.设置排名 $data["reg"] = $this->setRand($new_user_count,$old_user_count); @@ -502,50 +507,66 @@ class StatisticsController extends ThinkController { $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(); + if($today){ + $map = ["puid"=>0,"fgame_id"=>["gt",0]];//0不是小号 + $new_user_count = M("User","tab_")->field('COUNT(1) AS cg,fgame_id game_id,fgame_name game_name')->where($map)->where("register_time {$starttime}")->group("fgame_id")->order("cg desc")->limit(self::COUNTLIMIT)->select(); + }else{ + $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); + $data["reg"] = $this->setRand($new_user_count,$old_user_count,"game_id"); //活跃排行 //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(); - if(count($new_active_count) > 0){ - $listarr = array(); - $promote_id_str = ''; - for ($i=0; $i < count($new_active_count); $i++) { - # code... - $promote_id_str .= ($new_active_count[$i]['game_id'].","); - $new_active_count[$i]["active_user_list"] = []; - $listarr[$new_active_count[$i]['game_id']] = $new_active_count[$i]; - } - - $promote_id_str = \rtrim($promote_id_str,","); - //查询 - $active_user_list = $GameCount->field("active_user_list,game_id")->where("`date` {$starttime} AND game_id in ({$promote_id_str})")->select(); - for ($i=0; $i < count($active_user_list); $i++) { - $listarr[$active_user_list[$i]["game_id"]]["active_user_list"] += json_decode($active_user_list[$i]["active_user_list"],true); - } - foreach ($listarr as $key => $value) { - $value['cg'] = count(array_flip(array_flip($value['active_user_list']))); - unset($value['active_user_list']); - $listarr[$key] = $value; + if($today){ + $map = ["game_id"=>["gt",0]]; + $new_active_count = M("user_login_record","tab_")->field('COUNT(DISTINCT user_id) AS cg,game_id,game_name')->where($map)->where("login_time {$starttime}")->group("game_id")->order("cg desc")->limit(self::COUNTLIMIT)->select(); + }else{ + $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(); + if(count($new_active_count) > 0){ + $listarr = array(); + $promote_id_str = ''; + for ($i=0; $i < count($new_active_count); $i++) { + # code... + $promote_id_str .= ($new_active_count[$i]['game_id'].","); + $new_active_count[$i]["active_user_list"] = []; + $listarr[$new_active_count[$i]['game_id']] = $new_active_count[$i]; + } + + $promote_id_str = \rtrim($promote_id_str,","); + //查询 + $active_user_list = $GameCount->field("active_user_list,game_id")->where("`date` {$starttime} AND game_id in ({$promote_id_str})")->select(); + for ($i=0; $i < count($active_user_list); $i++) { + $listarr[$active_user_list[$i]["game_id"]]["active_user_list"] += json_decode($active_user_list[$i]["active_user_list"],true); + } + foreach ($listarr as $key => $value) { + $value['cg'] = count(array_flip(array_flip($value['active_user_list']))); + unset($value['active_user_list']); + $listarr[$key] = $value; + } + $last_names = array_column($listarr,'cg'); + array_multisort($last_names,SORT_DESC,$listarr); + $new_active_count = $listarr; } - $last_names = array_column($listarr,'cg'); - array_multisort($last_names,SORT_DESC,$listarr); - $new_active_count = $listarr; } + $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); + $data["active"] = $this->setRand($new_active_count,$old_active_count,"game_id"); //支付排行 //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(); + if($today){ + $map = ["pay_status"=>1,"game_id"=>["gt",0]]; + $new_money_count = M("Spend","tab_")->field('sum(pay_amount) AS cg,game_id,game_name')->where($map)->where("pay_time {$starttime}")->group("game_id")->order("cg desc")->limit(self::COUNTLIMIT)->select(); + }else{ + $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); + $data["pay"] = $this->setRand($new_money_count,$old_money_count,"game_id"); //设置chart $char = array(); @@ -579,123 +600,8 @@ class StatisticsController extends ThinkController { 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(); - $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; - } - } - } - - } - - // //充值排行 - //spend - $ri_spay_order=$spend->field('game_id,game_name,sum(pay_amount) as cg') - ->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']; - } - } - } - - } - $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; - } - } - } - - foreach($chart as $k => $v) { - if ($k == 'game') - $data['chart'][$k] = '"'.implode('","',$v).'"'; - else - $data['chart'][$k] = implode(',',$v); - } - return $data; - } //设置排名 - public function setRand($randdata,$oldrand) + public function setRand($randdata,$oldrand,$field = "promote_id") { //数据是否为空 $rcount = count($randdata); @@ -706,7 +612,7 @@ class StatisticsController extends ThinkController { if($ocount < 1){ $isold = false; }else{ - $oldrand = array_column($oldrand,"promote_id"); + $oldrand = array_column($oldrand,$field); $oldrand=array_flip($oldrand);//反转数组 } @@ -715,10 +621,10 @@ class StatisticsController extends ThinkController { $randdata[$i]['rand'] =$rand; if($isold){ - if(empty($oldrand[$randdata[$i]['promote_id']])){ + if(empty($oldrand[$randdata[$i][$field]])){ $randdata[$i]['change'] = 0; }else{ - $randdata[$i]['change'] = $oldrand[$randdata[$i]['promote_id']] - $rand; + $randdata[$i]['change'] = $oldrand[$randdata[$i][$field]] - $rand; } }else{