优化接口终结

master
chenzhi 5 years ago
parent cce64d646b
commit e0857168f8

@ -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,6 +21,7 @@ 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_');
} }
/** /**
* 初始化统计/用于之前数据的聚合 * 初始化统计/用于之前数据的聚合
@ -31,7 +33,7 @@ class SpendCountSetController extends \Think\Controller
die("init error"); die("init error");
} }
$nowdate = date('Y')."-".(date('m') > 9 ? date('m') : "0".date('m')); $nowdate = date('Y')."-".(date('m') > 9 ? date('m') : "0".date('m'));
$nowdate = "2017-10"; // $nowdate = "2017-10";
//获取所有的月份 pay_time //获取所有的月份 pay_time
$res = M("spend",'tab_')->field("FROM_UNIXTIME(pay_time,'%Y-%m') AS pay_time")->buildSql(); $res = M("spend",'tab_')->field("FROM_UNIXTIME(pay_time,'%Y-%m') AS pay_time")->buildSql();
$res = M()->table($res.' a')->group('pay_time')->select(); $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++) { for ($i=0; $i < count($res); $i++) {
# code... # code...
if($res[$i]['pay_time'] != $nowdate){ if($res[$i]['pay_time'] != $nowdate){
//设定初始时间
$month = $res[$i]['pay_time']; $month = $res[$i]['pay_time'];
$this->date = $month; $this->date = $month;
$tarry = explode('-',$month); $tarry = explode('-',$month);
$this->beginThismonth=mktime(0,0,0,$tarry[1],1,$tarry[0]); $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->endThismonth=mktime(0,0,0,$tarry[1]-0+1,1,$tarry[0])-1;
//执行 //执行聚合
$this->model->startTrans(); $this->model->startTrans();
$this->usermodel->startTrans();
$this->continue =true; $this->continue =true;
$this->getCashData(); //执行游戏表统计
$this->getBalanceData(); $this->setGameCount();
$this->getBingData();
$this->getInsideData();
$this->setRoot();
//执行用户表统计 //执行用户表统计
$this->setUserCount(); $this->setUserCount();
$this->model->commit(); $this->model->commit();
$this->usermodel->commit();
} }
} }
die("success"); 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']; $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->getCashData(); //执行游戏表统计
$this->getBalanceData(); $this->setGameCount();
$this->getBingData();
$this->getInsideData();
$this->setRoot();
//执行用户表统计 //执行用户表统计
$this->setUserCount(); $this->setUserCount();
//执行
$this->model->commit(); $this->model->commit();
$this->usermodel->commit();
die("success"); die("success");
} }
/**
* 获取游戏聚合
*/
public function setGameCount()
{
$this->getCashData();
$this->getBalanceData();
$this->getBingData();
$this->getInsideData();
$this->getRoot();
# code...
}
//获取游戏现金流水 //获取游戏现金流水
public function getCashData() public function getCashData()
{ {
@ -265,7 +279,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");
@ -312,6 +326,7 @@ class SpendCountSetController extends \Think\Controller
//获取会长信息 //获取会长信息
public function getRootUser() public function getRootUser()
{ {
if(!$this->continue) die("api error");
//获取所有数据 //获取所有数据
$month = $this->date; $month = $this->date;
$from = " $from = "
@ -342,13 +357,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 +397,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 +435,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 +498,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