123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace App\Http\Controllers\Coach;
- use Illuminate\Http\Request;
- use App\Traits\ResponseTrait;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
- use App\Services\Coach\ProjectService;
- use App\Http\Requests\Coach\OpenProjectRequest;
- /**
- * @group 技师端
- *
- * 项目管理相关的API接口
- */
- class ProjectController extends Controller
- {
- use ResponseTrait;
- protected ProjectService $service;
- public function __construct(ProjectService $service)
- {
- $this->service = $service;
- }
- /**
- * [项目]获取可开通项目列表
- *
- * @description 获取技师可以开通的项目列表,包含项目的基本信息、价格信息和服务说明,以及是否已开通状态
- *
- * @authenticated 需要技师身份认证
- *
- * @response {
- * "status": true,
- * "message": "获取成功",
- * "data": [
- * {
- * "id": 1, // 项目ID
- * "title": "精油推拿", // 项目标题
- * "subtitle": "专业精油推拿", // 项目副标题
- * "cover": "http://example.com/cover.jpg", // 项目封面图
- * "price": "188.00", // 项目价格
- * "original_price": "288.00", // 原价
- * "sales": 100, // 销量
- * "duration": 60, // 服务时长(分钟)
- * "project_desc": "项目描述", // 项目描述
- * "service_desc": "服务说明", // 服务说明
- * "type": 1, // 项目类型
- * "is_opened": false // 是否已开通
- * }
- * ]
- * }
- *
- * @response 404 {
- * "message": "技师信息不存在"
- * }
- */
- public function getAvailableProjects()
- {
- return $this->success(
- $this->service->getAvailableProjects(Auth::user()->coach)
- );
- }
- /**
- * [项目]开通/关闭项目
- *
- * @description 技师开通或关闭服务项目,包含项目状态和资格检查
- *
- * 业务流程:
- * 1. 验证项目ID和操作类型
- * 2. 调用服务层处理开关逻辑
- * 3. 返回操作结果
- *
- * @authenticated 需要技师身份认证
- *
- * @bodyParam project_id integer required 项目ID Example: 1
- * @bodyParam action string required 操作类型(open:开通 close:关闭) Example: "open"
- *
- * @response {
- * "status": true,
- * "message": "获取成功",
- * "data": {
- * "project_id": 1, // 项目ID
- * "project_name": "精油推拿", // 项目名称
- * "state": 1, // 项目状态
- * "state_text": "已开通" // 状态描述
- * }
- * }
- *
- * @response 404 {
- * "message": "项目不存在或已下架"
- * }
- * @response 422 {
- * "message": "技师状态异常,无法操作项目"
- * }
- */
- public function openProject(OpenProjectRequest $request)
- {
- // 调用服务层处理开通/关闭逻辑并返回结果
- return $this->success(
- $this->service->openProject(Auth::user()->coach, $request->validated())
- );
- }
- /**
- * [项目]项目设置
- *
- * @description 设置技师已开通项目的相关参数
- *
- * @authenticated
- *
- * @bodyParam project_id integer required 项目ID Example: 1
- * @bodyParam voucher numeric 代金卷金额(0-10元) Example: 5.00
- * @bodyParam gender integer 顾客性别(0:不限 1:男 2:女) Example: 0
- * @bodyParam traffic_fee integer 路费类型(0:免费 1:单程 2:双程) Example: 2
- *
- * @response {
- * "message": "项目设置更新成功",
- * "project_id": 1,
- * "settings": {
- * "voucher": "5.00",
- * "gender": 0,
- * "traffic_fee": 2,
- * }
- * }
- */
- public function setProject(Request $request)
- {
- $data = $request->validate([
- 'project_id' => 'required|integer|exists:project,id',
- 'voucher' => 'nullable|numeric|min:0|max:10',
- 'gender' => 'nullable|integer|in:0,1,2',
- 'traffic_fee' => 'nullable|integer|in:0,1,2',
- ]);
- return $this->success($this->service->setProject(Auth::user()->id, $data));
- }
- }
|