master
chenzhi 5 years ago
parent 9e171f2ce2
commit 63c27e62ca

@ -6,6 +6,7 @@ use Think\Controller;
/**
* 后台总览聚合
* @author cz
* 与group_concat最大字符数102400。后期考虑放弃
*/
class StatisticsCountSetController extends Controller {
public $beginTime;
@ -24,12 +25,13 @@ class StatisticsCountSetController extends Controller {
public function _initialize(){
//初始化
$this->UserModel =M("User","tab_");
$this->ChartModel =M("IndexChart","tab_");
$this->LoginModel =M("user_login_record","tab_");
$this->SpendModel =M("spend","tab_");
$this->PromoteModel =M("promote","tab_");
$this->PromoteModel =M("promote","tab_");
$this->PromoteCountModel =M("PromoteCount","tab_");
$this->GameCountModel =M("GameCount","tab_");
$this->nowdata =time();
if(I("reset")) $this->reset = true;
@ -56,23 +58,32 @@ class StatisticsCountSetController extends Controller {
// }
// }
$group_concat_max_len = M()->query("show variables like 'group_concat_max_len'")[0]['value'];
if($group_concat_max_len < 102400){
echo ("请".PHP_EOL);
}
dump($res);
// $this->promoteNew();
// $this->promotePayMoeny();
// $this->promoteActive();
// $this->promoteCreateDb();
// $this->addid = [];
// $this->adddata = [];
// $this->gameNew();
// $this->gamePayMoeny();
// $this->gameActive();
// $this->gameCreateDb();
// $this->newUser();
// $this->activeUser();
// $this->payUser();
// $this->payMoney();
$this->promoteNew();
// $this->allCount();
// $this->createDb();
echo "<pre>";
dump($this->addid);
dump($this->adddata);
$t2 = microtime(true);
echo ("{$this->date} {$reset}success runtime:".round($t2-$t1,3).'s'.PHP_EOL);
# code...
}
//聚合推广员
//=======================聚合推广员========================
//1聚合新增
public function promoteNew()
{
@ -83,16 +94,15 @@ class StatisticsCountSetController extends Controller {
->select();
$count = count($promoteNew);
for ($i=0; $i < $count; $i++) {
$promoteNew[$i]['']
$this->addid[] = $promoteNew[$i]["promote_id"];
$this->adddata[$promoteNew[$i]["promote_id"]] = $promoteNew[$i];
}
}
unset($promoteNew);
}
//2聚合付费
public function promotePayMoeny()
{
$map = ['pay_time'=>['between',[$this->beginTime,$this->endTime]],"pay_status"=>1];//1支付成功
$map = ['pay_time'=>['between',[$this->beginTime,$this->endTime]],"pay_status"=>1,"promote_id"=>["gt",0]];//1支付成功
$promotePayMoeny = $this->SpendModel->field('sum(pay_amount) AS pay_money_count,promote_id,promote_account')
->where($map)
->group("promote_id")
@ -101,12 +111,120 @@ class StatisticsCountSetController extends Controller {
for ($i=0; $i < $count; $i++) {
if (in_array($promotePayMoeny[$i]["promote_id"],$this->addid)) {
//存在
$this->adddata[$promotePayMoeny[$i]["promote_id"]]["pay_money_count"] = $promotePayMoeny[$i]["pay_money_count"];
}else{
$this->addid[] = $promotePayMoeny[$i]["promote_id"];
$this->adddata[$promotePayMoeny[$i]["promote_id"]] = $promotePayMoeny[$i];
}
$this->addid[] = $promoteNew[$i]["promote_id"];
$this->adddata[$promoteNew[$i]["promote_id"]] = $promoteNew[$i];
}
unset($promotePayMoeny);
}
//3聚合活跃
public function promoteActive()
{
$map = ['login_time'=>['between',[$this->beginTime,$this->endTime]],"promote_id"=>["gt",0]];//0不是小号
$promoteActive = $this->LoginModel->field('COUNT(DISTINCT user_id) AS active_user_count,GROUP_CONCAT(DISTINCT user_id) active_user_list,promote_id')
->where($map)
->group("promote_id")
->select();
$count = count($promoteActive);
for ($i=0; $i < $count; $i++) {
if (in_array($promoteActive[$i]["promote_id"],$this->addid)) {
//存在
$this->adddata[$promoteActive[$i]["promote_id"]]["active_user_count"] = $promoteActive[$i]["active_user_count"];
$this->adddata[$promoteActive[$i]["promote_id"]]["active_user_list"] = $promoteActive[$i]["active_user_list"];
}else{
$this->addid[] = $promoteActive[$i]["promote_id"];
$this->adddata[$promoteActive[$i]["promote_id"]] = $promoteActive[$i];
}
}
unset($promoteActive);
}
//4加入数据库
public function promoteCreateDb()
{
$count = count($this->addid);
if ($count > 0) {
foreach ($this->adddata as $key => $value) {
$value['date']=$this->beginTime;
$value['create_time']=$this->nowdata;
$value['active_user_list'] = @serialize(explode(",",$value['active_user_list']));
if(empty($value['promote_account'])){
$value['promote_account'] = $this->PromoteModel->field("account")->where("id = {$value['promote_id']}")->find()['account'];
}
$this->PromoteCountModel->add($value);
}
}
}
//=======================聚合游戏========================
//1聚合新增
public function gameNew()
{
$map = ['register_time'=>['between',[$this->beginTime,$this->endTime]],"puid"=>0,"fgame_id"=>["gt",0]];//0不是小号
$gameNew = $this->UserModel->field('COUNT(1) AS new_user_count,fgame_id game_id,fgame_name game_name')
->where($map)
->group("fgame_id")
->select();
$count = count($gameNew);
for ($i=0; $i < $count; $i++) {
$this->addid[] = $gameNew[$i]["game_id"];
$this->adddata[$gameNew[$i]["game_id"]] = $gameNew[$i];
}
unset($gameNew);
}
//2聚合付费
public function gamePayMoeny()
{
$map = ['pay_time'=>['between',[$this->beginTime,$this->endTime]],"pay_status"=>1,"game_id"=>["gt",0]];//1支付成功
$gamePayMoeny = $this->SpendModel->field('sum(pay_amount) AS pay_money_count,game_id,game_name')
->where($map)
->group("game_id")
->select();
$count = count($gamePayMoeny);
for ($i=0; $i < $count; $i++) {
if (in_array($gamePayMoeny[$i]["game_id"],$this->addid)) {
//存在
$this->adddata[$gamePayMoeny[$i]["game_id"]]["pay_money_count"] = $gamePayMoeny[$i]["pay_money_count"];
}else{
$this->addid[] = $gamePayMoeny[$i]["game_id"];
$this->adddata[$gamePayMoeny[$i]["game_id"]] = $gamePayMoeny[$i];
}
}
unset($gamePayMoeny);
}
//3聚合活跃
public function gameActive()
{
$map = ['login_time'=>['between',[$this->beginTime,$this->endTime]],"game_id"=>["gt",0]];//0不是小号
$gameActive = $this->LoginModel->field('COUNT(DISTINCT user_id) AS active_user_count,GROUP_CONCAT(DISTINCT user_id) active_user_list,game_id,game_name')
->where($map)
->group("game_id")
->select();
$count = count($gameActive);
for ($i=0; $i < $count; $i++) {
if (in_array($gameActive[$i]["game_id"],$this->addid)) {
//存在
$this->adddata[$gameActive[$i]["game_id"]]["active_user_count"] = $gameActive[$i]["active_user_count"];
$this->adddata[$gameActive[$i]["game_id"]]["active_user_list"] = $gameActive[$i]["active_user_list"];
}else{
$this->addid[] = $gameActive[$i]["game_id"];
$this->adddata[$gameActive[$i]["game_id"]] = $gameActive[$i];
}
}
unset($gameActive);
}
//4加入数据库
public function gameCreateDb()
{
$count = count($this->addid);
if ($count > 0) {
foreach ($this->adddata as $key => $value) {
$value['date']=$this->beginTime;
$value['create_time']=$this->nowdata;
$value['active_user_list'] = @serialize(explode(",",$value['active_user_list']));
$this->GameCountModel->add($value);
}
}
}
}

Loading…
Cancel
Save