V2boardCache.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Utils\CacheKey;
  4. use Illuminate\Console\Command;
  5. use App\Models\ServerLog;
  6. use App\Models\ServerStat;
  7. use Illuminate\Support\Facades\Cache;
  8. use Illuminate\Support\Facades\DB;
  9. class V2boardCache extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'v2board:cache';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = '缓存任务';
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return mixed
  36. */
  37. public function handle()
  38. {
  39. }
  40. private function cacheServerStat()
  41. {
  42. $serverLogs = ServerLog::select(
  43. 'server_id',
  44. DB::raw("sum(u) as u"),
  45. DB::raw("sum(d) as d"),
  46. DB::raw("count(*) as online")
  47. )
  48. ->where('updated_at', '>=', time() - 3600)
  49. ->groupBy('server_id')
  50. ->get();
  51. foreach ($serverLogs as $serverLog) {
  52. $data = [
  53. 'server_id' => $serverLog->server_id,
  54. 'u' => $serverLog->u,
  55. 'd' => $serverLog->d,
  56. 'online' => $serverLog->online
  57. ];
  58. // ServerStat::create($data);
  59. }
  60. }
  61. }