v2board/app/Http/Controllers/Admin/Server/ManageController.php

62 lines
1.9 KiB
PHP
Raw Normal View History

2020-11-14 17:26:17 +08:00
<?php
namespace App\Http\Controllers\Admin\Server;
2023-03-08 02:28:00 +08:00
use App\Models\ServerHysteria;
2023-02-15 14:53:13 +08:00
use App\Models\ServerVmess;
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();
2023-01-30 20:12:01 +08:00
foreach ($request->input('sorts') ?? [] as $k => $v) {
2020-11-14 17:26:17 +08:00
switch ($v['key']) {
case 'shadowsocks':
2023-01-30 20:12:01 +08:00
if (!ServerShadowsocks::find($v['value'])->update(['sort' => $v['sort']])) {
2020-11-14 17:26:17 +08:00
DB::rollBack();
abort(500, '保存失败');
}
break;
2023-02-15 14:53:13 +08:00
case 'vmess':
if (!ServerVmess::find($v['value'])->update(['sort' => $v['sort']])) {
2020-11-14 17:26:17 +08:00
DB::rollBack();
abort(500, '保存失败');
}
break;
case 'trojan':
2023-01-30 20:12:01 +08:00
if (!ServerTrojan::find($v['value'])->update(['sort' => $v['sort']])) {
2020-11-14 17:26:17 +08:00
DB::rollBack();
abort(500, '保存失败');
}
break;
2023-03-08 02:28:00 +08:00
case 'hysteria':
if (!ServerHysteria::find($v['value'])->update(['sort' => $v['sort']])) {
DB::rollBack();
abort(500, '保存失败');
}
break;
2020-11-14 17:26:17 +08:00
}
}
DB::commit();
return response([
'data' => true
]);
}
}