IndexController.php
17.6 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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\home\controller;
use think\Db;
use think\Validate;
use cmf\controller\RestBaseController;
use app\portal\model\UserModel;
/**
* @title 首页
*/
class IndexController extends RestBaseController
{
/**
* @title 领导,员工首页
* @description 接口说明
* @author 开发者
* @url /api/home/index/index
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:project_id type:int require:0 default: other desc:项目id(员工传字段)
*
* @return is_work:上班状态(1:上班,2:下班)
* @return identity:身份(1:甲方员工,2:乙方员工,3:甲方领导,4:乙方领导,5:甲方总领导)
* @return company_name:公司名称
* @return logo:公司logo
* @return service:企业拥有的服务@
* @service id:服务id(1:日检,2:月检,3:改造,4:维修,5:培训,6:演习,7:年检,100:使用说明) name:服务名称 icon:图标路径
* @return run_time:0 运行时间
* @return is_finish:未检修数量(甲乙方员工有此字段)
* @return tips:提示语
*/
public function index(){
if($this->request->isGet()){
$common = new CommonController();
$res = $common->getIndexData();
//获取未完成数量
$user = $common->getUserIdentity();
//如果是员工
if($user['identity'] == config('site.a_staff') || $user['identity'] == config('site.b_staff')){
$project_id = $this->request->get('project_id');
$rule = config('site.project_id');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['project_id'=>$project_id])) {
$this->error($validate->getError());
}
$arr = $common->getInsList($project_id);
$res['is_finish'] = $arr['is_finish'];
}
$res['tips'] = config('site.tips');
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 总领导首页
* @description 接口说明
* @author 开发者
* @url /api/home/index/chiefLeaderIndex
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:project_id type:int require:0 default: other desc:项目id
*
* @return data: @
* @data id:公司id company_name:总公司名称 logo:总公司logo address:地区 run_time:运行时间 service:服务列表@
* @service id:服务id(1:日检,2:月检,3:改造,4:维修,5:培训,6:演习,7:年检,100:使用说明) name:服务名称 icon:图标路径 english_name:英文名称
* @return tips:提示语
*/
public function chiefLeaderIndex(){
if($this->request->isGet()){
$project_id = $this->request->get('project_id');
$field = 'id,company_name_head company_name,address,head_logo logo,u_ls_id';
$common = new CommonController();
//查询甲方公司id
$company = $common->getCompanyAid($project_id);
$res = $common->getTotalCompany(['id'=>$company['a_cid']],$field);
$host = config('site.host');
foreach($res as &$value){
//查找企业拥有的服务
$data['c_id'] = $value['id'];
$rule = $common->getRule($data,'',1);
$value['service'] = $rule;
foreach($value['service'] as &$value1){
if($value1['id'] != 100){
$value1['name'] = $value1['name'].'报表';
}
}
$value['logo'] = $host.'/'.$value['logo'];
//总公司运行时间
$time = $common->getHeadTime(['u_ls_id'=>['like','%,'.$this->userId.',%']]);
$value['run_time'] = $common->getRunTime($time['create_time_head']);
}
$arr['data'] = $res;
$arr['tips'] = config('site.tips');
$this->success('成功',$arr);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 获取视频第一帧
* @description 接口说明
* @author 开发者
* @url /api/home/index/getVideoCover
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:mp4_src type:string require:1 default: other desc:MP4文件路径
*
* @return src:视频第一帧图片路径
*/
public function getVideoCover() {
if($this->request->isGet()){
$mp4_src = $this->request->get('mp4_src');
$rule = config('site.mp4_src');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['mp4_src'=>$mp4_src])) {
$this->error($validate->getError());
}
//自己服务器
// $ffm_peg = FFMpeg::create([
// 'ffmpeg.binaries' => '/usr/bin/ffmpeg',
// 'ffprobe.binaries' => '/usr/bin/ffprobe'
// ]);
// $host = config('site.host');
// $time = time();
// $src = str_replace($host,'',$mp4_src);
// //打开文件路径
// $video = $ffm_peg->open(ROOT_PATH.'public/'.$src);
// //截取大小
// $video->filters()->resize(new \FFMpeg\Coordinate\Dimension(320, 240))->synchronize();
// //第一帧图片
// $video->frame(TimeCode::fromSeconds(1))->save(ROOT_PATH.'public/pegImg/'.$time.'.jpg');
// $src_jpg = $host.'/pegImg/'.$time.'.jpg';
//七牛云服务器
$this->success('成功',['src'=>$mp4_src.'?vframe/jpg/offset/1']);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 极光推送
* @description 接口说明
* @author 开发者
* @url /api/home/index/jpush
* @method GET
*
* @header name:token require:1 default: desc:header
* @param name:registration_id type:string require:1 default: other desc:registration_id
*
*/
public function jpush(){
if($this->request->isGet()){
$registration_id = $this->request->get('registration_id');
$userModel = new UserModel();
$userModel->where('id',$this->userId)->update(['registration_id'=>$registration_id]);
$this->success('成功');
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 员工项目列表
* @description 接口说明
* @author 开发者
* @url /api/home/index/projectList
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @return project_id:项目id
* @return project_name:项目名称
*/
public function projectList(){
if($this->request->isGet()){
$common = new CommonController();
//获取未完成数量
$user = $common->getUserIdentity();
//如果是员工
$res = [];
$uid = ','.$this->userId.',';
if(isset($user['identity'])){
if($user['identity'] == config('site.a_staff')){
//甲方
$res = $common->getProjectByUid(['a_sid'=>['like','%'.$uid.'%']]);
}else if($user['identity'] == config('site.b_staff')){
//乙方
$res = $common->getProjectByUid(['b_sid'=>['like','%'.$uid.'%']]);
}
$this->success('成功',$res);
}
$this->error('请联系管理员分配公司!');
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 员工项目列表1
* @description 接口说明
* @author 开发者
* @url /api/home/index/projectsList
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @return project_a:字母排序['b','c']
* @return project_n:项目名称@
* @project_n acronym:字母 project:项目列表@
* @project project_id:项目id project_name:项目名称
*/
public function projectsList(){
if($this->request->isGet()){
$common = new CommonController();
//获取未完成数量
$user = $common->getUserIdentity();
//如果是员工
$res = [];
$arr2['project_a'] = [];
$arr2['project_n'] = [];
$uid = ','.$this->userId.',';
if(isset($user['identity'])){
if($user['identity'] == config('site.a_staff')){
//甲方
$res = $common->getProjectByUid(['a_sid'=>['like','%'.$uid.'%']]);
}else if($user['identity'] == config('site.b_staff')){
//乙方
$res = $common->getProjectByUid(['b_sid'=>['like','%'.$uid.'%']]);
}
$arr2 = [];
if($res){
$acronym = [];
foreach($res as $key=>$value){
$acronym[$key] = $common->getFirstCharter($value['project_name']);
}
$acronym =array_values(array_unique($acronym));
sort($acronym);
$arr1 = [];
foreach($acronym as $a_key=>$a_value){
$k = 0;
$arr1[$a_key]['acronym'] = $a_value;
foreach($res as $r_value){
$k+=0;
$first = $common->getFirstCharter($r_value['project_name']);
if($first == $a_value){
$arr1[$a_key]['project'][$k] = $r_value;
$k++;
}
}
}
if(in_array('#',$acronym)){
$count = count($acronym);
foreach ($arr1 as $key=>$a_value){
if($a_value['acronym'] == '#'){
$arr1[$count-1] = $a_value;
}else{
$arr1[$key-1] = $a_value;
}
}
foreach($acronym as $key1=>$a_value1){
if($a_value1 == '#'){
$acronym[$count-1] = $a_value1;
}else{
$acronym[$key1-1] = $a_value1;
}
}
}
$arr2['project_a'] = $acronym;
$arr2['project_n'] = $arr1;
}
$this->success('成功',$arr2);
}
$this->error('请联系管理员分配公司!');
}else{
$this->error('请求方式错误!');
}
}
/**
* @title IOS更新版本
* @description 接口说明
* @author 开发者
* @url /api/home/index/updateIOSVersion
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:version_number type:string require:1 default: other desc:版本号
*
* @return status:状态(0:无更新,1:有更新-强制,2:有更新-非强制)
* @return update_content:更新内容
*/
public function updateIOSVersion(){
if($this->request->isGet()){
$version_number = $this->request->get('version_number');
$rule = config('site.version');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['version_number'=>$version_number])) {
$this->error($validate->getError());
}
$common = new CommonController();
$res = $common->getVersion(0,'id,last_version,update_content,force_update');
if($res){
if (version_compare($res['last_version'], $version_number, ">")) {
$data['update_content'] = $res['update_content'];
if($res['force_update'] == 0){
//强制更新
$data['status'] = 1;
$this->success('成功',$data);
}else{
//不强制更新
$data['status'] = 2;
$this->success('成功',$data);
}
}else{
$this->success('成功',['status'=>0]);
}
}
$this->success('成功',['status'=>0]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title Android更新版本
* @description 接口说明
* @author 开发者
* @url /api/home/index/updateAndroidVersion
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:version_number type:string require:1 default: other desc:版本号
*
* @return status:状态(0:无更新,1:有更新-强制,2:有更新-非强制)
* @return update_content:更新内容
* @return soft_size:软件大小
* @return download_url:下载地址
* @return last_version:最新版本号
*/
public function updateAndroidVersion(){
if($this->request->isGet()){
$version_number = $this->request->get('version_number');
$rule = config('site.version');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['version_number'=>$version_number])) {
$this->error($validate->getError());
}
$common = new CommonController();
$res = $common->getVersion(1,'id,last_version,update_content,force_update,soft_size,download_url');
if($res){
if (version_compare($res['last_version'], $version_number, ">")) {
$data = [
'update_content'=>$res['update_content'],
'soft_size'=>$res['soft_size'],
'download_url'=>$res['download_url'],
'last_version'=>$res['last_version'],
];
if($res['force_update'] == 0){
//强制更新
$data['status'] = 1;
$this->success('成功',$data);
}else{
//不强制更新
$data['status'] = 2;
$this->success('成功',$data);
}
}else{
$this->success('成功',['status'=>0]);
}
}
$this->success('成功',['status'=>0]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 获取甲方员工列表
* @description 接口说明
* @author 开发者
* @url /api/home/index/getStaffListA
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:project_id type:inter require:1 default: other desc:项目id
*
* @return data:数据@
* @data id:负责人id user_login:负责人姓名 position:职位
*/
public function getStaffListA(){
if($this->request->isGet()){
$project_id = $this->request->get('project_id');
$rule = config('site.project_id');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['project_id'=>$project_id])) {
$this->error($validate->getError());
}
$common = new CommonController();
//根据项目id获取甲方uid
$users = $common->getUserByProject($project_id,'id,a_sid');
$this->success('成功',['data'=>$users]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 获取乙方员工列表
* @description 接口说明
* @author 开发者
* @url /api/home/index/getStaffListB
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:project_id type:inter require:1 default: other desc:项目id
*
* @return data:数据@
* @data id:负责人id user_login:负责人姓名 position:职位
*/
public function getStaffListB(){
if($this->request->isGet()){
$project_id = $this->request->get('project_id');
$rule = config('site.project_id');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['project_id'=>$project_id])) {
$this->error($validate->getError());
}
$common = new CommonController();
//根据项目id获取甲方uid
$users = $common->getUserByProjectId($project_id,'id,b_sid',1);
$this->success('成功',['data'=>$users]);
}else{
$this->error('请求方式错误!');
}
}
}