diff --git a/app/admin/controller/v1/Article.php b/app/admin/controller/v1/Article.php index 4c4adf55..53ba5430 100644 --- a/app/admin/controller/v1/Article.php +++ b/app/admin/controller/v1/Article.php @@ -228,7 +228,7 @@ class Article private function getExportArticleData() { $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(['title', 'category_id', 'release_time']); $data = ArticleModel::field([ '*', @@ -253,7 +253,7 @@ class Article ]) ->bindAttr('category', ['category_name' => 'name']) ->each(function ($item) use($image_host) { - $item->image = !empty($item->image) ? $image_host . $item->image : ''; + $item->image = !empty($item->image) ? url_join($image_host, $item->image) : ''; return $item; }); diff --git a/app/admin/controller/v1/BannerItem.php b/app/admin/controller/v1/BannerItem.php index b1936dcc..3b196d14 100644 --- a/app/admin/controller/v1/BannerItem.php +++ b/app/admin/controller/v1/BannerItem.php @@ -262,11 +262,9 @@ class BannerItem // 获取导出数据 private function getBannerExportData() { - $param = request()->param([ - 'title', - 'banner_id', - 'created_at' - ]); + $server = request()->server(); + $image_host = $server['REQUEST_SCHEME'] . "://" . $server['SERVER_NAME'] . '/'; + $param = request()->param(['title', 'banner_id', 'created_at']); return SysBannerItemModel::alias('item') ->field([ 'item.id', @@ -311,7 +309,13 @@ class BannerItem } }) ->order(['item.sort' => 'asc', 'item.id' => 'desc']) - ->select(); + ->select() + ->each(function($item) use($image_host) { + $item->image = !empty($item->image) ? url_join($image_host, $item->image) : ''; + $item->extra_image = !empty($item->extra_image) ? url_join($image_host, $item->extra_image) : ''; + $item->video = !empty($item->video) ? url_join($image_host, $item->video) : ''; + return $item; + }); } // 删除 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/admin/controller/v1/Video.php b/app/admin/controller/v1/Video.php index 6ec0586b..c392424f 100644 --- a/app/admin/controller/v1/Video.php +++ b/app/admin/controller/v1/Video.php @@ -209,9 +209,6 @@ class Video ]); $domain = request()->domain(); - $image_path = Config::get('filesystem.disks.image.url'); - $video_path = Config::get('filesystem.disks.video.url'); - return VideoModel::withoutField([ 'language_id', 'updated_at', @@ -230,13 +227,9 @@ class Video ->select() ->bindAttr('category', ['category_name' => 'name']) ->hidden(['category_id', 'category']) - ->each(function ($item) use($domain, $image_path, $video_path) { - if (!empty($item->image)) { - $item->image = $domain . $image_path . '/' . $item->image; - } - if (!empty($item->video)) { - $item->video = $domain . $video_path . '/' . $item->video; - } + ->each(function ($item) use($domain) { + $item->image = !empty($item->image) ? url_join($domain, $item->image) : ''; + $item->video = !empty($item->video) ? url_join($domain, $item->video) : ''; $item->recommend = $item->recommend == 1 ? '是' : '否'; $item->status = $item->status == 1 ? '启用' : '禁用'; return $item; diff --git a/app/common.php b/app/common.php index 8ba851ef..f15ba098 100644 --- a/app/common.php +++ b/app/common.php @@ -155,7 +155,7 @@ if (!function_exists('get_filesystem_url')) { */ function get_filesystem_url(string $url, string $disk): string { - if (\think\helper\Str::startsWith($url, ['http://', 'https://'])) { + if (\think\helper\Str::startsWith($url, ['http://', 'https://', '//'])) { return $url; } if (empty($disk)) { @@ -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 diff --git a/app/index/view/mobile/attachment/video.html b/app/index/view/mobile/attachment/video.html index 71f4704d..39ca3a55 100644 --- a/app/index/view/mobile/attachment/video.html +++ b/app/index/view/mobile/attachment/video.html @@ -14,7 +14,7 @@
{notempty name="video_categorys"} {volist name="video_categorys" id="va"} -
{$va.name}
+
{$va.name}
{/volist} {/notempty}
diff --git a/app/index/view/mobile/public/footer.html b/app/index/view/mobile/public/footer.html index 1374d1ac..858a0624 100644 --- a/app/index/view/mobile/public/footer.html +++ b/app/index/view/mobile/public/footer.html @@ -29,12 +29,13 @@ {/notempty}
  • {:lang_i18n('联系方式')}

    - {notempty name="contact_config.website_email"} -

    {$contact_config.website_email.title}: {$contact_config.website_email.value}

    - {/notempty} - {notempty name="contact_config.website_hotline_office_hours"} -

    {$contact_config.website_hotline_office_hours.title}: {$contact_config.website_hotline_office_hours.value}

    - {/notempty} + {if condition="!empty($contact_config)"} + {volist name="contact_config" id="vo"} + {if condition="$vo.type != 'image'"} +

    {$vo.value}

    + {/if} + {/volist} + {/if}
  • diff --git a/app/index/view/pc/index/index.html b/app/index/view/pc/index/index.html index fc681983..b0bab1e6 100644 --- a/app/index/view/pc/index/index.html +++ b/app/index/view/pc/index/index.html @@ -117,8 +117,8 @@

    {$scene.desc|raw}

    {:lang_i18n('了解更多')} > --> +
    -
    {/volist} diff --git a/app/index/view/pc/public/footer.html b/app/index/view/pc/public/footer.html index 86821864..41bb2923 100644 --- a/app/index/view/pc/public/footer.html +++ b/app/index/view/pc/public/footer.html @@ -58,7 +58,7 @@ {else/} {$vo.value} - {/if} + {/if} {/volist} diff --git a/app/openapi/common.php b/app/openapi/common.php index e31187a6..c38dad1c 100644 --- a/app/openapi/common.php +++ b/app/openapi/common.php @@ -18,7 +18,7 @@ if (!function_exists('image_domain_concat')) { return $path; } - return rtrim($domain, '/') . '/' . ltrim($path, '/'); + return url_join($domain, $path); } } @@ -39,7 +39,7 @@ if (!function_exists('video_domain_concat')) { return $path; } - return rtrim($domain, '/') . '/' . ltrim($path, '/'); + return url_join($domain, $path); } }