AdminGroupsController.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Models\Group;
  4. use App\Models\GroupCategory;
  5. use App\Models\GroupInteraction;
  6. use App\Models\GroupMember;
  7. use App\Models\GroupPost;
  8. use App\Models\GroupReport;
  9. use Cache;
  10. use Illuminate\Http\Request;
  11. trait AdminGroupsController
  12. {
  13. public function groupsHome(Request $request)
  14. {
  15. $stats = $this->groupAdminStats();
  16. return view('admin.groups.home', compact('stats'));
  17. }
  18. protected function groupAdminStats()
  19. {
  20. return Cache::remember('admin:groups:stats', 3, function () {
  21. $res = [
  22. 'total' => Group::count(),
  23. 'local' => Group::whereLocal(true)->count(),
  24. ];
  25. $res['remote'] = $res['total'] - $res['local'];
  26. $res['categories'] = GroupCategory::count();
  27. $res['posts'] = GroupPost::count();
  28. $res['members'] = GroupMember::count();
  29. $res['interactions'] = GroupInteraction::count();
  30. $res['reports'] = GroupReport::count();
  31. $res['local_30d'] = Cache::remember('admin:groups:stats:local_30d', 43200, function () {
  32. return Group::whereLocal(true)->where('created_at', '>', now()->subMonth())->count();
  33. });
  34. $res['remote_30d'] = Cache::remember('admin:groups:stats:remote_30d', 43200, function () {
  35. return Group::whereLocal(false)->where('created_at', '>', now()->subMonth())->count();
  36. });
  37. return $res;
  38. });
  39. }
  40. }