This commit is contained in:
root 2019-12-23 15:26:08 +08:00
parent 1e0712fce1
commit ae738c1c48
5 changed files with 47 additions and 2 deletions

View File

@ -10,6 +10,7 @@ use App\Models\ServerGroup;
use App\Models\Server; use App\Models\Server;
use App\Models\Plan; use App\Models\Plan;
use App\Models\User; use App\Models\User;
use Illuminate\Support\Facades\Redis;
class ServerController extends Controller class ServerController extends Controller
{ {
@ -20,6 +21,7 @@ class ServerController extends Controller
$server[$i]['tags'] = json_decode($server[$i]['tags']); $server[$i]['tags'] = json_decode($server[$i]['tags']);
} }
$server[$i]['group_id'] = json_decode($server[$i]['group_id']); $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([ return response([
'data' => $server 'data' => $server

View File

@ -9,6 +9,7 @@ use App\Models\Plan;
use App\Models\Server; use App\Models\Server;
use App\Models\ServerLog; use App\Models\ServerLog;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
class DeepbworkController extends Controller class DeepbworkController extends Controller
{ {
@ -20,8 +21,7 @@ class DeepbworkController extends Controller
if (!$server) { if (!$server) {
abort(500, 'fail'); abort(500, 'fail');
} }
$server->last_check_at = time(); Redis::set('server_last_check_at_' . $server->id, time());
$server->save();
$users = User::whereIn('group_id', json_decode($server->group_id)) $users = User::whereIn('group_id', json_decode($server->group_id))
->select([ ->select([
'id', 'id',

View File

@ -3,9 +3,13 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Server; use App\Models\Server;
use App\Models\ServerLog; use App\Models\ServerLog;
use App\Models\User;
use App\Utils\Helper;
class ServerController extends Controller { class ServerController extends Controller {
public function getTrafficLog (Request $request) { public function getTrafficLog (Request $request) {
@ -34,4 +38,27 @@ class ServerController extends Controller {
'sum' => $sum '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
]);
}
} }

View File

@ -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) { public function subscribe (Request $request) {
$user = User::find($request->session()->get('id')); $user = User::find($request->session()->get('id'));

View File

@ -67,6 +67,7 @@ Route::prefix('v1')
Route::get ('info', 'UserController@info'); Route::get ('info', 'UserController@info');
Route::post('changePassword', 'UserController@changePassword'); Route::post('changePassword', 'UserController@changePassword');
Route::post('update', 'UserController@update'); Route::post('update', 'UserController@update');
Route::get ('getSubscribe', 'UserController@getSubscribe');
// Order // Order
Route::get ('order', 'OrderController@index'); Route::get ('order', 'OrderController@index');
Route::post('order/save', 'OrderController@save'); Route::post('order/save', 'OrderController@save');
@ -92,6 +93,7 @@ Route::prefix('v1')
Route::post('ticket/close', 'TicketController@close'); Route::post('ticket/close', 'TicketController@close');
// Server // Server
Route::get ('server/getTrafficLog', 'ServerController@getTrafficLog'); Route::get ('server/getTrafficLog', 'ServerController@getTrafficLog');
Route::get ('server/getServers', 'ServerController@getServers');
}); });
// Passport // Passport