table('category_item')->where(array('enable' => '1'))->order('sort asc')->select(); $result = array(); foreach ($category_list as $value) { $item['id'] = $value['id']; $item['name'] = $value['name']; $item['type'] = $value['category_type']; $item['gc_id'] = $value['gc_id']; array_push($result, $item); } joutput_data(array("category" => $result)); } /** * 此时需要带图片了 */ public function category_list_2Op() { $category_list = Model()->table('category_item')->where(array('category_type' => 'keyword', 'enable' => '1'))->order('sort asc')->select(); $result = array(); foreach ($category_list as $value) { $item['id'] = $value['id']; $item['name'] = $value['name']; $item['type'] = $value['category_type']; $item['gc_id'] = $value['gc_id']; $item['img'] = $this->_formatPic($value['img']); // 子查询 $child_list = Model()->table('goods_class')->where(array('gc_parent_id' => $value['gc_id']))->select(); $child = array(); foreach ($child_list as $child_value) { $child_item['id'] = $child_value['gc_id']; $child_item['gc_name'] = $child_value['gc_name']; $child_item['gc_id'] = $child_value['gc_id']; array_push($child, $child_item); } $item['child_item'] = $child; array_push($result, $item); } joutput_data(array("category" => $result)); } /** * 添加图片路径 */ private function _formatPic($filename) { if (!isset($filename) || empty($filename)) { return ''; } return UPLOAD_SITE_URL . '/shop/class/' . $filename; } }