ProjectSummary.php
6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
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;
class ProjectSummary extends DoubleBase
{
protected $containerId = null;
protected $shopIdAutoCondition = false;
protected $model = null;
use ProjectData;
public function _initialize()
{
parent::_initialize();
$this->containerId = $_COOKIE['container_id'];
$this->model = new ProjectRegister();
}
public function index() {
if ($this->request->isAjax()) {
$map = [];
$filter = json_decode($this->request->get('filter'), true);
//自定义搜索条件
if(isset($filter['project_type'])) {
$map['a.project_type'] = $filter['project_type'];
}
if(isset($filter['project_level'])) {
$map['a.project_level'] = $filter['project_level'];
}
if(isset($filter['college_id'])) {
$map['u.college'] = $filter['college_id'];
}
if(isset($filter['username'])) {
$map['u.nickname'] = ['like',"%{$filter['username']}%"];
}
$map['a.project_status'] = ['IN', '0,1,2,3'];
if ($this->auth->rule_type == 1){
//所属学院或部门
$map['a.project_college'] = $this->auth->college_id;
}
$res = $this->projectData($map);
foreach ($res['rows'] as &$row) {
// 已经中期评审或者立项结题的项目状态为:已立项、已提交
if ('0' != $row['review_stage']) {
$row['check_stage'] = 3;
}
}
return $res;
}
return $this->view->fetch();
}
/**
* 导出数据(全部数据)
*/
public function export()
{
//获取sql 数量
$map = [];
$map['a.project_status'] = ['IN', '0,1,2,3'];
if ($this->auth->rule_type == 1){
//所属学院或部门
$map['a.project_college'] = $this->auth->college_id;
}
$result = $this->getExportSql($map);
$sqlInfo = collection($result)->toArray();
if($sqlInfo['total'] == 0){
$this->error('暂无可导出数据');
}
//开始导出
$export = new Export();
$export->setCount($sqlInfo['total']);
$export->setSql($sqlInfo['sql']);
$export->setFileName(time().'export');
$export->setDirName(date('Y-m-d'));
$export->setHeader(['Id','项目名称','项目编号','项目分类','项目所属学院','负责人姓名','负责人学号','负责人学院','负责人专业','项目级别','项目状态']);
$export->setFields('id,project_name,project_no,project_type_name,project_college,nickname,student_no,college_name,major_name,project_level,check_stage');
$exportRes = $export->out();
if($exportRes) {
$url = $export->getUrl();
header( "Content-Type: application/zip" );
header( "Content-Transfer-Encoding: Binary" );
header( "Content-Length: " . filesize ($url));
header( "Content-Disposition: attachment; filename=\"".basename ($url)."\"" );
readfile( $url);
exit ;
}else{
$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);
}
}