V2boardStatistics.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Jobs\StatServerJob;
  4. use Illuminate\Console\Command;
  5. use App\Models\ServerLog;
  6. use Illuminate\Support\Facades\DB;
  7. class V2BoardStatistics extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'v2board:statistics';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '统计任务';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. $this->statServer();
  38. }
  39. private function statOrder()
  40. {
  41. }
  42. private function statServer()
  43. {
  44. $endAt = strtotime(date('Y-m-d'));
  45. $startAt = strtotime('-1 day', $endAt);
  46. $statistics = ServerLog::select([
  47. 'server_id',
  48. 'method as server_type',
  49. DB::raw("sum(u) as u"),
  50. DB::raw("sum(d) as d"),
  51. ])
  52. ->where('log_at', '>=', $startAt)
  53. ->where('log_at', '<', $endAt)
  54. ->groupBy('server_id', 'method')
  55. ->get()
  56. ->toArray();
  57. foreach ($statistics as $statistic) {
  58. $statistic['record_type'] = 'm';
  59. $statistic['record_at'] = $startAt;
  60. StatServerJob::dispatch($statistic);
  61. }
  62. }
  63. }