You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
883 B

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Constants\v3\ErrorCode;
  4. use App\Exception\ErrorCodeException;
  5. use App\Model\v3\User;
  6. use App\Service\v3\Interfaces\UserBindTelServiceInterface;
  7. class UserBindTelService implements UserBindTelServiceInterface
  8. {
  9. public function do($userId, $tel)
  10. {
  11. $user = User::find($userId);
  12. $user->tel = $tel;
  13. if (!$user->save()) {
  14. throw new ErrorCodeException(ErrorCode::BIND_TEL_ERROR);
  15. }
  16. return true;
  17. }
  18. public function check($userId)
  19. {
  20. $user = User::find($userId);
  21. return $user->tel ? true : false;
  22. }
  23. public function undo($userId)
  24. {
  25. $user = User::find($userId);
  26. $user->tel = '';
  27. if (!$user->save()) {
  28. throw new ErrorCodeException(ErrorCode::UNBIND_TEL_ERROR);
  29. }
  30. return true;
  31. }
  32. }