ptgen api point support parameter & default user

This commit is contained in:
xiaomlove
2022-02-28 23:20:42 +08:00
parent 5ed80ed637
commit b9d5df232b
51 changed files with 447 additions and 51 deletions

View File

@@ -17,11 +17,11 @@ class Comment extends NexusModel
public function create_user()
{
return $this->belongsTo(User::class, 'user');
return $this->belongsTo(User::class, 'user')->withDefault(User::getDefaultUserAttributes());
}
public function update_user()
{
return $this->belongsTo(User::class, 'editedby');
return $this->belongsTo(User::class, 'editedby')->withDefault(User::getDefaultUserAttributes());
}
}

23
app/Models/News.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
namespace App\Models;
class News extends NexusModel
{
protected $table = 'news';
protected $fillable = [
'userid', 'added', 'title', 'body', 'notify',
];
protected $casts = [
'added' => 'datetime',
];
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(User::class, 'userid');
}
}

View File

@@ -108,7 +108,7 @@ class Torrent extends NexusModel
public function user()
{
return $this->belongsTo(User::class, 'owner');
return $this->belongsTo(User::class, 'owner')->withDefault(User::getDefaultUserAttributes());
}
public function thanks()

View File

@@ -143,6 +143,31 @@ class User extends Authenticatable
'invited_by', 'enabled', 'seed_points',
];
public static function getDefaultUserAttributes(): array
{
return [
'id' => 0,
'username' => nexus_trans('user.deleted_username'),
'class' => self::CLASS_PEASANT,
'email' => '',
'status' => self::STATUS_CONFIRMED,
'added' => '1970-01-01 08:00:00',
'avatar' => '',
'uploaded' => 0,
'downloaded' => 0,
'seedbonus' => 0,
'seedtime' => 0,
'leechtime' => 0,
'enabled' => self::ENABLED_NO,
'seed_points' => 0
];
}
public static function defaultUser()
{
return new static(self::getDefaultUserAttributes());
}
public function checkIsNormal(array $fields = ['status', 'enabled'])
{
if (in_array('status', $fields) && $this->getAttribute('status') != self::STATUS_CONFIRMED) {