@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
رؤيتنا: تعزيز الأداء، رفع جودة الالتزام، وضمان تنظيم مثالي داخل جيش الوفاء الذهبي.
{!! nl2br(e($message->body)) !!}
| المشارك | النوع | نقاط اليوم | النقاط الكلية |
|---|---|---|---|
|
{{ $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) }} |
هذا الرقم هو مفتاح دخولك الرسمي للنظام ووسيلة التحقق من عضويتك داخل جيش الوفاء الذهبي. الرجاء عدم مشاركته مع أي شخص.
يوضّح مستوى مشاركتك ونجاحك في اختبارات نظام الوفاء الذهبي.
هذا المعدّل يمثّل نسبة الاختبارات التي نجحت فيها من كل الاختبارات التي شاركت بها. كل ما ارتفع المعدّل، زادت فرصتك بالحصول على هدايا وتحفيزات خاصة من القائد سيف الوفاء والصقر.
@php $totalTests = (int)($testGauge->total_tests ?? 0); @endphp @if($totalTests === 0)لم تشارك بأي اختبار بعد. أول ما تبدأ تحل الاختبارات، رح يظهر معدل التزامك هنا.
@elseif($p < 60)معدلّك حالياً منخفض شوي… شدّ حيلك بالاختبارات الجاية 💪
@elseif($p >= 60 && $p < 85)أداء جيّد 👏 كم اختبار زيادة وبتصير من النخبة.
@elseمستوى أسطوري 🔥 انت من نخبة الملتزمين.
@endifإجمالي النقاط
نقاط هذا الشهر
التقييمات
{{ $statsEvalsThisMonth }} هذا الشهر
لايفات قادمة
الأنشطة المشاركة
المخالفات
{{ $statsActiveViolations }} نشطة
نقاط مكتسبة
نقاط مخصومة
{{ (int)($member->total_points ?? 0) }}
{{ $point->description }}
{{ $point->created_at ? $point->created_at->diffForHumans() : '' }} @if(isset($point->awardedBy) && $point->awardedBy) • بواسطة {{ $point->awardedBy->name }} @endif
لا توجد نقاط بعد
@endif{{ \Illuminate\Support\Str::limit($live->description, 80) }}
@endifلا توجد لايفات مجدولة
@endif{{ $eval->evaluator->name ?? 'غير محدد' }}
المقيّم
تم التقييم {{ $eval->created_at ? $eval->created_at->diffForHumans() : '' }}