游戏-用户管理-优化表格和表单样式
This commit is contained in:
@@ -32,6 +32,91 @@ class Channel extends Backend
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 渠道-管理员树(父级=渠道,子级=管理员,仅可选择子级)
|
||||
*/
|
||||
public function adminTree(WebmanRequest $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) return $response;
|
||||
|
||||
$channels = Db::name('game_channel')
|
||||
->field(['id', 'name', 'admin_group_id'])
|
||||
->order('id', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$groupChildrenCache = [];
|
||||
$getGroupChildren = function ($groupId) use (&$getGroupChildren, &$groupChildrenCache) {
|
||||
if ($groupId === null || $groupId === '') return [];
|
||||
if (array_key_exists($groupId, $groupChildrenCache)) return $groupChildrenCache[$groupId];
|
||||
$children = Db::name('admin_group')
|
||||
->where('pid', $groupId)
|
||||
->where('status', 1)
|
||||
->column('id');
|
||||
$all = [];
|
||||
foreach ($children as $cid) {
|
||||
$all[] = $cid;
|
||||
foreach ($getGroupChildren($cid) as $cc) {
|
||||
$all[] = $cc;
|
||||
}
|
||||
}
|
||||
$groupChildrenCache[$groupId] = $all;
|
||||
return $all;
|
||||
};
|
||||
|
||||
$tree = [];
|
||||
foreach ($channels as $ch) {
|
||||
$groupId = $ch['admin_group_id'] ?? null;
|
||||
$groupIds = [];
|
||||
if ($groupId !== null && $groupId !== '') {
|
||||
$groupIds[] = $groupId;
|
||||
foreach ($getGroupChildren($groupId) as $gid) {
|
||||
$groupIds[] = $gid;
|
||||
}
|
||||
}
|
||||
|
||||
$adminIds = [];
|
||||
if ($groupIds) {
|
||||
$adminIds = Db::name('admin_group_access')
|
||||
->where('group_id', 'in', array_unique($groupIds))
|
||||
->column('uid');
|
||||
}
|
||||
$adminIds = array_values(array_unique($adminIds));
|
||||
|
||||
$admins = [];
|
||||
if ($adminIds) {
|
||||
$admins = Db::name('admin')
|
||||
->field(['id', 'username'])
|
||||
->where('id', 'in', $adminIds)
|
||||
->order('id', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
$children = [];
|
||||
foreach ($admins as $a) {
|
||||
$children[] = [
|
||||
'value' => (string) $a['id'],
|
||||
'label' => $a['username'],
|
||||
'channel_id' => $ch['id'],
|
||||
'is_leaf' => true,
|
||||
];
|
||||
}
|
||||
|
||||
$tree[] = [
|
||||
'value' => 'channel_' . $ch['id'],
|
||||
'label' => $ch['name'],
|
||||
'disabled' => true,
|
||||
'children' => $children,
|
||||
];
|
||||
}
|
||||
|
||||
return $this->success('', [
|
||||
'list' => $tree,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加(重写:管理员只选顶级组;admin_group_id 后端自动写入)
|
||||
* @throws Throwable
|
||||
|
||||
Reference in New Issue
Block a user