mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 09:39:10 +08:00
update: server/getServerLog to stat/getTrafficLog
This commit is contained in:
parent
d0cab99ae4
commit
98b12205f7
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\ServerLog;
|
||||
|
||||
class ResetServerLog extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'reset:serverLog';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '节点服务器日志重置';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
ServerLog::truncate();
|
||||
}
|
||||
}
|
@ -35,7 +35,6 @@ class Kernel extends ConsoleKernel
|
||||
$schedule->command('check:ticket')->everyMinute();
|
||||
// reset
|
||||
$schedule->command('reset:traffic')->daily();
|
||||
$schedule->command('reset:serverLog')->quarterly()->at('0:15');
|
||||
// send
|
||||
$schedule->command('send:remindMail')->dailyAt('11:30');
|
||||
// horizon metrics
|
||||
|
@ -30,22 +30,4 @@ class ServerController extends Controller
|
||||
'data' => $servers
|
||||
]);
|
||||
}
|
||||
|
||||
public function getServerLogs(Request $request)
|
||||
{
|
||||
$serverLogModel = ServerLog::select([
|
||||
DB::raw('sum(u) as u'),
|
||||
DB::raw('sum(d) as d'),
|
||||
'log_at',
|
||||
'user_id',
|
||||
'rate'
|
||||
])
|
||||
->where('user_id', $request->session()->get('id'))
|
||||
->where('log_at', '>=', strtotime(date('Y-m-1')))
|
||||
->groupBy('log_at', 'user_id', 'rate')
|
||||
->orderBy('log_at', 'DESC');
|
||||
return response([
|
||||
'data' => $serverLogModel->get()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
29
app/Http/Controllers/User/StatController.php
Normal file
29
app/Http/Controllers/User/StatController.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\StatUser;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StatController extends Controller
|
||||
{
|
||||
public function getTrafficLog(Request $request)
|
||||
{
|
||||
$builder = StatUser::select([
|
||||
DB::raw('sum(u) as u'),
|
||||
DB::raw('sum(d) as d'),
|
||||
'record_at',
|
||||
'user_id',
|
||||
'server_rate'
|
||||
])
|
||||
->where('user_id', $request->session()->get('id'))
|
||||
->where('record_at', '>=', strtotime(date('Y-m-1')))
|
||||
->groupBy('record_at', 'user_id', 'server_rate')
|
||||
->orderBy('record_at', 'DESC');
|
||||
return response([
|
||||
'data' => $builder->get()
|
||||
]);
|
||||
}
|
||||
}
|
@ -10,11 +10,9 @@ use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use App\Models\Plan;
|
||||
use App\Models\ServerV2ray;
|
||||
use App\Models\Ticket;
|
||||
use App\Utils\Helper;
|
||||
use App\Models\Order;
|
||||
use App\Models\ServerLog;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class UserController extends Controller
|
||||
|
@ -48,7 +48,6 @@ class UserRoute
|
||||
$router->post('/ticket/withdraw', 'User\\TicketController@withdraw');
|
||||
// Server
|
||||
$router->get ('/server/fetch', 'User\\ServerController@fetch');
|
||||
$router->get ('/server/getServerLogs', 'User\\ServerController@getServerLogs');
|
||||
// Coupon
|
||||
$router->post('/coupon/check', 'User\\CouponController@check');
|
||||
// Telegram
|
||||
@ -59,6 +58,8 @@ class UserRoute
|
||||
// Knowledge
|
||||
$router->get ('/knowledge/fetch', 'User\\KnowledgeController@fetch');
|
||||
$router->get ('/knowledge/getCategory', 'User\\KnowledgeController@getCategory');
|
||||
// Stat
|
||||
$router->get ('/stat/getTrafficLog', 'User\\StatController@getTrafficLog');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Services\ServerService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ServerLogJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
protected $u;
|
||||
protected $d;
|
||||
protected $userId;
|
||||
protected $server;
|
||||
protected $protocol;
|
||||
|
||||
public $tries = 3;
|
||||
public $timeout = 3;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($u, $d, $userId, $server, $protocol)
|
||||
{
|
||||
$this->onQueue('server_log');
|
||||
$this->u = $u;
|
||||
$this->d = $d;
|
||||
$this->userId = $userId;
|
||||
$this->server = $server;
|
||||
$this->protocol = $protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$serverService = new ServerService();
|
||||
if (!$serverService->log(
|
||||
$this->userId,
|
||||
$this->server->id,
|
||||
$this->u,
|
||||
$this->d,
|
||||
$this->server->rate,
|
||||
$this->protocol
|
||||
)) {
|
||||
throw new \Exception('日志记录失败');
|
||||
}
|
||||
}
|
||||
}
|
@ -87,7 +87,6 @@ class UserService
|
||||
public function trafficFetch(int $u, int $d, int $userId, object $server, string $protocol)
|
||||
{
|
||||
TrafficFetchJob::dispatch($u, $d, $userId, $server, $protocol);
|
||||
ServerLogJob::dispatch($u, $d, $userId, $server, $protocol);
|
||||
StatServerJob::dispatch($u, $d, $server, $protocol, 'd');
|
||||
StatUserJob::dispatch($u, $d, $userId, $server, $protocol, 'd');
|
||||
}
|
||||
|
@ -176,7 +176,6 @@ return [
|
||||
'order_handle',
|
||||
'traffic_fetch',
|
||||
'stat',
|
||||
'server_log',
|
||||
'send_email',
|
||||
'send_email_mass',
|
||||
'send_telegram',
|
||||
|
@ -188,25 +188,6 @@ CREATE TABLE `v2_server_group` (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `v2_server_log`;
|
||||
CREATE TABLE `v2_server_log` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int(11) NOT NULL,
|
||||
`server_id` int(11) NOT NULL,
|
||||
`u` varchar(255) NOT NULL,
|
||||
`d` varchar(255) NOT NULL,
|
||||
`rate` decimal(10,2) NOT NULL,
|
||||
`method` varchar(255) NOT NULL,
|
||||
`log_at` int(11) NOT NULL,
|
||||
`created_at` int(11) NOT NULL,
|
||||
`updated_at` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `log_at` (`log_at`),
|
||||
KEY `user_id` (`user_id`),
|
||||
KEY `server_id` (`server_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `v2_server_shadowsocks`;
|
||||
CREATE TABLE `v2_server_shadowsocks` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
@ -393,4 +374,4 @@ CREATE TABLE `v2_user` (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
-- 2022-02-25 09:10:24
|
||||
-- 2022-03-04 16:25:43
|
||||
|
Loading…
Reference in New Issue
Block a user