@extends('layouts.member') @section('title', 'لوحة تحكم العضو') @section('page-title', 'لوحة التحكم الرئيسية') @section('content') {{-- ============================================================================ 🏛️ لوحة تحكم العضو — جيش الوفاء الذهبي (نسخة ملحمية موحّدة) ✅ تصميم موحّد (ذهب + ليل) ✅ حلّ التعارضات: رسالة القائد (مرة واحدة) + سكربتات داخل @push ✅ رمضان: لوحات المنافسة (فقط #9/#10) + قابل للطي + عضو/ضيف + اليوم/الإجمالي + بطل الأمس 👑 ✅ بدون "use" في أي مكان ============================================================================ --}} @php $tz = config('app.timezone', 'Asia/Jerusalem'); $now = \Carbon\Carbon::now($tz); $today = $now->toDateString(); $yesterday = $now->copy()->subDay()->toDateString(); // جداول رمضان $scoreTable = 'ramadan_competition_score_events'; $seasonTable = 'ramadan_seasons'; $linksTable = 'ramadan_competition_links'; $competitionsTable = 'competitions'; $visitorsTable = 'ramadan_visitors'; $usersTable = 'users'; // موسم فعّال $seasonId = null; if (\Illuminate\Support\Facades\Schema::hasTable($seasonTable)) { $seasonId = \Illuminate\Support\Facades\DB::table($seasonTable) ->where('is_active', 1) ->orderByDesc('id') ->value('id'); } $scoreOk = \Illuminate\Support\Facades\Schema::hasTable($scoreTable); // مفتاح موحّد للمشارك (عضو/ضيف) $pkey = function ($type, $uid, $vid) { $type = ($type === 'visitor') ? 'visitor' : 'user'; return $type === 'visitor' ? ('v:' . (int)$vid) : ('u:' . (int)$uid); }; // اسم العضو $userName = function ($u) { if (!$u) return 'عضو'; $name = trim((string)($u->name ?? '')); if ($name !== '') return $name; $un = trim((string)($u->username ?? '')); if ($un !== '') return '@' . $un; $email = trim((string)($u->email ?? '')); if ($email !== '') return $email; $id = (int)($u->id ?? 0); return $id > 0 ? ('User#' . $id) : 'عضو'; }; // اسم الضيف $visitorName = function ($v) { if (!$v) return 'ضيف'; $name = trim((string)($v->name ?? '')); if ($name !== '') return $name; $id = (int)($v->id ?? 0); return $id > 0 ? ('Visitor#' . $id) : 'ضيف'; }; $epicBoards = collect(); $epicError = null; // ====================================================================== // ✅ Ramadan Epic Boards (Only #9/#10) // ====================================================================== if (!$seasonId) { $epicError = 'لا يوجد موسم رمضان فعّال حالياً.'; } elseif (!\Illuminate\Support\Facades\Schema::hasTable($linksTable) || !\Illuminate\Support\Facades\Schema::hasTable($competitionsTable)) { $epicError = 'جداول ربط مسابقات رمضان غير موجودة.'; } elseif (!$scoreOk) { $epicError = 'جدول نقاط رمضان غير موجود: ' . $scoreTable; } else { $comps = \Illuminate\Support\Facades\DB::table($linksTable.' as l') ->join($competitionsTable.' as c', 'c.id', '=', 'l.competition_id') ->where('l.season_id', $seasonId) ->whereIn('c.id', [9, 10]) // ✅ فقط 9 أو 10 ->select('c.id','c.title','c.status') ->orderByDesc('c.id') ->get(); $compIds = []; foreach ($comps as $c) { $compIds[] = (int)$c->id; } if (empty($compIds)) { $epicError = 'لا توجد مسابقات مرتبطة برمضان (9 أو 10).'; } else { // تجميع اليوم + الإجمالي $agg = \Illuminate\Support\Facades\DB::table($scoreTable) ->where('season_id', $seasonId) ->whereIn('competition_id', $compIds) ->select('competition_id','participant_type','user_id','visitor_id') ->selectRaw('SUM(points) as total_points') ->selectRaw('SUM(CASE WHEN event_date = ? THEN points ELSE 0 END) as today_points', [$today]) ->groupBy('competition_id','participant_type','user_id','visitor_id') ->get(); // تجميع الأمس لتحديد بطل الأمس 👑 $yAgg = \Illuminate\Support\Facades\DB::table($scoreTable) ->where('season_id', $seasonId) ->whereIn('competition_id', $compIds) ->where('event_date', $yesterday) ->select('competition_id','participant_type','user_id','visitor_id') ->selectRaw('SUM(points) as pts') ->groupBy('competition_id','participant_type','user_id','visitor_id') ->get(); // أعلى نقاط بالأمس لكل مسابقة $yMaxByComp = []; foreach ($yAgg as $r) { $cid = (int)$r->competition_id; $pts = (int)($r->pts ?? 0); if (!isset($yMaxByComp[$cid]) || $pts > $yMaxByComp[$cid]) $yMaxByComp[$cid] = $pts; } // مفاتيح الأبطال (قد يكون أكثر من بطل لو تعادل) $yChampKeys = []; foreach ($yAgg as $r) { $cid = (int)$r->competition_id; $pts = (int)($r->pts ?? 0); $max = (int)($yMaxByComp[$cid] ?? 0); if ($max <= 0) continue; if ($pts === $max) { $key = $pkey((string)($r->participant_type ?? 'user'), (int)($r->user_id ?? 0), (int)($r->visitor_id ?? 0)); if (!isset($yChampKeys[$cid])) $yChampKeys[$cid] = []; $yChampKeys[$cid][$key] = true; } } // جمع IDs لجلب الأسماء $userIds = []; $visitorIds = []; foreach ($agg as $r) { $type = (string)($r->participant_type ?? 'user'); if ($type === 'visitor') { $vid = (int)($r->visitor_id ?? 0); if ($vid > 0) $visitorIds[$vid] = true; } else { $uid = (int)($r->user_id ?? 0); if ($uid > 0) $userIds[$uid] = true; } } $usersMap = collect(); if (!empty($userIds) && \Illuminate\Support\Facades\Schema::hasTable($usersTable)) { $usersMap = \Illuminate\Support\Facades\DB::table($usersTable) ->whereIn('id', array_keys($userIds)) ->select('id','name','username','email','avatar') ->get() ->keyBy('id'); } $visitorsMap = collect(); if (!empty($visitorIds) && \Illuminate\Support\Facades\Schema::hasTable($visitorsTable)) { $visitorsMap = \Illuminate\Support\Facades\DB::table($visitorsTable) ->whereIn('id', array_keys($visitorIds)) ->select('id','name') ->get() ->keyBy('id'); } // ترتيب حسب المسابقة $byComp = []; foreach ($agg as $r) { $cid = (int)$r->competition_id; $type = (string)($r->participant_type ?? 'user'); $uid = (int)($r->user_id ?? 0); $vid = (int)($r->visitor_id ?? 0); $key = $pkey($type, $uid, $vid); $name = ($type === 'visitor') ? $visitorName($visitorsMap->get($vid)) : $userName($usersMap->get($uid)); $todayPts = (int)($r->today_points ?? 0); $totalPts = (int)($r->total_points ?? 0); $isChamp = isset($yChampKeys[$cid]) && isset($yChampKeys[$cid][$key]); if (!isset($byComp[$cid])) $byComp[$cid] = []; $byComp[$cid][] = [ 'name' => $name, 'type_label' => ($type === 'visitor') ? 'ضيف' : 'عضو', 'today_points' => $todayPts, 'total_points' => $totalPts, 'is_yesterday_champion' => $isChamp, ]; } $out = []; foreach ($comps as $c) { $cid = (int)$c->id; $list = $byComp[$cid] ?? []; usort($list, function ($a, $b) { if ((int)$a['today_points'] === (int)$b['today_points']) { if ((int)$a['total_points'] === (int)$b['total_points']) { return strcmp((string)$a['name'], (string)$b['name']); } return ((int)$b['total_points'] <=> (int)$a['total_points']); } return ((int)$b['today_points'] <=> (int)$a['today_points']); }); $sumToday = 0; $sumTotal = 0; foreach ($list as $p) { $sumToday += (int)$p['today_points']; $sumTotal += (int)$p['total_points']; } $out[] = [ 'competition' => $c, 'totals' => [ 'participants' => count($list), 'today_points' => $sumToday, 'total_points' => $sumTotal, ], 'participants' => $list, ]; } $epicBoards = collect($out); } } // بيانات عامة احتياطية لتفادي undefined $statsTotalPoints = (int)($stats['total_points'] ?? 0); $statsPointsThisMonth = (int)($stats['points_this_month'] ?? 0); $statsEvaluationsCount = (int)($stats['evaluations_count'] ?? 0); $statsEvalsThisMonth = (int)($stats['evaluations_this_month'] ?? 0); $statsUpcomingLives = (int)($stats['upcoming_lives'] ?? 0); $statsActivities = (int)($stats['activities_participated'] ?? 0); $statsViolationsCount = (int)($stats['violations_count'] ?? 0); $statsActiveViolations = (int)($stats['active_violations'] ?? 0); $statsEarned = (int)($stats['points_earned'] ?? 0); $statsDeducted = (int)($stats['points_deducted'] ?? 0); $evalApproved = (int)($evaluationStats['approved'] ?? 0); $evalPending = (int)($evaluationStats['pending'] ?? 0); $evalRejected = (int)($evaluationStats['rejected'] ?? 0); $attPresent = (int)($attendanceStats['present'] ?? 0); $attExcuse = (int)($attendanceStats['absent_with_excuse'] ?? 0); $attAbsent = (int)($attendanceStats['absent_without_excuse'] ?? 0); $ptsEarned = (int)($pointsStats['earned'] ?? 0); $ptsDeducted = (int)($pointsStats['deducted'] ?? 0); $me = auth()->user(); @endphp
{{-- ========================================================================= 🏆 Hero Header — ذهبي ملحمي ========================================================================= --}}
{{-- Avatar --}}
صورة العضو
{{-- Text --}}
جيش الوفاء الذهبي {{ $me->membership_status ? ('رتبتك — ' . $me->membership_status) : 'رتبتك' }}

مرحباً {{ $me->name ?? 'عضو' }}

{{ $now->copy()->locale('ar')->isoFormat('dddd D MMMM YYYY') }}
آخر تسجيل دخول: {{ $me->last_activity ? \Carbon\Carbon::parse($me->last_activity, $tz)->diffForHumans() : 'لأول مرة' }}

رؤيتنا: تعزيز الأداء، رفع جودة الالتزام، وضمان تنظيم مثالي داخل جيش الوفاء الذهبي.

{{-- Quick Chips --}}
إجمالي النقاط
{{ $statsTotalPoints }}
نقاط هذا الشهر
{{ $statsPointsThisMonth }}
التقييمات
{{ $statsEvaluationsCount }}
لايفات قادمة
{{ $statsUpcomingLives }}
{{-- ========================================================================= 📜 رسالة القائد (مرة واحدة فقط — بدون تكرار) ========================================================================= --}} @if(isset($message) && $message)

📜 {{ $message->title }}

{!! nl2br(e($message->body)) !!}

قيادة جيش الوفاء الذهبي
آخر تحديث: {{ $message->updated_at ? $message->updated_at->diffForHumans() : '—' }}
@endif {{-- ========================================================================= 🏆 قسم ملحمي — مسابقات رمضان #9/#10 ========================================================================= --}}
قسم ملحمي: المشاركون في مسابقات رمضان ونقاطهم
اضغط على اسم المسابقة لعرض المشاركين
يعرض: نوع المشارك (عضو/ضيف) + نقاط اليوم + النقاط الكلية.
👑 بطل الأمس يظهر تحت الاسم مباشرة.
اليوم: {{ $today }} الأمس: {{ $yesterday }} فقط: #9 / #10
@if($epicError)
تنبيه
{{ $epicError }}
@else
@foreach($epicBoards as $b) @php $c = $b['competition']; $t = $b['totals']; $participants = $b['participants']; @endphp
#{{ (int)$c->id }} — {{ $c->title ?? 'مسابقة رمضان' }}
الحالة: {{ $c->status ?? '—' }} مشاركون: {{ (int)($t['participants'] ?? 0) }}
مشاركون
{{ (int)($t['participants'] ?? 0) }}
نقاط اليوم
{{ (int)($t['today_points'] ?? 0) }}
المجموع
{{ (int)($t['total_points'] ?? 0) }}
@if(empty($participants))
لا يوجد مشاركون/نقاط لهذه المسابقة بعد.
@else
@foreach($participants as $p) @endforeach
المشارك النوع نقاط اليوم النقاط الكلية
{{ $p['name'] }}
{{-- 👑 بطل الأمس تحت الاسم --}} @if(!empty($p['is_yesterday_champion']))
بطل الأمس
@endif
@if(($p['type_label'] ?? '') === 'ضيف') ضيف @else عضو @endif {{ (int)($p['today_points'] ?? 0) }} {{ (int)($p['total_points'] ?? 0) }}
*ملاحظة: الترتيب حسب نقاط اليوم ثم النقاط الكلية.
@endif
@endforeach
@endif
{{-- ========================================================================= 🎯 الهدف + التعتير + رسائل الإدارة (ستايل موحّد) ========================================================================= --}}
{{-- هدف الشهر --}}
@if(isset($personalGoal)) @php $badgeCls = match(true){ ($personalGoal['status'] ?? '')==='ممتاز' => 'bg-emerald-500/15 border-emerald-400/30 text-emerald-200', ($personalGoal['status'] ?? '')==='جيد' => 'bg-sky-500/15 border-sky-400/30 text-sky-200', ($personalGoal['status'] ?? '')==='متوسط' => 'bg-amber-500/15 border-amber-400/30 text-amber-200', default => 'bg-rose-500/15 border-rose-400/30 text-rose-200', }; @endphp
🎯 هدفي هذا الشهر
50س (لايف + قست) • 5س سهرة
{{ $personalGoal['status'] ?? '—' }}
لايف + قست
{{ (int)($personalGoal['pct_mix'] ?? 0) }}%
{{ (int)($personalGoal['live'] ?? 0) }}س لايف • {{ (int)($personalGoal['guest'] ?? 0) }}س قست
سهرة
{{ (int)($personalGoal['pct_sahra'] ?? 0) }}%
{{ (int)($personalGoal['sahra'] ?? 0) }}س سهرة
{{ $personalGoal['ai_text'] ?? '' }}
@endif
{{-- التعتير + رسائل الإدارة --}}
{{-- بطاقة التعتير --}}
@if(isset($taateer) && $taateer) @php $issuedAt = \Carbon\Carbon::parse($taateer->issued_at, $tz)->locale('ar'); $expiresAt = \Carbon\Carbon::parse($taateer->expires_at, $tz)->locale('ar'); @endphp

رقم التعتير الخاص بك

مفعل حالياً

هذا الرقم هو مفتاح دخولك الرسمي للنظام ووسيلة التحقق من عضويتك داخل جيش الوفاء الذهبي. الرجاء عدم مشاركته مع أي شخص.

رقم التعتير
{{ $taateer->code }}
تاريخ الإنشاء
{{ $issuedAt->isoFormat('D MMMM YYYY – h:mm A') }}
تاريخ انتهاء الصلاحية
{{ $expiresAt->isoFormat('D MMMM YYYY – h:mm A') }}
عند انتهاء الصلاحية لن تتمكن من الدخول حتى يتم إصدار رقم جديد بواسطة الصقر.
@else
🚨 لا يوجد رقم تعتير فعّال لحسابك حالياً. الرجاء التواصل مع مدير نظام التعتير — الصقر.
@endif
{{-- رسائل الإدارة --}}
📣 رسائل الإدارة
{{-- ========================================================================= 🧪 معدل الاختبارات للعضو ========================================================================= --}} @if(isset($testGauge))

معدل التزامك بالاختبارات

يوضّح مستوى مشاركتك ونجاحك في اختبارات نظام الوفاء الذهبي.

@php $p = max(0, min(100, (int)($testGauge->success_rate ?? 0))); @endphp
معدل الاختبارات {{ $p }}% ناجح في {{ (int)($testGauge->passed_tests ?? 0) }}/{{ (int)($testGauge->total_tests ?? 0) }} اختبار

مستوى التزامك بالاختبارات

هذا المعدّل يمثّل نسبة الاختبارات التي نجحت فيها من كل الاختبارات التي شاركت بها. كل ما ارتفع المعدّل، زادت فرصتك بالحصول على هدايا وتحفيزات خاصة من القائد سيف الوفاء والصقر.

@php $totalTests = (int)($testGauge->total_tests ?? 0); @endphp @if($totalTests === 0)

لم تشارك بأي اختبار بعد. أول ما تبدأ تحل الاختبارات، رح يظهر معدل التزامك هنا.

@elseif($p < 60)

معدلّك حالياً منخفض شوي… شدّ حيلك بالاختبارات الجاية 💪

@elseif($p >= 60 && $p < 85)

أداء جيّد 👏 كم اختبار زيادة وبتصير من النخبة.

@else

مستوى أسطوري 🔥 انت من نخبة الملتزمين.

@endif
@endif {{-- ========================================================================= 📊 شبكة الإحصائيات (ستايل موحّد) ========================================================================= --}}

إجمالي النقاط

{{ $statsTotalPoints }}

نقاط هذا الشهر

{{ $statsPointsThisMonth }}

التقييمات

{{ $statsEvaluationsCount }}

{{ $statsEvalsThisMonth }} هذا الشهر

لايفات قادمة

{{ $statsUpcomingLives }}

الأنشطة المشاركة

{{ $statsActivities }}

المخالفات

{{ $statsViolationsCount }}

{{ $statsActiveViolations }} نشطة

نقاط مكتسبة

{{ $statsEarned }}

نقاط مخصومة

{{ $statsDeducted }}

{{-- ========================================================================= 📈 الرسوم (ApexCharts) ========================================================================= --}}

حالة التقييمات

موافق {{ $evalApproved }}
معلق {{ $evalPending }}
مرفوض {{ $evalRejected }}

سجل الحضور

حاضر {{ $attPresent }}
عذر {{ $attExcuse }}
غائب {{ $attAbsent }}

توزيع النقاط

مكتسبة {{ $ptsEarned }}
مخصومة {{ $ptsDeducted }}
{{-- ========================================================================= 🏅 المتصدرون ========================================================================= --}} @if(isset($topMembers) && $topMembers->count() > 0)

المتصدرون - قارن نفسك معهم

@foreach($topMembers as $index => $member)
{{ $member->name }} @if(method_exists($member, 'isOnline') && $member->isOnline())
@endif {{ $index + 1 }}

{{ $member->name }}

{{ (int)($member->total_points ?? 0) }}

@endforeach
@endif {{-- ========================================================================= 🧾 آخر النقاط + اللايفات القادمة ========================================================================= --}}
{{-- آخر النقاط --}}

آخر النقاط

@if(isset($recent_points) && $recent_points->count() > 0) @foreach($recent_points as $point)
@if(((int)$point->points) > 0) @else @endif

{{ $point->description }}

{{ $point->created_at ? $point->created_at->diffForHumans() : '' }} @if(isset($point->awardedBy) && $point->awardedBy) • بواسطة {{ $point->awardedBy->name }} @endif

{{ ((int)$point->points) > 0 ? '+' : '' }}{{ (int)$point->points }}
@endforeach @else

لا توجد نقاط بعد

@endif
{{-- اللايفات القادمة --}}

اللايفات القادمة

@if(isset($upcoming_lives) && $upcoming_lives->count() > 0) @foreach($upcoming_lives as $live)

{{ $live->title }}

@if($live->description)

{{ \Illuminate\Support\Str::limit($live->description, 80) }}

@endif
{{ \Carbon\Carbon::parse($live->scheduled_date, $tz)->locale('ar')->isoFormat('D MMMM YYYY') }}
قريباً
@endforeach @else

لا توجد لايفات مجدولة

@endif
{{-- ========================================================================= 🧠 آخر التقييمات ========================================================================= --}} @if(isset($recent_evaluations) && $recent_evaluations->count() > 0)

آخر التقييمات

@foreach($recent_evaluations as $eval)
{{ \Carbon\Carbon::parse($eval->evaluation_date, $tz)->format('Y-m-d') }}
@php $st = (string)($eval->status ?? 'pending'); @endphp @if($st === 'approved') موافق @elseif($st === 'pending') معلق @else مرفوض @endif

{{ $eval->evaluator->name ?? 'غير محدد' }}

المقيّم

الحضور: @php $att = (string)($eval->attendance_status ?? 'present'); @endphp @if($att === 'present') حاضر @elseif($att === 'absent_with_excuse') عذر @else غائب @endif

تم التقييم {{ $eval->created_at ? $eval->created_at->diffForHumans() : '' }}

@endforeach
@endif
@push('scripts') {{-- ======================================================================== 🔐 Encrypted Access Token (LocalStorage) ======================================================================== --}} {{-- ======================================================================== 📣 Admin Messages Feed ======================================================================== --}} {{-- ======================================================================== 📊 ApexCharts ======================================================================== --}} @once @endonce @endpush @endsection