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()); // } } /** * 生成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()); } } /** * 保存测量数据和体型选择(合并接口) */ public function saveMeasurementAndBodyType() { $params = $this->request->post(); // 验证基本参数 if (!isset($params['profile_id']) || !$params['profile_id']) { $this->error('档案ID不能为空'); } // 分离测量数据和体型选择数据 $measurementData = []; $bodyTypeSelections = []; // 测量数据字段 $measurementFields = [ 'chest', 'waist', 'hip', 'thigh', 'calf', 'upper_arm', 'forearm', 'neck', 'shoulder_width', 'bust', 'underbust', 'inseam', 'outseam', 'knee', 'arm_length', 'wrist', 'pants_length','belly_belt','leg_root', 'shoe_size', 'measurement_date' ]; // 提取测量数据 foreach ($measurementFields as $field) { if (isset($params[$field]) && $params[$field] !== '') { $measurementData[$field] = $params[$field]; } } // 提取体型选择数据 if (isset($params['selections']) && is_array($params['selections'])) { $bodyTypeSelections = $params['selections']; } // 提取档案更新数据(身高体重) $profileUpdateData = []; if (isset($params['height']) && $params['height'] !== '') { $profileUpdateData['height'] = floatval($params['height']); } if (isset($params['weight']) && $params['weight'] !== '') { $profileUpdateData['weight'] = floatval($params['weight']); } // 检查是否至少有一种数据 if (empty($measurementData) && empty($bodyTypeSelections) && empty($profileUpdateData)) { $this->error('请至少提供测量数据、体型选择数据或档案更新数据'); } // 验证测量数据(如果有) if (!empty($measurementData)) { $measurementData['profile_id'] = $params['profile_id']; $measurementValidate = new BodyMeasurementsValidate(); if (!$measurementValidate->scene('add')->check($measurementData)) { $this->error('测量数据验证失败:' . $measurementValidate->getError()); } } // 验证体型选择数据(如果有) if (!empty($bodyTypeSelections)) { $selectionData = [ 'profile_id' => $params['profile_id'], 'selections' => $bodyTypeSelections ]; $selectionValidate = new BodyTypeSelectionValidate(); if (!$selectionValidate->scene('save')->check($selectionData)) { $this->error('体型选择数据验证失败:' . $selectionValidate->getError()); } } // 验证档案更新数据(如果有) if (!empty($profileUpdateData)) { // 简单的身高体重验证 if (isset($profileUpdateData['height']) && ($profileUpdateData['height'] <= 0 || $profileUpdateData['height'] > 300)) { $this->error('身高必须在0-300厘米之间'); } if (isset($profileUpdateData['weight']) && ($profileUpdateData['weight'] <= 0 || $profileUpdateData['weight'] > 1000)) { $this->error('体重必须在0-1000公斤之间'); } } // try { $result = BodyProfileService::saveMeasurementAndBodyType( $params['profile_id'], $this->auth->id, $measurementData ?: [], // 确保不是null $bodyTypeSelections ?: [], // 确保不是null $profileUpdateData ?: [] // 档案更新数据 ); $this->success('保存成功', $result); // } catch (\Exception $e) { // $this->error($e->getMessage()); // } } /** * 编辑测量数据和体型选择(合并接口) */ public function updateMeasurementAndBodyType() { $params = $this->request->post(); // 验证基本参数 if (!isset($params['profile_id']) || !$params['profile_id']) { $this->error('档案ID不能为空'); } // 分离测量数据和体型选择数据 $measurementData = []; $bodyTypeSelections = []; // 测量数据字段 $measurementFields = [ 'chest', 'waist', 'hip', 'thigh', 'calf', 'upper_arm', 'forearm', 'neck', 'shoulder_width', 'bust', 'underbust', 'inseam', 'outseam', 'knee', 'arm_length', 'wrist', 'pants_length','belly_belt','leg_root', 'shoe_size', 'measurement_date' ]; // 提取测量数据 foreach ($measurementFields as $field) { if (isset($params[$field]) && $params[$field] !== '') { $measurementData[$field] = $params[$field]; } } // 提取体型选择数据 if (isset($params['selections']) && is_array($params['selections'])) { $bodyTypeSelections = $params['selections']; } // 提取档案更新数据(身高体重) $profileUpdateData = []; if (isset($params['height']) && $params['height'] !== '') { $profileUpdateData['height'] = floatval($params['height']); } if (isset($params['weight']) && $params['weight'] !== '') { $profileUpdateData['weight'] = floatval($params['weight']); } // 检查是否至少有一种数据 if (empty($measurementData) && empty($bodyTypeSelections) && empty($profileUpdateData)) { $this->error('请至少提供测量数据、体型选择数据或档案更新数据'); } // 验证测量数据(如果有) if (!empty($measurementData)) { $measurementData['profile_id'] = $params['profile_id']; $measurementValidate = new BodyMeasurementsValidate(); if (!$measurementValidate->scene('add')->check($measurementData)) { $this->error('测量数据验证失败:' . $measurementValidate->getError()); } } // 验证体型选择数据(如果有) if (!empty($bodyTypeSelections)) { $selectionData = [ 'profile_id' => $params['profile_id'], 'selections' => $bodyTypeSelections ]; $selectionValidate = new BodyTypeSelectionValidate(); if (!$selectionValidate->scene('save')->check($selectionData)) { $this->error('体型选择数据验证失败:' . $selectionValidate->getError()); } } // 验证档案更新数据(如果有) if (!empty($profileUpdateData)) { // 简单的身高体重验证 if (isset($profileUpdateData['height']) && ($profileUpdateData['height'] <= 0 || $profileUpdateData['height'] > 300)) { $this->error('身高必须在0-300厘米之间'); } if (isset($profileUpdateData['weight']) && ($profileUpdateData['weight'] <= 0 || $profileUpdateData['weight'] > 1000)) { $this->error('体重必须在0-1000公斤之间'); } } // try { $result = BodyProfileService::updateMeasurementAndBodyType( $params['profile_id'], $this->auth->id, $measurementData ?: [], $bodyTypeSelections ?: [], $profileUpdateData ?: [] ); $this->success('更新成功', $result); // } catch (\Exception $e) { // $this->error($e->getMessage()); // } } }