优化游戏及推广员统计

master
chenzhi 5 years ago
parent 44e5ca356a
commit cd9363f9fe

@ -29,55 +29,85 @@ class StatisticsCountSetController extends Controller {
$this->LoginModel =M("user_login_record","tab_");
$this->SpendModel =M("spend","tab_");
$this->PromoteModel =M("promote","tab_");
$this->model =M();
$this->PromoteCountModel =M("PromoteCount","tab_");
$this->GameCountModel =M("GameCount","tab_");
$this->nowdata =time();
$group_concat_max_len = M()->execute("SET SESSION group_concat_max_len = 4294967295");
echo "set group_concat_max_len ok,beging count".PHP_EOL;
if(I("reset")) $this->reset = true;
}
}
public function setChartCount()
{
$begin = date("Y-m-d",strtotime("-1 day"));
$this->setDateCount($begin);
}
public function setFreeDateCount($begin,$end='')
{
if($end == '') $end = $begin;
//判断日期格式
$patten = "/^\d{4}[\-](0?[1-9]|1[012])[\-](0?[1-9]|[12][0-9]|3[01])$/";
if (!preg_match($patten, $begin)) {
die("开始时间格式错误");
}
if (!preg_match($patten, $end)) {
die("结束时间格式错误");
}
if(strtotime($end) < strtotime($begin)){
die("结束时间不能比开始时间小");
}
if(strtotime($end)+86399 > time()){
die("结束时间不能包含今日");
}
if($begin == $end){
$this->setDateCount($begin);
}else{
$starttime = $begin?strtotime($begin):mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endtime = $end?strtotime($end)+86399:$starttime+86399;
$datelist = get_date_list($starttime,$endtime,1);
$countdate = count($datelist);
for($i=0;$i<$countdate;$i++){
$this->setDateCount($datelist[$i]);
}
}
}
public function setDateCount($date)
{
$this->date = $date;
$tarry = explode('-',$date);
$this->beginTime=mktime(0,0,0,$tarry[1],$tarry[2],$tarry[0]);
$this->endTime=mktime(0,0,0,$tarry[1],$tarry[2]-0+1,$tarry[0])-1;
set_time_limit(0);
$t1 = microtime(true);
//判断是否存在
// $res = $this->ChartModel->where("date = '{$this->beginTime}'")->find();
// $reset='';
// if(!empty($res)){
// if($this->reset){
// $this->ChartModel->where("date = '{$this->beginTime}'")->delete();
// $reset = "reset and creat ";
// }else{
// echo ("{$this->date} 已统计,请勿重复提交".PHP_EOL);
// return;
// }
// }
$group_concat_max_len = M()->query("show variables like 'group_concat_max_len'")[0]['value'];
if($group_concat_max_len < 102400){
echo ("请".PHP_EOL);
$PromoteRes = $this->PromoteCountModel->where("date = '{$this->beginTime}'")->find();
$GameRes = $this->GameCountModel->where("date = '{$this->beginTime}'")->find();
$reset='';
if(!empty($PromoteRes) || !empty($GameRes) ){
if($this->reset){
$this->PromoteCountModel->where("date = '{$this->beginTime}'")->delete();
$this->GameCountModel->where("date = '{$this->beginTime}'")->delete();
$reset = "reset and creat ";
}else{
echo ("{$this->date} 已统计,请勿重复提交".PHP_EOL);
return;
}
}
dump($res);
// $this->promoteNew();
// $this->promotePayMoeny();
// $this->promoteActive();
// $this->promoteCreateDb();
// $this->addid = [];
// $this->adddata = [];
// $this->gameNew();
// $this->gamePayMoeny();
// $this->gameActive();
// $this->gameCreateDb();
$this->model->startTrans();
$this->promoteNew();
$this->promotePayMoeny();
$this->promoteActive();
$this->promoteCreateDb();
$this->addid = [];
$this->adddata = [];
$this->gameNew();
$this->gamePayMoeny();
$this->gameActive();
$this->gameCreateDb();
$this->model->commit();
$t2 = microtime(true);
echo ("{$this->date} {$reset}success runtime:".round($t2-$t1,3).'s'.PHP_EOL);
# code...
@ -149,10 +179,14 @@ class StatisticsCountSetController extends Controller {
$value['date']=$this->beginTime;
$value['create_time']=$this->nowdata;
$value['active_user_list'] = @serialize(explode(",",$value['active_user_list']));
if(empty($value['promote_account'])){
if(empty($value['promote_account']) && $value['promote_id']){
$value['promote_account'] = $this->PromoteModel->field("account")->where("id = {$value['promote_id']}")->find()['account'];
}
$this->PromoteCountModel->add($value);
$tempdbres = $this->PromoteCountModel->add($value);
if($tempdbres === false){
$this->model->rollback();
die("error");
}
}
}
}
@ -222,7 +256,11 @@ class StatisticsCountSetController extends Controller {
$value['date']=$this->beginTime;
$value['create_time']=$this->nowdata;
$value['active_user_list'] = @serialize(explode(",",$value['active_user_list']));
$this->GameCountModel->add($value);
$tempdbres = $this->GameCountModel->add($value);
if($tempdbres === false){
$this->model->rollback();
die("error");
}
}
}
}

Loading…
Cancel
Save