This commit is contained in:
weiz 2024-05-28 10:38:56 +08:00
parent 86192ad03e
commit 32cb4992ee
3 changed files with 43 additions and 7 deletions

View File

@ -93,6 +93,22 @@ class AdminController extends BaseAdminController
}
return $this->fail(AdminLogic::getError());
}
/**
* @notes 删除管理员
* @return \think\response\Json
* @author 段誉
* @date 2021/12/29 11:03
*/
public function pwd()
{
$params = (new AdminValidate())->post()->goCheck('pwd');
$result = AdminLogic::pwd($params);
if (true === $result) {
return $this->success('操作成功', [], 1, 1);
}
return $this->fail(AdminLogic::getError());
}
/**

View File

@ -130,12 +130,6 @@ class AdminLogic extends BaseLogic
// 头像
$data['avatar'] = !empty($params['avatar']) ? FileService::setFileUrl($params['avatar']) : '';
// 密码
if (!empty($params['password'])) {
$passwordSalt = Config::get('project.unique_identification');
$data['password'] = create_password($params['password'], $passwordSalt);
}
// 禁用或更换角色后.设置token过期
$roleId = AdminRole::where('admin_id', $params['id'])->column('role_id');
$editRole = false;
@ -162,6 +156,27 @@ class AdminLogic extends BaseLogic
return false;
}
}
public static function pwd(array $params): bool
{
$passwordSalt = Config::get('project.unique_identification');
$password = create_password($params['password'], $passwordSalt);
Db::startTrans();
try {
// 基础信息
$data = [
'id' => $params['id'],
'password' => $password,
];
Admin::update($data);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**

View File

@ -32,7 +32,7 @@
'account' => 'require|length:1,32|unique:' . Admin::class,
'name' => 'require|length:1,16|unique:' . Admin::class,
'password' => 'require|length:6,32',
'password_confirm' => 'requireWith:password|confirm',
'password_confirm' => 'require|confirm:password',
'role_id' => 'require',
'disable' => 'require|in:0,1|checkAbleDisable',
'multipoint_login' => 'require|in:0,1',
@ -129,6 +129,11 @@
->append('id', 'require|checkAdmin');
}
public function scenePwd()
{
return $this->only(['id', 'password', 'password_confirm']);
}
/**
* @notes 删除场景