|
|
|
@ -24,50 +24,49 @@ class SpendCountSetController extends \Think\Controller
|
|
|
|
|
$this->usermodel =M("spend_user_count",'tab_');
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 初始化统计/用于之前数据的聚合
|
|
|
|
|
* TODO:仅供测试,测试结束后删除
|
|
|
|
|
* 更新某月数据
|
|
|
|
|
*/
|
|
|
|
|
public function initCount()
|
|
|
|
|
public function setMonthSpendCount()
|
|
|
|
|
{
|
|
|
|
|
$countRes = M("spend_count","tab_")->field("count(*) date_count")->find()['date_count'];
|
|
|
|
|
if($countRes > 0){
|
|
|
|
|
die("init error");
|
|
|
|
|
}
|
|
|
|
|
$nowdate = date('Y')."-".(date('m') > 9 ? date('m') : "0".date('m'));
|
|
|
|
|
// $nowdate = "2017-10";
|
|
|
|
|
//获取所有的月份 pay_time
|
|
|
|
|
$res = M("spend",'tab_')->field("FROM_UNIXTIME(pay_time,'%Y-%m') AS pay_time")->buildSql();
|
|
|
|
|
$res = M()->table($res.' a')->group('pay_time')->select();
|
|
|
|
|
//执行数据统计
|
|
|
|
|
for ($i=0; $i < count($res); $i++) {
|
|
|
|
|
# code...
|
|
|
|
|
if($res[$i]['pay_time'] != $nowdate){
|
|
|
|
|
//设定初始时间
|
|
|
|
|
$month = $res[$i]['pay_time'];
|
|
|
|
|
$this->date = $month;
|
|
|
|
|
$tarry = explode('-',$month);
|
|
|
|
|
$this->beginThismonth=mktime(0,0,0,$tarry[1],1,$tarry[0]);
|
|
|
|
|
$this->endThismonth=mktime(0,0,0,$tarry[1]-0+1,1,$tarry[0])-1;
|
|
|
|
|
//执行聚合
|
|
|
|
|
$this->model->startTrans();
|
|
|
|
|
$this->usermodel->startTrans();
|
|
|
|
|
$this->continue =true;
|
|
|
|
|
//执行游戏表统计
|
|
|
|
|
$this->setGameCount();
|
|
|
|
|
//执行用户表统计
|
|
|
|
|
$this->setUserCount();
|
|
|
|
|
|
|
|
|
|
$this->model->commit();
|
|
|
|
|
$this->usermodel->commit();
|
|
|
|
|
}
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
$t1 = microtime(true);
|
|
|
|
|
|
|
|
|
|
$month = I("count_date");
|
|
|
|
|
if(empty($month)) die("参数错误");
|
|
|
|
|
|
|
|
|
|
$this->date = $month;
|
|
|
|
|
$tarry = explode('-',$month);
|
|
|
|
|
$this->beginThismonth=mktime(0,0,0,$tarry[1],1,$tarry[0]);
|
|
|
|
|
$this->endThismonth=mktime(0,0,0,$tarry[1]-0+1,1,$tarry[0])-1;
|
|
|
|
|
//判断是否已经聚合
|
|
|
|
|
$countRes = M("spend_count","tab_")->field("count(*) date_count")->where("count_date = '{$this->date}'")->find()['date_count'];
|
|
|
|
|
$countUserRes = M("spend_user_count","tab_")->field("count(*) date_count")->where("count_date = '{$this->date}'")->find()['date_count'];
|
|
|
|
|
if($countRes > 0 || $countUserRes >0){
|
|
|
|
|
die("error:Repeated statistics");
|
|
|
|
|
}
|
|
|
|
|
die("success");
|
|
|
|
|
|
|
|
|
|
$this->model->startTrans();
|
|
|
|
|
$this->usermodel->startTrans();
|
|
|
|
|
$this->continue =true;
|
|
|
|
|
//执行游戏表统计
|
|
|
|
|
$this->setGameCount();
|
|
|
|
|
//执行用户表统计
|
|
|
|
|
$this->setUserCount();
|
|
|
|
|
//执行
|
|
|
|
|
$this->model->commit();
|
|
|
|
|
$this->usermodel->commit();
|
|
|
|
|
|
|
|
|
|
$t2 = microtime(true);
|
|
|
|
|
die("success runtime:".round($t2-$t1,3).'s');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 每个月的统计接口
|
|
|
|
|
*/
|
|
|
|
|
public function setSpendCount()
|
|
|
|
|
{
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
$t1 = microtime(true);
|
|
|
|
|
//判断是否已经聚合
|
|
|
|
|
$countRes = M("spend_count","tab_")->field("count(*) date_count")->where("count_date = '{$this->date}'")->find()['date_count'];
|
|
|
|
|
$countUserRes = M("spend_user_count","tab_")->field("count(*) date_count")->where("count_date = '{$this->date}'")->find()['date_count'];
|
|
|
|
@ -84,7 +83,9 @@ class SpendCountSetController extends \Think\Controller
|
|
|
|
|
//执行
|
|
|
|
|
$this->model->commit();
|
|
|
|
|
$this->usermodel->commit();
|
|
|
|
|
die("success");
|
|
|
|
|
|
|
|
|
|
$t2 = microtime(true);
|
|
|
|
|
die("success runtime:".round($t2-$t1,3).'s');
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 获取游戏聚合
|
|
|
|
|