YearlyController.php
25.3 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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
<?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 app\portal\model\InsCheckModel;
use think\Db;
use think\Validate;
use cmf\controller\RestBaseController;
use app\portal\model\ProCheckModel;
use app\portal\model\CheckPointModel;
/**
* @title 项目年检
*/
class YearlyController extends RestBaseController
{
/**
* @title 乙方发起年检申请
* @description 接口说明
* @author 开发者
* @url /api/home/yearly/applyYearCheck
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:title type:string require:1 default: other desc:表头信息
* @param name:year_m_time type:int require:1 default: other desc:年检时间
* @param name:project_id type:int require:1 default: other desc:项目id
* @param name:address type:string require:1 default: other desc:年检地点
* @param name:remark type:string require:1 default: other desc:年检申请备注
* @param name:u_id type:inter require:1 default: other desc:指派甲方人员id
*/
public function applyYearCheck(){
if($this->request->isPost()){
$data = $this->request->post();
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.year_m_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$data['uid'] = $this->userId;
//单号
$data['number'] = $common->genOrderSn();
$data['create_time'] = time();
//指派人员uid
$data['h_uid'] = $data['u_id'];
unset($data['u_id']);
$proCheckModel = new ProCheckModel();
$res = $proCheckModel->create($data);
if($res){
//极光推送
//乙方发起,提醒指派甲方员工
$user_ids = [$data['h_uid']];
$content = config('site.check_content_add_b');
$registration_id = $common->getPushUsers($user_ids);
if($registration_id){
$common = new CommonController();
$title = config('site.title');
$common->pushMessage($registration_id,$content,$title);
}
$this->success('年检信息提交成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 年检信息列表
* @description 接口说明
* @author 开发者
* @url /api/home/yearly/yearList
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:page type:inter require:1 default: other desc:分页页码
* @param name:project_id type:inter require:1 default: other desc:项目id
* @return data: @
* @data id:年检id title:年检表头信息 user_login:乙方发起人 status:年检状态(0:待甲方员工确认,1:甲方员工驳回,2:进行中,3:已完成) project_name:项目名称 year_m_time:月检时间 staff:指派甲方确认员工 confirm:是否有确认/驳回按钮(0:无,1:有)
* @return page:当前页数
* @return total_page:总页数
*/
public function yearList(){
if($this->request->isGet()){
$page = $this->request->get('page');
$project_id = $this->request->get('project_id');
$rule = config('site.pages');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['page'=>$page,'project_id'=>$project_id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$res = $common->getCheckList('pro_check',$page,$project_id,'c.id,c.title,u.user_login,c.status,c.year_m_time,c.h_uid');
//查询总页数
$total_page = $common->getCheckPage('pro_check');
$this->success('成功',['data'=>$res,'page'=>intval($page),'total_page'=>$total_page]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲方员工确认
* @description 接口说明
* @author 开发者
* @url /api/home/yearly/confirmA
* @method GET
*
* @header name:token require:1 default: desc:header
* @param name:id type:inter require:1 default: other desc:列表id
*/
public function confirmA(){
if($this->request->isGet()){
$id = $this->request->get('id');
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getIdentity();
//如果是乙方,则没有权限操作
if($user['party'] == 1){
$this->error('无权操作');
}
$proCheckModel = new ProCheckModel();
$res = $proCheckModel->where(['id'=>$id,'status'=>0])->update(['status'=>2,'confirm_time'=>time()]);
if($res){
//极光推送,提醒发起乙方员工
$user_ids = $common->getLaunchUid('pro_check',$id);
$user_ids = explode(',',trim($user_ids['uid'],','));
$content = config('site.year_content_confirm_s');
$registration_id = $common->getPushUsers($user_ids);
if($registration_id){
$common = new CommonController();
$title = config('site.title');
$common->pushMessage($registration_id,$content,$title);
}
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲方员工驳回
* @description 接口说明
* @author 开发者
* @url /api/home/yearly/rejectA
* @method GET
*
* @header name:token require:1 default: desc:header
* @param name:id type:inter require:1 default: other desc:列表id
*/
public function rejectA(){
if($this->request->isGet()){
$id = $this->request->get('id');
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getIdentity();
//如果是乙方,则没有权限操作
if($user['party'] == 1){
$this->error('无权操作');
}
//月检
$proCheckModel = new ProCheckModel();
$data = [
'status'=>1,
'reject_time'=>time()
];
$res = $proCheckModel->where(['id'=>$id,'status'=>0])->update($data);
if($res){
//极光推送,提醒发起乙方员工
$user_ids = $common->getLaunchUid('pro_check',$id);
$user_ids = explode(',',trim($user_ids['uid'],','));
$content = config('site.year_content_reject_s');
$registration_id = $common->getPushUsers($user_ids);
if($registration_id){
$common = new CommonController();
$title = config('site.title');
$common->pushMessage($registration_id,$content,$title);
}
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 重新编辑显示(甲方员工驳回)
* @description 接口说明
* @author 开发者
* @url /api/home/yearly/reEditYearCheck
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:年检id
* @return id:年检列表id
* @return title:年检表头信息
* @return year_m_time:年检时间
* @return address:年检地点
* @return remark:年检备注
*/
public function reEditYearCheck(){
if($this->request->isGet()){
$id = $this->request->get('id');
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$field = 'id,title,year_m_time,address,remark';
$res = $common->getCheckById('pro_check',['id'=>$id,'status'=>1],$field);
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 乙方重新发起年检提交(被驳回)
* @description 接口说明
* @author 开发者
* @url /api/home/yearly/reApplyYearCheck
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:年检id
* @param name:title type:string require:1 default: other desc:表头信息
* @param name:year_m_time type:int require:1 default: other desc:年检时间
* @param name:address type:string require:1 default: other desc:年检地点
* @param name:remark type:string require:1 default: other desc:年检申请备注
* @param name:u_id type:inter require:1 default: other desc:指派甲方人员id
*/
public function reApplyYearCheck(){
if($this->request->isPost()){
$data = $this->request->post();
$common = new CommonController();
$user = $common->getIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.year_re_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$arr['year_m_time'] = $data['year_m_time'];
$arr['title'] = $data['title'];
$arr['address'] = $data['address'];
$arr['remark'] = $data['remark'];
$arr['uid'] = $this->userId;
$arr['status'] = 0;
//指派人员uid
$data['h_uid'] = $data['u_id'];
unset($data['u_id']);
$proCheckModel = new ProCheckModel();
$res = $proCheckModel->where(['id'=>$data['id'],'status'=>1])->update($arr);
if($res){
//极光推送
//乙方重新发起,提醒指派甲方员工
$user_ids = [$data['h_uid']];
$content = config('site.year_content_again_b');
$registration_id = $common->getPushUsers($user_ids);
if($registration_id){
$common = new CommonController();
$title = config('site.title');
$common->pushMessage($registration_id,$content,$title);
}
$this->success('年检信息重新提交成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 完善年检单显示
* @description 接口说明
* @author 开发者
* @url /api/home/yearly/improveYearCheck
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:年检id
*
* @return id:年检列表id
* @return project_id:项目id
* @return project_name:年检项目名称
* @return title:年检表头信息
* @return year_point:年检点信息@
* @year_point is_finish:未检查数量 point:年检点@
* @point id:年检点id point_name:年检点名称 status:年检点状态(0:正常,1:故障,2:未检查)
*/
public function improveYearCheck(){
if($this->request->isGet()){
$id = $this->request->get('id');
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$field = 'id,title,project_id';
$res = $common->getCheckById('pro_check',['id'=>$id],$field);
if($res){
//查询项目名称
$project = $common->getProject(['id'=>$res['project_id']],'id,name project_name');
$res['project_name'] = isset($project)&&!empty($project)?$project['project_name']:'';
//展示年检点列表
$res['year_point'] = $common->getInsCheckList(['c_id'=>$id,'type'=>1],$res['project_id']);
}
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 添加年检巡检页面
* @description 接口说明
* @author 开发者
* @url /api/home/yearly/insYearCheckAdd
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:int require:1 default: other desc:年检点id
*
* @return point_id:年检点id
* @return point_name:年检点名称
* @return project_id:项目id
* @return project_name:项目名称
*/
public function insYearCheckAdd(){
if($this->request->isGet()){
$id = $this->request->get('id');
$rule = config('site.ins_add');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
//查询巡检名称
$arr = Db::name('check_point')
->alias('po')
->join('project p','po.p_id = p.id','LEFT')
->where('po.id',$id)
->field('po.id point_id,po.point_name,p.id project_id,p.name project_name')
->find();
$this->success('成功',$arr);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 添加年检巡检提交
* @description 接口说明
* @author 开发者
* @url /api/home/check/insYearCheckAddPost
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:c_id type:int require:1 default: other: desc:年检列表id
* @param name:point_id type:int require:1 default: other: desc:年检点id
* @param name:project_id type:int require:1 default: other: desc:项目id
* @param name:status type:int require:1 default: other desc:年检点状态(0:已检查,1:故障)
* @param name:create_time type:int require:1 default: other desc:检测时间
* @param name:images type:array require:1 default: other desc:年检图片(二维数组形式)
*
*/
public function insYearCheckAddPost(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.ins_check_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$where1 = [
'project_id'=>$data['project_id'],
'point_id'=>$data['point_id'],
'c_id' => $data['c_id'],
'type' => 1
];
//查询是否已添加巡检
$result = $common->getInspectionCheck($where1);
if($result){
$this->error('您已提交过月检点信息!');
}
$data['uid'] = $this->userId;
//绝对路径转相对路径
$data['images'] = $common->relationUrl($data['images']);
$data['type'] = 1;
$insCheckModel = new InsCheckModel();
$res = $insCheckModel->create($data);
if($res){
//记录月检人员id
$join_uid['service_id'] = $data['c_id'];
$join_uid['project_id'] = $data['project_id'];
$join_uid['create_time'] = $data['create_time'];
$common->createInsUid($join_uid,2);
$this->success('您的年检点信息添加成功!');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 编辑年检巡检页面
* @description 接口说明
* @author 开发者
* @url /api/home/yearly/insYearCheckEdit
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:int require:1 default: other desc:年检点id
* @param name:c_id type:int require:1 default: other desc:年检列表id
*
* @return point_id:年检点id
* @return point_name:年检点名称
* @return project_id:项目id
* @return project_name:项目名称
* @return status:年检点状态(0:已检查,1:故障)
* @return images:年检图片@
* @images image_url:图片路径 file_time:图片时间
* @return create_time:年检时间
*/
public function insYearCheckEdit(){
if($this->request->isGet()){
$id = $this->request->get('id');
$c_id = $this->request->get('c_id');
$rule = config('site.year_check_add');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id,'c_id'=>$c_id])) {
$this->error($validate->getError());
}
//查询巡检名称
$res = Db::name('check_point')
->alias('po')
->join('ins_check i','po.id = i.point_id','LEFT')
->join('project p','po.p_id = p.id','LEFT')
->where(['po.id'=>$id,'i.c_id'=>$c_id,'i.type'=>1])
->field('po.id point_id,po.point_name,p.id project_id,p.name project_name,i.status,i.images,i.create_time')
->find();
//相对路径转绝对路径
if($res['images']){
$common = new CommonController();
$res['images'] = $common->absolutionUrl($res['images']);
}
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 编辑月检巡检提交
* @description 接口说明
* @author 开发者
* @url /api/home/yearly/insYearCheckEditPost
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:c_id type:int require:1 default: other: desc:年检列表id
* @param name:point_id type:int require:1 default: other: desc:年检点id
* @param name:project_id type:int require:1 default: other: desc:项目id
* @param name:status type:int require:1 default: other desc:年检点状态(0:已检查,1:故障)
* @param name:create_time type:int require:1 default: other desc:检测时间
* @param name:images type:array require:1 default: other desc:年检图片(二维数组形式)
*
*/
public function insYearCheckEditPost(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.year_check_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
//绝对路径转相对路径
$common = new CommonController();
$images = $common->relationUrl($data['images']);
$arr['images'] = $images;
$arr['status'] = $data['status'];
$arr['create_time'] = $data['create_time'];
$insCheckModel = new InsCheckModel();
$insCheckModel->where(['project_id'=>$data['project_id'],'point_id'=>$data['point_id'],'c_id'=>$data['c_id'],'type'=>1])->update($arr);
//记录巡检人员id
$join_uid['project_id'] = $data['project_id'];
$join_uid['create_time'] = $data['create_time'];
$join_uid['service_id'] = $data['c_id'];
$common->createInsUid($join_uid,2);
$this->success('保存成功!');
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 申请甲方验收人
* @description 接口说明
* @author 开发者
* @url /api/home/yearly/applyYearCheckConfirm
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:年检id
* @param name:confirm_uid type:inter require:1 default: other desc:申请甲方人员id
*/
public function applyCheckConfirm(){
if($this->request->isGet()){
$data = $this->request->get();
$rule = config('site.apply_confirm');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$proCheckModel = new ProCheckModel();
$res = $proCheckModel->where(['id'=>$data['id'],'status'=>2])->update(['status'=>3,'finish_uid'=>$data['confirm_uid']]);
if($res){
$common = new CommonController();
//极光推送
//提醒指派甲方员工验收
$user_ids = [$data['confirm_uid']];
$content = config('site.year_content_finish_a');
$registration_id = $common->getPushUsers($user_ids);
if($registration_id){
$common = new CommonController();
$title = config('site.title');
$common->pushMessage($registration_id,$content,$title);
}
$this->success('保存成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误');
}
}
/**
* @title 乙方确认完成年检信息
* @description 接口说明
* @author 开发者
* @url /api/home/yearly/finishYearCheck
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:年检id
* @param name:confirm_images type:array require:1 default: other desc:验收照片(二维数组形式)
*/
public function finishYearCheck(){
if($this->request->isPost()){
$data = $this->request->post();
$common = new CommonController();
$user = $common->getIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.year_check');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$proCheckModel = new ProCheckModel();
$confirmImages = $common->relationUrl($data['confirm_images']);
$data1 = [
'finish_time'=>time(),
'status'=>4,
'confirm_images'=>$confirmImages
];
$res = $proCheckModel->where(['id'=>$data['id'],'status'=>3])->update($data1);
if($res){
//记录参与人员id
$project = $common->getLaunchUid('pro_check',$data['id']);
$join_uid['project_id'] = $project['project_id'];
$join_uid['create_time'] = time();
$join_uid['service_id'] = $data['id'];
$common->createInsUid($join_uid,2);
//极光推送,推送系统设置人员
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
}