userCurGroup($userId,$orgId,$rule); }else{ // 历史 $device_sn = Db::name('user')->where('id',$userId)->value('device_sn'); $device_sn = $device_sn?$device_sn:""; $info = Db::name('attendance_user_class') ->where('day',$day) ->where('user_id',$userId) ->find(); if($info){ $record = Db::name('attendance_record') ->where('user_class_id',$info['id']) ->where('user_id',$userId) ->where('effective',1) ->field('id,lat,lng,address,type,from,create_time,kq_time,result,status,cate,remark') ->order('create_time asc') ->select(); $group = Db::name('attendance_group')->where('id',$info['group_id'])->find(); $addr = []; if($group['addr']){ $addr = Db::name('attendance_addr') ->where('id','in',$group['addr']) ->where('enable',1) ->where('del',0) ->field('id,title,distance,lat,lng') ->select(); } $dates = json_decode($info['content'],true); $newdate = []; foreach ($dates as $k=>$v){ $newdate[] = [ 'stime' => date('H:i',strtotime($v['stime'])), 'etime' => date('H:i',strtotime($v['etime'])) ]; } $data = [ 'group' => [ 'name' => $group['name'], 'dates' => $newdate?$newdate:null, 'rule' => $rule, 'day' => $day, 'cate' => $group['cate'], 'addr' => $addr?$addr:[] ], 'record' => $record?$record:[], 'device_sn' => $device_sn ]; }else{ // 无考勤 $record = Db::name('attendance_record') ->where('create_time','>=',date('Y-m-d').' 00:00:00') ->where('create_time','<=',date('Y-m-d').' 00:00:00') ->where('user_id',$userId) ->where('effective',1) ->field('id,lat,lng,address,type,from,create_time,kq_time,result,status,cate,remark') ->order('create_time asc') ->select(); $data = [ 'group' => [ 'name' => '未设置考勤组', 'dates' => null, 'rule' => $rule, 'day' => $day, 'cate' => '', 'addr' => [] ], 'record' => $record?$record:[], 'device_sn' => $device_sn ]; } } return $data; } private function userCurGroup($userId,$orgId,$rule){ $device_sn = Db::name('user')->where('id',$userId)->value('device_sn'); $curTime = time(); $day = date('Y-m-d'); $yday = date('Y-m-d',time() - 86400); $nday = date('Y-m-d',time() + 86400); // 获取今天的考勤组 $info = Db::name('attendance_user_class') ->where('day',$day) ->where('user_id',$userId) ->where('status',0) ->find(); if($info){ // 今日班次 $record = Db::name('attendance_record') ->where('user_class_id',$info['id']) ->where('user_id',$userId) ->where('effective',1) ->field('id,lat,lng,address,type,from,create_time,kq_time,result,status,cate,remark') ->order('create_time asc') ->select(); $group = Db::name('attendance_group')->where('id',$info['group_id'])->find(); $addr = []; if($group['addr']){ $addr = Db::name('attendance_addr') ->where('id','in',$group['addr']) ->where('enable',1) ->where('del',0) ->field('id,title,distance,lat,lng') ->select(); } $dates = json_decode($info['content'],true); $newdate = []; foreach ($dates as $k=>$v){ $newdate[] = [ 'stime' => date('H:i',strtotime($v['stime'])), 'etime' => date('H:i',strtotime($v['etime'])) ]; } $data = [ 'group' => [ 'name' => $group['name'], 'dates' => $newdate, 'rule' => $rule, 'day' => $day, 'cate' => $group['cate'], 'addr' => $addr?$addr:[] ], 'record' => $record?$record:[], 'device_sn' => $device_sn ]; }else{ // 今日班次不存在 // 昨日班次 $yinfo = Db::name('attendance_user_class') ->where('day',$yday) ->where('user_id',$userId) ->where('next',1) ->where('status',0) ->find(); // 今日班次 $class = model('AttendanceGroupClass')->getClassByDay($userId); if(!$class && !$yinfo){ $record = Db::name('attendance_record') ->where('create_time','>=',date('Y-m-d').' 00:00:00') ->where('user_id',$userId) ->where('effective',1) ->field('id,lat,lng,address,type,from,create_time,kq_time,result,status,cate,remark') ->order('create_time asc') ->select(); $data = [ 'group' => [ 'name' => '未设置考勤组', 'dates' => [], 'rule' => $rule, 'day' => $day, 'cate' => '', 'addr' => [] ], 'record' => $record?$record:[], 'device_sn' => $device_sn ]; }else if($yinfo && !$class){ // 昨天班次 $group = Db::name('attendance_group')->where('id',$yinfo['group_id'])->find(); $record = Db::name('attendance_record') ->where('user_class_id',$yinfo['id']) ->where('user_id',$userId) ->where('effective',1) ->field('id,lat,lng,address,type,from,create_time,kq_time,result,status,cate,remark') ->order('create_time asc') ->select(); $addr = []; if($group['addr']){ $addr = Db::name('attendance_addr') ->where('id','in',$group['addr']) ->where('enable',1) ->where('del',0) ->field('id,title,distance,lat,lng') ->select(); } $dates = json_decode($yinfo['content'],true); $newdate = []; foreach ($dates as $k=>$v){ $newdate[] = [ 'stime' => date('H:i',strtotime($v['stime'])), 'etime' => date('H:i',strtotime($v['etime'])) ]; } $data = [ 'group' => [ 'name' => $group['name'], 'dates' => $newdate, 'rule' => $rule, 'day' => $day, 'cate' => $group['cate'], 'addr' => $addr?$addr:[] ], 'record' => $record?$record:[], 'device_sn' => $device_sn ]; }else if(!$info && $class){ // 今日班次不为空 $nday = date('Y-m-d',time() + 86400); $content = json_decode($class['content'],true); $dates = $content['dates']; $newdates = []; $newdates2 = []; foreach ($dates as $k=>$v) { $newdates[] = [ "stime" => $v['snext'] > 0 ? $nday . ' ' . $v['stime'] . ':00' : $day . ' ' . $v['stime'] . ':00', "etime" => $v['enext'] > 0 ? $nday . ' ' . $v['etime'] . ':00' : $day . ' ' . $v['etime'] . ':00', "sstatus" => 0, "estatus" => 0, ]; $newdates2[] = [ "stime" => $v['stime'], "etime" => $v['etime'], ]; } $addr = []; if($class['addr']){ $addr = Db::name('attendance_addr') ->where('id','in',$class['addr']) ->where('enable',1) ->where('del',0) ->field('id,title,distance,lat,lng') ->select(); } $group = Db::name('attendance_group') ->where('id',$yinfo['group_id'])->find(); $data = [ 'group' => [ 'name' => $class['group_name'], 'dates' => $newdates2, 'rule' => $rule, 'day' => $day, 'cate' => $group['cate'], 'addr' => $addr?$addr:[] ], 'record' => [], 'device_sn' => $device_sn ]; }else{ $nday = date('Y-m-d',time() + 86400); $content = json_decode($class['content'],true); $dates = $content['dates']; $newdates = []; $newdates2 = []; foreach ($dates as $k=>$v) { $newdates[] = [ "stime" => $v['snext'] > 0 ? $nday . ' ' . $v['stime'] . ':00' : $day . ' ' . $v['stime'] . ':00', "etime" => $v['enext'] > 0 ? $nday . ' ' . $v['etime'] . ':00' : $day . ' ' . $v['etime'] . ':00', "sstatus" => 0, "estatus" => 0, ]; $newdates2[] = [ "stime" => $v['stime'], "etime" => $v['etime'], ]; } if($curTime >= strtotime($newdates[0]['stime']) - 2*60){ // 显示今日 $nday = date('Y-m-d',time() + 86400); $content = json_decode($class['content'],true); $dates = $content['dates']; $newdates = []; $newdates2 = []; foreach ($dates as $k=>$v) { $newdates[] = [ "stime" => $v['snext'] > 0 ? $nday . ' ' . $v['stime'] . ':00' : $day . ' ' . $v['stime'] . ':00', "etime" => $v['enext'] > 0 ? $nday . ' ' . $v['etime'] . ':00' : $day . ' ' . $v['etime'] . ':00', "sstatus" => 0, "estatus" => 0, ]; $newdates2[] = [ "stime" => $v['stime'], "etime" => $v['etime'], ]; } $addr = []; if($class['addr']){ $addr = Db::name('attendance_addr') ->where('id','in',$class['addr']) ->where('enable',1) ->where('del',0) ->field('id,title,distance,lat,lng') ->select(); } $data = [ 'group' => [ 'name' => $class['group_name'], 'dates' => $newdates2, 'rule' => $rule, 'day' => $day, 'cate' => $yinfo['cate'], 'addr' => $addr?$addr:[] ], 'record' => [], 'device_sn' => $device_sn ]; }else{ // 显示昨日 $group_name = Db::name('attendance_group')->where('id',$yinfo['group_id'])->value('name'); $record = Db::name('attendance_record') ->where('user_class_id',$yinfo['id']) ->where('user_id',$userId) ->where('effective',1) ->field('id,lat,lng,address,type,from,create_time,kq_time,result,status,cate,remark') ->order('create_time asc') ->select(); $dates = json_decode($yinfo['content'],true); $newdate = []; foreach ($dates as $k=>$v){ $newdate[] = [ 'stime' => date('H:i',strtotime($v['stime'])), 'etime' => date('H:i',strtotime($v['etime'])) ]; } $addr = []; if($yinfo['addr']){ $addr = Db::name('attendance_addr') ->where('id','in',$yinfo['addr']) ->where('enable',1) ->where('del',0) ->field('id,title,distance,lat,lng') ->select(); } $data = [ 'group' => [ 'name' => $group_name, 'dates' => $newdate, 'rule' => $rule, 'day' => $day, 'cate' => $yinfo['cate'], 'addr' => $addr?$addr:[] ], 'record' => $record?$record:[], 'device_sn' => $device_sn ]; } } } return $data; } }