getAll($sql); $cat_arr = array(); foreach ($res as $row) { if ($row['if_view']) { $cat_arr[$row['catid']]['catid'] = $row['catid']; $cat_arr[$row['catid']]['catname'] = $row['catname']; $cat_arr[$row['catid']]['color'] = $row['color']; $cat_arr[$row['catid']]['if_view'] = $row['if_view']; $cat_arr[$row['catid']]['uri'] = Rewrite('goods', array('catid' => $row['catid'])); if ($row['childid'] != NULL) { $cat_arr[$row['catid']]['children'][$row['childid']]['catid'] = $row['childid']; $cat_arr[$row['catid']]['children'][$row['childid']]['catname'] = $row['childname']; $cat_arr[$row['catid']]['children'][$row['childid']]['if_view'] = $row['if_view']; $cat_arr[$row['catid']]['children'][$row['childid']]['color'] = $row['childcolor']; $cat_arr[$row['catid']]['children'][$row['childid']]['uri'] = Rewrite('goods', array('catid' => $row['childid'])); } } } write_static_cache('goods_category_tree', $cat_arr); } else { $cat_arr = $data; } } else { if ($data === NULL || empty($data[$catid])) { $bif_view = $ifview == '2' || $ifview == '1' ? ' AND b.if_view = \'' . $ifview . '\'' : ''; $parentid = $GLOBALS['db']->getOne('SELECT parentid FROM `' . $GLOBALS['db_mymps'] . 'goods_category` WHERE catid = \'' . $catid . '\''); if ($parentid == 0) { $sql = 'SELECT a.catid, a.catname, a.catorder, a.if_view, b.catid AS childid, b.catname AS childname, b.catorder AS childorder FROM `' . $GLOBALS['db_mymps'] . 'goods_category` AS a LEFT JOIN `' . $GLOBALS['db_mymps'] . 'goods_category` AS b ON b.parentid = a.catid ' . $bif_view . ' WHERE a.catid = \'' . $catid . '\' ORDER BY catorder ASC , catid ASC, childorder ASC'; } else { $sql = 'SELECT a.catid, a.catname, a.catorder, a.if_view, a.html_dir, a.htmlpath, b.catid AS childid, b.catname AS childname, b.catorder AS childorder FROM `' . $GLOBALS['db_mymps'] . 'goods_category` AS a LEFT JOIN `' . $GLOBALS['db_mymps'] . 'goods_category` AS b ON b.parentid = a.catid ' . $bif_view . ' WHERE b.parentid = \'' . $parentid . '\' ORDER BY catorder ASC , catid ASC, childorder ASC'; } $res = $GLOBALS['db']->getAll($sql); $cat_arr = array(); foreach ($res as $row) { if ($row['if_view']) { $cat_arr[$row['catid']]['catid'] = $row['catid']; $cat_arr[$row['catid']]['catname'] = $row['catname']; $cat_arr[$row['catid']]['catorder'] = $row['catorder']; $cat_arr[$row['catid']]['if_view'] = $row['if_view']; $cat_arr[$row['catid']]['uri'] = Rewrite('goods', array('catid' => $row['catid'])); if ($row['childid'] != NULL) { $cat_arr[$row['catid']]['children'][$row['childid']]['catid'] = $row['childid']; $cat_arr[$row['catid']]['children'][$row['childid']]['catname'] = $row['childname']; $cat_arr[$row['catid']]['children'][$row['childid']]['if_view'] = $row['if_view']; $cat_arr[$row['catid']]['children'][$row['childid']]['catorder'] = $row['childorder']; $cat_arr[$row['catid']]['children'][$row['childid']]['uri'] = Rewrite('goods', array('catid' => $row['childid'])); } } } } else { $cat_arr[] = $data[$catid]; } } return $cat_arr; } function goods_cat_list($catid = 0, $selected = 0, $re_type = true, $level = 0, $is_show_all = true) { global $seoset; $data = read_static_cache('goods_category_pid_releate'); if ($data === false) { $sql = 'SELECT c.catid, c.catname, c.parentid, c.if_view, c.catorder, COUNT(s.catid) AS has_children FROM `' . $GLOBALS['db_mymps'] . 'goods_category` AS c LEFT JOIN `' . $GLOBALS['db_mymps'] . 'goods_category` AS s ON s.parentid=c.catid GROUP BY c.catid ORDER BY c.parentid, c.catorder ASC'; $res = $GLOBALS['db']->getAll($sql); $sql = NULL; $newres = array(); if (count($res) <= 1000) { write_static_cache('goods_category_pid_releate', $res); } } else { $res = $data; } if (empty($res) == true) { return $re_type ? '' : array(); } $options = goods_cat_options($catid, $res); $children_level = 99999; if ($is_show_all == false) { foreach ($options as $key => $val) { if ($children_level < $val['level']) { unset($options[$key]); } else if ($val['is_show'] == 0) { unset($options[$key]); if ($val['level'] < $children_level) { $children_level = $val['level']; } } else { $children_level = 99999; } } } if (0 < $level) { if ($catid == 0) { $end_level = $level; } else { $first_item = reset($options); $end_level = $first_item['level'] + $level; } foreach ($options as $key => $val) { if ($end_level <= $val['level']) { unset($options[$key]); } } } if ($re_type == true) { $select = ''; foreach ($options as $var) { $select .= '