reward torrent add times limit

This commit is contained in:
xiaomlove
2025-09-08 13:05:42 +07:00
parent 22a91a5851
commit 500df6b922
7 changed files with 43 additions and 26 deletions

View File

@@ -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__);