Lae/app/Console/Commands/Count.php

104 lines
3.1 KiB
PHP
Raw Normal View History

2022-10-21 04:24:31 +00:00
<?php
namespace App\Console\Commands;
use App\Models\Host;
use App\Models\Transaction;
2022-11-06 11:28:22 +00:00
use App\Models\User;
2022-10-21 04:24:31 +00:00
use App\Models\WorkOrder\Reply;
use App\Models\WorkOrder\WorkOrder;
2022-11-06 11:28:22 +00:00
use Illuminate\Console\Command;
2022-10-21 04:24:31 +00:00
use Illuminate\Support\Facades\Cache;
class Count extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'count';
/**
* The console command description.
*
* @var string
*/
protected $description = '统计 主机,用户,工单,一年的交易记录,服务器数量。';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
2022-12-11 11:47:30 +00:00
* @return int
2022-10-21 04:24:31 +00:00
*/
2023-01-10 13:42:27 +00:00
public function handle(): int
2022-10-21 04:24:31 +00:00
{
//
2022-10-21 04:35:17 +00:00
$this->info('正在获取用户数量...');
2023-01-10 13:42:27 +00:00
$users = (new User)->count();
// $transactions = new Transaction();
2022-10-21 04:24:31 +00:00
2022-10-21 04:33:54 +00:00
// 获取今年的交易记录 (MongoDB)
$startOfYear = now()->startOfYear();
$endOfYear = now()->endOfYear();
2022-10-21 04:24:31 +00:00
2022-10-21 04:35:17 +00:00
$this->info('正在获取交易记录...');
2023-01-10 13:42:27 +00:00
$transactions = (new Transaction)->where('type', 'payout')->whereBetween('created_at', [$startOfYear, $endOfYear])->count();
2022-10-21 04:24:31 +00:00
2022-10-21 04:35:17 +00:00
$this->info('正在获取主机数量...');
2023-01-10 13:42:27 +00:00
$hosts = (new Host)->count();
2022-11-08 01:43:48 +00:00
$this->info('正在获取部署中的主机数量...');
2023-01-10 13:42:27 +00:00
$pending_hosts = (new Host)->where('status', 'pending')->count();
2022-11-08 01:43:48 +00:00
$this->info('正在获取已停止的主机数量...');
2023-01-10 13:42:27 +00:00
$stopped_hosts = (new Host)->where('status', 'stopped')->count();
2022-11-08 01:43:48 +00:00
$this->info('正在获取部署失败的主机数量...');
2023-01-10 13:42:27 +00:00
$error_hosts = (new Host)->where('status', 'error')->count();
2022-10-21 04:35:17 +00:00
2022-10-29 04:26:34 +00:00
$this->info('正在获取激活的主机数量...');
2023-01-10 13:42:27 +00:00
$active_hosts = (new Host)->where('status', 'running')->count();
2022-10-29 04:26:34 +00:00
$this->info('正在获取暂停的主机数量...');
2023-01-10 13:42:27 +00:00
$suspended_hosts = (new Host)->whereNotNull('suspended_at')->count();
2022-10-29 04:26:34 +00:00
2022-10-21 04:35:17 +00:00
$this->info('正在获取工单数量...');
2023-01-10 13:42:27 +00:00
$workOrders = (new WorkOrder)->count();
2022-10-21 04:35:17 +00:00
$this->info('正在获取工单回复数量...');
2023-01-10 13:42:27 +00:00
$replies = (new Reply)->count();
2022-10-21 04:24:31 +00:00
2022-10-21 04:35:17 +00:00
$this->info('统计服务器...');
2022-10-21 04:24:31 +00:00
$servers = Cache::get('servers', []);
$servers = count($servers);
2022-10-21 04:35:17 +00:00
$this->info('完成。');
2023-02-07 09:03:47 +00:00
$this->warn('用户数量: ' . $users);
$this->warn('主机数量: ' . $hosts);
$this->warn('正在部署的主机数量: ' . $pending_hosts);
$this->warn('已停止的主机数量: ' . $stopped_hosts);
$this->warn('部署失败的主机数量: ' . $error_hosts);
$this->warn('正常的主机数量: ' . $active_hosts);
$this->warn('暂停的主机数量: ' . $suspended_hosts);
$this->warn('服务器数量: ' . $servers);
$this->warn('工单数量: ' . $workOrders);
$this->warn('工单回复数量: ' . $replies);
$this->warn('今年的交易记录: ' . $transactions . ' 条');
2022-10-29 04:26:34 +00:00
return 0;
2022-10-21 04:24:31 +00:00
}
}