PHP计算连续签到天数以及累计签到天数

时间:2023-03-09 09:49:37
PHP计算连续签到天数以及累计签到天数

代码如下:

/**
* 统计连续签到天数以及累计签到天数
* @param string $user_long_id 用户ID
* @return array 一维数组
*/
function sign_count($user_long_id){
//获取上个月最后一天
$endDay = strtotime(date('Y-m-t', strtotime('-1 month')));
// $time = strtotime("2017-11-22 12:00:00");
$cur_day = date('Ymd',time());
$sql = "select sign_time from bzf_sign_info where user_long_id = '$user_long_id' and sign_score = 1 and sign_time > $endDay order by sign_time desc";
$arr = $this->doquery_rows($sql); $add_count_days = ;//连续签到天数
$count = ; //累计签到天数
$day_list = [];
if (!empty($arr)){
foreach ($arr as $k=>$v){
$day_list[] = $v['sign_time'];
}
$count = count($day_list); //累计签到天数
}
if($cur_day - > date("Ymd",$day_list[])){
return array('add_days'=>$add_count_days,'total_day'=>$count);
} else {
$add_count_days = ;//连续签到天数
}
for($i = ;$i < $count - ;$i++){
$res = $this->compareDay(date("Ymd",$day_list[$i]),date("Ymd",$day_list[$i+]));
if($res) $add_count_days++;
else break;
}
return array('add_days'=>$add_count_days,'total_day'=>$count);
} /**
* 比较当天签到天数与上一次签到时间
* @param string $curDay 当天签到天数
* @param string $nextDay 上一次签到天数
* @return boolean
*/
function compareDay($curDay,$nextDay)
{
if($curDay - == $nextDay){
return true;
}else{
return false;
}
}

以上就是这次的全部内容!