UserService.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * @Name
  4. * @Description
  5. * @Author 刘学玺
  6. * @Date 2024/9/10 16:07
  7. */
  8. namespace App\Http\Services\Frontend\Server\Coach;
  9. use App\Exceptions\ApiException;
  10. use App\Http\Services\Service;
  11. use App\Models\Coach\User;
  12. use App\Models\Coach\Verify;
  13. class UserService extends Service
  14. {
  15. protected array $selectColumn = ['name', 'mobile', 'sex', 'birthday', 'work_img as workImg', 'city_id as cityId', 'status', 'verify_text as verifyText'];
  16. public function getUser()
  17. {
  18. // 获取用户ID
  19. $user_id = 1; // member_user_id
  20. // 获取认证信息
  21. $coach = Verify::query()->where('user_id', $user_id)->select($this->selectColumn)->first();
  22. // 判断认证信息
  23. return $coach ?: User::query()->where('user_id', $user_id)->select($this->selectColumn)->first();
  24. }
  25. /**
  26. * @throws ApiException
  27. */
  28. public function updateUser(array $data): void
  29. {
  30. // 获取用户ID
  31. $user_id = 1; // member_user_id
  32. // 获取技师ID
  33. $coach_id = User::query()->where('user_id', $user_id)->value('id');
  34. // 验证技师ID
  35. !$coach_id && self::error('数据错误');
  36. // 填充数据
  37. $data['user_id'] = $user_id;
  38. $data['coach_id'] = $coach_id;
  39. $data['status'] = 0;
  40. $data['id'] = Verify::query()->where('coach_id', $user_id)->value('id');
  41. self::toModel($data, Verify::class)->save();
  42. }
  43. }