作者 曹东东

统计

@@ -4,6 +4,7 @@ namespace app\school\controller; @@ -4,6 +4,7 @@ namespace app\school\controller;
4 4
5 use app\common\controller\DoubleBase; 5 use app\common\controller\DoubleBase;
6 use app\school\controller\project_common\ProjectData; 6 use app\school\controller\project_common\ProjectData;
  7 +use app\school\model\basic\College;
7 use app\school\model\project_common\ProjectRegister; 8 use app\school\model\project_common\ProjectRegister;
8 use think\Db; 9 use think\Db;
9 use fast\Export; 10 use fast\Export;
@@ -97,4 +98,67 @@ class ProjectSummary extends DoubleBase @@ -97,4 +98,67 @@ class ProjectSummary extends DoubleBase
97 $this->error('导出失败,稍后请重新尝试'); 98 $this->error('导出失败,稍后请重新尝试');
98 } 99 }
99 } 100 }
  101 +
  102 + public function statistics()
  103 + {
  104 + if($this->request->isAjax()) {
  105 +// dump($this->containerId);die;
  106 + $matchInfo = Db::name('project_container')->where(['id' => $this->containerId])->find();
  107 + $responseData = ['match_title'=>$matchInfo['container_name'],'group'=>['title' => [],'value'=>[]],'college_people' => [],'people'=>['title' => [],'value'=>[]]];
  108 + $collegeModel = new \app\school\model\basic\College();
  109 +
  110 + $typeGroup = Db::name('project_type')->alias('a')
  111 + ->field('a.name as title,count(b.id) as value')
  112 + ->join('project_register b','a.id = b.project_type','left')
  113 + ->where(['a.container_id' => $this->containerId])
  114 + ->group('a.id')
  115 + ->select();
  116 +
  117 + if($typeGroup) {
  118 + $responseData['group']['title'] = array_column($typeGroup,'title');
  119 + $responseData['group']['value'] = array_column($typeGroup,'value');
  120 + }
  121 +
  122 + $peopleData = Db::name('project_type')->alias('a')
  123 + ->field('a.name as title,count(c.id) as value')
  124 + ->join('project_register b','a.id = b.project_type','left')
  125 + ->join('members c','b.id = c.item_id and c.member_source = 2 and member_type = 1','left')
  126 + ->where(['a.container_id' => $this->containerId])
  127 + ->group('a.id')
  128 + ->select();
  129 +// dump(collection($peopleData)->toArray());die;
  130 + if($peopleData) {
  131 + $responseData['people']['title'] = array_column($peopleData,'title');
  132 + $responseData['people']['value'] = array_column($peopleData,'value');
  133 + }
  134 + $this->success('',null,$responseData);
  135 + }
  136 + $collegeList = (new College())->field('college_name,id')->where(['school_id' => SCHOOL_ID,'is_college' => 1])->select();
  137 + $this->assignconfig('collegeList',$collegeList);
  138 + return $this->view->fetch();
  139 + }
  140 +
  141 +
  142 + public function getCollegeData()
  143 + {
  144 + $collegeId = request()->param('college_id');
  145 + $result = ['match_title' => '','title' => [],'val' => []];
  146 + $data = Db::name('project_type')->alias('a')
  147 + ->field('a.name as title,count(b.id) as value')
  148 + ->join('project_register b','a.id = b.project_type','left')
  149 + ->join('user c','b.user_id = c.id and c.college = '.$collegeId,'left')
  150 + ->where(['a.container_id' => $this->containerId])
  151 + ->group('a.id')
  152 + ->select();
  153 + if($data) {
  154 + $result['title'] = array_column($data,'title');
  155 + $result['val'] = array_column($data,'value');
  156 + }
  157 +
  158 + $this->success('',null,$result);
  159 + }
  160 +
  161 +
  162 +
  163 +
100 } 164 }
@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 <div id="toolbar" class="toolbar"> 9 <div id="toolbar" class="toolbar">
10 <a href="javascript:;" class="btn btn-primary btn-refresh" title="刷新"><i class="fa fa-refresh"></i> </a> 10 <a href="javascript:;" class="btn btn-primary btn-refresh" title="刷新"><i class="fa fa-refresh"></i> </a>
11 <a href="javascript:;" class="btn btn-danger btn-export" title="{:__('Export')}" id="btn-export" ><i></i> {:__('Export')}</a> 11 <a href="javascript:;" class="btn btn-danger btn-export" title="{:__('Export')}" id="btn-export" ><i></i> {:__('Export')}</a>
  12 + <a href="javascript:;" class="btn btn-danger" title="{:__('统计')}" id="btn-statistics" ><i></i> {:__('统计')}</a>
12 </div> 13 </div>
13 <table id="table" 14 <table id="table"
14 class="table table-striped table-bordered table-hover table-nowrap" 15 class="table table-striped table-bordered table-hover table-nowrap"
  1 +<link rel="stylesheet" href="__CDN__/assets/ele/element/element.css">
  2 +<script src="__CDN__/assets/ele/vue.js"></script>
  3 +<script src="__CDN__/assets/ele/element/element.js"></script>
  4 +<script src="__CDN__/assets/ele/Sortable.min.js"></script>
  5 +<script src="__CDN__/assets/ele/vuedraggable.js"></script>
  6 +<script src="__CDN__/assets/ele/moment.js"></script>
  7 +<div id="app">
  8 + <template>
  9 + <div class="box-body">
  10 + <div id="group" style="height: 600px; width: 1200px;"></div>
  11 + </div>
  12 + <div class="box-body">
  13 + <div id="people" style="height: 600px; width: 1200px;"></div>
  14 + </div>
  15 +
  16 + <div class="box-body" style=" height: 600px; width: 1200px;">
  17 + <template>
  18 + <el-select v-model="statistics_val" @change="getData" placeholder="请选择学院">
  19 + <el-option
  20 + v-for="item in collegeList"
  21 + :key="item.id"
  22 + :label="item.college_name"
  23 + :value="item.id">
  24 + </el-option>
  25 + </el-select>
  26 + </template>
  27 + <div id="college" style="height: 600px; width: 1200px;"></div>
  28 + </div>
  29 + </template>
  30 +</div>
1 -define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) { 1 +
  2 +
  3 +
  4 +
  5 +
  6 +define(['jquery', 'bootstrap', 'backend', 'form', 'table','echarts', 'echarts-theme'], function ($, undefined, Backend, Form, Table, Echarts) {
2 var Controller = { 7 var Controller = {
3 index: function () { 8 index: function () {
4 // 初始化表格参数配置 9 // 初始化表格参数配置
@@ -94,13 +99,266 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefin @@ -94,13 +99,266 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefin
94 }); 99 });
95 //导出功能 100 //导出功能
96 $(document).on("click", ".btn-export", function () { 101 $(document).on("click", ".btn-export", function () {
97 - console.log("导出功能");  
98 //以后可以添加检索条件 location.search 102 //以后可以添加检索条件 location.search
99 top.location.href="/school/project_summary/export"; 103 top.location.href="/school/project_summary/export";
100 }); 104 });
  105 + //统计查看
  106 + $(document).on("click", "#btn-statistics", function () {
  107 + Fast.api.open('/school/project_summary/statistics','统计',{area: ['75%', '70%'],});
  108 + });
101 // 为表格绑定事件 109 // 为表格绑定事件
102 Table.api.bindevent(table); 110 Table.api.bindevent(table);
103 }, 111 },
  112 + statistics: function() {
  113 + var vm = new Vue({
  114 + el:"#app",
  115 + data() {
  116 + return {
  117 + statistics_val:'',
  118 + collegeList:[],
  119 + match_title:'',
  120 + title:[],
  121 + }
  122 + },
  123 + mounted() {
  124 + this.collegeList = Config.collegeList;
  125 + this.statistics();
  126 + },
  127 + methods: {
  128 + statistics:function() {
  129 + var _this = this;
  130 + //请求数据
  131 + $.ajax({
  132 + url:'/school/project_summary/statistics',
  133 + type:'post',
  134 + dataType:'json',
  135 + success:function(res){
  136 + if(res.code != 0) {
  137 + _this.match_title = res.data.match_title;
  138 + _this.title = res.data.group.title;
  139 + var Group = Echarts.init(document.getElementById('group')),
  140 + people = Echarts.init(document.getElementById('people')),
  141 + college = Echarts.init(document.getElementById('college'));
  142 + var groupOption = {
  143 + title: {
  144 + x:'center',
  145 + text: res.data.match_title + '【各项目类型报名组数统计】',
  146 + },
  147 + xAxis: {
  148 + type: 'category',
  149 + data: res.data.group.title,
  150 + axisTick: {
  151 + alignWithLabel: true
  152 + },
  153 + axisLabel: {
  154 + interval:0,
  155 + rotate:40//角度顺时针计算的
  156 + },
  157 + max:function (value) {
  158 + if (value.max < 8 ){
  159 + value.max = 8;
  160 + } else {
  161 + value.max = value.max;
  162 + }
  163 + return value.max;
  164 + },
  165 + },
  166 + grid: { bottom: "35%" },
  167 + yAxis: {
  168 + type : 'value',
  169 + axisLine: {
  170 + lineStyle: {
  171 + color: "#272822"
  172 + }
  173 + }
  174 + },
  175 + series: [{
  176 + data:res.data.group.value,
  177 + type: 'bar',
  178 + itemStyle: {
  179 + normal: {
  180 + label: {
  181 + show: true, //开启显示
  182 + position: 'top', //在上方显示
  183 + textStyle: { //数值样式
  184 + color: '#AAAAAA',
  185 + fontSize: 12
  186 + }
  187 + }
  188 + }
  189 + },
  190 + }]
  191 + };
  192 + var peopleOption = {
  193 + title: {
  194 + x:'center',
  195 + text: res.data.match_title + '【各项目类型报名人数统计】',
  196 + },
  197 + xAxis: {
  198 + type: 'category',
  199 + data: res.data.people.title,
  200 + axisTick: {
  201 + alignWithLabel: true
  202 + },
  203 + axisLabel: {
  204 + interval:0,
  205 + rotate:40//角度顺时针计算的
  206 + },
  207 + max:function (value) {
  208 + if (value.max < 8 ){
  209 + value.max = 8;
  210 + } else {
  211 + value.max = value.max;
  212 + }
  213 + return value.max;
  214 + },
  215 + },
  216 + grid: { bottom: "35%" },
  217 + yAxis: {
  218 + type : 'value',
  219 + axisLine: {
  220 + lineStyle: {
  221 + color: "#272822"
  222 + }
  223 + }
  224 + },
  225 + series: [{
  226 + data:res.data.people.value,
  227 + type: 'bar',
  228 + itemStyle: {
  229 + normal: {
  230 + label: {
  231 + show: true, //开启显示
  232 + position: 'top', //在上方显示
  233 + textStyle: { //数值样式
  234 + color: '#AAAAAA',
  235 + fontSize: 12
  236 + }
  237 + }
  238 + }
  239 + },
  240 + }]
  241 + };
  242 + var collegeOption = {
  243 + title: {
  244 + x:'center',
  245 + text: res.data.match_title + '【各学院项目报名组统计】',
  246 + },
  247 + xAxis: {
  248 + type: 'category',
  249 + data: _this.title,
  250 + axisTick: {
  251 + alignWithLabel: true
  252 + },
  253 + axisLabel: {
  254 + interval:0,
  255 + rotate:40//角度顺时针计算的
  256 + },
  257 + max:function (value) {
  258 + if (value.max < 8 ){
  259 + value.max = 8;
  260 + } else {
  261 + value.max = value.max;
  262 + }
  263 + return value.max;
  264 + },
  265 + },
  266 + grid: { bottom: "35%" },
  267 + yAxis: {
  268 + type : 'value',
  269 + axisLine: {
  270 + lineStyle: {
  271 + color: "#272822"
  272 + }
  273 + }
  274 + },
  275 + series: [{
  276 + data:[],
  277 + type: 'bar',
  278 + itemStyle: {
  279 + normal: {
  280 + label: {
  281 + show: true, //开启显示
  282 + position: 'top', //在上方显示
  283 + textStyle: { //数值样式
  284 + color: '#AAAAAA',
  285 + fontSize: 12
  286 + }
  287 + }
  288 + }
  289 + },
  290 + }]
  291 + };
  292 + Group.setOption(groupOption);
  293 + people.setOption(peopleOption);
  294 + college.setOption(collegeOption);
  295 + }
  296 + }
  297 + })
  298 + },
  299 + getData:function(val) {
  300 + var _this = this;
  301 + $.ajax({
  302 + url:'/school/project_summary/getCollegeData',
  303 + type:'post',
  304 + data:{college_id:val},
  305 + dataType:'json',
  306 + success:function(res){
  307 + if(res.code != 0) {
  308 + var college = Echarts.init(document.getElementById('college'));
  309 + var collegeOption = {
  310 + title: {
  311 + x:'center',
  312 + text: _this.match_title + '【各学院项目报名组统计】',
  313 + subtext: '',
  314 + },
  315 + xAxis: {
  316 + type: 'category',
  317 + data: res.data.title,
  318 + axisTick: {
  319 + alignWithLabel: true
  320 + },
  321 + axisLabel: {
  322 + interval:0,
  323 + rotate:40//角度顺时针计算的
  324 + },
  325 + },
  326 + grid: { bottom: "35%" },
  327 + yAxis: {
  328 + type : 'value',
  329 + axisLine: {
  330 + lineStyle: {
  331 + color: "#272822"
  332 + }
  333 + }
  334 + },
  335 + series: [{
  336 + data:res.data.val,
  337 + type: 'bar',
  338 + itemStyle: {
  339 + normal: {
  340 + label: {
  341 + show: true, //开启显示
  342 + position: 'top', //在上方显示
  343 + textStyle: { //数值样式
  344 + color: '#AAAAAA',
  345 + fontSize: 12
  346 + }
  347 + }
  348 + }
  349 + },
  350 + }]
  351 + };
  352 + college.setOption(collegeOption);
  353 + }
  354 + }
  355 + });
  356 + },
  357 + },
  358 +
  359 + })
  360 +
  361 + },
104 api: { 362 api: {
105 bindevent: function () { 363 bindevent: function () {
106 Form.api.bindevent($("form[role=form]")); 364 Form.api.bindevent($("form[role=form]"));