diff --git a/service/Application/Admin/Controller/CommonController.class.php b/service/Application/Admin/Controller/CommonController.class.php index cc0771ab7..fa16348e0 100755 --- a/service/Application/Admin/Controller/CommonController.class.php +++ b/service/Application/Admin/Controller/CommonController.class.php @@ -484,7 +484,7 @@ class CommonController extends Controller // 存储图片 $temp_all = [ 'tmp_name' => $_FILES[$images_name]['tmp_name'][$i], - 'type' => $_FILES[$images_name]['type'][$i] + 'type' => $_FILES[$images_name]['type'][$i], ]; $original = $images_obj->GetOriginal($temp_all, $root_path.$img_path.'original'.$date); if(!empty($original)) @@ -507,6 +507,65 @@ class CommonController extends Controller return ['status'=>true, 'data'=>$result]; } + /** + * 商品图片集合处理 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-08-07 + * @desc description + * @param [array] $data [字段列表] + */ + protected function GetGoodsImagesParams($data) + { + $result = []; + if(!empty($data)) + { + // 定义图片目录 + $root_path = ROOT_PATH; + $img_path = 'Public'.DS.'Upload'.DS.'goods_images'.DS; + $date = DS.date('Y').DS.date('m').DS.date('d').DS; + + // 图像类库 + $images_obj = \Library\Images::Instance(['is_new_name'=>false]); + + foreach($data as $field) + { + $file = $_FILES[$field]; + + // 文件上传校验 + $error = FileUploadError($field); + if($error !== true) + { + return ['status'=>false, 'msg'=>$error]; + } + + // 存储图片 + $temp_all = [ + 'tmp_name' => $file['tmp_name'], + 'type' => $file['type'], + ]; + $original = $images_obj->GetOriginal($temp_all, $root_path.$img_path.'original'.$date); + if(!empty($original)) + { + // 根据原图再次生成小图 + $compr = $images_obj->GetBinaryCompress($root_path.$img_path.'original'.$date.$original, $root_path.$img_path.'compr'.$date, 600); + $small = $images_obj->GetBinaryCompress($root_path.$img_path.'original'.$date.$original, $root_path.$img_path.'small'.$date, 100, 100); + + if(!empty($compr)) + { + $result[$field] = DS.$img_path.'compr'.$date.$small; + } else { + // 如果图片格式有误,则删除原图片 + $this->ImagesDelete($img_path.'original'.$date.$original); + } + } + } + } + + return ['status'=>true, 'data'=>$result]; + } + /** * 图片删除 * @author Devil diff --git a/service/Application/Admin/Controller/GoodsController.class.php b/service/Application/Admin/Controller/GoodsController.class.php index 57e3815e7..6604a241f 100755 --- a/service/Application/Admin/Controller/GoodsController.class.php +++ b/service/Application/Admin/Controller/GoodsController.class.php @@ -177,13 +177,22 @@ class GoodsController extends CommonController $this->assign('region_province_list', M('Region')->where(['pid'=>0, 'is_enable'=>1])->select()); // 商品分类 - $field = 'id,name,icon'; - $category = M('GoodsCategory')->field($field)->where(['is_enable'=>1, 'pid'=>0])->order('sort asc')->select(); + $field = 'id,name'; + $m = M('GoodsCategory'); + $category = $m->field($field)->where(['is_enable'=>1, 'pid'=>0])->order('sort asc')->select(); if(!empty($category)) { foreach($category as &$v) { - $v['items'] = M('GoodsCategory')->field($field)->where(['is_enable'=>1, 'pid'=>$v['id']])->order('sort asc')->select(); + $two = $m->field($field)->where(['is_enable'=>1, 'pid'=>$v['id']])->order('sort asc')->select(); + if(!empty($two)) + { + foreach($two as &$vs) + { + $vs['items'] = $m->field($field)->where(['is_enable'=>1, 'pid'=>$vs['id']])->order('sort asc')->select(); + } + } + $v['items'] = $two; } } $this->assign('category_list', $category); @@ -270,6 +279,14 @@ class GoodsController extends CommonController $this->ajaxReturn($content_app['msg'], -1); } + // 集合主图片 + $images_field = ['file_home_recommended_images']; + $images = $this->GetGoodsImagesParams($images_field); + if($images['status'] === false) + { + $this->ajaxReturn($images['msg'], -1); + } + // 基础数据 $data = [ 'title' => I('title'), @@ -289,6 +306,7 @@ class GoodsController extends CommonController 'images' => isset($photo['data'][0]) ? $photo['data'][0] : '', 'photo_count' => count($photo['data']), 'is_home_recommended' => intval(I('is_home_recommended')), + 'home_recommended_images' => empty($images['data']['file_home_recommended_images']) ? '' : $images['data']['file_home_recommended_images'], ]; // 添加/编辑 diff --git a/service/Application/Admin/Lang/zh-cn/goods.php b/service/Application/Admin/Lang/zh-cn/goods.php index d4b5268ee..af7a40ea8 100755 --- a/service/Application/Admin/Lang/zh-cn/goods.php +++ b/service/Application/Admin/Lang/zh-cn/goods.php @@ -90,5 +90,10 @@ return array( 'goods_so_keyword_tips' => '标题/型号', + 'goods_category_level_two' => '二级', + 'goods_category_level_three' => '三级', + + 'goods_home_recommended_images_text'=> '首页推荐图片', + 'goods_home_recommended_images_tips'=> '留空则取相册第一张图', ); ?> \ No newline at end of file diff --git a/service/Application/Admin/View/Default/Express/Index.html b/service/Application/Admin/View/Default/Express/Index.html index 12fd8feae..c6af02103 100755 --- a/service/Application/Admin/View/Default/Express/Index.html +++ b/service/Application/Admin/View/Default/Express/Index.html @@ -27,7 +27,7 @@
-