ProjectController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. namespace App\Http\Controllers\Client;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\Client\ProjectService;
  6. /**
  7. * @group 用户端
  8. *
  9. * 项目相关的API接口
  10. */
  11. class ProjectController extends Controller
  12. {
  13. protected ProjectService $service;
  14. public function __construct(ProjectService $service)
  15. {
  16. $this->service = $service;
  17. }
  18. /**
  19. * [项目]获取项目列表
  20. *
  21. * 根据区域代码获取项目列表
  22. *
  23. * @authenticated
  24. *
  25. * @queryParam area_code string required 区域代码. Example: 330100
  26. * @queryParam project_cate_id integer 项目分类ID. Example: 1
  27. * @queryParam type integer required 项目类型(1:普通项目,2:加钟项目). Example: 1
  28. *
  29. * @response {
  30. * "code": 200,
  31. * "message": "获取成功",
  32. * "data": {
  33. * "current_page": 1,
  34. * "data": [
  35. * {
  36. * "id": 1,
  37. * "name": "项目名称",
  38. * "description": "项目描述",
  39. * "price": "100.00",
  40. * "duration": 60,
  41. * "category": {
  42. * "id": 1,
  43. * "name": "分类名称"
  44. * }
  45. * }
  46. * ],
  47. * "total": 10,
  48. * "per_page": 10
  49. * }
  50. * }
  51. */
  52. public function index(Request $request)
  53. {
  54. // 验证请求参数
  55. $validated = $request->validate([
  56. 'area_code' => ['required', 'string', 'regex:/^\d{6}$/'],
  57. 'project_cate_id' => 'nullable|integer',
  58. 'type' => 'required|in:1,2'
  59. ]);
  60. // 调用服务层获取项目列表
  61. return $this->success(
  62. $this->service->getProjectList(
  63. $validated['area_code'],
  64. $validated['project_cate_id'] ?? null,
  65. $validated['type']
  66. )
  67. );
  68. }
  69. /**
  70. * [项目]获取项目详情
  71. *
  72. * 获取指定项目的详细信息
  73. *
  74. * @authenticated
  75. *
  76. * @queryParam id integer required 项目ID. Example: 1
  77. * @queryParam area_code string required 区域代码. Example: 330100
  78. *
  79. * @response {
  80. * "code": 200,
  81. * "message": "获取成功",
  82. * "data": {
  83. * "id": 1,
  84. * "name": "项目名称",
  85. * "description": "项目描述",
  86. * "price": "100.00",
  87. * "duration": 60,
  88. * "category": {
  89. * "id": 1,
  90. * "name": "分类名称"
  91. * },
  92. * "agent": {
  93. * "id": 1,
  94. * "name": "代理商名称",
  95. * "contact": "联系人",
  96. * "mobile": "13800138000"
  97. * }
  98. * }
  99. * }
  100. * @response 404 {
  101. * "code": 404,
  102. * "message": "项目不存在"
  103. * }
  104. * @response 400 {
  105. * "code": 400,
  106. * "message": "该区域暂无代理商"
  107. * }
  108. */
  109. public function detail(Request $request)
  110. {
  111. $projectId = $request->input('id');
  112. $areaCode = $request->input('area_code');
  113. return $this->success($this->service->getProjectDetail($projectId, $areaCode));
  114. }
  115. /**
  116. * [项目]获取技师项目列表
  117. *
  118. * 获取指定技师已开通的项目列表
  119. *
  120. * @authenticated
  121. *
  122. * @queryParam coach_id integer required 技师ID. Example: 6
  123. * @queryParam area_code string required 区域代码. Example: 330100
  124. * @queryParam project_cate_id integer 项目分类ID. Example: 1
  125. *
  126. * @response {
  127. * "code": 200,
  128. * "message": "获取成功",
  129. * "data": {
  130. * "current_page": 1,
  131. * "data": [
  132. * {
  133. * "id": 1,
  134. * "name": "项目名称",
  135. * "description": "项目描述",
  136. * "price": "100.00",
  137. * "duration": 60,
  138. * "category": {
  139. * "id": 1,
  140. * "name": "分类名称"
  141. * }
  142. * }
  143. * ],
  144. * "total": 10,
  145. * "per_page": 10
  146. * }
  147. * }
  148. * @response 404 {
  149. * "code": 404,
  150. * "message": "技师不存在或未通过认证"
  151. * }
  152. */
  153. public function coachProjectList(Request $request)
  154. {
  155. $validated = $request->validate([
  156. 'coach_id' => 'required|integer',
  157. 'area_code' => 'required|string',
  158. 'project_cate_id' => 'required|integer',
  159. ]);
  160. return $this->success(
  161. $this->service->getCoachProjectList(
  162. $validated['coach_id'],
  163. $validated['area_code'],
  164. $validated['project_cate_id']
  165. )
  166. );
  167. }
  168. }