diff --git a/Application/Admin/Controller/PublicController.class.php b/Application/Admin/Controller/PublicController.class.php index 7254d0541..858f2c816 100644 --- a/Application/Admin/Controller/PublicController.class.php +++ b/Application/Admin/Controller/PublicController.class.php @@ -238,5 +238,88 @@ 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"); + } + }