CoachController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace App\Http\Controllers\Client;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\Client\CoachService;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Auth;
  7. /**
  8. * @group 用户端
  9. *
  10. * 技师相关的API接口
  11. */
  12. class CoachController extends Controller
  13. {
  14. protected CoachService $service;
  15. public function __construct(CoachService $service)
  16. {
  17. $this->service = $service;
  18. }
  19. /**
  20. * [技师]获取附近技师列表
  21. *
  22. * 根据经纬度获取技师列表
  23. *
  24. * @authenticated
  25. *
  26. * @queryParam latitude float required 纬度. Example: 39.9042
  27. * @queryParam longitude float required 经度. Example: 116.4074
  28. *
  29. * @response {
  30. * "code": 200,
  31. * "message": "获取成功",
  32. * "data": [
  33. * {
  34. * "id": 1,
  35. * "name": "技师A",
  36. * "latitude": 34.0522,
  37. * "longitude": -118.2437
  38. * }
  39. * ]
  40. * }
  41. */
  42. public function list(Request $request)
  43. {
  44. $latitude = $request->input('latitude');
  45. $longitude = $request->input('longitude');
  46. return $this->success($this->service->getNearCoachList(Auth::user()->id, $latitude, $longitude));
  47. }
  48. /**
  49. * [技师]获取技师详情
  50. *
  51. * 根据ID获取技师的详细信息
  52. *
  53. * @authenticated
  54. *
  55. * @urlParam id int required 技师ID. Example: 6
  56. *
  57. * @queryParam latitude float 纬度. Example: 34.0522
  58. * @queryParam longitude float 经度. Example: -118.2437
  59. *
  60. * @response {
  61. * "code": 200,
  62. * "message": "获取成功",
  63. * "data": {
  64. * "id": 1,
  65. * "name": "技师A",
  66. * "latitude": 34.0522,
  67. * "longitude": -118.2437,
  68. * "details": "详细信息"
  69. * }
  70. * }
  71. */
  72. public function detail(Request $request, $id)
  73. {
  74. $latitude = $request->input('latitude');
  75. $longitude = $request->input('longitude');
  76. return $this->success($this->service->getCoachDetail($id, $latitude, $longitude));
  77. }
  78. /**
  79. * [技师]获取可预约时间段
  80. *
  81. * @description 获取指定技师的可预约时间段列表,包含日期、星期、时间段等信息
  82. *
  83. * @queryParam coach_id int required 技师ID Example: 6
  84. * @queryParam date string 日期(格式:Y-m-d) Example: 2024-03-22
  85. *
  86. * @response {
  87. * "data": {
  88. * "date": "2024-03-22",
  89. * "day_of_week": "星期五",
  90. * "is_today": false,
  91. * "time_slots": [
  92. * {
  93. * "start_time": "09:00",
  94. * "end_time": "09:30",
  95. * "is_available": true,
  96. * "duration": 30
  97. * }
  98. * ],
  99. * "total_slots": 1,
  100. * "updated_at": "2024-03-22 10:00:00"
  101. * }
  102. * }
  103. * @response 404 {
  104. * "message": "技师不存在"
  105. * }
  106. * @response 400 {
  107. * "message": "技师状态异常"
  108. * }
  109. * @response 400 {
  110. * "message": "不能查询过去的日期"
  111. * }
  112. * @response 400 {
  113. * "message": "只能查询未来30天内的时间段"
  114. * }
  115. */
  116. public function getSchedule(Request $request)
  117. {
  118. // 验证参数
  119. $validated = $request->validate([
  120. 'coach_id' => 'required|integer|exists:coach_users,id',
  121. 'date' => 'nullable|date_format:Y-m-d',
  122. ]);
  123. // 调用service获取技师可预约时间段
  124. return $this->success($this->service->getSchedule($validated['coach_id'], $validated['date'] ?? null));
  125. }
  126. }