From 7409e9087584a904299a617ce3ae65db5bd765f5 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Mon, 21 Feb 2022 00:14:52 +0800 Subject: [PATCH] locale file & thank api --- app/Http/Controllers/CommentController.php | 6 +++++- app/Http/Controllers/FileController.php | 3 +++ app/Http/Controllers/ThankController.php | 9 ++++++++- app/Http/Resources/UserResource.php | 1 + app/Models/User.php | 7 ++++--- .../2021_06_24_013107_add_seed_points_to_users_table.php | 2 +- include/cleanup.php | 2 +- include/functions.php | 2 +- resources/lang/en/file.php | 6 ++++++ resources/lang/en/thank.php | 6 ++++++ resources/lang/zh_CN/file.php | 6 ++++++ resources/lang/zh_CN/thank.php | 6 ++++++ resources/lang/zh_TW/file.php | 6 ++++++ resources/lang/zh_TW/thank.php | 6 ++++++ 14 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 resources/lang/en/file.php create mode 100644 resources/lang/en/thank.php create mode 100644 resources/lang/zh_CN/file.php create mode 100644 resources/lang/zh_CN/thank.php create mode 100644 resources/lang/zh_TW/file.php create mode 100644 resources/lang/zh_TW/thank.php diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php index c824de78..d1f42218 100644 --- a/app/Http/Controllers/CommentController.php +++ b/app/Http/Controllers/CommentController.php @@ -17,7 +17,11 @@ class CommentController extends Controller { $torrentId = $request->torrent_id; $with = ['create_user', 'update_user']; - $comments = Comment::query()->with($with)->where('torrent', $torrentId)->paginate(); + $comments = Comment::query() + ->with($with) + ->where('torrent', $torrentId) + ->whereHas('create_user') + ->paginate(); $resource = CommentResource::collection($comments); $resource->additional([ 'page_title' => nexus_trans('comment.index.page_title'), diff --git a/app/Http/Controllers/FileController.php b/app/Http/Controllers/FileController.php index a4c4305f..1d60b9bb 100644 --- a/app/Http/Controllers/FileController.php +++ b/app/Http/Controllers/FileController.php @@ -19,6 +19,9 @@ class FileController extends Controller $torrentId = $request->torrent_id; $files = File::query()->where('torrent', $torrentId)->get(); $resource = FileResource::collection($files); + $resource->additional([ + 'page_title' => nexus_trans('file.index.page_title'), + ]); return $this->success($resource); } diff --git a/app/Http/Controllers/ThankController.php b/app/Http/Controllers/ThankController.php index 8071dede..ba5e2916 100644 --- a/app/Http/Controllers/ThankController.php +++ b/app/Http/Controllers/ThankController.php @@ -16,8 +16,15 @@ class ThankController extends Controller public function index(Request $request) { $torrentId = $request->torrent_id; - $thanks = Thank::query()->where('torrentid', $torrentId)->with(['user'])->paginate(); + $thanks = Thank::query() + ->where('torrentid', $torrentId) + ->whereHas('user') + ->with(['user']) + ->paginate(); $resource = ThankResource::collection($thanks); + $resource->additional([ + 'page_title' => nexus_trans('thank.index.page_title'), + ]); return $this->success($resource); } diff --git a/app/Http/Resources/UserResource.php b/app/Http/Resources/UserResource.php index 9fe3c56f..b8a580db 100644 --- a/app/Http/Resources/UserResource.php +++ b/app/Http/Resources/UserResource.php @@ -29,6 +29,7 @@ class UserResource extends JsonResource 'downloaded' => $this->downloaded, 'downloaded_text' => mksize($this->downloaded), 'bonus' => $this->seedbonus, + 'seed_points' => $this->seed_points, 'seedtime' => $this->seedtime, 'seedtime_text' => mkprettytime($this->seedtime), 'leechtime' => $this->leechtime, diff --git a/app/Models/User.php b/app/Models/User.php index 2342e7ac..4ba81cca 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -72,10 +72,11 @@ class User extends Authenticatable public static $cardTitles = [ 'uploaded_human' => '上传', 'downloaded_human' => '下载', - 'share_ratio' => '分享率', - 'seed_time' => '做种时间', +// 'share_ratio' => '分享率', +// 'seed_time' => '做种时间', 'seed_bonus' => '魔力值', - 'invites' => '邀请', + 'seed_points' => '做种积分', +// 'invites' => '邀请', ]; public function getClassTextAttribute(): string diff --git a/database/migrations/2021_06_24_013107_add_seed_points_to_users_table.php b/database/migrations/2021_06_24_013107_add_seed_points_to_users_table.php index 4958be09..a53fa631 100644 --- a/database/migrations/2021_06_24_013107_add_seed_points_to_users_table.php +++ b/database/migrations/2021_06_24_013107_add_seed_points_to_users_table.php @@ -14,7 +14,7 @@ class AddSeedPointsToUsersTable extends Migration public function up() { Schema::table('users', function (Blueprint $table) { - $table->decimal('seed_points', 20, 1)->nullable(); + $table->decimal('seed_points', 20, 1)->default(0); }); } diff --git a/include/cleanup.php b/include/cleanup.php index 068c7aa9..3a140248 100644 --- a/include/cleanup.php +++ b/include/cleanup.php @@ -290,7 +290,7 @@ function docleanup($forceAll = 0, $printProgress = false) { if ($is_donor == 'yes' && $donortimes_bonus > 0) $all_bonus = $all_bonus * $donortimes_bonus; KPS("+",$all_bonus,$arr["userid"]); - sql_query("update users set seed_points = seed_points + $seedPoints where id = {$arr["userid"]}"); + sql_query("update users set seed_points = ifnull(seed_points, 0) + $seedPoints where id = {$arr["userid"]}"); } } $log = 'calculate seeding bonus'; diff --git a/include/functions.php b/include/functions.php index 308a655a..3514c248 100644 --- a/include/functions.php +++ b/include/functions.php @@ -2933,7 +2933,7 @@ function commenttable($rows, $type, $parent_id, $review = false) { // $userRow = get_user_row($row['user']); $userInfo = $userInfoArr->get($row['user']); - $userRow = $userInfo->toArray(); + $userRow = empty($userInfo) ? [] : $userInfo->toArray(); if ($count>=1) { if ($Advertisement->enable_ad()){ diff --git a/resources/lang/en/file.php b/resources/lang/en/file.php new file mode 100644 index 00000000..5c3b6a93 --- /dev/null +++ b/resources/lang/en/file.php @@ -0,0 +1,6 @@ + [ + 'page_title' => 'Files', + ], +]; diff --git a/resources/lang/en/thank.php b/resources/lang/en/thank.php new file mode 100644 index 00000000..ece86916 --- /dev/null +++ b/resources/lang/en/thank.php @@ -0,0 +1,6 @@ + [ + 'page_title' => 'Thanks', + ], +]; diff --git a/resources/lang/zh_CN/file.php b/resources/lang/zh_CN/file.php new file mode 100644 index 00000000..a614546d --- /dev/null +++ b/resources/lang/zh_CN/file.php @@ -0,0 +1,6 @@ + [ + 'page_title' => '文件列表', + ], +]; diff --git a/resources/lang/zh_CN/thank.php b/resources/lang/zh_CN/thank.php new file mode 100644 index 00000000..8694ce66 --- /dev/null +++ b/resources/lang/zh_CN/thank.php @@ -0,0 +1,6 @@ + [ + 'page_title' => '感谢者', + ], +]; diff --git a/resources/lang/zh_TW/file.php b/resources/lang/zh_TW/file.php new file mode 100644 index 00000000..a614546d --- /dev/null +++ b/resources/lang/zh_TW/file.php @@ -0,0 +1,6 @@ + [ + 'page_title' => '文件列表', + ], +]; diff --git a/resources/lang/zh_TW/thank.php b/resources/lang/zh_TW/thank.php new file mode 100644 index 00000000..54294c03 --- /dev/null +++ b/resources/lang/zh_TW/thank.php @@ -0,0 +1,6 @@ + [ + 'page_title' => '感謝者', + ], +];