AdminProjectController.php
29.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
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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use app\portal\model\CompanyModel;
use app\portal\model\InspectModel;
use app\portal\model\ServiceRuleModel;
use app\portal\model\SetPushModel;
use app\user\model\UserModel;
use cmf\controller\AdminBaseController;
use app\portal\model\ProjectModel;
use app\portal\model\PointModel;
use think\Db;
use think\db\Query;
use app\portal\model\CheckPointModel;
class AdminProjectController extends AdminBaseController
{
//列表页
public function index(){
$param = $this->request->param();
$common = new AdminCommonController();
$admin_id = cmf_get_current_admin_id();
if($admin_id == 1){
$where = [];
}else{
$company_id = $common->getProjectId($admin_id);
$where = ['b_cid'=>$company_id];
}
$service_id = $this->request->param('service_id',2);
$list = Db::name('project')
->where(function (Query $query) use($where) {
$param = $this->request->param();
if (!empty($where)) {
$query->where($where);
}
if (!empty($param['name'])) {
$keyword = $param['name'];
$query->where('name', 'like', "%$keyword%");
}
if (!empty($param['a_cid'])) {
$a_cid = $param['a_cid'];
$query->where('a_cid',$a_cid);
}
$startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
$endTime = empty($param['end_time']) ? 0 : strtotime($param['end_time'])+86400;
if (!empty($startTime)) {
$query->where('create_time', '>=', $startTime);
}
if (!empty($endTime)) {
$query->where('create_time', '<=', $endTime);
}
})
->order("id desc")
->paginate(10,false,['query'=>request()->param()]);
$data = $list->toArray();
$data = $data['data'];
//获取甲方企业
$a_cids = array_unique(array_column($data,'a_cid'));
$a_company = $common->getCompanyNameByIds($a_cids);
//获取乙方企业
$b_cids = array_unique(array_column($data,'b_cid'));
$b_company = $common->getCompanyNameByIds($b_cids);
//获取用户信息
foreach($data as &$value){
$project_id = $value['id'];
if($service_id == 2){
//月检
$value['type'] = '月检';
//完成
$finish_count = $common->getServiceCount('check',['status'=>4,'project_id'=>$project_id]);
//未完成
$not_count = $common->getServiceCount('check',['status'=>['<>',4],'project_id'=>$project_id]);
//总数
$total_count = $common->getServiceCount('check',['project_id'=>$project_id]);
}else if($service_id == 4){
//报修
$value['type'] = '报修';
//完成
$finish_count = $common->getServiceCount('repair',['status'=>3,'project_id'=>$project_id]);
//未完成
$not_count = $common->getServiceCount('repair',['status'=>['<>',3],'project_id'=>$project_id]);
//总数
$total_count = $common->getServiceCount('repair',['project_id'=>$project_id]);
}else if($service_id == 3){
//改造
$value['type'] = '改造';
//完成
$finish_count = $common->getServiceCount('reform',['status'=>3,'project_id'=>$project_id]);
//未完成
$not_count = $common->getServiceCount('reform',['status'=>['<>',3],'project_id'=>$project_id]);
//总数
$total_count = $common->getServiceCount('reform',['project_id'=>$project_id]);
}else if($service_id == 5){
//培训
$value['type'] = '培训';
//完成
$finish_count = $common->getServiceCount('train',['status'=>2,'project_id'=>$project_id]);
//未完成
$not_count = $common->getServiceCount('train',['status'=>['<>',2],'project_id'=>$project_id]);
//总数
$total_count = $common->getServiceCount('train',['project_id'=>$project_id]);
}else if($service_id == 6){
//演习
$value['type'] = '演习';
//完成
$finish_count = $common->getServiceCount('exercise',['status'=>2,'project_id'=>$project_id]);
//未完成
$not_count = $common->getServiceCount('exercise',['status'=>['<>',2],'project_id'=>$project_id]);
//总数
$total_count = $common->getServiceCount('exercise',['project_id'=>$project_id]);
}else{
$value['type'] = '年检';
//完成
$finish_count = $common->getServiceCount('pro_check',['status'=>4,'project_id'=>$project_id]);
//未完成
$not_count = $common->getServiceCount('pro_check',['status'=>['<>',4],'project_id'=>$project_id]);
//总数
$total_count = $common->getServiceCount('pro_check',['project_id'=>$project_id]);
}
//完成
$value['finish_count'] = $finish_count;
//未完成
$value['not_count'] = $not_count;
//总数
$value['total_count'] = $total_count;
//甲乙双方企业
$value['a_company'] = $a_company[$value['a_cid']];
$value['b_company'] = $b_company[$value['b_cid']];
//计算运行天数
$common = new AdminCommonController();
$value['run_time'] = $common->runTime($value['create_time']);
}
// 获取分页显示
$page = $list->render();
$this->assign('list', $data);
$this->assign('page', $page);
//获取甲方企业名称
if($admin_id == 1){
$part_A = $common->getCompanyInfo(['pid'=>['neq',0]],'id,company_name');
}else{
$part_A = $common->getCompanyInfo(['pid'=>$company_id],'id,company_name');
}
$this->assign('part_a',$part_A);
$this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
$this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
$this->assign('a_cid', isset($param['a_cid']) ? $param['a_cid'] : '');
$this->assign('service_id',$service_id);
$this->assign('service',$common::serviceList);
//登录用户id
$this->assign('login_uid',$admin_id);
// 渲染模板输出
return $this->fetch();
}
//新增页面
public function add(){
//获取乙方企业名称,企业员工
$common = new AdminCommonController();
$admin_id = cmf_get_current_admin_id();
$company_id = $common->getProjectId($admin_id);
$res = $common->getCompanyById($company_id,'id,company_name,u_s_id');
$u_s_id = explode(',',trim($res['u_s_id'],','));
$res['u_s_id'] = $common->getUserName($u_s_id);
$this->assign('post',$res);
return $this->fetch();
}
//添加用户页面
public function user(){
$company_id = $this->request->param('id');
$arr = [
['id' => 0,'name'=>'员工'],
['id' => 1,'name'=>'领导'],
['id' => 2,'name'=>'总领导'],
];
$this->assign('list',$arr);
$this->assign('company_id',$company_id);
return $this->fetch();
}
//新增提交
public function addPost(){
$data = $this->request->param();
$result = $this->validate($data, 'AdminProject');
if ($result !== true) {
$this->error($result);
}
//合并甲方员工
$keys = ['user_login','mobile','position'];
$common = new AdminCommonController();
$userModel = new UserModel();
$res = $common->array_merge_more($keys, $data['user_login'], $data['mobile'], $data['position']);
//创建甲方员工用户
$u_s_id = '';
foreach($res as $value){
$value['user_pass'] = cmf_password(123456);
$value['user_type'] = 2;
$value['identity'] = 0;
$value['create_time'] = time();
$arr = $userModel->create($value);
$uid = $arr->id;
$u_s_id .= $uid.',';
}
$u_s_id = ','.$u_s_id;
//合并甲方领导
$res1 = $common->array_merge_more($keys, $data['user_login1'], $data['mobile1'], $data['position1']);
//创建甲方领导
$u_l_id = '';
foreach($res1 as $value){
$value['user_pass'] = cmf_password(123456);
$value['user_type'] = 2;
$value['identity'] = 1;
$value['create_time'] = time();
$arr1 = $userModel->create($value);
$uid = $arr1->id;
$u_l_id .= $uid.',';
}
$u_l_id = ','.$u_l_id;
//如果有总领导
$u_ls_id = '';
$companyModel = new CompanyModel();
if($data['is_children'] == 1){
//合并甲方总领导
if(!empty($data['mobile2'])){
$res2 = $common->array_merge_more($keys, $data['user_login2'], $data['mobile2'], $data['position2']);
foreach ($res2 as $value2){
$res = $common->getIsMobile($value2['mobile']);
if(!$res){
//创建总领导
$value2['user_pass'] = cmf_password(123456);
$value2['user_type'] = 2;
$value2['identity'] = 2;
$value2['create_time'] = time();
$arr2 = $userModel->create($value2);
$u_ls_id .= $arr2->id.',';
}else{
$u_ls_id .= $res['id'].',';
}
}
}
}
if(!empty($u_ls_id)){
$u_ls_id = ','.$u_ls_id;
}
//创建甲方公司
$admin_id = cmf_get_current_admin_id();
//乙方项目id
$company_id = $common->getProjectId($admin_id);
$company_a['pid'] = $company_id;//乙方企业id
$company_a['u_l_id'] = $u_l_id;//领导uid
$company_a['u_ls_id'] = $u_ls_id;//总领导uid
$company_a['company_name'] = $data['company_name'];//甲方公司名称
if($data['is_children'] == 1){
$company_a['company_name_head'] = $data['company_name_head'];//甲方总公司名称
$company_a['head_logo'] = $data['head_logo'];//总公司logo
//$company_a['address'] = $data['address'];//地区
}
$company_a['u_s_id'] = $u_s_id;//甲方员工uid
$company_a['is_children'] = $data['is_children'];
$company_a['logo'] = $data['logo'];//logo
$company_a['license'] = $data['license'];//营业执照
$company_a['create_time'] = time();
$res_company = $companyModel->create($company_a);
if($res_company){
//甲方公司id
$a_cid = $res_company->id;
//创建项目
$project['name'] = $data['name'];
$project['type'] = '1,2,3,4,5,6,7';
$project['is_inspect'] = $data['is_inspect'];
$project['a_cid'] = $a_cid;
$project['a_sid'] = $u_s_id;//甲方员工
$project['b_cid'] = $company_id;//乙方企业id
$project['b_sid'] = ','.implode(',',$data['u_s_id']).',';//乙方负责项目员工
$project['create_time'] = time();
$projectModel = new ProjectModel();
$res_project = $projectModel->create($project);
//日检
if(isset($data['point_name']) && !empty($data['point_name'])){
$arr = [];
$k = 0;
foreach($data['point_name'] as $key=>$value){
$k += 0;
$arr[$k]['point_name'] = $value;
$arr[$k]['p_id'] = $res_project->id;
$k++;
}
$pointModel = new PointModel();
$pointModel->saveAll($arr);
}
//月检
if(isset($data['check_name']) && !empty($data['check_name'])){
$arr = [];
$k = 0;
foreach($data['check_name'] as $key=>$value){
$k += 0;
$arr[$k]['point_name'] = $value;
$arr[$k]['p_id'] = $res_project->id;
$k++;
}
$spotModel = new CheckPointModel();
$spotModel->saveAll($arr);
}
//更新默认服务
$res1 = $this->getServiceRule();
$serviceModel = new ServiceRuleModel();
foreach($res1 as $value){
$c_id = $value['c_id'].$a_cid.',';
$serviceModel->where('id',$value['id'])->update(['c_id'=>$c_id]);
}
}
$this->success("添加成功!", url("AdminProject/index"));
}
//获取所有服务列表
public function getServiceRule(){
$res = Db::name('service_rule')
->field('id,c_id')
->select()
->toArray();
return $res;
}
//设置服务页面
public function edit(){
$id = $this->request->param('id');
$common = new AdminCommonController();
//获取项目相关内容
$post = $common->getProject(['id'=>$id],'id,name,a_cid,b_sid,a_sid,b_cid,is_inspect');
//根据甲方企业id获取甲方企业名称,logo,营业执照等信息
$part_a = $common->getCompanyById($post['a_cid'],'*');
$post['part_a'] = $part_a;
//获取甲方企业总领导
$u_ls_ids = explode(',',trim($part_a['u_ls_id'],','));
$post['u_ls_id_a'] = $common->getUserName($u_ls_ids);
//获取甲方企业负责人
$u_l_ids = explode(',',trim($part_a['u_l_id'],','));
$post['u_l_id_a'] = $common->getUserName($u_l_ids);
//获取甲方企业员工
$u_s_ids = explode(',',trim($part_a['u_s_id'],','));
$post['u_s_id_a'] = $common->getUserName($u_s_ids);
//查询日检点名称
$point = Db::name('point')
->where('p_id',$id)
->select()
->toArray();
$post['point'] = $point;
//查询月检点名称
$point = Db::name('check_point')
->where('p_id',$id)
->select()
->toArray();
$post['check_point'] = $point;
//乙方企业,乙方人员
$res = $common->getCompanyById($post['b_cid'],'id,company_name,u_s_id');
$u_s_id = explode(',',trim($res['u_s_id'],','));
$post['company_name_b'] = $res['company_name'];
$post['u_s_id_b'] = $common->getUserName($u_s_id);
//乙方服务员工
$post['b_sid'] = explode(',',trim($post['b_sid'],','));
$this->assign('post',$post);
//登录人id
$admin_id = cmf_get_current_admin_id();
$this->assign('login_uid',$admin_id);
return $this->fetch();
}
//设置保存页面
public function editPost(){
$data = $this->request->param();
$result = $this->validate($data, 'AdminProject');
if ($result !== true) {
$this->error($result);
}
$projectModel = new ProjectModel();
$common = new AdminCommonController();
$b_sid = ','.implode($data['u_s_id_b'],',').',';
//更新项目名称
$projectModel->where('id',$data['id'])->update(['name'=>$data['name'],'b_sid'=>$b_sid,'is_inspect'=>$data['is_inspect']]);
//甲方企业id,甲方员工id
$project = $common->getProject(['id'=>$data['id']],'id,a_cid');
//领导
if(!empty($data['u_l_id'])){
$company_a['u_l_id'] = ','.implode($data['u_l_id'],',').',';//领导
}
//员工
if(!empty($data['u_s_id'])){
$company_a['u_s_id'] = ','.implode($data['u_s_id'],',').',';//员工
}
$companyModel = new CompanyModel();
//更新甲方企业公司名称,logo,营业执照
$company_a['company_name'] = $data['company_name'];
$company_a['is_children'] = $data['is_children'];
$company_a['logo'] = $data['logo'];
$company_a['license'] = $data['license'];
if($data['is_children'] == 1){
$company_a['company_name_head'] = $data['company_name_head'];//甲方总公司名称
$company_a['head_logo'] = $data['head_logo'];//总公司logo
//$company_a['address'] = $data['address'];//地区
if(!empty($data['u_ls_id'])){
$company_a['u_ls_id'] = ','.implode($data['u_ls_id'],',').',';//总领导
}
}else{
$company_a['company_name_head'] = '';//甲方总公司名称
//$company_a['address'] = '';//地区
$company_a['u_ls_id'] = '';//总领导
}
$companyModel->where('id',$project['a_cid'])->update($company_a);
//更新日检点
if(isset($data['point_name']) && !empty($data['point_name'])){
$pointModel = new PointModel();
if(isset($data['point_id']) && !empty($data['point_id'])){
$keys = ['id','point_name'];
$point = $common->array_merge_more($keys, $data['point_id'], $data['point_name']);
$arr = [];
foreach($point as $key=>$value){
if(isset($value['id'])){
$arr[$key]['id'] = $value['id'];
}
$arr[$key]['point_name'] = $value['point_name'];
$arr[$key]['p_id'] = $data['id'];
}
$ids = array_column($point,'id');
//删除无用的
$pointModel->where('p_id',$data['id'])->whereNotIn('id',$ids)->delete();
//新增或编辑已有的
$pointModel->saveAll($arr);
}else{
$arr = [];
$k = 0;
foreach($data['point_name'] as $key=>$value){
$k += 0;
$arr[$k]['point_name'] = $value;
$arr[$k]['p_id'] = $data['id'];
$k++;
}
$pointModel->saveAll($arr);
}
}
//更新月检点
if(isset($data['check_name']) && !empty($data['check_name'])){
$spotModel = new CheckPointModel();
if(isset($data['check_id']) && !empty($data['check_id'])){
$keys = ['id','point_name'];
$point = $common->array_merge_more($keys, $data['check_id'], $data['check_name']);
$arr = [];
foreach($point as $key=>$value){
if(isset($value['id'])){
$arr[$key]['id'] = $value['id'];
}
$arr[$key]['point_name'] = $value['point_name'];
$arr[$key]['p_id'] = $data['id'];
}
$ids = array_column($point,'id');
//删除无用的
$spotModel->where('p_id',$data['id'])->whereNotIn('id',$ids)->delete();
//新增或编辑已有的
$spotModel->saveAll($arr);
}else{
$arr = [];
$k = 0;
foreach($data['check_name'] as $key=>$value){
$k += 0;
$arr[$k]['point_name'] = $value;
$arr[$k]['p_id'] = $data['id'];
$k++;
}
$spotModel->saveAll($arr);
}
}
$this->success("修改成功!", url("AdminProject/index"));
}
//添加用户提交
public function addUserPost(){
$data = $this->request->param();
$adminCommon = new AdminCommonController();
//创建普通用户
$userModel = new UserModel();
$arr['user_login'] = $data['user_login'];
$arr['mobile'] = $data['mobile'];
$arr['identity'] = $data['identity'];
$arr['position'] = $data['position'];
$arr['user_pass'] = cmf_password(123456);
$arr['user_type'] = 2;
$arr['create_time'] = time();
if($data['identity'] == 2){
//总领导
$res = $adminCommon->getIsMobile($data['mobile']);
if($res){
//存在则不用添加
$res_user = 2;
$uid = $res['id'];
}else{
//不存在则新增用户
$res_user = $userModel->create($arr);
$uid = $res_user->id;
}
}else{
$res = $adminCommon->getIsMobile($data['mobile']);
if($res){
$this->error('手机号不能重复');
}
$res_user = $userModel->create($arr);
$uid = $res_user->id;
}
if($res_user){
$common = new AdminCommonController();
//甲方企业id,甲方员工id
$project = $common->getProject(['id'=>$data['project_id']],'id,a_cid,a_sid');
//更新所属公司的员工或领导
$companyModel = new CompanyModel();
if($data['identity'] == 0){
//更新项目甲方员工
$projectModel = new ProjectModel();
$a_sid = $project['a_sid'].$uid.',';
$projectModel->where('id',$data['project_id'])->update(['a_sid'=>$a_sid]);
//更新甲方公司的员工
$res = $this->getStaffLeader($project['a_cid'],'id,u_s_id');
$u_s_id = $res['u_s_id'].$uid.',';
$res1 = $companyModel->where('id',$project['a_cid'])->update(['u_s_id'=>$u_s_id]);
}else if($data['identity'] == 1){
//更新甲方公司的领导
$res = $this->getStaffLeader($project['a_cid'],'id,u_l_id');
$u_l_id = $res['u_l_id'].$uid.',';
$res1 = $companyModel->where('id',$project['a_cid'])->update(['u_l_id'=>$u_l_id]);
}else{
//更新甲方公司的总领导
$res = $this->getStaffLeader($project['a_cid'],'id,u_ls_id');
$u_ls_id = $res['u_ls_id'].$uid.',';
$res1 = $companyModel->where('id',$project['a_cid'])->update(['u_ls_id'=>$u_ls_id]);
}
if($res1){
$this->success("添加成功");
}else{
$this->error("失败");
}
}
$this->error("保存失败");
}
//删除用户提交
public function delUserPost(){
$data = $this->request->param();
$userModel = new UserModel();
$common = new AdminCommonController();
//甲方企业id,甲方员工id
$project = $common->getProject(['id'=>$data['project_id']],'id,a_cid,a_sid');
if($data['identity'] == 2){
//总领导,查询该账号是否存在其他项目中
$u_ls_id = ','.$data['uid'].',';
$res = $this->getLeadersCount(['id'=>['<>',$project['a_cid']],'u_ls_id'=>['like','%'.$u_ls_id.'%']]);
if($res == 0){
//不存在则删除
$res_user = $userModel->where(['id'=>$data['uid']])->delete();
}else{
//存在不用删除
$res_user = 1;
}
}else{
$res_user = $userModel->where(['id'=>$data['uid']])->delete();
}
if($res_user){
$companyModel = new CompanyModel();
$uid = ','.$data['uid'];
if($data['identity'] == 0){
//更新项目甲方员工
$projectModel = new ProjectModel();
$a_sid = str_replace($uid,'',$project['a_sid']);
$projectModel->where('id',$data['project_id'])->update(['a_sid'=>$a_sid]);
//更新甲方公司的员工
$res = $this->getStaffLeader($project['a_cid'],'id,u_s_id');
$u_s_id = str_replace($uid,'',$res['u_s_id']);
$res1 = $companyModel->where('id',$project['a_cid'])->update(['u_s_id'=>$u_s_id]);
}else if($data['identity'] == 1){
//更新甲方公司的领导
$res = $this->getStaffLeader($project['a_cid'],'id,u_l_id');
$u_l_id = str_replace($uid,'',$res['u_l_id']);
$res1 = $companyModel->where('id',$project['a_cid'])->update(['u_l_id'=>$u_l_id]);
}else{
//更新甲方公司的总领导
$res = $this->getStaffLeader($project['a_cid'],'id,u_ls_id');
$u_ls_id = str_replace($uid,'',$res['u_ls_id']);
$res1 = $companyModel->where('id',$project['a_cid'])->update(['u_ls_id'=>$u_ls_id]);
}
if($res1){
//更新推送甲方表
$res_push = $this->getPushId($data['project_id']);
if($res_push){
$p_uid = trim($res_push['push_uid'],',');
$p_uid_s = explode(',',$p_uid);
if(in_array($data['uid'],$p_uid_s)){
$push_uid = $uid.$res_push['push_uid'];
$setPushModel = new SetPushModel();
$setPushModel->where('project_id',$data['project_id'])->update(['push_uid'=>$push_uid]);
}
}
$this->success("删除成功");
}else{
$this->error("失败");
}
}
$this->error("删除用户失败");
}
//查询甲方其他公司是否存在总领导
public function getLeadersCount($where){
$res = Db::name('company')
->where($where)
->count();
return $res;
}
//查询甲方公司领导或者员工
public function getStaffLeader($id,$field){
$res = Db::name('company')
->where('id',$id)
->field($field)
->find();
return $res;
}
//查询项目是否存在员工
public function getProjectLeader($where){
$res = Db::name('project')
->where($where)
->select()
->toArray();
return $res;
}
//推送设置
public function set(){
$id = $this->request->param('id');
$common = new AdminCommonController();
//获取项目甲方id,乙方id,乙方项目组人uid
$post = $common->getProject(['id'=>$id],'id,a_cid,b_cid,b_sid');
//显示甲方领导uid,总领导uid,员工uid
$part_res = $common->getCompanyById($post['a_cid'],'id,u_l_id,u_ls_id,u_s_id');
//员工
$u_s_ids_a = explode(',',trim($part_res['u_s_id'],','));
$part_a['u_s_id'] = $common->getUserName($u_s_ids_a);
//领导
$u_l_ids_a = explode(',',trim($part_res['u_l_id'],','));
$part_a['u_l_id'] = $common->getUserName($u_l_ids_a);
//总领导
$u_ls_ids_a = explode(',',trim($part_res['u_ls_id'],','));
$part_a['u_ls_id'] = $common->getUserName($u_ls_ids_a);
$this->assign('set',$part_a);
//登录人id
$admin_id = cmf_get_current_admin_id();
$this->assign('login_uid',$admin_id);
//查询设置人员
$set_push = $common->isSetPush($id);
$set_push = explode(',',trim($set_push['push_uid'],','));
$this->assign('set_push',$set_push);
$this->assign('project_id',$id);
return $this->fetch();
}
//推送设置提交
public function setPost(){
$param = $this->request->param();
$setPushModel = new SetPushModel();
$push_sid = '';
if(isset($param['u_s_id'])){
$push_sid = implode($param['u_s_id'],',').',';
}
$push_lid = '';
if(isset($param['u_l_id'])){
$push_lid = implode($param['u_l_id'],',').',';
}
$push_lsid = '';
if(isset($param['u_ls_id'])){
$push_lsid = implode($param['u_ls_id'],',').',';
}
$push_uid = $push_sid.$push_lid.$push_lsid;
$common = new AdminCommonController();
$res = $common->isSetPush($param['project_id']);
if($res){
if(!empty($push_uid)){
$push_uid = ','.$push_uid;
$setPushModel->where('project_id',$param['project_id'])->update(['push_uid'=>$push_uid]);
}
}else{
if(!empty($push_uid)){
$push_uid = ','.$push_uid;
$arr['push_uid'] = $push_uid;
$arr['project_id'] = $param['project_id'];
$arr['create_time'] = time();
$setPushModel->create($arr);
}
}
$this->success("设置成功!", url("AdminProject/index"));
}
//根据项目id查询推送甲方人员id
public function getPushId($project_id){
$res = Db::name('set_push')
->where('project_id',$project_id)
->field('id,push_uid')
->find();
return $res;
}
}