ManagerRepository.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * 管理员仓库.
  4. *
  5. * @author jim <jim458734573@gmail.com>
  6. * @date 2020-01-23 00:27:19
  7. */
  8. declare(strict_types=1);
  9. namespace App\Repositories;
  10. use App\Model\ManagerModel;
  11. use KZ2\Repositories\Model\Repository;
  12. class ManagerRepository extends Repository
  13. {
  14. public function model()
  15. {
  16. return ManagerModel::class;
  17. }
  18. /**
  19. * 生成密码.
  20. * @param string $plain 明文密码.
  21. * @param string $salt 盐.
  22. * @return string
  23. */
  24. public function generatePassword($plain, $salt)
  25. {
  26. return md5(md5($plain) . $salt);
  27. }
  28. /**
  29. * 是否存在相同用户名.
  30. * @param string $username 用户名.
  31. * @param string $excludeManagerId 排除的用户ID.
  32. * @return bool
  33. */
  34. public function isExistsUsername($username, $excludeManagerId = '')
  35. {
  36. $model = new ManagerModel();
  37. if (!empty($excludeManagerId)) {
  38. $model = $model->where('manager_id', '!=', $excludeManagerId);
  39. }
  40. $model = $model->where('username', $username);
  41. return $model->exists();
  42. }
  43. }