82 lines
2.9 KiB
PHP
82 lines
2.9 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers\Admin;
|
||
|
||
use App\Http\Controllers\Concerns\ResolvesPlatformAdminContext;
|
||
use App\Http\Controllers\Controller;
|
||
use App\Models\Admin;
|
||
use App\Models\Order;
|
||
use App\Models\Product;
|
||
use App\Models\Merchant;
|
||
use App\Models\PlatformOrder;
|
||
use App\Models\User;
|
||
use App\Support\CacheKeys;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Support\Facades\Cache;
|
||
use Illuminate\View\View;
|
||
|
||
class DashboardController extends Controller
|
||
{
|
||
use ResolvesPlatformAdminContext;
|
||
|
||
public function index(Request $request): View
|
||
{
|
||
$admin = $this->ensurePlatformAdmin($request);
|
||
|
||
$stats = Cache::remember(
|
||
CacheKeys::platformDashboardStats(),
|
||
now()->addMinutes(10),
|
||
fn () => [
|
||
'merchants' => Merchant::count(),
|
||
'admins' => Admin::count(),
|
||
'users' => User::count(),
|
||
'products' => Product::count(),
|
||
'orders' => Order::count(),
|
||
|
||
// 收费中心(平台侧)
|
||
'platform_orders' => PlatformOrder::count(),
|
||
'platform_orders_unpaid_pending' => PlatformOrder::query()
|
||
->where('payment_status', 'unpaid')
|
||
->where('status', 'pending')
|
||
->count(),
|
||
'platform_orders_paid_pending' => PlatformOrder::query()
|
||
->where('payment_status', 'paid')
|
||
->where('status', 'pending')
|
||
->count(),
|
||
// 同步失败:沿用平台订单列表口径(meta.subscription_activation_error.message 存在即失败)
|
||
'platform_orders_sync_failed' => PlatformOrder::query()
|
||
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NOT NULL")
|
||
->count(),
|
||
|
||
// 站点治理
|
||
'active_merchants' => Merchant::query()->where('status', 'active')->count(),
|
||
'pending_orders' => Order::query()->where('status', 'pending')->count(),
|
||
]
|
||
);
|
||
|
||
$recentPlatformOrders = PlatformOrder::query()
|
||
->orderByDesc('id')
|
||
->limit(5)
|
||
->get();
|
||
|
||
return view('admin.dashboard', [
|
||
'adminName' => $admin->name,
|
||
'stats' => $stats,
|
||
'recentPlatformOrders' => $recentPlatformOrders,
|
||
'platformAdmin' => $admin,
|
||
'cacheMeta' => [
|
||
'store' => config('cache.default'),
|
||
'ttl' => '10m',
|
||
],
|
||
'platformOverview' => [
|
||
'system_role' => '总台管理',
|
||
'current_scope' => '总台运营方视角',
|
||
'merchant_mode' => '统一管理多个站点',
|
||
'channel_count' => 5,
|
||
'active_merchants' => $stats['active_merchants'],
|
||
'pending_orders' => $stats['pending_orders'],
|
||
],
|
||
]);
|
||
}
|
||
}
|