CheckController.php
11.5 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
<?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\CheckModel;
/**
* @title 月检
*/
class CheckController extends RestBaseController
{
/**
* @title 甲方项目组人员
* @description 接口说明
* @author 开发者
* @url /api/home/check/userAGroup
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @return data:数据@
* @data id:负责人id user_login:负责人姓名
*/
public function userAGroup(){
if($this->request->isGet()){
$common = new CommonController();
//获取用户所在项目
$user = $common->getUserIdentity();
//根据项目id获取甲方uid
$users = $common->getUserByProject($user['project_id'],'id,a_sid');
$this->success('成功',['data'=>$users]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 乙方发起月检申请
* @description 接口说明
* @author 开发者
* @url /api/home/check/applyCheck
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:ins_m_time type:string require:1 default: other desc:月检时间
* @param name:address type:string require:1 default: other desc:月检地点
* @param name:a_uid type:inter require:1 default: other desc:甲方负责人id
* @param name:remark type:string require:1 default: other desc:月检申请备注
*/
public function applyCheck(){
if($this->request->isPost()){
$data = $this->request->post();
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.ins_m_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$data['uid'] = $this->userId;
$data['project_id'] = $user['project_id'];
$data['create_time'] = time();
$checkModel = new CheckModel();
$res = $checkModel->create($data);
if($res){
$this->success('月检信息提交成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 月检信息列表
* @description 接口说明
* @author 开发者
* @url /api/home/check/checkList
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:page type:inter require:1 default: other desc:分页页码
* @return data: @
* @data id:月检id user_login:乙方发起人 status:月检状态(0:待甲方领导确认,1:甲方领导驳回,2:待乙方员工完成,3:已完成) project_name:项目名称 ins_m_time:月检时间
*/
public function checkList(){
if($this->request->isGet()){
$page = $this->request->get('page');
$rule = config('site.pages');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['page'=>$page])) {
$this->error($validate->getError());
}
$common = new CommonController();
$res = $common->getCheckList($page);
$this->success('成功',['data'=>$res]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 重新编辑显示(甲方领导驳回)
* @description 接口说明
* @author 开发者
* @url /api/home/check/reEdit
* @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 ins_m_time:月检时间
* @return address:月检地点
* @return a_uid:月检甲方负责人uid
* @return remark:月检备注
*/
public function reEdit(){
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,ins_m_time,address,a_uid,remark';
$res = $common->getCheckById(['id'=>$id,'status'=>1],$field);
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 乙方重新发起月检(被驳回)
* @description 接口说明
* @author 开发者
* @url /api/home/check/reApply
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:月检id
* @param name:ins_m_time type:string require:1 default: other desc:月检时间
* @param name:address type:string require:1 default: other desc:月检地点
* @param name:a_uid type:inter require:1 default: other desc:甲方负责人id
* @param name:remark type:string require:1 default: other desc:月检申请备注
*/
public function reApply(){
if($this->request->isPost()){
$data = $this->request->post();
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.ins_re_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$arr['ins_m_time'] = $data['ins_m_time'];
$arr['address'] = $data['address'];
$arr['a_uid'] = $data['a_uid'];
$arr['remark'] = $data['remark'];
$arr['uid'] = $this->userId;
$arr['status'] = 0;
$checkModel = new CheckModel();
$res = $checkModel->where(['id'=>$data['id']])->update($arr);
if($res){
$this->success('月检信息提交成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 完善月检单显示
* @description 接口说明
* @author 开发者
* @url /api/home/check/improveCheck
* @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 ins_m_time:月检日期
* @return project_name:月检项目名称
* @return user_login:确认甲方领导
* @return images:月检图片(多张以逗号隔开)
*/
public function improveCheck(){
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());
}
$arr = [];
$common = new CommonController();
$field = 'id,ins_m_time,a_leader,images,project_id';
$res = $common->getCheckById(['id'=>$id],$field);
if($res){
$arr['id'] = $res['id'];
$arr['ins_m_time'] = $res['ins_m_time'];
//查询项目名称
$project = $common->getProject(['id'=>$res['project_id']],'id,name project_name');
$arr['project_name'] = isset($project)&&!empty($project)?$project['project_name']:'';
//查询甲方领导人
$user = $common->getLeader(['id'=>$res['a_leader']]);
$arr['user_login'] = isset($user)&&!empty($user)?$user['user_login']:'';
$arr['images'] = $res['images'];
}
$this->success('成功',$arr);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 完善月检单提交
* @description 接口说明
* @author 开发者
* @url /api/home/check/improveCheckPost
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:月检id
* @param name:images type:file require:1 default: other desc:月检图片
*
*/
public function improveCheckPost(){
if($this->request->isPost()){
$data = $this->request->post();
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.improve_check_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$checkModel = new CheckModel();
$res = $checkModel->where(['id'=>$data['id'],'status'=>2])->update(['images'=>$data['images']]);
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 乙方确认完成月检信息
* @description 接口说明
* @author 开发者
* @url /api/home/check/finishCheck
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:月检id
*/
public function finishCheck(){
if($this->request->isGet()){
$id = $this->request->get('id');
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$checkModel = new CheckModel();
$res = $checkModel->where(['id'=>$id,'status'=>2])->update(['finish_uid'=>$this->userId,'finish_time'=>time(),'status'=>3]);
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
}