ReformController.php
26.7 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
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
<?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\ReformModel;
/**
* @title 改造
*/
class ReformController extends RestBaseController
{
/**
* @title 新增改造提交
* @description 接口说明
* @author 开发者
* @url /api/home/reform/addReformPost
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:title type:string require:1 default: other desc:表头信息
* @param name:images type:array require:1 default: other desc:图片凭证(二维数组形式)
* @param name:project_id type:inter require:1 default: other desc:项目id
* @param name:video type:file require:0 default: other desc:视频凭证
* @param name:audio type:file require:0 default: other desc:音频凭证
* @param name:description type:string require:1 default: other desc:故障问题描述
* @param name:u_id type:inter require:1 default: other desc:指派人员id
*/
public function addReformPost(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.repair_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$data['uid'] = $this->userId;
$data['create_time'] = time();
//获取甲方,乙方
$common = new CommonController();
$party = $common->getUserIdentity();
$data['party'] = $party['party'];
//单号
$data['number'] = $common->genOrderSn();
//查询是否已提价保修单
// $result = Db::name('repair')
// ->where('uid',$this->userId)
// ->find();
// if($result){
// $this->error('您已提交过改造信息!');
// }
$host = config('site.host');
if(isset($data['audio'])){
$data['audio'] = str_replace($host,'',$data['audio']);
}
if(isset($data['video'])){
//视频
$data['video'] = str_replace($host,'',$data['video']);
}
$data['images'] = $common->relationUrl($data['images']);
//指派人员uid
$data['h_uid'] = $data['u_id'];
unset($data['u_id']);
$reformModel = new ReformModel();
$res = $reformModel->create($data);
if($res){
//极光推送
if($data['party'] == 0){
//甲方发起,提醒指派乙方员工
$user_ids = [$data['h_uid']];
$content = config('site.reform_content_add_a');
}else{
//乙方发起,提醒指派甲方员工
$user_ids = [$data['h_uid']];
$content = config('site.reform_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);
}
$id = $res->id;
$data1['create_time'] = time();
if($party['party'] == 0){
//甲方
$step_name = config('site.a_reform_step')[0];
}else{
//乙方
$step_name = config('site.b_reform_step')[0];
}
$common->repairStep($id,$step_name,1);
//记录参与人员id
$join_uid['project_id'] = $data['project_id'];
$join_uid['create_time'] = $data['create_time'];
$common->createInsUid($join_uid,4);
$this->success('您的改造消息提交成功!请等待维修人员确认');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 获取甲方改造列表
* @description 接口说明
* @author 开发者
* @url /api/home/reform/reformAList
* @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
* @param name:status type:inter require:1 default: other desc:切换状态(-1:全部,1:处理中(待确认,维修中),2:申请中,3:已完成)
* @param name:keys type:file require:0 default: other desc:关键字(检索)
*
* @return data:改造列表@
* @data id:改造id uid:提交人id status:改造状态(0:待确认,1:维修中,2:申请中,3:已完成) description:改造问题 party:甲方,乙方(0:甲方员工,1:乙方员工) create_time:改造时间 user_login:客户经理 confirm:是否有确认按钮(0:无,1:有) finish:是否有确认完成按钮(0:无,1:有) title:表头信息
* @return page:当前页数
* @return total_page:总页数
*/
public function reformAList(){
if($this->request->isGet()){
//查询用户所属项目
$page = $this->request->get('page');
$status = $this->request->get('status');//切换状态(全部:-1,处理中:1,已完成:2)
$keys = $this->request->get('keys');
$project_id = $this->request->get('project_id');
$rule = config('site.pages_list');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['page'=>$page,'status'=>$status,'project_id'=>$project_id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$where = $common->getRepairStatus($status);
$where['r.project_id'] = $project_id;
//获取总页数
$total_page = $common->getRepairPage('reform',$where,$keys);
//列表数据
$res = $common->getRepairList('reform',$where,$page,$keys);
$this->success('成功',['data'=>$res,'page'=>intval($page),'total_page'=>$total_page]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 获取乙方改造列表
* @description 接口说明
* @author 开发者
* @url /api/home/reform/reformBList
* @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
* @param name:status type:inter require:1 default: other desc:切换状态(-1:全部,1:处理中(待确认,维修中),2:申请中,3:已完成)
* @param name:keys type:file require:0 default: other desc:关键字(检索)
*
* @return data:改造列表@
* @data id:改造id h_uid:处理人id status:改造状态(0:待确认,1:维修中,2:申请中,3:已完成) description:改造问题 party:甲方,乙方(0:甲方员工,1:乙方员工) create_time:改造时间 user_login:客户经理姓名 confirm:是否有确认按钮(0:无,1:有) finish:是否有确认完成按钮(0:无,1:有) title:表头信息
* @return page:当前页数
* @return total_page:总页数
*/
public function reformBList(){
if($this->request->isGet()){
//查询用户所属项目
$page = $this->request->get('page');
$status = $this->request->get('status');//切换状态(全部:-1,处理中:1,已完成:2)
$keys = $this->request->get('keys');
$project_id = $this->request->get('project_id');
$rule = config('site.pages_list');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['status'=>$status,'page'=>$page,'project_id'=>$project_id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$where = $common->getRepairStatus($status);
$where['r.project_id'] = $project_id;
//获取总页数
$total_page = $common->getRepairPage('reform',$where,$keys);
//列表数据
$res = $common->getRepairList('reform',$where,$page,$keys);
$this->success('成功',['data'=>$res,'page'=>intval($page),'total_page'=>$total_page]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲方改造确认
* @description 接口说明
* @author 开发者
* @url /api/home/reform/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');//改造列表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('无权操作');
}
$reformModel = new ReformModel();
$res = $reformModel->where(['id'=>$id,'status'=>0])->update(['status'=>1]);
if($res){
//极光推送,提醒发起乙方员工
$user_ids = $common->getLaunchUid('reform',$id);
$content = config('site.reform_content_confirm_a');
$registration_id = $common->getPushUsers($user_ids);
if($registration_id){
$common = new CommonController();
$title = config('site.title');
$common->pushMessage($registration_id,$content,$title);
}
//甲方确认
$step_name = config('site.b_reform_step')[1];
$common->repairStep($id,$step_name,1);
//乙方维修
$step_name = config('site.a_reform_step')[2];
$common->repairStep($id,$step_name,1);
$res_reform = $common->getRepairDetail($id,'reform');
$this->success('成功!',$res_reform);
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 乙方改造确认
* @description 接口说明
* @author 开发者
* @url /api/home/reform/confirmB
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:改造id
*/
public function confirmB(){
if($this->request->isGet()){
$id = $this->request->get('id');//改造列表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'] == 0){
$this->error('无权操作');
}
$reformModel = new ReformModel();
$res = $reformModel->where(['id'=>$id,'status'=>0])->update(['status'=>1]);
if($res){
//极光推送,推送发起甲方员工
$user_ids = $common->getLaunchUid('repair',$id);
$content = config('site.reform_content_confirm_b');
$registration_id = $common->getPushUsers($user_ids);
if($registration_id){
$common = new CommonController();
$title = config('site.title');
$common->pushMessage($registration_id,$content,$title);
}
//乙方确认
$step_name = config('site.a_reform_step')[1];
$common->repairStep($id,$step_name,1);
//乙方维修
$step_name = config('site.a_reform_step')[2];
$common->repairStep($id,$step_name,1);
//查询当前改造列表数据
$res_reform = $common->getRepairDetail($id,'reform');
$this->success('成功!',$res_reform);
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 改造单详情
* @description 接口说明
* @author 开发者
* @url /api/home/reform/reformDetail
* @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 images:图片凭证@
* @images image_url:图片路径 file_time:图片时间
* @return video:视频凭证
* @return audio:音频凭证
* @return description:故障问题
*/
public function reformDetail(){
if($this->request->isGet()){
$id = $this->request->get('id');//改造列表id
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$res = Db::name('reform')
->where('id',$id)
->field('id,title,images,video,audio,description')
->find();
$host = config('site.host');
//音频
if($res['audio']){
$res['audio'] = $host.$res['audio'];
}
//视频
if($res['video']){
$res['video'] = $host.$res['video'];
}
if($res['images']){
$common = new CommonController();
$res['images'] = $common->absolutionUrl($res['images']);
}
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 改造流程
* @description 接口说明
* @author 开发者
* @url /api/home/reform/reformProcess
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:改造id
*
* @return data:流程数据@
* @data id:流程id step_name:流程名称 create_time:流程时间
* @return status:状态(0:待确认,1:维修中,2:申请中,3:已完成)
*/
public function reformProcess(){
if($this->request->isGet()){
$id = $this->request->get('id');//改造列表id
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$res = Db::name('step')
->where(['r_id'=>$id,'type'=>1])
->field('id,step_name,create_time')
->select()
->toArray();
if($res){
foreach($res as &$value){
$value['create_time'] = date('Y-m-d',$value['create_time']);
}
}
$common = new CommonController();
$status = $common->getStepRepairStatus('reform',$id);
$this->success('成功',['data'=>$res,'status'=>$status]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲乙方完善改造单详情
* @description 接口说明
* @author 开发者
* @url /api/home/reform/improveReform
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:改造id
*
* @return user_login:甲方负责人
* @return h_user_login:乙方负责人
* @return create_time:故障改造时间
* @return number:改造单号
* @return description:故障描述
* @return reform_images:维修结果照片@
* @reform_images image_url:图片路径 file_time:图片时间
* @return update_time:修复时间
* @return user_group:乙方项目组人员
* @return reform_description:备注
* @return confirm_status:甲方确认情况
*/
public function improveReform(){
if($this->request->isGet()){
$id = $this->request->get('id');//改造列表id
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$res = Db::name('reform')
->where('id',$id)
->find();
//如果是甲方提交改造
$common = new CommonController();
$arr = [];
if($res){
if($res['party'] == 0){
//甲方负责人
$user = $common->getUserById(['id' => $res['uid']]);
$arr['user_login'] = isset($user['user_login'])&&!empty($user['user_login'])?$user['user_login']:'';
//乙方负责人
$h_user = $common->getUserById(['id' => $res['h_uid']]);
$arr['h_user_login'] = isset($h_user['user_login'])&&!empty($h_user['user_login'])?$h_user['user_login']:'';
}else{
//甲方负责人
$user = $common->getUserById(['id' => $res['h_uid']]);
$arr['user_login'] = isset($user['user_login'])&&!empty($user['user_login'])?$user['user_login']:'';
//乙方负责人
$h_user = $common->getUserById(['id' => $res['uid']]);
$arr['h_user_login'] = isset($h_user['user_login'])&&!empty($h_user['user_login'])?$h_user['user_login']:'';
}
//甲方确认情况
if($res['status'] == 2){
$arr['confirm_status'] = '已确认';
}else{
$arr['confirm_status'] = '未确认';
}
//故障改造时间
$arr['create_time'] = $res['create_time'];
//报修单号
$arr['number'] = $res['number'];
//故障描述
$arr['description'] = $res['description'];
//维修结果照片
if($res['reform_images']){
$arr['reform_images'] = $common->absolutionUrl($res['reform_images']);
}else{
$arr['reform_images'] = [];
}
//修复时间
$arr['update_time'] = !empty($res['update_time'])?$res['update_time']:'';
//查询乙方项目组人员
$arr['user_group'] = $common->getUserByProjectId($res['project_id'],'id,b_sid');
//维修结果备注
$arr['reform_description'] = $res['reform_description'];
}
$this->success('成功',$arr);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲乙方完善改造单提交
* @description 接口说明
* @author 开发者
* @url /api/home/reform/improveReformPost
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:改造单id
* @param name:reform_images type:array require:1 default: other desc:改造照片(二维数组形式)
* @param name:reform_description type:string require:1 default: other desc:改造备注
*/
public function improveReformPost(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.reform_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$reformModel = new ReformModel();
$common = new CommonController();
$reform_images = $common->relationUrl($data['reform_images']);
$arr = [
'reform_images'=>$reform_images,
'reform_description'=>$data['reform_description'],
'update_time'=>time()
];
$res = $reformModel->where(['id'=>$data['id'],'status'=>1])->update($arr);
if($res){
//创建流程或更新流程日期
$common = new CommonController();
$common->getStep($data['id'],1);
//记录参与人员id
$project = $common->getLaunchUid('reform',$data['id']);
$join_uid['project_id'] = $project['project_id'];
$join_uid['create_time'] = time();
$common->createInsUid($join_uid,4);
$this->success('保存成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 申请甲方验收人
* @description 接口说明
* @author 开发者
* @url /api/home/reform/applyReformConfirm
* @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 applyReformConfirm(){
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());
}
$reformModel = new ReformModel();
$res = $reformModel->where(['id'=>$data['id'],'status'=>1])->update(['status'=>2,'confirm_uid'=>$data['confirm_uid']]);
if($res){
//创建甲方验收维修结果流程
$common = new CommonController();
$step_name = config('site.a_step')[4];
$common->repairStep($data['id'],$step_name,1);
//极光推送
//提醒指派甲方员工验收
$user_ids = [$data['confirm_uid']];
$content = config('site.reform_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/reform/checkReformPost
* @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:file require:1 default: other desc:验收照片(二维数组形式)
*/
public function checkReformPost(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.check_reform');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
//如果是乙方,则无权操作
$common = new CommonController();
$user = $common->getIdentity();
//如果是乙方,则没有权限操作
if($user['party'] == 1){
$this->error('无权操作');
}
$reformModel = new ReformModel();
$confirmImages = $common->relationUrl($data['confirm_images']);
$arr = [
'confirm_images'=>$confirmImages,
'finish_time'=>time(),
'status'=>3
];
$res = $reformModel->where(['id'=>$data['id'],'status'=>2])->update($arr);
if($res){
//创建最后维修流程
$step_name = config('site.a_reform_step')[5];
$common->repairStep($data['id'],$step_name,1);
//记录参与人员id
$project = $common->getLaunchUid('reform',$data['id']);
$join_uid['project_id'] = $project['project_id'];
$join_uid['create_time'] = time();
$common->createInsUid($join_uid,4);
//极光推送,推送甲乙方领导
$project = $common->getProjectId('reform',['id'=>$data['id']],'id,project_id');
$user_ids = $common->getLeadersId($project['project_id']);
$content = config('site.reform_content_finish');
$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('请求方式错误!');
}
}
}