Updated dashboard

This commit is contained in:
m.razaghi
2026-08-09 16:53:42 +03:30
parent bd4789a85c
commit 47dfbba165
2 changed files with 18 additions and 4 deletions

View File

@@ -25,16 +25,30 @@ class DashboardController extends Controller
->distinct('user_id') ->distinct('user_id')
->count('user_id'); ->count('user_id');
// 3. Get Paid Subscribers & Breakdown by Plan Type // 3. Get Paid Subscribers & Breakdown by Plan Type AND Market Provider
$paidBreakdown = UserSubscriber::where('user_subscribers.expired_at', '>=', now()) $paidBreakdown = UserSubscriber::where('user_subscribers.expired_at', '>=', now())
->whereHas('subscribe', function (Builder $query) { ->whereHas('subscribe', function (Builder $query) {
$query->where('is_free', false); $query->where('is_free', false);
}) })
->join('subscribe_plans', 'user_subscribers.subscribe_plan_id', '=', 'subscribe_plans.id') ->join('subscribe_plans', 'user_subscribers.subscribe_plan_id', '=', 'subscribe_plans.id')
->selectRaw('subscribe_plans.name as plan_name, count(DISTINCT user_subscribers.user_id) as total') ->selectRaw('subscribe_plans.name as plan_name, user_subscribers.market_provider, count(DISTINCT user_subscribers.user_id) as total')
->groupBy('subscribe_plans.name') ->groupBy('subscribe_plans.name', 'user_subscribers.market_provider')
->get(); ->get();
// Format the display name to show the source clearly
$paidBreakdown->each(function ($item) {
$provider = strtolower($item->market_provider ?? '');
if ($provider === 'bazaar') {
$item->display_name = $item->plan_name . ' (کافه بازار)';
} elseif ($provider === 'myket') {
$item->display_name = $item->plan_name . ' (مایکت)';
} else {
// If market_provider is null or empty, it was purchased directly from the site
$item->display_name = $item->plan_name . ' (سایت / مستقیم)';
}
});
// Total paid is the sum of the breakdown // Total paid is the sum of the breakdown
$paidSubscribers = $paidBreakdown->sum('total'); $paidSubscribers = $paidBreakdown->sum('total');

View File

@@ -31,7 +31,7 @@
<div> <div>
@foreach($paidBreakdown as $plan) @foreach($paidBreakdown as $plan)
<span class="badge bg-light text-success font-size-12 me-1 mb-1 shadow-sm"> <span class="badge bg-light text-success font-size-12 me-1 mb-1 shadow-sm">
{{ $plan->plan_name }}: {{ $plan->total }} {{ $plan->display_name }}: {{ $plan->total }}
</span> </span>
@endforeach @endforeach
</div> </div>