Esempio n. 1
0
 function getCateArray($cate_type, $pid)
 {
     if ($cate_type == 0) {
         $table_name = DB_PREFIX . 'deal_cate';
     } else {
         if ($cate_type == 1) {
             $table_name = DB_PREFIX . 'shop_cate';
         } else {
             if ($cate_type == 2) {
                 $table_name = DB_PREFIX . 'event_cate';
             }
         }
     }
     if ($cate_type == 2) {
         $sql = "select id,name,0 as pid, '' as py, '' as icon, 0 as has_child from " . $table_name . " where is_effect =1 ";
         //echo $sql ;exit;
         $tree_list = $GLOBALS['db']->getAll($sql);
     } else {
         $sql = "select id,name,pid,uname as py, '' as icon from " . $table_name . " where is_effect =1 and is_delete =0 and pid = " . $pid;
         $list = $GLOBALS['db']->getAll($sql);
         foreach ($list as $k => $v) {
             $count = intval($GLOBALS['db']->getOne("select count(*) from " . $table_name . " where is_effect =1 and is_delete =0 and pid = " . $v['id']));
             if ($count > 0) {
                 $list[$k]['has_child'] = 1;
             } else {
                 $list[$k]['has_child'] = 0;
             }
         }
         $tree_list = m_toTree($list, "id", "pid", "child");
     }
     if ($pid == 0) {
         $all = array();
         $all[] = array("id" => 0, "name" => "全部分类", pid => 0, py => "", icon => "", has_child => 0);
         $tree_list = array_merge($all, $tree_list);
         return $tree_list;
     } else {
         return $tree_list;
     }
 }
Esempio n. 2
0
function getCatalogArraySearch()
{
    $list = $GLOBALS['cache']->get("m_CATELISTSEARCH");
    if ($list === false) {
        $sql = "select id,name,pid,uname as py,icon from " . DB_PREFIX . "deal_cate";
        $list = $GLOBALS['db']->getAll($sql);
        foreach ($list as $k => $v) {
            $count = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_cate where pid = " . $v['id']));
            if ($count > 0) {
                $list[$k]['has_child'] = 1;
                $child = new m_child("deal_cate");
                $ids = $child->getChildIds($v['id'], $pk_str = 'id', $pid_str = 'pid');
                $ids[] = 0;
                $child_list = $GLOBALS['db']->getAll("select id,name,pid,uname as py  from " . DB_PREFIX . "deal_cate where id in (" . implode(",", $ids) . ")");
                foreach ($child_list as $kk => $vv) {
                    $count = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_cate where pid = " . $vv['id']));
                    if ($count > 0) {
                        $child_list[$kk]['has_child'] = 1;
                    } else {
                        $child_list[$kk]['has_child'] = 0;
                    }
                }
                $list[$k]['child'] = m_toTree($child_list, "id", "pid", "child");
            } else {
                $list[$k]['has_child'] = 0;
            }
        }
        $GLOBALS['cache']->set("m_CATELISTSEARCH", $list);
    }
    return $list;
}