From e2f30ecf0ca1174c2408fa8225b37de7bc2cb378 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Wed, 23 Feb 2022 21:17:25 +0800 Subject: [PATCH] H&R, VIP or above ignore it --- app/Console/Commands/Test.php | 2 +- app/Repositories/HitAndRunRepository.php | 48 +++++++++++++++--------- resources/lang/en/hr.php | 1 + resources/lang/zh_CN/hr.php | 1 + resources/lang/zh_TW/hr.php | 1 + 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 267e76b5..95120ad8 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -59,7 +59,7 @@ class Test extends Command public function handle() { $rep = new HitAndRunRepository(); - $r = $rep->getStatusStats(1)->get(2); + $r = $rep->cronjobUpdateStatus(); dd($r); } diff --git a/app/Repositories/HitAndRunRepository.php b/app/Repositories/HitAndRunRepository.php index fb5513a1..24eb7af7 100644 --- a/app/Repositories/HitAndRunRepository.php +++ b/app/Repositories/HitAndRunRepository.php @@ -35,7 +35,7 @@ class HitAndRunRepository extends BaseRepository ->with([ 'torrent' => function ($query) {$query->select(['id', 'size', 'name']);}, 'snatch', - 'user' => function ($query) {$query->select(['id', 'username', 'lang']);}, + 'user' => function ($query) {$query->select(['id', 'username', 'lang', 'class']);}, 'user.language', ]); if (!is_null($uid)) { @@ -69,6 +69,15 @@ class HitAndRunRepository extends BaseRepository continue; } + //If is VIP or above, pass + if ($row->user->class >= User::CLASS_VIP) { + $result = $this->reachedBySpecialUserClass($row); + if ($result) { + $successCounts++; + } + continue; + } + //check seed time $targetSeedTime = $row->snatch->seedtime; $requireSeedTime = bcmul($setting['seed_time_minimum'], 3600); @@ -130,21 +139,9 @@ class HitAndRunRepository extends BaseRepository 'ignore_when_ratio_reach' => Setting::get('hr.ignore_when_ratio_reach'), ], $hitAndRun->user->locale); $update = [ - 'status' => HitAndRun::STATUS_REACHED, 'comment' => $comment ]; - $affectedRows = DB::table($hitAndRun->getTable()) - ->where('id', $hitAndRun->id) - ->where('status', HitAndRun::STATUS_INSPECTING) - ->update($update); - do_log("[H&R_REACHED_BY_SHARE_RATIO], " . last_query() . ", affectedRows: $affectedRows"); - if ($affectedRows != 1) { - do_log($hitAndRun->toJson() . ", [H&R_REACHED_BY_SHARE_RATIO], affectedRows != 1, skip!", 'notice'); - return false; - } - $message = $this->geReachedMessage($hitAndRun); - Message::query()->insert($message); - return true; + return $this->inspectingToReached($hitAndRun, $update, __FUNCTION__); } private function reachedBySeedTime(HitAndRun $hitAndRun): bool @@ -156,16 +153,33 @@ class HitAndRunRepository extends BaseRepository 'seed_time_minimum' => Setting::get('hr.seed_time_minimum') ], $hitAndRun->user->locale); $update = [ - 'status' => HitAndRun::STATUS_REACHED, 'comment' => $comment ]; + return $this->inspectingToReached($hitAndRun, $update, __FUNCTION__); + } + + private function reachedBySpecialUserClass(HitAndRun $hitAndRun): bool + { + do_log(__METHOD__); + $comment = nexus_trans('hr.reached_by_special_user_class_comment', [ + 'user_class_text' => $hitAndRun->user->class_text, + ], $hitAndRun->user->locale); + $update = [ + 'comment' => $comment + ]; + return $this->inspectingToReached($hitAndRun, $update, __FUNCTION__); + } + + private function inspectingToReached(HitAndRun $hitAndRun, array $update, string $logPrefix = ''): bool + { + $update['status'] = HitAndRun::STATUS_REACHED; $affectedRows = DB::table($hitAndRun->getTable()) ->where('id', $hitAndRun->id) ->where('status', HitAndRun::STATUS_INSPECTING) ->update($update); - do_log("[H&R_REACHED_BY_SEED_TIME], " . last_query() . ", affectedRows: $affectedRows"); + do_log("[$logPrefix], " . last_query() . ", affectedRows: $affectedRows"); if ($affectedRows != 1) { - do_log($hitAndRun->toJson() . ", [H&R_REACHED_BY_SEED_TIME], affectedRows != 1, skip!", 'notice'); + do_log($hitAndRun->toJson() . ", [$logPrefix], affectedRows != 1, skip!", 'notice'); return false; } $message = $this->geReachedMessage($hitAndRun); diff --git a/resources/lang/en/hr.php b/resources/lang/en/hr.php index c78462e4..5c41e50e 100644 --- a/resources/lang/en/hr.php +++ b/resources/lang/en/hr.php @@ -12,6 +12,7 @@ return [ 'reached_by_seed_time_comment' => 'Up to::now,seed time: :seed_time Hour(s) reached :seed_time_minimum Hour(s)', 'reached_by_share_ratio_comment' => "Up to::now \nseed time: :seed_time Hour(s) Unreached :seed_time_minimum Hour(s) \nShare ratio: :share_ratio reached standard::ignore_when_ratio_reach", + 'reached_by_special_user_class_comment' => "Your user class: :user_class_text, ignore this H&R", 'reached_message_subject' => 'H&R(ID: :hit_and_run_id) reached!', 'reached_message_content' => 'Congratulation! The torrent: :torrent_name(ID: :torrent_id) you download at: :completed_at has reach the requirement.', diff --git a/resources/lang/zh_CN/hr.php b/resources/lang/zh_CN/hr.php index 581ff04f..33aef1c8 100644 --- a/resources/lang/zh_CN/hr.php +++ b/resources/lang/zh_CN/hr.php @@ -12,6 +12,7 @@ return [ 'reached_by_seed_time_comment' => '截止::now,做种时间: :seed_time Hour(s) 已达标 :seed_time_minimum Hour(s)', 'reached_by_share_ratio_comment' => "截止::now \n做种时间: :seed_time Hour(s) 未达标 :seed_time_minimum Hour(s) \n分享率: :share_ratio 达忽略标准::ignore_when_ratio_reach", + 'reached_by_special_user_class_comment' => "你是::user_class_text,无视此 H&R", 'reached_message_subject' => 'H&R(ID: :hit_and_run_id) 已达标!', 'reached_message_content' => '你于 :completed_at 下载完成的种子::torrent_name(ID: :torrent_id) H&R 已达标,恭喜!', diff --git a/resources/lang/zh_TW/hr.php b/resources/lang/zh_TW/hr.php index b470ba40..066d307c 100644 --- a/resources/lang/zh_TW/hr.php +++ b/resources/lang/zh_TW/hr.php @@ -12,6 +12,7 @@ return [ 'reached_by_seed_time_comment' => '截止::now,做種時間: :seed_time Hour(s) 已達標 :seed_time_minimum Hour(s)', 'reached_by_share_ratio_comment' => "截止::now \n做種時間: :seed_time Hour(s) 未達標 :seed_time_minimum Hour(s) \n分享率: :share_ratio 達忽略標準::ignore_when_ratio_reach", + 'reached_by_special_user_class_comment' => "你是::user_class_text,無視此 H&R", 'reached_message_subject' => 'H&R(ID: :hit_and_run_id) 已達標!', 'reached_message_content' => '你於 :completed_at 下載完成的種子::torrent_name(ID: :torrent_id) H&R 已達標,恭喜!',