完善功能
This commit is contained in:
40
web10/app/Filament/Widgets/OverviewStats.php
Normal file
40
web10/app/Filament/Widgets/OverviewStats.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Ad;
|
||||
use App\Models\Article;
|
||||
use App\Models\Comment;
|
||||
use App\Models\ContentViewLog;
|
||||
use App\Models\Product;
|
||||
use Filament\Widgets\StatsOverviewWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class OverviewStats extends StatsOverviewWidget
|
||||
{
|
||||
protected function getStats(): array
|
||||
{
|
||||
$today = now()->toDateString();
|
||||
$todayViews = Schema::hasTable('content_view_logs')
|
||||
? ContentViewLog::where('viewed_on', $today)->count()
|
||||
: 0;
|
||||
|
||||
$productClicks = Schema::hasTable('products')
|
||||
? Product::sum('click_count')
|
||||
: 0;
|
||||
|
||||
$adClicks = Schema::hasTable('ads')
|
||||
? Ad::sum('click_count')
|
||||
: 0;
|
||||
|
||||
return [
|
||||
Stat::make('产品总数', Schema::hasTable('products') ? Product::count() : 0),
|
||||
Stat::make('文章总数', Schema::hasTable('articles') ? Article::count() : 0),
|
||||
Stat::make('今日访问', $todayViews),
|
||||
Stat::make('待审评论', Schema::hasTable('comments') ? Comment::where('status', 'pending')->count() : 0),
|
||||
Stat::make('官网点击', $productClicks),
|
||||
Stat::make('推广点击', $adClicks),
|
||||
];
|
||||
}
|
||||
}
|
||||
34
web10/app/Filament/Widgets/TopArticlesWidget.php
Normal file
34
web10/app/Filament/Widgets/TopArticlesWidget.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Article;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class TopArticlesWidget extends TableWidget
|
||||
{
|
||||
protected int | string | array $columnSpan = 'full';
|
||||
|
||||
protected function getTableHeading(): string
|
||||
{
|
||||
return '热门文章';
|
||||
}
|
||||
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Article::query()
|
||||
->orderByDesc('view_count')
|
||||
->orderByDesc('published_at');
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
TextColumn::make('title')->label('文章')->searchable()->limit(40),
|
||||
TextColumn::make('view_count')->label('浏览')->sortable(),
|
||||
TextColumn::make('published_at')->label('发布时间')->dateTime(),
|
||||
];
|
||||
}
|
||||
}
|
||||
35
web10/app/Filament/Widgets/TopProductsWidget.php
Normal file
35
web10/app/Filament/Widgets/TopProductsWidget.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Product;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class TopProductsWidget extends TableWidget
|
||||
{
|
||||
protected int | string | array $columnSpan = 'full';
|
||||
|
||||
protected function getTableHeading(): string
|
||||
{
|
||||
return '热门产品';
|
||||
}
|
||||
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Product::query()
|
||||
->orderByDesc('hot_score')
|
||||
->orderByDesc('view_count');
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
TextColumn::make('name')->label('产品')->searchable()->limit(30),
|
||||
TextColumn::make('hot_score')->label('热度')->sortable(),
|
||||
TextColumn::make('view_count')->label('浏览')->sortable(),
|
||||
TextColumn::make('click_count')->label('点击')->sortable(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user