torrent api + swip constants

This commit is contained in:
xiaomlove
2021-05-15 19:29:44 +08:00
parent 786095ca96
commit 33e99516b6
55 changed files with 1968 additions and 38 deletions
+71
View File
@@ -59,6 +59,15 @@ class User extends Authenticatable
self::CLASS_STAFF_LEADER => ['text' => 'Staff Leader'],
];
public static $cardTitles = [
'uploaded_human' => '上传',
'downloaded_human' => '下载',
'share_ratio' => '分享率',
'seed_time' => '做种时间',
'seed_bonus' => '魔力值',
'invites' => '邀请',
];
public function getClassTextAttribute(): string
{
return self::$classes[$this->class]['text'] ?? '';
@@ -157,6 +166,68 @@ class User extends Authenticatable
return $this->belongsTo(User::class, 'invited_by');
}
public function send_messages()
{
return $this->hasMany(Message::class, 'sender');
}
public function receive_messages()
{
return $this->hasMany(Message::class, 'receiver');
}
public function comments()
{
return $this->hasMany(Comment::class, 'user');
}
public function posts()
{
return $this->hasMany(Post::class, 'userid');
}
public function torrents()
{
return $this->hasMany(Torrent::class, 'owner');
}
public function peers_torrents()
{
return $this->hasManyThrough(
Torrent::class,
Peer::class,
'userid',
'id',
'id',
'torrent');
}
public function snatched_torrents()
{
return $this->hasManyThrough(
Torrent::class,
Snatch::class,
'userid',
'id',
'id',
'torrentid');
}
public function getAvatarAttribute($value)
{
if ($value) {
if (substr($value, 0, 4) == 'http') {
return $value;
} else {
do_log("用户头像: $value 不是 http 地址");
}
}
return getSchemeAndHttpHost() . '/pic/default_avatar.png';
}
public function updateWithModComment(array $update, $modComment)
{
if (!$this->exists) {