优化接口终结

master
chenzhi 5 years ago
parent cce64d646b
commit e0857168f8

@ -12,6 +12,7 @@ class SpendCountSetController extends \Think\Controller
public $date;
public $nowdata;
public $model;
public $usermodel;
public $continue=false;//单元测试,开启后可访问独立函数测试
public function _initialize(){
//初始化
@ -20,6 +21,7 @@ class SpendCountSetController extends \Think\Controller
$this->date = date('Y')."-".((date('m')-1) > 9 ? (date('m')-1) : "0".(date('m')-1));
$this->nowdata =time();
$this->model =M("spend_count",'tab_');
$this->usermodel =M("spend_user_count",'tab_');
}
/**
* 初始化统计/用于之前数据的聚合
@ -31,7 +33,7 @@ class SpendCountSetController extends \Think\Controller
die("init error");
}
$nowdate = date('Y')."-".(date('m') > 9 ? date('m') : "0".date('m'));
$nowdate = "2017-10";
// $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();
@ -39,23 +41,23 @@ class SpendCountSetController extends \Think\Controller
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->getCashData();
$this->getBalanceData();
$this->getBingData();
$this->getInsideData();
$this->setRoot();
//执行游戏表统计
$this->setGameCount();
//执行用户表统计
$this->setUserCount();
$this->model->commit();
$this->usermodel->commit();
}
}
die("success");
@ -68,22 +70,34 @@ class SpendCountSetController extends \Think\Controller
{
//判断是否已经聚合
$countRes = M("spend_count","tab_")->field("count(*) date_count")->where("count_date = '{$this->date}'")->find()['date_count'];
if($countRes > 0){
die("Repeated statistics");
$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");
}
$this->model->startTrans();
$this->usermodel->startTrans();
$this->continue =true;
$this->getCashData();
$this->getBalanceData();
$this->getBingData();
$this->getInsideData();
$this->setRoot();
//执行游戏表统计
$this->setGameCount();
//执行用户表统计
$this->setUserCount();
//执行
$this->model->commit();
$this->usermodel->commit();
die("success");
}
/**
* 获取游戏聚合
*/
public function setGameCount()
{
$this->getCashData();
$this->getBalanceData();
$this->getBingData();
$this->getInsideData();
$this->getRoot();
# code...
}
//获取游戏现金流水
public function getCashData()
{
@ -265,7 +279,7 @@ class SpendCountSetController extends \Think\Controller
}
// return true;
}
public function setRoot()
public function getRoot()
{
if(!$this->continue){
die("api error");
@ -312,6 +326,7 @@ class SpendCountSetController extends \Think\Controller
//获取会长信息
public function getRootUser()
{
if(!$this->continue) die("api error");
//获取所有数据
$month = $this->date;
$from = "
@ -342,13 +357,18 @@ class SpendCountSetController extends \Think\Controller
"count_date"=>$this->date,
"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()
{
if(!$this->continue) die("api error");
$month =$this->date;
//获取数据
$from = "
@ -377,13 +397,18 @@ class SpendCountSetController extends \Think\Controller
"count_date"=>$this->date,
"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()
{
if(!$this->continue) die("api error");
$month = $this->date;;
//获取数据
$from = "
@ -410,14 +435,18 @@ class SpendCountSetController extends \Think\Controller
"count_date"=>$this->date,
"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...
}
//处理inside_cash_count
public function getInsideData2()
{
if(!$this->continue) die("api error");
$insideRes = M()
->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")
@ -469,7 +498,11 @@ class SpendCountSetController extends \Think\Controller
);
$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']);
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...
}

Loading…
Cancel
Save