getBrandList(array('brand_apply' => '1')); $brands = $this->_tidyBrand($brand_c_list); extract($brands); ds_json_encode(10000, '', array('brand_l' => $brand_listchar, 'brand_c' => $brand_listnew, 'brand_class' => $brand_class, 'brand_r' => $brand_r_list)); } /** * 所有品牌全部显示在一级类目下,不显示二三级类目 * @param type $brand_c_list * @return type */ private function _tidyBrand($brand_c_list) { $brand_listnew = array(); #品牌分类下对应的品牌 $brand_listchar = array(); #品牌首字母下对应的品牌 $brand_class = array(); #品牌分类 $brand_r_list = array(); #推荐品牌 if (!empty($brand_c_list) && is_array($brand_c_list)) { $goods_class = model('goodsclass')->getGoodsclassForCacheModel(); foreach ($brand_c_list as $key => $brand_c) { $brand_c['brand_pic'] = brand_image($brand_c['brand_pic']); $gc_array = $this->_getTopClass($goods_class, $brand_c['gc_id']); if (empty($gc_array)) { $brand_listnew[0][] = $brand_c; $brand_class[0]['brand_class'] = lang('brand_index_other'); } else { $brand_listnew[$gc_array['gc_id']][] = $brand_c; $brand_class[$gc_array['gc_id']]['brand_class'] = $gc_array['gc_name']; } $brand_listchar[$brand_c['brand_initial']][] = $brand_c; //推荐品牌 if ($brand_c['brand_recommend'] == 1) { $brand_r_list[] = $brand_c; } } } krsort($brand_class); krsort($brand_listnew); ksort($brand_listchar); return array('brand_listchar' => $brand_listchar, 'brand_listnew' => $brand_listnew, 'brand_class' => $brand_class, 'brand_r_list' => $brand_r_list); } /** * 获取顶级商品分类\递归调用 * @param type $goods_class * @param type $gc_id * @return type */ private function _getTopClass($goods_class, $gc_id) { if (!isset($goods_class[$gc_id])) { return null; } if ($goods_class[$gc_id]['gc_parent_id'] == $gc_id) { //自身ID等于父ID return null; } if (isset($goods_class[$goods_class[$gc_id]['gc_parent_id']]['gc_parent_id']) && $goods_class[$goods_class[$gc_id]['gc_parent_id']]['gc_parent_id'] == $gc_id) { //父分类的父ID等于自身ID return null; } return $goods_class[$gc_id]['gc_parent_id'] == 0 ? $goods_class[$gc_id] : $this->_getTopClass($goods_class, $goods_class[$gc_id]['gc_parent_id']); } }