<?php
function smarty_function_channellist($params, &$smarty){
	if(empty($params)) $params['row']=0;
	extract($params);
	if(!isset($pid)) $pid=isset($_GET['cid'])?intval($_GET['cid']):'0';
	$sql=M('duotaopu');
	if(!isset($id)){
		$where=array('pid='.$pid,'and','isshow=1');
		$limit=isset($row)?($row-1):999;
		$data=$sql->select(array(
			'table'=>'shopclass',
			'where'=>$where,
			'limit'=>array('0',$limit),
			'orderby'=>array('order','DESC')
		));
		//如果没有下级分类则获取同级分类
		if(!$data && isset($type) && $type=='self'){
			$result=$sql->select(array(
				'table'=>'shopclass',
				'where'=>array('id='.$pid),
			));
			$pid=$result[0]['pid'];
			$where=array('pid='.$pid,'and','isshow=1');
			$data=$sql->select(array(
				'table'=>'shopclass',
				'where'=>$where,
				'limit'=>array('0',$limit),
				'orderby'=>array('order','DESC')
			));
		}
	}else{
		$where=array('id='.$id,'and','isshow=1');
		$data=$sql->select(array(
			'table'=>'shopclass',
			'where'=>$where,
		));
	}
	if($data){
		foreach($data as $k=>$vo){
			$data[$k]['url']=get_show_url('channel',$data[$k]['id'],1);
		}
		$smarty->assign('classlist',$data);
	}
}
?>