|
@@ -96,10 +96,21 @@ class BodyTypeService
|
|
}
|
|
}
|
|
|
|
|
|
$config = Config::get('body_type_config');
|
|
$config = Config::get('body_type_config');
|
|
|
|
+
|
|
|
|
+ // 检查配置是否存在
|
|
|
|
+ if (!$config || !isset($config['recommendation_rules']) || !is_array($config['recommendation_rules'])) {
|
|
|
|
+ return []; // 如果配置不存在,返回空数组
|
|
|
|
+ }
|
|
|
|
+
|
|
$rules = $config['recommendation_rules'];
|
|
$rules = $config['recommendation_rules'];
|
|
$recommendations = [];
|
|
$recommendations = [];
|
|
|
|
|
|
foreach ($rules as $category => $rule) {
|
|
foreach ($rules as $category => $rule) {
|
|
|
|
+ // 检查规则格式是否正确
|
|
|
|
+ if (!is_array($rule) || !isset($rule['metrics']) || !is_array($rule['metrics'])) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
// 检查是否有必要的测量数据
|
|
// 检查是否有必要的测量数据
|
|
$hasRequiredData = true;
|
|
$hasRequiredData = true;
|
|
foreach ($rule['metrics'] as $metric) {
|
|
foreach ($rule['metrics'] as $metric) {
|
|
@@ -128,11 +139,21 @@ class BodyTypeService
|
|
*/
|
|
*/
|
|
private static function applyRecommendationRules($measurements, $rule)
|
|
private static function applyRecommendationRules($measurements, $rule)
|
|
{
|
|
{
|
|
|
|
+ // 检查规则格式
|
|
|
|
+ if (!isset($rule['rules']) || !is_array($rule['rules'])) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
foreach ($rule['rules'] as $ruleItem) {
|
|
foreach ($rule['rules'] as $ruleItem) {
|
|
|
|
+ // 检查规则项格式
|
|
|
|
+ if (!is_array($ruleItem) || !isset($ruleItem['condition'])) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
if ($ruleItem['condition'] === 'default') {
|
|
if ($ruleItem['condition'] === 'default') {
|
|
return [
|
|
return [
|
|
- 'type_name' => $ruleItem['type'],
|
|
|
|
- 'confidence' => $ruleItem['confidence'],
|
|
|
|
|
|
+ 'type_name' => $ruleItem['type'] ?? '未知类型',
|
|
|
|
+ 'confidence' => $ruleItem['confidence'] ?? 0.5,
|
|
'reason' => '基于默认规则推荐'
|
|
'reason' => '基于默认规则推荐'
|
|
];
|
|
];
|
|
}
|
|
}
|
|
@@ -140,8 +161,8 @@ class BodyTypeService
|
|
// 解析条件表达式
|
|
// 解析条件表达式
|
|
if (self::evaluateCondition($measurements, $ruleItem['condition'])) {
|
|
if (self::evaluateCondition($measurements, $ruleItem['condition'])) {
|
|
return [
|
|
return [
|
|
- 'type_name' => $ruleItem['type'],
|
|
|
|
- 'confidence' => $ruleItem['confidence'],
|
|
|
|
|
|
+ 'type_name' => $ruleItem['type'] ?? '未知类型',
|
|
|
|
+ 'confidence' => $ruleItem['confidence'] ?? 0.5,
|
|
'reason' => '基于测量数据分析推荐'
|
|
'reason' => '基于测量数据分析推荐'
|
|
];
|
|
];
|
|
}
|
|
}
|
|
@@ -208,15 +229,19 @@ class BodyTypeService
|
|
];
|
|
];
|
|
|
|
|
|
// 检查是否与AI推荐一致
|
|
// 检查是否与AI推荐一致
|
|
- if (isset($recommendations[$category])) {
|
|
|
|
|
|
+ if (isset($recommendations[$category]) && is_array($recommendations[$category])) {
|
|
$recommendation = $recommendations[$category];
|
|
$recommendation = $recommendations[$category];
|
|
- if ($recommendation['type_name'] === $selectedType->type_name) {
|
|
|
|
- $matchingData['matching_score'] = $recommendation['confidence'];
|
|
|
|
|
|
+ $typeName = $recommendation['type_name'] ?? '';
|
|
|
|
+ $confidence = $recommendation['confidence'] ?? 0.5;
|
|
|
|
+ $reason = $recommendation['reason'] ?? '';
|
|
|
|
+
|
|
|
|
+ if ($typeName === $selectedType->type_name) {
|
|
|
|
+ $matchingData['matching_score'] = $confidence;
|
|
$matchingData['is_recommended'] = true;
|
|
$matchingData['is_recommended'] = true;
|
|
- $matchingData['recommendation_reason'] = $recommendation['reason'];
|
|
|
|
|
|
+ $matchingData['recommendation_reason'] = $reason;
|
|
} else {
|
|
} else {
|
|
- $matchingData['matching_score'] = max(0.3, 1 - $recommendation['confidence']);
|
|
|
|
- $matchingData['recommendation_reason'] = "AI推荐: {$recommendation['type_name']}";
|
|
|
|
|
|
+ $matchingData['matching_score'] = max(0.3, 1 - $confidence);
|
|
|
|
+ $matchingData['recommendation_reason'] = "AI推荐: {$typeName}";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|