优化财务聚合接口

master
chenzhi 5 years ago
parent f44a11a915
commit 58c405e914

@ -23,6 +23,7 @@ class SpendCountSetController extends \Think\Controller
$this->model =M("spend_count",'tab_'); $this->model =M("spend_count",'tab_');
$this->usermodel =M("spend_user_count",'tab_'); $this->usermodel =M("spend_user_count",'tab_');
$this->monthmodel =M("spend_month_count",'tab_'); $this->monthmodel =M("spend_month_count",'tab_');
$this->gamemodel =M("spend_count",'tab_');
} }
/** /**
@ -101,147 +102,89 @@ class SpendCountSetController extends \Think\Controller
$this->getRoot(); $this->getRoot();
# code... # code...
} }
//获取游戏现金流水 //获取游戏现金流水
protected function getCashData() protected function getCashData()
{ {
if(!$this->continue){ $this->createGameCount("cash_count");
die("api error"); }
} //获取平台币聚合
$map = array( protected function getBalanceData()
"pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)), {
"spend.pay_status"=>1, $this->createGameCount("balance_coin_count");
"pay_way"=>array("GT",0) }
); //获取绑定币充值
$field = "IFNULL(game.partner_id,0) partner_id,partner.partner partner_name, protected function getInsideData()
spend.promote_id,spend.promote_account,spend.game_id,spend.game_name, {
IFNULL(promote.parent_id,0) parent_id,promote.parent_name,sum(pay_amount) cash_count, $this->createGameCount("inside_cash_count");
'{$this->date}' as count_date,'{$this->nowdata}' as create_time";
//获取现金
$cashRes = M()
->table("tab_spend spend")
->field($field)
->where($map)
->join("tab_promote promote ON spend.promote_id = promote.id","left")
->join("tab_game game ON spend.game_id = game.id","left")
->join("tab_partner partner ON partner.id = game.partner_id","left")
->group('spend.promote_id,spend.game_id')
->select();
if(!empty($cashRes)){
$dbres = $this->model->addAll($cashRes);
if(!$dbres){
$this->model->rollback();
die("error");
}
}
# code...
}
//获取平台币聚合
protected function getBalanceData()
{
if(!$this->continue){
die("api error");
}
$map = array(
"pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"spend.pay_status"=>1,
"pay_way"=> array("EQ",0)
);
$field = "IFNULL(game.partner_id,0) partner_id,partner.partner partner_name,
spend.promote_id,spend.promote_account,spend.game_id,spend.game_name,
IFNULL(promote.parent_id,0) parent_id,promote.parent_name,sum(pay_amount) balance_coin_count,
'{$this->date}' as count_date,'{$this->nowdata}' as create_time";
$balanceRes = M()
->table("tab_spend spend")
->field($field)
->where($map)
->join("tab_promote promote ON spend.promote_id = promote.id","left")
->join("tab_game game ON spend.game_id = game.id","left")
->join("tab_partner partner ON partner.id = game.partner_id","left")
->group('spend.promote_id,spend.game_id')
->select();
//集中两个表
if(!empty($balanceRes)){
for ($i=0; $i < count($balanceRes); $i++) { }
# code... protected function createGameCount($type)
$tempmap = array( {
"game_id"=>$balanceRes[$i]['game_id'], $map = array(
"promote_id"=>$balanceRes[$i]['promote_id'], "pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"count_date"=>$this->date "spend.pay_status"=>1
); );
$dbres = $this->model->where($tempmap)->find();
if(!$dbres){
//不存在
$tempdbres = $this->model->add($balanceRes[$i]);
if(!$tempdbres){
$this->model->rollback();
die("error");
}
}else{
$dbres["balance_coin_count"] = $balanceRes[$i]['balance_coin_count'];
$tempdbres = $this->model->save($dbres);
if(!$tempdbres){
$this->model->rollback();
die("error");
}
}
}
}
# code...
}
//获取绑定币充值
protected function getInsideData()
{
if(!$this->continue){
die("api error");
}
$map = array(
"pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"spend.pay_status"=>1,
"pay_way"=> array("LT",0)
);
$field = "IFNULL(game.partner_id,0) partner_id,partner.partner partner_name,
spend.promote_id,spend.promote_account,spend.game_id,spend.game_name,
IFNULL(promote.parent_id,0) parent_id,promote.parent_name,sum(pay_amount) inside_cash_count,
'{$this->date}' as count_date,'{$this->nowdata}' as create_time";
$balanceRes = M()
->table("tab_spend spend")
->field($field)
->where($map)
->join("tab_promote promote ON spend.promote_id = promote.id","left")
->join("tab_game game ON spend.game_id = game.id","left")
->join("tab_partner partner ON partner.id = game.partner_id","left")
->group('spend.promote_id,spend.game_id')
->select();
//集中两个表
if(!empty($balanceRes)){
for ($i=0; $i < count($balanceRes); $i++) { if($type == "cash_count"){
# code... //现金统计
$tempmap = array( $map['pay_way'] = array("GT",0);
"game_id"=>$balanceRes[$i]['game_id'], }elseif($type == "balance_coin_count"){
"promote_id"=>$balanceRes[$i]['promote_id'], $map['pay_way']= array("EQ",0);
"count_date"=>$this->date }elseif($type == "inside_cash_count"){
); $map['pay_way']= array("LT",0);
$dbres = $this->model->where($tempmap)->find(); }
if(!$dbres){ $field = "IFNULL(game.partner_id,0) partner_id,partner.partner partner_name,
//不存在 spend.promote_id,spend.promote_account,spend.game_id,spend.game_name,sum(pay_amount) {$type},
$tempdbres = $this->model->add($balanceRes[$i]); IFNULL(promote.parent_id,0) parent_id,promote.parent_name,
if(!$tempdbres){ '{$this->date}' as count_date,'{$this->nowdata}' as create_time";
$this->model->rollback(); $spendRes = M()
die("error"); ->table("tab_spend spend")
} ->field($field)
}else{ ->where($map)
$dbres["inside_cash_count"] = $balanceRes[$i]['inside_cash_count']; ->join("tab_promote promote ON spend.promote_id = promote.id","left")
$tempdbres = $this->model->save($dbres); ->join("tab_game game ON spend.game_id = game.id","left")
if(!$tempdbres){ ->join("tab_partner partner ON partner.id = game.partner_id","left")
$this->model->rollback(); ->group('spend.promote_id,spend.game_id')
die("error"); ->select();
} if(empty($spendRes)){
} return ;
} }
} //集中两个表
} if($type == "cash_count"){
$dbres = $this->gamemodel->addAll($spendRes);
if(!$dbres){
$this->model->rollback();
die("error");
}
}else{
for ($i=0; $i < count($spendRes); $i++) {
$spendRes[$i][$type] || $spendRes[$i][$type]=0;
# code...
$tempmap = array(
"game_id"=>$spendRes[$i]['game_id'],
"promote_id"=>$spendRes[$i]['promote_id'],
"count_date"=>$this->date
);
$dbres = $this->gamemodel->where($tempmap)->find();
if(!$dbres){
//不存在
$tempdbres = $this->gamemodel->add($spendRes[$i]);
if(!$tempdbres){
$this->model->rollback();
die("error");
}
}else{
$dbres[$type] = $dbres[$type]-0+$spendRes[$i][$type];
$tempdbres = $this->gamemodel->save($dbres);
if($tempdbres === false){
$this->model->rollback();
die("error");
}
}
}
}
# code...
}
protected function getRoot() protected function getRoot()
{ {
@ -252,7 +195,7 @@ class SpendCountSetController extends \Think\Controller
"parent_id"=>array("GT",0), "parent_id"=>array("GT",0),
"count_date"=>$this->date "count_date"=>$this->date
); );
$user = $this->model->field("parent_id,promote_id")->where($map)->group("promote_id")->select(); $user = $this->gamemodel->field("parent_id,promote_id")->where($map)->group("promote_id")->select();
$Promote=M("promote","tab_"); $Promote=M("promote","tab_");
for ($i=0; $i < count($user); $i++) { for ($i=0; $i < count($user); $i++) {
# code... # code...
@ -267,7 +210,7 @@ class SpendCountSetController extends \Think\Controller
"promote_id"=>$user[$i]['promote_id'], "promote_id"=>$user[$i]['promote_id'],
"count_date"=>$this->date "count_date"=>$this->date
); );
$tempdbres = $this->model->where($where)->save($root); $tempdbres = $this->gamemodel->where($where)->save($root);
if(!$tempdbres){ if(!$tempdbres){
$this->model->rollback(); $this->model->rollback();
die("setRoot error"); die("setRoot error");

Loading…
Cancel
Save