master
chenzhi 5 years ago
parent da1686fe14
commit 4f7077a3ec

@ -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 getBingData() public function getInsideData()
{ {
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)
->join("tab_partner partner ON partner.id = game.partner_id","left") ->where($map)
->group('bind.promote_id,bind.game_id') ->join("tab_promote promote ON spend.promote_id = promote.id","left")
->select(); ->join("tab_game game ON spend.game_id = game.id","left")
//聚合表 ->join("tab_partner partner ON partner.id = game.partner_id","left")
if(!empty($bindRes)){ ->group('spend.promote_id,spend.game_id')
for ($i=0; $i < count($bindRes); $i++) { ->select();
//集中两个表
if(!empty($balanceRes)){
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($bindRes[$i]); $tempdbres = $this->model->add($balanceRes[$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->getUserInsideData();
} }
/** --------以下为辅助函数---------- **/ /** --------以下为辅助函数---------- **/
@ -424,21 +385,20 @@ class SpendCountSetController extends \Think\Controller
} }
# code... # code...
} }
//处理inside_cash_count //渠道角色统计仅计算推广员的平台币发放与收回
public function getInsideData2() public function getUserInsideData()
{ {
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...
}
} }

@ -205,8 +205,7 @@ CREATE TABLE `tab_spend_count` (
`partner_name` varchar(50) DEFAULT NULL COMMENT '合作方名称', `partner_name` varchar(50) DEFAULT NULL COMMENT '合作方名称',
`cash_count` decimal(10,2) DEFAULT '0.00' COMMENT '现金流水', `cash_count` decimal(10,2) DEFAULT '0.00' COMMENT '现金流水',
`balance_coin_count` decimal(10,2) DEFAULT '0.00' COMMENT '平台币流水', `balance_coin_count` decimal(10,2) DEFAULT '0.00' COMMENT '平台币流水',
`bind_coin_count` decimal(10,2) DEFAULT '0.00' COMMENT '绑定币流水', `inside_cash_count` decimal(10,2) DEFAULT '0.00' COMMENT '内充流水/绑定币流水',
`inside_cash_count` decimal(10,2) DEFAULT '0.00' COMMENT '内充流水(仅对用户与月份唯一)',
`count_date` varchar(30) DEFAULT '' COMMENT '统计月份', `count_date` varchar(30) DEFAULT '' COMMENT '统计月份',
`create_time` int(11) DEFAULT NULL COMMENT '添加时间', `create_time` int(11) DEFAULT NULL COMMENT '添加时间',
PRIMARY KEY (`id`) USING BTREE, PRIMARY KEY (`id`) USING BTREE,
@ -227,11 +226,23 @@ CREATE TABLE `tab_spend_user_count` (
`cash_count` decimal(10,2) DEFAULT '0.00' COMMENT '现金流水', `cash_count` decimal(10,2) DEFAULT '0.00' COMMENT '现金流水',
`balance_coin_count` decimal(10,2) DEFAULT '0.00' COMMENT '平台币流水', `balance_coin_count` decimal(10,2) DEFAULT '0.00' COMMENT '平台币流水',
`inside_cash_count` decimal(10,2) DEFAULT '0.00' COMMENT '内充流水', `inside_cash_count` decimal(10,2) DEFAULT '0.00' COMMENT '内充流水',
`all_count` decimal(10,2) DEFAULT '0.00' COMMENT '内充流水', `all_count` decimal(10,2) DEFAULT '0.00' COMMENT '流水',
`count_date` varchar(30) DEFAULT '' COMMENT '统计月份', `count_date` varchar(30) DEFAULT '' COMMENT '统计月份',
`create_time` int(11) DEFAULT NULL COMMENT '添加时间', `create_time` int(11) DEFAULT NULL COMMENT '添加时间',
PRIMARY KEY (`id`) USING BTREE, PRIMARY KEY (`id`) USING BTREE,
KEY `promote_id` (`promote_id`) USING BTREE, KEY `promote_id` (`promote_id`) USING BTREE,
KEY `parent_id` (`parent_id`) USING BTREE, KEY `parent_id` (`parent_id`) USING BTREE,
KEY `count_date` (`count_date`) USING BTREE KEY `count_date` (`count_date`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='流水角色聚合表'; ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='流水角色聚合表';
CREATE TABLE `tab_spend_month_count` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键',
`cash_count` decimal(10,2) DEFAULT '0.00' COMMENT '现金流水',
`balance_coin_count` decimal(10,2) DEFAULT '0.00' COMMENT '平台币流水',
`inside_cash_count` decimal(10,2) DEFAULT '0.00' COMMENT '内充流水',
`all_count` decimal(10,2) DEFAULT '0.00' COMMENT '流水和',
`count_date` varchar(30) DEFAULT '' COMMENT '统计月份',
`create_time` int(11) DEFAULT NULL COMMENT '添加时间',
PRIMARY KEY (`id`) USING BTREE,
KEY `count_date` (`count_date`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='流水月份聚合表';
Loading…
Cancel
Save