auth->id); $this->success('获取成功', $profiles); // } catch (\Exception $e) { // $this->error($e->getMessage()); // } } /** * 创建新档案 */ public function create() { $params = $this->request->post(); // 验证数据 $validate = new BodyProfileValidate(); if (!$validate->scene('create')->check($params)) { $this->error($validate->getError()); } // try { // 设置用户ID $params['user_id'] = $this->auth->id; $profile = BodyProfileService::createProfile($params); $this->success('创建成功', ['profile_id' => $profile->id]); // } catch (\Exception $e) { // $this->error($e->getMessage()); // } } /** * 获取档案详情 */ public function detail() { $profile_id = $this->request->get('profile_id/d'); if (!$profile_id) { $this->error('档案ID不能为空'); } // try { $profileData = BodyProfileService::getProfileDetail($profile_id, $this->auth->id); $this->success('获取成功', $profileData); // } catch (\Exception $e) { // $this->error($e->getMessage()); // } } /** * 更新档案基础信息 */ public function update() { $profile_id = $this->request->post('profile_id/d'); $params = $this->request->post(); if (!$profile_id) { $this->error('档案ID不能为空'); } // 过滤允许更新的字段 $allowedFields = ['profile_name', 'relation', 'age', 'height', 'weight', 'profile_photo', 'body_photos']; $updateData = []; foreach ($allowedFields as $field) { if (isset($params[$field])) { $updateData[$field] = $params[$field]; } } if (empty($updateData)) { $this->error('没有需要更新的数据'); } // 验证数据 $validate = new BodyProfileValidate(); if (!$validate->scene('update')->check($updateData)) { $this->error($validate->getError()); } // try { BodyProfileService::updateProfile($profile_id, $this->auth->id, $updateData); $this->success('更新成功'); // } catch (\Exception $e) { // $this->error($e->getMessage()); // } } /** * 删除档案 */ public function delete() { $profile_id = $this->request->post('profile_id/d'); if (!$profile_id) { $this->error('档案ID不能为空'); } // try { BodyProfileService::deleteProfile($profile_id, $this->auth->id); $this->success('删除成功'); // } catch (\Exception $e) { // $this->error($e->getMessage()); // } } /** * 添加测量数据 */ public function addMeasurement() { $params = $this->request->post(); // 验证数据 $validate = new BodyMeasurementsValidate(); if (!$validate->scene('add')->check($params)) { $this->error($validate->getError()); } try { $measurement = BodyProfileService::addMeasurement( $params['profile_id'], $this->auth->id, $params ); $this->success('添加成功', ['measurement_id' => $measurement->id]); } catch (\Exception $e) { $this->error($e->getMessage()); } } /** * 获取测量历史 */ public function measurementHistory() { $profile_id = $this->request->get('profile_id/d'); $page = $this->request->get('page/d', 1); $limit = $this->request->get('limit/d', 10); if (!$profile_id) { $this->error('档案ID不能为空'); } try { $result = BodyProfileService::getMeasurementHistory($profile_id, $this->auth->id, $page, $limit); $this->success('获取成功', $result); } catch (\Exception $e) { $this->error($e->getMessage()); } } /** * 获取体型配置选项 */ public function getBodyTypeOptions() { $gender = $this->request->get('gender/d', 0); // try { $categories = BodyTypeService::getTypeSelectionConfig($gender); $this->success('获取成功', $categories); // } catch (\Exception $e) { // $this->error($e->getMessage()); // } } /** * 保存体型选择 */ public function saveBodyTypeSelection() { $params = $this->request->post(); // 验证数据 $validate = new BodyTypeSelectionValidate(); if (!$validate->scene('save')->check($params)) { $this->error($validate->getError()); } // try { BodyProfileService::saveBodyTypeSelection( $params['profile_id'], $this->auth->id, $params['selections'] ); $this->success('保存成功'); // } catch (\Exception $e) { // $this->error($e->getMessage()); // } } /** * 获取体型推荐 */ public function getBodyTypeRecommendation() { $profile_id = $this->request->get('profile_id/d'); if (!$profile_id) { $this->error('档案ID不能为空'); } try { $recommendations = BodyProfileService::getBodyTypeRecommendation($profile_id, $this->auth->id); $this->success('获取成功', $recommendations); } catch (\Exception $e) { $this->error($e->getMessage()); } } /** * 生成AI测试报告 */ public function generateAiReport() { $profile_id = $this->request->post('profile_id/d'); $report_type = $this->request->post('report_type', 'comprehensive'); if (!$profile_id) { $this->error('档案ID不能为空'); } try { $report = BodyProfileService::generateAiReport($profile_id, $this->auth->id, $report_type); $this->success('报告生成成功', ['report_id' => $report->id]); } catch (\Exception $e) { $this->error($e->getMessage()); } } /** * 获取AI报告详情 */ public function getAiReport() { $report_id = $this->request->get('report_id/d'); if (!$report_id) { $this->error('报告ID不能为空'); } try { $report = BodyProfileService::getAiReport($report_id, $this->auth->id); $this->success('获取成功', $report->toArray()); } catch (\Exception $e) { $this->error($e->getMessage()); } } /** * 获取AI报告列表 */ public function getAiReportList() { $profile_id = $this->request->get('profile_id/d'); $page = $this->request->get('page/d', 1); $limit = $this->request->get('limit/d', 10); if (!$profile_id) { $this->error('档案ID不能为空'); } try { $result = BodyProfileService::getAiReportList($profile_id, $this->auth->id, $page, $limit); $this->success('获取成功', $result); } catch (\Exception $e) { $this->error($e->getMessage()); } } /** * 获取体型选择建议报告 */ public function getSelectionReport() { $profile_id = $this->request->get('profile_id/d'); if (!$profile_id) { $this->error('档案ID不能为空'); } try { $report = BodyProfileService::getSelectionReport($profile_id, $this->auth->id); $this->success('获取成功', $report); } catch (\Exception $e) { $this->error($e->getMessage()); } } /** * 获取体型选择统计数据 */ public function getSelectionStatistics() { $category = $this->request->get('category', ''); $gender = $this->request->get('gender/d', 0); try { $statistics = BodyTypeService::getSelectionStatistics($category, $gender); $this->success('获取成功', $statistics); } catch (\Exception $e) { $this->error($e->getMessage()); } } }