套餐管理:修复 summaryStats sum(subscriptions_count) 未知列错误
This commit is contained in:
@@ -5,6 +5,8 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Controllers\Concerns\ResolvesPlatformAdminContext;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Plan;
|
||||
use App\Models\PlatformOrder;
|
||||
use App\Models\SiteSubscription;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -112,8 +114,24 @@ class PlanController extends Controller
|
||||
'published_plans' => (clone $plansQuery)->whereNotNull('published_at')->count(),
|
||||
'unpublished_plans' => (clone $plansQuery)->whereNull('published_at')->count(),
|
||||
// 治理联动:当前筛选范围内关联订阅/订单总量
|
||||
'subscriptions_count' => (clone $plansQuery)->sum('subscriptions_count'),
|
||||
'platform_orders_count' => (clone $plansQuery)->sum('platform_orders_count'),
|
||||
// 注意:subscriptions_count/platform_orders_count 是 withCount() 的别名列,不能直接 sum('subscriptions_count'),
|
||||
// 否则 MySQL 会报 Unknown column。
|
||||
'subscriptions_count' => (function () use ($plansQuery) {
|
||||
$planIds = (clone $plansQuery)->pluck('id')->all();
|
||||
if (count($planIds) === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) SiteSubscription::query()->whereIn('plan_id', $planIds)->count();
|
||||
})(),
|
||||
'platform_orders_count' => (function () use ($plansQuery) {
|
||||
$planIds = (clone $plansQuery)->pluck('id')->all();
|
||||
if (count($planIds) === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) PlatformOrder::query()->whereIn('plan_id', $planIds)->count();
|
||||
})(),
|
||||
],
|
||||
'statusLabels' => $this->statusLabels(),
|
||||
'billingCycleLabels' => $this->billingCycleLabels(),
|
||||
|
||||
Reference in New Issue
Block a user