fix: 后台 产品导出数据问题

This commit is contained in:
2025-08-06 11:40:09 +08:00
parent 1288ffd51b
commit ed7f274c6e
2 changed files with 49 additions and 5 deletions

View File

@@ -346,7 +346,7 @@ class Product
private function getExportProductData() private function getExportProductData()
{ {
$server = request()->server(); $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([ $param = request()->param([
'name', 'name',
'spu', 'spu',
@@ -360,10 +360,10 @@ class Product
'spu', 'spu',
'name', 'name',
'short_name', 'short_name',
'CONCAT("' . $image_host . '", `cover_image`)' => 'cover_image', 'cover_image',
'desc', 'desc',
'CONCAT("' . $image_host . '", `video_img`)' => 'video_img', 'video_img',
'CONCAT("' . $image_host . '", `video_url`)' => 'video_url', 'video_url',
'CASE WHEN is_new = 1 THEN "是" ELSE "否" END' => 'is_new', 'CASE WHEN is_new = 1 THEN "是" ELSE "否" END' => 'is_new',
'CASE WHEN is_hot = 1 THEN "是" ELSE "否" END' => 'is_hot', 'CASE WHEN is_hot = 1 THEN "是" ELSE "否" END' => 'is_hot',
'CASE WHEN is_sale = 1 THEN "是" ELSE "否" END' => 'is_sale', 'CASE WHEN is_sale = 1 THEN "是" ELSE "否" END' => 'is_sale',
@@ -390,7 +390,18 @@ class Product
->order(['id' => 'asc']) ->order(['id' => 'asc'])
->select() ->select()
->bindAttr('category', ['category_name' => 'name']) ->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()) { if (!$products->isEmpty()) {
// 产品参数 // 产品参数

View File

@@ -190,4 +190,37 @@ if (!function_exists('url_filesystem_detect')) {
return $url; 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;
}
} }