<?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 GoodsSpecModel extends MultiLangModel  {
	/**
	 * 查询当前商品的规格组合列表
	 *
	 * @param integer $goods_id
	 * @return array
	 */
	public function getGoodsSpecList($goods_id)
	{
		$list1 = $this->where("goods_id=".$goods_id." and idx=1 and session_id=''")->findAll();
		foreach($list1 as $k=>$v)
		{
			$result[0]['spec_type'] = D("SpecType")->getById($v['spec_type_id']);
			$result[0]['spec_type']['name'] = $result[0]['spec_type']['name_'.FANWE_LANG_ID];
			$v['spec_name'] = $v['spec_name_'.FANWE_LANG_ID];
			$result[0]['spec_list'][] = $v; 
		}
		$list2 = $this->where("goods_id=".$goods_id." and idx=2 and session_id=''")->findAll();
		foreach($list2 as $k=>$v)
		{
			$result[1]['spec_type'] = D("SpecType")->getById($v['spec_type_id']);
			$result[1]['spec_type']['name'] = $result[1]['spec_type']['name_'.FANWE_LANG_ID];
			$v['spec_name'] = $v['spec_name_'.FANWE_LANG_ID];
			$result[1]['spec_list'][] = $v; 
		}
		return $result;
	}
	
	/**
	 * 查询出所有的规格列表
	 */
	public function getSpecList()
	{
		$result = D("GoodsSpec")->where("session_id=''")->field("distinct spec_name_".FANWE_LANG_ID." as spec_name,spec_type_id")->findAll();
		foreach($result as $k=>$row)
		{
			$spec_list[$row['spec_type_id']]['spec_type'] = D("SpecType")->getById($row['spec_type_id']);			
			$spec_list[$row['spec_type_id']]['spec_list'][] = $row;
		}
		return $spec_list;		
	}
}
?>