mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 04:20:49 +08:00
finish seed box basic
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class Message extends NexusModel
|
||||
{
|
||||
protected $table = 'messages';
|
||||
@@ -24,4 +26,11 @@ class Message extends NexusModel
|
||||
return $this->belongsTo(User::class, 'receiver');
|
||||
}
|
||||
|
||||
public static function add(array $data): bool
|
||||
{
|
||||
NexusDB::cache_del('user_'.$data["receiver"].'_inbox_count');
|
||||
NexusDB::cache_del('user_'.$data["receiver"].'_unread_message_count');
|
||||
return self::query()->insert($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,22 +6,68 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class SeedBoxRecord extends NexusModel
|
||||
{
|
||||
protected $table = 'seedbox_records';
|
||||
|
||||
protected $fillable = ['type', 'uid', 'operator', 'bandwidth', 'ip', 'ip_begin', 'ip_end', 'ip_begin_numeric', 'ip_end_numeric', 'comment'];
|
||||
protected $fillable = ['type', 'uid', 'status', 'operator', 'bandwidth', 'ip', 'ip_begin', 'ip_end', 'ip_begin_numeric', 'ip_end_numeric', 'comment', 'version'];
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
const TYPE_USER = 1;
|
||||
const TYPE_ADMIN = 2;
|
||||
|
||||
public static array $types = [
|
||||
self::TYPE_USER => ['text' => 'User'],
|
||||
self::TYPE_ADMIN => ['text' => 'Administrator'],
|
||||
];
|
||||
|
||||
const STATUS_UNAUDITED = 0;
|
||||
const STATUS_ALLOWED = 1;
|
||||
const STATUS_DENIED = 2;
|
||||
|
||||
public static array $status = [
|
||||
self::STATUS_UNAUDITED => ['text' => 'Unaudited'],
|
||||
self::STATUS_ALLOWED => ['text' => 'Allowed'],
|
||||
self::STATUS_DENIED => ['text' => 'Denied'],
|
||||
];
|
||||
|
||||
protected function typeText(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn($value, $attributes) => __("seedbox.type_text." . $attributes['type'])
|
||||
get: fn($value, $attributes) => nexus_trans("seed-box.type_text." . $attributes['type'])
|
||||
);
|
||||
}
|
||||
|
||||
protected function statusText(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn($value, $attributes) => nexus_trans("seed-box.status_text." . $attributes['status'])
|
||||
);
|
||||
}
|
||||
|
||||
public static function listTypes($key = null): array
|
||||
{
|
||||
$result = self::$types;
|
||||
$keyValues = [];
|
||||
foreach ($result as $type => &$info) {
|
||||
$info['text'] = nexus_trans("seed-box.type_text.$type");
|
||||
if ($key !== null) {
|
||||
$keyValues[$type] = $info[$key];
|
||||
}
|
||||
}
|
||||
return $key === null ? $result : $keyValues;
|
||||
}
|
||||
|
||||
public static function listStatus($key = null): array
|
||||
{
|
||||
$result = self::$status;
|
||||
$keyValues = [];
|
||||
foreach ($result as $status => &$info) {
|
||||
$info['text'] = nexus_trans("seed-box.status_text.$status");
|
||||
if ($key !== null) {
|
||||
$keyValues[$status] = $info[$key];
|
||||
}
|
||||
}
|
||||
return $key === null ? $result : $keyValues;
|
||||
}
|
||||
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'uid');
|
||||
|
||||
Reference in New Issue
Block a user