CoachService.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Services\Client;
  3. use App\Models\CoachUser;
  4. use App\Models\MemberUser;
  5. use App\Models\CoachLocation;
  6. use Illuminate\Support\Facades\Auth;
  7. use Illuminate\Support\Facades\DB;
  8. class CoachService
  9. {
  10. /**
  11. * 获取技师列表
  12. */
  13. public function getCoachList($latitude, $longitude)
  14. {
  15. // 获取当前用户
  16. $userId = Auth::id();
  17. $user = MemberUser::findOrFail($userId);
  18. // 检查用户状态
  19. if ($user->state !== 'enable') {
  20. throw new \Exception('用户状态异常');
  21. }
  22. // 获取附近的技师
  23. $coaches = CoachUser::query()
  24. ->where('state', 'enable')
  25. ->where('auth_state', 'passed')
  26. ->with(['user:id,nickname,avatar,gender'])
  27. ->with(['location'])
  28. ->whereHas('location', function($query) use ($latitude, $longitude) {
  29. // TODO: 实现经纬度范围查询
  30. $query->where('state', 'enable');
  31. })
  32. ->paginate(10);
  33. return $coaches;
  34. }
  35. /**
  36. * 获取技师详情
  37. */
  38. public function getCoachDetail($coachId, $latitude, $longitude)
  39. {
  40. // 获取当前用户
  41. $userId = Auth::id();
  42. $user = MemberUser::findOrFail($userId);
  43. // 检查用户状态
  44. if ($user->state !== 'enable') {
  45. throw new \Exception('用户状态异常');
  46. }
  47. // 获取技师信息
  48. $coach = CoachUser::where('id', $coachId)
  49. ->where('state', 'enable')
  50. ->where('auth_state', 'passed')
  51. ->with(['user:id,nickname,avatar,gender'])
  52. ->with(['location'])
  53. ->firstOrFail();
  54. // TODO: 计算距离
  55. $distance = 0;
  56. if ($coach->location) {
  57. // 实现距离计算逻辑
  58. }
  59. $coach->distance = $distance;
  60. return $coach;
  61. }
  62. }