diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 99b903d7..9dbb6b2c 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -95,7 +95,8 @@ class Test extends Command */ public function handle() { - + $logFile = getLogFile("seed-points"); + dd($logFile); } } diff --git a/app/Jobs/CalculateUserSeedBonus.php b/app/Jobs/CalculateUserSeedBonus.php index a0b20371..eb4b351f 100644 --- a/app/Jobs/CalculateUserSeedBonus.php +++ b/app/Jobs/CalculateUserSeedBonus.php @@ -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"); diff --git a/app/Repositories/ClaimRepository.php b/app/Repositories/ClaimRepository.php index 0884971f..2c81e935 100644 --- a/app/Repositories/ClaimRepository.php +++ b/app/Repositories/ClaimRepository.php @@ -1,6 +1,7 @@ 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')", diff --git a/include/constants.php b/include/constants.php index 46bb82da..08bc7a94 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ saveUserMedal($CURUSER['id'], $data); } + +function claimAllSeeding() +{ + global $CURUSER; + $rep = new \App\Repositories\ClaimRepository(); + return $rep->claimAllSeeding($CURUSER['id']); +} diff --git a/public/getusertorrentlistajax.php b/public/getusertorrentlistajax.php index cc1d963e..1afec73f 100644 --- a/public/getusertorrentlistajax.php +++ b/public/getusertorrentlistajax.php @@ -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('%s%s', $count, $lang_getusertorrentlistajax['text_record'] . add_s ( $count )); if (isset($total_size) && $total_size){ - echo "
" . $count . "" . $lang_getusertorrentlistajax['text_record'] . add_s ( $count ) . $lang_getusertorrentlistajax['text_total_size'] . mksize($total_size) . $pagertop . $torrentlist . $pagerbottom; -} elseif ($count){ - echo "
".$count."".$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('', nexus_trans('claim.claim_all_seeding_btn')); + } + $header = sprintf('
%s
%s
', $summary, $claimAllBtn); + echo '
' . $header . $table; } else { echo $lang_getusertorrentlistajax['text_no_record']; } + ?> diff --git a/public/userdetails.php b/public/userdetails.php index 2ec3a770..b3810c24 100644 --- a/public/userdetails.php +++ b/public/userdetails.php @@ -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 = << diff --git a/resources/lang/en/claim.php b/resources/lang/en/claim.php index b2caf10b..1848793a 100644 --- a/resources/lang/en/claim.php +++ b/resources/lang/en/claim.php @@ -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?' , ]; diff --git a/resources/lang/zh_CN/claim.php b/resources/lang/zh_CN/claim.php index 075539a7..cdb45339 100644 --- a/resources/lang/zh_CN/claim.php +++ b/resources/lang/zh_CN/claim.php @@ -35,4 +35,8 @@ return [ 'fields' => [ 'torrent_id' => '种子 ID', ], + + 'claim_all_seeding_btn' => '一键认领', + 'claim_all_seeding_confirmation' => '确定要认领当前全部做种中的种子吗?', + ]; diff --git a/resources/lang/zh_TW/claim.php b/resources/lang/zh_TW/claim.php index 9fe68ede..d8585f61 100644 --- a/resources/lang/zh_TW/claim.php +++ b/resources/lang/zh_TW/claim.php @@ -33,4 +33,6 @@ return [ 'fields' => [ 'torrent_id' => '種子 ID', ], + 'claim_all_seeding_btn' => '一鍵認領', + 'claim_all_seeding_confirmation' => '確定要認領當前全部做種中的種子嗎?', ];