根据用户信息及签到日期,获取用户起始的签到天数,可以根据当天是否签到获取连签天数
$signinTables = getAllSignTable();
// 当前月表
$curTable = 'signinlog'.date('Ym');
$signStartDate = '';
foreach ($signinTables as $table) {
// 应签天数
$needDays = $curTable == $table ? ((int)date('d') -1) : (int)date('t');
$monthFirstDay = date('Y-m-01',strtotime(substr($table,6).'01'));
$endDay = $curTable == $table ? date('Y-m-d',strtotime('-1 day')) : date('Y-m-t',strtotime($monthFirstDay));
// 该月累计签到天数
$sql = " select signdate from {$table} where userid={$userid}";
$result = $actDb->getAll($sql);
if ($needDays > count($result)) {
if (empty($result)) {
break;
}
$signDayArr = array_column($result,'signdate');
for($i = $endDay; $i >= $monthFirstDay; $i = date('Y-m-d',strtotime('-1 day',strtotime($i)))) {
if (!in_array($i,$signDayArr)) {
break 2;
}
$signStartDate = $i;
}
} else {
$signStartDate = date('Y-m-d',strtotime(substr($table,6).'01'));
}
}
echo $signStartDate;