From 9803b418b9913fdc95c8a763d28070aa66e26022 Mon Sep 17 00:00:00 2001 From: chenzhi <“chenzhi063@qq.com> Date: Tue, 29 Oct 2019 16:13:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/FinanceController.class.php | 6 +- .../SpendCountSetController.class.php | 140 +++++++++++++++++- Data/update.sql | 22 ++- 3 files changed, 160 insertions(+), 8 deletions(-) diff --git a/Application/Admin/Controller/FinanceController.class.php b/Application/Admin/Controller/FinanceController.class.php index 9415f88da..3f19fd8d0 100644 --- a/Application/Admin/Controller/FinanceController.class.php +++ b/Application/Admin/Controller/FinanceController.class.php @@ -214,15 +214,15 @@ class FinanceController extends ThinkController //获取数据 $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 + 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 root_id = '{$root_id}' and count_date='{$month}' group by parent_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') + ->field('parent_id,parent_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") + ->group("a.parent_id") ->select(); dump($subQueryAll); # code... diff --git a/Application/Admin/Controller/SpendCountSetController.class.php b/Application/Admin/Controller/SpendCountSetController.class.php index 0de595c6e..5226ea34f 100644 --- a/Application/Admin/Controller/SpendCountSetController.class.php +++ b/Application/Admin/Controller/SpendCountSetController.class.php @@ -2,8 +2,8 @@ namespace Admin\Controller; /** - * 后台首页控制器 - * @author 麦当苗儿 + * 游戏流水聚合接口 + * @author chenzhi */ class SpendCountSetController extends \Think\Controller { @@ -12,7 +12,7 @@ class SpendCountSetController extends \Think\Controller public $date; public $nowdata; public $model; - public $continue=false; + public $continue=false;//单元测试,开启后可访问独立函数测试 public function _initialize(){ //初始化 $this->beginThismonth = mktime(0,0,0,date('m')-1,1,date('Y')); @@ -21,6 +21,9 @@ class SpendCountSetController extends \Think\Controller $this->nowdata =time(); $this->model =M("spend_count",'tab_'); } + /** + * 初始化统计/用于之前数据的聚合 + */ public function initCount() { $countRes = M("spend_count","tab_")->field("count(*) date_count")->find()['date_count']; @@ -49,6 +52,8 @@ class SpendCountSetController extends \Think\Controller $this->getBingData(); $this->getInsideData(); $this->setRoot(); + //执行用户表统计 + $this->setUserCount(); $this->model->commit(); } @@ -56,7 +61,9 @@ class SpendCountSetController extends \Think\Controller die("success"); } - //流水聚合接口 + /** + * 每个月的统计接口 + */ public function setSpendCount() { //判断是否已经聚合 @@ -71,6 +78,9 @@ class SpendCountSetController extends \Think\Controller $this->getBingData(); $this->getInsideData(); $this->setRoot(); + //执行用户表统计 + $this->setUserCount(); + $this->model->commit(); die("success"); } @@ -286,4 +296,126 @@ class SpendCountSetController extends \Think\Controller } } } + /** + * 获取角色聚合 + */ + public function setUserCount() + { + //获取会长信息 + $this->getRootUser(); + $this->getParentUser(); + $this->getPromoteUser(); + + } + /** --------以下为辅助函数--------- **/ + //获取会长信息 + public function getRootUser() + { + //获取所有数据 + $month = $this->date; + $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') + ->group("a.root_id") + ->having("cash_count > 0 or balance_coin_count > 0 or inside_cash_count > 0") + ->select(); + for ($i=0; $i$subQueryAll[$i]['root_id'], + "promote_account"=>$subQueryAll[$i]['root_name'], + "parent_id"=>0, + "parent_name"=>'官方渠道', + "root_id"=>0, + "root_name"=>'官方渠道', + "cash_count"=>$subQueryAll[$i]['cash_count'], + "balance_coin_count"=>$subQueryAll[$i]['balance_coin_count'], + "inside_cash_count"=>$subQueryAll[$i]['inside_cash_count'], + "all_count"=>$subQueryAll[$i]['cash_count']-0+$subQueryAll[$i]['balance_coin_count']-0+$subQueryAll[$i]['inside_cash_count'], + "count_date"=>$this->date, + "create_time"=>$this->nowdata + ); + M("spend_user_count","tab_")->add($adddata); + } + } + //获取组长信息 + public function getParentUser() + { + $month =$this->date; + //获取数据 + $from = " + ( + SELECT parent_id,parent_name,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 parent_id + UNION + SELECT promote_id,promote_account,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 promote_id + ) + "; + $subQueryAll = M()->table($from." a") + ->field('parent_id,parent_name,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.parent_id") + ->having("cash_count > 0 or balance_coin_count > 0 or inside_cash_count > 0") + ->select(); + for ($i=0; $i$subQueryAll[$i]['parent_id'], + "promote_account"=>$subQueryAll[$i]['parent_name'], + "parent_id"=>$subQueryAll[$i]['root_id'], + "parent_name"=>$subQueryAll[$i]['root_name'], + "root_id"=>0, + "root_name"=>'官方渠道', + "cash_count"=>$subQueryAll[$i]['cash_count'], + "balance_coin_count"=>$subQueryAll[$i]['balance_coin_count'], + "inside_cash_count"=>$subQueryAll[$i]['inside_cash_count'], + "all_count"=>$subQueryAll[$i]['cash_count']-0+$subQueryAll[$i]['balance_coin_count']-0+$subQueryAll[$i]['inside_cash_count'], + "count_date"=>$this->date, + "create_time"=>$this->nowdata + ); + M("spend_user_count","tab_")->add($adddata); + } + # code... + } + //获取组员 + public function getPromoteUser() + { + $month = $this->date;; + //获取数据 + $from = " + ( + SELECT promote_id,promote_account,parent_id,parent_name,root_id,root_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 promote_id + ) + "; + $subQueryAll = M()->table($from." a") + ->field('*') + // ->limit(1) + ->group("a.promote_id") + ->having("cash_count > 0 or balance_coin_count > 0 or inside_cash_count > 0") + ->select(); + for ($i=0; $i$subQueryAll[$i]['promote_id'], + "promote_account"=>$subQueryAll[$i]['promote_account'], + "parent_id"=>$subQueryAll[$i]['parent_id'], + "parent_name"=>$subQueryAll[$i]['parent_name'], + "root_id"=>$subQueryAll[$i]['root_id'], + "root_name"=>$subQueryAll[$i]['root_name'], + "cash_count"=>$subQueryAll[$i]['cash_count'], + "balance_coin_count"=>$subQueryAll[$i]['balance_coin_count'], + "inside_cash_count"=>$subQueryAll[$i]['inside_cash_count'], + "all_count"=>$subQueryAll[$i]['cash_count']-0+$subQueryAll[$i]['balance_coin_count']-0+$subQueryAll[$i]['inside_cash_count'], + "count_date"=>$this->date, + "create_time"=>$this->nowdata + ); + M("spend_user_count","tab_")->add($adddata); + } + # code... + } + } diff --git a/Data/update.sql b/Data/update.sql index 731cd306b..a8da89bed 100644 --- a/Data/update.sql +++ b/Data/update.sql @@ -214,4 +214,24 @@ CREATE TABLE `tab_spend_count` ( KEY `promote_id` (`promote_id`) USING BTREE, KEY `partner_id` (`partner_id`) USING BTREE, KEY `count_date` (`count_date`) USING BTREE -) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='游戏流水聚合表'; \ No newline at end of file +) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='游戏流水聚合表'; + +CREATE TABLE `tab_spend_user_count` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `promote_id` int(11) NOT NULL DEFAULT '0' COMMENT '推广员id', + `promote_account` varchar(30) DEFAULT '' COMMENT '推广员账号', + `parent_id` int(11) DEFAULT '0' COMMENT '父类ID', + `parent_name` varchar(30) DEFAULT NULL COMMENT '父类名称', + `root_id` int(11) DEFAULT 0 COMMENT '根ID', + `root_name` varchar(30) DEFAULT NULL 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 `promote_id` (`promote_id`) USING BTREE, + 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='流水角色聚合表'; \ No newline at end of file