41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
|
|
<?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),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|