exam progress update when get

This commit is contained in:
xiaomlove
2021-06-14 01:54:19 +08:00
parent 0c11ceaaa2
commit 67d68e73f7
4 changed files with 23 additions and 12 deletions
+19 -6
View File
@@ -440,6 +440,10 @@ class ExamRepository extends BaseRepository
} }
$examUser = $examUser->first(); $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; $exam = $examUser->exam;
if (!$user instanceof User) { if (!$user instanceof User) {
$user = $examUser->user()->select(['id', 'uploaded', 'downloaded', 'seedtime', 'leechtime', 'seedbonus'])->first(); $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", "[UPDATE_PROGRESS] %s, result: %s, cost time: %s sec",
json_encode($update), var_export($result, true), sprintf('%.3f', microtime(true) - $beginTimestamp) 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 $uid
* @param null $status * @param null $status
* @param string[] $with
* @return mixed|null * @return mixed|null
*/ */
public function getUserExamProgress($uid, $status = null, $with = ['exam', 'user']) public function getUserExamProgress($uid, $status = null)
{ {
$logPrefix = "uid: $uid"; $logPrefix = "uid: $uid";
$query = ExamUser::query()->where('uid', $uid)->orderBy('exam_id', 'desc'); $query = ExamUser::query()->where('uid', $uid)->orderBy('exam_id', 'desc');
if (!is_null($status)) { if (!is_null($status)) {
$query->where('status', $status); $query->where('status', $status);
} }
if (!empty($with)) {
$query->with($with);
}
$examUsers = $query->get(); $examUsers = $query->get();
if ($examUsers->isEmpty()) { if ($examUsers->isEmpty()) {
do_log("$logPrefix, no examUser, query: " . last_query()); 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'); do_log("$logPrefix, user exam more than 1.", 'warning');
} }
$examUser = $examUsers->first(); $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; $exam = $examUser->exam;
$progress = $examUser->progress; $progress = $examUser->progress;
do_log("$logPrefix, progress: " . nexus_json_encode($progress)); do_log("$logPrefix, progress: " . nexus_json_encode($progress));
+3 -3
View File
@@ -23,16 +23,16 @@ class Attendance
public function attend($initial = 10, $step = 5, $maximum = 2000, $continous = array()) public function attend($initial = 10, $step = 5, $maximum = 2000, $continous = array())
{ {
if($this->check(true)) return false; 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); $doUpdate = mysql_num_rows($res);
if ($doUpdate) { if ($doUpdate) {
$row = mysql_fetch_row($res); $row = mysql_fetch_row($res);
do_log("uid: {$this->userid}, row: " . json_encode($row)); do_log("uid: {$this->userid}, row: " . json_encode($row));
} else { } else {
$row = [0, 0, 0, 0]; $row = [0, 0, 0];
} }
$points = min($initial + $step * $row['total_attend_times'], $maximum); $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; $cdays = $datediff == 1 ? ++$days : 1;
if($cdays > 1){ if($cdays > 1){
krsort($continous); krsort($continous);
-2
View File
@@ -286,8 +286,6 @@ function docleanup($forceAll = 0, $printProgress = false) {
if ($is_donor == 'yes' && $donortimes_bonus > 0) if ($is_donor == 'yes' && $donortimes_bonus > 0)
$all_bonus = $all_bonus * $donortimes_bonus; $all_bonus = $all_bonus * $donortimes_bonus;
KPS("+",$all_bonus,$arr["userid"]); KPS("+",$all_bonus,$arr["userid"]);
//update exam progress
$examRep->updateProgress($arr['userid']);
} }
} }
$log = 'calculate seeding bonus'; $log = 'calculate seeding bonus';
+1 -1
View File
@@ -10,7 +10,7 @@ class Exam
public function render($uid) public function render($uid)
{ {
$examRep = new ExamRepository(); $examRep = new ExamRepository();
$userExam = $examRep->getUserExamProgress($uid, ExamUser::STATUS_NORMAL, ['exam']); $userExam = $examRep->getUserExamProgress($uid, ExamUser::STATUS_NORMAL);
if (empty($userExam)) { if (empty($userExam)) {
return ''; return '';
} }