improve paid torrent + hit and run

This commit is contained in:
xiaomlove
2025-06-17 20:54:18 +07:00
parent ee4757cdc9
commit 3db4537153
21 changed files with 326 additions and 70 deletions
+45 -37
View File
@@ -347,6 +347,46 @@ $log .= ", [SEED_BOX], isSeedBoxRuleEnabled: $isSeedBoxRuleEnabled, isIPSeedBox:
do_log($log);
//handle paid torrent
if (
$seeder == 'no'
&& isset($az['seedbonus'])
&& isset($torrent['price'])
&& $torrent['price'] > 0
&& $torrent['owner'] != $userid
&& get_setting("torrent.paid_torrent_enabled") == "yes"
) {
$torrentRep = new \App\Repositories\TorrentRepository();
$buyStatus = $torrentRep->getBuyStatus($userid, $torrentid);
do_log("user: $userid buy torrent: $torrentid, status: $buyStatus");
if ($buyStatus > 0) {
do_log(sprintf("user: %s buy torrent %s fail count: %s", $userid, $torrentid, $buyStatus), "error");
if ($buyStatus > 3) {
//warn
\App\Utils\MsgAlert::getInstance()->add(
"announce_paid_torrent_too_many_times",
time() + 86400,
"announce to paid torrent and fail too many times, please make sure you have enough bonus!",
"",
"black"
);
}
if ($buyStatus > 10) {
//disable download
(new \App\Repositories\UserRepository())->updateDownloadPrivileges(null, $userid, 'no', 'announce_paid_torrent_too_many_times');
}
\Nexus\Nexus::dispatchQueueJob(new \App\Jobs\BuyTorrent($userid, $torrentid));
//already fail, add fail times
$torrentRep->addBuyFailCache($userid, $torrentid);
warn("purchase in progress, please try again later, and make sure you have enough bonus", 300);
}
if ($buyStatus == \App\Repositories\TorrentRepository::BUY_STATUS_UNKNOWN) {
//just enqueue job
\Nexus\Nexus::dispatchQueueJob(new \App\Jobs\BuyTorrent($userid, $torrentid));
warn("purchase started, please wait", 300);
}
}
// current peer_id, or you could say session with tracker not found in table peers
if (!isset($self))
{
@@ -393,42 +433,6 @@ if (!isset($self))
}
}
}
if (
$seeder == 'no'
&& isset($az['seedbonus'])
&& isset($torrent['price'])
&& $torrent['price'] > 0
&& $torrent['owner'] != $userid
&& get_setting("torrent.paid_torrent_enabled") == "yes"
) {
$torrentRep = new \App\Repositories\TorrentRepository();
$buyStatus = $torrentRep->getBuyStatus($userid, $torrentid);
if ($buyStatus > 0) {
do_log(sprintf("user: %v buy torrent %v fail count: %v", $userid, $torrentid, $buyStatus), "error");
if ($buyStatus > 3) {
//warn
\App\Utils\MsgAlert::getInstance()->add(
"announce_paid_torrent_too_many_times",
time() + 86400,
"announce to paid torrent and fail too many times, please make sure you have enough bonus!",
"",
"black"
);
}
if ($buyStatus > 10) {
//disable download
(new \App\Repositories\UserRepository())->updateDownloadPrivileges(null, $userid, 'no', 'announce_paid_torrent_too_many_times');
}
//already fail, add fail times
$torrentRep->addBuyFailCache($userid, $torrentid);
warn("purchase fail, please try again later, please make sure you have enough bonus", 300);
}
if ($buyStatus == \App\Repositories\TorrentRepository::BUY_STATUS_UNKNOWN) {
//just enqueue job
\App\Utils\ThirdPartyJob::addBuyTorrent($userid, $torrentid);
warn("purchase in progress, please wait", 300);
}
}
}
else // continue an existing session
{
@@ -567,7 +571,11 @@ if (($left > 0 || $event == "completed") && $az['class'] < \App\Models\HitAndRun
$userid, $torrentid, $snatchInfo['id'], $nowStr, $nowStr, $nowStr
);
$affectedRows = sql_query($sql);
do_log("$hrLog, total downloaded: {$snatchInfo['downloaded']} >= required: $requiredDownloaded, [INSERT_H&R], sql: $sql, affectedRows: $affectedRows");
$hitAndRunId = mysql_insert_id();
do_log("$hrLog, total downloaded: {$snatchInfo['downloaded']} >= required: $requiredDownloaded, [INSERT_H&R], sql: $sql, affectedRows: $affectedRows, hitAndRunId: $hitAndRunId");
if ($hitAndRunId > 0) {
sql_query("update snatched set hit_and_run_id = $hitAndRunId where id = {$snatchInfo['id']}");
}
} else {
do_log("$hrLog, total downloaded: {$snatchInfo['downloaded']} < required: $requiredDownloaded", "debug");
}
+3
View File
@@ -9,6 +9,9 @@ function bark($msg) {
dbconn();
loggedinorreturn();
user_can('staffmem', true);
if (empty($_POST['delreport'])) {
stderr('Error', $lang_functions['select_at_least_one_record']);
}
if ($_POST['setdealt']){
$res = sql_query ("SELECT id FROM reports WHERE dealtwith=0 AND id IN (" . implode(", ", $_POST['delreport']) . ")");
while ($arr = mysql_fetch_assoc($res))
+9 -4
View File
@@ -769,7 +769,8 @@ if (isset($searchstr))
case 1 : // torrent description
{
foreach ($like_expression_array as &$like_expression_array_element)
$like_expression_array_element = "torrents.descr". $like_expression_array_element;
// $like_expression_array_element = "torrents.descr". $like_expression_array_element;
$like_expression_array_element = "torrent_extras.descr". $like_expression_array_element;
$wherea[] = implode($ANDOR, $like_expression_array);
break;
}
@@ -913,12 +914,16 @@ if ($tagId > 0) {
$tagFilter = " inner join torrent_tags on torrents.id = torrent_tags.torrent_id and torrent_tags.tag_id = $tagId ";
$addparam .= "tag_id={$tagId}&";
}
$torrentExtraFilter = "";
if ($search_area == 1) {
$torrentExtraFilter = " inner join torrent_extras on torrents.id = torrent_extras.torrent_id ";
}
if ($allsec == 1 || $enablespecial != 'yes')
{
if ($where != "")
$where = "WHERE $where ";
else $where = "";
$sql = "SELECT COUNT(*) FROM torrents " . ($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "") . $tagFilter . $where;
$sql = "SELECT COUNT(*) FROM torrents " . ($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "") . $tagFilter . $torrentExtraFilter . $where;
}
else
{
@@ -930,7 +935,7 @@ else
$where = "WHERE $where";
else $where = "";
// $sql = "SELECT COUNT(*), categories.mode FROM torrents LEFT JOIN categories ON category = categories.id " . ($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "") . $tagFilter . $where . " GROUP BY categories.mode";
$sql = "SELECT COUNT(*) FROM torrents " . ($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "") . $tagFilter . $where;
$sql = "SELECT COUNT(*) FROM torrents " . ($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "") . $tagFilter . $torrentExtraFilter . $where;
}
if ($shouldUseMeili) {
@@ -986,7 +991,7 @@ if ($count)
// $query = "SELECT $fieldsStr FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")." $tagFilter $where $orderby $limit";
// } else {
// $query = "SELECT $fieldsStr, categories.mode as search_box_id FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")." LEFT JOIN categories ON torrents.category=categories.id $tagFilter $where $orderby $limit";
$query = "SELECT $fieldsStr, $sectiontype as search_box_id FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")."$tagFilter $where $orderby $limit";
$query = "SELECT $fieldsStr, $sectiontype as search_box_id FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")."$tagFilter $torrentExtraFilter $where $orderby $limit";
// }
do_log("[TORRENT_LIST_SQL] $query", 'debug');
if (!$shouldUseMeili) {