新增强制更新某月份

master
chenzhi 5 years ago
parent e0857168f8
commit 2983f5b93f

@ -24,50 +24,49 @@ class SpendCountSetController extends \Think\Controller
$this->usermodel =M("spend_user_count",'tab_'); $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']; set_time_limit(0);
if($countRes > 0){ $t1 = microtime(true);
die("init error");
} $month = I("count_date");
$nowdate = date('Y')."-".(date('m') > 9 ? date('m') : "0".date('m')); if(empty($month)) die("参数错误");
// $nowdate = "2017-10";
//获取所有的月份 pay_time $this->date = $month;
$res = M("spend",'tab_')->field("FROM_UNIXTIME(pay_time,'%Y-%m') AS pay_time")->buildSql(); $tarry = explode('-',$month);
$res = M()->table($res.' a')->group('pay_time')->select(); $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;
for ($i=0; $i < count($res); $i++) { //判断是否已经聚合
# code... $countRes = M("spend_count","tab_")->field("count(*) date_count")->where("count_date = '{$this->date}'")->find()['date_count'];
if($res[$i]['pay_time'] != $nowdate){ $countUserRes = M("spend_user_count","tab_")->field("count(*) date_count")->where("count_date = '{$this->date}'")->find()['date_count'];
//设定初始时间 if($countRes > 0 || $countUserRes >0){
$month = $res[$i]['pay_time']; die("error:Repeated statistics");
$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();
}
} }
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() 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']; $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']; $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->model->commit();
$this->usermodel->commit(); $this->usermodel->commit();
die("success");
$t2 = microtime(true);
die("success runtime:".round($t2-$t1,3).'s');
} }
/** /**
* 获取游戏聚合 * 获取游戏聚合

Loading…
Cancel
Save