2020-11-14 17:26:17 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin\Server;
|
|
|
|
|
2021-09-21 18:07:53 +08:00
|
|
|
use App\Models\ServerV2ray;
|
2020-11-14 17:26:17 +08:00
|
|
|
use App\Models\ServerShadowsocks;
|
|
|
|
use App\Models\ServerTrojan;
|
|
|
|
use App\Services\ServerService;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
class ManageController extends Controller
|
|
|
|
{
|
|
|
|
public function getNodes(Request $request)
|
|
|
|
{
|
|
|
|
$serverService = new ServerService();
|
|
|
|
return response([
|
2021-06-08 19:07:10 +08:00
|
|
|
'data' => $serverService->getAllServers()
|
2020-11-14 17:26:17 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function sort(Request $request)
|
|
|
|
{
|
2021-12-28 01:49:33 +08:00
|
|
|
ini_set('post_max_size', '1m');
|
2020-11-14 17:26:17 +08:00
|
|
|
DB::beginTransaction();
|
|
|
|
foreach ($request->input('sorts') as $k => $v) {
|
|
|
|
switch ($v['key']) {
|
|
|
|
case 'shadowsocks':
|
|
|
|
if (!ServerShadowsocks::find($v['value'])->update(['sort' => $k + 1])) {
|
|
|
|
DB::rollBack();
|
|
|
|
abort(500, '保存失败');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'v2ray':
|
2021-09-21 18:07:53 +08:00
|
|
|
if (!ServerV2ray::find($v['value'])->update(['sort' => $k + 1])) {
|
2020-11-14 17:26:17 +08:00
|
|
|
DB::rollBack();
|
|
|
|
abort(500, '保存失败');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'trojan':
|
|
|
|
if (!ServerTrojan::find($v['value'])->update(['sort' => $k + 1])) {
|
|
|
|
DB::rollBack();
|
|
|
|
abort(500, '保存失败');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DB::commit();
|
|
|
|
return response([
|
|
|
|
'data' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|