<?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 GoodsCateModel extends MultiLangModel  {
	/**
	 * 查询商品列表
	 */
	public function getGoodsCateList($condition='',$order='sort desc',$limit)
	{
		$curr_lang_id = D("LangConf")->where("lang_name ='".FANWE_LANG_SET."'")->getField('id');
		if($limit)
		$list = $this->where($condition)->order($order)->limit($limit)->findAll();
		else 
		$list = $this->where($condition)->order($order)->findAll();
		foreach($list as $k=>$v)
		{
			if(sunnyiC("URL_ROUTE")==1)
			$list[$k]['url'] = U("cate/".$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'] = 'c'.C("URL_PATHINFO_DEPR").$url.$v['id'].C("URL_HTML_SUFFIX"); 
			}
			else
			$list[$k]['url'] = U("Goods/index",array('id'=>$v['id']));
			$list[$k]['short'] = msubstr($v['name_'.$curr_lang_id],0,sunnyiC("GOODS_SHORT_NAME"));			
		}
		return $list;
	}
	
	/**
	 * 查询单款商品
	 */
	public function getGoodsCateItem($condition='')
	{
		$curr_lang_id = D("LangConf")->where("lang_name ='".FANWE_LANG_SET."'")->getField('id');
		$item = $this->where($condition)->find();
		if($item)
		{
			if(sunnyiC("URL_ROUTE")==1)
			$item['url'] = U("cate/".$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'] = 'c'.C("URL_PATHINFO_DEPR").$url.$item['id'].C("URL_HTML_SUFFIX"); 
			}
			else
			$item['url'] = U("Goods/index",array('id'=>$item['id']));
			$item['short'] = msubstr($v['name_'.$curr_lang_id],0,sunnyiC("GOODS_SHORT_NAME"));			
		}
		return $item;
	}
}
?>