mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-22 02:47:27 +08:00
exam progress update when get
This commit is contained in:
@@ -440,6 +440,10 @@ class ExamRepository extends BaseRepository
|
||||
}
|
||||
$examUser = $examUser->first();
|
||||
}
|
||||
if ($examUser->status != ExamUser::STATUS_NORMAL) {
|
||||
do_log("examUser: {$examUser->id} status not normal, won't update progress.");
|
||||
return false;
|
||||
}
|
||||
$exam = $examUser->exam;
|
||||
if (!$user instanceof User) {
|
||||
$user = $examUser->user()->select(['id', 'uploaded', 'downloaded', 'seedtime', 'leechtime', 'seedbonus'])->first();
|
||||
@@ -548,7 +552,8 @@ class ExamRepository extends BaseRepository
|
||||
"[UPDATE_PROGRESS] %s, result: %s, cost time: %s sec",
|
||||
json_encode($update), var_export($result, true), sprintf('%.3f', microtime(true) - $beginTimestamp)
|
||||
));
|
||||
return true;
|
||||
$examUser->progress_formatted = $examProgressFormatted;
|
||||
return $examUser;
|
||||
}
|
||||
|
||||
|
||||
@@ -557,19 +562,15 @@ class ExamRepository extends BaseRepository
|
||||
*
|
||||
* @param $uid
|
||||
* @param null $status
|
||||
* @param string[] $with
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function getUserExamProgress($uid, $status = null, $with = ['exam', 'user'])
|
||||
public function getUserExamProgress($uid, $status = null)
|
||||
{
|
||||
$logPrefix = "uid: $uid";
|
||||
$query = ExamUser::query()->where('uid', $uid)->orderBy('exam_id', 'desc');
|
||||
if (!is_null($status)) {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
if (!empty($with)) {
|
||||
$query->with($with);
|
||||
}
|
||||
$examUsers = $query->get();
|
||||
if ($examUsers->isEmpty()) {
|
||||
do_log("$logPrefix, no examUser, query: " . last_query());
|
||||
@@ -579,6 +580,18 @@ class ExamRepository extends BaseRepository
|
||||
do_log("$logPrefix, user exam more than 1.", 'warning');
|
||||
}
|
||||
$examUser = $examUsers->first();
|
||||
$logPrefix .= ", examUser: " . $examUser->id;
|
||||
try {
|
||||
$updateResult = $this->updateProgress($examUser);
|
||||
if ($updateResult) {
|
||||
do_log("$logPrefix, [UPDATE_SUCCESS_RETURN_DIRECTLY]");
|
||||
return $updateResult;
|
||||
} else {
|
||||
do_log("$logPrefix, [UPDATE_SUCCESS_FAIL]");
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
do_log("$logPrefix, [UPDATE_SUCCESS_FAIL]: " . $exception->getMessage(), 'error');
|
||||
}
|
||||
$exam = $examUser->exam;
|
||||
$progress = $examUser->progress;
|
||||
do_log("$logPrefix, progress: " . nexus_json_encode($progress));
|
||||
|
||||
@@ -23,16 +23,16 @@ class Attendance
|
||||
public function attend($initial = 10, $step = 5, $maximum = 2000, $continous = array())
|
||||
{
|
||||
if($this->check(true)) return false;
|
||||
$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__);
|
||||
$res = sql_query(sprintf('SELECT DATEDIFF(%s, `added`) AS diff, `days`, `total_days` 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];
|
||||
$row = [0, 0, 0];
|
||||
}
|
||||
$points = min($initial + $step * $row['total_attend_times'], $maximum);
|
||||
list($datediff, $days, $totalDays, $totalPoints) = $row;
|
||||
list($datediff, $days, $totalDays) = $row;
|
||||
$cdays = $datediff == 1 ? ++$days : 1;
|
||||
if($cdays > 1){
|
||||
krsort($continous);
|
||||
|
||||
@@ -286,8 +286,6 @@ function docleanup($forceAll = 0, $printProgress = false) {
|
||||
if ($is_donor == 'yes' && $donortimes_bonus > 0)
|
||||
$all_bonus = $all_bonus * $donortimes_bonus;
|
||||
KPS("+",$all_bonus,$arr["userid"]);
|
||||
//update exam progress
|
||||
$examRep->updateProgress($arr['userid']);
|
||||
}
|
||||
}
|
||||
$log = 'calculate seeding bonus';
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ class Exam
|
||||
public function render($uid)
|
||||
{
|
||||
$examRep = new ExamRepository();
|
||||
$userExam = $examRep->getUserExamProgress($uid, ExamUser::STATUS_NORMAL, ['exam']);
|
||||
$userExam = $examRep->getUserExamProgress($uid, ExamUser::STATUS_NORMAL);
|
||||
if (empty($userExam)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user