mirror of
https://github.com/v2board/v2board.git
synced 2025-04-25 02:52:36 +08:00
update: stat command
This commit is contained in:
parent
948177f22e
commit
32eaf301fe
@ -4,12 +4,9 @@ namespace App\Console\Commands;
|
|||||||
|
|
||||||
use App\Models\StatServer;
|
use App\Models\StatServer;
|
||||||
use App\Models\StatUser;
|
use App\Models\StatUser;
|
||||||
use App\Models\User;
|
|
||||||
use App\Services\StatisticalService;
|
use App\Services\StatisticalService;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use App\Models\Order;
|
|
||||||
use App\Models\Stat;
|
use App\Models\Stat;
|
||||||
use App\Models\CommissionLog;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class V2boardStatistics extends Command
|
class V2boardStatistics extends Command
|
||||||
@ -50,19 +47,19 @@ class V2boardStatistics extends Command
|
|||||||
$this->statUser();
|
$this->statUser();
|
||||||
$this->statServer();
|
$this->statServer();
|
||||||
$this->stat();
|
$this->stat();
|
||||||
$this->info('耗时' . (microtime(true) - $startAt));
|
info('统计任务执行完毕。耗时:' . (microtime(true) - $startAt) / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function statServer()
|
private function statServer()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
$createdAt = time();
|
$createdAt = time();
|
||||||
$recordAt = strtotime('-1 day', strtotime(date('Y-m-d')));
|
$recordAt = strtotime('-1 day', strtotime(date('Y-m-d')));
|
||||||
$statService = new StatisticalService();
|
$statService = new StatisticalService();
|
||||||
$statService->setStartAt($recordAt);
|
$statService->setStartAt($recordAt);
|
||||||
$statService->setServerStats();
|
$statService->setServerStats();
|
||||||
$stats = $statService->getStatServer();
|
$stats = $statService->getStatServer();
|
||||||
try {
|
|
||||||
DB::beginTransaction();
|
|
||||||
foreach ($stats as $stat) {
|
foreach ($stats as $stat) {
|
||||||
if (!StatServer::insert([
|
if (!StatServer::insert([
|
||||||
'server_id' => $stat['server_id'],
|
'server_id' => $stat['server_id'],
|
||||||
@ -81,20 +78,20 @@ class V2boardStatistics extends Command
|
|||||||
$statService->clearStatServer();
|
$statService->clearStatServer();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
DB::rollback();
|
DB::rollback();
|
||||||
$this->error($e->getMessage());
|
\Log::error($e->getMessage(), ['exception' => $e]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function statUser()
|
private function statUser()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
$createdAt = time();
|
$createdAt = time();
|
||||||
$recordAt = strtotime('-1 day', strtotime(date('Y-m-d')));
|
$recordAt = strtotime('-1 day', strtotime(date('Y-m-d')));
|
||||||
$statService = new StatisticalService();
|
$statService = new StatisticalService();
|
||||||
$statService->setStartAt($recordAt);
|
$statService->setStartAt($recordAt);
|
||||||
$statService->setUserStats();
|
$statService->setUserStats();
|
||||||
$stats = $statService->getStatUser();
|
$stats = $statService->getStatUser();
|
||||||
try {
|
|
||||||
DB::beginTransaction();
|
|
||||||
foreach ($stats as $stat) {
|
foreach ($stats as $stat) {
|
||||||
if (!StatUser::insert([
|
if (!StatUser::insert([
|
||||||
'user_id' => $stat['user_id'],
|
'user_id' => $stat['user_id'],
|
||||||
@ -113,12 +110,13 @@ class V2boardStatistics extends Command
|
|||||||
$statService->clearStatUser();
|
$statService->clearStatUser();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
DB::rollback();
|
DB::rollback();
|
||||||
$this->error($e->getMessage());
|
\Log::error($e->getMessage(), ['exception' => $e]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function stat()
|
private function stat()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$endAt = strtotime(date('Y-m-d'));
|
$endAt = strtotime(date('Y-m-d'));
|
||||||
$startAt = strtotime('-1 day', $endAt);
|
$startAt = strtotime('-1 day', $endAt);
|
||||||
$statisticalService = new StatisticalService();
|
$statisticalService = new StatisticalService();
|
||||||
@ -135,5 +133,8 @@ class V2boardStatistics extends Command
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Stat::create($data);
|
Stat::create($data);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
\Log::error($e->getMessage(), ['exception' => $e]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user