OverViewController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Egg;
  5. use App\Models\Location;
  6. use App\Models\Nest;
  7. use App\Models\Node;
  8. use App\Models\Payment;
  9. use App\Models\Server;
  10. use App\Models\User;
  11. use Illuminate\Support\Facades\Cache;
  12. class OverViewController extends Controller
  13. {
  14. public const TTL = 86400;
  15. public function index()
  16. {
  17. $userCount = Cache::remember('user:count', self::TTL, function () {
  18. return User::query()->count();
  19. });
  20. $creditCount = Cache::remember('credit:count', self::TTL, function () {
  21. return User::query()->sum('credits');
  22. });
  23. $paymentCount = Cache::remember('payment:count', self::TTL, function () {
  24. return Payment::query()->count();
  25. });
  26. $serverCount = Cache::remember('server:count', self::TTL, function () {
  27. return Server::query()->count();
  28. });
  29. $lastEgg = Egg::query()->latest('updated_at')->first();
  30. $syncLastUpdate = $lastEgg ? $lastEgg->updated_at->isoFormat('LLL') : __('unknown');
  31. return view('admin.overview.index', [
  32. 'serverCount' => $serverCount,
  33. 'userCount' => $userCount,
  34. 'paymentCount' => $paymentCount,
  35. 'creditCount' => number_format($creditCount, 2, '.', ''),
  36. 'locationCount' => Location::query()->count(),
  37. 'nodeCount' => Node::query()->count(),
  38. 'nestCount' => Nest::query()->count(),
  39. 'eggCount' => Egg::query()->count(),
  40. 'syncLastUpdate' => $syncLastUpdate
  41. ]);
  42. }
  43. /**
  44. * @description Sync locations,nodes,nests,eggs with the linked pterodactyl panel
  45. */
  46. public function syncPterodactyl()
  47. {
  48. Node::syncNodes();
  49. Egg::syncEggs();
  50. return redirect()->back()->with('success', __('Pterodactyl synced'));
  51. }
  52. }