1.优化/admin/auth/admin中上级代理下拉框选项
This commit is contained in:
@@ -34,9 +34,31 @@ class Admin extends Backend
|
||||
|
||||
protected string $dataLimitField = 'id';
|
||||
|
||||
protected Tree $tree;
|
||||
|
||||
protected array $initValue = [];
|
||||
|
||||
protected string $keyword = '';
|
||||
|
||||
protected bool $assembleTree = false;
|
||||
|
||||
protected function initController(Request $request): ?Response
|
||||
{
|
||||
$this->model = new AdminModel();
|
||||
$this->tree = Tree::instance();
|
||||
|
||||
$isTree = $request->get('isTree') ?? $request->post('isTree') ?? false;
|
||||
$initValue = $request->get('initValue') ?? $request->post('initValue') ?? [];
|
||||
if (is_array($initValue)) {
|
||||
$this->initValue = array_filter($initValue);
|
||||
} elseif ($initValue !== null && $initValue !== '') {
|
||||
$this->initValue = array_filter(explode(',', (string) $initValue));
|
||||
} else {
|
||||
$this->initValue = [];
|
||||
}
|
||||
$this->keyword = (string) ($request->get('quickSearch') ?? $request->post('quickSearch') ?? '');
|
||||
$this->assembleTree = ($isTree === true || $isTree === '1' || $isTree === 1) && $this->initValue === [];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -596,7 +618,50 @@ class Admin extends Backend
|
||||
|
||||
public function select(Request $request): Response
|
||||
{
|
||||
return parent::select($request);
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$rows = $this->getAdminsForSelect($request);
|
||||
if ($this->assembleTree) {
|
||||
$treeData = $this->tree->assembleChild($rows, 'pid', 'id');
|
||||
$rows = $this->tree->assembleTree($this->tree->getTreeArray($treeData, 'username'));
|
||||
}
|
||||
|
||||
return $this->success('', [
|
||||
'options' => $rows,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
private function getAdminsForSelect(Request $request): array
|
||||
{
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$adminAlias = $alias[strtolower($this->model->getTable())] ?? 'admin';
|
||||
|
||||
$query = $this->model
|
||||
->withoutField('login_failure,password,salt')
|
||||
->alias($alias)
|
||||
->where($where);
|
||||
|
||||
$visibleIds = AdminCommissionDistributionService::getVisibleAdminIdsForOperator(
|
||||
intval($this->auth->id),
|
||||
$this->auth->isSuperAdmin()
|
||||
);
|
||||
if ($visibleIds !== []) {
|
||||
$query->where($adminAlias . '.id', 'in', $visibleIds);
|
||||
}
|
||||
|
||||
$rows = $query->order($order)->select()->toArray();
|
||||
foreach ($rows as $k => $row) {
|
||||
$parentId = intval($row['parent_admin_id'] ?? 0);
|
||||
$rows[$k]['pid'] = $parentId > 0 ? $parentId : 0;
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
private function checkGroupAuth(array $groups): ?Response
|
||||
|
||||
Reference in New Issue
Block a user