1. 维护代码健壮

2. 更新项目结构文档
This commit is contained in:
技术老胡
2026-04-27 16:20:41 +08:00
parent 9a16a88640
commit 0e5de50337
198 changed files with 21038 additions and 702 deletions

View File

@@ -5,6 +5,7 @@ namespace app\service\system\user;
use app\common\base\BaseService;
use app\common\constant\CommonConstant;
use app\exception\ResourceNotFoundException;
use app\exception\ValidationException;
use app\model\admin\AdminUser;
use app\repository\system\user\AdminUserRepository;
@@ -196,6 +197,40 @@ class AdminUserService extends BaseService
];
}
/**
* 修改当前管理员登录密码。
*
* @param int $adminId 管理员ID
* @param array $data 密码数据
* @return array<string, mixed> 修改结果
* @throws ResourceNotFoundException
* @throws ValidationException
*/
public function changePassword(int $adminId, array $data): array
{
$admin = $this->adminUserRepository->find($adminId);
if (!$admin) {
throw new ResourceNotFoundException('管理员不存在', ['admin_id' => $adminId]);
}
$currentPassword = trim((string) ($data['current_password'] ?? ''));
$newPassword = trim((string) ($data['password'] ?? ''));
if (!password_verify($currentPassword, (string) $admin->password_hash)) {
throw new ValidationException('旧密码不正确');
}
if ($currentPassword === $newPassword) {
throw new ValidationException('新密码不能与旧密码相同');
}
$this->adminUserRepository->updateById($adminId, [
'password_hash' => password_hash($newPassword, PASSWORD_DEFAULT),
]);
return ['updated' => true];
}
/**
* 统一整理写入字段,并处理密码哈希。
*
@@ -226,6 +261,3 @@ class AdminUserService extends BaseService
}
}