提交 7b54a3c4 编写于 作者: G gongfuxiang

商品规格图片优化

上级 7f710915
...@@ -171,8 +171,7 @@ class Common extends Controller ...@@ -171,8 +171,7 @@ class Common extends Controller
{ {
exit(json_encode(DataReturn($name.' 非法访问', -1000))); exit(json_encode(DataReturn($name.' 非法访问', -1000)));
} else { } else {
$this->assign('msg', $name.' 非法访问'); exit($name.' 非法访问');
return $this->fetch('public/error');
} }
} }
} }
......
...@@ -28,8 +28,7 @@ class Error extends Common ...@@ -28,8 +28,7 @@ class Error extends Common
{ {
exit(json_encode(DataReturn($request->controller().' 控制器不存在', -1000))); exit(json_encode(DataReturn($request->controller().' 控制器不存在', -1000)));
} else { } else {
$this->assign('msg', $request->controller().' 控制器不存在'); exit($request->controller().' 控制器不存在');
return $this->fetch('public/error');
} }
} }
} }
......
...@@ -255,23 +255,29 @@ ...@@ -255,23 +255,29 @@
<span class="business-operations-submit specifications-line-add">+添加一行</span> <span class="business-operations-submit specifications-line-add">+添加一行</span>
<span class="business-operations-submit specifications-line-images-add m-l-10">+添加规格图片</span> <span class="business-operations-submit specifications-line-images-add m-l-10">+添加规格图片</span>
<ul class="spec-images-list"> <ul class="spec-images-list">
{{if !empty($specifications['images'])}}
<div class="am-alert am-alert-warning am-radius" data-am-alert> <div class="am-alert am-alert-warning am-radius" data-am-alert>
<button type="button" class="am-close">&times;</button> <button type="button" class="am-close">&times;</button>
<p class="fs-12">规格名称与规格值保持一致,相同规格名称添加一次即可,重复添加则后面覆盖前面,顺序不影响前端展示效果。</p> <p class="fs-12">规格名称与规格值保持一致,相同规格名称添加一次即可,重复添加则后面覆盖前面,顺序不影响前端展示效果。</p>
</div> </div>
{{foreach $specifications.images as $spec_images}} {{if !empty($specifications['type'])}}
<li class="spec-images-items spec-images-items-{{$spec_images.id}}"> {{foreach $specifications.type as $type}}
<input type="text" name="spec_images_name[{{$spec_images.id}}]" placeholder="规格名称" class="am-radius t-c" data-validation-message="请填写规格名称" value="{{$spec_images.name}}" required > {{if !empty($type['value'])}}
<ul class="plug-file-upload-view spec-images-view-{{$spec_images.id}}" data-form-name="spec_images[{{$spec_images.id}}]" data-max-number="1" data-delete='0' data-dialog-type="images"> {{foreach $type.value as $spec_key=>$spec}}
<li> {{if !empty($spec['images'])}}
<input type="hidden" name="spec_images[{{$spec_images.id}}]" value="{{$spec_images.images_old}}" data-validation-message="请上传规格图片" required /> <li class="spec-images-items spec-images-items-{{$type.id}}{{$spec_key}}">
<img src="{{$spec_images.images}}" /> <input type="text" name="spec_images_name[{{$type.id}}{{$spec_key}}]" placeholder="规格名称" class="am-radius t-c" data-validation-message="请填写规格名称" value="{{$spec.name}}" required >
<i>×</i> <ul class="plug-file-upload-view spec-images-view-{{$type.id}}{{$spec_key}}" data-form-name="spec_images[{{$type.id}}{{$spec_key}}]" data-max-number="1" data-delete='0' data-dialog-type="images">
</li> <li>
</ul> <input type="hidden" name="spec_images[{{$type.id}}{{$spec_key}}]" value="{{$spec.images_old}}" data-validation-message="请上传规格图片" required />
<div class="plug-file-upload-submit" data-view-tag="ul.spec-images-view-{{$spec_images.id}}">+上传图片</div> <img src="{{$spec.images}}" />
</li> <i>×</i>
</li>
</ul>
<div class="plug-file-upload-submit" data-view-tag="ul.spec-images-view-{{$type.id}}{{$spec_key}}">+上传图片</div>
</li>
{{/if}}
{{/foreach}}
{{/if}}
{{/foreach}} {{/foreach}}
{{/if}} {{/if}}
</ul> </ul>
......
{{include file="public/header" /}} {{include file="public/header" /}}
<!-- nav start -->
{{include file="public/nav" /}}
<!-- nav end -->
<!-- header top nav --> <!-- header top nav -->
{{include file="public/header_top_nav" /}} {{include file="public/header_top_nav" /}}
......
...@@ -144,11 +144,11 @@ ...@@ -144,11 +144,11 @@
<div class="cart-title">{{$spec.name}}</div> <div class="cart-title">{{$spec.name}}</div>
<ul> <ul>
{{foreach $spec.value as $keys=>$specs}} {{foreach $spec.value as $keys=>$specs}}
<li class="sku-line {{if !empty($goods['specifications']['images'][$specs])}} sku-line-images{{/if}} {{if $key gt 0}} sku-dont-choose{{/if}}" data-type-value="{{$spec.name}}" data-value="{{$specs}}" {{if !empty($goods['specifications']['images'][$specs])}} data-type-images="{{$goods.specifications.images[$specs]}}"{{/if}}> <li class="sku-line {{if !empty($specs['images'])}} sku-line-images{{/if}} {{if $key gt 0}} sku-dont-choose{{/if}}" data-type-value="{{$spec.name}}" data-value="{{$specs.name}}" {{if !empty($specs['images'])}} data-type-images="{{$specs.images}}"{{/if}}>
{{if !empty($goods['specifications']['images'][$specs])}} {{if !empty($specs['images'])}}
<img src="{{$goods.specifications.images[$specs]}}" /> <img src="{{$specs.images}}" />
{{/if}} {{/if}}
{{$specs}}<i></i> {{$specs.name}}<i></i>
</li> </li>
{{/foreach}} {{/foreach}}
</ul> </ul>
......
{{include file="public/header" /}} {{include file="public/header" /}}
<!-- nav start -->
{{include file="public/nav" /}}
<!-- nav end -->
<!-- header top nav --> <!-- header top nav -->
{{include file="public/header_top_nav" /}} {{include file="public/header_top_nav" /}}
......
{{include file="public/header" /}} {{include file="public/header" /}}
<!-- nav start -->
{{include file="public/nav" /}}
<!-- nav end -->
<!-- header top nav --> <!-- header top nav -->
{{include file="public/header_top_nav" /}} {{include file="public/header_top_nav" /}}
......
...@@ -371,25 +371,20 @@ class GoodsService ...@@ -371,25 +371,20 @@ class GoodsService
$type = Db::name('GoodsSpecType')->where($where)->order('id asc')->select(); $type = Db::name('GoodsSpecType')->where($where)->order('id asc')->select();
if(!empty($type)) if(!empty($type))
{ {
// 数据处理
$images_host = config('images_host');
foreach($type as &$temp_type) foreach($type as &$temp_type)
{ {
$temp_type['value'] = json_decode($temp_type['value'], true); $temp_type_value = json_decode($temp_type['value'], true);
foreach($temp_type_value as &$vs)
{
$vs['images'] = empty($vs['images']) ? '' : $images_host.$vs['images'];
}
$temp_type['value'] = $temp_type_value;
$temp_type['add_time'] = date('Y-m-d H:i:s'); $temp_type['add_time'] = date('Y-m-d H:i:s');
} }
} }
return ['type'=>$type];
// 规格图片
$images = Db::name('GoodsSpecImages')->where($where)->column('name,images');
if(!empty($images))
{
$images_host = config('images_host');
foreach($images as &$temp_iamges)
{
$temp_iamges = $images_host.$temp_iamges;
}
}
return ['type'=>$type, 'images'=>$images];
} }
/** /**
...@@ -1155,13 +1150,9 @@ class GoodsService ...@@ -1155,13 +1150,9 @@ class GoodsService
{ {
if(!empty($params['spec_images'][$k])) if(!empty($params['spec_images'][$k]))
{ {
$images[$v] = [ $images[$v] = $params['spec_images'][$k];
'name' => $v,
'images' => $params['spec_images'][$k],
];
} }
} }
$images = array_values($images);
} }
return DataReturn('success', 0, ['data'=>$data, 'title'=>$title, 'images'=>$images]); return DataReturn('success', 0, ['data'=>$data, 'title'=>$title, 'images'=>$images]);
...@@ -1344,15 +1335,22 @@ class GoodsService ...@@ -1344,15 +1335,22 @@ class GoodsService
Db::name('GoodsSpecType')->where(['goods_id'=>$goods_id])->delete(); Db::name('GoodsSpecType')->where(['goods_id'=>$goods_id])->delete();
Db::name('GoodsSpecValue')->where(['goods_id'=>$goods_id])->delete(); Db::name('GoodsSpecValue')->where(['goods_id'=>$goods_id])->delete();
Db::name('GoodsSpecBase')->where(['goods_id'=>$goods_id])->delete(); Db::name('GoodsSpecBase')->where(['goods_id'=>$goods_id])->delete();
Db::name('GoodsSpecImages')->where(['goods_id'=>$goods_id])->delete();
// 类型 // 类型
if(!empty($data['title'])) if(!empty($data['title']))
{ {
foreach($data['title'] as &$v) foreach($data['title'] as &$v)
{ {
$spec = [];
foreach($v['value'] as $vs)
{
$spec[] = [
'name' => $vs,
'images' => isset($data['images'][$vs]) ? ResourcesService::AttachmentPathHandle($data['images'][$vs]) : '',
];
}
$v['goods_id'] = $goods_id; $v['goods_id'] = $goods_id;
$v['value'] = json_encode(array_values($v['value'])); $v['value'] = json_encode($spec);
$v['add_time'] = time(); $v['add_time'] = time();
} }
if(Db::name('GoodsSpecType')->insertAll($data['title']) < count($data['title'])) if(Db::name('GoodsSpecType')->insertAll($data['title']) < count($data['title']))
...@@ -1432,25 +1430,6 @@ class GoodsService ...@@ -1432,25 +1430,6 @@ class GoodsService
} }
} }
// 规格图片
if(!empty($data['images']))
{
$images = [];
foreach($data['images'] as $v)
{
$images[] = [
'goods_id' => $goods_id,
'name' => $v['name'],
'images' => ResourcesService::AttachmentPathHandle($v['images']),
'add_time' => time(),
];
}
if(Db::name('GoodsSpecImages')->insertAll($images) < count($images))
{
return DataReturn('规格图片添加失败', -1);
}
}
return DataReturn('添加成功', 0); return DataReturn('添加成功', 0);
} }
...@@ -1578,11 +1557,19 @@ class GoodsService ...@@ -1578,11 +1557,19 @@ class GoodsService
if(!empty($type)) if(!empty($type))
{ {
// 数据处理 // 数据处理
foreach($type as &$v) $images_host = config('images_host');
foreach($type as &$temp_type)
{ {
$v['value'] = json_decode($v['value'], true); $temp_type_value = json_decode($temp_type['value'], true);
foreach($temp_type_value as &$vs)
{
$vs['images_old'] = $vs['images'];
$vs['images'] = empty($vs['images']) ? '' : $images_host.$vs['images'];
}
$temp_type['value'] = $temp_type_value;
} }
// 获取规格值 // 获取规格值
$temp_value = Db::name('GoodsSpecValue')->where($where)->field('goods_spec_base_id,value')->order('id asc')->select(); $temp_value = Db::name('GoodsSpecValue')->where($where)->field('goods_spec_base_id,value')->order('id asc')->select();
if(!empty($temp_value)) if(!empty($temp_value))
...@@ -1592,10 +1579,13 @@ class GoodsService ...@@ -1592,10 +1579,13 @@ class GoodsService
$key = ''; $key = '';
foreach($type as $type_v) foreach($type as $type_v)
{ {
if(in_array($value_v['value'], $type_v['value'])) foreach($type_v['value'] as $type_vs)
{ {
$key = $type_v['id']; if($type_vs['name'] == $value_v['value'])
break; {
$key = $type_v['id'];
break;
}
} }
} }
$value[$value_v['goods_spec_base_id']][] = [ $value[$value_v['goods_spec_base_id']][] = [
...@@ -1627,22 +1617,9 @@ class GoodsService ...@@ -1627,22 +1617,9 @@ class GoodsService
]; ];
} }
// 规格图片
$images = Db::name('GoodsSpecImages')->where($where)->select();
if(!empty($images))
{
$images_host = config('images_host');
foreach($images as &$temp_iamges)
{
$temp_iamges['images_old'] = $temp_iamges['images'];
$temp_iamges['images'] = $images_host.$temp_iamges['images'];
}
}
return [ return [
'type' => $type, 'type' => $type,
'value' => array_values($value), 'value' => array_values($value),
'images' => $images,
]; ];
} }
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册