<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * shop search page
 * @author		Jade Xia
 * @copyright	Copyright (c) 2010 - 2011 天夏网络.
 * @link		http://www.tianxianet.com
 *
 */
class Shop_search extends Controller
{
	var $site_title;
		
	function Shop_search()
	{
		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()
	{
		parse_str($_SERVER['QUERY_STRING'],$get);
		
		$cid = 0;
		if(isset($get['cid']) && $get['cid'] != '')
		{
			$cid = $get['cid'];
		}
		
		$nav = array(
			'nav_title' => '店铺搜索',
			'nav_str' => ' &gt; 店铺搜索'
		);
		$this->load->config('shop_catalog_config');
		$catalog = $this->config->item('shop_catalog');
		foreach($catalog as $v)
		{
			if($v['cid'] == $cid)
			{
				$nav['nav_title'] = $v['cat_name'];
				$nav['nav_str'] = ' &gt; '.$v['cat_name'];
			}
		}
		
		$data = array(
			'site_title' => $nav['nav_title'].'--'.$this->site_title,
			'cat_url' => $this->config->item('cat_url'),
			'nav'		=> $nav['nav_str'],
			'industry_catalog' => $this->config->item('industry_catalog'),
			'top_nav' => $this->config->item('top_nav'),
			'hot_keyword' => $this->config->item('hot_keyword'),
			'total' => 0,
			'paginate' => ''
		);
		
		$this->load->library('top/TaobaokeShopsGetRequest','','req');
		$this->req->setPid($this->config->item('pid'));
		$this->req->setFields('click_url,shop_title,seller_credit,shop_type,auction_count');
		if($start_commission_rate = $this->config->item('start_commission_rate')) $this->req->setStartCommissionrate($start_commission_rate);
		if($end_commission_rate = $this->config->item('end_commission_rate')) $this->req->setEndCommissionrate($end_commission_rate);
		if($start_credit = $this->config->item('start_credit')) $this->req->setStartCredit($start_credit);
		if($end_credit = $this->config->item('end_credit')) $this->req->setEndCredit($end_credit);
		$page_size = 40;
		$this->req->setPageSize($page_size);
		if(isset($get['keyword']) && $get['keyword'] != '') 
		{
			$this->req->setKeyword($get['keyword']);
		}
		if($cid > 0)
		{
			$this->req->setCid($cid);
		}
		$page_no = 1;
		if(isset($get['page_no']) && $get['page_no'] != '')
		{
			$page_no = $get['page_no'];
			$this->req->setPageNo($page_no);
		}
		else $this->req->setPageNo($page_no);
		
		$resp = $this->top->execute($this->req);
		if($resp && isset($resp['taobaoke_shops']['taobaoke_shop']))
		{
			$data['query'] = $resp['taobaoke_shops']['taobaoke_shop']; 
		}
		if(isset($resp['total_results']))
		{
			$data['total'] = $resp['total_results']; 
			$data['paginate'] = $this->com_model->get_page_nav($data['total'],$page_no,$page_size);
		}
		
		//推荐商家
		$this->req->setStartCommissionrate('1000');
		$this->req->setEndCommissionrate('5000');
		$this->req->setStartCredit('2diamond');
		$this->req->setEndCredit('5goldencrown');
		$this->req->setPageSize(40);
		
		$resp = $this->top->execute($this->req);
		if($resp && isset($resp['taobaoke_shops']['taobaoke_shop']))
		{
			$data['shop_top'] = $resp['taobaoke_shops']['taobaoke_shop']; 
		}
		$this->load->view(TPL_FOLDER.'shop_search',$data);
	}
}
?>