medal add priority

This commit is contained in:
xiaomlove
2025-04-21 11:52:05 +07:00
parent d990723ebc
commit e3673ef3da
4 changed files with 48 additions and 6 deletions
@@ -34,6 +34,7 @@ class MedalResource extends Resource
return self::getNavigationLabel(); return self::getNavigationLabel();
} }
public static function form(Form $form): Form public static function form(Form $form): Form
{ {
return $form return $form
@@ -82,6 +83,12 @@ class MedalResource extends Resource
->numeric() ->numeric()
->default(0) ->default(0)
, ,
Forms\Components\TextInput::make('priority')
->label(__('label.priority'))
->helperText(__('label.priority_help'))
->numeric()
->default(0)
,
Forms\Components\Textarea::make('description') Forms\Components\Textarea::make('description')
->label(__('label.description')) ->label(__('label.description'))
, ,
@@ -107,13 +114,12 @@ class MedalResource extends Resource
Tables\Columns\TextColumn::make('duration')->label(__('label.medal.duration')), Tables\Columns\TextColumn::make('duration')->label(__('label.medal.duration')),
Tables\Columns\TextColumn::make('inventory') Tables\Columns\TextColumn::make('inventoryText')
->label(__('medal.fields.inventory')) ->label(__('medal.fields.inventory'))
->formatStateUsing(fn ($record) => $record->inventory ?? nexus_trans('label.infinite'))
, ,
Tables\Columns\TextColumn::make('users_count')->label(__('medal.fields.users_count')), Tables\Columns\TextColumn::make('users_count')->label(__('medal.fields.users_count')),
Tables\Columns\TextColumn::make('priority')->label(__('label.priority')),
]) ])
->defaultSort('id', 'desc')
->filters([ ->filters([
// //
]) ])
@@ -122,7 +128,9 @@ class MedalResource extends Resource
]) ])
->bulkActions([ ->bulkActions([
Tables\Actions\DeleteBulkAction::make(), Tables\Actions\DeleteBulkAction::make(),
]); ])
->modifyQueryUsing(fn (Builder $query) => $query->orderBy("priority", 'desc')->orderBy('id', 'desc'))
;
} }
public static function getRelations(): array public static function getRelations(): array
+6 -1
View File
@@ -18,7 +18,7 @@ class Medal extends NexusModel
protected $fillable = [ protected $fillable = [
'name', 'description', 'image_large', 'image_small', 'price', 'duration', 'get_type', 'name', 'description', 'image_large', 'image_small', 'price', 'duration', 'get_type',
'display_on_medal_page', 'sale_begin_time', 'sale_end_time', 'inventory', 'bonus_addition_factor', 'display_on_medal_page', 'sale_begin_time', 'sale_end_time', 'inventory', 'bonus_addition_factor',
'gift_fee_factor', 'gift_fee_factor', 'priority'
]; ];
public $timestamps = true; public $timestamps = true;
@@ -48,6 +48,11 @@ class Medal extends NexusModel
return nexus_trans("medal.get_types." . $this->get_type); return nexus_trans("medal.get_types." . $this->get_type);
} }
public function getInventoryTextAttribute(): string
{
return $this->inventory ?? nexus_trans("label.infinite");
}
public function getDurationTextAttribute($value): string public function getDurationTextAttribute($value): string
{ {
if ($this->duration > 0) { if ($this->duration > 0) {
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('medals', function (Blueprint $table) {
$table->integer("priority")->default(0);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('medals', function (Blueprint $table) {
$table->dropColumn("priority");
});
}
};
+2 -1
View File
@@ -2,7 +2,8 @@
require "../include/bittorrent.php"; require "../include/bittorrent.php";
dbconn(); dbconn();
loggedinorreturn(); loggedinorreturn();
$query = \App\Models\Medal::query()->where('display_on_medal_page', 1); $query = \App\Models\Medal::query()->where('display_on_medal_page', 1)
->orderBy('priority', 'desc')->orderBy("id", 'desc');
$q = htmlspecialchars($_REQUEST['q'] ?? ''); $q = htmlspecialchars($_REQUEST['q'] ?? '');
if (!empty($q)) { if (!empty($q)) {
$query->where('username', 'name', "%{$q}%"); $query->where('username', 'name', "%{$q}%");