移除渠道管理
This commit is contained in:
@@ -17,7 +17,7 @@ class Admin extends Backend
|
||||
{
|
||||
protected ?object $model = null;
|
||||
|
||||
protected array|string $preExcludeFields = ['create_time', 'update_time', 'password', 'salt', 'login_failure', 'last_login_time', 'last_login_ip', 'agent_id'];
|
||||
protected array|string $preExcludeFields = ['create_time', 'update_time', 'password', 'salt', 'login_failure', 'last_login_time', 'last_login_ip', 'agent_id', 'agent_api_secret', 'channel_id'];
|
||||
|
||||
protected array|string $quickSearchField = ['username', 'nickname'];
|
||||
|
||||
@@ -25,8 +25,6 @@ class Admin extends Backend
|
||||
|
||||
protected string $dataLimitField = 'id';
|
||||
|
||||
protected array $withJoinTable = ['channel'];
|
||||
|
||||
protected function initController(Request $request): ?Response
|
||||
{
|
||||
$this->model = new AdminModel();
|
||||
@@ -46,8 +44,7 @@ class Admin extends Backend
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$res = $this->model
|
||||
->withoutField('login_failure,password,salt')
|
||||
->withJoin($this->withJoinTable, $this->withJoinType ?? 'LEFT')
|
||||
->visible(['channel' => ['name']])
|
||||
->withJoin($this->withJoinTable ?? [], $this->withJoinType ?? 'LEFT')
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
@@ -81,13 +78,9 @@ class Admin extends Backend
|
||||
'mobile' => 'regex:/^1[3-9]\d{9}$/|unique:admin,mobile',
|
||||
'group_arr' => 'required|array',
|
||||
];
|
||||
if ($this->auth->isSuperAdmin()) {
|
||||
$rules['channel_id'] = 'required|integer|min:1';
|
||||
}
|
||||
$messages = [
|
||||
'username.regex' => __('Please input correct username'),
|
||||
'password.regex' => __('Please input correct password'),
|
||||
'channel_id.required' => __('Please select channel'),
|
||||
];
|
||||
Validator::make($data, $rules, $messages)->validate();
|
||||
} catch (ValidationException $e) {
|
||||
@@ -95,14 +88,6 @@ class Admin extends Backend
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->auth->isSuperAdmin()) {
|
||||
$currentChannelId = (int) ($this->auth->model->channel_id ?? 0);
|
||||
if ($currentChannelId <= 0) {
|
||||
return $this->error(__('Current admin has no channel bound'));
|
||||
}
|
||||
$data['channel_id'] = $currentChannelId;
|
||||
}
|
||||
|
||||
$passwd = $data['password'] ?? '';
|
||||
$data = $this->excludeFields($data);
|
||||
$result = false;
|
||||
@@ -115,7 +100,12 @@ class Admin extends Backend
|
||||
$result = $this->model->save($data);
|
||||
if ($result !== false) {
|
||||
$agentId = strtolower(md5($this->model->username . $this->model->id));
|
||||
$this->model->where('id', $this->model->id)->update(['agent_id' => $agentId]);
|
||||
$agentSecret = strtoupper(md5($this->model->username . $this->model->id));
|
||||
// 使用原生 SQL,避免 ThinkORM 按当前表结构校验字段时因未迁移缺少 agent_api_secret 列而报错
|
||||
Db::execute(
|
||||
'UPDATE `admin` SET `agent_id` = ?, `agent_api_secret` = ? WHERE `id` = ?',
|
||||
[$agentId, $agentSecret, $this->model->id]
|
||||
);
|
||||
}
|
||||
if (!empty($data['group_arr'])) {
|
||||
$groupAccess = [];
|
||||
@@ -306,6 +296,39 @@ class Admin extends Backend
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉已废弃的渠道字段,避免组合搜索生成对不存在列的条件
|
||||
*/
|
||||
protected function filterSearchArray(array $search): array
|
||||
{
|
||||
return array_values(array_filter($search, static function ($item) {
|
||||
if (!is_array($item) || !isset($item['field'])) {
|
||||
return true;
|
||||
}
|
||||
$f = (string) $item['field'];
|
||||
if ($f === 'channel_id' || str_ends_with($f, '.channel_id')) {
|
||||
return false;
|
||||
}
|
||||
if ($f === 'channel.name' || str_starts_with($f, 'channel.')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
|
||||
public function queryOrderBuilder(): array
|
||||
{
|
||||
$order = parent::queryOrderBuilder();
|
||||
foreach (array_keys($order) as $key) {
|
||||
if ($key === 'channel_id' || (is_string($key) && str_contains($key, 'channel.'))) {
|
||||
unset($order[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
private function checkGroupAuth(array $groups): ?Response
|
||||
{
|
||||
if ($this->auth->isSuperAdmin()) {
|
||||
|
||||
Reference in New Issue
Block a user