diff --git a/app/Repositories/HitAndRunRepository.php b/app/Repositories/HitAndRunRepository.php index f976598e..bcb6cac5 100644 --- a/app/Repositories/HitAndRunRepository.php +++ b/app/Repositories/HitAndRunRepository.php @@ -98,6 +98,7 @@ class HitAndRunRepository extends BaseRepository $setting['diff_in_section'] = $diffInSection; $setting['search_box_id'] = $browseMode; $this->doCronjobUpdateStatus($setting, $uid, $torrentId, $ignoreTime); + $this->checkAndDisableUser($setting); $specialMode = Setting::get('main.specialcat'); if ($diffInSection && $browseMode != $specialMode) { @@ -105,6 +106,7 @@ class HitAndRunRepository extends BaseRepository $setting['diff_in_section'] = $diffInSection; $setting['search_box_id'] = $specialMode; $this->doCronjobUpdateStatus($setting, $uid, $torrentId, $ignoreTime); + $this->checkAndDisableUser($setting); } } @@ -333,37 +335,43 @@ class HitAndRunRepository extends BaseRepository ]; Message::query()->insert($message); - if (!$disableUser) { - do_log("[DO_NOT_DISABLE_USER], return"); - return true; - } - if ($hitAndRun->user->enabled == 'no') { - do_log("[USER_ALREADY_DISABLED], return"); - return true; - } - //disable user - /** @var User $user */ - $user = $hitAndRun->user; - $countsQuery = $user->hitAndRuns()->where('status', HitAndRun::STATUS_UNREACHED); + return true; + } + + private function checkAndDisableUser(array $setting): void + { + $disableCounts = HitAndRun::getConfig('ban_user_when_counts_reach', $setting['search_box_id']); + $query = HitAndRun::query() + ->selectRaw("count(*) as counts, uid") + ->where('status', HitAndRun::STATUS_UNREACHED) + ->groupBy('uid') + ->having("counts", '>=', $disableCounts) + ; if ($setting['diff_in_section']) { - $countsQuery->whereHas('torrent.basic_category', function (Builder $query) use ($setting) { + $query->whereHas('torrent.basic_category', function (Builder $query) use ($setting) { return $query->where('mode', $setting['search_box_id']); }); } - $counts = $countsQuery->count(); - $disableCounts = HitAndRun::getConfig('ban_user_when_counts_reach', $setting['search_box_id']); - do_log("user: {$user->id}, H&R counts: $counts, disableCounts: $disableCounts", 'notice'); - if ($counts >= $disableCounts) { - do_log("[DISABLE_USER_DUE_TO_H&R_UNREACHED]", 'notice'); - $comment = nexus_trans('hr.unreached_disable_comment', [], $user->locale); - $user->updateWithModComment(['enabled' => User::ENABLED_NO], $comment); + $result = $query->get(); + if ($result->isEmpty()) { + do_log("No user to disable"); + return; + } + $users = User::query() + ->with('language') + ->where('enabled', User::ENABLED_YES) + ->find($result->pluck('id')->toArray(), ['id', 'username', 'lang']); + foreach ($users as $user) { + $locale = $user->locale; + $comment = nexus_trans('hr.unreached_disable_comment', [], $locale); + $user->updateWithModComment(['enabled' => User::ENABLED_NO], sprintf('%s - %s', date('Y-m-d'), $comment)); $message = [ - 'receiver' => $hitAndRun->uid, + 'receiver' => $user->id, 'added' => Carbon::now()->toDateTimeString(), 'subject' => $comment, 'msg' => nexus_trans('hr.unreached_disable_message_content', [ 'ban_user_when_counts_reach' => Setting::get('hr.ban_user_when_counts_reach'), - ], $hitAndRun->user->locale), + ], $locale), ]; Message::query()->insert($message); $userBanLog = [ @@ -372,9 +380,8 @@ class HitAndRunRepository extends BaseRepository 'reason' => $comment ]; UserBanLog::query()->insert($userBanLog); + do_log("Disable user: " . nexus_json_encode($userBanLog)); } - - return true; } public function getStatusStats($uid, $formatted = true) diff --git a/include/constants.php b/include/constants.php index 89e7ebeb..a8d55c01 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ "只有", 'std_or_above_can_invite' => "及以上的用户才能发送邀请。", 'text_email_restriction_note' => "你只能发送邀请给以下邮箱:", - 'harem_addition' => '后宫加成', + 'signup_link_help' => '右键复制', + 'signup_link' => '注册链接', ); ?> diff --git a/lang/cht/lang_invite.php b/lang/cht/lang_invite.php index 27840ebc..bfe290c5 100644 --- a/lang/cht/lang_invite.php +++ b/lang/cht/lang_invite.php @@ -49,6 +49,8 @@ $lang_invite = array 'std_or_above_can_invite' => "及以上的用戶才能發送邀請。", 'text_email_restriction_note' => "你只能發送邀請給以下郵箱:", 'harem_addition' => '後宮加成', + 'signup_link_help' => '右鍵復製', + 'signup_link' => '註冊鏈接', ); ?> diff --git a/lang/en/lang_invite.php b/lang/en/lang_invite.php index 55710fa1..4185e322 100644 --- a/lang/en/lang_invite.php +++ b/lang/en/lang_invite.php @@ -52,6 +52,8 @@ Best Regards, 'std_or_above_can_invite' => " or above can send invitation.", 'text_email_restriction_note' => "You could only send invitation to email from those domains: ", 'harem_addition' => 'Harem addition', + 'signup_link_help' => 'Right click to copy', + 'signup_link' => 'Signup link', ); ?> diff --git a/public/invite.php b/public/invite.php index 11f92378..01efb9bd 100644 --- a/public/invite.php +++ b/public/invite.php @@ -166,12 +166,17 @@ if ($type == 'new'){ for ($i = 0; $i < $num1; ++$i) { $arr1 = mysql_fetch_assoc($rer); + $isHashValid = $arr1['valid'] == \App\Models\Invite::VALID_YES; + $registerLink = ''; + if ($isHashValid) { + $registerLink = sprintf(' [%s]', $arr1['hash'], $lang_invite['signup_link_help'], $lang_invite['signup_link']); + } $tr = "