30c2f655e7
统一将节点编辑和批量修改的 group_ids、route_ids 序列化为字符串 ID,避免保存权限组后订阅侧无法命中节点 后端新增 whereGroupId 兼容历史字符串与数字 JSON 值, 并补齐 TUIC 版本、ALPN 选项及 AnyTLS 默认 Padding 配置 docs: 新增 HelloAGENTS 通用与工作流避坑指南
67 lines
1.9 KiB
PHP
67 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\V2\Admin\Server;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Plan;
|
|
use App\Models\Server;
|
|
use App\Models\ServerGroup;
|
|
use App\Models\User;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class GroupController extends Controller
|
|
{
|
|
public function fetch(Request $request): JsonResponse
|
|
{
|
|
$serverGroups = ServerGroup::query()
|
|
->orderByDesc('id')
|
|
->withCount('users')
|
|
->get();
|
|
|
|
// 只在需要时手动加载server_count
|
|
$serverGroups->each(function ($group) {
|
|
$group->setAttribute('server_count', $group->server_count);
|
|
});
|
|
|
|
return $this->success($serverGroups);
|
|
}
|
|
|
|
public function save(Request $request)
|
|
{
|
|
if (empty($request->input('name'))) {
|
|
return $this->fail([422, '组名不能为空']);
|
|
}
|
|
|
|
if ($request->input('id')) {
|
|
$serverGroup = ServerGroup::find($request->input('id'));
|
|
} else {
|
|
$serverGroup = new ServerGroup();
|
|
}
|
|
|
|
$serverGroup->name = $request->input('name');
|
|
return $this->success($serverGroup->save());
|
|
}
|
|
|
|
public function drop(Request $request)
|
|
{
|
|
$groupId = $request->input('id');
|
|
|
|
$serverGroup = ServerGroup::find($groupId);
|
|
if (!$serverGroup) {
|
|
return $this->fail([400202, '组不存在']);
|
|
}
|
|
if (Server::whereGroupId($groupId)->exists()) {
|
|
return $this->fail([400, '该组已被节点所使用,无法删除']);
|
|
}
|
|
|
|
if (Plan::where('group_id', $groupId)->exists()) {
|
|
return $this->fail([400, '该组已被订阅所使用,无法删除']);
|
|
}
|
|
if (User::where('group_id', $groupId)->exists()) {
|
|
return $this->fail([400, '该组已被用户所使用,无法删除']);
|
|
}
|
|
return $this->success($serverGroup->delete());
|
|
}
|
|
}
|