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); + } }