RepairController.php
21.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
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
<?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\InspectModel;
use app\portal\model\RepairModel;
/**
* @title 报修
*/
class RepairController extends RestBaseController
{
/**
* @title 新增报修提交
* @description 接口说明
* @author 开发者
* @url /api/home/repair/addRepairPost
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:images type:file require:1 default: other desc:图片凭证
* @param name:video type:file require:1 default: other desc:视频凭证
* @param name:audio type:file require:1 default: other desc:音频凭证
* @param name:description type:string require:1 default: other desc:故障问题描述
*/
public function addRepairPost(){
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'];
//获取项目id
$project = $common->getUserIdentity();
$data['project_id'] = $project['project_id'];
//查询是否已提价保修单
// $result = Db::name('repair')
// ->where('uid',$this->userId)
// ->find();
// if($result){
// $this->error('您已提交过报修信息!');
// }
$repairModel = new RepairModel();
$res = $repairModel->create($data);
if($res){
$id = $res->id;
$data1['create_time'] = time();
if($party['party'] == 0){
//甲方
$step_name = config('site.a_step')[0];
}else{
//乙方
$step_name = config('site.b_step')[0];
}
$common->repairStep($id,$step_name);
$this->success('您的报修消息提交成功!请等待维修人员确认');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 获取甲方报修列表
* @description 接口说明
* @author 开发者
* @url /api/home/repair/repairAList
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:page type:inter require:1 default: other desc:分页页码
* @param name:status type:inter require:1 default: other desc:切换状态(-1:全部,1:处理中(待确认,维修中),2:已完成)
* @return data:报修列表@
* @data id:报修id uid:提交人id status:报修状态(0:待确认,1:维修中,2:已完成) description:报修问题 party:甲方,乙方(0:甲方员工,1:乙方员工) create_time:报修时间 user_login:客户经理 confirm:是否有确认按钮(0:无,1:有)
* @return page:当前页数
* @return total_page:总页数
*/
public function repairAList(){
if($this->request->isGet()){
//查询用户所属项目
$page = $this->request->get('page');
$status = $this->request->get('status');//切换状态(全部:-1,处理中:1,已完成:2)
$limit = config('site.limit');
$rule = config('site.pages_list');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['page'=>$page,'status'=>$status])) {
$this->error($validate->getError());
}
$common = new CommonController();
$project = $common->getUserIdentity();
if($status == 1){
$where = ['project_id' => $project['project_id'], 'status' => ['in',[0,1]]];
}else if($status == 2) {
$where = ['project_id' => $project['project_id'], 'status' => $status];
}else{
$where = ['project_id'=>$project['project_id']];
}
$res = Db::name('repair')
->where($where)
->page($page,$limit)
->field('id,uid,h_uid,status,description,party,create_time')
->order('id desc')
->select()
->toArray();
//获取总页数
$total_page = $common->getCountPage('repair',$where);
foreach($res as &$value){
if($value['party'] == 0) {
//如果是甲方提交,客户经理为乙方确认人
$user = $common->getUserById(['id' => $value['h_uid']]);
}else{
//乙方提交,客户经理为乙方发起人
$user = $common->getUserById(['id' => $value['uid']]);
}
$value['user_login'] = isset($user['user_login'])&&!empty($user['user_login'])?$user['user_login']:'';
//查看是否有确认按钮
$value['confirm'] = 0;
//如果乙方提交报修,甲方有确认按钮
if($value['party'] == 1 && $value['status'] == 0){
//甲方有确认按钮
$value['confirm'] = 1;
}
}
$this->success('成功',['data'=>$res,'page'=>intval($page),'total_page'=>$total_page]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 获取乙方报修列表
* @description 接口说明
* @author 开发者
* @url /api/home/repair/repairBList
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:page type:inter require:1 default: other desc:分页页码
* @param name:status type:inter require:1 default: other desc:切换状态(全部:-1,处理中(待确认,维修中):1,已完成:2)
* @return data:报修列表@
* @data id:报修id h_uid:处理人id status:报修状态(0:待确认,1:维修中,2:已完成) description:报修问题 party:甲方,乙方(0:甲方员工,1:乙方员工) create_time:报修时间 user_login:客户经理姓名 confirm:是否有确认按钮(0:无,1:有) title:表头信息
* @return page:当前页数
* @return total_page:总页数
*/
public function repairBList(){
if($this->request->isGet()){
//查询用户所属项目
$page = $this->request->get('page');
$status = $this->request->get('status');//切换状态(全部:-1,处理中:1,已完成:2)
$limit = config('site.limit');
$rule = config('site.pages_list');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['status'=>$status,'page'=>$page])) {
$this->error($validate->getError());
}
$common = new CommonController();
$project = $common->getUserIdentity();
if($status == 1){
$where = ['project_id' => $project['project_id'], 'status' => ['in',[0,1]]];
}else if($status == 2) {
$where = ['project_id' => $project['project_id'], 'status' => $status];
}else{
$where = ['project_id'=>$project['project_id']];
}
$res = Db::name('repair')
->where($where)
->page($page,$limit)
->field('id,uid,h_uid,status,description,party,create_time,project_id')
->order('id desc')
->select()
->toArray();
//获取总页数
$total_page = $common->getCountPage('repair',$where);
foreach($res as &$value){
//查看处理人用户信息
if($value['party'] == 0) {
//如果是甲方提交,客户经理为乙方确认人
$user = $common->getUserById(['id' => $value['h_uid']]);
}else{
//乙方提交,客户经理为乙方发起人
$user = $common->getUserById(['id' => $value['uid']]);
}
$value['user_login'] = isset($user['user_login'])&&!empty($user['user_login'])?$user['user_login']:'';
$title = $common->getProject(['id'=>$value['project_id']],'name project_name');
//表头信息
$value['title'] = isset($title)&&!empty($title)?$title['project_name'].'报修表':'';
//查看是否有确认按钮
$value['confirm'] = 0;
//如果甲方提交报修,乙方有确认按钮
if($value['party'] == 0 && $value['status'] == 0){
//甲方有确认按钮
$value['confirm'] = 1;
}
}
$this->success('成功',['data'=>$res,'page'=>intval($page),'total_page'=>$total_page]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲方报修确认
* @description 接口说明
* @author 开发者
* @url /api/home/repair/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('无权操作');
}
$repairModel = new RepairModel();
$res = $repairModel->where(['id'=>$id,'status'=>0])->update(['status'=>1,'h_uid'=>$this->userId]);
if($res){
//甲方确认
$step_name = config('site.b_step')[1];
$common->repairStep($id,$step_name);
//乙方维修
$step_name = config('site.a_step')[2];
$common->repairStep($id,$step_name);
$this->success('成功!');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 乙方报修确认
* @description 接口说明
* @author 开发者
* @url /api/home/repair/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('无权操作');
}
$repairModel = new RepairModel();
$res = $repairModel->where(['id'=>$id,'status'=>0])->update(['status'=>1,'h_uid'=>$this->userId]);
if($res){
//乙方确认
$step_name = config('site.a_step')[1];
$common->repairStep($id,$step_name);
//乙方维修
$step_name = config('site.a_step')[2];
$common->repairStep($id,$step_name);
$this->success('成功!');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 报修单详情
* @description 接口说明
* @author 开发者
* @url /api/home/repair/repairDetail
* @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 images:图片凭证
* @return video:视频凭证
* @return audio:音频凭证
* @return description:故障问题
*/
public function repairDetail(){
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('repair')
->where('id',$id)
->field('id,images,video,audio,description')
->find();
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 报修流程
* @description 接口说明
* @author 开发者
* @url /api/home/repair/repairProcess
* @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:流程时间
*/
public function repairProcess(){
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)
->field('id,step_name,create_time')
->select()
->toArray();
foreach($res as &$value){
$value['create_time'] = date('Y-m-d',$value['create_time']);
}
$this->success('成功',['data'=>$res]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲乙方完善报修单详情
* @description 接口说明
* @author 开发者
* @url /api/home/repair/improveRepair
* @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 description:故障描述
* @return repair_images:维修结果照片
* @return update_time:修复时间
* @return user_group:乙方项目组人员
* @return repair_description:备注
* @return confirm_status:甲方确认情况
*/
public function improveRepair(){
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('repair')
->where('id',$id)
->find();
//如果是甲方提交报修
$common = new CommonController();
$arr = [];
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'] = date('Y-m-d',$res['create_time']);
//故障描述
$arr['description'] = $res['description'];
//维修结果照片
$arr['repair_images'] = $res['repair_images'];
//修复时间
$arr['update_time'] = !empty($res['update_time'])?date('Y-m-d',$res['update_time']):'';
//查询乙方项目组人员
$arr['user_group'] = $common->getUserByProjectId($res['project_id'],'id,b_sid');
//维修结果备注
$arr['repair_description'] = $res['repair_description'];
$this->success('成功',$arr);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲乙方完善报修单提交
* @description 接口说明
* @author 开发者
* @url /api/home/repair/improveRepairPost
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:报修单id
* @param name:repair_images type:file require:1 default: other desc:报修照片
* @param name:repair_description type:string require:1 default: other desc:报修备注
*/
public function improveRepairPost(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.improve_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$repairModel = new RepairModel();
$arr = [
'repair_images'=>$data['repair_images'],
'repair_description'=>$data['repair_description'],
'update_time'=>time()
];
$res = $repairModel->where(['id'=>$data['id'],'status'=>1])->update($arr);
if($res){
//创建流程或更新流程日期
$common = new CommonController();
$common->getStep($data['id']);
$this->success('保存成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲方验收维修结果
* @description 接口说明
* @author 开发者
* @url /api/home/repair/checkRepairPost
* @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 checkRepairPost(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.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'] == 1){
$this->error('无权操作');
}
$repairModel = new RepairModel();
$arr = ['confirm_images'=>$data['confirm_images'],'confirm_uid'=>$this->userId,'finish_time'=>time(),'status'=>2];
$res = $repairModel->where(['id'=>$data['id'],'status'=>1])->update($arr);
if($res){
//创建完成流程
$step_name = config('site.a_step')[4];
$common->repairStep($data['id'],$step_name);
$step_name = config('site.a_step')[5];
$common->repairStep($data['id'],$step_name);
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
}