mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-05 07:20:58 +08:00
[api] user torrents stat
This commit is contained in:
@@ -177,13 +177,13 @@ class UserController extends Controller
|
||||
$rows = [
|
||||
[
|
||||
['icon' => 'icon-user', 'label' => '种子评论', 'name' => 'comments_count'],
|
||||
['icon' => 'icon-user', 'label' => '论坛坛子', 'name' => 'posts_count'],
|
||||
['icon' => 'icon-user', 'label' => '论坛帖子', 'name' => 'posts_count'],
|
||||
],[
|
||||
['icon' => 'icon-user', 'label' => '发布种子', 'name' => 'comments_count'],
|
||||
['icon' => 'icon-user', 'label' => '当前做种', 'name' => 'posts_count'],
|
||||
['icon' => 'icon-user', 'label' => '当前下载', 'name' => 'posts_count'],
|
||||
['icon' => 'icon-user', 'label' => '完成种子', 'name' => 'posts_count'],
|
||||
['icon' => 'icon-user', 'label' => '未完成种子', 'name' => 'posts_count'],
|
||||
['icon' => 'icon-user', 'label' => '发布种子', 'name' => 'torrents_count'],
|
||||
['icon' => 'icon-user', 'label' => '当前做种', 'name' => 'seeding_torrents_count'],
|
||||
['icon' => 'icon-user', 'label' => '当前下载', 'name' => 'leeching_torrents_count'],
|
||||
['icon' => 'icon-user', 'label' => '完成种子', 'name' => 'completed_torrents_count'],
|
||||
['icon' => 'icon-user', 'label' => '未完成种子', 'name' => 'incomplete_torrents_count'],
|
||||
]
|
||||
];
|
||||
$resource->additional([
|
||||
@@ -196,7 +196,11 @@ class UserController extends Controller
|
||||
|
||||
private function getUserProfile($id)
|
||||
{
|
||||
$user = User::query()->withCount(['comments', 'posts'])->findOrFail($id);
|
||||
$user = User::query()->withCount([
|
||||
'comments', 'posts', 'torrents', 'seeding_torrents', 'leeching_torrents',
|
||||
'completed_torrents' => function ($query) use ($id) {$query->where('snatched.userid', '!=', $id);},
|
||||
'incomplete_torrents' => function ($query) use ($id) {$query->where('snatched.userid', '!=', $id);},
|
||||
])->findOrFail($id);
|
||||
$resource = new UserResource($user);
|
||||
return $resource;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class UserResource extends JsonResource
|
||||
'uploaded_text' => mksize($this->uploaded),
|
||||
'downloaded' => $this->downloaded,
|
||||
'downloaded_text' => mksize($this->downloaded),
|
||||
'bonus' => $this->seedbonus,
|
||||
'seed_bonus' => $this->seedbonus,
|
||||
'seed_points' => $this->seed_points,
|
||||
'seedtime' => $this->seedtime,
|
||||
'seedtime_text' => mkprettytime($this->seedtime),
|
||||
@@ -43,10 +43,14 @@ class UserResource extends JsonResource
|
||||
$out['seed_time'] = mkprettytime($this->seedtime);
|
||||
$out['leech_time'] = mkprettytime($this->leechtime);
|
||||
$out['share_ratio'] = get_share_ratio($this->uploaded, $this->downloaded);
|
||||
$out['seed_bonus'] = $this->seedbonus;
|
||||
$out['invites'] = $this->invites;
|
||||
$out['comments_count'] = $this->comments_count;
|
||||
$out['posts_count'] = $this->posts_count;
|
||||
$out['torrents_count'] = $this->torrents_count;
|
||||
$out['seeding_torrents_count'] = $this->seeding_torrents_count;
|
||||
$out['leeching_torrents_count'] = $this->leeching_torrents_count;
|
||||
$out['completed_torrents_count'] = $this->completed_torrents_count;
|
||||
$out['incomplete_torrents_count'] = $this->incomplete_torrents_count;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
@@ -70,8 +70,8 @@ class User extends Authenticatable
|
||||
];
|
||||
|
||||
public static $cardTitles = [
|
||||
'uploaded_human' => '上传',
|
||||
'downloaded_human' => '下载',
|
||||
'uploaded_human' => '上传量',
|
||||
'downloaded_human' => '下载量',
|
||||
'share_ratio' => '分享率',
|
||||
// 'seed_time' => '做种时间',
|
||||
'seed_bonus' => '魔力值',
|
||||
@@ -135,7 +135,7 @@ class User extends Authenticatable
|
||||
public static $commonFields = [
|
||||
'id', 'username', 'email', 'class', 'status', 'added', 'avatar',
|
||||
'uploaded', 'downloaded', 'seedbonus', 'seedtime', 'leechtime',
|
||||
'invited_by', 'enabled',
|
||||
'invited_by', 'enabled', 'seed_points',
|
||||
];
|
||||
|
||||
public function checkIsNormal(array $fields = ['status', 'enabled'])
|
||||
@@ -260,6 +260,27 @@ class User extends Authenticatable
|
||||
'torrentid');
|
||||
}
|
||||
|
||||
public function seeding_torrents()
|
||||
{
|
||||
return $this->peers_torrents()->where('peers.seeder', Peer::SEEDER_YES);
|
||||
}
|
||||
|
||||
public function leeching_torrents()
|
||||
{
|
||||
return $this->peers_torrents()->where('peers.seeder', Peer::SEEDER_NO);
|
||||
}
|
||||
|
||||
public function completed_torrents()
|
||||
{
|
||||
return $this->snatched_torrents()->where('snatched.finished', Snatch::FINISHED_YES);
|
||||
}
|
||||
|
||||
public function incomplete_torrents()
|
||||
{
|
||||
return $this->snatched_torrents()->where('snatched.finished', Snatch::FINISHED_NO);
|
||||
}
|
||||
|
||||
|
||||
public function hitAndRuns(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(HitAndRun::class, 'uid');
|
||||
|
||||
Reference in New Issue
Block a user