移除渠道管理
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()) {
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\channel;
|
||||
|
||||
use Throwable;
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 渠道管理
|
||||
*/
|
||||
class Manage extends Backend
|
||||
{
|
||||
/**
|
||||
* ChannelManage模型对象
|
||||
* @var object|null
|
||||
* @phpstan-var \app\common\model\ChannelManage|null
|
||||
*/
|
||||
protected ?object $model = null;
|
||||
|
||||
protected array|string $preExcludeFields = ['id', 'create_time', 'update_time', 'secret'];
|
||||
|
||||
protected array $withJoinTable = ['admin'];
|
||||
|
||||
protected string|array $quickSearchField = ['id'];
|
||||
|
||||
protected bool $autoFillAdminId = true;
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new \app\common\model\ChannelManage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function index(\Webman\Http\Request $request): \support\Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
if ($request->get('select') || $request->post('select')) {
|
||||
return $this->select($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. withJoin 不可使用 alias 方法设置表别名,别名将自动使用关联模型名称(小写下划线命名规则)
|
||||
* 2. 以下的别名设置了主表别名,同时便于拼接查询参数等
|
||||
* 3. paginate 数据集可使用链式操作 each(function($item, $key) {}) 遍历处理
|
||||
*/
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$res = $this->model
|
||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||
->visible(['admin' => ['username']])
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
->paginate($limit);
|
||||
|
||||
return $this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
'remark' => get_route_remark(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 白名单(页面按钮规则,用于菜单规则中配置按钮权限)
|
||||
* 实际编辑通过 edit 接口提交 ip_white 字段
|
||||
*/
|
||||
public function whitelist(\Webman\Http\Request $request): \support\Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 渠道下拉选择(供 remoteSelect 使用)
|
||||
*/
|
||||
public function select(\Webman\Http\Request $request): \support\Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$res = $this->model
|
||||
->field('id,name,title')
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
->paginate($limit);
|
||||
return $this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* add、edit、del、sortable 已由父类 Backend 实现,无需重写即可直接使用
|
||||
* 若需重写,请确保调用 initializeBackend($request) 并传入 Request 参数
|
||||
* 若模型有 admin_id 字段需自动填充,可设置 protected bool $autoFillAdminId = true
|
||||
*/
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class AdminInfo extends Backend
|
||||
{
|
||||
protected ?object $model = null;
|
||||
|
||||
protected array|string $preExcludeFields = ['username', 'last_login_time', 'password', 'salt', 'status'];
|
||||
protected array|string $preExcludeFields = ['username', 'last_login_time', 'password', 'salt', 'status', 'channel_id', 'agent_id', 'agent_api_secret'];
|
||||
protected array $authAllowFields = ['id', 'username', 'nickname', 'avatar', 'email', 'mobile', 'motto', 'last_login_time'];
|
||||
|
||||
protected function initController(Request $request): ?Response
|
||||
|
||||
Reference in New Issue
Block a user