From 1802f5790602e7c5a924eedbb3f664d308588deb Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Wed, 6 Aug 2025 11:40:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=90=8E=E5=8F=B0=20=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=95=B0=E6=8D=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/v1/Product.php | 21 +++++++++++++----- app/common.php | 33 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/app/admin/controller/v1/Product.php b/app/admin/controller/v1/Product.php index 83c561f0..3b635255 100644 --- a/app/admin/controller/v1/Product.php +++ b/app/admin/controller/v1/Product.php @@ -346,7 +346,7 @@ class Product private function getExportProductData() { $server = request()->server(); - $image_host = $server['REQUEST_SCHEME'] . "://" . $server['SERVER_NAME'] . config('filesystem.disks.public.url') . '/'; + $image_host = $server['REQUEST_SCHEME'] . "://" . $server['SERVER_NAME'] . '/'; $param = request()->param([ 'name', 'spu', @@ -360,10 +360,10 @@ class Product 'spu', 'name', 'short_name', - 'CONCAT("' . $image_host . '", `cover_image`)' => 'cover_image', + 'cover_image', 'desc', - 'CONCAT("' . $image_host . '", `video_img`)' => 'video_img', - 'CONCAT("' . $image_host . '", `video_url`)' => 'video_url', + 'video_img', + 'video_url', 'CASE WHEN is_new = 1 THEN "是" ELSE "否" END' => 'is_new', 'CASE WHEN is_hot = 1 THEN "是" ELSE "否" END' => 'is_hot', 'CASE WHEN is_sale = 1 THEN "是" ELSE "否" END' => 'is_sale', @@ -390,7 +390,18 @@ class Product ->order(['id' => 'asc']) ->select() ->bindAttr('category', ['category_name' => 'name']) - ->hidden(['category_id', 'category']); + ->hidden(['category_id', 'category']) + ->each(function($item) use($image_host) { + if (!empty($item["cover_image"])) { + $item["cover_image"] = url_join($image_host, $item["cover_image"]); + } + if (!empty($item["video_img"])) { + $item["video_img"] = url_join($image_host, $item["video_img"]); + } + if (!empty($item["video_url"])) { + $item["video_url"] = url_join($image_host, $item["video_url"]); + } + }); if (!$products->isEmpty()) { // 产品参数 diff --git a/app/common.php b/app/common.php index 5e356e96..f15ba098 100644 --- a/app/common.php +++ b/app/common.php @@ -190,4 +190,37 @@ if (!function_exists('url_filesystem_detect')) { return $url; } +} + +if (!function_exists('url_join')) { + /** + * 合并URL + * @param string $url 基础URL + * @param string $path 路径 + * @param bool $remove_slash 是否移除首尾的斜杠 + * @return string + */ + function url_join(string $url, string $path, bool $remove_slash = true): string + { + if (empty($url)) { + return $path; + } + if (empty($path)) { + return $url; + } + if (\think\helper\Str::startsWith($path, ['http://', 'https://', '//'])) { + return $path; + } + + if ($remove_slash) { + if (str_ends_with($url, '/') && str_starts_with($path, '/')) { + return $url . substr($path, 1); + } + if (!str_ends_with($url, '/') && !str_starts_with($path, '/')) { + return $url . '/' . $path; + } + } + + return $url . $path; + } } \ No newline at end of file