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

View File

@@ -34,6 +34,7 @@ class MedalResource extends Resource
return self::getNavigationLabel();
}
public static function form(Form $form): Form
{
return $form
@@ -82,6 +83,12 @@ class MedalResource extends Resource
->numeric()
->default(0)
,
Forms\Components\TextInput::make('priority')
->label(__('label.priority'))
->helperText(__('label.priority_help'))
->numeric()
->default(0)
,
Forms\Components\Textarea::make('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('inventory')
Tables\Columns\TextColumn::make('inventoryText')
->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('priority')->label(__('label.priority')),
])
->defaultSort('id', 'desc')
->filters([
//
])
@@ -122,7 +128,9 @@ class MedalResource extends Resource
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
])
->modifyQueryUsing(fn (Builder $query) => $query->orderBy("priority", 'desc')->orderBy('id', 'desc'))
;
}
public static function getRelations(): array

View File

@@ -18,7 +18,7 @@ class Medal extends NexusModel
protected $fillable = [
'name', 'description', 'image_large', 'image_small', 'price', 'duration', 'get_type',
'display_on_medal_page', 'sale_begin_time', 'sale_end_time', 'inventory', 'bonus_addition_factor',
'gift_fee_factor',
'gift_fee_factor', 'priority'
];
public $timestamps = true;
@@ -48,6 +48,11 @@ class Medal extends NexusModel
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
{
if ($this->duration > 0) {

View File

@@ -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");
});
}
};

View File

@@ -2,7 +2,8 @@
require "../include/bittorrent.php";
dbconn();
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'] ?? '');
if (!empty($q)) {
$query->where('username', 'name', "%{$q}%");