From 7a876e01abab89e450b41542ace2a0f0c34810f4 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Tue, 17 Nov 2020 17:36:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=B0=E5=A2=9E=E6=8E=A8?= =?UTF-8?q?=E5=B9=BF=E5=91=98=E6=B1=87=E6=80=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/PlatformController.class.php | 192 +++++++++++- .../Admin/View/Platform/promote_pool.html | 282 ++++++++++++++++++ .../View/Platform/promote_statistics.html | 1 + .../View/Platform/promotepay_statistics.html | 1 + 4 files changed, 475 insertions(+), 1 deletion(-) create mode 100644 Application/Admin/View/Platform/promote_pool.html diff --git a/Application/Admin/Controller/PlatformController.class.php b/Application/Admin/Controller/PlatformController.class.php index 741948b58..9e958090b 100644 --- a/Application/Admin/Controller/PlatformController.class.php +++ b/Application/Admin/Controller/PlatformController.class.php @@ -11,6 +11,197 @@ use Org\UcenterSDK\Ucservice; */ class PlatformController extends ThinkController { + public function promote_pool() + { + if(!array_key_exists("year",$_REQUEST) || !array_key_exists("company_belong",$_REQUEST)){ + $this->redirect(ACTION_NAME, array('year' => date('Y',time()),"company_belong"=>0)); + } + $isExport = false; + if(isset($_REQUEST['export']) && $_REQUEST['export'] == 1){ + $isExport = true; + } + + $page = intval($_REQUEST['p']); + $page = $page ? $page : 1; //默认显示第一页数据 + if (isset($_REQUEST['row'])) { + $row = $_REQUEST['row']; + } else { + $row = 10; + } + $companyBelong = isset($_REQUEST['company_belong']) ? $_REQUEST['company_belong'] : 0; + $year = isset($_REQUEST['year']) ? $_REQUEST['year'] : date("Y",time()); + $yearMap = [strtotime("$year-1-1 00:00:00"),strtotime("$year-12-31 23:59:59")]; + //获取公司数据 tab_promote_company + $companyMap = "1"; + if($companyBelong > -1){ + $companyMap .= " AND company_belong = {$companyBelong}"; + } + if(isset($_REQUEST['company_name'])){ + $companyId = $_REQUEST['company_name']; + $companyMap .= " AND company_name like '%{$companyId}%' "; + } + + $promoteCompany = M("promote_company","tab_"); + $data = $promoteCompany + ->field("id,company_name,company_belong") + ->where($companyMap); + if($isExport){ + $data = $data->select(); + //生成头 + $fp = $this->setPromotePoolTitle($year); + }else{ + $data = $data->page($page,$row)->select(); + $count = $promoteCompany->where($companyMap)->count(); + } + + //获取公司累计注册 + $sendData = []; + foreach($data as $k=>$v){ + $promote = getPromoteByLevel(0,$v['id']); + if(empty($promote)){ + $promoteIds = ''; + }else{ + $promoteIds = implode(",",array_column($promote,"id")); + } + $list = self::setYearList($year); + $this->getRegisterCount($list,$promoteIds,$yearMap); + $this->getPayamountCount($list,$promoteIds,$yearMap); + $v["list"] = $list; + $v["company_belong"] = getCompanyBlongOther($v["company_belong"]); + $sendData[] = $v; + if($isExport) $fp = $this->setCsvData($fp,$v); + } + + if($isExport){ + //刷新输出缓冲到浏览器 + fclose($fp); + exit(); + } + + $th = array_keys(self::setYearList($year)); + $this->assign('th', $th); + $this->assign('list_data', $sendData); + $this->getYearList(); + + $page = set_pagination($count, $row); + if ($page) { + $this->assign('_page', $page); + } + $this->display(); + // var_dump($sendData); + + + } + //获取公司每个月的注册及充值金额 + private static function setYearList($year) + { + $range = []; + $i = 1; + do { + if($i < 10){ + $month = "0".$i; + }else{ + $month = $i; + } + $range[$year."-".$month] = ["register"=>0,"payamount"=>0]; + $i++; + } while ($i<13); + return $range; + } + //获取注册量 + protected function getRegisterCount(&$list,$promoteIds,$yearMap) + { + $map = [ + "promote_id"=>["in",$promoteIds], + "register_time"=>["between",$yearMap] + ]; + $Register = M("User","tab_")->field("count(id) count,FROM_UNIXTIME(`register_time`, '%Y-%m') regtime")->where($map)->group("regtime")->select(); + if(empty($Register)) return ; + foreach ($Register as $v) { + $list[$v['regtime']]['register'] = $v['count']; + } + } + //获取支付流水 + protected function getPayamountCount(&$list,$promoteIds,$yearMap) + { + $map = [ + "promote_id"=>["in",$promoteIds], + "pay_time"=>["between",$yearMap], + "pay_status"=>1 + ]; + $Payamount = M("Spend","tab_")->field("sum(pay_amount) pay_amount,FROM_UNIXTIME(`pay_time`, '%Y-%m') paytime")->where($map)->group("paytime")->select(); + if(empty($Payamount)) return ; + foreach ($Payamount as $v) { + $list[$v['paytime']]['payamount'] = $v['pay_amount']; + } + } + //获取所有年分 + protected function getYearList() + { + $star = 2019; + $end = date("Y",time()); + $list = []; + for ($i=$star; $i <= $end; $i++) { + $temp = array( + "value"=>$i, + "name"=>"{$i}年" + ); + $list[] = $temp ; + } + $this->assign('YearList', $list); + } + //获取导出头 + private static function setPromotePoolTitle($year) + { + $range = ["推广公司","内外团归属"]; + $i = 1; + do { + if($i < 10){ + $month = "0".$i; + }else{ + $month = $i; + } + $range[] = $year."年".$month."月注册数"; + $range[] = $year."年".$month."月充值流水"; + $i++; + } while ($i<13); + + $csvFileName = '推广公司汇总.csv'; + //设置好告诉浏览器要下载excel文件的headers + header('Content-Description: File Transfer'); + header('Content-Type: application/vnd.ms-excel'); + header('Content-Disposition: attachment; filename="'. $csvFileName .'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + $fp = fopen('php://output', 'a');//打开output流 + mb_convert_variables('GBK', 'UTF-8', $range); + fputcsv($fp, $range);//将数据格式化为CSV格式并写入到output流中 + + return $fp; + } + //获取导出头 + private static function setCsvData($fp,$data) + { + unset($data['id']); + $sendData = []; + foreach ($data as $key => $value) { + if($key != "list"){ + $sendData[] = $value; + } + } + foreach ($data['list'] as $key => $value) { + $sendData[] = $value['register']; + $sendData[] = $value['payamount']; + } + mb_convert_variables('GBK', 'UTF-8', $sendData); + fputcsv($fp, $sendData);//将数据格式化为CSV格式并写入到output流中 + ob_flush(); + flush(); + return $fp; + } + + function game_statistics($p = 0) { $page = intval($p); @@ -437,7 +628,6 @@ class PlatformController extends ThinkController $this->display(); } - function promote_statistics($p = 0) { $page = intval($p); diff --git a/Application/Admin/View/Platform/promote_pool.html b/Application/Admin/View/Platform/promote_pool.html new file mode 100644 index 000000000..d4a4745aa --- /dev/null +++ b/Application/Admin/View/Platform/promote_pool.html @@ -0,0 +1,282 @@ + + + + + + + + + + +
+ + +
+
+ +
+ +
+ +
+
+ + +
+ +
+   +
+ + +
+ 搜索 +
+
+
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
推广公司内外团归属{$vo}
注册数充值流水
aOh! 暂时还没有内容!
{$data['company_name']}{$data['company_belong']}{$it}
+
+
+
+ 导出 + {$_page|default=''} +
+
+ + + + + + if(C('COLOR_STYLE')=='blue_color') echo ''; + + + + + + \ No newline at end of file diff --git a/Application/Admin/View/Platform/promote_statistics.html b/Application/Admin/View/Platform/promote_statistics.html index e226976b6..8a3df4834 100644 --- a/Application/Admin/View/Platform/promote_statistics.html +++ b/Application/Admin/View/Platform/promote_statistics.html @@ -29,6 +29,7 @@