暂存修改

master
chenzhi 5 years ago
parent c178de254b
commit 9962366ab9

@ -8,7 +8,7 @@ use User\Api\UserApi as UserApi;
* @author 麦当苗儿 <zuojiazi@vip.qq.com> * @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/ */
class StatisticsController extends ThinkController { class StatisticsController extends ThinkController {
const COUNTLIMIT = 15; const COUNTLIMIT = 10;
public function overview(){ public function overview(){
$shuju = json_decode(M('IndexChart','tab_')->field("all_count")->order('`date` desc')->find()["all_count"],true); $shuju = json_decode(M('IndexChart','tab_')->field("all_count")->order('`date` desc')->find()["all_count"],true);
$this->assign('shuju',$shuju); $this->assign('shuju',$shuju);
@ -43,8 +43,8 @@ class StatisticsController extends ThinkController {
default: default:
$promote_data = $this->promote_data_order2($today,$yesterday); $promote_data = $this->promote_data_order2($today,$yesterday);
} }
dump($list_data);die();
$this->assign('zhuce',$list_data['zhuce']); $this->assign('zhuce',$list_data['reg']);
$this->assign('active',$list_data['active']); $this->assign('active',$list_data['active']);
$this->assign('pay',$list_data['pay']); $this->assign('pay',$list_data['pay']);
$this->assign('game_chart',$list_data['chart']); $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 结束时间戳) * @param string $nowtime 现在时间段between 开始时间戳 and 结束时间戳)
@ -500,8 +466,68 @@ class StatisticsController extends ThinkController {
} }
return $data; 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();
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 $nowtime 现在时间段between 开始时间戳 and 结束时间戳)
@ -509,7 +535,7 @@ class StatisticsController extends ThinkController {
* @return array 结果集 * @return array 结果集
* @author lwx edit * @author lwx edit
*/ */
private function data_order($nowtime,$othertime){ private function data_order2($nowtime,$othertime){
$user = M("User","tab_"); $user = M("User","tab_");
$spend = M('Spend',"tab_"); $spend = M('Spend',"tab_");
@ -517,33 +543,6 @@ class StatisticsController extends ThinkController {
$chart2 = []; $chart2 = [];
$chart3 = []; $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();
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') $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)) ->where(array('register_time'.$nowtime,'fgame_id'=>array('gt',0),'puid'=>0))
->group('fgame_id')->order('cg desc')->limit(10)->select(); ->group('fgame_id')->order('cg desc')->limit(10)->select();
@ -642,10 +641,44 @@ if ($payids) {
else else
$data['chart'][$k] = implode(',',$v); $data['chart'][$k] = implode(',',$v);
} }
echo "<pre>";dump($data);die();
return $data; 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(){ public function zhexian(){
$day=$this->every_day(7); $day=$this->every_day(7);
$time=$this->total(9); $time=$this->total(9);

Loading…
Cancel
Save