UserRepositoryEloquent.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Repositories\Eloquent\Base;
  3. use App\Contracts\Repositories\Base\AdminRepository;
  4. use App\Repositories\Models\Base\User;
  5. use Illuminate\Support\Facades\Hash;
  6. use Prettus\Repository\Criteria\RequestCriteria;
  7. use Prettus\Repository\Eloquent\BaseRepository;
  8. class UserRepositoryEloquent extends BaseRepository implements AdminRepository
  9. {
  10. protected $fieldSearchable = [
  11. // 'name' => 'like', Default Condition "="
  12. ];
  13. /**
  14. * Specify Model class name.
  15. *
  16. * @return string
  17. */
  18. public function model()
  19. {
  20. return User::class;
  21. }
  22. /**
  23. * Boot up the repository, pushing criteria.
  24. *
  25. * @throws \Prettus\Repository\Exceptions\RepositoryException
  26. */
  27. public function boot()
  28. {
  29. $this->pushCriteria(app(RequestCriteria::class));
  30. }
  31. /**
  32. * @return mixed
  33. */
  34. public function searchUsersByPage()
  35. {
  36. return $this->paginate(request('per_page', 15));
  37. }
  38. /**
  39. * @param $id
  40. *
  41. * @return mixed
  42. */
  43. public function searchAdminBy($id)
  44. {
  45. return $this->find($id);
  46. }
  47. public function searchUserBy($id)
  48. {
  49. return $this->find($id);
  50. }
  51. /**
  52. * 更新用户登录地址
  53. * @param $admin_id
  54. * @param $ip
  55. * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection|mixed
  56. * @throws \Prettus\Validator\Exceptions\ValidatorException
  57. */
  58. public function updateLoginInfo($user_id, $ip)
  59. {
  60. $this->validator = null;
  61. return $this->update([
  62. 'last_login_time' => date('Y-m-d H:i:s'),
  63. 'last_login_ip' => $ip,
  64. ], $user_id);
  65. }
  66. /**
  67. * 验证密码是否正确
  68. * @param $id
  69. * @param $password
  70. * @return mixed
  71. */
  72. public function byIdConfirmPassword($id, $password)
  73. {
  74. $user_password = $this->where('id', $id)->value('password');
  75. return Hash::check(base64_decode($password), $user_password);
  76. }
  77. }