From 500df6b922691053bc14bc3227c79b58dcd91b8a Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Mon, 8 Sep 2025 13:05:42 +0700 Subject: [PATCH] reward torrent add times limit --- app/Models/Setting.php | 5 +++++ lang/chs/lang_settings.php | 2 ++ lang/cht/lang_settings.php | 2 ++ lang/en/lang_settings.php | 2 ++ public/js/common.js | 32 ++++++++++++++++---------------- public/magic.php | 23 ++++++++++++++--------- public/settings.php | 3 ++- 7 files changed, 43 insertions(+), 26 deletions(-) diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 792ad336..d178138d 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -317,5 +317,10 @@ class Setting extends NexusModel return Torrent::BONUS_REWARD_VALUES; } + public static function getBonusRewardTimesLimit(): int + { + return (int)self::get("torrent.reward_times_limit", 0); + } + } diff --git a/lang/chs/lang_settings.php b/lang/chs/lang_settings.php index d5a02282..716b1c2a 100644 --- a/lang/chs/lang_settings.php +++ b/lang/chs/lang_settings.php @@ -823,6 +823,8 @@ $lang_settings = array 'text_bonus_mini_size_help' => '。小于此体积的种子不参与魔力计算。单位:字节(Byte),如 1 Byte = 1024 KiB。', 'row_reward_bonus_options' => '魔力值奖励选项', 'text_reward_bonus_options_note' => '种子详情页的魔力值奖励选项,多个用英文逗号分割', + 'row_reward_times_limit' => '魔力奖励次数限制', + 'text_reward_times_limit_note' => '种子详情页的魔力奖励每人每天次数限制,设置为 0 不限制。默认:0', ); ?> diff --git a/lang/cht/lang_settings.php b/lang/cht/lang_settings.php index 655f00d0..9f08e286 100644 --- a/lang/cht/lang_settings.php +++ b/lang/cht/lang_settings.php @@ -821,6 +821,8 @@ $lang_settings = array 'text_bonus_mini_size_help' => '。小於此體積的種子不參與魔力計算。單位:字節(Byte),如 1 Byte = 1024 KiB。', 'row_reward_bonus_options' => '魔力值獎勵選項', 'text_reward_bonus_options_note' => '種子詳情頁的魔力值獎勵選項,多個用英文逗號分割', + 'row_reward_times_limit' => '魔力獎勵次數限制', + 'text_reward_times_limit_note' => '種子詳情頁的魔力獎勵每人每天次數限制,設置爲 0 不限制。默認:0', ); ?> diff --git a/lang/en/lang_settings.php b/lang/en/lang_settings.php index 7edcdb3a..f228ad82 100644 --- a/lang/en/lang_settings.php +++ b/lang/en/lang_settings.php @@ -821,6 +821,8 @@ $lang_settings = array 'text_bonus_mini_size_help' => '. Torrent size smaller than this volume are not included in the bonus calculation. Unit: bytes (Byte), e.g., 1 Byte = 1024 KiB.', 'row_reward_bonus_options' => 'Reward Bonus Options', 'text_reward_bonus_options_note' => 'Reward bonus options on the torrent details page, multiple options separated by commas', + 'row_reward_times_limit' => 'Reward Frequency Limit', + 'text_reward_times_limit_note' => 'Daily limit per user for bonus rewards on seed detail pages. Set to 0 for no limit. Default: 0', ); ?> diff --git a/public/js/common.js b/public/js/common.js index aedab636..e1fe8d6e 100644 --- a/public/js/common.js +++ b/public/js/common.js @@ -93,22 +93,22 @@ function unpreview(obj){ function saveMagicValue(torrentid,value) { - var list=ajax.posts('magic.php','value='+value +'&id='+torrentid); -// document.getElementById("thanksbutton").innerHTML = document.getElementById("thanksadded").innerHTML; - document.getElementById("magic_add").value += value; - document.getElementById("magic_add").style.display = ''; - document.getElementById("listNumber").style.display = 'none'; - document.getElementById("current_user_magic").style.display = ''; - var sumAll = document.getElementById("spanSumAll").innerHTML; - document.getElementById("spanSumAll").innerHTML = sumAll*1 + value; - if(document.getElementById("count_user_spa")){ - var userAll = document.getElementById("count_user_spa").innerHTML; - document.getElementById("count_user_spa").innerHTML = userAll*1 + 1; - } - - //document.getElementById("listNumber").innerHTML = ""; - -// document.getElementById("addcuruser").innerHTML = document.getElementById("curuser").innerHTML; + jQuery.post("magic.php", {"value": value, "id": torrentid}, function(res) { + if (res.ret !== 0) { + alert(res.msg) + return + } + document.getElementById("magic_add").value += value; + document.getElementById("magic_add").style.display = ''; + document.getElementById("listNumber").style.display = 'none'; + document.getElementById("current_user_magic").style.display = ''; + var sumAll = document.getElementById("spanSumAll").innerHTML; + document.getElementById("spanSumAll").innerHTML = sumAll*1 + value; + if(document.getElementById("count_user_spa")){ + var userAll = document.getElementById("count_user_spa").innerHTML; + document.getElementById("count_user_spa").innerHTML = userAll*1 + 1; + } + }, "json") } // java_klappe.js diff --git a/public/magic.php b/public/magic.php index 36cbbe91..47e7f4ac 100644 --- a/public/magic.php +++ b/public/magic.php @@ -3,29 +3,34 @@ require "../include/bittorrent.php"; dbconn(); loggedinorreturn(); -if (isset($_GET['id'])) stderr("Party is over!", "This trick doesn't work anymore. You need to click the button!"); - $userid = $CURUSER["id"]; $torrentid = (int) $_POST["id"]; $value = (int) abs($_POST['value']); if (!in_array($value, \App\Models\Setting::getBonusRewardOptions())) { - stderr('Error', 'Invalid value.'); + exit(json_encode(fail("Invalid value.", $_POST))); } -if($value <= 0) stderr('Error', 'Value must be positive.'); -if($value > $CURUSER['seedbonus']) stderr('Error','You do not have such bonus!'); + +if($value > $CURUSER['seedbonus']) exit(json_encode(fail('You do not have such bonus!', $_POST))); $tsql = sql_query("SELECT owner FROM torrents WHERE id = $torrentid") or sqlerr(__FILE__,__LINE__); $arr = mysql_fetch_assoc($tsql); -if (!$arr) stderr("Error", "Invalid torrent id!"); +if (!$arr) exit(json_encode(fail("Invalid torrent id!", $_POST))); $torrentowner = $arr['owner']; -if($torrentowner == $userid) stderr('Error', 'You are giving magic to yourself.'); +if($torrentowner == $userid) exit(json_encode(fail('You are giving magic to yourself.', $_POST))); $tsql = sql_query("SELECT COUNT(*) FROM magic WHERE torrentid=$torrentid and userid=$userid") or sqlerr(__FILE__,__LINE__); $trows = mysql_fetch_assoc($tsql); $t_ab = $trows[0]; -if ($t_ab != 0) stderr("Error", "You already gave the magic value!"); +if ($t_ab != 0) exit(json_encode(fail("You already gave the magic value!", $_POST))); +$todayStr = now()->startOfDay(); +$todayCount = \App\Models\Reward::query() + ->where('userid', $userid) + ->where('created_at', ">=", $todayStr) + ->count(); +$timesLimit = \App\Models\Setting::getBonusRewardTimesLimit(); +if ($timesLimit > 0 && $todayCount >= $timesLimit) exit(json_encode(fail("You already reach times limit!", $_POST))); $torrentOwnerInfo = \App\Models\User::query()->find($torrentowner, \App\Models\User::$commonFields); if (!$torrentOwnerInfo) { - stderr('Error', 'Invalid torrent owner!'); + exit(json_encode(fail("Invalid torrent owner!", $_POST))); } if (isset($userid) && isset($torrentid)&& isset($value)) { sql_query("INSERT INTO magic (torrentid, userid,value) VALUES ($torrentid, $userid, $value)") or sqlerr(__FILE__,__LINE__); diff --git a/public/settings.php b/public/settings.php index c6ec9584..43047698 100644 --- a/public/settings.php +++ b/public/settings.php @@ -158,7 +158,7 @@ elseif($action == 'savesettings_torrent') // save account 'thirtypercentleechbecome', 'expirethirtypercentleech', 'sticky_first_level_background_color', 'sticky_second_level_background_color', 'download_support_passkey', 'claim_enabled', 'claim_torrent_ttl', 'claim_torrent_user_counts_up_limit', 'claim_user_torrent_counts_up_limit', 'claim_remove_deduct_user_bonus', 'claim_give_up_deduct_user_bonus', 'claim_bonus_multiplier', 'claim_reach_standard_seed_time', 'claim_reach_standard_uploaded', 'approval_status_icon_enabled', 'approval_status_none_visible', - 'nfo_view_style_default', 'tax_factor', 'max_price', 'paid_torrent_enabled', 'reward_bonus_options' + 'nfo_view_style_default', 'tax_factor', 'max_price', 'paid_torrent_enabled', 'reward_bonus_options', 'reward_times_limit' ); $validConfig = apply_filter('setting_valid_config', $validConfig); GetVar($validConfig); @@ -748,6 +748,7 @@ elseif ($action == 'torrentsettings') tr($lang_settings['row_tax_factor']," ".$lang_settings['text_tax_factor_note'], 1); tr($lang_settings['row_max_price']," ".$lang_settings['text_max_price_note'], 1); tr($lang_settings['row_reward_bonus_options']," ".$lang_settings['text_reward_bonus_options_note'], 1); + tr($lang_settings['row_reward_times_limit']," ".$lang_settings['text_reward_times_limit_note'], 1); // yesorno($lang_settings['row_promotion_rules'], 'prorules', $TORRENT["prorules"], $lang_settings['text_promotion_rules_note']); tr($lang_settings['row_random_promotion'], $lang_settings['text_random_promotion_note_one']."".$lang_settings['text_random_promotion_note_two'], 1);