考勤算法

考勤算法


//获取打卡次数
$sworknum=$_CONFIG->config_data('sworknum');
print_r($sworknum);
$swork=$_CONFIG->config_data('swork');
$ework=$_CONFIG->config_data('ework');
$sworkex=explode(':',$swork);
$eworkex=explode(':',$ework);
print_r($sworkex);
print_r($eworkex);
if($sworknum=='0'){
$swork1=$_CONFIG->config_data('swork1');
$ework1=$_CONFIG->config_data('ework1');
$swork1ex=explode(':',$swork1);
$ework1ex=explode(':',$ework1);
print_r($swork1ex);
print_r($ework1ex);
}
$dates=get_date('H',PHP_TIME)*60+get_date('i',PHP_TIME);
$datee=$sworkex[0]*60+$sworkex[1];
$number=$dates-$datee;
print_r($dates);
echo "
";
print_r($datee);
echo "
";
print_r($number);
echo "
";

if ($do == 'list') {
//列表信息 
$wheresql = '';
$page = max(1, getGP('page','G','int'));
$pagesize = $_CONFIG->config_data('pagenum');
$offset = ($page - 1) * $pagesize;
$url = 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'';
$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."registration WHERE uid='".$_USER->id."' ORDER BY id desc");
    $sql = "SELECT * FROM ".DB_TABLEPRE."registration WHERE uid='".$_USER->id."' ORDER BY id desc LIMIT $offset, $pagesize";
$result = $db->fetch_all($sql);
//生成打卡记录
$user = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."registration  WHERE date='".get_date('Y-m-d',PHP_TIME)."'  and uid='".$_USER->id."' ");
if($user['id']==''){
$registration = array(
'name' => get_realname($_USER->id),
'uid' => $_USER->id,
'date' => get_date('Y-m-d',PHP_TIME),
'year' => get_date('Y',PHP_TIME),
'month' => get_date('m',PHP_TIME),
'day' => get_date('d',PHP_TIME)
);
insert_db('registration',$registration);
}
$rows = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."registration  WHERE date='".get_date('Y-m-d',PHP_TIME)."'  and uid='".$_USER->id."' ");
include_once('template/registrationlist.php');
}elseif ($do == 'add') {
$rows = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."registration  WHERE date='".get_date('Y-m-d',PHP_TIME)."'  and uid='".$_USER->id."' ");
$nums = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."registration_log WHERE rid='".$rows['id']."' ORDER BY lid desc");
$rid=$rows['id'];
print_r('$nums');
print_r($nums);
if($nums<1){
print_r('第一次打卡');
print_r(get_date('Hi',PHP_TIME));
print_r(str_replace(":","",$ework));
if(get_date('Hi',PHP_TIME)$hour=get_date('H:i',PHP_TIME);
if(get_date('Hi',PHP_TIME)>str_replace(":","",$swork)){
$dates=get_date('H',PHP_TIME)*60+get_date('i',PHP_TIME);
$datee=$sworkex[0]*60+$sworkex[1];
$number=$dates-$datee;
$type=1;
}else{
$number=0;
$type=0;
}
workbench_registadd($rid,$hour,$number,$type);
}else{
workbench_registadd($rid,'',0,'');
}
show_msg('成功更新考勤信息!', 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'');
}elseif($nums<2 && $nums>0 && get_date('Hi',PHP_TIME)>str_replace(":","",$swork)){
print_r('第二次打卡');
if($sworknum=='0'){
if(get_date('Hi',PHP_TIME)>str_replace(":","",$swork1)){
workbench_registadd($rid,'',0,'');
}else{
$hour=get_date('H:i',PHP_TIME);
if(get_date('Hi',PHP_TIME)$dates=get_date('H',PHP_TIME)*60+get_date('i',PHP_TIME);
$datee=$eworkex[0]*60+$eworkex[1];
$number=$datee-$dates;
$type=2;
}else{
$number=0;
$type=0;
}
workbench_registadd($rid,$hour,$number,$type);
}
}else{
$hour=get_date('H:i',PHP_TIME);
if(get_date('Hi',PHP_TIME)$dates=get_date('H',PHP_TIME)*60+get_date('i',PHP_TIME);
$datee=$eworkex[0]*60+$eworkex[1];
$number=$datee-$dates;
$type=2;
if($_GET['typeshow']==''){
show_msg_type('还没有到下班时间,您确定要执行早退吗!', 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'&typeshow=1&do=add');
exit;
}
}else{
$number=0;
$type=0;
}
workbench_registadd($rid,$hour,$number,$type);
}
show_msg('成功更新考勤信息!', 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'');
}elseif($sworknum=='0'){
print_r('要大于上班次结束时间');
if($nums<3 && $nums>=2 && get_date('Hi',PHP_TIME)>str_replace(":","",$ework)){
if(get_date('Hi',PHP_TIME)$hour=get_date('H:i',PHP_TIME);
if(get_date('Hi',PHP_TIME)>str_replace(":","",$swork1)){
$dates=get_date('H',PHP_TIME)*60+get_date('i',PHP_TIME);
$datee=$swork1ex[0]*60+$swork1ex[1];
$number=$dates-$datee;
$type=1;
}else{
$number=0;
$type=0;
}
workbench_registadd($rid,$hour,$number,$type);
}else{
workbench_registadd($rid,'',0,'');
}
show_msg('成功更新考勤信息!', 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'');
}elseif($nums<4 && get_date('Hi',PHP_TIME)>str_replace(":","",$swork1)){
$hour=get_date('H:i',PHP_TIME);
if(get_date('Hi',PHP_TIME)$dates=get_date('H',PHP_TIME)*60+get_date('i',PHP_TIME);
$datee=$ework1ex[0]*60+$ework1ex[1];
$number=$datee-$dates;
$type=2;
if($_GET['typeshow']==''){
show_msg_type('还没有到下班时间,您确定要执行早退吗!', 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'&typeshow=1&do=add');
exit;
}
}else{
$number=0;
$type=0;
}
workbench_registadd($rid,$hour,$number,$type);
show_msg('成功更新考勤信息!', 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'');
}else{
show_msg('请不要重复打卡!', 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'');
}
}else{
show_msg('请不要重复打卡!', 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'');
}


}

你可能感兴趣的:(php)