InformationController.php
18.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
<?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;
use app\portal\model\ExerciseModel;
/**
* @title 消息审批
*/
class InformationController extends RestBaseController
{
/**
* @title 项目组名称
* @description 接口说明
* @author 开发者
* @url /api/home/information/getProjectGroup
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @return project_a:字母排序['b','c']
* @return project_n:项目名称@
* @project_n acronym:字母 project:项目列表@
* @project id:项目id project_name:项目名称
*/
public function getProjectGroup(){
if($this->request->isGet()){
$common = new CommonController();
$user = $common->getUserIdentity();
//根据企业id查询项目组名称
$res = [];
if($user['identity'] == config('site.a_leader')){
//项目组
//甲方领导
$res = $common->getProjectGroup($user['company_id']);
}else if($user['identity'] == config('site.a_leaders')){
//甲方总领导
$res = $common->getAsProjectGroup();
}else if($user['identity'] == config('site.b_leader')){
//乙方领导
$res = $common->getProjectGroup($user['company_id'],1);
}
$arr2 = [];
$arr2['project_a'] = [];
$arr2['project_n'] = [];
if($res){
$acronym = [];
foreach($res as $key=>$value){
$acronym[$key] = $common->getFirstCharter($value['project_name']);
}
$acronym =array_values(array_unique($acronym));
sort($acronym);
$arr1 = [];
foreach($acronym as $a_key=>$a_value){
$k = 0;
$arr1[$a_key]['acronym'] = $a_value;
foreach($res as $r_value){
$k+=0;
$first = $common->getFirstCharter($r_value['project_name']);
if($first == $a_value){
$arr1[$a_key]['project'][$k] = $r_value;
$k++;
}
}
}
if(in_array('#',$acronym)){
$count = count($acronym);
foreach ($arr1 as $key=>$a_value){
if($a_value['acronym'] == '#'){
$arr1[$count-1] = $a_value;
}else{
$arr1[$key-1] = $a_value;
}
}
foreach($acronym as $key1=>$a_value1){
if($a_value1 == '#'){
$acronym[$count-1] = $a_value1;
}else{
$acronym[$key1-1] = $a_value1;
}
}
}
$arr2['project_a'] = $acronym;
$arr2['project_n'] = $arr1;
}
$this->success('成功',$arr2);
}else{
$this->error('请求方式错误!');
}
}
/**
* @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:company_id type:inter require:0 default: other desc:公司id(如果是总领导有此字段)
* @param name:project_id type:inter require:0 default: other desc:项目id(检索)
* @param name:start_time type:inter require:0 default: other desc:开始日期(检索开始日期)
* @param name:end_time type:inter require:0 default: other desc:开始日期(检索结束日期)
*
* @return data:列表@
* @data id:列表id project_id:项目id project_name:项目名称 ins_m_time:月检时间 user_group:项目组
* @return page:当前页数
* @return total_page:总页数
*/
public function informationAList(){
if($this->request->isGet()){
$data = $this->request->get();
$company_id = $this->request->get('company_id');
$rule = config('site.pages_report');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getUserIdentity();
//如果不是甲方领导,则没有权限操作
if($user['identity'] != config('site.a_leader') && $user['identity'] != config('site.a_leaders')){
$this->error('无权操作');
}
//月检
if($user['identity'] == config('site.a_leaders')){
//总领导
$where = ['id'=>$company_id];
}else{
//领导
$where = ['id'=>$user['company_id']];
}
//查看甲方领导的对应的乙方
$b_company_id = $common->getCompany($where,'pid');
$res['data'] = $common->getCheckByCompanyBId($b_company_id['pid'],$data);
$res['total_page'] = $common->getCheckByCompanyBPage($b_company_id['pid'],$data);
//查找乙方项目组下的乙方员工
foreach($res['data'] as &$value){
$value['user_group'] = $common->getUserByProjectId($value['project_id'],'id,b_sid');
}
$res['page'] = intval($data['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:分页页码
* @param name:type type:inter require:1 default: other desc:工作类型(1:培训,2:演习)
* @param name:project_id type:inter require:0 default: other desc:项目id(检索)
* @param name:start_time type:inter require:0 default: other desc:开始日期(检索开始日期)
* @param name:end_time type:inter require:0 default: other desc:开始日期(检索结束日期)
*
* @return data:列表@
* @data id:列表id project_id:项目id project_name:项目名称 train_time:培训时间 user_group:项目组
* @return page:当前页数
* @return total_page:总页数
*/
public function informationBList(){
if($this->request->isGet()){
$data = $this->request->get();
$rule = config('site.pages_type');
//工作类型(培训演习)
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getUserIdentity();
//如果不是乙方领导,则没有权限操作
if($user['identity'] != config('site.b_leader')){
$this->error('无权操作');
}
if($data['type'] == 1){
//培训
$res['data'] = $common->getTrainByCompanyBId($user['company_id'],0,$data);
$res['total_page'] = $common->getTrainByCompanyBPage($user['company_id'],0,$data);
}else{
//演习
$res['data'] = $common->getExerciseByCompanyBId($user['company_id'],0,$data);
$res['total_page'] = $common->getExerciseByCompanyBPage($user['company_id'],0,$data);
}
//查找乙方项目组下的乙方员工
foreach($res['data'] as &$value){
$value['user_group'] = $common->getUserByProjectId($value['project_id'],'id,b_sid');
}
//工作类型
$res['page'] = intval($data['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
*/
public function confirmA(){
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.a_leader') && $user['identity'] != config('site.a_leaders')){
$this->error('无权操作');
}
//月检
$checkModel = new CheckModel();
$res = $checkModel->where(['id'=>$id,'status'=>0])->update(['a_leader'=>$this->userId,'status'=>2,'l_confirm_time'=>time()]);
if($res){
//推送
//月检,甲方领导确认,提醒甲乙方员工
$project = $common->getProjectId('check',['id'=>$id],'id,project_id');
$user_ids = $common->getStaffId($project['project_id']);
$content = config('site.check_content_confirm_l');
$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/information/confirmB
* @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 confirmB(){
if($this->request->isGet()){
$id = $this->request->get('id');
$type = $this->request->get('type');
$rule = config('site.data_type');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id,'type'=>$type])) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getIdentity();
//如果不是乙方领导,则没有权限操作
if($user['identity'] != config('site.b_leader')){
$this->error('无权操作');
}
$data = [
'b_leader'=>$this->userId,
'b_confirm_time'=>time(),
'status'=>2
];
if($type == 1){
//培训
$trainModel = new TrainModel();
$res = $trainModel->where(['id'=>$id,'status'=>0])->update($data);
}else{
//演习
$exerciseModel = new ExerciseModel();
$res = $exerciseModel->where(['id'=>$id,'status'=>0])->update($data);
}
if($res){
//推送
if($type == 1){
//培训,乙方领导确认,提醒甲乙方员工
$project = $common->getProjectId('train',['id'=>$id],'id,project_id');
$user_ids = $common->getStaffId($project['project_id']);
$content = config('site.train_content_confirm_l');
}else{
//演习,乙方领导确认,提醒甲乙方员工
$project = $common->getProjectId('exercise',['id'=>$id],'id,project_id');
$user_ids = $common->getStaffId($project['project_id']);
$content = config('site.exercise_content_confirm_l');
}
$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/information/rejectA
* @method GET
*
* @header name:token require:1 default: desc:header
* @param name:id type:inter require:1 default: other desc:列表id
*/
public function rejectA(){
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.a_leader') && $user['identity'] != config('site.a_leaders')){
$this->error('无权操作');
}
//月检
$checkModel = new CheckModel();
$data = [
'a_leader'=>$this->userId,
'status'=>1,
'reject_time'=>time()
];
$res = $checkModel->where(['id'=>$id,'status'=>0])->update($data);
if($res){
//推送
//月检,甲方领导驳回,提醒乙方发起员工
$user_ids = $common->getUserA('check',$id);
$content = config('site.check_content_reject_l');
$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/information/rejectB
* @method GET
*
* @header name:token require:1 default: desc:header
* @param name:id type:inter require:1 default: other desc:列表id
* @param name:advice_time type:inter require:1 default: other desc:建议时间
* @param name:type type:inter require:1 default: other desc:工作类型(1:培训,2:演习)
*/
public function rejectB(){
if($this->request->isGet()){
$id = $this->request->get('id');
$advice_time = $this->request->get('advice_time');
$type = $this->request->get('type');
$rule = config('site.train_advice_time');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id,'advice_time'=>$advice_time,'type'=>$type])) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getIdentity();
//如果不是乙方领导,则没有权限操作
if($user['identity'] != config('site.b_leader')){
$this->error('无权操作');
}
$data = [
'b_leader'=>$this->userId,
'b_reject_time'=>time(),
'advice_time'=>$advice_time,
'status'=>1
];
if($type == 1){
//培训
$trainModel = new TrainModel();
$res = $trainModel->where(['id'=>$id,'status'=>0])->update($data);
}else{
//演习
$exerciseModel = new ExerciseModel();
$res = $exerciseModel->where(['id'=>$id,'status'=>0])->update($data);
}
if($res){
//推送
if($type == 1){
//培训,乙方领导驳回,提醒甲方发起员工
$user_ids = $common->getUserA('train',$id);
$content = config('site.train_content_reject_l');
}else{
//演习,乙方领导发起,提醒甲方发起员工
$user_ids = $common->getUserA('exercise',$id);
$content = config('site.exercise_content_reject_l');
}
$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('请求方式错误!');
}
}
}