2019-12-22 23:59:27 +08:00
|
|
|
<?php
|
|
|
|
|
2020-01-29 16:08:50 +08:00
|
|
|
namespace App\Http\Controllers\User;
|
2019-12-22 23:59:27 +08:00
|
|
|
|
2020-01-29 16:08:50 +08:00
|
|
|
use App\Http\Controllers\Controller;
|
2020-06-12 00:18:35 +08:00
|
|
|
use App\Services\ServerService;
|
2020-02-28 01:12:55 +08:00
|
|
|
use App\Services\UserService;
|
2020-06-05 13:25:32 +08:00
|
|
|
use App\Utils\CacheKey;
|
2019-12-22 23:59:27 +08:00
|
|
|
use Illuminate\Http\Request;
|
2020-01-12 01:27:36 +08:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2021-09-21 18:07:53 +08:00
|
|
|
use App\Models\ServerV2ray;
|
2019-12-22 23:59:27 +08:00
|
|
|
use App\Models\ServerLog;
|
2019-12-23 15:26:08 +08:00
|
|
|
use App\Models\User;
|
|
|
|
|
|
|
|
use App\Utils\Helper;
|
2022-01-04 13:40:35 +08:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2019-12-22 23:59:27 +08:00
|
|
|
|
2020-01-11 13:36:52 +08:00
|
|
|
class ServerController extends Controller
|
|
|
|
{
|
|
|
|
public function fetch(Request $request)
|
|
|
|
{
|
2019-12-23 15:38:50 +08:00
|
|
|
$user = User::find($request->session()->get('id'));
|
2020-06-12 00:18:35 +08:00
|
|
|
$servers = [];
|
2020-02-28 17:16:05 +08:00
|
|
|
$userService = new UserService();
|
|
|
|
if ($userService->isAvailable($user)) {
|
2020-06-12 00:18:35 +08:00
|
|
|
$serverService = new ServerService();
|
2020-11-14 17:26:17 +08:00
|
|
|
$servers = $serverService->getAvailableServers($user);
|
2019-12-23 15:38:50 +08:00
|
|
|
}
|
|
|
|
return response([
|
2020-06-12 00:18:35 +08:00
|
|
|
'data' => $servers
|
2019-12-23 15:38:50 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-01-11 13:36:52 +08:00
|
|
|
public function logFetch(Request $request)
|
|
|
|
{
|
|
|
|
$type = $request->input('type') ? $request->input('type') : 0;
|
2019-12-23 01:06:15 +08:00
|
|
|
$current = $request->input('current') ? $request->input('current') : 1;
|
|
|
|
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
|
2022-01-04 13:40:35 +08:00
|
|
|
$serverLogModel = ServerLog::select([
|
|
|
|
DB::raw('sum(u) as u'),
|
|
|
|
DB::raw('sum(d) as d'),
|
|
|
|
'log_at',
|
|
|
|
'user_id',
|
|
|
|
'updated_at'
|
|
|
|
])
|
|
|
|
->where('user_id', $request->session()->get('id'))
|
|
|
|
->groupBy('log_at', 'user_id')
|
2021-08-01 22:56:11 +08:00
|
|
|
->orderBy('log_at', 'DESC');
|
2020-01-11 13:36:52 +08:00
|
|
|
switch ($type) {
|
|
|
|
case 0:
|
2021-08-01 22:56:11 +08:00
|
|
|
$serverLogModel->where('log_at', '>=', strtotime(date('Y-m-d')));
|
2020-01-11 13:36:52 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2021-08-01 22:56:11 +08:00
|
|
|
$serverLogModel->where('log_at', '>=', strtotime(date('Y-m-d')) - 604800);
|
2020-01-11 13:36:52 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2021-08-01 22:56:11 +08:00
|
|
|
$serverLogModel->where('log_at', '>=', strtotime(date('Y-m-1')));
|
2020-01-11 13:36:52 +08:00
|
|
|
}
|
2019-12-23 01:06:15 +08:00
|
|
|
$total = $serverLogModel->count();
|
|
|
|
$res = $serverLogModel->forPage($current, $pageSize)
|
|
|
|
->get();
|
|
|
|
return response([
|
|
|
|
'data' => $res,
|
2020-04-26 19:19:31 +08:00
|
|
|
'total' => $total
|
2019-12-23 01:06:15 +08:00
|
|
|
]);
|
2019-12-22 23:59:27 +08:00
|
|
|
}
|
2020-01-11 13:36:52 +08:00
|
|
|
}
|