ManagerRepository.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * 描述.
  4. *
  5. * @author nj
  6. * @date 2021-05-18 20:45:46
  7. */
  8. namespace App\Repositories;
  9. use KZ2\Laravel\Repositories\Eloquent\Repository;
  10. use App\Models\Mysql\ManagerModel;
  11. class ManagerRepository extends Repository
  12. {
  13. public function model()
  14. {
  15. return ManagerModel::class;
  16. }
  17. /**
  18. * 生成密码.
  19. * @param string $plain 明文密码.
  20. * @param string $salt 盐.
  21. * @return string
  22. */
  23. public function generatePassword($plain, $salt)
  24. {
  25. return md5(md5($plain) . $salt);
  26. }
  27. /**
  28. * 是否存在相同用户名.
  29. * @param string $username 用户名.
  30. * @param string $excludeManagerUid 排除的用户ID.
  31. * @return bool
  32. */
  33. public function isExistsUsername($username, $excludeManagerUid = '')
  34. {
  35. $model = new ManagerModel();
  36. if (!empty($excludeManagerUid)) {
  37. $model = $model->where('manager_uid', '!=', $excludeManagerUid);
  38. }
  39. $model = $model->where('username', $username);
  40. return $model->exists();
  41. }
  42. }