master
chenzhi 5 years ago
parent da1686fe14
commit 4f7077a3ec

@ -74,7 +74,7 @@ class SpendCountSetController extends \Think\Controller
{
$this->getCashData();
$this->getBalanceData();
$this->getBingData();
// $this->getBingData();
$this->getInsideData();
$this->getRoot();
# code...
@ -122,7 +122,7 @@ class SpendCountSetController extends \Think\Controller
$map = array(
"pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"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,
spend.promote_id,spend.promote_account,spend.game_id,spend.game_name,
@ -168,29 +168,33 @@ class SpendCountSetController extends \Think\Controller
# code...
}
//获取绑定币充值
public function getBingData()
public function getInsideData()
{
if(!$this->continue){
die("api error");
}
$bindRes = M()
->table("tab_bind_recharge bind")
->field("IFNULL(game.partner_id,0) partner_id,partner.partner partner_name,
bind.game_id,bind.game_name,bind.promote_id,bind.promote_account,
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")
->where(array(
"bind.create_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"bind.pay_status"=>1
))
->join("tab_promote promote ON bind.promote_id = promote.id","left")
->join("tab_game game ON bind.game_id = game.id","left")
$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('bind.promote_id,bind.game_id')
->group('spend.promote_id,spend.game_id')
->select();
//聚合表
if(!empty($bindRes)){
for ($i=0; $i < count($bindRes); $i++) {
//集中两个表
if(!empty($balanceRes)){
for ($i=0; $i < count($balanceRes); $i++) {
# code...
$tempmap = array(
"game_id"=>$balanceRes[$i]['game_id'],
@ -200,13 +204,13 @@ class SpendCountSetController extends \Think\Controller
$dbres = $this->model->where($tempmap)->find();
if(!$dbres){
//不存在
$tempdbres =$this->model->add($bindRes[$i]);
$tempdbres = $this->model->add($balanceRes[$i]);
if(!$tempdbres){
$this->model->rollback();
die("error");
}
}else{
$dbres["bind_coin_count"] = $bindRes[$i]['bind_coin_count'];
$dbres["inside_cash_count"] = $balanceRes[$i]['inside_cash_count'];
$tempdbres = $this->model->save($dbres);
if(!$tempdbres){
$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()
{
if(!$this->continue){
@ -300,7 +261,7 @@ class SpendCountSetController extends \Think\Controller
$this->getRootUser();
$this->getParentUser();
$this->getPromoteUser();
$this->getInsideData2();
$this->getUserInsideData();
}
/** --------以下为辅助函数---------- **/
@ -424,21 +385,20 @@ class SpendCountSetController extends \Think\Controller
}
# code...
}
//处理inside_cash_count
public function getInsideData2()
//渠道角色统计仅计算推广员的平台币发放与收回
public function getUserInsideData()
{
if(!$this->continue) die("api error");
// 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")
->table("tab_promote_coin")
->field("*")
->where(array(
"deposit.create_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"pay_status"=>1
"create_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"banlan_type"=>1,
"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...
@ -447,6 +407,13 @@ class SpendCountSetController extends \Think\Controller
"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
@ -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数据
public function setInsideCount($promote_id,$inside_cash_count)
@ -486,5 +495,54 @@ class SpendCountSetController extends \Think\Controller
}
# 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 '合作方名称',
`cash_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 '统计月份',
`create_time` int(11) DEFAULT NULL COMMENT '添加时间',
PRIMARY KEY (`id`) USING BTREE,
@ -227,7 +226,7 @@ CREATE TABLE `tab_spend_user_count` (
`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 '内充流水',
`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,
@ -235,3 +234,15 @@ CREATE TABLE `tab_spend_user_count` (
KEY `parent_id` (`parent_id`) USING BTREE,
KEY `count_date` (`count_date`) USING BTREE
) 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