聚合新增月份

master
chenzhi 5 years ago
parent af05f08689
commit 8796458ead

@ -60,6 +60,8 @@ class SpendCountSetController extends \Think\Controller
$this->setGameCount();
//执行用户表统计
$this->setUserCount();
//执行月份统计
$this->setMonthCount();
//执行
$this->model->commit();
$this->usermodel->commit();
@ -74,7 +76,6 @@ class SpendCountSetController extends \Think\Controller
{
$this->getCashData();
$this->getBalanceData();
// $this->getBingData();
$this->getInsideData();
$this->getRoot();
# code...
@ -252,6 +253,8 @@ class SpendCountSetController extends \Think\Controller
}
}
}
/** --------以下为设定角色聚合---------- **/
/**
* 获取角色聚合
*/
@ -264,7 +267,6 @@ class SpendCountSetController extends \Think\Controller
$this->getUserInsideData();
}
/** --------以下为辅助函数---------- **/
//获取会长信息
public function getRootUser()
{
@ -395,140 +397,48 @@ class SpendCountSetController extends \Think\Controller
->field("*")
->where(array(
"create_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"banlan_type"=>1,
"source_id"=>0,
"status"=>1
))
->select();
if(!empty($insideRes)){
for ($i=0; $i < count($insideRes); $i++) {
# code...
$tempmap = array(
"promote_id"=>$insideRes[$i]['promote_id'],
"count_date"=>$this->date
);
$dbres = M("spend_user_count","tab_")->where($tempmap)->find();
//获取等级
if(empty($dbres)){
//不存在
}else{
}
//修正数据
if($dbres['root_id'] > 0 && $dbres['parent_id'] > 0){//是推广员
//修正root
$this->setInsideCount($dbres['root_id'],$insideRes[$i]['inside_cash_count']);
//修正Parent
$this->setInsideCount($dbres['parent_id'],$insideRes[$i]['inside_cash_count']);
//修正自己
$this->setInsideCount($dbres['promote_id'],$insideRes[$i]['inside_cash_count']);
}elseif($dbres['root_id'] == 0 && $dbres['parent_id'] > 0){//是组长
//修正root
$this->setInsideCount($dbres['parent_id'],$insideRes[$i]['inside_cash_count']);
//修正Parent
$this->setInsideCount($dbres['promote_id'],$insideRes[$i]['inside_cash_count']);
}else{//是会长
//修正root
$this->setInsideCount($dbres['promote_id'],$insideRes[$i]['inside_cash_count']);
if($insideRes[$i]['type'] > 1){
$insideRes[$i]['num'] = ( 0- $insideRes[$i]['num']);
}
$this->createUserCount($insideRes[$i]['promote_id'],$insideRes[$i]['num']);
}
}
// $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")
// ->where(array(
// "deposit.create_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
// "pay_status"=>1
// ))
// ->join("tab_promote promote ON deposit.promote_id = promote.id","left")
// ->group('promote_id')
// ->select();
// //聚合表
// if(!empty($insideRes)){
// for ($i=0; $i < count($insideRes); $i++) {
// # code...
// $tempmap = array(
// "promote_id"=>$insideRes[$i]['promote_id'],
// "count_date"=>$this->date
// );
// $dbres = M("spend_user_count","tab_")->where($tempmap)->find();
// //修正数据
// if($dbres['root_id'] > 0 && $dbres['parent_id'] > 0){//是推广员
// //修正root
// $this->setInsideCount($dbres['root_id'],$insideRes[$i]['inside_cash_count']);
// //修正Parent
// $this->setInsideCount($dbres['parent_id'],$insideRes[$i]['inside_cash_count']);
// //修正自己
// $this->setInsideCount($dbres['promote_id'],$insideRes[$i]['inside_cash_count']);
// }elseif($dbres['root_id'] == 0 && $dbres['parent_id'] > 0){//是组长
// //修正root
// $this->setInsideCount($dbres['parent_id'],$insideRes[$i]['inside_cash_count']);
// //修正Parent
// $this->setInsideCount($dbres['promote_id'],$insideRes[$i]['inside_cash_count']);
// }else{//是会长
// //修正root
// $this->setInsideCount($dbres['promote_id'],$insideRes[$i]['inside_cash_count']);
// }
// }
// }
}
//按角色修正inside_cash_count数据
public function setInsideCount($promote_id,$inside_cash_count)
{
$tempmap = array(
"promote_id"=>$promote_id,
"count_date"=>$this->date
);
$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']);
$tempdbres = $this->usermodel->where($tempmap)->save($savedata);
if(!$tempdbres){
$this->usermodel->rollback();
die("setInsideCount error");
}
# code...
}
//建立user表空数据
protected function createUserCount($promote_id,$inside_cash_count)
{
$promote = M("Promote","tab_")->field("id,account,parent_id,parent_name,grand_id,grand_account")->where("id='".$promote_id."'")->find();
if(empty($promote)){
return false;
}
$temprootarr=array(
// "promote_id"=>$promote['id'],
// "promote_account"=>$promote['account'],
"parent_id"=>0,
"root_id"=>0,
"inside_cash_count"=>$inside_cash_count,
"balance_coin_count"=>$subQueryAll[$i]['balance_coin_count'],
"all_count"=>$inside_cash_count,
"count_date"=>$this->date,
"create_time"=>$this->nowdata
);
$tempparentarr=array(
// "promote_id"=>$promote['id'],
// "promote_account"=>$promote['account'],
// "parent_id"=>0,
"root_id"=>0,
"inside_cash_count"=>$inside_cash_count,
"balance_coin_count"=>$subQueryAll[$i]['balance_coin_count'],
"all_count"=>$inside_cash_count,
"count_date"=>$this->date,
"create_time"=>$this->nowdata
);
$temppromotearr=array(
// "promote_id"=>$promote['id'],
// "promote_account"=>$promote['account'],
// "parent_id"=>0,
// "root_id"=>0,
"inside_cash_count"=>$inside_cash_count,
"balance_coin_count"=>$subQueryAll[$i]['balance_coin_count'],
"all_count"=>$inside_cash_count,
"count_date"=>$this->date,
"create_time"=>$this->nowdata
@ -536,13 +446,170 @@ class SpendCountSetController extends \Think\Controller
if($promote["parent_id"] == 0){
//会长
$temprootarr["promote_id"]= $promote['id'];
$temprootarr["promote_account"]= $promote['account'];
$this->usermodel->add($temprootarr);
$dbres = M("spend_user_count","tab_")->where(array(
"promote_id"=>$promote["id"],
"count_date"=>$this->date
))->find();
if(empty($dbres)){
$temprootarr["promote_id"]= $promote['id'];
$temprootarr["promote_account"]= $promote['account'];
$this->usermodel->add($temprootarr);
}else{
//叠加
$this->setInsideCount($promote['id'],$inside_cash_count);
}
}elseif($promote["parent_id"] > 0 && $promote["grand_id"] == 0){
//组长
//是组长
//添加会长
$dbres = M("spend_user_count","tab_")->where(array(
"promote_id"=>$promote["parent_id"],
"count_date"=>$this->date
))->find();
if(empty($dbres)){
$temprootarr["promote_id"]= $promote['parent_id'];
$temprootarr["promote_account"]= $promote['parent_name'];
$this->usermodel->add($temprootarr);
}else{
//叠加
$this->setInsideCount($promote['parent_id'],$inside_cash_count);
}
//添加自己
$dbres = M("spend_user_count","tab_")->where(array(
"promote_id"=>$promote["id"],
"count_date"=>$this->date
))->find();
if(empty($dbres)){
$tempparentarr['promote_id']=$promote['id'];
$tempparentarr['promote_account']=$promote['account'];
$tempparentarr['parent_id']=$promote["parent_id"];
$tempparentarr['parent_name']=$promote["parent_name"];
$this->usermodel->add($tempparentarr);
}else{
//叠加
$this->setInsideCount($promote['id'],$inside_cash_count);
}
}else{
//推广员
//添加会长
$dbres = M("spend_user_count","tab_")->where(array(
"promote_id"=>$promote["grand_id"],
"count_date"=>$this->date
))->find();
if(empty($dbres)){
$temprootarr["promote_id"]= $promote['grand_id'];
$temprootarr["promote_account"]= $promote['grand_account'];
$this->usermodel->add($temprootarr);
}else{
//叠加
$this->setInsideCount($promote['grand_id'],$inside_cash_count);
}
//添加组长
$dbres = M("spend_user_count","tab_")->where(array(
"promote_id"=>$promote["parent_id"],
"count_date"=>$this->date
))->find();
if(empty($dbres)){
$tempparentarr["promote_id"]= $promote['parent_id'];
$tempparentarr["promote_account"]= $promote['parent_name'];
$tempparentarr['parent_id']=$promote["grand_id"];
$tempparentarr['parent_name']=$promote["grand_account"];
$this->usermodel->add($tempparentarr);
}else{
//叠加
$this->setInsideCount($promote['parent_id'],$inside_cash_count);
}
$dbres = M("spend_user_count","tab_")->where(array(
"promote_id"=>$promote["id"],
"count_date"=>$this->date
))->find();
if(empty($dbres)){
$temppromotearr['promote_id']=$promote['id'];
$temppromotearr['promote_account']=$promote['account'];
$temppromotearr['parent_id']=$promote["parent_id"];
$temppromotearr['parent_name']=$promote["parent_name"];
$temppromotearr['root_id']=$promote['grand_id'];
$temppromotearr['root_name']=$promote['grand_account'];
$this->usermodel->add($temppromotearr);
}else{
//叠加
$this->setInsideCount($promote['id'],$inside_cash_count);
}
//添加自己
}
# code...
}
//按角色修正inside_cash_count数据
public function setInsideCount($promote_id,$inside_cash_count)
{
$tempmap = array(
"promote_id"=>$promote_id,
"count_date"=>$this->date
);
$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']);
$tempdbres = $this->usermodel->where($tempmap)->save($savedata);
if($tempdbres === false){
dump($dbres);
dump($savedata);
$this->usermodel->rollback();
die("setInsideCount error");
}
# code...
}
/** --------以下为设定月份聚合---------- **/
public function setMonthCount()
{
$initdata = $this->getMonthInit();
$balance = $this->getBalanceUser();
$bind = $this->getBindUser();
$initdata["inside_cash_count"] = $initdata["inside_cash_count"]-$balance-$bind;
$initdata["all_count"] = $initdata["inside_cash_count"]-0+$initdata["balance_coin_count"]-0+$initdata["cash_count"];
$initdata["count_date"] = $this->date;
$initdata["create_time"] = $this->nowdata;
M("spend_month_count","tab_")->add($initdata);
# code...
}
//获取除了内充的
protected function getMonthInit()
{
$tempmap = array(
"count_date"=>$this->date,
"parent_id"=>0
);
return M("spend_user_count","tab_")->field("sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count")->where($tempmap)->find();
}
//设置 后台发放平台币给玩家 及 回收玩家 的最终值
protected function getBalanceUser()
{
$map = array(
"create_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
);
$add = M("provide_user","tab_")->field("sum(amount) amount")->where($map)->find()['amount'];
$add || $add=0;
$jq = M("user_coin","tab_")->field("sum(num) num")->where($map)->find()['num'];
$jq || $jq=0;
return $add-$jq;
}
//设置 后台发放绑币给玩家 及 回收玩家绑币 的最终值
protected function getBindUser()
{
$map = array(
"create_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
);
$add = M("provide","tab_")->field("sum(amount) amount")->where($map)->find()['amount'];
$add || $add=0;
$jq = M("deduct_bind_record","tab_")->field("sum(quantity) quantity")->where($map)->find()['quantity'];
$jq || $jq=0;
return $add-$jq;
}
}

Loading…
Cancel
Save