|
|
@ -79,10 +79,10 @@ class SpendCountSetController extends \Think\Controller
|
|
|
|
$this->continue =true;
|
|
|
|
$this->continue =true;
|
|
|
|
//执行游戏表统计
|
|
|
|
//执行游戏表统计
|
|
|
|
$this->setGameCount();
|
|
|
|
$this->setGameCount();
|
|
|
|
//执行用户表统计
|
|
|
|
// //执行用户表统计
|
|
|
|
$this->setUserCount();
|
|
|
|
// $this->setUserCount();
|
|
|
|
//执行月份统计
|
|
|
|
// //执行月份统计
|
|
|
|
$this->setMonthCount();
|
|
|
|
// $this->setMonthCount();
|
|
|
|
//执行
|
|
|
|
//执行
|
|
|
|
$this->model->commit();
|
|
|
|
$this->model->commit();
|
|
|
|
$this->usermodel->commit();
|
|
|
|
$this->usermodel->commit();
|
|
|
@ -95,167 +95,44 @@ class SpendCountSetController extends \Think\Controller
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function setGameCount()
|
|
|
|
public function setGameCount()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!$this->continue){
|
|
|
|
|
|
|
|
die("api error");
|
|
|
|
|
|
|
|
}
|
|
|
|
$this->getCashData();
|
|
|
|
$this->getCashData();
|
|
|
|
$this->getBalanceData();
|
|
|
|
$this->getBalanceData();
|
|
|
|
$this->getInsideData();
|
|
|
|
$this->getInsideData();
|
|
|
|
$this->getRoot();
|
|
|
|
|
|
|
|
# code...
|
|
|
|
# code...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//获取游戏现金流水
|
|
|
|
//获取游戏现金流水
|
|
|
|
protected function getCashData()
|
|
|
|
protected function getCashData()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->createGameCount("cash_count");
|
|
|
|
$this->createGameCount("cash_count");
|
|
|
|
// if(!$this->continue){
|
|
|
|
|
|
|
|
// die("api error");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// $map = array(
|
|
|
|
|
|
|
|
// "pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
|
|
|
|
|
|
|
|
// "spend.pay_status"=>1,
|
|
|
|
|
|
|
|
// "pay_way"=>array("GT",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) 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()
|
|
|
|
protected function getBalanceData()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->createGameCount("balance_coin_count");
|
|
|
|
$this->createGameCount("balance_coin_count");
|
|
|
|
// 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...
|
|
|
|
|
|
|
|
// $tempmap = array(
|
|
|
|
|
|
|
|
// "game_id"=>$balanceRes[$i]['game_id'],
|
|
|
|
|
|
|
|
// "promote_id"=>$balanceRes[$i]['promote_id'],
|
|
|
|
|
|
|
|
// "count_date"=>$this->date
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// $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()
|
|
|
|
protected function getInsideData()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->createGameCount("inside_cash_count");
|
|
|
|
$this->createGameCount("inside_cash_count");
|
|
|
|
// 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++) {
|
|
|
|
|
|
|
|
// # code...
|
|
|
|
|
|
|
|
// $tempmap = array(
|
|
|
|
|
|
|
|
// "game_id"=>$balanceRes[$i]['game_id'],
|
|
|
|
|
|
|
|
// "promote_id"=>$balanceRes[$i]['promote_id'],
|
|
|
|
|
|
|
|
// "count_date"=>$this->date
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// $dbres = $this->model->where($tempmap)->find();
|
|
|
|
|
|
|
|
// if(!$dbres){
|
|
|
|
|
|
|
|
// //不存在
|
|
|
|
|
|
|
|
// $tempdbres = $this->model->add($balanceRes[$i]);
|
|
|
|
|
|
|
|
// if(!$tempdbres){
|
|
|
|
|
|
|
|
// $this->model->rollback();
|
|
|
|
|
|
|
|
// die("error");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }else{
|
|
|
|
|
|
|
|
// $dbres["inside_cash_count"] = $balanceRes[$i]['inside_cash_count'];
|
|
|
|
|
|
|
|
// $tempdbres = $this->model->save($dbres);
|
|
|
|
|
|
|
|
// if(!$tempdbres){
|
|
|
|
|
|
|
|
// $this->model->rollback();
|
|
|
|
|
|
|
|
// die("error");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
protected function createGameCount($type)
|
|
|
|
protected function createGameCount($type)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$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",0)
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if($type == "cash_count"){
|
|
|
|
if($type == "cash_count"){
|
|
|
|
//现金统计
|
|
|
|
//现金统计
|
|
|
|
$map['pay_way'] = array("GT",0);
|
|
|
|
$map['pay_way'] = array("GT",0);
|
|
|
|
|
|
|
|
}elseif($type == "balance_coin_count"){
|
|
|
|
|
|
|
|
$map['pay_way']= array("EQ",0);
|
|
|
|
|
|
|
|
}elseif($type == "inside_cash_count"){
|
|
|
|
|
|
|
|
$map['pay_way']= array("LT",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,sum(pay_amount) {$type},
|
|
|
|
spend.promote_id,spend.promote_account,spend.game_id,spend.game_name,sum(pay_amount) {$type},
|
|
|
@ -282,6 +159,7 @@ class SpendCountSetController extends \Think\Controller
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
for ($i=0; $i < count($spendRes); $i++) {
|
|
|
|
for ($i=0; $i < count($spendRes); $i++) {
|
|
|
|
|
|
|
|
$spendRes[$i][$type] || $spendRes[$i][$type]=0;
|
|
|
|
# code...
|
|
|
|
# code...
|
|
|
|
$tempmap = array(
|
|
|
|
$tempmap = array(
|
|
|
|
"game_id"=>$spendRes[$i]['game_id'],
|
|
|
|
"game_id"=>$spendRes[$i]['game_id'],
|
|
|
@ -297,9 +175,9 @@ class SpendCountSetController extends \Think\Controller
|
|
|
|
die("error");
|
|
|
|
die("error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
$dbres[$type] = $balanceRes[$i][$type];
|
|
|
|
$dbres[$type] = $dbres[$type]-0+$spendRes[$i][$type];
|
|
|
|
$tempdbres = $this->gamemodel->save($dbres);
|
|
|
|
$tempdbres = $this->gamemodel->save($dbres);
|
|
|
|
if(!$tempdbres){
|
|
|
|
if($tempdbres === false){
|
|
|
|
$this->model->rollback();
|
|
|
|
$this->model->rollback();
|
|
|
|
die("error");
|
|
|
|
die("error");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -309,37 +187,6 @@ class SpendCountSetController extends \Think\Controller
|
|
|
|
# code...
|
|
|
|
# code...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function getRoot()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!$this->continue){
|
|
|
|
|
|
|
|
die("api error");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$map = array(
|
|
|
|
|
|
|
|
"parent_id"=>array("GT",0),
|
|
|
|
|
|
|
|
"count_date"=>$this->date
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$user = $this->model->field("parent_id,promote_id")->where($map)->group("promote_id")->select();
|
|
|
|
|
|
|
|
$Promote=M("promote","tab_");
|
|
|
|
|
|
|
|
for ($i=0; $i < count($user); $i++) {
|
|
|
|
|
|
|
|
# code...
|
|
|
|
|
|
|
|
$map['id']=$user[$i]['parent_id'];
|
|
|
|
|
|
|
|
$root=$Promote->field('IFNULL(parent_id,0) root_id,parent_name root_name')->where($map)->find();
|
|
|
|
|
|
|
|
if(!$root){
|
|
|
|
|
|
|
|
$root['root_id']=0;
|
|
|
|
|
|
|
|
$root['root_name']='官方渠道';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//保存
|
|
|
|
|
|
|
|
$where = array(
|
|
|
|
|
|
|
|
"promote_id"=>$user[$i]['promote_id'],
|
|
|
|
|
|
|
|
"count_date"=>$this->date
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$tempdbres = $this->model->where($where)->save($root);
|
|
|
|
|
|
|
|
if(!$tempdbres){
|
|
|
|
|
|
|
|
$this->model->rollback();
|
|
|
|
|
|
|
|
die("setRoot error");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/** --------以下为设定角色聚合---------- **/
|
|
|
|
/** --------以下为设定角色聚合---------- **/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -353,6 +200,46 @@ class SpendCountSetController extends \Think\Controller
|
|
|
|
$this->getPromoteUser();
|
|
|
|
$this->getPromoteUser();
|
|
|
|
$this->getUserInsideData();
|
|
|
|
$this->getUserInsideData();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//用户聚合
|
|
|
|
|
|
|
|
public function getUserCountInit()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$gameres = $this->gamemodel->field("sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,chain,level,promote_id,promote_account")
|
|
|
|
|
|
|
|
->where("count_date='{$this->date}'")->group("promote_id")->select();
|
|
|
|
|
|
|
|
if(empty($gameres)){
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$count = count($gameres);
|
|
|
|
|
|
|
|
$adddata=array();
|
|
|
|
|
|
|
|
$userarr = array();
|
|
|
|
|
|
|
|
//执行
|
|
|
|
|
|
|
|
for ($i=0; $i < $count; $i++) {
|
|
|
|
|
|
|
|
$d = $gameres[$i];
|
|
|
|
|
|
|
|
if($d['level'] == 0){
|
|
|
|
|
|
|
|
$adddata[$d['promote_id']] = $d;
|
|
|
|
|
|
|
|
$userarr[] =$d['promote_id'];
|
|
|
|
|
|
|
|
// $tempdbres = $this->usermodel->add($d);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
//获取所有链路
|
|
|
|
|
|
|
|
$chain = trim($d['chain'],"/");
|
|
|
|
|
|
|
|
$pid = explode("/", $chain);
|
|
|
|
|
|
|
|
for ($k=0; $k <count($pid); $k++) {
|
|
|
|
|
|
|
|
if(in_array($pid[$k], $userarr)){
|
|
|
|
|
|
|
|
//存在
|
|
|
|
|
|
|
|
// $adddata[$pid[$k]]["cash_count"] += $d;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# code...
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// dump($pid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# code...
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dump($adddata);
|
|
|
|
|
|
|
|
dump($userarr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function createUser(){
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//获取会长信息
|
|
|
|
//获取会长信息
|
|
|
|
protected function getRootUser()
|
|
|
|
protected function getRootUser()
|
|
|
|