From 6bc0cdcf1eb2a4da3dc462bbed1fb47afa73fe1c Mon Sep 17 00:00:00 2001 From: chenzhi Date: Tue, 3 Dec 2019 10:42:34 +0800 Subject: [PATCH] 123 --- .../Controller/StatisticsController.class.php | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/Application/Admin/Controller/StatisticsController.class.php b/Application/Admin/Controller/StatisticsController.class.php index d6ec64979..98ab40d7f 100644 --- a/Application/Admin/Controller/StatisticsController.class.php +++ b/Application/Admin/Controller/StatisticsController.class.php @@ -292,6 +292,32 @@ class StatisticsController extends ThinkController { //活跃排行 //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(); + 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]['promote_id'].","); + $new_active_count[$i]["active_user_list"] = []; + $listarr[$new_active_count[$i]['promote_id']] = $new_active_count[$i]; + } + + $promote_id_str = \rtrim($promote_id_str,","); + //查询 + $active_user_list = $PromoteCount->field("active_user_list,promote_id")->where("`date` {$starttime} AND promote_id in ({$promote_id_str})")->select(); + for ($i=0; $i < count($active_user_list); $i++) { + $listarr[$active_user_list[$i]["promote_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; + } + //获取活跃总量排行 $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); @@ -471,11 +497,12 @@ class StatisticsController extends ThinkController { * @param [type] $endtime 比较时间 * @return void */ - private function data_order($starttime,$endtime){ + private function data_order($starttime,$endtime,$today =false){ $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.设置排名 @@ -484,6 +511,31 @@ class StatisticsController extends ThinkController { //活跃排行 //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; + } + $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);