Merge branch 'dev_zyx' of 47.111.118.107:/srv/git/platform into dev_zyx

master
zyx 5 years ago
commit da1686fe14

@ -12,6 +12,7 @@ class SpendCountSetController extends \Think\Controller
public $date; public $date;
public $nowdata; public $nowdata;
public $model; public $model;
public $usermodel;
public $continue=false;//单元测试,开启后可访问独立函数测试 public $continue=false;//单元测试,开启后可访问独立函数测试
public function _initialize(){ public function _initialize(){
//初始化 //初始化
@ -20,69 +21,63 @@ class SpendCountSetController extends \Think\Controller
$this->date = date('Y')."-".((date('m')-1) > 9 ? (date('m')-1) : "0".(date('m')-1)); $this->date = date('Y')."-".((date('m')-1) > 9 ? (date('m')-1) : "0".(date('m')-1));
$this->nowdata =time(); $this->nowdata =time();
$this->model =M("spend_count",'tab_'); $this->model =M("spend_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']; $month = I("count_date");
if($countRes > 0){ if(empty($month)) die("参数错误");
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->continue =true;
$this->getCashData();
$this->getBalanceData();
$this->getBingData();
$this->getInsideData();
$this->setRoot();
//执行用户表统计
$this->setUserCount();
$this->model->commit(); $this->date = $month;
} $tarry = explode('-',$month);
} $this->beginThismonth=mktime(0,0,0,$tarry[1],1,$tarry[0]);
die("success"); $this->endThismonth=mktime(0,0,0,$tarry[1]-0+1,1,$tarry[0])-1;
$this->setSpendCount();
} }
/** /**
* 每个月的统计接口 * 每个月的统计接口
*/ */
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'];
if($countRes > 0){ $countUserRes = M("spend_user_count","tab_")->field("count(*) date_count")->where("count_date = '{$this->date}'")->find()['date_count'];
die("Repeated statistics"); if($countRes > 0 || $countUserRes >0){
die("error:Repeated statistics");
} }
$this->model->startTrans(); $this->model->startTrans();
$this->usermodel->startTrans();
$this->continue =true; $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 setGameCount()
{
$this->getCashData(); $this->getCashData();
$this->getBalanceData(); $this->getBalanceData();
$this->getBingData(); $this->getBingData();
$this->getInsideData(); $this->getInsideData();
$this->setRoot(); $this->getRoot();
//执行用户表统计 # code...
$this->setUserCount();
$this->model->commit();
die("success");
} }
//获取游戏现金流水 //获取游戏现金流水
public function getCashData() public function getCashData()
@ -265,7 +260,7 @@ class SpendCountSetController extends \Think\Controller
} }
// return true; // return true;
} }
public function setRoot() public function getRoot()
{ {
if(!$this->continue){ if(!$this->continue){
die("api error"); die("api error");
@ -308,10 +303,11 @@ class SpendCountSetController extends \Think\Controller
$this->getInsideData2(); $this->getInsideData2();
} }
/** --------以下为辅助函数--------- **/ /** --------以下为辅助函数---------- **/
//获取会长信息 //获取会长信息
public function getRootUser() public function getRootUser()
{ {
if(!$this->continue) die("api error");
//获取所有数据 //获取所有数据
$month = $this->date; $month = $this->date;
$from = " $from = "
@ -342,13 +338,18 @@ class SpendCountSetController extends \Think\Controller
"count_date"=>$this->date, "count_date"=>$this->date,
"create_time"=>$this->nowdata "create_time"=>$this->nowdata
); );
M("spend_user_count","tab_")->add($adddata); $tempdbres = $this->usermodel->add($adddata);
if(!$tempdbres){
$this->usermodel->rollback();
die("getRootUser error");
}
} }
} }
//获取组长信息 //获取组长信息
public function getParentUser() public function getParentUser()
{ {
if(!$this->continue) die("api error");
$month =$this->date; $month =$this->date;
//获取数据 //获取数据
$from = " $from = "
@ -377,13 +378,18 @@ class SpendCountSetController extends \Think\Controller
"count_date"=>$this->date, "count_date"=>$this->date,
"create_time"=>$this->nowdata "create_time"=>$this->nowdata
); );
M("spend_user_count","tab_")->add($adddata); $tempdbres = $this->usermodel->add($adddata);
if(!$tempdbres){
$this->usermodel->rollback();
die("getParentUser error");
}
} }
} }
//获取组员 //获取组员
public function getPromoteUser() public function getPromoteUser()
{ {
if(!$this->continue) die("api error");
$month = $this->date;; $month = $this->date;;
//获取数据 //获取数据
$from = " $from = "
@ -410,14 +416,18 @@ class SpendCountSetController extends \Think\Controller
"count_date"=>$this->date, "count_date"=>$this->date,
"create_time"=>$this->nowdata "create_time"=>$this->nowdata
); );
M("spend_user_count","tab_")->add($adddata); $tempdbres = $this->usermodel->add($adddata);
if(!$tempdbres){
$this->usermodel->rollback();
die("getPromoteUser error");
}
} }
# code... # code...
} }
//处理inside_cash_count //处理inside_cash_count
public function getInsideData2() public function getInsideData2()
{ {
if(!$this->continue) die("api error");
$insideRes = M() $insideRes = M()
->table("tab_deposit deposit") ->table("tab_deposit deposit")
->field("promote_id,promote_account,IFNULL(promote.parent_id,0) parent_id,parent_name,sum(pay_amount) inside_cash_count,'{$this->date}' as count_date,'{$this->nowdata}' as create_time") ->field("promote_id,promote_account,IFNULL(promote.parent_id,0) parent_id,parent_name,sum(pay_amount) inside_cash_count,'{$this->date}' as count_date,'{$this->nowdata}' as create_time")
@ -469,7 +479,11 @@ class SpendCountSetController extends \Think\Controller
); );
$dbres = M("spend_user_count","tab_")->where($tempmap)->find(); $dbres = M("spend_user_count","tab_")->where($tempmap)->find();
$savedata = array("inside_cash_count"=>$inside_cash_count-0+$dbres['inside_cash_count'],"all_count"=>$inside_cash_count-0+$dbres['all_count']); $savedata = array("inside_cash_count"=>$inside_cash_count-0+$dbres['inside_cash_count'],"all_count"=>$inside_cash_count-0+$dbres['all_count']);
M("spend_user_count","tab_")->where($tempmap)->save($savedata); $tempdbres = $this->usermodel->where($tempmap)->save($savedata);
if(!$tempdbres){
$this->usermodel->rollback();
die("setInsideCount error");
}
# code... # code...
} }

Loading…
Cancel
Save