总览-推广员聚合及展示

master
chenzhi 5 years ago
parent 177b1b1ee5
commit ce20d48d57

@ -8,6 +8,7 @@ use User\Api\UserApi as UserApi;
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
class StatisticsController extends ThinkController {
const COUNTLIMIT = 15;
public function overview(){
$shuju = json_decode(M('IndexChart','tab_')->field("all_count")->order('`date` desc')->find()["all_count"],true);
$this->assign('shuju',$shuju);
@ -40,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_order($today,$yesterday);
$promote_data = $this->promote_data_order2($today,$yesterday);
}
$this->assign('zhuce',$list_data['zhuce']);
@ -272,18 +273,106 @@ class StatisticsController extends ThinkController {
}
# code...
}
/**
* 获取推广员排行
* @param [type] $starttime 当前时间
* @param [type] $endtime 比较时间
* @return void
*/
private function promote_data_order($starttime,$endtime){
//注册排行
$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();
$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);
//活跃排行
//1.获取注册前十名
$new_active_count = $PromoteCount->field("promote_id,promote_account,sum(active_user_count) cg")->where("`date` {$starttime}")->group("promote_id")->order("cg desc")->limit(self::COUNTLIMIT)->select();
$old_active_count = $PromoteCount->field("promote_id,promote_account,sum(active_user_count) cg")->where("`date` {$endtime}")->group("promote_id")->order("cg desc")->limit(self::COUNTLIMIT)->select();
//2.设置排名
$data["active"] = $this->setRand($new_active_count,$old_active_count);
//支付排行
//1.获取注册前十名
$new_money_count = $PromoteCount->field("promote_id,promote_account,sum(pay_money_count) cg")->where("`date` {$starttime}")->group("promote_id")->order("cg desc")->limit(self::COUNTLIMIT)->select();
$old_money_count = $PromoteCount->field("promote_id,promote_account,sum(pay_money_count) cg")->where("`date` {$endtime}")->group("promote_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['promote_id']])){
//不存在
$char[$t['promote_id']] = array(
// "promote_id" =>$t['promote_id'],
"promote_account" =>$t['promote_account'],
"reg" => 0,
"active"=>0,
"pay"=>0
);
}
$char[$t['promote_id']][$key] = $t['cg'];
}
}
foreach ($char as $key => $value) {
$data["chart"]["promote"] .= ("\"".$value['promote_account']."\",");
$data["chart"]["reg"] .= ( $value['reg'].",");
$data["chart"]["active"] .= ( $value['active'].",");
$data["chart"]["pay"] .= ( $value['pay'].",");
}
$data["chart"]["promote"] = \rtrim($data["chart"]["promote"],",");
$data["chart"]["reg"] = \rtrim($data["chart"]["reg"],",");
$data["chart"]["active"] = \rtrim($data["chart"]["active"],",");
$data["chart"]["pay"] = \rtrim($data["chart"]["pay"],",");
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);//反转数组
}
//获取当前注册前十名
$new_user_count = $PromoteCount->field("promote_account,new_user_count")->where("`date` {$starttime}")->order("new_user_count desc")->limit(10)->select(false);
echo "<pre>";dump($new_user_count);die();
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 结束时间戳)
@ -331,7 +420,7 @@ class StatisticsController extends ThinkController {
$ri_active_order=array_order($ri_active_order);
$activeids = array_column($ri_active_order,'promote_id');
if ($activeids) {
if ($activeids) {
$yes_active = $duser->activeRankOnPromote($othertime,'cg',$activeids);
$yes_active=array_order($yes_active);
foreach ($ri_active_order as $key => $value) {
@ -344,7 +433,7 @@ if ($activeids) {
}
}
}
}
// //充值排行
//spend
@ -356,7 +445,7 @@ if ($activeids) {
$ri_spay_order = $spend->field('promote_id,promote_account,sum(cg) as cg')->table('('.$ri_spay_sql.') as a')->group('promote_id')->order('cg desc')->limit(10)->select();
$ri_spay_order=array_order($ri_spay_order);
$payids = array_column($ri_spay_order,'promote_id');
if ($payids) {
if ($payids) {
$yes_spay_sql=$spend->field('tab_spend.promote_id,tab_promote.account as promote_account,sum(pay_amount) as cg')
->join('tab_promote on(tab_spend.promote_id = tab_promote.id)')
->union('select promote_id,tab_promote.account as promote_account,sum(pay_amount) as cg from tab_deposit inner join tab_promote on(tab_promote.id = tab_deposit.promote_id) where pay_status=1 and promote_id>0 and tab_deposit.create_time '.$othertime.' group by promote_id ')
@ -374,7 +463,7 @@ if ($payids) {
}
}
}
}
}
$data['reg']=$ri_ug_order;
$data['active']=$ri_active_order;
@ -409,7 +498,6 @@ if ($payids) {
else
$data['chart'][$k] = implode(',',$v);
}
echo "<pre>";dump($data);die();
return $data;
}

Loading…
Cancel
Save