Xboard/app/Http/Controllers/V1/Admin/Server/ManageController.php

47 lines
1.2 KiB
PHP
Raw Normal View History

2023-11-17 01:44:01 -05:00
<?php
namespace App\Http\Controllers\V1\Admin\Server;
2023-12-04 07:40:49 -05:00
use App\Exceptions\ApiException;
2023-11-17 01:44:01 -05:00
use App\Http\Controllers\Controller;
use App\Services\ServerService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class ManageController extends Controller
{
public function getNodes(Request $request)
{
$serverService = new ServerService();
return $this->success($serverService->getAllServers());
2023-11-17 01:44:01 -05:00
}
public function sort(Request $request)
{
ini_set('post_max_size', '1m');
$params = $request->only(
'shadowsocks',
'vmess',
'trojan',
'hysteria',
'vless'
) ?? [];
try{
DB::beginTransaction();
foreach ($params as $k => $v) {
$model = 'App\\Models\\Server' . ucfirst($k);
foreach($v as $id => $sort) {
$model::where('id', $id)->update(['sort' => $sort]);
2023-11-17 01:44:01 -05:00
}
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
\Log::error($e);
return $this->fail([500,'保存失败']);
2023-11-17 01:44:01 -05:00
}
return $this->success(true);
2023-11-17 01:44:01 -05:00
}
}