admin add claim

This commit is contained in:
xiaomlove
2022-07-02 15:08:23 +08:00
parent 579351c0eb
commit 5191a1ba9a
48 changed files with 992 additions and 293 deletions
+24
View File
@@ -22,6 +22,30 @@ class Claim extends NexusModel
'last_settle_at' => 'datetime',
];
public function getSeedTimeThisMonthAttribute()
{
return mkprettytime($this->snatch->seedtime - $this->seed_time_begin);
}
public function getUploadedThisMonthAttribute()
{
return mksize($this->snatch->uploaded - $this->uploaded_begin);
}
public function getIsReachedThisMonthAttribute(): bool
{
$seedTimeRequiredHours = self::getConfigStandardSeedTimeHours();
$uploadedRequiredTimes = self::getConfigStandardUploadedTimes();
if (
bcsub($this->snatch->seedtime, $this->seed_time_begin) >= $seedTimeRequiredHours * 3600
|| bcsub($this->snatch->uploaded, $this->uploaded_begin) >= $uploadedRequiredTimes * $this->torrent->size
) {
return true;
} else {
return false;
}
}
public function user()
{
return $this->belongsTo(User::class, 'uid');
+24 -9
View File
@@ -39,8 +39,8 @@ class Exam extends NexusModel
public static $indexes = [
self::INDEX_UPLOADED => ['name' => 'Uploaded', 'unit' => 'GB', 'source_user_field' => 'uploaded'],
self::INDEX_SEED_TIME_AVERAGE => ['name' => 'Seed time average', 'unit' => 'Hour', 'source_user_field' => 'seedtime'],
self::INDEX_DOWNLOADED => ['name' => 'Downloaded', 'unit' => 'GB', 'source_user_field' => 'downloaded'],
self::INDEX_SEED_TIME_AVERAGE => ['name' => 'Seed time average', 'unit' => 'Hour', 'source_user_field' => 'seedtime'],
self::INDEX_SEED_BONUS => ['name' => 'Bonus', 'unit' => '', 'source_user_field' => 'seedbonus'],
];
@@ -61,9 +61,24 @@ class Exam extends NexusModel
});
}
public static function listIndex($onlyKeyValue = false): array
{
$result = self::$indexes;
$keyValues = [];
foreach ($result as $key => &$value) {
$text = nexus_trans("exam.index_text_$key");
$value['text'] = $text;
$keyValues[$key] = $text;
}
if ($onlyKeyValue) {
return $keyValues;
}
return $result;
}
public function getStatusTextAttribute(): string
{
return self::$status[$this->status]['text'] ?? '';
return $this->status == self::STATUS_ENABLED ? nexus_trans('label.enabled') : nexus_trans('label.disabled');
}
public function getIsDiscoveredTextAttribute(): string
@@ -87,7 +102,7 @@ class Exam extends NexusModel
if (isset($index['checked']) && $index['checked']) {
$arr[] = sprintf(
'%s: %s %s',
self::$indexes[$index['index']]['name'] ?? '',
nexus_trans("exam.index_text_{$index['index']}"),
$index['require_value'],
self::$indexes[$index['index']]['unit'] ?? ''
);
@@ -103,24 +118,24 @@ class Exam extends NexusModel
$filter = self::FILTER_USER_CLASS;
if (!empty($currentFilters->{$filter})) {
$classes = collect(User::$classes)->only($currentFilters->{$filter});
$arr[] = sprintf('%s: %s', self::$filters[$filter]['name'], $classes->pluck('text')->implode(', '));
$arr[] = sprintf('%s: %s', nexus_trans("exam.filters.$filter"), $classes->pluck('text')->implode(', '));
}
$filter = self::FILTER_USER_REGISTER_TIME_RANGE;
if (!empty($currentFilters->{$filter})) {
$range = $currentFilters->{$filter};
$arr[] = sprintf(
"%s: \n%s ~ %s",
self::$filters[$filter]['name'],
$range[0] ? Carbon::parse($range[0])->toDateTimeString() : '-',
$range[1] ? Carbon::parse($range[1])->toDateTimeString() : '-'
"%s: <br/>%s ~ %s",
nexus_trans("exam.filters.$filter"),
$range[0] ? Carbon::parse($range[0])->toDateTimeString() : '--',
$range[1] ? Carbon::parse($range[1])->toDateTimeString() : '--'
);
}
$filter = self::FILTER_USER_DONATE;
if (!empty($currentFilters->{$filter})) {
$donateStatus = $classes = collect(User::$donateStatus)->only($currentFilters->{$filter});
$arr[] = sprintf('%s: %s', self::$filters[$filter]['name'], $donateStatus->pluck('text')->implode(', '));
$arr[] = sprintf('%s: %s', nexus_trans("exam.filters.$filter"), $donateStatus->pluck('text')->implode(', '));
}
return implode("<br/>", $arr);
+35
View File
@@ -41,6 +41,41 @@ class ExamUser extends NexusModel
return self::$isDoneInfo[$this->is_done]['text'] ?? '';
}
public function getProgressFormattedAttribute(): array
{
$result = [];
$progress = $this->progress;
foreach ($this->exam->indexes as $key => $index) {
if (!isset($index['checked']) || !$index['checked']) {
continue;
}
$currentValue = $progress[$index['index']] ?? 0;
$requireValue = $index['require_value'];
switch ($index['index']) {
case Exam::INDEX_UPLOADED:
case Exam::INDEX_DOWNLOADED:
$currentValueFormatted = mksize($currentValue);
$requireValueAtomic = $requireValue * 1024 * 1024 * 1024;
break;
case Exam::INDEX_SEED_TIME_AVERAGE:
$currentValueFormatted = number_format($currentValue / 3600, 2) . " {$index['unit']}";
$requireValueAtomic = $requireValue * 3600;
break;
default:
$currentValueFormatted = $currentValue;
$requireValueAtomic = $requireValue;
}
$index['name'] = Exam::$indexes[$index['index']]['name'] ?? '';
$index['index_formatted'] = nexus_trans('exam.index_text_' . $index['index']);
$index['require_value_formatted'] = "$requireValue " . ($index['unit'] ?? '');
$index['current_value'] = $currentValue;
$index['current_value_formatted'] = $currentValueFormatted;
$index['passed'] = $currentValue >= $requireValueAtomic;
$result[] = $index;
}
return $result;
}
public static function listStatus($onlyKeyValue = false): array
{
$result = self::$status;
+22
View File
@@ -35,6 +35,10 @@ class Snatch extends NexusModel
const FINISHED_NO = 'no';
/**
* @deprecated Use uploadedText instead
* @return Attribute
*/
protected function uploadText(): Attribute
{
return new Attribute(
@@ -42,6 +46,10 @@ class Snatch extends NexusModel
);
}
/**
* @deprecated Use downloadedText instead
* @return Attribute
*/
protected function downloadText(): Attribute
{
return new Attribute(
@@ -49,6 +57,20 @@ class Snatch extends NexusModel
);
}
protected function uploadedText(): Attribute
{
return new Attribute(
get: fn($value, $attributes) => sprintf('%s@%s', mksize($attributes['uploaded']), $this->getUploadSpeed())
);
}
protected function downloadedText(): Attribute
{
return new Attribute(
get: fn($value, $attributes) => sprintf('%s@%s', mksize($attributes['downloaded']), $this->getDownloadSpeed())
);
}
protected function shareRatio(): Attribute
{
return new Attribute(
+1 -1
View File
@@ -105,7 +105,7 @@ class User extends Authenticatable implements FilamentUser, HasName
public function canAccessFilament(): bool
{
return $this->class >= self::CLASS_ADMINISTRATOR;
return $this->canAccessAdmin();
}
public function getFilamentName(): string