diff --git a/app/Http/Controllers/Admin/ServerController.php b/app/Http/Controllers/Admin/ServerController.php index 56b9a5a3..e5bb5a5d 100755 --- a/app/Http/Controllers/Admin/ServerController.php +++ b/app/Http/Controllers/Admin/ServerController.php @@ -10,6 +10,7 @@ use App\Models\ServerGroup; use App\Models\Server; use App\Models\Plan; use App\Models\User; +use Illuminate\Support\Facades\Redis; class ServerController extends Controller { @@ -20,6 +21,7 @@ class ServerController extends Controller $server[$i]['tags'] = json_decode($server[$i]['tags']); } $server[$i]['group_id'] = json_decode($server[$i]['group_id']); + $server[$i]['last_check_at'] = Redis::get('server_last_check_at_' . $server[$i]['id']); } return response([ 'data' => $server diff --git a/app/Http/Controllers/Server/DeepbworkController.php b/app/Http/Controllers/Server/DeepbworkController.php index 177724b7..a26cef82 100644 --- a/app/Http/Controllers/Server/DeepbworkController.php +++ b/app/Http/Controllers/Server/DeepbworkController.php @@ -9,6 +9,7 @@ use App\Models\Plan; use App\Models\Server; use App\Models\ServerLog; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Redis; class DeepbworkController extends Controller { @@ -20,8 +21,7 @@ class DeepbworkController extends Controller if (!$server) { abort(500, 'fail'); } - $server->last_check_at = time(); - $server->save(); + Redis::set('server_last_check_at_' . $server->id, time()); $users = User::whereIn('group_id', json_decode($server->group_id)) ->select([ 'id', diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index 81b3651b..f4c70de9 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -3,9 +3,13 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Redis; use App\Http\Controllers\Controller; use App\Models\Server; use App\Models\ServerLog; +use App\Models\User; + +use App\Utils\Helper; class ServerController extends Controller { public function getTrafficLog (Request $request) { @@ -34,4 +38,27 @@ class ServerController extends Controller { 'sum' => $sum ]); } + + public function getServers (Request $request) { + $user = User::find($request->session()->get('id')); + $server = []; + if ($user->expired_at > time()) { + $servers = Server::where('show', 1) + ->orderBy('name') + ->get(); + foreach ($servers as $item) { + $groupId = json_decode($item['group_id']); + if (in_array($user->group_id, $groupId)) { + array_push($server, $item); + } + } + } + for ($i = 0; $i < count($server); $i++) { + $server[$i]['link'] = Helper::buildVmessLink($server[$i], $user); + $server[$i]['last_check_at'] = Redis::get('server_last_check_at' . $server[$i]['id']); + } + return response([ + 'data' => $server + ]); + } } \ No newline at end of file diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index e28c9de4..d555c000 100755 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -86,6 +86,20 @@ class UserController extends Controller ] ]); } + + public function getSubscribe (Request $request) { + $user = User::find($request->session()->get('id')); + $server = []; + if ($user->plan_id) { + $user['plan'] = Plan::find($user->plan_id); + if (!$user['plan']) { + abort(500, '订阅计划不存在'); + } + } + return response([ + 'data' => $user + ]); + } public function subscribe (Request $request) { $user = User::find($request->session()->get('id')); diff --git a/routes/api.php b/routes/api.php index 1609b101..71416d1d 100755 --- a/routes/api.php +++ b/routes/api.php @@ -67,6 +67,7 @@ Route::prefix('v1') Route::get ('info', 'UserController@info'); Route::post('changePassword', 'UserController@changePassword'); Route::post('update', 'UserController@update'); + Route::get ('getSubscribe', 'UserController@getSubscribe'); // Order Route::get ('order', 'OrderController@index'); Route::post('order/save', 'OrderController@save'); @@ -92,6 +93,7 @@ Route::prefix('v1') Route::post('ticket/close', 'TicketController@close'); // Server Route::get ('server/getTrafficLog', 'ServerController@getTrafficLog'); + Route::get ('server/getServers', 'ServerController@getServers'); }); // Passport