From a47d91df963f3d08bb4f4f897e168f4242cb9b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Sun, 15 Mar 2026 18:57:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(admin):=20=E4=BB=AA=E8=A1=A8=E7=9B=98?= =?UTF-8?q?=E5=8D=A0=E6=AF=94=E5=8D=A1=E6=8E=A5=E5=85=A5=E5=A5=97=E9=A4=90?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=8D=A0=E6=AF=94=EF=BC=88Top5=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/DashboardController.php | 22 +++++++++ resources/views/admin/dashboard.blade.php | 46 +++++++++++++++++-- ...oardPlanOrderShareCardShouldRenderTest.php | 36 +++++++++++++++ 3 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 tests/Feature/AdminDashboardPlanOrderShareCardShouldRenderTest.php diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index 59b11d8..573805a 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -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'), diff --git a/resources/views/admin/dashboard.blade.php b/resources/views/admin/dashboard.blade.php index 7e6abcb..6fec59b 100644 --- a/resources/views/admin/dashboard.blade.php +++ b/resources/views/admin/dashboard.blade.php @@ -151,9 +151,49 @@
-

占比(占位)

-
后续接入:套餐销量占比 / 渠道占比 / 支付方式占比(支持时间范围切换)。
-
说明:后续会补占比卡的 legend 与颜色体系(对齐 AntD Pro)。
+
+

套餐订单占比(Top5)

+ 查看套餐 +
+ + @php + $shareRows = (array) ($planOrderShare ?? []); + $totalOrders = 0; + foreach ($shareRows as $r) { + $totalOrders += (int) ($r['count'] ?? 0); + } + @endphp + + + + + + + + + + + @forelse($shareRows as $row) + @php + $planId = (int) ($row['plan_id'] ?? 0); + $count = (int) ($row['count'] ?? 0); + $pct = $totalOrders > 0 ? round(($count / $totalOrders) * 100, 1) : 0; + $planName = (string) (($planIdToName[$planId] ?? '') ?: ('#' . $planId)); + @endphp + + + + + + @empty + + + + @endforelse + +
套餐订单数占比
{{ $planName }}{{ $count }}{{ $pct }}%
暂无数据
+ +
说明:当前口径为“平台订单按 plan_id 的数量占比(Top5)”;后续扩展到金额占比、渠道占比与时间范围切换。
@endsection diff --git a/tests/Feature/AdminDashboardPlanOrderShareCardShouldRenderTest.php b/tests/Feature/AdminDashboardPlanOrderShareCardShouldRenderTest.php new file mode 100644 index 0000000..c780f06 --- /dev/null +++ b/tests/Feature/AdminDashboardPlanOrderShareCardShouldRenderTest.php @@ -0,0 +1,36 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_dashboard_plan_order_share_card_should_render(): void + { + $this->loginAsPlatformAdmin(); + + $res = $this->get('/admin'); + $res->assertOk(); + + $res->assertSee('套餐订单占比', false); + $res->assertSee('Top5', false); + $res->assertSee('查看套餐', false); + + // 有数据时至少应包含百分号展示 + $res->assertSee('%', false); + } +}