diff --git a/Application/Admin/Controller/PublicController.class.php b/Application/Admin/Controller/PublicController.class.php index 858f2c816..0dda9d160 100644 --- a/Application/Admin/Controller/PublicController.class.php +++ b/Application/Admin/Controller/PublicController.class.php @@ -238,88 +238,4 @@ class PublicController extends \Think\Controller cookie('think_language', 'en-us'); $this->ajaxReturn(['status' => 1]); } - //流水聚合接口 - public function setSpendCount() - { - //获取上个月的时间挫 - $beginThismonth=mktime(0,0,0,date('m')-1,1,date('Y')); - $endThismonth=mktime(0,0,0,date('m')-1,date('t'),date('Y'))-1; - $date = date('Y')."-".((date('m')-1) > 9 ? (date('m')-1) : "0".(date('m')-1)); - - dump($date); - //获取各推广员的现金数据 - $map = array( - "pay_time"=> array('BETWEEN',array($beginThismonth, $endThismonth)), - "pay_status"=>1, - "pay_way"=>array("GT",0) - ); - $field = "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,'{$date}' as count_date"; - //获取现金 - $model = M(); - $model->startTrans(); - - $cashRes = M() - ->table("tab_spend spend") - ->field($field) - ->where($map) - ->join("tab_promote promote ON spend.promote_id = promote.id","left") - ->group('spend.promote_id,spend.game_id') - ->select(); - dump($cashRes); - if(!empty($cashRes)){ - $dbres = M("spend_count",'tab_')->addAll($cashRes); - if(!$dbres){ - $model->rollback(); - die("error"); - } - } - //添加数据库 - //获取平台币聚合 - $map['pay_way'] = array("LT",1); - $balanceRes = M() - ->table("tab_spend spend") - ->field($field) - ->where($map) - ->join("tab_promote promote ON spend.promote_id = promote.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'] - ); - $dbres = M("spend_count","tab_")->where($tempmap)->find(); - if(!$dbres){ - //不存在 - // $balanceRes[$i]['all_cash_count'] = $balanceRes[$i]['cash_count']; - $balanceRes[$i]['balance_coin_count'] = $balanceRes[$i]['cash_count']; - unset($balanceRes[$i]['cash_count']); - $tempdbres = M("spend_count","tab_")->add($balanceRes[$i]); - if(!$tempdbres){ - $model->rollback(); - die("1error"); - } - }else{ - $dbres["balance_coin_count"] = $balanceRes[$i]['cash_count']; - // $dbres['all_cash_count'] = $dbres["cash_count"]-0+ $balanceRes[$i]['cash_count']; - dump( $dbres); - $tempdbres = M("spend_count","tab_")->save($dbres); - if(!$tempdbres){ - $model->rollback(); - die("2error"); - } - } - } - } - //获取绑定币充值 - - - $model->commit(); - die("success"); - } - - } diff --git a/Application/Admin/Controller/SpendCountSetController.class.php b/Application/Admin/Controller/SpendCountSetController.class.php new file mode 100644 index 000000000..9b4d7bff2 --- /dev/null +++ b/Application/Admin/Controller/SpendCountSetController.class.php @@ -0,0 +1,245 @@ + + */ +class SpendCountSetController extends \Think\Controller +{ + public $beginThismonth; + public $endThismonth; + public $date; + public $nowdata; + public $model; + public $continue=false; + public function _initialize(){ + //初始化 + $this->beginThismonth = mktime(0,0,0,date('m')-1,1,date('Y')); + $this->endThismonth = mktime(0,0,0,date('m')-1,date('t'),date('Y'))-1; + $this->date = date('Y')."-".((date('m')-1) > 9 ? (date('m')-1) : "0".(date('m')-1)); + $this->nowdata =time(); + $this->model =M(); + } + public function initCount() + { + $countRes = M("spend_count","tab_")->field("count(*) date_count")->find()['date_count']; + if($countRes > 0){ + die("init error"); + } + $nowdate = date('Y')."-".(date('m') > 9 ? date('m') : "0".date('m')); + // $nowdate = "2017-10"; + //获取所有的月份 pay_time + $res = M("spend",'tab_')->field("FROM_UNIXTIME(pay_time,'%Y-%m') AS pay_time")->buildSql(); + $res = M()->table($res.' a')->group('pay_time')->select(); + //执行数据统计 + for ($i=0; $i < count($res); $i++) { + # code... + if($res[$i]['pay_time'] != $nowdate){ + $month = $res[$i]['pay_time']; + $this->date = $month; + $tarry = explode('-',$month); + $this->beginThismonth=mktime(0,0,0,$tarry[1],1,$tarry[0]); + $this->endThismonth=mktime(0,0,0,$tarry[1]-0+1,1,$tarry[0])-1; + //执行 + $this->model->startTrans(); + $this->continue =true; + $this->getCashData(); + $this->getBalanceData(); + $this->getBingData(); + $this->getInsideData(); + + $this->model->commit(); + } + } + die("success"); + + } + //流水聚合接口 + public function setSpendCount() + { + //判断是否已经聚合 + $countRes = M("spend_count","tab_")->field("count(*) date_count")->where("count_date = '{$this->date}'")->find()['date_count']; + if($countRes > 0){ + die("Repeated statistics"); + } + $this->model->startTrans(); + $this->continue =true; + $this->getCashData(); + $this->getBalanceData(); + $this->getBingData(); + $this->getInsideData(); + + $this->model->commit(); + die("success"); + } + //获取游戏现金流水 + public function getCashData() + { + if(!$this->continue){ + die("api error"); + } + $map = array( + "pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)), + "pay_status"=>1, + "pay_way"=>array("GT",0) + ); + $field = "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") + ->group('spend.promote_id,spend.game_id') + ->select(); + if(!empty($cashRes)){ + $dbres = M("spend_count",'tab_')->addAll($cashRes); + if(!$dbres){ + $this->model->rollback(); + die("error"); + } + } + # code... + } + //获取平台币聚合 + public function getBalanceData() + { + if(!$this->continue){ + die("api error"); + } + $map = array( + "pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)), + "pay_status"=>1, + "pay_way"=> array("LT",1) + ); + $field = "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") + ->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 = M("spend_count","tab_")->where($tempmap)->find(); + if(!$dbres){ + //不存在 + $tempdbres = M("spend_count","tab_")->add($balanceRes[$i]); + if(!$tempdbres){ + $this->model->rollback(); + die("error"); + } + }else{ + $dbres["balance_coin_count"] = $balanceRes[$i]['balance_coin_count']; + $tempdbres = M("spend_count","tab_")->save($dbres); + if(!$tempdbres){ + $this->model->rollback(); + die("error"); + } + } + } + } + # code... + } + //获取绑定币充值 + public function getBingData() + { + if(!$this->continue){ + die("api error"); + } + $bindRes = M() + ->table("tab_bind_recharge bind") + ->field("game_id,game_name,promote_id,promote_account,IFNULL(promote.parent_id,0) parent_id,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)), + "pay_status"=>1 + )) + ->join("tab_promote promote ON bind.promote_id = promote.id","left") + ->group('bind.promote_id,bind.game_id') + ->select(); + //聚合表 + if(!empty($bindRes)){ + for ($i=0; $i < count($bindRes); $i++) { + # code... + $tempmap = array( + "game_id"=>$balanceRes[$i]['game_id'], + "promote_id"=>$balanceRes[$i]['promote_id'], + "count_date"=>$this->date + ); + $dbres = M("spend_count","tab_")->where($tempmap)->find(); + if(!$dbres){ + //不存在 + $tempdbres = M("spend_count","tab_")->add($bindRes[$i]); + if(!$tempdbres){ + $this->model->rollback(); + die("error"); + } + }else{ + $dbres["bind_coin_count"] = $bindRes[$i]['bind_coin_count']; + $tempdbres = M("spend_count","tab_")->save($dbres); + if(!$tempdbres){ + $this->model->rollback(); + die("error"); + } + } + } + } + } + //获取内充流水 + 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"=>$balanceRes[$i]['promote_id'], + "count_date"=>$this->date + ); + $dbres = M("spend_count","tab_")->where($tempmap)->find(); + if(!$dbres){ + //不存在 + $tempdbres = M("spend_count","tab_")->add($insideRes[$i]); + if(!$tempdbres){ + $this->model->rollback(); + die("error"); + } + }else{ + $dbres["inside_cash_count"] = $insideRes[$i]['inside_cash_count']; + $tempdbres = M("spend_count","tab_")->save($dbres); + if(!$tempdbres){ + $this->model->rollback(); + die("error"); + } + } + } + } + // return true; + } + + + +}