0455c1577e
- 引入 Redis(predis)快取層:Admin Stats(5分鐘)、課程列表(3分鐘,tag-based 失效)、評價分布(10分鐘) - ReviewController::publicList 改為 paginate + eager load votes,消除 N+1 - AdminReviewController::index 加入分頁(預設 20,最大 100) - 新增 notifications / diving_offers 效能索引 migration - 新增 docker-compose.override.yml 本機開發 port mapping 機制(不進 git) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
27 lines
763 B
PHP
27 lines
763 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\DivingOffer;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class AdminStatsController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
if (auth()->user()->role !== 'admin') {
|
|
return response()->json(['status' => false, 'message' => '無權限存取'], 403);
|
|
}
|
|
|
|
$stats = Cache::remember('admin_stats', 300, fn() => [
|
|
'total_members' => User::where('role', 'member')->count(),
|
|
'total_providers' => User::where('role', 'provider')->count(),
|
|
'total_offers' => DivingOffer::count(),
|
|
]);
|
|
|
|
return response()->json(['status' => true, 'data' => $stats]);
|
|
}
|
|
}
|