提交 5fa361de 编写于 作者: G gongfuxiang

商品分类优化

上级 65046166
......@@ -135,7 +135,7 @@ class Goods extends Common
$this->assign('region_province_list', RegionService::RegionItems(['pid'=>0]));
// 商品分类
$this->assign('category_list', GoodsService::GoodsCategory());
$this->assign('category_list', GoodsService::GoodsCategoryAll());
// 品牌分类
$this->assign('brand_list', BrandService::CategoryBrand());
......
......@@ -56,7 +56,7 @@ class GoodsCategory extends Common
$this->assign('common_is_text_list', lang('common_is_text_list'));
// 商品分类
$this->assign('goods_category_list', GoodsService::GoodsCategory());
$this->assign('goods_category_list', GoodsService::GoodsCategoryAll());
// 编辑器文件存放地址
$this->assign('editor_path_type', 'goods_category');
......
......@@ -67,7 +67,7 @@ class Navigation extends Common
$this->assign('article_list', $article_category_content['data']);
// 商品分类
$this->assign('goods_category_list', GoodsService::GoodsCategory());
$this->assign('goods_category_list', GoodsService::GoodsCategoryAll());
// 自定义页面
$this->assign('customview_list', db('CustomView')->field(array('id', 'title'))->where(array('is_enable'=>1))->select());
......
......@@ -247,7 +247,7 @@ class Common extends Controller
$this->assign('user_left_menu', NavigationService::UsersCenterLeftList());
// 商品大分类
$this->assign('goods_category_list', GoodsService::GoodsCategory());
$this->assign('goods_category_list', GoodsService::GoodsCategoryAll());
// 搜索框下热门关键字
$home_search_keywords = [];
......
......@@ -223,7 +223,7 @@ class Admin extends Controller
$this->assign('goods', $goods['data']);
// 商品分类
$this->assign('goods_category_list', GoodsService::GoodsCategory());
$this->assign('goods_category_list', GoodsService::GoodsCategoryAll());
return $this->fetch('../../../plugins/view/answers/admin/goodsinfo');
}
......
......@@ -46,7 +46,7 @@ class GoodsService
}
/**
* 获取分类
* 获取所有分类
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
......@@ -54,7 +54,7 @@ class GoodsService
* @desc description
* @param [array] $params [输入参数]
*/
public static function GoodsCategory($params = [])
public static function GoodsCategoryAll($params = [])
{
// 从缓存获取
$key = config('shopxo.cache_goods_category_key');
......@@ -64,6 +64,27 @@ class GoodsService
return $data;
}
// 获取分类
$params['where'] = ['pid'=>0, 'is_enable'=>1];
$data = self::GoodsCategory($params);
// 存储缓存
cache($key, $data);
return $data;
}
/**
* 获取分类
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-08-29
* @desc description
* @param [array] $params [输入参数]
*/
public static function GoodsCategory($params = [])
{
// 获取分类
$where = empty($params['where']) ? ['pid'=>0, 'is_enable'=>1] : $params['where'];
$data = self::GoodsCategoryList($where);
......@@ -71,11 +92,13 @@ class GoodsService
{
foreach($data as &$v)
{
$v['items'] = self::GoodsCategoryList(['pid'=>$v['id'], 'is_enable'=>1]);
$where['pid'] = $v['id'];
$v['items'] = self::GoodsCategoryList($where);
if(!empty($v['items']))
{
// 一次性查出所有二级下的三级、再做归类、避免sql连接超多
$items = self::GoodsCategoryList(['pid'=>array_column($v['items'], 'id'), 'is_enable'=>1]);
$where['pid'] = array_column($v['items'], 'id');
$items = self::GoodsCategoryList($where);
if(!empty($items))
{
foreach($v['items'] as &$vs)
......@@ -92,10 +115,6 @@ class GoodsService
}
}
}
// 存储缓存
cache($key, $data);
return $data;
}
......@@ -160,7 +179,7 @@ class GoodsService
public static function HomeFloorList($params = [])
{
// 商品大分类
$params['where'] = ['pid'=>0, 'is_home_recommended'=>1];
$params['where'] = ['pid'=>0, 'is_home_recommended'=>1, 'is_enable'=>1];
$goods_category = self::GoodsCategory($params);
if(!empty($goods_category))
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册