管理员新增渠道channel_id和代理angent_id
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'];
|
||||
protected array|string $preExcludeFields = ['create_time', 'update_time', 'password', 'salt', 'login_failure', 'last_login_time', 'last_login_ip', 'agent_id'];
|
||||
|
||||
protected array|string $quickSearchField = ['username', 'nickname'];
|
||||
|
||||
@@ -25,6 +25,8 @@ class Admin extends Backend
|
||||
|
||||
protected string $dataLimitField = 'id';
|
||||
|
||||
protected array $withJoinTable = ['channel'];
|
||||
|
||||
protected function initController(Request $request): ?Response
|
||||
{
|
||||
$this->model = new AdminModel();
|
||||
@@ -44,7 +46,8 @@ class Admin extends Backend
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$res = $this->model
|
||||
->withoutField('login_failure,password,salt')
|
||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||
->withJoin($this->withJoinTable, $this->withJoinType ?? 'LEFT')
|
||||
->visible(['channel' => ['name']])
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
@@ -78,9 +81,13 @@ 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) {
|
||||
@@ -88,6 +95,14 @@ 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;
|
||||
@@ -98,6 +113,10 @@ class Admin extends Backend
|
||||
$this->model->startTrans();
|
||||
try {
|
||||
$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]);
|
||||
}
|
||||
if (!empty($data['group_arr'])) {
|
||||
$groupAccess = [];
|
||||
foreach ($data['group_arr'] as $datum) {
|
||||
|
||||
@@ -43,8 +43,7 @@ class Manage extends Backend
|
||||
}
|
||||
|
||||
if ($request->get('select') || $request->post('select')) {
|
||||
$this->_select();
|
||||
return $this->success();
|
||||
return $this->select($request);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,6 +80,28 @@ class Manage extends Backend
|
||||
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 参数
|
||||
|
||||
@@ -2,4 +2,6 @@
|
||||
return [
|
||||
'Group Name Arr' => 'Administrator Grouping ',
|
||||
'Please use another administrator account to disable the current account!' => 'Disable the current account, please use another administrator account!',
|
||||
'Please select channel' => 'Please select channel',
|
||||
'Current admin has no channel bound' => 'Current admin has no channel bound',
|
||||
];
|
||||
@@ -3,4 +3,6 @@ return [
|
||||
'Group Name Arr' => '管理员分组',
|
||||
'Please use another administrator account to disable the current account!' => '请使用另外的管理员账户禁用当前账户!',
|
||||
'You have no permission to add an administrator to this group!' => '您没有权限向此分组添加管理员!',
|
||||
'Please select channel' => '请选择渠道',
|
||||
'Current admin has no channel bound' => '当前管理员未绑定渠道',
|
||||
];
|
||||
@@ -21,6 +21,8 @@ use support\think\Db;
|
||||
* @property string $password 密码密文
|
||||
* @property string $salt 密码盐
|
||||
* @property string $status 状态:enable=启用,disable=禁用
|
||||
* @property string $agent_id 代理ID(关联渠道)
|
||||
* @property int $channel_id 渠道ID
|
||||
*/
|
||||
class Admin extends Model
|
||||
{
|
||||
@@ -64,4 +66,12 @@ class Admin extends Model
|
||||
{
|
||||
return $this->where(['id' => $uid])->update(['password' => hash_password($newPassword), 'salt' => '']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联渠道
|
||||
*/
|
||||
public function channel(): \think\model\relation\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\app\common\model\ChannelManage::class, 'channel_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user