[H&R] basically

This commit is contained in:
xiaomlove
2021-06-21 02:01:26 +08:00
parent 45aba84111
commit d2a8f1a1a6
39 changed files with 966 additions and 74 deletions

View File

@@ -6,25 +6,73 @@ class HitAndRun extends NexusModel
{
protected $table = 'hit_and_runs';
protected $fillable = ['uid', 'peer_id', 'torrent_id', 'status', 'comment'];
protected $fillable = ['uid', 'snatch_id', 'torrent_id', 'status', 'comment'];
public $timestamps = true;
const STATUS_INSPECTING = 1;
const STATUS_PASSED = 2;
const STATUS_NOT_PASSED = 3;
const STATUS_CANCELED = 4;
const STATUS_REACHED = 2;
const STATUS_UNREACHED = 3;
const STATUS_PARDONED = 4;
public static $status = [
self::STATUS_INSPECTING => ['text' => '考察中'],
self::STATUS_PASSED => ['text' => '已通过'],
self::STATUS_NOT_PASSED => ['text' => '未通过'],
self::STATUS_CANCELED => ['text' => '已取消'],
self::STATUS_INSPECTING => ['text' => 'Inspecting'],
self::STATUS_REACHED => ['text' => 'Reached'],
self::STATUS_UNREACHED => ['text' => 'Unreached'],
self::STATUS_PARDONED => ['text' => 'Pardoned'],
];
const MODE_DISABLED = 'disabled';
const MODE_MANUAL = 'manual';
const MODE_GLOBAL = 'global';
public static $modes = [
self::MODE_DISABLED => ['text' => 'Disabled'],
self::MODE_MANUAL => ['text' => 'Manual'],
self::MODE_GLOBAL => ['text' => 'Global'],
];
public function getStatusTextAttribute()
{
return self::$status[$this->status] ?? '';
return nexus_trans('hr.status_' . $this->status);
}
public static function listStatus(): array
{
$result = self::$status;
foreach ($result as $key => &$value) {
$value['text'] = nexus_trans('hr.status_' . $key);
}
return $result;
}
public static function listModes(): array
{
$result = self::$modes;
foreach ($result as $key => &$value) {
$value['text'] = nexus_trans('hr.mode_' . $key);
}
return $result;
}
public static function getIsEnabled(): bool
{
return Setting::get('hr.mode') != self::MODE_DISABLED;
}
public function torrent(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Torrent::class, 'torrent_id');
}
public function snatch(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Snatch::class, 'snatched_id');
}
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(User::class, 'uid');
}