ProjectController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace App\Http\Controllers\Coach;
  3. use Illuminate\Http\Request;
  4. use App\Traits\ResponseTrait;
  5. use App\Http\Controllers\Controller;
  6. use Illuminate\Support\Facades\Auth;
  7. use App\Services\Coach\ProjectService;
  8. use App\Http\Requests\Coach\OpenProjectRequest;
  9. /**
  10. * @group 技师端
  11. *
  12. * 项目管理相关的API接口
  13. */
  14. class ProjectController extends Controller
  15. {
  16. use ResponseTrait;
  17. protected ProjectService $service;
  18. public function __construct(ProjectService $service)
  19. {
  20. $this->service = $service;
  21. }
  22. /**
  23. * [项目]获取可开通项目列表
  24. *
  25. * @description 获取技师可以开通的项目列表,包含项目的基本信息、价格信息和服务说明,以及是否已开通状态
  26. *
  27. * @authenticated 需要技师身份认证
  28. *
  29. * @response {
  30. * "status": true,
  31. * "message": "获取成功",
  32. * "data": [
  33. * {
  34. * "id": 1, // 项目ID
  35. * "title": "精油推拿", // 项目标题
  36. * "subtitle": "专业精油推拿", // 项目副标题
  37. * "cover": "http://example.com/cover.jpg", // 项目封面图
  38. * "price": "188.00", // 项目价格
  39. * "original_price": "288.00", // 原价
  40. * "sales": 100, // 销量
  41. * "duration": 60, // 服务时长(分钟)
  42. * "project_desc": "项目描述", // 项目描述
  43. * "service_desc": "服务说明", // 服务说明
  44. * "type": 1, // 项目类型
  45. * "is_opened": false // 是否已开通
  46. * }
  47. * ]
  48. * }
  49. *
  50. * @response 404 {
  51. * "message": "技师信息不存在"
  52. * }
  53. */
  54. public function getAvailableProjects()
  55. {
  56. return $this->success(
  57. $this->service->getAvailableProjects(Auth::user()->coach)
  58. );
  59. }
  60. /**
  61. * [项目]开通/关闭项目
  62. *
  63. * @description 技师开通或关闭服务项目,包含项目状态和资格检查
  64. *
  65. * 业务流程:
  66. * 1. 验证项目ID和操作类型
  67. * 2. 调用服务层处理开关逻辑
  68. * 3. 返回操作结果
  69. *
  70. * @authenticated 需要技师身份认证
  71. *
  72. * @bodyParam project_id integer required 项目ID Example: 1
  73. * @bodyParam action string required 操作类型(open:开通 close:关闭) Example: "open"
  74. *
  75. * @response {
  76. * "status": true,
  77. * "message": "获取成功",
  78. * "data": {
  79. * "project_id": 1, // 项目ID
  80. * "project_name": "精油推拿", // 项目名称
  81. * "state": 1, // 项目状态
  82. * "state_text": "已开通" // 状态描述
  83. * }
  84. * }
  85. *
  86. * @response 404 {
  87. * "message": "项目不存在或已下架"
  88. * }
  89. * @response 422 {
  90. * "message": "技师状态异常,无法操作项目"
  91. * }
  92. */
  93. public function openProject(OpenProjectRequest $request)
  94. {
  95. // 调用服务层处理开通/关闭逻辑并返回结果
  96. return $this->success(
  97. $this->service->openProject(Auth::user()->coach, $request->validated())
  98. );
  99. }
  100. /**
  101. * [项目]项目设置
  102. *
  103. * @description 设置技师已开通项目的相关参数
  104. *
  105. * @authenticated
  106. *
  107. * @bodyParam project_id integer required 项目ID Example: 1
  108. * @bodyParam voucher numeric 代金卷金额(0-10元) Example: 5.00
  109. * @bodyParam gender integer 顾客性别(0:不限 1:男 2:女) Example: 0
  110. * @bodyParam traffic_fee integer 路费类型(0:免费 1:单程 2:双程) Example: 2
  111. *
  112. * @response {
  113. * "message": "项目设置更新成功",
  114. * "project_id": 1,
  115. * "settings": {
  116. * "voucher": "5.00",
  117. * "gender": 0,
  118. * "traffic_fee": 2,
  119. * }
  120. * }
  121. */
  122. public function setProject(Request $request)
  123. {
  124. $data = $request->validate([
  125. 'project_id' => 'required|integer|exists:project,id',
  126. 'voucher' => 'nullable|numeric|min:0|max:10',
  127. 'gender' => 'nullable|integer|in:0,1,2',
  128. 'traffic_fee' => 'nullable|integer|in:0,1,2',
  129. ]);
  130. return $this->success($this->service->setProject(Auth::user()->id, $data));
  131. }
  132. }