diff --git a/Application/Admin/Controller/FinanceController.class.php b/Application/Admin/Controller/FinanceController.class.php index 418fd940a..9415f88da 100644 --- a/Application/Admin/Controller/FinanceController.class.php +++ b/Application/Admin/Controller/FinanceController.class.php @@ -177,6 +177,78 @@ class FinanceController extends ThinkController $this->display(); } - + //按月份获取会长统计 + public function getRootUser() + { + //获取所有数据 + if (!empty(I("count_date"))) { + $month = I("count_date"); + } else { + $this->error('月份不能为空'); + } + $from = " + ( + SELECT root_id,root_name,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,inside_cash_count FROM tab_spend_count WHERE root_id > 0 and count_date='{$month}' group by root_id + UNION + SELECT promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,inside_cash_count FROM tab_spend_count WHERE parent_id = 0 and count_date='{$month}' group by promote_id + UNION + SELECT parent_id,parent_name,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,inside_cash_count FROM tab_spend_count WHERE parent_id > 0 and root_id = 0 and count_date='{$month}' group by parent_id + ) + "; + $subQueryAll = M()->table($from." a") + ->field('root_id,root_name,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count') + // ->limit(1) + ->group("a.root_id") + ->select(); + dump($subQueryAll); + } + //按月份获取组长统计 + public function getParentUser() + { + if (!empty(I("count_date")) && !empty(I("root_id"))) { + $month = I("count_date"); + $root_id = I("root_id"); + } else { + $this->error('参数错误'); + } + //获取数据 + $from = " + ( + SELECT root_id,root_name,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,inside_cash_count FROM tab_spend_count WHERE root_id = '{$root_id}' and count_date='{$month}' group by root_id + UNION + SELECT promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,inside_cash_count FROM tab_spend_count WHERE parent_id = '{$root_id}' and count_date='{$month}' group by promote_id + ) + "; + $subQueryAll = M()->table($from." a") + ->field('root_id,root_name,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count') + // ->limit(1) + ->group("a.root_id") + ->select(); + dump($subQueryAll); + # code... + } + public function getPromoteUser() + { + if (!empty(I("count_date")) && !empty(I("parent_id"))) { + $month = I("count_date"); + $parent_id = I("parent_id"); + } else { + $this->error('参数错误'); + } + //获取数据 + $from = " + ( + SELECT promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,inside_cash_count FROM tab_spend_count WHERE parent_id = '{$parent_id}' and count_date='{$month}' group by promote_id + ) + "; + $subQueryAll = M()->table($from." a") + ->field('promote_id,promote_account,cash_count,balance_coin_count,inside_cash_count') + // ->limit(1) + ->group("a.promote_id") + ->select(); + dump($subQueryAll); + # code... + } + } \ No newline at end of file diff --git a/Application/Admin/Controller/SpendCountSetController.class.php b/Application/Admin/Controller/SpendCountSetController.class.php index 4fb11e70e..0de595c6e 100644 --- a/Application/Admin/Controller/SpendCountSetController.class.php +++ b/Application/Admin/Controller/SpendCountSetController.class.php @@ -27,7 +27,7 @@ class SpendCountSetController extends \Think\Controller if($countRes > 0){ die("init error"); } - // $nowdate = date('Y')."-".(date('m') > 9 ? date('m') : "0".date('m')); + $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(); @@ -100,7 +100,7 @@ class SpendCountSetController extends \Think\Controller ->group('spend.promote_id,spend.game_id') ->select(); if(!empty($cashRes)){ - $dbres = M("spend_count",'tab_')->addAll($cashRes); + $dbres = $this->model->addAll($cashRes); if(!$dbres){ $this->model->rollback(); die("error"); @@ -142,17 +142,17 @@ class SpendCountSetController extends \Think\Controller "promote_id"=>$balanceRes[$i]['promote_id'], "count_date"=>$this->date ); - $dbres = M("spend_count","tab_")->where($tempmap)->find(); + $dbres = $this->model->where($tempmap)->find(); if(!$dbres){ //不存在 - $tempdbres = M("spend_count","tab_")->add($balanceRes[$i]); + $tempdbres = $this->model->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); + $tempdbres = $this->model->save($dbres); if(!$tempdbres){ $this->model->rollback(); die("error"); @@ -192,17 +192,17 @@ class SpendCountSetController extends \Think\Controller "promote_id"=>$balanceRes[$i]['promote_id'], "count_date"=>$this->date ); - $dbres = M("spend_count","tab_")->where($tempmap)->find(); + $dbres = $this->model->where($tempmap)->find(); if(!$dbres){ //不存在 - $tempdbres = M("spend_count","tab_")->add($bindRes[$i]); + $tempdbres =$this->model->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); + $tempdbres = $this->model->save($dbres); if(!$tempdbres){ $this->model->rollback(); die("error"); @@ -235,17 +235,17 @@ class SpendCountSetController extends \Think\Controller "promote_id"=>$insideRes[$i]['promote_id'], "count_date"=>$this->date ); - $dbres = M("spend_count","tab_")->where($tempmap)->find(); + $dbres = $this->model->where($tempmap)->find(); if(!$dbres){ //不存在 - $tempdbres = M("spend_count","tab_")->add($insideRes[$i]); + $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 = M("spend_count","tab_")->where($tempmap)->save($savedata); + $tempdbres = $this->model->where($tempmap)->save($savedata); if(!$tempdbres){ $this->model->rollback(); die("error"); @@ -286,7 +286,4 @@ class SpendCountSetController extends \Think\Controller } } } - - - }