claim bulk

This commit is contained in:
xiaomlove
2023-03-13 17:41:03 +08:00
parent 77420ea1e1
commit 709ca90458
12 changed files with 98 additions and 22 deletions
+2 -1
View File
@@ -95,7 +95,8 @@ class Test extends Command
*/
public function handle()
{
$logFile = getLogFile("seed-points");
dd($logFile);
}
}
+14 -1
View File
@@ -71,7 +71,9 @@ class CalculateUserSeedBonus implements ShouldQueue
$autoclean_interval_one = Setting::get('main.autoclean_interval_one');
$sql = sprintf("select %s from users where id in (%s)", implode(',', User::$commonFields), implode(',', array_column($results, 'userid')));
$results = NexusDB::select($sql);
do_log("$logPrefix, [GET_UID_REAL], count: " . count($results));
$logFile = getLogFile("seed-bonus-points");
do_log("$logPrefix, [GET_UID_REAL], count: " . count($results) . ", logFile: $logFile");
$fd = fopen($logFile, 'a');
foreach ($results as $userInfo)
{
$uid = $userInfo['id'];
@@ -107,6 +109,17 @@ class CalculateUserSeedBonus implements ShouldQueue
$sql = "update users set seed_points = ifnull(seed_points, 0) + $seed_points, seedbonus = seedbonus + $all_bonus, seed_points_updated_at = '$updatedAt' where id = $uid limit 1";
do_log("$bonusLog, query: $sql");
NexusDB::statement($sql);
if ($fd) {
$log = sprintf(
'%s|%s|%s|%s|%s|%s|%s|%s',
date('Y-m-d H:i:s'), $uid,
$userInfo['seed_points'], number_format($seed_points, 1, '.', ''), number_format($userInfo['seed_points'] + $seed_points, 1, '.', ''),
$userInfo['seedbonus'], number_format($all_bonus, 1, '.', ''), number_format($userInfo['seedbonus'] + $all_bonus, 1, '.', '')
);
fwrite($fd, $log . PHP_EOL);
} else {
do_log("logFile: $logFile is not writeable!", 'error');
}
}
$costTime = time() - $beginTimestamp;
do_log("$logPrefix, [DONE], cost time: $costTime seconds");
+11 -7
View File
@@ -1,6 +1,7 @@
<?php
namespace App\Repositories;
use App\Exceptions\InsufficientPermissionException;
use App\Models\Claim;
use App\Models\Message;
use App\Models\Peer;
@@ -59,7 +60,7 @@ class ClaimRepository extends BaseRepository
if ($torrent->added->addDays($claimTorrentTTL)->gte(Carbon::now())) {
throw new \RuntimeException(nexus_trans("torrent.can_no_be_claimed_yet"));
}
if (!apply_filter('user_has_role_work_seeding', false, $uid)) {
if (!has_role_work_seeding($uid)) {
$max = Claim::getConfigTorrentUpLimit();
$count = Claim::query()->where('uid', $uid)->count();
if ($count >= $max) {
@@ -162,7 +163,7 @@ class ClaimRepository extends BaseRepository
public function settleUser($uid, $force = false, $test = false): bool
{
$hasRoleWorkSeeding = apply_filter('user_has_role_work_seeding', false, $uid);
$hasRoleWorkSeeding = has_role_work_seeding($uid);
if ($hasRoleWorkSeeding) {
do_log("uid: $uid, filter: user_has_role_work_seeding => true, skip");
return false;
@@ -346,21 +347,24 @@ class ClaimRepository extends BaseRepository
public function claimAllSeeding(int $uid)
{
if (!has_role_work_seeding($uid)) {
throw new InsufficientPermissionException();
}
$page = 1;
$size = 1000;
$total = 0;
while (true) {
$peers = Peer::query()
->where('uid', $uid)
->where('userid', $uid)
->where('seeder', 'yes')
->where('to_go', 0)
->groupBy('torrentid')
->groupBy('torrent')
->forPage($page, $size)
->get(['torrentid']);
->get(['torrent']);
if ($peers->isEmpty()) {
break;
}
$torrentIdArr = $peers->pluck('torrentid')->toArray();
$torrentIdArr = $peers->pluck('torrent')->toArray();
$snatches = Snatch::query()
->whereIn('torrentid', $torrentIdArr)
->where('userid', $uid)
@@ -369,7 +373,7 @@ class ClaimRepository extends BaseRepository
if ($snatches->isNotEmpty()) {
$values = [];
$nowStr = now()->toDateTimeString();
$sql = "insert into claims (uid, torrent_id, snatched_id, seed_time_begin, uploaded_begin, created_at, uploaded_at)";
$sql = "insert into claims (uid, torrent_id, snatched_id, seed_time_begin, uploaded_begin, created_at, updated_at)";
foreach ($snatches as $snatch) {
$values[] = sprintf(
"(%s, %s, %s, %s, %s, '%s', '%s')",
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-03-06');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-03-13');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
+4 -3
View File
@@ -576,9 +576,10 @@ function int_check($value,$stdhead = false, $stdfood = true, $die = true, $log =
{
if (!is_valid_id($value)) {
$msg = "Invalid ID Attempt: Username: ".$CURUSER["username"]." - UserID: ".$CURUSER["id"]." - UserIP : ".getip();
if ($log)
write_log($msg,'mod');
if ($log) {
write_log($msg,'mod');
}
do_log($msg, 'error');
if ($stdhead)
stderr($lang_functions['std_error'],$lang_functions['std_invalid_id']);
else
+15 -6
View File
@@ -232,11 +232,11 @@ function do_log($log, $level = 'info', $echo = false)
}
}
function getLogFile()
function getLogFile($append = '')
{
static $logFile;
if (!is_null($logFile)) {
return $logFile;
static $logFiles = [];
if (isset($logFiles[$append])) {
return $logFiles[$append];
}
$config = nexus_config('nexus');
$path = getenv('NEXUS_LOG_DIR', true);
@@ -257,8 +257,12 @@ function getLogFile()
$prefix = $logFile;
$suffix = '';
}
$logFile = sprintf('%s-%s%s', $prefix, date('Y-m-d'), $suffix);
return $logFile;
$name = $prefix;
if ($append) {
$name .= "-$append";
}
$logFile = sprintf('%s-%s%s', $name, date('Y-m-d'), $suffix);
return $logFiles[$append] = $logFile;
}
@@ -1172,3 +1176,8 @@ function executeCommand($command, $format = 'string', $artisan = false, $excepti
return $format == 'string' ? $outputString : $output;
}
function has_role_work_seeding($uid)
{
return apply_filter('user_has_role_work_seeding', false, $uid);
}
+7
View File
@@ -161,3 +161,10 @@ function saveUserMedal($params)
$rep = new \App\Repositories\MedalRepository();
return $rep->saveUserMedal($CURUSER['id'], $data);
}
function claimAllSeeding()
{
global $CURUSER;
$rep = new \App\Repositories\ClaimRepository();
return $rep->claimAllSeeding($CURUSER['id']);
}
+16 -3
View File
@@ -343,11 +343,24 @@ if ($count > 0 && isset($tableWhere, $fields, $order))
list($torrentlist, $total_size_this_page) = maketable ( $res, $type);
}
$table = $pagertop . $torrentlist . $pagerbottom;
$hasData = false;
$summary = sprintf('<b>%s</b>%s', $count, $lang_getusertorrentlistajax['text_record'] . add_s ( $count ));
if (isset($total_size) && $total_size){
echo "<br /><b>" . $count . "</b>" . $lang_getusertorrentlistajax['text_record'] . add_s ( $count ) . $lang_getusertorrentlistajax['text_total_size'] . mksize($total_size) . $pagertop . $torrentlist . $pagerbottom;
} elseif ($count){
echo "<br /><b>".$count."</b>".$lang_getusertorrentlistajax['text_record'].add_s($count). $pagertop . $torrentlist . $pagerbottom;
$hasData = true;
$summary .= $lang_getusertorrentlistajax['text_total_size'] . mksize($total_size);
} elseif ($count) {
$hasData = true;
}
if ($hasData) {
$claimAllBtn = '';
if ($id == $CURUSER['id'] && has_role_work_seeding($CURUSER['id'])) {
$claimAllBtn = sprintf('<input type="button" value="%s" id="claim-all-seeding">', nexus_trans('claim.claim_all_seeding_btn'));
}
$header = sprintf('<div style="display: flex;justify-content: space-between"><div>%s</div><div>%s</div></div>', $summary, $claimAllBtn);
echo '<br/>' . $header . $table;
} else {
echo $lang_getusertorrentlistajax['text_no_record'];
}
?>
+20
View File
@@ -627,6 +627,23 @@ JS;
}
end_main_frame();
$claimAllSeedingConfirmation = nexus_trans('claim.claim_all_seeding_confirmation');
$claimJs = '';
if ($userInfo->id == $CURUSER['id'] && has_role_work_seeding($userInfo->id)) {
$claimJs = <<<JS
jQuery("body").on("click", "#claim-all-seeding", function (e) {
layer.confirm("$claimAllSeedingConfirmation", {}, function () {
jQuery.post('ajax.php', {"action": "claimAllSeeding"}, function (response) {
if (response.ret == 0) {
window.location.reload()
} else {
layer.alert(response.msg)
}
}, 'json')
})
})
JS;
}
$paginationJs = <<<JS
jQuery("body").on("click", ".nexus-pagination a", function (e) {
e.preventDefault()
@@ -637,7 +654,10 @@ jQuery("body").on("click", ".nexus-pagination a", function (e) {
let result = ajax.gets(url);
box.html(result)
})
$claimJs
JS;
\Nexus\Nexus::js($paginationJs, 'footer', false);
stdfoot();
?>
+2
View File
@@ -34,4 +34,6 @@ return [
'fields' => [
'torrent_id' => 'Torrent ID',
],
'claim_all_seeding_btn' => 'One click to claim',
'claim_all_seeding_confirmation' => 'Are you sure you want to claim all the torrents that are currently being seeding?' ,
];
+4
View File
@@ -35,4 +35,8 @@ return [
'fields' => [
'torrent_id' => '种子 ID',
],
'claim_all_seeding_btn' => '一键认领',
'claim_all_seeding_confirmation' => '确定要认领当前全部做种中的种子吗?',
];
+2
View File
@@ -33,4 +33,6 @@ return [
'fields' => [
'torrent_id' => '種子 ID',
],
'claim_all_seeding_btn' => '一鍵認領',
'claim_all_seeding_confirmation' => '確定要認領當前全部做種中的種子嗎?',
];