UserService.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 22/04/26
  6. * Time: 14:41.
  7. */
  8. namespace App\Services\Api;
  9. use App\Models\User;
  10. class UserService
  11. {
  12. // 获取用户信息(需要更多信息的话在这里追加)
  13. public static function getUserInfoById($id)
  14. {
  15. $info = User::query()->where('id', $id)->whereNull('deleted_at')->first();
  16. $info->makeHidden(['updated_at', 'deleted_at']);
  17. $info = !empty($info) ? $info->toArray() : [];
  18. return $info;
  19. }
  20. // 通过手机号查用户
  21. public static function checkUserByMobile($mobile)
  22. {
  23. $user = User::where('mobile', $mobile)->whereNull('deleted_at')->first();
  24. if ($user) {
  25. return true;
  26. }
  27. return false;
  28. }
  29. // 通过邮箱查找用户
  30. public static function checkUserByEmail($email)
  31. {
  32. $user = User::where('email', $email)->whereNull('deleted_at')->first();
  33. if ($user) {
  34. return true;
  35. }
  36. return false;
  37. }
  38. // 收藏数+1
  39. public static function collectNumInc($userId)
  40. {
  41. User::query()->where('id', $userId)->increment('collect_num');
  42. }
  43. // 收藏数-1
  44. public static function collectNumDec($userId)
  45. {
  46. User::query()->where('id', $userId)->decrement('collect_num');
  47. }
  48. }