feat(admin): 仪表盘占比卡接入套餐订单占比(Top5)

This commit is contained in:
萝卜
2026-03-15 18:57:48 +08:00
parent 257b532757
commit a47d91df96
3 changed files with 101 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ use App\Models\Admin;
use App\Models\Order;
use App\Models\Product;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use App\Models\User;
use App\Support\CacheKeys;
@@ -59,10 +60,31 @@ class DashboardController extends Controller
->limit(5)
->get();
// 占比卡(最小可用):按套餐统计平台订单数量 TopN
$planOrderShare = PlatformOrder::query()
->selectRaw('plan_id, COUNT(*) as cnt')
->whereNotNull('plan_id')
->groupBy('plan_id')
->orderByDesc('cnt')
->limit(5)
->get()
->map(function ($row) {
return [
'plan_id' => (int) $row->plan_id,
'count' => (int) $row->cnt,
];
})
->values()
->all();
$planIdToName = Plan::query()->pluck('name', 'id')->all();
return view('admin.dashboard', [
'adminName' => $admin->name,
'stats' => $stats,
'recentPlatformOrders' => $recentPlatformOrders,
'planOrderShare' => $planOrderShare,
'planIdToName' => $planIdToName,
'platformAdmin' => $admin,
'cacheMeta' => [
'store' => config('cache.default'),