@ -74,7 +74,7 @@ class SpendCountSetController extends \Think\Controller
{
{
$this->getCashData();
$this->getCashData();
$this->getBalanceData();
$this->getBalanceData();
$this->getBingData();
// $this->getBingData();
$this->getInsideData();
$this->getInsideData();
$this->getRoot();
$this->getRoot();
# code...
# code...
@ -122,7 +122,7 @@ class SpendCountSetController extends \Think\Controller
$map = array(
$map = array(
"pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"spend.pay_status"=>1,
"spend.pay_status"=>1,
"pay_way"=> array("LT",1 )
"pay_way"=> array("EQ",0 )
);
);
$field = "IFNULL(game.partner_id,0) partner_id,partner.partner partner_name,
$field = "IFNULL(game.partner_id,0) partner_id,partner.partner partner_name,
spend.promote_id,spend.promote_account,spend.game_id,spend.game_name,
spend.promote_id,spend.promote_account,spend.game_id,spend.game_name,
@ -168,29 +168,33 @@ class SpendCountSetController extends \Think\Controller
# code...
# code...
}
}
//获取绑定币充值
//获取绑定币充值
public function getBing Data()
public function getInside Data()
{
{
if(!$this->continue){
if(!$this->continue){
die("api error");
die("api error");
}
}
$bindRes = M()
$map = array(
->table("tab_bind_recharge bind")
"pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
->field("IFNULL(game.partner_id,0) partner_id,partner.partner partner_name,
"spend.pay_status"=>1,
bind.game_id,bind.game_name,bind.promote_id,bind.promote_account,
"pay_way"=> array("LT",0)
IFNULL(promote.parent_id,0) parent_id,promote.parent_name,sum(real_amount) bind_coin_count,
);
'{$this->date}' as count_date,'{$this->nowdata}' as create_time")
$field = "IFNULL(game.partner_id,0) partner_id,partner.partner partner_name,
->where(array(
spend.promote_id,spend.promote_account,spend.game_id,spend.game_name,
"bind.create_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
IFNULL(promote.parent_id,0) parent_id,promote.parent_name,sum(pay_amount) inside_cash_count,
"bind.pay_status"=>1
'{$this->date}' as count_date,'{$this->nowdata}' as create_time";
))
$balanceRes = M()
->join("tab_promote promote ON bind.promote_id = promote.id","left")
->table("tab_spend spend")
->join("tab_game game ON bind.game_id = game.id","left")
->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")
->join("tab_partner partner ON partner.id = game.partner_id","left")
->group('bind.promote_id,bind.game_id')
->group('spend.promote_id,spe nd.game_id')
->select();
->select();
//聚合表
//集中两个表
if(!empty($bindRes)){
if(!empty($balanceRes)){
for ($i=0; $i < count ( $ bindRes ) ; $ i + + ) {
for ($i=0; $i < count ( $ balanceRes ) ; $ i + + ) {
# code...
# code...
$tempmap = array(
$tempmap = array(
"game_id"=>$balanceRes[$i]['game_id'],
"game_id"=>$balanceRes[$i]['game_id'],
@ -200,13 +204,13 @@ class SpendCountSetController extends \Think\Controller
$dbres = $this->model->where($tempmap)->find();
$dbres = $this->model->where($tempmap)->find();
if(!$dbres){
if(!$dbres){
//不存在
//不存在
$tempdbres =$this->model->add($bind Res[$i]);
$tempdbres = $this->model->add($balance Res[$i]);
if(!$tempdbres){
if(!$tempdbres){
$this->model->rollback();
$this->model->rollback();
die("error");
die("error");
}
}
}else{
}else{
$dbres["bind_coin_count"] = $bindRes[$i]['bind_coin _count'];
$dbres["inside_cash_count"] = $balanceRes[$i]['inside_cash _count'];
$tempdbres = $this->model->save($dbres);
$tempdbres = $this->model->save($dbres);
if(!$tempdbres){
if(!$tempdbres){
$this->model->rollback();
$this->model->rollback();
@ -216,50 +220,7 @@ class SpendCountSetController extends \Think\Controller
}
}
}
}
}
}
//获取内充流水
public function getInsideData()
{
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")
->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 = $this->model->where($tempmap)->find();
if(!$dbres){
//不存在
$tempdbres = $this->model->add($insideRes[$i]);
if(!$tempdbres){
$this->model->rollback();
die("error");
}
}else{
$savedata = array("inside_cash_count"=>$insideRes[$i]['inside_cash_count']);
$tempdbres = $this->model->where($tempmap)->save($savedata);
if(!$tempdbres){
$this->model->rollback();
die("error");
}
}
}
}
// return true;
}
public function getRoot()
public function getRoot()
{
{
if(!$this->continue){
if(!$this->continue){
@ -300,7 +261,7 @@ class SpendCountSetController extends \Think\Controller
$this->getRootUser();
$this->getRootUser();
$this->getParentUser();
$this->getParentUser();
$this->getPromoteUser();
$this->getPromoteUser();
$this->getInsideData2 ();
$this->getUser InsideData();
}
}
/** --------以下为辅助函数---------- **/
/** --------以下为辅助函数---------- **/
@ -424,21 +385,20 @@ class SpendCountSetController extends \Think\Controller
}
}
# code...
# code...
}
}
//处理inside_cash_count
//渠道角色统计仅计算推广员的平台币发放与收回
public function getInsideData2 ()
public function getUser InsideData()
{
{
if(!$this->continue) die("api error");
// if(!$this->continue) die("api error");
//获取发送给推广员的数据
$insideRes = M()
$insideRes = M()
->table("tab_deposit deposit ")
->table("tab_promote_coin ")
->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("* ")
->where(array(
->where(array(
"deposit.create_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"create_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"pay_status"=>1
"banlan_type"=>1,
"status"=>1
))
))
->join("tab_promote promote ON deposit.promote_id = promote.id","left")
->group('promote_id')
->select();
->select();
//聚合表
if(!empty($insideRes)){
if(!empty($insideRes)){
for ($i=0; $i < count ( $ insideRes ) ; $ i + + ) {
for ($i=0; $i < count ( $ insideRes ) ; $ i + + ) {
# code...
# code...
@ -447,6 +407,13 @@ class SpendCountSetController extends \Think\Controller
"count_date"=>$this->date
"count_date"=>$this->date
);
);
$dbres = M("spend_user_count","tab_")->where($tempmap)->find();
$dbres = M("spend_user_count","tab_")->where($tempmap)->find();
//获取等级
if(empty($dbres)){
//不存在
}else{
}
//修正数据
//修正数据
if($dbres['root_id'] > 0 & & $dbres['parent_id'] > 0){//是推广员
if($dbres['root_id'] > 0 & & $dbres['parent_id'] > 0){//是推广员
//修正root
//修正root
@ -468,7 +435,49 @@ class SpendCountSetController extends \Think\Controller
}
}
}
}
// return true;
// $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数据
//按角色修正inside_cash_count数据
public function setInsideCount($promote_id,$inside_cash_count)
public function setInsideCount($promote_id,$inside_cash_count)
@ -486,5 +495,54 @@ class SpendCountSetController extends \Think\Controller
}
}
# code...
# 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();
$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
);
if($promote["parent_id"] == 0){
//会长
$temprootarr["promote_id"]= $promote['id'];
$temprootarr["promote_account"]= $promote['account'];
$this->usermodel->add($temprootarr);
}elseif($promote["parent_id"] > 0 & & $promote["grand_id"] == 0){
//组长
}
# code...
}
}
}