mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-05 07:20:58 +08:00
Google Authenticator
This commit is contained in:
@@ -23,10 +23,16 @@ class Attendance
|
||||
public function attend($initial = 10, $step = 5, $maximum = 2000, $continous = array())
|
||||
{
|
||||
if($this->check(true)) return false;
|
||||
$count = get_row_count('attendance', sprintf('WHERE `uid` = %u', $this->userid));
|
||||
$points = min($initial + $step * $count, $maximum);
|
||||
$res = sql_query(sprintf('SELECT DATEDIFF(%s, `added`) AS diff, `days` FROM `attendance` WHERE `uid` = %u ORDER BY `id` DESC LIMIT 1', sqlesc($this->curdate), $this->userid)) or sqlerr(__FILE__,__LINE__);
|
||||
list($datediff, $days) = mysql_num_rows($res) ? mysql_fetch_row($res) : array('diff' => 0, 'days' => 0);
|
||||
$res = sql_query(sprintf('SELECT DATEDIFF(%s, `added`) AS diff, `days`, `total_days`, `total_points` FROM `attendance` WHERE `uid` = %u ORDER BY `id` DESC LIMIT 1', sqlesc($this->curdate), $this->userid)) or sqlerr(__FILE__,__LINE__);
|
||||
$doUpdate = mysql_num_rows($res);
|
||||
if ($doUpdate) {
|
||||
$row = mysql_fetch_row($res);
|
||||
do_log("uid: {$this->userid}, row: " . json_encode($row));
|
||||
} else {
|
||||
$row = [0, 0, 0, 0];
|
||||
}
|
||||
$points = min($initial + $step * $row['total_attend_times'], $maximum);
|
||||
list($datediff, $days, $totalDays, $totalPoints) = $row;
|
||||
$cdays = $datediff == 1 ? ++$days : 1;
|
||||
if($cdays > 1){
|
||||
krsort($continous);
|
||||
@@ -37,10 +43,23 @@ class Attendance
|
||||
}
|
||||
}
|
||||
}
|
||||
sql_query(sprintf('INSERT INTO `attendance` (`uid`,`added`,`points`,`days`) VALUES (%u, %s, %u, %u)', $this->userid, sqlesc(date('Y-m-d H:i:s')), $points, $cdays)) or sqlerr(__FILE__, __LINE__);
|
||||
// sql_query(sprintf('INSERT INTO `attendance` (`uid`,`added`,`points`,`days`) VALUES (%u, %s, %u, %u)', $this->userid, sqlesc(date('Y-m-d H:i:s')), $points, $cdays)) or sqlerr(__FILE__, __LINE__);
|
||||
if ($doUpdate) {
|
||||
$sql = sprintf(
|
||||
'UPDATE `attendance` set added = %s, points = %s, days = %s, total_days= %s, total_points = %s where uid = %s order by id desc limit 1',
|
||||
sqlesc(date('Y-m-d H:i:s')), $points, $cdays, $totalDays + 1, $totalPoints + $points, $this->userid
|
||||
);
|
||||
} else {
|
||||
$sql = sprintf(
|
||||
'INSERT INTO `attendance` (`uid`, `added`, `points`, `days`, `total_days`, `total_points`) VALUES (%u, %s, %u, %u, %u, %u)',
|
||||
$this->userid, sqlesc(date('Y-m-d H:i:s')), $points, $cdays, $totalDays + 1, $totalPoints + $points
|
||||
);
|
||||
}
|
||||
do_log(sprintf('uid: %s, date: %s, doUpdate: %s, sql: %s', $this->userid, $this->curdate, $doUpdate, $sql), 'notice');
|
||||
sql_query($sql) or sqlerr(__FILE__, __LINE__);
|
||||
KPS('+', $points, $this->userid);
|
||||
global $Cache;
|
||||
$Cache->delete_value($this->cachename);
|
||||
return array(++$count, $cdays, $points);
|
||||
return array(++$totalDays, $cdays, $points);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user