* @date 2020-01-23 00:27:19 */ declare(strict_types=1); namespace App\Repositories; use App\Model\ManagerModel; use KZ2\Repositories\Model\Repository; class ManagerRepository extends Repository { public function model() { return ManagerModel::class; } /** * 生成密码. * @param string $plain 明文密码. * @param string $salt 盐. * @return string */ public function generatePassword($plain, $salt) { return md5(md5($plain) . $salt); } /** * 是否存在相同用户名. * @param string $username 用户名. * @param string $excludeManagerId 排除的用户ID. * @return bool */ public function isExistsUsername($username, $excludeManagerId = '') { $model = new ManagerModel(); if (!empty($excludeManagerId)) { $model = $model->where('manager_id', '!=', $excludeManagerId); } $model = $model->where('username', $username); return $model->exists(); } }