From f3a6d366d874fbae0f317af30ff1a54d3be117af Mon Sep 17 00:00:00 2001 From: xiaomlove <1939737565@qq.com> Date: Fri, 30 Jan 2026 15:03:52 +0700 Subject: [PATCH] add job RemoveUserVipStatus + RemoveUserDonorStatus + RemoveUserWarning --- app/Console/Kernel.php | 6 + app/Jobs/RemoveUserDonorStatus.php | 63 +++++++++++ app/Jobs/RemoveUserVipStatus.php | 69 ++++++++++++ app/Jobs/RemoveUserWarning.php | 63 +++++++++++ include/cleanup.php | 175 +++++++++++++++-------------- resources/lang/en/bonus-log.php | 2 + resources/lang/zh_TW/bonus-log.php | 2 + 7 files changed, 294 insertions(+), 86 deletions(-) create mode 100644 app/Jobs/RemoveUserDonorStatus.php create mode 100644 app/Jobs/RemoveUserVipStatus.php create mode 100644 app/Jobs/RemoveUserWarning.php diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 277ad9e6..a021a57a 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -6,6 +6,9 @@ use App\Jobs\CheckCleanup; use App\Jobs\CheckQueueFailedJobs; use App\Jobs\MaintainPluginState; use App\Jobs\ManagePlugin; +use App\Jobs\RemoveUserDonorStatus; +use App\Jobs\RemoveUserVipStatus; +use App\Jobs\RemoveUserWarning; use App\Jobs\SaveIpLogCacheToDB; use App\Jobs\UpdateIsSeedBoxFromUserRecordsCache; use App\Utils\ThirdPartyJob; @@ -53,6 +56,9 @@ class Kernel extends ConsoleKernel $schedule->job(new UpdateIsSeedBoxFromUserRecordsCache())->everySixHours(); $schedule->job(new CheckCleanup())->everyFifteenMinutes(); $schedule->job(new SaveIpLogCacheToDB())->hourly(); + $schedule->job(new RemoveUserWarning())->everyTwentySeconds(); + $schedule->job(new RemoveUserVipStatus())->everyMinute(); + $schedule->job(new RemoveUserDonorStatus())->everyMinute(); } diff --git a/app/Jobs/RemoveUserDonorStatus.php b/app/Jobs/RemoveUserDonorStatus.php new file mode 100644 index 00000000..da5c1398 --- /dev/null +++ b/app/Jobs/RemoveUserDonorStatus.php @@ -0,0 +1,63 @@ +with('language') + ->where('donor', 'yes') + ->whereNotNull('donoruntil') + ->where('donoruntil', '!=', '0000-00-00 00:00:00') + ->where('donoruntil', '<', now()) + ->get(); + $userModifyLogs = []; + foreach ($users as $user) { + $locale = $user->locale; + $userModifyLogs[] = [ + 'user_id' => $user->id, + 'content' => "donor status removed by - AutoSystem", + 'created_at' => now(), + 'updated_at' => now(), + ]; + $user->donor = 'no'; + do_log(sprintf("update user %s => %s", $user->id, json_encode($user->getDirty()))); + $user->save(); + clear_user_cache($user->id); + publish_model_event(ModelEventEnum::USER_UPDATED, $user->id); + $subject = sqlesc(nexus_trans("cleanup.msg_donor_status_removed", [], $locale)); + $msg = sqlesc(nexus_trans("cleanup.msg_donor_status_removed_body", [], $locale)); + Message::add([ + 'sender' => 0, + 'receiver' => $user->id, + 'added' => now(), + 'subject' => $subject, + 'msg' => $msg, + ]); + } + if (!empty($userModifyLogs)) { + UserModifyLog::query()->insert($userModifyLogs); + } + do_log("remove donor status if time's up, success handle user count: " . $users->count()); + } +} diff --git a/app/Jobs/RemoveUserVipStatus.php b/app/Jobs/RemoveUserVipStatus.php new file mode 100644 index 00000000..abf1f4af --- /dev/null +++ b/app/Jobs/RemoveUserVipStatus.php @@ -0,0 +1,69 @@ +with('language') + ->where('vip_added', 'yes') + ->where('vip_until', '<', now()) + ->get(); + $userModifyLogs = []; + foreach ($users as $user) { + $locale = $user->locale; + $userModifyLogs[] = [ + 'user_id' => $user->id, + 'content' => "VIP status removed by - AutoSystem", + 'created_at' => now(), + 'updated_at' => now(), + ]; + $message = []; + $user->vip_added = 'no'; + $user->vip_until = null; + if ($user->class <= User::CLASS_VIP) { + $user->class = User::CLASS_USER; + $subject = sqlesc(nexus_trans("cleanup.msg_vip_status_removed", [], $locale)); + $msg = sqlesc(nexus_trans("cleanup.msg_vip_status_removed_body", [], $locale)); + $message = [ + 'sender' => 0, + 'receiver' => $user->id, + 'added' => now(), + 'subject' => $subject, + 'msg' => $msg, + ]; + } + do_log(sprintf("update user %s => %s", $user->id, json_encode($user->getDirty()))); + $user->save(); + clear_user_cache($user->id); + publish_model_event(ModelEventEnum::USER_UPDATED, $user->id); + if (!empty($message)) { + Message::add($message); + } + } + if (!empty($userModifyLogs)) { + UserModifyLog::query()->insert($userModifyLogs); + } + do_log("remove VIP status if time's up, success handle user count: " . $users->count()); + } +} diff --git a/app/Jobs/RemoveUserWarning.php b/app/Jobs/RemoveUserWarning.php new file mode 100644 index 00000000..7c9b455d --- /dev/null +++ b/app/Jobs/RemoveUserWarning.php @@ -0,0 +1,63 @@ +with('language') + ->where('enabled', 'yes') + ->where('warned', 'yes') + ->where('warneduntil', '<', now()) + ->get(); + $userModifyLogs = []; + foreach ($users as $user) { + $locale = $user->locale; + $userModifyLogs[] = [ + 'user_id' => $user->id, + 'content' => "Warning removed by System.", + 'created_at' => now(), + 'updated_at' => now(), + ]; + $user->warned = 'no'; + $user->warneduntil = null; + do_log(sprintf("update user %s => %s", $user->id, json_encode($user->getDirty()))); + $user->save(); + clear_user_cache($user->id); + publish_model_event(ModelEventEnum::USER_UPDATED, $user->id); + $subject = nexus_trans("cleanup.msg_warning_removed", [], $locale); + $msg = nexus_trans("cleanup.msg_your_warning_removed", [], $locale); + Message::add([ + 'sender' => 0, + 'receiver' => $user->id, + 'added' => now(), + 'subject' => $subject, + 'msg' => $msg, + ]); + } + if (!empty($userModifyLogs)) { + UserModifyLog::query()->insert($userModifyLogs); + } + do_log("remove warning of users, success handle user count: " . $users->count()); + } +} diff --git a/include/cleanup.php b/include/cleanup.php index 3a88daf6..10ee2bdd 100644 --- a/include/cleanup.php +++ b/include/cleanup.php @@ -734,75 +734,77 @@ function docleanup($forceAll = 0, $printProgress = false) { printProgress($log); } + //migrate to job: RemoveUserVipStatus //remove VIP status if time's up - $res = sql_query("SELECT id, class FROM users WHERE vip_added='yes' AND vip_until < NOW()") or sqlerr(__FILE__, __LINE__); - $userModifyLogs = []; - if (mysql_num_rows($res) > 0) - { - while ($arr = mysql_fetch_assoc($res)) - { - $dt = sqlesc(date("Y-m-d H:i:s")); - $locale = get_user_locale($arr['id']); - $subject = sqlesc(nexus_trans("cleanup.msg_vip_status_removed", [], $locale)); - $msg = sqlesc(nexus_trans("cleanup.msg_vip_status_removed_body", [], $locale)); - $userModifyLogs[] = [ - 'user_id' => $arr['id'], - 'content' => "VIP status removed by - AutoSystem", - 'created_at' => date("Y-m-d H:i:s"), - 'updated_at' => date("Y-m-d H:i:s"), - ]; - if ($arr['class'] > \App\Models\User::CLASS_VIP) { - /** - * @since 1.8 - * never demotion VIP above - */ - sql_query("UPDATE users SET vip_added = 'no', vip_until = null WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__); - } else { - sql_query("UPDATE users SET class = '1', vip_added = 'no', vip_until = null WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__); - sql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, {$arr['id']}, $dt, $msg, $subject)") or sqlerr(__FILE__, __LINE__); - } - publish_model_event(ModelEventEnum::USER_UPDATED, $arr['id']); - } - } - if (!empty($userModifyLogs)) { - \App\Models\UserModifyLog::query()->insert($userModifyLogs); - } - $log = "remove VIP status if time's up"; - do_log($log); - if ($printProgress) { - printProgress($log); - } +// $res = sql_query("SELECT id, class FROM users WHERE vip_added='yes' AND vip_until < NOW()") or sqlerr(__FILE__, __LINE__); +// $userModifyLogs = []; +// if (mysql_num_rows($res) > 0) +// { +// while ($arr = mysql_fetch_assoc($res)) +// { +// $dt = sqlesc(date("Y-m-d H:i:s")); +// $locale = get_user_locale($arr['id']); +// $subject = sqlesc(nexus_trans("cleanup.msg_vip_status_removed", [], $locale)); +// $msg = sqlesc(nexus_trans("cleanup.msg_vip_status_removed_body", [], $locale)); +// $userModifyLogs[] = [ +// 'user_id' => $arr['id'], +// 'content' => "VIP status removed by - AutoSystem", +// 'created_at' => date("Y-m-d H:i:s"), +// 'updated_at' => date("Y-m-d H:i:s"), +// ]; +// if ($arr['class'] > \App\Models\User::CLASS_VIP) { +// /** +// * @since 1.8 +// * never demotion VIP above +// */ +// sql_query("UPDATE users SET vip_added = 'no', vip_until = null WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__); +// } else { +// sql_query("UPDATE users SET class = '1', vip_added = 'no', vip_until = null WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__); +// sql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, {$arr['id']}, $dt, $msg, $subject)") or sqlerr(__FILE__, __LINE__); +// } +// publish_model_event(ModelEventEnum::USER_UPDATED, $arr['id']); +// } +// } +// if (!empty($userModifyLogs)) { +// \App\Models\UserModifyLog::query()->insert($userModifyLogs); +// } +// $log = "remove VIP status if time's up"; +// do_log($log); +// if ($printProgress) { +// printProgress($log); +// } + //migrate to job: RemoveUserDonorStatus //remove donor status if time's up - $userModifyLogs = []; - $res = sql_query("SELECT id FROM users WHERE donor='yes' AND donoruntil is not null and donoruntil != '0000-00-00 00:00:00' and donoruntil < NOW()") or sqlerr(__FILE__, __LINE__); - if (mysql_num_rows($res) > 0) - { - while ($arr = mysql_fetch_assoc($res)) - { - $dt = sqlesc(date("Y-m-d H:i:s")); - $locale = get_user_locale($arr['id']); - $subject = sqlesc(nexus_trans("cleanup.msg_donor_status_removed", [], $locale)); - $msg = sqlesc(nexus_trans("cleanup.msg_donor_status_removed_body", [], $locale)); - $userModifyLogs[] = [ - 'user_id' => $arr['id'], - 'content' => "donor status removed by - AutoSystem", - 'created_at' => date("Y-m-d H:i:s"), - 'updated_at' => date("Y-m-d H:i:s"), - ]; - sql_query("UPDATE users SET donor = 'no' WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__); - sql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, {$arr['id']}, $dt, $msg, $subject)") or sqlerr(__FILE__, __LINE__); - publish_model_event(ModelEventEnum::USER_UPDATED, $arr['id']); - } - } - if (!empty($userModifyLogs)) { - \App\Models\UserModifyLog::query()->insert($userModifyLogs); - } - $log = "remove donor status if time's up"; - do_log($log); - if ($printProgress) { - printProgress($log); - } +// $userModifyLogs = []; +// $res = sql_query("SELECT id FROM users WHERE donor='yes' AND donoruntil is not null and donoruntil != '0000-00-00 00:00:00' and donoruntil < NOW()") or sqlerr(__FILE__, __LINE__); +// if (mysql_num_rows($res) > 0) +// { +// while ($arr = mysql_fetch_assoc($res)) +// { +// $dt = sqlesc(date("Y-m-d H:i:s")); +// $locale = get_user_locale($arr['id']); +// $subject = sqlesc(nexus_trans("cleanup.msg_donor_status_removed", [], $locale)); +// $msg = sqlesc(nexus_trans("cleanup.msg_donor_status_removed_body", [], $locale)); +// $userModifyLogs[] = [ +// 'user_id' => $arr['id'], +// 'content' => "donor status removed by - AutoSystem", +// 'created_at' => date("Y-m-d H:i:s"), +// 'updated_at' => date("Y-m-d H:i:s"), +// ]; +// sql_query("UPDATE users SET donor = 'no' WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__); +// sql_query("INSERT INTO messages (sender, receiver, added, msg, subject) VALUES(0, {$arr['id']}, $dt, $msg, $subject)") or sqlerr(__FILE__, __LINE__); +// publish_model_event(ModelEventEnum::USER_UPDATED, $arr['id']); +// } +// } +// if (!empty($userModifyLogs)) { +// \App\Models\UserModifyLog::query()->insert($userModifyLogs); +// } +// $log = "remove donor status if time's up"; +// do_log($log); +// if ($printProgress) { +// printProgress($log); +// } // promote peasant back to user @@ -889,27 +891,28 @@ function docleanup($forceAll = 0, $printProgress = false) { printProgress($log); } + //migrate to job: RemoveUserWarning //Remove warning of users - $dt = sqlesc(date("Y-m-d H:i:s")); // take date time - $res = sql_query("SELECT id FROM users WHERE enabled = 'yes' AND warned = 'yes' AND warneduntil < $dt") or sqlerr(__FILE__, __LINE__); - - if (mysql_num_rows($res) > 0) - { - while ($arr = mysql_fetch_assoc($res)) - { - $locale = get_user_locale($arr['id']); - $subject = nexus_trans("cleanup.msg_warning_removed", [], $locale); - $msg = nexus_trans("cleanup.msg_your_warning_removed", [], $locale); - writecomment($arr['id'],"Warning removed by System."); - sql_query("UPDATE users SET warned = 'no', warneduntil = null WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__); - sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, {$arr['id']}, $dt, ".sqlesc($subject).", ".sqlesc($msg).")") or sqlerr(__FILE__, __LINE__); - } - } - $log = "remove warning of users"; - do_log($log); - if ($printProgress) { - printProgress($log); - } +// $dt = sqlesc(date("Y-m-d H:i:s")); // take date time +// $res = sql_query("SELECT id FROM users WHERE enabled = 'yes' AND warned = 'yes' AND warneduntil < $dt") or sqlerr(__FILE__, __LINE__); +// +// if (mysql_num_rows($res) > 0) +// { +// while ($arr = mysql_fetch_assoc($res)) +// { +// $locale = get_user_locale($arr['id']); +// $subject = nexus_trans("cleanup.msg_warning_removed", [], $locale); +// $msg = nexus_trans("cleanup.msg_your_warning_removed", [], $locale); +// writecomment($arr['id'],"Warning removed by System."); +// sql_query("UPDATE users SET warned = 'no', warneduntil = null WHERE id = {$arr['id']}") or sqlerr(__FILE__, __LINE__); +// sql_query("INSERT INTO messages (sender, receiver, added, subject, msg) VALUES(0, {$arr['id']}, $dt, ".sqlesc($subject).", ".sqlesc($msg).")") or sqlerr(__FILE__, __LINE__); +// } +// } +// $log = "remove warning of users"; +// do_log($log); +// if ($printProgress) { +// printProgress($log); +// } //17.update total seeding and leeching time of users // $res = sql_query("SELECT id FROM users where enabled = 'yes' and status = 'confirmed'") or sqlerr(__FILE__, __LINE__); diff --git a/resources/lang/en/bonus-log.php b/resources/lang/en/bonus-log.php index add8d52c..c7a2b738 100644 --- a/resources/lang/en/bonus-log.php +++ b/resources/lang/en/bonus-log.php @@ -21,6 +21,8 @@ return [ \App\Models\BonusLogs::BUSINESS_TYPE_BUY_CHANGE_USERNAME_CARD => 'Buy change username card', \App\Models\BonusLogs::BUSINESS_TYPE_GIFT_MEDAL => 'Gift medal', \App\Models\BonusLogs::BUSINESS_TYPE_BUY_TORRENT => 'Buy torrent', + \App\Models\BonusLogs::BUSINESS_TYPE_TASK_PASS_REWARD => 'Task finished reward', + \App\Models\BonusLogs::BUSINESS_TYPE_TASK_NOT_PASS_DEDUCT => 'Task unfinished deduct', \App\Models\BonusLogs::BUSINESS_TYPE_REWARD_TORRENT => 'Reward torrent', \App\Models\BonusLogs::BUSINESS_TYPE_CLAIMED_UNREACHED => 'Claimed torrent unreached', diff --git a/resources/lang/zh_TW/bonus-log.php b/resources/lang/zh_TW/bonus-log.php index b6d12bb7..13781e15 100644 --- a/resources/lang/zh_TW/bonus-log.php +++ b/resources/lang/zh_TW/bonus-log.php @@ -21,6 +21,8 @@ return [ \App\Models\BonusLogs::BUSINESS_TYPE_BUY_CHANGE_USERNAME_CARD => '購買改名卡', \App\Models\BonusLogs::BUSINESS_TYPE_GIFT_MEDAL => '贈送勛章', \App\Models\BonusLogs::BUSINESS_TYPE_BUY_TORRENT => '購買種子', + \App\Models\BonusLogs::BUSINESS_TYPE_TASK_PASS_REWARD => '任務完成獎勵', + \App\Models\BonusLogs::BUSINESS_TYPE_TASK_NOT_PASS_DEDUCT => '任務未完成扣除', \App\Models\BonusLogs::BUSINESS_TYPE_REWARD_TORRENT => '獎勵種子', \App\Models\BonusLogs::BUSINESS_TYPE_CLAIMED_UNREACHED => '認領種子未達標扣除',