<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * goods detail
 * @author		Jade Xia
 * @copyright	Copyright (c) 2010 - 2011 天夏网络.
 * @link		http://www.tianxianet.com
 *
 */
class Item extends Controller
{
	var $site_title;
		
	function Item()
	{
		parent::Controller();
		$this->load->database();
		$this->load->model('com_model');
		$this->load->library('TopClient','','top');
		$this->load->config('top_config');
		$this->load->config('top_nav_config');
		$this->load->config('hot_keyword_config');
		$this->load->config('industry_catalog_config');
		$this->load->config('cat_url_config');
		$this->site_title=$this->config->item('sys_site_title');
	}
	
	function index()
	{
		$num_iid = $this->uri->segment($this->com_model->uri_segnum,0);
		
		$data = array(
			'site_title' => $this->site_title,
			'cat_url' => $this->config->item('cat_url'),
			'industry_catalog' => $this->config->item('industry_catalog'),
			'top_nav' => $this->config->item('top_nav'),
			'hot_keyword' => $this->config->item('hot_keyword')
		);
		
		$this->load->library('top/TaobaokeItemsDetailGetRequest','','req');
		$this->req->setPid($this->config->item('pid'));
		$this->req->setFields('num_iid,title,nick,cid,pic_url,post_fee,express_fee,ems_fee,num,price,list_time,delist_time,location,props,props_name,desc,click_url,shop_click_url,seller_credit_score');
		if($num_iid > 0) $this->req->setNumIids($num_iid);
		else echo_msg('<li>查看的商品ID有误</li>');
		
		$resp = $this->top->execute($this->req);
		if($resp && isset($resp['taobaoke_item_details']['taobaoke_item_detail']))
		{
			$data['goods'] = $resp['taobaoke_item_details']['taobaoke_item_detail']; 
		}
		else
		{
			echo_msg('<li>很抱歉，您查看的商品不存在</li>');
		}
		
		if(isset($data['goods']['item']['cid'])) $cid = $data['goods']['item']['cid'];
		else $cid = 0;
		
		$nav_arr=array(
			'tb'=> 'shop_industry_catalog',
			'base' => CTL_FOLDER.'search',
			'nav_title'=> $data['goods']['item']['title'],
			'catalog_id' =>$cid,
			'is_list' => FALSE
		);
		
		$nav = $this->com_model->get_nav($nav_arr);
		
		$data['site_title'] = $nav['nav_title'].'--'.$this->site_title;
		$data['nav'] = $nav['nav_str'];
		
		//商品属性值
		$this->load->library('top/ItempropvaluesGetRequest','','req');
		$this->req->setCid($cid);
		$this->req->setFields('prop_name,name,sort_order');
		$this->req->setPvs($data['goods']['item']['props']);
		$resp = $this->top->execute($this->req);
		if($resp && isset($resp['prop_values']['prop_value']))
		{
			$data['props'] = $resp['prop_values']['prop_value']; 
		}
		
		
		//畅销排行
		$this->load->library('top/TaobaokeItemsGetRequest','','req');
		$this->req->setPid($this->config->item('pid'));
		$this->req->setFields('title,pic_url,price,click_url,num_iid,shop_click_url,commission_num');
		$this->req->setCid($cid);
		$this->req->setStartCommissionrate('2000');
		$this->req->setEndCommissionrate('5000');
		$this->req->setStartCredit('1diamond');
		$this->req->setEndCredit('5goldencrown');
		$this->req->setSort('commissionNum_desc');
		$this->req->setPageSize(20);
		
		$resp = $this->top->execute($this->req);
		if($resp && isset($resp['taobaoke_items']['taobaoke_item']))
		{
			$data['sale_top'] = $resp['taobaoke_items']['taobaoke_item']; 
		}
		
		$this->load->view(TPL_FOLDER.'item',$data);
	}
}
?>