<?php
// +----------------------------------------------------------------------
// | Sunnyi 多语商城建站系统 (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.sunnyi.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 商易网络(admin@sunnyi.cn)
// +----------------------------------------------------------------------

//品牌
class BrandModel extends MultiLangModel  {
	/**
	 * 查询品牌列表
	 */
	public function getBrandList($condition='',$limit=10,$order='')
	{
		$list = $this->where($condition)->order($order)->limit($limit)->findAll();

		foreach($list as $k=>$v)
		{
			if(sunnyiC("URL_ROUTE")==1)
			$list[$k]['url'] = U("brand/".$v['id']);
			elseif(sunnyiC("URL_ROUTE")==2)
			{
				$arr = explode(" ",$v['name_'.FANWE_LANG_ID]);
				$url = '';
				$py = new Pinyin();
				foreach($arr as $idx => $ar)
				{
					$ar = $py->complie($ar);
					$prefix = "";
					$prefix = preg_replace("/\d/","",$ar);
					$prefix = preg_replace("/[^a-zA-Z-]/","",$prefix);
					$url.=$prefix.C("URL_PATHINFO_DEPR");
				}
				$url=strtolower($url);
				$list[$k]['url'] = 'b'.C("URL_PATHINFO_DEPR").$url.$v['id'].C("URL_HTML_SUFFIX"); 
			}
			else			
			$list[$k]['url'] = U("Brand/show",array('id'=>$v['id']));
			if($v['logo']=="")
			$list[$k]['logo'] = sunnyiC("NO_PIC");
	   		$list[$k]['count'] = D("Goods")->where("status=1 and brand_id=".$v['id'])->count();
		}
		return $list;
	}
	
	/**
	 * 查询单款品牌
	 */
	public function getBrandItem($condition='')
	{
		$item = $this->where($condition)->find();

		if(sunnyiC("URL_ROUTE")==1)
		$item['url'] = U("brand/".$item['id']);
		elseif(sunnyiC("URL_ROUTE")==2)
			{
				$arr = explode(" ",$item['name_'.FANWE_LANG_ID]);
				$url = '';
				$py = new Pinyin();
				foreach($arr as $idx => $ar)
				{
					$ar = $py->complie($ar);
					$prefix = "";
					$prefix = preg_replace("/\d/","",$ar);
					$prefix = preg_replace("/[^a-zA-Z-]/","",$prefix);
					$url.=$prefix.C("URL_PATHINFO_DEPR");
				}
				$url=strtolower($url);
				$item['url'] = 'b'.C("URL_PATHINFO_DEPR").$url.$item['id'].C("URL_HTML_SUFFIX"); 
			}
		else
		$item['url'] = U("Brand/show",array('id'=>$item['id']));
		if($item['logo']=="")
		$item['logo'] = sunnyiC("NO_PIC");
		
		$item['count'] = D("Goods")->where("status=1 and brand_id=".$item['id'])->count();
		
		return $item;
	}
}
?>