|
|
@@ -48,6 +48,9 @@ class ProductReviewProcessor implements ProcessorInterface
|
|
|
if (method_exists($request, 'all')) {
|
|
|
$allData = $request->all();
|
|
|
|
|
|
+ // images / attachments 不是主表字段,先剔除,避免 fill 时污染模型属性
|
|
|
+ unset($allData['images'], $allData['attachments'], $allData['Images'], $allData['Attachments']);
|
|
|
+
|
|
|
$data->fill($allData);
|
|
|
|
|
|
// API Platform 使用 SnakeCaseToCamelCaseNameConverter,请求体字段会被
|
|
|
@@ -75,7 +78,25 @@ class ProductReviewProcessor implements ProcessorInterface
|
|
|
}
|
|
|
$this->validateReview($data);
|
|
|
|
|
|
- return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
|
|
+ $saved = $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
|
|
+
|
|
|
+ // REST 创建接口:处理图片上传(与 GraphQL handleCreate 保持一致)
|
|
|
+ if ($operation instanceof \ApiPlatform\Metadata\Post && $saved instanceof ProductReview) {
|
|
|
+ $request = $context['request'] ?? request();
|
|
|
+ $images = $request->input('images');
|
|
|
+ $attachmentsInput = $request->input('attachments');
|
|
|
+
|
|
|
+ if (! empty($images) && is_array($images)) {
|
|
|
+ $this->saveImagesToS3($images, $saved->id);
|
|
|
+ } elseif (! empty($attachmentsInput)) {
|
|
|
+ $this->saveAttachments(
|
|
|
+ is_array($attachmentsInput) ? json_encode($attachmentsInput) : $attachmentsInput,
|
|
|
+ $saved->id
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $saved;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -125,10 +146,6 @@ class ProductReviewProcessor implements ProcessorInterface
|
|
|
$attachments = $this->saveAttachments($data->attachments, $review->id);
|
|
|
}
|
|
|
|
|
|
- if ($attachments) {
|
|
|
- $review->setAttribute('attachments', json_encode($attachments));
|
|
|
- }
|
|
|
-
|
|
|
return $this->mapToOutput($review);
|
|
|
}
|
|
|
|
|
|
@@ -170,21 +187,14 @@ class ProductReviewProcessor implements ProcessorInterface
|
|
|
$review->save();
|
|
|
|
|
|
// 处理图片上传(新方式:使用 images 字段)
|
|
|
- $attachments = [];
|
|
|
-
|
|
|
if (! empty($data->images) && is_array($data->images)) {
|
|
|
- $attachments = $this->saveImagesToS3($data->images, $review->id);
|
|
|
+ $this->saveImagesToS3($data->images, $review->id);
|
|
|
} elseif (! empty($data->attachments)) {
|
|
|
// 向后兼容:使用旧的 attachments 字段(Base64格式)
|
|
|
- $attachments = $this->saveAttachments($data->attachments, $review->id);
|
|
|
+ $this->saveAttachments($data->attachments, $review->id);
|
|
|
}
|
|
|
|
|
|
- if ($attachments) {
|
|
|
- $review->setAttribute('attachments', json_encode($attachments));
|
|
|
- $review->save();
|
|
|
- }
|
|
|
-
|
|
|
- return $this->mapToOutput($review);
|
|
|
+ return $this->mapToOutput($review);
|
|
|
}
|
|
|
|
|
|
/**
|