From 14be551526f07584c1dedd8e8886b15ceb1c73c5 Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Mon, 31 Oct 2022 14:32:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=A7=E5=93=81=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=B8=8D=E5=AD=98=E5=9C=A8=20=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Admin/Http/Resources/ProductResource.php | 3 ++- beike/Helpers.php | 11 ----------- beike/Services/ImageService.php | 4 ++++ 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/beike/Admin/Http/Resources/ProductResource.php b/beike/Admin/Http/Resources/ProductResource.php index 62b8cb40..ac332f5e 100644 --- a/beike/Admin/Http/Resources/ProductResource.php +++ b/beike/Admin/Http/Resources/ProductResource.php @@ -12,6 +12,7 @@ class ProductResource extends JsonResource * * @param Request $request * @return array + * @throws \Exception */ public function toArray($request): array { @@ -20,7 +21,7 @@ class ProductResource extends JsonResource $data = [ 'id' => $this->id, 'images' => array_map(function ($image) { - return thumbnail($image); + return image_resize($image); }, $this->images ?? []), 'name' => $this->description->name ?? '', 'price_formatted' => currency_format($masterSku->price), diff --git a/beike/Helpers.php b/beike/Helpers.php index 49f8fcd3..edefacbc 100644 --- a/beike/Helpers.php +++ b/beike/Helpers.php @@ -266,17 +266,6 @@ function current_customer(): ?Customer return auth()->guard(Customer::AUTH_GUARD)->user(); } -/** - * 获取缩略图 - * - * @param $path - * @return string - */ -function thumbnail($path): string -{ - return $path; -} - /** * 获取语言列表 * diff --git a/beike/Services/ImageService.php b/beike/Services/ImageService.php index 4e9ba5f1..9e6713dd 100644 --- a/beike/Services/ImageService.php +++ b/beike/Services/ImageService.php @@ -29,6 +29,10 @@ class ImageService { $this->image = $image ?: self::PLACEHOLDER_IMAGE; $this->imagePath = public_path($this->image); + if (!file_exists($this->imagePath)) { + $this->image = self::PLACEHOLDER_IMAGE; + $this->imagePath = public_path($this->image); + } }