AdminPartAController.php
5.8 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
<?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 cmf\controller\AdminBaseController;
use think\Db;
use think\db\Query;
use app\portal\model\InspectModel;
class AdminPartAController extends AdminBaseController
{
private $identity_arr = ['员工','领导','总领导'];
//列表页
public function index(){
$common = new AdminCommonController();
//查询甲方员工
$staff_A = $common->getPartA();
//员工
$s_ids = '';
//领导
$l_ids = '';
//总领导
$ls_ids = '';
foreach($staff_A as $s_value){
$s_ids .= $s_value['u_s_id'].',' ;
$l_ids .= $s_value['u_l_id'].',';
if(!empty($s_value['u_ls_id'])){
$ls_ids .= $s_value['u_ls_id'].',';
}
}
$ids = $s_ids.$l_ids.$ls_ids;
$ids = explode(',',trim($ids,','));
//根据id获取员工
$list = Db::name('user')
->whereIn('id',$ids)
->where('user_status',1)
->where(function (Query $query) {
$data = $this->request->param();
if (!empty($data['user_login'])) {
$user_login = $data['user_login'];
$query->where('user_login', 'like', "%$user_login%");
}
if (!empty($data['mobile'])) {
$mobile = $data['mobile'];
$query->where('mobile', 'like', "%$mobile%");
}
})
->field('id,user_login,avatar,identity,mobile,position')
->order('id desc')
->paginate(10,false,['query'=>request()->param()]);
$s_user = $list->toArray();
foreach($s_user['data'] as &$value){
// $value['identity_a'] = $this->identity_arr[$value['identity']];
$uid = $value['id'];
$value['company_name_head'] = '';
$value['company_name'] = '';
$value['is_children'] = 0;
foreach($staff_A as $c_value){
if($value['identity'] == 0){
//员工
$u_s_ids = explode(',',trim($c_value['u_s_id'],','));
if(in_array($uid,$u_s_ids)){
$value['company_name'] = $c_value['company_name'];
//是否有子企业
if($c_value['is_children'] == 1){
$value['company_name_head'] = $c_value['company_name_head'];
}
$value['is_children'] = $c_value['is_children'];
//查找甲方员工所在的项目组
$arr = $common->getProjectA($c_value['id'],$uid);
$value['project_name'] = isset($arr['project_name'])&&!empty($arr['project_name'])?$arr['project_name']:'';
}
}else if($value['identity'] == 1){
//领导
if($uid == $c_value['u_l_id']){
$value['company_name'] = $c_value['company_name'];
//是否有子企业
if($c_value['is_children'] == 1){
$value['company_name_head'] = $c_value['company_name_head'];
}
$value['is_children'] = $c_value['is_children'];
}
}else{
//总领导
if($uid == $c_value['u_ls_id']){
$value['company_name'] = $c_value['company_name'];
//是否有子企业
if($c_value['is_children'] == 1){
$value['company_name_head'] = $c_value['company_name_head'];
}
$value['is_children'] = $c_value['is_children'];
}
}
}
}
$page = $list->render();
$host = new InspectModel();
$this->assign('host',$host::host);
$this->assign('list',$s_user['data']);
$this->assign('page',$page);
// 渲染模板输出
return $this->fetch();
}
//根据uid查询用户正常考勤日期
public function getNormalWork($uid){
//聚合相同日期
$res = Db::name('work')
->where(['uid'=>$uid])
->field('id,uid,create_time')
->group("DATE_FORMAT(FROM_UNIXTIME(create_time),'%Y-%m-%d')")
->select()
->toArray();
$normal = 0;
$not_normal = 0;
$arr = [];
foreach($res as $value){
$count = $this->getWorkCount($value['uid'],$value['create_time']);
if($count == 2){
//正常
$arr['normal'] = ++$normal;
}else{
//缺卡
$arr['not_normal'] = ++$not_normal;
}
}
return $arr;
}
//根据uid获取是否含有上班,下班
public function getWorkCount($uid,$create_time){
$time = date('Y-m-d',$create_time);
$time1 = date('Y-m-d',$create_time+86400);
//查询所有记录
$count = Db::name('work')
->where(['uid'=>$uid])
->whereTime('create_time',[$time,$time1])
->count();
return $count;
}
}