商品封面图片优化

This commit is contained in:
devil 2020-08-11 21:26:43 +08:00
parent c7f5f4bf63
commit 5e89503a91
10 changed files with 40 additions and 50 deletions

View File

@ -151,12 +151,12 @@
</select>
</div>
<div class="am-form-group am-form-file">
<label class="block">首页推荐图片<span class="am-form-group-label-tips">留空则取相册第一张图</span></label>
<ul class="plug-file-upload-view goods-recommended-images-view" data-form-name="home_recommended_images" data-max-number="1" data-dialog-type="images">
{{if !empty($data['home_recommended_images'])}}
<label class="block">封面图片<span class="am-form-group-label-tips">留空则取相册第一张图</span></label>
<ul class="plug-file-upload-view goods-recommended-images-view" data-form-name="images" data-max-number="1" data-dialog-type="images">
{{if !empty($data['images'])}}
<li>
<input type="text" name="home_recommended_images" value="{{$data.home_recommended_images}}" />
<img src="{{$data.home_recommended_images}}" />
<input type="text" name="images" value="{{$data.images}}" />
<img src="{{$data.images}}" />
<i>×</i>
</li>
{{/if}}

View File

@ -128,7 +128,7 @@ class Goods extends Common
'is_home_recommended'=>1,
],
'order_by' => 'sales_count desc',
'field' => 'id,title,title_color,price,images,home_recommended_images',
'field' => 'id,title,title_color,price,images',
'n' => 16,
];
$like_goods = GoodsService::GoodsList($params);

View File

@ -582,7 +582,7 @@
<li>
<div class="i-pic limit">
<a href="{{:$v['goods_url']}}">
<img alt="{{$v.title}}" src="{{$v.home_recommended_images}}" />
<img alt="{{$v.title}}" src="{{$v.images}}" />
</a>
<a href="{{:$v['goods_url']}}">
<p class="am-text-truncate-2 am-margin-bottom-xs" {{if !empty($v.title_color)}}style="color:{{$v.title_color}};"{{/if}}>{{$v.title}}</p>

View File

@ -253,7 +253,7 @@
}
}
{{/php}}
<img src="{{$goods.home_recommended_images}}" alt="{{$goods.title}}" class="goods-images" />
<img src="{{$goods.images}}" alt="{{$goods.title}}" class="goods-images" />
</a>
<div class="outer-con">
<div class="goods-title am-text-truncate-2 am-margin-bottom-xs">

View File

@ -347,9 +347,34 @@ class GoodsService
$v['goods_url'] = MyUrl('index/goods/index', ['id'=>$v['id']]);
}
// 获取相册
if($is_photo && !empty($v['id']))
{
$v['photo'] = Db::name('GoodsPhoto')->where(['goods_id'=>$v['id'], 'is_show'=>1])->order('sort asc')->select();
if(!empty($v['photo']))
{
foreach($v['photo'] as &$vs)
{
$vs['images_old'] = $vs['images'];
$vs['images'] = ResourcesService::AttachmentPathViewHandle($vs['images']);
}
}
}
// 商品封面图片
if(isset($v['images']))
{
// 不存在则读取相册第一张图片
if(empty($v['images']))
{
// 是否已存在相册
if(empty($v['photo']) || empty($v['photo'][0]) || empty($v['photo'][0]['images_old']))
{
$v['images'] = Db::name('GoodsPhoto')->where(['goods_id'=>$v['id'], 'is_show'=>0])->order('sort asc')->value('images');
} else {
$v['images'] = $v['photo'][0]['images_old'];
}
}
$v['images_old'] = $v['images'];
$v['images'] = ResourcesService::AttachmentPathViewHandle($v['images']);
}
@ -361,27 +386,6 @@ class GoodsService
$v['video'] = ResourcesService::AttachmentPathViewHandle($v['video']);
}
// 商品首页推荐图片,不存在则使用商品封面图片
if(isset($v['home_recommended_images']))
{
if(empty($v['home_recommended_images']))
{
if(isset($v['images']))
{
$v['home_recommended_images'] = $v['images'];
} else {
if(!empty($v['id']))
{
$images = Db::name('Goods')->where(['id'=>$v['id']])->value('images');
$v['home_recommended_images'] = ResourcesService::AttachmentPathViewHandle($images);
}
}
} else {
$v['home_recommended_images_old'] = $v['home_recommended_images'];
$v['home_recommended_images'] = ResourcesService::AttachmentPathViewHandle($v['home_recommended_images']);
}
}
// PC内容处理
if(isset($v['content_web']))
{
@ -424,20 +428,6 @@ class GoodsService
$v['category_text'] = implode('', $category_name);
}
// 获取相册
if($is_photo && !empty($v['id']))
{
$v['photo'] = Db::name('GoodsPhoto')->where(['goods_id'=>$v['id'], 'is_show'=>1])->order('sort asc')->select();
if(!empty($v['photo']))
{
foreach($v['photo'] as &$vs)
{
$vs['images_old'] = $vs['images'];
$vs['images'] = ResourcesService::AttachmentPathViewHandle($vs['images']);
}
}
}
// 规格基础
if(isset($v['spec_base']))
{
@ -790,7 +780,7 @@ class GoodsService
}
// 其它附件
$data_fields = ['home_recommended_images', 'video'];
$data_fields = ['images', 'video'];
$attachment = ResourcesService::AttachmentParams($params, $data_fields);
if($attachment['code'] != 0)
{
@ -821,7 +811,7 @@ class GoodsService
'images' => isset($photo['data'][0]) ? $photo['data'][0] : '',
'photo_count' => count($photo['data']),
'is_home_recommended' => isset($params['is_home_recommended']) ? intval($params['is_home_recommended']) : 0,
'home_recommended_images' => $attachment['data']['home_recommended_images'],
'images' => $attachment['data']['images'],
'brand_id' => isset($params['brand_id']) ? intval($params['brand_id']) : 0,
'video' => $attachment['data']['video'],
'seo_title' => empty($params['seo_title']) ? '' : $params['seo_title'],

View File

@ -48,7 +48,7 @@
<view class="goods-list" a:if="{{floor.goods.length > 0}}">
<view a:for="{{floor.goods}}" a:for-item="goods" class="goods bg-white">
<navigator url="/pages/goods-detail/goods-detail?goods_id={{goods.id}}" hover-class="none">
<image src="{{goods.home_recommended_images}}" mode="aspectFit" />
<image src="{{goods.images}}" mode="aspectFit" />
<view class="goods-base">
<view class="goods-title single-text">{{goods.title}}</view>
<view class="sales-price">{{price_symbol}}{{goods.min_price}}</view>

View File

@ -48,7 +48,7 @@
<view class="goods-list" s-if="floor.goods.length > 0">
<view s-for="goods, index in floor.goods" s-key="keys" class="goods bg-white">
<navigator url="/pages/goods-detail/goods-detail?goods_id={{goods.id}}" hover-class="none">
<image src="{{goods.home_recommended_images}}" mode="aspectFit" />
<image src="{{goods.images}}" mode="aspectFit" />
<view class="goods-base">
<view class="goods-title single-text">{{goods.title}}</view>
<view class="sales-price">{{price_symbol}}{{goods.min_price}}</view>

View File

@ -48,7 +48,7 @@
<view class="goods-list" qq:if="{{floor.goods.length > 0}}">
<view qq:for="{{floor.goods}}" qq:key="keys" qq:for-item="goods" class="goods bg-white">
<navigator url="/pages/goods-detail/goods-detail?goods_id={{goods.id}}" hover-class="none">
<image src="{{goods.home_recommended_images}}" mode="aspectFit" />
<image src="{{goods.images}}" mode="aspectFit" />
<view class="goods-base">
<view class="goods-title single-text">{{goods.title}}</view>
<view class="sales-price">{{price_symbol}}{{goods.min_price}}</view>

View File

@ -51,7 +51,7 @@
<view class="goods-list" tt:if="{{floor.goods.length > 0}}">
<view tt:for="{{floor.goods}}" tt:key="keys" tt:for-item="goods" class="goods bg-white">
<navigator url="/pages/goods-detail/goods-detail?goods_id={{goods.id}}" hover-class="none">
<image src="{{goods.home_recommended_images}}" mode="aspectFit" />
<image src="{{goods.images}}" mode="aspectFit" />
<view class="goods-base">
<view class="goods-title single-text">{{goods.title}}</view>
<view class="sales-price">{{price_symbol}}{{goods.min_price}}</view>

View File

@ -48,7 +48,7 @@
<view class="goods-list" wx:if="{{floor.goods.length > 0}}">
<view wx:for="{{floor.goods}}" wx:key="keys" wx:for-item="goods" class="goods bg-white">
<navigator url="/pages/goods-detail/goods-detail?goods_id={{goods.id}}" hover-class="none">
<image src="{{goods.home_recommended_images}}" mode="aspectFit" />
<image src="{{goods.images}}" mode="aspectFit" />
<view class="goods-base">
<view class="goods-title single-text">{{goods.title}}</view>
<view class="sales-price">{{price_symbol}}{{goods.min_price}}</view>