mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
claim bulk
This commit is contained in:
@@ -95,7 +95,8 @@ class Test extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
$logFile = getLogFile("seed-points");
|
||||||
|
dd($logFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,9 @@ class CalculateUserSeedBonus implements ShouldQueue
|
|||||||
$autoclean_interval_one = Setting::get('main.autoclean_interval_one');
|
$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')));
|
$sql = sprintf("select %s from users where id in (%s)", implode(',', User::$commonFields), implode(',', array_column($results, 'userid')));
|
||||||
$results = NexusDB::select($sql);
|
$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)
|
foreach ($results as $userInfo)
|
||||||
{
|
{
|
||||||
$uid = $userInfo['id'];
|
$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";
|
$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");
|
do_log("$bonusLog, query: $sql");
|
||||||
NexusDB::statement($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;
|
$costTime = time() - $beginTimestamp;
|
||||||
do_log("$logPrefix, [DONE], cost time: $costTime seconds");
|
do_log("$logPrefix, [DONE], cost time: $costTime seconds");
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Repositories;
|
namespace App\Repositories;
|
||||||
|
|
||||||
|
use App\Exceptions\InsufficientPermissionException;
|
||||||
use App\Models\Claim;
|
use App\Models\Claim;
|
||||||
use App\Models\Message;
|
use App\Models\Message;
|
||||||
use App\Models\Peer;
|
use App\Models\Peer;
|
||||||
@@ -59,7 +60,7 @@ class ClaimRepository extends BaseRepository
|
|||||||
if ($torrent->added->addDays($claimTorrentTTL)->gte(Carbon::now())) {
|
if ($torrent->added->addDays($claimTorrentTTL)->gte(Carbon::now())) {
|
||||||
throw new \RuntimeException(nexus_trans("torrent.can_no_be_claimed_yet"));
|
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();
|
$max = Claim::getConfigTorrentUpLimit();
|
||||||
$count = Claim::query()->where('uid', $uid)->count();
|
$count = Claim::query()->where('uid', $uid)->count();
|
||||||
if ($count >= $max) {
|
if ($count >= $max) {
|
||||||
@@ -162,7 +163,7 @@ class ClaimRepository extends BaseRepository
|
|||||||
|
|
||||||
public function settleUser($uid, $force = false, $test = false): bool
|
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) {
|
if ($hasRoleWorkSeeding) {
|
||||||
do_log("uid: $uid, filter: user_has_role_work_seeding => true, skip");
|
do_log("uid: $uid, filter: user_has_role_work_seeding => true, skip");
|
||||||
return false;
|
return false;
|
||||||
@@ -346,21 +347,24 @@ class ClaimRepository extends BaseRepository
|
|||||||
|
|
||||||
public function claimAllSeeding(int $uid)
|
public function claimAllSeeding(int $uid)
|
||||||
{
|
{
|
||||||
|
if (!has_role_work_seeding($uid)) {
|
||||||
|
throw new InsufficientPermissionException();
|
||||||
|
}
|
||||||
$page = 1;
|
$page = 1;
|
||||||
$size = 1000;
|
$size = 1000;
|
||||||
$total = 0;
|
$total = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
$peers = Peer::query()
|
$peers = Peer::query()
|
||||||
->where('uid', $uid)
|
->where('userid', $uid)
|
||||||
->where('seeder', 'yes')
|
->where('seeder', 'yes')
|
||||||
->where('to_go', 0)
|
->where('to_go', 0)
|
||||||
->groupBy('torrentid')
|
->groupBy('torrent')
|
||||||
->forPage($page, $size)
|
->forPage($page, $size)
|
||||||
->get(['torrentid']);
|
->get(['torrent']);
|
||||||
if ($peers->isEmpty()) {
|
if ($peers->isEmpty()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$torrentIdArr = $peers->pluck('torrentid')->toArray();
|
$torrentIdArr = $peers->pluck('torrent')->toArray();
|
||||||
$snatches = Snatch::query()
|
$snatches = Snatch::query()
|
||||||
->whereIn('torrentid', $torrentIdArr)
|
->whereIn('torrentid', $torrentIdArr)
|
||||||
->where('userid', $uid)
|
->where('userid', $uid)
|
||||||
@@ -369,7 +373,7 @@ class ClaimRepository extends BaseRepository
|
|||||||
if ($snatches->isNotEmpty()) {
|
if ($snatches->isNotEmpty()) {
|
||||||
$values = [];
|
$values = [];
|
||||||
$nowStr = now()->toDateTimeString();
|
$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) {
|
foreach ($snatches as $snatch) {
|
||||||
$values[] = sprintf(
|
$values[] = sprintf(
|
||||||
"(%s, %s, %s, %s, %s, '%s', '%s')",
|
"(%s, %s, %s, %s, %s, '%s', '%s')",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0');
|
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('IN_TRACKER') || define('IN_TRACKER', false);
|
||||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||||
|
|||||||
@@ -576,9 +576,10 @@ function int_check($value,$stdhead = false, $stdfood = true, $die = true, $log =
|
|||||||
{
|
{
|
||||||
if (!is_valid_id($value)) {
|
if (!is_valid_id($value)) {
|
||||||
$msg = "Invalid ID Attempt: Username: ".$CURUSER["username"]." - UserID: ".$CURUSER["id"]." - UserIP : ".getip();
|
$msg = "Invalid ID Attempt: Username: ".$CURUSER["username"]." - UserID: ".$CURUSER["id"]." - UserIP : ".getip();
|
||||||
if ($log)
|
if ($log) {
|
||||||
write_log($msg,'mod');
|
write_log($msg,'mod');
|
||||||
|
}
|
||||||
|
do_log($msg, 'error');
|
||||||
if ($stdhead)
|
if ($stdhead)
|
||||||
stderr($lang_functions['std_error'],$lang_functions['std_invalid_id']);
|
stderr($lang_functions['std_error'],$lang_functions['std_invalid_id']);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -232,11 +232,11 @@ function do_log($log, $level = 'info', $echo = false)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLogFile()
|
function getLogFile($append = '')
|
||||||
{
|
{
|
||||||
static $logFile;
|
static $logFiles = [];
|
||||||
if (!is_null($logFile)) {
|
if (isset($logFiles[$append])) {
|
||||||
return $logFile;
|
return $logFiles[$append];
|
||||||
}
|
}
|
||||||
$config = nexus_config('nexus');
|
$config = nexus_config('nexus');
|
||||||
$path = getenv('NEXUS_LOG_DIR', true);
|
$path = getenv('NEXUS_LOG_DIR', true);
|
||||||
@@ -257,8 +257,12 @@ function getLogFile()
|
|||||||
$prefix = $logFile;
|
$prefix = $logFile;
|
||||||
$suffix = '';
|
$suffix = '';
|
||||||
}
|
}
|
||||||
$logFile = sprintf('%s-%s%s', $prefix, date('Y-m-d'), $suffix);
|
$name = $prefix;
|
||||||
return $logFile;
|
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;
|
return $format == 'string' ? $outputString : $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function has_role_work_seeding($uid)
|
||||||
|
{
|
||||||
|
return apply_filter('user_has_role_work_seeding', false, $uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -161,3 +161,10 @@ function saveUserMedal($params)
|
|||||||
$rep = new \App\Repositories\MedalRepository();
|
$rep = new \App\Repositories\MedalRepository();
|
||||||
return $rep->saveUserMedal($CURUSER['id'], $data);
|
return $rep->saveUserMedal($CURUSER['id'], $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function claimAllSeeding()
|
||||||
|
{
|
||||||
|
global $CURUSER;
|
||||||
|
$rep = new \App\Repositories\ClaimRepository();
|
||||||
|
return $rep->claimAllSeeding($CURUSER['id']);
|
||||||
|
}
|
||||||
|
|||||||
@@ -343,11 +343,24 @@ if ($count > 0 && isset($tableWhere, $fields, $order))
|
|||||||
list($torrentlist, $total_size_this_page) = maketable ( $res, $type);
|
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){
|
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;
|
$hasData = true;
|
||||||
} elseif ($count){
|
$summary .= $lang_getusertorrentlistajax['text_total_size'] . mksize($total_size);
|
||||||
echo "<br /><b>".$count."</b>".$lang_getusertorrentlistajax['text_record'].add_s($count). $pagertop . $torrentlist . $pagerbottom;
|
} 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 {
|
} else {
|
||||||
echo $lang_getusertorrentlistajax['text_no_record'];
|
echo $lang_getusertorrentlistajax['text_no_record'];
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -627,6 +627,23 @@ JS;
|
|||||||
}
|
}
|
||||||
end_main_frame();
|
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
|
$paginationJs = <<<JS
|
||||||
jQuery("body").on("click", ".nexus-pagination a", function (e) {
|
jQuery("body").on("click", ".nexus-pagination a", function (e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -637,7 +654,10 @@ jQuery("body").on("click", ".nexus-pagination a", function (e) {
|
|||||||
let result = ajax.gets(url);
|
let result = ajax.gets(url);
|
||||||
box.html(result)
|
box.html(result)
|
||||||
})
|
})
|
||||||
|
$claimJs
|
||||||
JS;
|
JS;
|
||||||
|
|
||||||
\Nexus\Nexus::js($paginationJs, 'footer', false);
|
\Nexus\Nexus::js($paginationJs, 'footer', false);
|
||||||
|
|
||||||
stdfoot();
|
stdfoot();
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -34,4 +34,6 @@ return [
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'torrent_id' => 'Torrent ID',
|
'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?' ,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -35,4 +35,8 @@ return [
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'torrent_id' => '种子 ID',
|
'torrent_id' => '种子 ID',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'claim_all_seeding_btn' => '一键认领',
|
||||||
|
'claim_all_seeding_confirmation' => '确定要认领当前全部做种中的种子吗?',
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -33,4 +33,6 @@ return [
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'torrent_id' => '種子 ID',
|
'torrent_id' => '種子 ID',
|
||||||
],
|
],
|
||||||
|
'claim_all_seeding_btn' => '一鍵認領',
|
||||||
|
'claim_all_seeding_confirmation' => '確定要認領當前全部做種中的種子嗎?',
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user