InspectionController.php
10.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
<?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;
/**
* @title 日检
*/
class InspectionController extends RestBaseController
{
/**
* @title 巡检列表
* @description 接口说明
* @author 开发者
* @url /api/home/inspection/insList
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:project_id type:int require:1 default: other desc:项目id
*
* @return id:项目id
* @return project_name:项目名称
* @return point: @
* @point id:巡检点id point_name:巡检名称 status:巡检状态(0:已检查,1:故障,2:未完成)
* @return is_finish: 未完成数量
* @return is_post:是否可以编辑或提交(0:是,1:否)
*/
public function insList(){
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();
$arr = $common->getInsList($project_id);
$this->success('成功',$arr);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 添加巡检页面
* @description 接口说明
* @author 开发者
* @url /api/home/inspection/insAdd
* @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 insAdd(){
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('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/inspection/insAddPost
* @method POST
*
* @header name:token require:1 default: desc:header
* @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 insAddPost(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.ins_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$data['uid'] = $this->userId;
//获取甲方,乙方
$common = new CommonController();
//处理图片+时间格式,序列化存入数据库中
//绝对路径转相对路径
$data['images'] = $common->relationUrl($data['images']);
$party = $common->getUserIdentity();
//查询对方是否巡检
$where = ['project_id'=>$data['project_id']];
$res = $common->getInspection($where);
if($res){
if($res['party'] != $party['party']){
$this->error('不可巡检,对方已在巡检当中!');
}
}
$where1 = [
'project_id'=>$data['project_id'],
'point_id'=>$data['point_id'],
'party'=>$party['party']
];
//查询是否已添加巡检
$result = $common->getInspection($where1);
if($result){
$this->error('您已提交过巡检点信息!');
}
$data['party'] = $party['party'];
$inspectModel = new InspectModel();
// $keys = ['images','file_time'];
// $images = $common->array_merge_more($keys, $data['images'], $data['file_time']);
$res = $inspectModel->create($data);
if($res){
$this->success('您的巡检点信息添加成功!');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 编辑巡检页面
* @description 接口说明
* @author 开发者
* @url /api/home/inspection/insEdit
* @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:项目名称
* @return status:巡检点状态(0:已检查,1:故障)
* @return images:巡检图片@
* @images image_url:图片路径 file_time:图片时间
* @return create_time:巡检时间
*/
public function insEdit(){
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());
}
//查询巡检名称
$res = Db::table('xf_point')
->alias('po')
->join('xf_inspect','po.id = xf_inspect.point_id','LEFT')
->join('xf_project p','po.p_id = p.id','LEFT')
->whereTime('xf_inspect.create_time','today')
->where(['po.id'=>$id])
->field('po.id point_id,po.point_name,p.id project_id,p.name project_name,xf_inspect.status,xf_inspect.images,xf_inspect.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/inspection/insEditPost
* @method POST
*
* @header name:token require:1 default: desc:header
* @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 insEditPost(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.ins_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'];
$inspectModel = new InspectModel();
$time = date('Y-m-d',time());//今天时间戳
$create_time = date('Y-m-d',$data['create_time']);//提交时间戳
if($create_time != $time){
$this->error('只能修改当天的巡检信息');
}
$user = $common->getIdentity();
//查询对方是否巡检
$where = ['project_id'=>$data['project_id']];
$res = $common->getInspection($where);
if($res){
if($res['party'] != $user['party']){
$this->error('不可编辑,对方已在巡检当中!');
}
}
$inspectModel->where(['point_id'=>$data['point_id'],'party'=>$user['party']])->whereTime('create_time','today')->update($arr);
$this->success('保存成功!');
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 日检记录
* @description 接口说明
* @author 开发者
* @url /api/home/inspection/insRecord
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:date_time type:int require:1 default: other desc:时间
* @param name:project_id type:int require:1 default: other desc:项目id
*
* @return id:报表id
*/
public function insRecord(){
if($this->request->isGet()){
$data = $this->request->get();
$rule = config('site.ins_record');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$common = new CommonController();
$res = $common->getInsRecord('inspect',$data);
$this->success('成功',$res);
}else{
$this->error('请求方式错误');
}
}
}