UserService.php 1023 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Services;
  3. use App\Models\NickName;
  4. use App\Models\User;
  5. class UserService
  6. {
  7. public function updatePassword(User $user, string $password): bool
  8. {
  9. $user->password = $password;
  10. if ($user->save()) {
  11. return true;
  12. }
  13. return false;
  14. }
  15. public function updateMobile(User $user, $mobile)
  16. {
  17. if ($user->mobile != $mobile) {
  18. }
  19. if ($user->mobile == $mobile) {
  20. return ['error' => '新手机号与原手机号一致'];
  21. }
  22. if (User::where(['mobile' => $mobile, 'id' => ['<>', $user->id]])->first()) {
  23. return ['error' => '手机号已被占用'];
  24. }
  25. $user->mobile = $mobile;
  26. if ($user->save()) {
  27. return true;
  28. }
  29. return ['error' => '手机号修改失败'];
  30. }
  31. public function selectUserNickNameById(array $id_arr)
  32. {
  33. $list = NickName::query()->whereIn('id', $id_arr)->pluck('name', 'id');
  34. return $list;
  35. }
  36. }