作者 曹东东

统计

... ... @@ -4,6 +4,7 @@ namespace app\school\controller;
use app\common\controller\DoubleBase;
use app\school\controller\project_common\ProjectData;
use app\school\model\basic\College;
use app\school\model\project_common\ProjectRegister;
use think\Db;
use fast\Export;
... ... @@ -97,4 +98,67 @@ class ProjectSummary extends DoubleBase
$this->error('导出失败,稍后请重新尝试');
}
}
public function statistics()
{
if($this->request->isAjax()) {
// dump($this->containerId);die;
$matchInfo = Db::name('project_container')->where(['id' => $this->containerId])->find();
$responseData = ['match_title'=>$matchInfo['container_name'],'group'=>['title' => [],'value'=>[]],'college_people' => [],'people'=>['title' => [],'value'=>[]]];
$collegeModel = new \app\school\model\basic\College();
$typeGroup = Db::name('project_type')->alias('a')
->field('a.name as title,count(b.id) as value')
->join('project_register b','a.id = b.project_type','left')
->where(['a.container_id' => $this->containerId])
->group('a.id')
->select();
if($typeGroup) {
$responseData['group']['title'] = array_column($typeGroup,'title');
$responseData['group']['value'] = array_column($typeGroup,'value');
}
$peopleData = Db::name('project_type')->alias('a')
->field('a.name as title,count(c.id) as value')
->join('project_register b','a.id = b.project_type','left')
->join('members c','b.id = c.item_id and c.member_source = 2 and member_type = 1','left')
->where(['a.container_id' => $this->containerId])
->group('a.id')
->select();
// dump(collection($peopleData)->toArray());die;
if($peopleData) {
$responseData['people']['title'] = array_column($peopleData,'title');
$responseData['people']['value'] = array_column($peopleData,'value');
}
$this->success('',null,$responseData);
}
$collegeList = (new College())->field('college_name,id')->where(['school_id' => SCHOOL_ID,'is_college' => 1])->select();
$this->assignconfig('collegeList',$collegeList);
return $this->view->fetch();
}
public function getCollegeData()
{
$collegeId = request()->param('college_id');
$result = ['match_title' => '','title' => [],'val' => []];
$data = Db::name('project_type')->alias('a')
->field('a.name as title,count(b.id) as value')
->join('project_register b','a.id = b.project_type','left')
->join('user c','b.user_id = c.id and c.college = '.$collegeId,'left')
->where(['a.container_id' => $this->containerId])
->group('a.id')
->select();
if($data) {
$result['title'] = array_column($data,'title');
$result['val'] = array_column($data,'value');
}
$this->success('',null,$result);
}
}
\ No newline at end of file
... ...
... ... @@ -9,6 +9,7 @@
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="刷新"><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-danger btn-export" title="{:__('Export')}" id="btn-export" ><i></i> {:__('Export')}</a>
<a href="javascript:;" class="btn btn-danger" title="{:__('统计')}" id="btn-statistics" ><i></i> {:__('统计')}</a>
</div>
<table id="table"
class="table table-striped table-bordered table-hover table-nowrap"
... ...
<link rel="stylesheet" href="__CDN__/assets/ele/element/element.css">
<script src="__CDN__/assets/ele/vue.js"></script>
<script src="__CDN__/assets/ele/element/element.js"></script>
<script src="__CDN__/assets/ele/Sortable.min.js"></script>
<script src="__CDN__/assets/ele/vuedraggable.js"></script>
<script src="__CDN__/assets/ele/moment.js"></script>
<div id="app">
<template>
<div class="box-body">
<div id="group" style="height: 600px; width: 1200px;"></div>
</div>
<div class="box-body">
<div id="people" style="height: 600px; width: 1200px;"></div>
</div>
<div class="box-body" style=" height: 600px; width: 1200px;">
<template>
<el-select v-model="statistics_val" @change="getData" placeholder="请选择学院">
<el-option
v-for="item in collegeList"
:key="item.id"
:label="item.college_name"
:value="item.id">
</el-option>
</el-select>
</template>
<div id="college" style="height: 600px; width: 1200px;"></div>
</div>
</template>
</div>
... ...
define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) {
define(['jquery', 'bootstrap', 'backend', 'form', 'table','echarts', 'echarts-theme'], function ($, undefined, Backend, Form, Table, Echarts) {
var Controller = {
index: function () {
// 初始化表格参数配置
... ... @@ -94,13 +99,266 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefin
});
//导出功能
$(document).on("click", ".btn-export", function () {
console.log("导出功能");
//以后可以添加检索条件 location.search
top.location.href="/school/project_summary/export";
});
//统计查看
$(document).on("click", "#btn-statistics", function () {
Fast.api.open('/school/project_summary/statistics','统计',{area: ['75%', '70%'],});
});
// 为表格绑定事件
Table.api.bindevent(table);
},
statistics: function() {
var vm = new Vue({
el:"#app",
data() {
return {
statistics_val:'',
collegeList:[],
match_title:'',
title:[],
}
},
mounted() {
this.collegeList = Config.collegeList;
this.statistics();
},
methods: {
statistics:function() {
var _this = this;
//请求数据
$.ajax({
url:'/school/project_summary/statistics',
type:'post',
dataType:'json',
success:function(res){
if(res.code != 0) {
_this.match_title = res.data.match_title;
_this.title = res.data.group.title;
var Group = Echarts.init(document.getElementById('group')),
people = Echarts.init(document.getElementById('people')),
college = Echarts.init(document.getElementById('college'));
var groupOption = {
title: {
x:'center',
text: res.data.match_title + '【各项目类型报名组数统计】',
},
xAxis: {
type: 'category',
data: res.data.group.title,
axisTick: {
alignWithLabel: true
},
axisLabel: {
interval:0,
rotate:40//角度顺时针计算的
},
max:function (value) {
if (value.max < 8 ){
value.max = 8;
} else {
value.max = value.max;
}
return value.max;
},
},
grid: { bottom: "35%" },
yAxis: {
type : 'value',
axisLine: {
lineStyle: {
color: "#272822"
}
}
},
series: [{
data:res.data.group.value,
type: 'bar',
itemStyle: {
normal: {
label: {
show: true, //开启显示
position: 'top', //在上方显示
textStyle: { //数值样式
color: '#AAAAAA',
fontSize: 12
}
}
}
},
}]
};
var peopleOption = {
title: {
x:'center',
text: res.data.match_title + '【各项目类型报名人数统计】',
},
xAxis: {
type: 'category',
data: res.data.people.title,
axisTick: {
alignWithLabel: true
},
axisLabel: {
interval:0,
rotate:40//角度顺时针计算的
},
max:function (value) {
if (value.max < 8 ){
value.max = 8;
} else {
value.max = value.max;
}
return value.max;
},
},
grid: { bottom: "35%" },
yAxis: {
type : 'value',
axisLine: {
lineStyle: {
color: "#272822"
}
}
},
series: [{
data:res.data.people.value,
type: 'bar',
itemStyle: {
normal: {
label: {
show: true, //开启显示
position: 'top', //在上方显示
textStyle: { //数值样式
color: '#AAAAAA',
fontSize: 12
}
}
}
},
}]
};
var collegeOption = {
title: {
x:'center',
text: res.data.match_title + '【各学院项目报名组统计】',
},
xAxis: {
type: 'category',
data: _this.title,
axisTick: {
alignWithLabel: true
},
axisLabel: {
interval:0,
rotate:40//角度顺时针计算的
},
max:function (value) {
if (value.max < 8 ){
value.max = 8;
} else {
value.max = value.max;
}
return value.max;
},
},
grid: { bottom: "35%" },
yAxis: {
type : 'value',
axisLine: {
lineStyle: {
color: "#272822"
}
}
},
series: [{
data:[],
type: 'bar',
itemStyle: {
normal: {
label: {
show: true, //开启显示
position: 'top', //在上方显示
textStyle: { //数值样式
color: '#AAAAAA',
fontSize: 12
}
}
}
},
}]
};
Group.setOption(groupOption);
people.setOption(peopleOption);
college.setOption(collegeOption);
}
}
})
},
getData:function(val) {
var _this = this;
$.ajax({
url:'/school/project_summary/getCollegeData',
type:'post',
data:{college_id:val},
dataType:'json',
success:function(res){
if(res.code != 0) {
var college = Echarts.init(document.getElementById('college'));
var collegeOption = {
title: {
x:'center',
text: _this.match_title + '【各学院项目报名组统计】',
subtext: '',
},
xAxis: {
type: 'category',
data: res.data.title,
axisTick: {
alignWithLabel: true
},
axisLabel: {
interval:0,
rotate:40//角度顺时针计算的
},
},
grid: { bottom: "35%" },
yAxis: {
type : 'value',
axisLine: {
lineStyle: {
color: "#272822"
}
}
},
series: [{
data:res.data.val,
type: 'bar',
itemStyle: {
normal: {
label: {
show: true, //开启显示
position: 'top', //在上方显示
textStyle: { //数值样式
color: '#AAAAAA',
fontSize: 12
}
}
}
},
}]
};
college.setOption(collegeOption);
}
}
});
},
},
})
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
... ...