2021-06-08 02:01:35 +08:00
|
|
|
<?php
|
|
|
|
|
require "../include/bittorrent.php";
|
|
|
|
|
dbconn();
|
|
|
|
|
loggedinorreturn();
|
|
|
|
|
|
|
|
|
|
$userid = $CURUSER["id"];
|
|
|
|
|
$torrentid = (int) $_POST["id"];
|
|
|
|
|
$value = (int) abs($_POST['value']);
|
2025-09-08 11:57:33 +07:00
|
|
|
if (!in_array($value, \App\Models\Setting::getBonusRewardOptions())) {
|
2025-09-08 13:05:42 +07:00
|
|
|
exit(json_encode(fail("Invalid value.", $_POST)));
|
2025-09-08 11:57:33 +07:00
|
|
|
}
|
2025-09-08 13:05:42 +07:00
|
|
|
|
|
|
|
|
if($value > $CURUSER['seedbonus']) exit(json_encode(fail('You do not have such bonus!', $_POST)));
|
2021-06-08 02:01:35 +08:00
|
|
|
$tsql = sql_query("SELECT owner FROM torrents WHERE id = $torrentid") or sqlerr(__FILE__,__LINE__);
|
|
|
|
|
$arr = mysql_fetch_assoc($tsql);
|
2025-09-08 13:05:42 +07:00
|
|
|
if (!$arr) exit(json_encode(fail("Invalid torrent id!", $_POST)));
|
2021-06-08 02:01:35 +08:00
|
|
|
|
|
|
|
|
$torrentowner = $arr['owner'];
|
2025-09-08 13:05:42 +07:00
|
|
|
if($torrentowner == $userid) exit(json_encode(fail('You are giving magic to yourself.', $_POST)));
|
2025-10-01 02:41:45 +07:00
|
|
|
$t_ab = get_row_count("magic", "WHERE torrentid=$torrentid and userid=$userid");
|
2025-09-08 13:05:42 +07:00
|
|
|
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)));
|
2025-09-08 11:57:33 +07:00
|
|
|
$torrentOwnerInfo = \App\Models\User::query()->find($torrentowner, \App\Models\User::$commonFields);
|
|
|
|
|
if (!$torrentOwnerInfo) {
|
2025-09-08 13:05:42 +07:00
|
|
|
exit(json_encode(fail("Invalid torrent owner!", $_POST)));
|
2025-09-08 11:57:33 +07:00
|
|
|
}
|
2021-06-08 02:01:35 +08:00
|
|
|
if (isset($userid) && isset($torrentid)&& isset($value)) {
|
|
|
|
|
sql_query("INSERT INTO magic (torrentid, userid,value) VALUES ($torrentid, $userid, $value)") or sqlerr(__FILE__,__LINE__);
|
|
|
|
|
KPS("-",$value,$CURUSER['id']);//selete
|
2025-09-08 11:57:33 +07:00
|
|
|
\App\Models\BonusLogs::add($CURUSER['id'], $CURUSER['seedbonus'], $value, $CURUSER['seedbonus'] - $value, "", \App\Models\BonusLogs::BUSINESS_TYPE_REWARD_TORRENT);
|
2021-06-08 02:01:35 +08:00
|
|
|
KPS("+",$value,$torrentowner);//add to the owner
|
2025-09-08 11:57:33 +07:00
|
|
|
\App\Models\BonusLogs::add($torrentOwnerInfo['id'], $torrentOwnerInfo['seedbonus'], $value, $torrentOwnerInfo['seedbonus'] + $value, "", \App\Models\BonusLogs::BUSINESS_TYPE_TORRENT_BE_REWARD);
|
2025-10-01 02:41:45 +07:00
|
|
|
exit(json_encode(success("OK", $_POST)));
|
2021-06-08 02:01:35 +08:00
|
|
|
}
|