Dashboard.php
13.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php
namespace app\admin\controller;
use think\Db;
use app\common\controller\Backend;
use think\Config;
/**
* 控制台
*
* @icon fa fa-dashboard
* @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
*/
class Dashboard extends Backend
{
/**
* 查看
*/
public function index()
{
$seventtime = \fast\Date::unixtime('day', -7);
$paylist = $createlist = [];
for ($i = 0; $i < 7; $i++) {
$day = date("Y-m-d", $seventtime + ($i * 86400));
$createlist[$day] = mt_rand(20, 200);
$paylist[$day] = mt_rand(1, mt_rand(1, $createlist[$day]));
}
$hooks = config('addons.hooks');
$uploadmode = isset($hooks['upload_config_init']) && $hooks['upload_config_init'] ? implode(',', $hooks['upload_config_init']) : 'local';
$addonComposerCfg = ROOT_PATH . '/vendor/karsonzhang/fastadmin-addons/composer.json';
Config::parse($addonComposerCfg, "json", "composer");
$config = Config::get("composer");
$addonVersion = isset($config['version']) ? $config['version'] : __('Unknown');
//月 起止时间戳
$start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
$end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
$map['createtime'] = ['between', [$start_time, $end_time]];
//报修总量
$BaoxiuArr = Db::name('baoxiudan')->where($map)->select();
$BaoxiuWancheng = Db::name('baoxiudan')->where('type', 2)->where($map)->select();
$BaoxiuWeiWancheng = Db::name('baoxiudan')->where('type', 1)->where($map)->select();
$Round = round(count($BaoxiuWancheng) / count($BaoxiuArr) * 100, 2);
$WRound = round(count($BaoxiuWeiWancheng) / count($BaoxiuArr) * 100, 2);
//监控系统
$jiankong = Db::name('baoxiudan')->where('system', 1)->where($map)->select();
//通信系统
$tongxin = Db::name('baoxiudan')->where('system', 2)->where($map)->select();
//供配电系统
$peidian = Db::name('baoxiudan')->where('system', 3)->where($map)->select();
//计重设备
$jizhong = Db::name('baoxiudan')->where('system', 4)->where($map)->select();
//收费系统
$shoufei = Db::name('baoxiudan')->where('system', 5)->where($map)->select();
$this->view->assign([
'baoxiunum' => count($BaoxiuArr),
'baoxiu' => $Round . '%',
'wbaoxiu' => $WRound . '%',
'jiankong' => count($jiankong),
'tongxin' => count($tongxin),
'peidian' => count($peidian),
'jizhong' => count($jizhong),
'shoufei' => count($shoufei),
'totaluser' => 35200,
'totalviews' => 219390,
'totalorder' => 32143,
'totalorderamount' => 174800,
'todayuserlogin' => 321,
'todayusersignup' => 430,
'todayorder' => 2324,
'unsettleorder' => 132,
'sevendnu' => '80%',
'sevendau' => '32%',
'paylist' => $paylist,
'createlist' => $createlist,
'addonversion' => $addonVersion,
'uploadmode' => $uploadmode,
]);
$ZhanDianArr = Db::name('zhandian')->select();
foreach ($ZhanDianArr as $k => $v) {
$data[$k]['id'] = $v['id'];
$data[$k]['zhandian_name'] = $v['zhandian'];
$BaoXiuZhandian = Db::name('baoxiudan')->where('zhandian_id', $v['id'])->where($map)->select();
$BaoxiuWancheng = Db::name('baoxiudan')->where('zhandian_id', $v['id'])->where($map)->where('type', 2)->select();
$BaoxiuWeiWancheng = Db::name('baoxiudan')->where('zhandian_id', $v['id'])->where($map)->where('type', 1)->select();
if (empty($BaoXiuZhandian)) {
$data[$k]['baoxiu_num'] = 0;
$data[$k]['BaoXiuStr'] = '';
$data[$k]['Round'] = '无记录';
$data[$k]['WRound'] = '无记录';
} else {
$data[$k]['baoxiu_num'] = count($BaoXiuZhandian);
foreach ($BaoXiuZhandian as $k1 => $v1) {
$StrArr[$k1] = $v1['colum'];
}
$Round = round(count($BaoxiuWancheng) / count($BaoXiuZhandian) * 100, 2);
$WRound = round(count($BaoxiuWeiWancheng) / count($BaoXiuZhandian) * 100, 2);
$data[$k]['BaoXiuStr'] = implode($StrArr, ',');
$data[$k]['Round'] = $Round . '%';
$data[$k]['WRound'] = $WRound . '%';
}
}
$this->view->assign("row", $data);
return $this->view->fetch();
}
//自定义导出
public function exportDayInner()
{
//月 起止时间戳
$start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
$end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
$map['createtime'] = ['between', [$start_time, $end_time]];
$ZhanDianArr = Db::name('zhandian')->select();
foreach ($ZhanDianArr as $k => $v) {
$data[$k]['id'] = $v['id'];
$data[$k]['zhandian_name'] = $v['zhandian'];
$BaoXiuZhandian = Db::name('baoxiudan')->where('zhandian_id', $v['id'])->where($map)->select();
$BaoxiuWancheng = Db::name('baoxiudan')->where('zhandian_id', $v['id'])->where($map)->where('type', 2)->select();
$BaoxiuWeiWancheng = Db::name('baoxiudan')->where('zhandian_id', $v['id'])->where($map)->where('type', 1)->select();
if (empty($BaoXiuZhandian)) {
$data[$k]['baoxiu_num'] = 0;
$data[$k]['BaoXiuStr'] = '';
$data[$k]['Round'] = '无记录';
$data[$k]['WRound'] = '无记录';
} else {
$data[$k]['baoxiu_num'] = count($BaoXiuZhandian);
foreach ($BaoXiuZhandian as $k1 => $v1) {
$StrArr[$k1] = $v1['colum'];
}
$Round = round(count($BaoxiuWancheng) / count($BaoXiuZhandian) * 100, 2);
$WRound = round(count($BaoxiuWeiWancheng) / count($BaoXiuZhandian) * 100, 2);
$data[$k]['BaoXiuStr'] = implode($StrArr, ',');
$data[$k]['Round'] = $Round . '%';
$data[$k]['WRound'] = $WRound . '%';
}
}
$table = '';
$table .= "<table>
<thead>
<tr>
<th class='name'>站点</th>
<th class='name'>报修单数量</th>
<th class='name'>报修完成率</th>
<th class='name'>报修未完成率</th>
<th class='name'>故障设备名称</th>
</tr>
</thead>
<tbody>";
foreach ($data as $v) {
$table .= "<tr>
<td class='name'>{$v['zhandian_name']}</td>
<td class='name'>{$v['baoxiu_num']}</td>
<td class='name'>{$v['Round']}</td>
<td class='name'>{$v['WRound']}</td>
<td class='name'>{$v['BaoXiuStr']}</td>
</tr>";
}
$table .= "</tbody>
</table>";
//通过header头控制输出excel表格
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header('Content-Disposition:attachment;filename="入库明细表.xls"');
header("Content-Transfer-Encoding:binary");
$objPHPExcel = new \PHPExcel();
//设置保存版本格式
$objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel);
$objWriter->save('php://output');
// echo $table;
}
public function out(){
$result = Db::name('applet_user')->field('id,name,mobile,colleges')->order('id desc')->select();
$filename = "用户测评数据";
vendor('PHPExcel.PHPExcel');
$objPHPExcel = new \PHPExcel();
//设置保存版本格式
$objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel);
//设置表头
$objPHPExcel->getActiveSheet()->setCellValue('A1','id');
$objPHPExcel->getActiveSheet()->setCellValue('B1','姓名');
$objPHPExcel->getActiveSheet()->setCellValue('C1','手机');
$objPHPExcel->getActiveSheet()->setCellValue('D1','意向院校');
$objPHPExcel->getActiveSheet()->setCellValue('E1','测评分值');
$objPHPExcel->getActiveSheet()->setCellValue('F1','学历背景得分');
$objPHPExcel->getActiveSheet()->setCellValue('G1','企业背景得分');
$objPHPExcel->getActiveSheet()->setCellValue('H1','收入水平得分');
$objPHPExcel->getActiveSheet()->setCellValue('I1','发展潜力得分');
$objPHPExcel->getActiveSheet()->setCellValue('J1','管理经验得分');
$objPHPExcel->getActiveSheet()->setCellValue('K1','英语水平得分');
$objPHPExcel->getActiveSheet()->setCellValue('L1','背景优势');
$objPHPExcel->getActiveSheet()->setCellValue('M1','背景劣势');
$objPHPExcel->getActiveSheet()->setCellValue('N1','匹配院校');
//改变此处设置的长度数值
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(12);
//输出表格
$str = '用户未进行测评';
foreach ($result as $key => &$val) {
$count = Db::name('applet_answer')->where(['uid'=>$val['id'],'isdelete'=>0])->count();
$i=$key+2;//表格是从2开始的
if ($count>=1){
$row = SubjectService::getResult($val['id'],'');//score--1学历背景 2企业背景 3收入水平 4发展潜力 5管理经验 6英语水平
//优势
$advan = $row['advan'] ? implode('、',$row['advan']) : '暂无优势';
$inferi = $row['inferi'] ? implode('、',$row['inferi']) : '暂无劣势';
$colllist = $row['colllist'] ? implode('、',array_column($row['colllist'],'title')) : '无匹配院校';
//$score = Db::name('applet_answer')->where(['uid'=>$val['id'],'isdelete'=>0])->sum('score');
//dump($row);exit();
$objPHPExcel->getActiveSheet()->setCellValue('A'.$i,$val['id']);
$objPHPExcel->getActiveSheet()->setCellValue('B'.$i,$val['name']);
$objPHPExcel->getActiveSheet()->setCellValue('C'.$i,$val['mobile']);
$objPHPExcel->getActiveSheet()->setCellValue('D'.$i,$val['colleges']);
$objPHPExcel->getActiveSheet()->setCellValue('E'.$i,$row['totalscore']);
$objPHPExcel->getActiveSheet()->setCellValue('F'.$i,$row['score'][0]);
$objPHPExcel->getActiveSheet()->setCellValue('G'.$i,$row['score'][1]);
$objPHPExcel->getActiveSheet()->setCellValue('H'.$i,$row['score'][2]);
$objPHPExcel->getActiveSheet()->setCellValue('I'.$i,$row['score'][3]);
$objPHPExcel->getActiveSheet()->setCellValue('J'.$i,$row['score'][4]);
$objPHPExcel->getActiveSheet()->setCellValue('K'.$i,$row['score'][5]);
$objPHPExcel->getActiveSheet()->setCellValue('L'.$i,$advan);
$objPHPExcel->getActiveSheet()->setCellValue('M'.$i,$inferi);
$objPHPExcel->getActiveSheet()->setCellValue('N'.$i,$colllist);
}
else{
$objPHPExcel->getActiveSheet()->setCellValue('A'.$i,$val['id']);
$objPHPExcel->getActiveSheet()->setCellValue('B'.$i,$val['name']);
$objPHPExcel->getActiveSheet()->setCellValue('C'.$i,$val['mobile']);
$objPHPExcel->getActiveSheet()->setCellValue('D'.$i,$val['colleges']);
$objPHPExcel->getActiveSheet()->setCellValue('E'.$i,$str);
$objPHPExcel->getActiveSheet()->setCellValue('F'.$i,$str);
$objPHPExcel->getActiveSheet()->setCellValue('G'.$i,$str);
$objPHPExcel->getActiveSheet()->setCellValue('H'.$i,$str);
$objPHPExcel->getActiveSheet()->setCellValue('I'.$i,$str);
$objPHPExcel->getActiveSheet()->setCellValue('J'.$i,$str);
$objPHPExcel->getActiveSheet()->setCellValue('K'.$i,$str);
$objPHPExcel->getActiveSheet()->setCellValue('L'.$i,$str);
$objPHPExcel->getActiveSheet()->setCellValue('M'.$i,$str);
$objPHPExcel->getActiveSheet()->setCellValue('N'.$i,$str);
}
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
header('Content-Disposition:attachment;filename='.$filename.'.xls');
header("Content-Transfer-Encoding:binary");
$objWriter->save('php://output');
}
}