|
@@ -334,7 +334,7 @@ class BodyProfile extends Api
|
|
$measurementFields = [
|
|
$measurementFields = [
|
|
'chest', 'waist', 'hip', 'thigh', 'calf', 'upper_arm', 'forearm',
|
|
'chest', 'waist', 'hip', 'thigh', 'calf', 'upper_arm', 'forearm',
|
|
'neck', 'shoulder_width', 'bust', 'underbust', 'inseam', 'outseam',
|
|
'neck', 'shoulder_width', 'bust', 'underbust', 'inseam', 'outseam',
|
|
- 'knee', 'arm_length', 'wrist', 'pants_length',
|
|
|
|
|
|
+ 'knee', 'arm_length', 'wrist', 'pants_length','belly_belt','leg_root',
|
|
'shoe_size', 'measurement_date'
|
|
'shoe_size', 'measurement_date'
|
|
];
|
|
];
|
|
|
|
|
|
@@ -350,9 +350,18 @@ class BodyProfile extends Api
|
|
$bodyTypeSelections = $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)) {
|
|
|
|
- $this->error('请至少提供测量数据或体型选择数据');
|
|
|
|
|
|
+ if (empty($measurementData) && empty($bodyTypeSelections) && empty($profileUpdateData)) {
|
|
|
|
+ $this->error('请至少提供测量数据、体型选择数据或档案更新数据');
|
|
}
|
|
}
|
|
|
|
|
|
// 验证测量数据(如果有)
|
|
// 验证测量数据(如果有)
|
|
@@ -376,12 +385,24 @@ class BodyProfile extends Api
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 验证档案更新数据(如果有)
|
|
|
|
+ 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 {
|
|
// try {
|
|
$result = BodyProfileService::saveMeasurementAndBodyType(
|
|
$result = BodyProfileService::saveMeasurementAndBodyType(
|
|
$params['profile_id'],
|
|
$params['profile_id'],
|
|
$this->auth->id,
|
|
$this->auth->id,
|
|
$measurementData ?: [], // 确保不是null
|
|
$measurementData ?: [], // 确保不是null
|
|
- $bodyTypeSelections ?: [] // 确保不是null
|
|
|
|
|
|
+ $bodyTypeSelections ?: [], // 确保不是null
|
|
|
|
+ $profileUpdateData ?: [] // 档案更新数据
|
|
);
|
|
);
|
|
|
|
|
|
$this->success('保存成功', $result);
|
|
$this->success('保存成功', $result);
|
|
@@ -389,4 +410,101 @@ class BodyProfile extends Api
|
|
// $this->error($e->getMessage());
|
|
// $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());
|
|
|
|
+ // }
|
|
|
|
+ }
|
|
}
|
|
}
|