InformationController.php
11.9 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
<?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\TrainModel;
use think\Db;
use think\Validate;
use cmf\controller\RestBaseController;
use app\portal\model\CheckModel;
/**
* @title 消息审批
*/
class InformationController extends RestBaseController
{
/**
* @title 甲方领导消息审批列表(月检,培训演习)
* @description 接口说明
* @author 开发者
* @url /api/home/information/informationAList
* @method GET
*
* @header name:token require:1 default: desc:header
* @param name:page type:inter require:1 default: other desc:分页页码
* @param name:type type:inter require:1 default: other desc:工作类型(1:月检,2:培训演习)
*
* @return data:列表@
* @data id:列表id project_id:项目id project_name:项目名称 ins_m_time:月检时间 user_group:项目组
* @return type:工作类型 (1:月检,2:培训演习)
* @return page:当前页数
* @return total_page:总页数
*/
public function informationAList(){
if($this->request->isGet()){
$page = $this->request->get('page');
$type = $this->request->get('type');
$rule = config('site.type');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['type'=>$type,'page'=>$page])) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getUserIdentity();
//如果不是甲方领导,则没有权限操作
if($user['identity'] != config('site.a_leader')){
$this->error('无权操作');
}
//查看甲方领导的对应的乙方
if($type == 1){
//月检
$b_company_id = $common->getCompany(['pid'=>$user['company_id']],'id');
$res['data'] = $common->getCheckByCompanyBId($b_company_id['id'],$page);
$res['total_page'] = $common->getCheckByCompanyBPage($b_company_id['id']);
}else{
//培训演习
$b_company_id = $common->getCompany(['pid'=>$user['company_id']],'id');
$res['data'] = $common->getTrainByCompanyBId($b_company_id['id'],2,$page);
$res['total_page'] = $common->getTrainByCompanyBPage($b_company_id['id'],2);
}
//查找乙方项目组下的乙方员工
foreach($res['data'] as &$value){
$value['user_group'] = $common->getUserByProjectId($value['project_id'],'id,b_sid');
}
//工作类型
$res['type'] = $type;
$res['page'] = intval($page);
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 乙方领导消息审批列表(培训演习)
* @description 接口说明
* @author 开发者
* @url /api/home/information/informationBList
* @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 project_id:项目id project_name:项目名称 train_time:培训时间 user_group:项目组
* @return type:工作类型 (3:培训演习)
* @return page:当前页数
* @return total_page:总页数
*/
public function informationBList(){
if($this->request->isGet()){
$page = $this->request->get('page');
$rule = config('site.type');
//工作类型(培训演习)
$type = 3;
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['type'=>$type,'page'=>$page])) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getUserIdentity();
//如果不是乙方领导,则没有权限操作
if($user['identity'] != config('site.b_leader')){
$this->error('无权操作');
}
//培训演习
$res['data'] = $common->getTrainByCompanyBId($user['company_id'],0,$page);
$res['total_page'] = $common->getTrainByCompanyBPage($user['company_id'],0);
//查找乙方项目组下的乙方员工
foreach($res['data'] as &$value){
$value['user_group'] = $common->getUserByProjectId($value['project_id'],'id,b_sid');
}
//工作类型
$res['type'] = $type;
$res['page'] = intval($page);
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲方领导确认审批
* @description 接口说明
* @author 开发者
* @url /api/home/information/confirmA
* @method GET
*
* @header name:token require:1 default: desc:header
* @param name:id type:inter require:1 default: other desc:列表id
* @param name:type type:inter require:1 default: other desc:工作类型(1:月检,2:培训演习)
*/
public function confirmA(){
if($this->request->isGet()){
$id = $this->request->get('id');
$type = $this->request->get('type');
$rule = config('site.confirm');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['type'=>$type,'id'=>$id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getIdentity();
//如果不是甲方领导,则没有权限操作
if($user['identity'] != config('site.a_leader')){
$this->error('无权操作');
}
if($type == 1){
//月检
$checkModel = new CheckModel();
$res = $checkModel->where(['id'=>$id,'status'=>0])->update(['a_leader'=>$this->userId,'status'=>2,'l_confirm_time'=>time()]);
}else{
//培新演习
$trainModel = new TrainModel();
$data = [
'a_leader'=>$this->userId,
'a_confirm_time'=>time(),
'status'=>4
];
$res = $trainModel->where(['id'=>$id,'status'=>2])->update($data);
}
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 乙方领导确认审批(培训演习)
* @description 接口说明
* @author 开发者
* @url /api/home/information/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');
$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['identity'] != config('site.b_leader')){
$this->error('无权操作');
}
$trainModel = new TrainModel();
$data = [
'b_leader'=>$this->userId,
'b_confirm_time'=>time(),
'status'=>2
];
$res = $trainModel->where(['id'=>$id,'status'=>0])->update($data);
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲方领导驳回
* @description 接口说明
* @author 开发者
* @url /api/home/information/rejectA
* @method GET
*
* @header name:token require:1 default: desc:header
* @param name:id type:inter require:1 default: other desc:列表id
* @param name:type type:inter require:1 default: other desc:工作类型(1:月检,2:培训演习)
*/
public function rejectA(){
if($this->request->isGet()){
$id = $this->request->get('id');
$type = $this->request->get('type');
$rule = config('site.confirm');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['type'=>$type,'id'=>$id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getIdentity();
//如果不是甲方领导,则没有权限操作
if($user['identity'] != config('site.a_leader')){
$this->error('无权操作');
}
if($type == 1){
//月检
$checkModel = new CheckModel();
$data = [
'a_leader'=>$this->userId,
'status'=>1,
'reject_time'=>time()
];
$res = $checkModel->where(['id'=>$id,'status'=>0])->update($data);
}else{
//培新演习
$trainModel = new TrainModel();
$data = [
'a_leader'=>$this->userId,
'a_reject_time'=>time(),
'status'=>3
];
$res = $trainModel->where(['id'=>$id,'status'=>2])->update($data);
}
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 乙方领导驳回审批(培训演习)
* @description 接口说明
* @author 开发者
* @url /api/home/information/rejectB
* @method GET
*
* @header name:token require:1 default: desc:header
* @param name:id type:inter require:1 default: other desc:列表id
*/
public function rejectB(){
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['identity'] != config('site.b_leader')){
$this->error('无权操作');
}
$trainModel = new TrainModel();
$data = [
'b_leader'=>$this->userId,
'b_reject_time'=>time(),
'status'=>1
];
$res = $trainModel->where(['id'=>$id,'status'=>0])->update($data);
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
}