where('org_id',$this->orgId)
->where('del',0)
->count();
$task = Db::name('daily_task')
->where('org_id',$this->orgId)
->where('status',2)
->where('del',0)
->count();
$recordIds = Db::name('comment')
->where('org_id',$this->orgId)
->where('type',0)
->where('score','<',3)
->column('from_id');
$taskIds = Db::name('daily_record')
->where('org_id',$this->orgId)
->whereIn('id',$recordIds)
->group('task_id')
->column('task_id');
$taskCount = Db::name('daily_task')
->where('org_id',$this->orgId)
->whereIn('id',$taskIds)
->where('del',0)
->where('status',2)
->count();
//合格数
$nums2 = $count - $taskCount;
$total = $total2 = 0;
if($count > 0){
$total = round($task/$count*100,0);
$total2 = round($nums2/$count*100,0);
}
$data = [
'list'=>['count'=>$total,'nums'=>$task],
'list2'=>['count'=>$total2,'nums'=>$nums2],
];
HelpHander::success($data);
}
//近7日检查情况概览
public function checkNums(){
$dlist = [
date('Ymd',strtotime('-6 days')),
date('Ymd',strtotime('-5 days')),
date('Ymd',strtotime('-4 days')),
date('Ymd',strtotime('-3 days')),
date('Ymd',strtotime('-2 days')),
date('Ymd',strtotime('-1 days')),
date('Ymd'),
];
$date = $list =$list2 = [];
foreach ($dlist as $k=>$v){
$date[] = date('m-d',strtotime($v));
$tt = date('Ymd',strtotime($v));
$count = Db::name('comment')
->where('org_id',$this->orgId)
->where('create_yyyymmdd',$tt)
->where('type',0)
->count();
$count2 = Db::name('comment')
->where('org_id',$this->orgId)
->where('create_yyyymmdd',$tt)
->where('type',0)
->avg('score');
$list[$k]= $count;
$list2[$k] = $count2;
}
$data = [
'title'=>$date,
'list'=>[
'list1'=>$list,
'list2'=>$list2,
]
];
HelpHander::success($data);
}
//员工排行榜
public function userRanking(){
$user = Db::name('daily_record')
->alias('dr')
->field('u.real_name,dr.user_id')
->join('user u','u.id=dr.user_id')
->where('dr.org_id',$this->orgId)
->group('dr.user_id')
->select();
$list = [];
foreach ($user as $k=>$v){
$list[$k]['count'] = Db::name('daily_record')
->where('user_id',$v['user_id'])
->where('org_id',$this->orgId)
->count();
$list[$k]['user_name'] = $v['real_name'];
}
$newList =array_slice(list_sort_by($list,'count','desc'),0,7) ;
$data = [];
foreach ($newList as $k=>$v){
if($k == 0){
$data[$k][] = '';
}
if($k == 1){
$data[$k][] = '';
}
if($k == 2){
$data[$k][] = '';
}
if($k == 3){
$data[$k][] = '';
}
if($k == 4){
$data[$k][] = '';
}
if($k == 5){
$data[$k][] = '';
}
if($k == 6){
$data[$k][] = '';
}
$data[$k][] = $v['user_name'];
$data[$k][] = $v['count'];
}
HelpHander::success($data);
}
public function dailyStatus(){
$lists = model('WorkTypeMode')->getRolesUserApp(9,$this->orgId);
$curday = date('Ymd');
$users = Db::name('daily_record')
->alias('dr')
->field('dr.user_id')
->join('daily_task dt','dt.id=dr.task_id')
->where('dt.del',0)
->where('dr.create_yyyymmdd',$curday)
->where('dt.status',1)
->where('dr.org_id',$this->orgId)
->group('dr.user_id')
->select();
$users = $users?$users:[];
$userIds = [];
foreach ($users as $k=>$v){
$userIds[] = $v['user_id'];
}
$nlists = $nlists2 = [];
foreach ($lists as $k=>$v){
if(!in_array($v['id'],$userIds)){
$nlists[] = $v;
}
}
//待命中的
$slist = $slist2 = [];
foreach ($nlists as $k=>$v){
$count = Db::name('daily_record')
->where('org_id',$this->orgId)
->where('user_id',$v['id'])
->where('create_yyyymmdd',$curday)
->count();
$addr = Db::name('daily_record')
->alias('dr')
->join('daily d','d.id=dr.daily_id')
->where('dr.org_id',$this->orgId)
->where('dr.user_id',$v['id'])
->where('dr.create_yyyymmdd',$curday)
->value('d.title');
$slist[$k][] = ''.$v['real_name'].'';
$slist[$k][] = ''.$count.'';
$slist[$k][] = ''.$addr.'';
}
//任务中的
foreach ($lists as $k=>$v){
if(in_array($v['id'],$userIds)){
$nlists2[] = $v;
}
}
foreach ($nlists2 as $k=>$v){
$count = Db::name('daily_record')
->where('org_id',$this->orgId)
->where('user_id',$v['id'])
->where('create_yyyymmdd',$curday)
->count();
$addr = Db::name('daily_record')
->alias('dr')
->join('daily d','d.id=dr.daily_id')
->where('dr.org_id',$this->orgId)
->where('dr.user_id',$v['id'])
->where('dr.create_yyyymmdd',$curday)
->value('d.title');
$slist2[$k][] = ''.$v['real_name'].'';
$slist2[$k][] = ''.$count.'';
$slist2[$k][] = ''.$addr.'';
}
$data = [
'list1'=>[
'list'=>$slist2,
'count'=>count($slist2),
],// 任务中
'list2'=>[
'list'=>$slist,
'count'=>count($slist),
],// 待命中
];
HelpHander::success($data);
}
public function taskRecordOne(){
$map[] = ['enable', '=', 1];
$map[] = ['org_id', '=', $this->orgId];
$map[] = ['del', '=', 0];
$lists = Db::name('daily')->where($map)->field('id,title')->order('id desc')->select();
$hours = model('Daily')->getTimeDaily($this->orgId);
foreach ($lists as $k=>$v){
$m = [];
$m[] = ['org_id','=',$this->orgId];
$m[] = ['daily_id','=',$v['id']];
$m[] = ['create_time','>=',$hours['start']];
$m[] = ['create_time','<',$hours['end']];
$count = Db::name('daily_record')->where($m)->count();
$lists[$k]['count'] = $count;
}
HelpHander::success($lists);
}
public function recordList(){
$list = Db::name('daily_record')
->field('task_id,user_id,create_time,daily_id')
->where('create_yyyymmdd',date('Ymd'))
->where('org_id',$this->orgId)
->order('id desc')
->select();
$data = [];
foreach ($list as $k=>$v){
$data[$k][] = Db::name('daily')->where('id',$v['daily_id'])->value('title');
$data[$k][] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
$data[$k][] = date('m-d H:i:s',strtotime($v['create_time']));
}
HelpHander::success($data);
}
}