v2board/app/Console/Commands/V2boardStatistics.php

73 lines
1.5 KiB
PHP
Raw Normal View History

2020-12-20 16:57:33 +08:00
<?php
namespace App\Console\Commands;
use App\Jobs\StatServerJob;
use Illuminate\Console\Command;
use App\Models\ServerLog;
use Illuminate\Support\Facades\DB;
2020-12-20 21:06:23 +08:00
class V2BoardStatistics extends Command
2020-12-20 16:57:33 +08:00
{
/**
* The name and signature of the console command.
*
* @var string
*/
2020-12-20 21:06:23 +08:00
protected $signature = 'v2board:statistics';
2020-12-20 16:57:33 +08:00
/**
* The console command description.
*
* @var string
*/
2020-12-20 21:06:23 +08:00
protected $description = '统计任务';
2020-12-20 16:57:33 +08:00
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
2020-12-20 21:06:23 +08:00
{
$this->statServer();
}
2020-12-21 17:11:48 +08:00
private function statOrder()
{
}
2020-12-20 21:06:23 +08:00
private function statServer()
2020-12-20 16:57:33 +08:00
{
$endAt = strtotime(date('Y-m-d'));
$startAt = strtotime('-1 day', $endAt);
$statistics = ServerLog::select([
2020-12-20 21:06:23 +08:00
'server_id',
'method as server_type',
DB::raw("sum(u) as u"),
DB::raw("sum(d) as d"),
])
2020-12-20 16:57:33 +08:00
->where('log_at', '>=', $startAt)
->where('log_at', '<', $endAt)
->groupBy('server_id', 'method')
->get()
->toArray();
foreach ($statistics as $statistic) {
$statistic['record_type'] = 'm';
$statistic['record_at'] = $startAt;
StatServerJob::dispatch($statistic);
}
}
}