暂存修改

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,91 +466,124 @@ 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];
* @param string $nowtime 现在时间段between 开始时间戳 and 结束时间戳) if(empty($char[$t['game_id']])){
* @param string $othertime 过去时间段between 开始时间戳 and 结束时间戳) //不存在
* @return array 结果集 $char[$t['game_id']] = array(
* @author lwx edit // "promote_id" =>$t['promote_id'],
*/ "game_name" =>$t['game_name'],
private function data_order($nowtime,$othertime){ "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_"); $user = M("User","tab_");
$spend = M('Spend',"tab_"); $spend = M('Spend',"tab_");
$chart1 = []; $chart1 = [];
$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=$user->field('fgame_id as game_id,fgame_name as game_name,count(tab_user.id) as cg')
$ri_ug_order[$key]['change']=0; ->where(array('register_time'.$nowtime,'fgame_id'=>array('gt',0),'puid'=>0))
$chart1['g'.$value['game_id']] = $value; ->group('fgame_id')->order('cg desc')->limit(10)->select();
foreach ($yes_ug_order as $k => $v) { $ri_ug_order=array_order($ri_ug_order);
if($value['game_id']==$v['game_id']){ $regids = array_column($ri_ug_order,'game_id');
$ri_ug_order[$key]['change']=$value['rank_no']-$v['rank_no'];break; 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'])
if($ri_ug_order[$key]['change']==0) { ->group('fgame_id')->order('cg desc')->select();
$ri_ug_order[$key]['change'] = $value['rank_no']-count($ri_ug_order)-1; $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) {
$ri_ug_order=$user->field('fgame_id as game_id,fgame_name as game_name,count(tab_user.id) as cg') if($value['game_id']==$v['game_id']){
->where(array('register_time'.$nowtime,'fgame_id'=>array('gt',0),'puid'=>0)) $ri_ug_order[$key]['change']=$value['rand']-$v['rand'];break;
->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'); $duser = D('User');
$ri_active_order = $duser->activeRankOnGame($nowtime,'cg'); $ri_active_order = $duser->activeRankOnGame($nowtime,'cg');
$ri_active_order=array_order($ri_active_order); $ri_active_order=array_order($ri_active_order);
$activeids = array_column($ri_active_order,'game_id'); $activeids = array_column($ri_active_order,'game_id');
if($activeids) { if($activeids) {
$yes_active = $duser->activeRankOnGame($othertime,'cg',$activeids); $yes_active = $duser->activeRankOnGame($othertime,'cg',$activeids);
$yes_active=array_order($yes_active); $yes_active=array_order($yes_active);
foreach ($ri_active_order as $key => $value) { foreach ($ri_active_order as $key => $value) {
$ri_active_order[$key]['change'] = $value['rand']-count($ri_active_order)-1; $ri_active_order[$key]['change'] = $value['rand']-count($ri_active_order)-1;
$chart2['g'.$value['game_id']] = $value; $chart2['g'.$value['game_id']] = $value;
foreach ($yes_active as $k => $v) { foreach ($yes_active as $k => $v) {
if($value['game_id']==$v['game_id']){ if($value['game_id']==$v['game_id']){
$ri_active_order[$key]['change']=$value['rand']-$v['rand'];break; $ri_active_order[$key]['change']=$value['rand']-$v['rand'];break;
} }
} }
} }
} }
// //充值排行 // //充值排行
//spend //spend
@ -592,60 +591,94 @@ if($activeids) {
->where(array('pay_time'.$nowtime,'game_id'=>array('gt',0),'pay_status'=>1)) ->where(array('pay_time'.$nowtime,'game_id'=>array('gt',0),'pay_status'=>1))
->group('game_id')->order('cg desc')->limit(10)->select(); ->group('game_id')->order('cg desc')->limit(10)->select();
$ri_spay_order=array_order($ri_spay_order); $ri_spay_order=array_order($ri_spay_order);
$payids = array_column($ri_spay_order,'game_id'); $payids = array_column($ri_spay_order,'game_id');
if ($payids) { if ($payids) {
$yes_spay=$spend->field('game_id,game_name,sum(pay_amount) as cg') $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']) ->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(); ->group('game_id')->order('cg desc')->select();
$yes_spay=array_order($yes_spay); $yes_spay=array_order($yes_spay);
foreach ($ri_spay_order as $key => $value) { foreach ($ri_spay_order as $key => $value) {
$ri_spay_order[$key]['change'] = $value['rand']-count($ri_spay_order)-1; $ri_spay_order[$key]['change'] = $value['rand']-count($ri_spay_order)-1;
$chart3['g'.$value['game_id']] = $value; $chart3['g'.$value['game_id']] = $value;
foreach ($yes_spay as $k => $v) { foreach ($yes_spay as $k => $v) {
if($value['game_id']==$v['game_id']){ if($value['game_id']==$v['game_id']){
$ri_spay_order[$key]['change']=$value['rand']-$v['rand']; $ri_spay_order[$key]['change']=$value['rand']-$v['rand'];
} }
} }
} }
} }
$data['zhuce']=$ri_ug_order; $data['zhuce']=$ri_ug_order;
$data['active']=$ri_active_order; $data['active']=$ri_active_order;
$data['pay']=$ri_spay_order; $data['pay']=$ri_spay_order;
$chart4 = array_merge($chart1,$chart2,$chart3); $chart4 = array_merge($chart1,$chart2,$chart3);
foreach($chart4 as $k => $v) { foreach($chart4 as $k => $v) {
$chart['game'][$k] = $v['game_name']; $chart['game'][$k] = $v['game_name'];
foreach($chart1 as $c) { foreach($chart1 as $c) {
$chart['reg'][$k] = 0; $chart['reg'][$k] = 0;
if ($v['game_id'] == $c['game_id']) { if ($v['game_id'] == $c['game_id']) {
$chart['reg'][$k] = (integer)$c['cg'];break; $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) { foreach($chart2 as $c) {
if ($k == 'game') $chart['active'][$k] = 0;
$data['chart'][$k] = '"'.implode('","',$v).'"'; if ($v['game_id'] == $c['game_id']) {
else $chart['active'][$k] = (integer)$c['cg'];break;
$data['chart'][$k] = implode(',',$v);
} }
}
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 "<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