管理员新增渠道channel_id和代理angent_id
This commit is contained in:
@@ -17,7 +17,7 @@ class Admin extends Backend
|
|||||||
{
|
{
|
||||||
protected ?object $model = null;
|
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'];
|
protected array|string $quickSearchField = ['username', 'nickname'];
|
||||||
|
|
||||||
@@ -25,6 +25,8 @@ class Admin extends Backend
|
|||||||
|
|
||||||
protected string $dataLimitField = 'id';
|
protected string $dataLimitField = 'id';
|
||||||
|
|
||||||
|
protected array $withJoinTable = ['channel'];
|
||||||
|
|
||||||
protected function initController(Request $request): ?Response
|
protected function initController(Request $request): ?Response
|
||||||
{
|
{
|
||||||
$this->model = new AdminModel();
|
$this->model = new AdminModel();
|
||||||
@@ -44,7 +46,8 @@ class Admin extends Backend
|
|||||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||||
$res = $this->model
|
$res = $this->model
|
||||||
->withoutField('login_failure,password,salt')
|
->withoutField('login_failure,password,salt')
|
||||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
->withJoin($this->withJoinTable, $this->withJoinType ?? 'LEFT')
|
||||||
|
->visible(['channel' => ['name']])
|
||||||
->alias($alias)
|
->alias($alias)
|
||||||
->where($where)
|
->where($where)
|
||||||
->order($order)
|
->order($order)
|
||||||
@@ -78,9 +81,13 @@ class Admin extends Backend
|
|||||||
'mobile' => 'regex:/^1[3-9]\d{9}$/|unique:admin,mobile',
|
'mobile' => 'regex:/^1[3-9]\d{9}$/|unique:admin,mobile',
|
||||||
'group_arr' => 'required|array',
|
'group_arr' => 'required|array',
|
||||||
];
|
];
|
||||||
|
if ($this->auth->isSuperAdmin()) {
|
||||||
|
$rules['channel_id'] = 'required|integer|min:1';
|
||||||
|
}
|
||||||
$messages = [
|
$messages = [
|
||||||
'username.regex' => __('Please input correct username'),
|
'username.regex' => __('Please input correct username'),
|
||||||
'password.regex' => __('Please input correct password'),
|
'password.regex' => __('Please input correct password'),
|
||||||
|
'channel_id.required' => __('Please select channel'),
|
||||||
];
|
];
|
||||||
Validator::make($data, $rules, $messages)->validate();
|
Validator::make($data, $rules, $messages)->validate();
|
||||||
} catch (ValidationException $e) {
|
} 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'] ?? '';
|
$passwd = $data['password'] ?? '';
|
||||||
$data = $this->excludeFields($data);
|
$data = $this->excludeFields($data);
|
||||||
$result = false;
|
$result = false;
|
||||||
@@ -98,6 +113,10 @@ class Admin extends Backend
|
|||||||
$this->model->startTrans();
|
$this->model->startTrans();
|
||||||
try {
|
try {
|
||||||
$result = $this->model->save($data);
|
$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'])) {
|
if (!empty($data['group_arr'])) {
|
||||||
$groupAccess = [];
|
$groupAccess = [];
|
||||||
foreach ($data['group_arr'] as $datum) {
|
foreach ($data['group_arr'] as $datum) {
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ class Manage extends Backend
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($request->get('select') || $request->post('select')) {
|
if ($request->get('select') || $request->post('select')) {
|
||||||
$this->_select();
|
return $this->select($request);
|
||||||
return $this->success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,6 +80,28 @@ class Manage extends Backend
|
|||||||
return $this->success();
|
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 实现,无需重写即可直接使用
|
* add、edit、del、sortable 已由父类 Backend 实现,无需重写即可直接使用
|
||||||
* 若需重写,请确保调用 initializeBackend($request) 并传入 Request 参数
|
* 若需重写,请确保调用 initializeBackend($request) 并传入 Request 参数
|
||||||
|
|||||||
@@ -2,4 +2,6 @@
|
|||||||
return [
|
return [
|
||||||
'Group Name Arr' => 'Administrator Grouping ',
|
'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 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' => '管理员分组',
|
'Group Name Arr' => '管理员分组',
|
||||||
'Please use another administrator account to disable the current account!' => '请使用另外的管理员账户禁用当前账户!',
|
'Please use another administrator account to disable the current account!' => '请使用另外的管理员账户禁用当前账户!',
|
||||||
'You have no permission to add an administrator to this group!' => '您没有权限向此分组添加管理员!',
|
'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 $password 密码密文
|
||||||
* @property string $salt 密码盐
|
* @property string $salt 密码盐
|
||||||
* @property string $status 状态:enable=启用,disable=禁用
|
* @property string $status 状态:enable=启用,disable=禁用
|
||||||
|
* @property string $agent_id 代理ID(关联渠道)
|
||||||
|
* @property int $channel_id 渠道ID
|
||||||
*/
|
*/
|
||||||
class Admin extends Model
|
class Admin extends Model
|
||||||
{
|
{
|
||||||
@@ -64,4 +66,12 @@ class Admin extends Model
|
|||||||
{
|
{
|
||||||
return $this->where(['id' => $uid])->update(['password' => hash_password($newPassword), 'salt' => '']);
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,8 @@
|
|||||||
"robmorgan/phinx": "^0.15",
|
"robmorgan/phinx": "^0.15",
|
||||||
"nelexa/zip": "^4.0.0",
|
"nelexa/zip": "^4.0.0",
|
||||||
"voku/anti-xss": "^4.1",
|
"voku/anti-xss": "^4.1",
|
||||||
"topthink/think-validate": "^3.0"
|
"topthink/think-validate": "^3.0",
|
||||||
|
"firebase/php-jwt": "^7.0"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"ext-event": "For better performance. "
|
"ext-event": "For better performance. "
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
export default {
|
export default {
|
||||||
username: 'Username',
|
username: 'Username',
|
||||||
nickname: 'Nickname',
|
nickname: 'Nickname',
|
||||||
|
channel_id: 'Channel',
|
||||||
|
channel_name: 'Channel name',
|
||||||
|
'Please select channel': 'Please select channel',
|
||||||
group: 'Group',
|
group: 'Group',
|
||||||
avatar: 'Avatar',
|
avatar: 'Avatar',
|
||||||
email: 'Email',
|
email: 'Email',
|
||||||
mobile: 'Mobile Number',
|
mobile: 'Mobile Number',
|
||||||
'Last login': 'Last login',
|
'Last login': 'Last login',
|
||||||
Password: 'Password',
|
Password: 'Password',
|
||||||
|
agent_id: 'agent',
|
||||||
'Please leave blank if not modified': 'Please leave blank if you do not modify.',
|
'Please leave blank if not modified': 'Please leave blank if you do not modify.',
|
||||||
'Personal signature': 'Personal Signature',
|
'Personal signature': 'Personal Signature',
|
||||||
'Administrator login': 'Administrator Login Name',
|
'Administrator login': 'Administrator Login Name',
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
export default {
|
export default {
|
||||||
username: '用户名',
|
username: '用户名',
|
||||||
nickname: '昵称',
|
nickname: '昵称',
|
||||||
|
channel_id: '渠道',
|
||||||
|
channel_name: '渠道名称',
|
||||||
|
'Please select channel': '请选择渠道',
|
||||||
group: '角色组',
|
group: '角色组',
|
||||||
avatar: '头像',
|
avatar: '头像',
|
||||||
email: '电子邮箱',
|
email: '电子邮箱',
|
||||||
mobile: '手机号',
|
mobile: '手机号',
|
||||||
'Last login': '最后登录',
|
'Last login': '最后登录',
|
||||||
Password: '密码',
|
Password: '密码',
|
||||||
|
agent_id: '代理',
|
||||||
'Please leave blank if not modified': '不修改请留空',
|
'Please leave blank if not modified': '不修改请留空',
|
||||||
'Personal signature': '个性签名',
|
'Personal signature': '个性签名',
|
||||||
'Administrator login': '管理员登录名',
|
'Administrator login': '管理员登录名',
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ const baTable = new baTableClass(
|
|||||||
{ label: t('Id'), prop: 'id', align: 'center', operator: '=', operatorPlaceholder: t('Id'), width: 70 },
|
{ label: t('Id'), prop: 'id', align: 'center', operator: '=', operatorPlaceholder: t('Id'), width: 70 },
|
||||||
{ label: t('auth.admin.username'), prop: 'username', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
{ label: t('auth.admin.username'), prop: 'username', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
||||||
{ label: t('auth.admin.nickname'), prop: 'nickname', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
{ label: t('auth.admin.nickname'), prop: 'nickname', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
||||||
{ label: t('auth.admin.group'), prop: 'group_name_arr', align: 'center', operator: false, render: 'tags' },
|
{ label: t('auth.admin.group'), prop: 'group_name_arr', align: 'center', minWidth: 120, operator: false, render: 'tags' },
|
||||||
{ label: t('auth.admin.avatar'), prop: 'avatar', align: 'center', render: 'image', operator: false },
|
{ label: t('auth.admin.avatar'), prop: 'avatar', align: 'center', render: 'image', operator: false },
|
||||||
{ label: t('auth.admin.email'), prop: 'email', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
{ label: t('auth.admin.email'), prop: 'email', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
||||||
{ label: t('auth.admin.mobile'), prop: 'mobile', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
{ label: t('auth.admin.mobile'), prop: 'mobile', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
||||||
@@ -61,6 +61,20 @@ const baTable = new baTableClass(
|
|||||||
operator: 'RANGE',
|
operator: 'RANGE',
|
||||||
width: 160,
|
width: 160,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: t('auth.admin.channel_name'),
|
||||||
|
prop: 'channel.name',
|
||||||
|
align: 'center',
|
||||||
|
minWidth: 120,
|
||||||
|
operator: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('auth.admin.agent_id'),
|
||||||
|
prop: 'agent_id',
|
||||||
|
align: 'center',
|
||||||
|
width: '160',
|
||||||
|
showOverflowTooltip: true,
|
||||||
|
},
|
||||||
{ label: t('Create time'), prop: 'create_time', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
|
{ label: t('Create time'), prop: 'create_time', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
|
||||||
{
|
{
|
||||||
label: t('State'),
|
label: t('State'),
|
||||||
|
|||||||
@@ -41,6 +41,19 @@
|
|||||||
prop="nickname"
|
prop="nickname"
|
||||||
:placeholder="t('Please input field', { field: t('auth.admin.nickname') })"
|
:placeholder="t('Please input field', { field: t('auth.admin.nickname') })"
|
||||||
/>
|
/>
|
||||||
|
<FormItem
|
||||||
|
v-if="baTable.form.operate === 'Add' && adminInfo.super"
|
||||||
|
:label="t('auth.admin.channel_id')"
|
||||||
|
v-model="baTable.form.items!.channel_id"
|
||||||
|
prop="channel_id"
|
||||||
|
type="remoteSelect"
|
||||||
|
:input-attr="{
|
||||||
|
pk: 'id',
|
||||||
|
field: 'name',
|
||||||
|
remoteUrl: '/admin/channel.Manage/index',
|
||||||
|
placeholder: t('auth.admin.Please select channel'),
|
||||||
|
}"
|
||||||
|
/>
|
||||||
<FormItem
|
<FormItem
|
||||||
:label="t('auth.admin.group')"
|
:label="t('auth.admin.group')"
|
||||||
v-model="baTable.form.items!.group_arr"
|
v-model="baTable.form.items!.group_arr"
|
||||||
@@ -134,6 +147,17 @@ const { t } = useI18n()
|
|||||||
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
||||||
username: [buildValidatorData({ name: 'required', title: t('auth.admin.username') }), buildValidatorData({ name: 'account' })],
|
username: [buildValidatorData({ name: 'required', title: t('auth.admin.username') }), buildValidatorData({ name: 'account' })],
|
||||||
nickname: [buildValidatorData({ name: 'required', title: t('auth.admin.nickname') })],
|
nickname: [buildValidatorData({ name: 'required', title: t('auth.admin.nickname') })],
|
||||||
|
channel_id: [
|
||||||
|
{
|
||||||
|
validator: (_rule: any, val: any, callback: Function) => {
|
||||||
|
if (baTable.form.operate === 'Add' && adminInfo.super && !val) {
|
||||||
|
return callback(new Error(t('auth.admin.Please select channel')))
|
||||||
|
}
|
||||||
|
return callback()
|
||||||
|
},
|
||||||
|
trigger: 'change',
|
||||||
|
},
|
||||||
|
],
|
||||||
group_arr: [buildValidatorData({ name: 'required', message: t('Please select field', { field: t('auth.admin.group') }) })],
|
group_arr: [buildValidatorData({ name: 'required', message: t('Please select field', { field: t('auth.admin.group') }) })],
|
||||||
email: [buildValidatorData({ name: 'email', message: t('Please enter the correct field', { field: t('auth.admin.email') }) })],
|
email: [buildValidatorData({ name: 'email', message: t('Please enter the correct field', { field: t('auth.admin.email') }) })],
|
||||||
mobile: [buildValidatorData({ name: 'mobile', message: t('Please enter the correct field', { field: t('auth.admin.mobile') }) })],
|
mobile: [buildValidatorData({ name: 'mobile', message: t('Please enter the correct field', { field: t('auth.admin.mobile') }) })],
|
||||||
|
|||||||
Reference in New Issue
Block a user