From 40093371338c280bd445b3097f24b4813b9ec7f7 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Wed, 17 Sep 2025 04:05:36 +0700 Subject: [PATCH] backend bonus log exclude seeding default --- .../Resources/Torrent/TorrentResource.php | 12 +++-- .../Resources/User/BonusLogResource.php | 10 ++++ app/Http/Controllers/UploadController.php | 4 +- app/Http/Resources/BookmarkResource.php | 23 +++++++++ app/Models/BonusLogs.php | 8 ++++ app/Models/HitAndRun.php | 4 ++ app/Models/SearchBox.php | 26 ++++++++-- app/Repositories/SearchBoxRepository.php | 10 ++-- app/Repositories/TorrentRepository.php | 47 +++++++++++++++++-- app/Repositories/UploadRepository.php | 2 +- include/constants.php | 2 +- include/functions.php | 9 ++-- public/userdetails.php | 7 +-- resources/lang/en/bonus-log.php | 1 + resources/lang/zh_CN/bonus-log.php | 1 + resources/lang/zh_TW/bonus-log.php | 1 + 16 files changed, 136 insertions(+), 31 deletions(-) create mode 100644 app/Http/Resources/BookmarkResource.php diff --git a/app/Filament/Resources/Torrent/TorrentResource.php b/app/Filament/Resources/Torrent/TorrentResource.php index 3dd187c8..b6ec2bc0 100644 --- a/app/Filament/Resources/Torrent/TorrentResource.php +++ b/app/Filament/Resources/Torrent/TorrentResource.php @@ -15,6 +15,7 @@ use App\Models\User; use App\Repositories\SearchBoxRepository; use App\Repositories\TagRepository; use App\Repositories\TorrentRepository; +use Elasticsearch\Endpoints\Search; use Filament\Facades\Filament; use Filament\Forms; use Filament\Pages\Actions\Action; @@ -302,7 +303,7 @@ class TorrentResource extends Resource }) ->deselectRecordsAfterCompletion(); } - $actions[] = self::getBulkActionChangeCategory(); +// $actions[] = self::getBulkActionChangeCategory(); if (user_can('torrent-delete')) { $actions[] = Tables\Actions\DeleteBulkAction::make('bulk-delete')->using(function (Collection $records) { @@ -357,7 +358,7 @@ class TorrentResource extends Resource ->helperText(new HtmlString(__('admin.resources.torrent.bulk_action_change_category_section_help'))) ->options(function() { $rep = new SearchBoxRepository(); - $list = $rep->listSections(false); + $list = $rep->listSections(SearchBox::listAllSectionId(), false); $result = []; foreach ($list as $section) { $result[$section->id] = $section->displaySectionName; @@ -367,12 +368,12 @@ class TorrentResource extends Resource ->reactive() ->required() , - $searchBoxRep->buildSearchBoxFormSchema(SearchBox::getBrowseSearchBox()) + $searchBoxRep->buildSearchBoxFormSchema(SearchBox::getBrowseSearchBox(), 'section_info') ->hidden(function (Forms\Get $get) { return $get('section_id') != SearchBox::getBrowseMode(); }) , - $searchBoxRep->buildSearchBoxFormSchema(SearchBox::getSpecialSearchBox()) + $searchBoxRep->buildSearchBoxFormSchema(SearchBox::getSpecialSearchBox(), 'section_info') ->hidden(function (Forms\Get $get) { return $get('section_id') != SearchBox::getSpecialMode(); }) @@ -381,8 +382,9 @@ class TorrentResource extends Resource ]) ->action(function (Collection $records, array $data) { $torrentRep = new TorrentRepository(); + $newSectionId = $data['section_id']; try { - $torrentRep->changeCategory($records, $data['section_id'], $data['category_id']); + $torrentRep->changeCategory($records, $newSectionId, $data['section_info']['section'][$newSectionId]); } catch (\Exception $exception) { do_log($exception->getMessage(), 'error'); } diff --git a/app/Filament/Resources/User/BonusLogResource.php b/app/Filament/Resources/User/BonusLogResource.php index 05f13b51..db3f81c8 100644 --- a/app/Filament/Resources/User/BonusLogResource.php +++ b/app/Filament/Resources/User/BonusLogResource.php @@ -88,6 +88,16 @@ class BonusLogResource extends Resource ->options(BonusLogs::listStaticProps(BonusLogs::$businessTypes, 'bonus-log.business_types', true)) ->label(__('bonus-log.fields.business_type')) , + Tables\Filters\Filter::make('exclude_seeding_bonus') + ->toggle() + ->label(__('bonus-log.exclude_seeding_bonus')) + ->query(function (Builder $query, array $data) { + if ($data['isActive']) { + $query->whereNotIn("business_type", BonusLogs::$businessTypeBonus); + } + }) + ->default() + , ]) ->actions([ // Tables\Actions\EditAction::make(), diff --git a/app/Http/Controllers/UploadController.php b/app/Http/Controllers/UploadController.php index 7ffcd2ea..1d5677ff 100644 --- a/app/Http/Controllers/UploadController.php +++ b/app/Http/Controllers/UploadController.php @@ -2,8 +2,10 @@ namespace App\Http\Controllers; +use App\Auth\Permission; use App\Http\Resources\SearchBoxResource; use App\Http\Resources\TorrentResource; +use App\Models\SearchBox; use App\Repositories\SearchBoxRepository; use App\Repositories\UploadRepository; use Illuminate\Http\Request; @@ -22,7 +24,7 @@ class UploadController extends Controller public function sections(Request $request) { - $sections = $this->searchBoxRepository->listSections(); + $sections = $this->searchBoxRepository->listSections(SearchBox::listAuthorizedSectionId()); $resource = SearchBoxResource::collection($sections); return $this->success($resource); } diff --git a/app/Http/Resources/BookmarkResource.php b/app/Http/Resources/BookmarkResource.php new file mode 100644 index 00000000..da0a7f9b --- /dev/null +++ b/app/Http/Resources/BookmarkResource.php @@ -0,0 +1,23 @@ + $this->id, + 'torrent_id' => $this->torrentid, + 'user_id' => $this->userid, + ]; + } +} diff --git a/app/Models/BonusLogs.php b/app/Models/BonusLogs.php index b7f70584..4bfd1019 100644 --- a/app/Models/BonusLogs.php +++ b/app/Models/BonusLogs.php @@ -96,6 +96,14 @@ class BonusLogs extends NexusModel self::BUSINESS_TYPE_SEEDING_MEDAL_ADDITION => ['text' => 'Seeding medal addition'], ]; + public static array $businessTypeBonus = [ + self::BUSINESS_TYPE_SEEDING_BASIC, + self::BUSINESS_TYPE_SEEDING_DONOR_ADDITION, + self::BUSINESS_TYPE_SEEDING_OFFICIAL_ADDITION, + self::BUSINESS_TYPE_SEEDING_HAREM_ADDITION, + self::BUSINESS_TYPE_SEEDING_MEDAL_ADDITION + ]; + public function getBusinessTypeTextAttribute() { return nexus_trans('bonus-log.business_types.' . $this->business_type); diff --git a/app/Models/HitAndRun.php b/app/Models/HitAndRun.php index 12667b0a..4c9d8483 100644 --- a/app/Models/HitAndRun.php +++ b/app/Models/HitAndRun.php @@ -113,6 +113,10 @@ class HitAndRun extends NexusModel do_log(sprintf('[INVALID_CATEGORY], Torrent: %s', $this->torrent_id), 'error'); return '---'; } + if (!$this->snatch) { + do_log("hit and run: {$this->id} no snatch", 'warning'); + return '---'; + } $seedTimeMinimum = HitAndRun::getConfig('seed_time_minimum', $searchBoxId); $diffInSeconds = 3600 * $seedTimeMinimum - $this->snatch->seedtime; return mkprettytime($diffInSeconds); diff --git a/app/Models/SearchBox.php b/app/Models/SearchBox.php index 3cd5af17..1249ecec 100644 --- a/app/Models/SearchBox.php +++ b/app/Models/SearchBox.php @@ -158,8 +158,8 @@ class SearchBox extends NexusModel } $table = self::$taxonomies[$torrentField]['table']; return NexusDB::table($table)->where(function (Builder $query) use ($searchBox) { - return $query->where('mode', $searchBox->id)->orWhere('mode', 0); - })->orderBy('sort_index')->orderBy('id')->get(); + return $query->whereIn('mode', [$searchBox->id, 0]); + })->orderBy('sort_index', 'desc')->orderBy('id', 'desc')->get(); } public static function listModeOptions(): array @@ -301,8 +301,8 @@ class SearchBox extends NexusModel $this->setRelation( $relationName, $modelName::query()->whereIn('mode', [$this->getKey(), 0]) - ->orderBy('sort_index') - ->orderBy('id') + ->orderBy('sort_index', 'desc') + ->orderBy('id', 'desc') ->get() ); } @@ -367,4 +367,22 @@ class SearchBox extends NexusModel return $results; } + public static function listAuthorizedSectionId(): array + { + $modeIds = [self::getBrowseMode()]; + if (self::isSpecialEnabled() && Permission::canViewSpecialSection()) { + $modeIds[] = self::getSpecialMode(); + } + return $modeIds; + } + + public static function listAllSectionId(): array + { + $modeIds = [self::getBrowseMode()]; + if (self::isSpecialEnabled()) { + $modeIds[] = self::getSpecialMode(); + } + return $modeIds; + } + } diff --git a/app/Repositories/SearchBoxRepository.php b/app/Repositories/SearchBoxRepository.php index 91602cd3..4473fa0a 100644 --- a/app/Repositories/SearchBoxRepository.php +++ b/app/Repositories/SearchBoxRepository.php @@ -242,13 +242,9 @@ class SearchBoxRepository extends BaseRepository return Category::query()->whereIn('id', $idArr)->delete(); } - public function listSections($withCategoryAndTags = true) + public function listSections($id, $withCategoryAndTags = true) { - $modeIds = [SearchBox::getBrowseMode()]; - if (SearchBox::isSpecialEnabled() && Permission::canUploadToSpecialSection()) { - $modeIds[] = SearchBox::getSpecialMode(); - } - $searchBoxList = SearchBox::query()->with($withCategoryAndTags ? ['categories'] : [])->find($modeIds); + $searchBoxList = SearchBox::query()->with($withCategoryAndTags ? ['categories'] : [])->find($id); if ($withCategoryAndTags) { foreach ($searchBoxList as $searchBox) { if ($searchBox->showsubcat) { @@ -260,7 +256,7 @@ class SearchBoxRepository extends BaseRepository return $searchBoxList; } - public function buildSearchBoxFormSchema(SearchBox $searchBox, string $namePrefix = ""): Forms\Components\Section + public function buildSearchBoxFormSchema(SearchBox $searchBox, string $namePrefix): Forms\Components\Section { $lang = get_langfolder_cookie(); $heading = $searchBox->section_name[$lang] ?? nexus_trans('searchbox.sections.browse'); diff --git a/app/Repositories/TorrentRepository.php b/app/Repositories/TorrentRepository.php index e27a0644..536be15f 100644 --- a/app/Repositories/TorrentRepository.php +++ b/app/Repositories/TorrentRepository.php @@ -1113,16 +1113,55 @@ HTML; } } - public function changeCategory(Collection $torrents, int $sectionId, int $categoryId): void + public function changeCategory(Collection $torrents, int $sectionId, array $specificSubCategoryAndTags): void { assert_has_permission(Permission::canManageTorrent()); - $searchBox = SearchBox::query()->findOrFail($sectionId); - $category = $searchBox->categories()->findOrFail($categoryId); $torrentIdArr = $torrents->pluck('id')->toArray(); if (empty($torrentIdArr)) { do_log("torrents is empty", 'warn'); return; } + $torrentIdStr = implode(',', $torrentIdArr); + do_log("torrentIdStr: $torrentIdStr, sectionId: $sectionId"); + $searchBoxRep = new SearchBoxRepository(); + $sections = $searchBoxRep->listSections(SearchBox::listAllSectionId(), true)->keyBy('id'); + if (!$sections->has($sectionId)) { + throw new NexusException(nexus_trans('upload.invalid_section')); + } + /** + * @var $section SearchBox + */ + $section = $sections->get($sectionId); + $validCategoryIdArr = $section->categories->pluck('id')->toArray(); + if (!empty($specificSubCategoryAndTags['category']) && !in_array($specificSubCategoryAndTags['category'], $validCategoryIdArr)) { + throw new NexusException(nexus_trans('upload.invalid_category')); + } + $baseUpdateQuery = Torrent::query()->whereIn('id', $torrentIdArr); + $updateCategoryQuery = $baseUpdateQuery->clone(); + if (!empty($validCategoryId)) { + $updateCategoryQuery->whereNotIn('category', $validCategoryIdArr); + } + $updateCategoryResult = $updateCategoryQuery->update(['category' => 0]); + do_log(sprintf("update category = 0 when category not in: %s, result: %s", implode(', ', $validCategoryIdArr), $updateCategoryResult)); + + foreach (SearchBox::$taxonomies as $name => $info) { + $relationName = "taxonomy_{$name}"; + $relation = $section->{$relationName}; + if (empty($specificSubCategoryAndTags[$name])) { + continue; + } + //有指定,看是否有效 + if (!$relation) { + do_log("searchBox: {$section->id} no relation of $name"); + throw new NexusException(nexus_trans('upload.not_supported_sub_category_field', ['field' => $name])); + } + $validIdArr = $relation->pluck('id')->toArray(); + if (!in_array($specificSubCategoryAndTags[$name], $validIdArr)) { + do_log("taxonomy {$name}, specific: {$specificSubCategoryAndTags[$name]} not in validIdArr: " . implode(', ', $validIdArr)); + throw new NexusException(nexus_trans('upload.not_supported_sub_category_field', ['field' => $name])); + } + + } $operatorId = get_user_id(); $siteLogArr = []; foreach ($torrents as $torrent) { @@ -1139,7 +1178,7 @@ HTML; foreach ($torrents as $torrent) { fire_event(ModelEventEnum::TORRENT_UPDATED, $torrent); } - do_log("success change torrent category to $categoryId, torrent count:" . $torrents->count()); + do_log("success change to section $sectionId, torrent count:" . $torrents->count()); } } diff --git a/app/Repositories/UploadRepository.php b/app/Repositories/UploadRepository.php index fd86eaaf..499cdb90 100644 --- a/app/Repositories/UploadRepository.php +++ b/app/Repositories/UploadRepository.php @@ -440,7 +440,7 @@ class UploadRepository extends BaseRepository private function getSubCategoriesAndTags(Request $request, Category $category): array { $searchBoxRep = new SearchBoxRepository(); - $sections = $searchBoxRep->listSections()->keyBy('id'); + $sections = $searchBoxRep->listSections(SearchBox::listAllSectionId())->keyBy('id'); if (!$sections->has($category->mode)) { throw new NexusException(nexus_trans('upload.invalid_section')); } diff --git a/include/constants.php b/include/constants.php index 36bc6c0b..336e3246 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ 0) { $rowSpan++; $hasHaremAddition = true; + $totalBonus += $haremAddition * $haremFactor; } if ($officialAdditionalFactor > 0 && $officialTag) { $rowSpan++; $hasOfficialAddition = true; + $totalBonus += $bonusResult['official_bonus'] * $officialAdditionalFactor; } if ($bonusResult['medal_additional_factor'] > 0) { $rowSpan++; $hasMedalAddition = true; + $totalBonus += $bonusResult['medal_bonus'] * $bonusResult['medal_additional_factor']; } $table = sprintf('', $options['table_style'] ?? ''); diff --git a/public/userdetails.php b/public/userdetails.php index 24f95ef8..499141f5 100644 --- a/public/userdetails.php +++ b/public/userdetails.php @@ -501,16 +501,17 @@ if (user_can('prfmanage') && $user["class"] < get_user_class()) ->orderBy("id", "desc") ->limit(20) ->get() - ->map(fn ($item) => sprintf("%s - %s", $item->created_at->format("Y-m-d"), $item->content)) - ->implode("content", "\n") + ->map(fn ($item) => sprintf("[%s] %s", $item->created_at->format("Y-m-d"), $item->content)) + ->implode("\n") ; tr($lang_userdetails['row_comment'], "", 1); $bonuscomment = \App\Models\BonusLogs::query() ->where("uid", $user["id"]) + ->whereNotIn("business_type", \App\Models\BonusLogs::$businessTypeBonus) ->orderBy("id", "desc") ->limit(20) ->get() - ->map(fn ($item) => sprintf("%s - %s", $item->created_at->format("Y-m-d"), $item->comment)) + ->map(fn ($item) => sprintf("[%s] %s", $item->created_at->format("Y-m-d"), $item->comment)) ->implode("\n") ; tr($lang_userdetails['row_seeding_karma'], "", 1); diff --git a/resources/lang/en/bonus-log.php b/resources/lang/en/bonus-log.php index 726b5f7a..93770f59 100644 --- a/resources/lang/en/bonus-log.php +++ b/resources/lang/en/bonus-log.php @@ -42,4 +42,5 @@ return [ 'value' => 'Trade value', 'new_total_value' => 'Post-trade value', ], + 'exclude_seeding_bonus' => 'Exclude seeding bonus', ]; diff --git a/resources/lang/zh_CN/bonus-log.php b/resources/lang/zh_CN/bonus-log.php index 75ef4c9b..cce264fe 100644 --- a/resources/lang/zh_CN/bonus-log.php +++ b/resources/lang/zh_CN/bonus-log.php @@ -44,4 +44,5 @@ return [ 'value' => '交易值', 'new_total_value' => '交易后值', ], + 'exclude_seeding_bonus' => '不包含做种魔力', ]; diff --git a/resources/lang/zh_TW/bonus-log.php b/resources/lang/zh_TW/bonus-log.php index efd4da2a..ebba6191 100644 --- a/resources/lang/zh_TW/bonus-log.php +++ b/resources/lang/zh_TW/bonus-log.php @@ -42,4 +42,5 @@ return [ 'value' => '交易值', 'new_total_value' => '交易後值', ], + 'exclude_seeding_bonus' => '不包含做種魔力', ];