<?php
require_once WEBROOT.'include/function.php';


$catid = intval(var_request("catid","0"));

//$catid = getnochengrencid($catid);
$page = intval(var_request("page","0"));


$cat_name = ""; 
$qserach = urldecode(var_request("qserach","")); //默认搜索词

$q = getcnstr(var_request("q_jt",""));
if(empty($q)) $q = urldecode(urldecode(var_request('q',"")));
if(!empty($qserach)) $q =$qserach;

$q = htmlspecialchars(setsplitkeyword($searchkeypb,$q,""),ENT_COMPAT);




if(empty($q) && $catid=="0") $q = "热门";


if(checkpingbi($catidpb,$catid)){
	exit("<script language=\"javascript\">alert('对不起，该类别已被屏蔽。');location.href='".$sitetitleurl."';</script>");	
}

if($catid != 0)
{
	$Taoapi->method = 'taobao.itemcats.get';
	$Taoapi->fields = 'cid,name,parent_cid,status';
	$Taoapi->cids = $catid;
	$TaoapiCat = $Taoapi->Send('get','xml')->getArrayData();
	$TaoapiCat = $TaoapiCat["item_cats"]["item_cat"];
	$cat_name = $TaoapiCat["name"];
	
	if(Show_list_small){
		$Taoapi->method = 'taobao.itemcats.get';
		$Taoapi->fields = 'cid,name,parent_cid';
		$Taoapi->parent_cid = $catid;
		$TaoapiSubCats = $Taoapi->Send('get','xml')->getArrayData();
	}
}

$result_subcats = "";
$result_subcats_count = 0;

if(isset($TaoapiSubCats["item_cats"]["item_cat"])){
	$result_subcats = $TaoapiSubCats["item_cats"]["item_cat"];
	$result_subcats_count = count($result_subcats);
}

$Taoapi->method = 'taobao.taobaoke.shops.get';
$Taoapi->fields = 'user_id,click_url,shop_title,commission_rate,seller_credit,shop_type,auction_count,total_auction';
$Taoapi->pid = $userpiddp;

if($catid!="0") $Taoapi->cid = $catid;
if($q!=""){
	$Taoapi->keyword = Newiconv("GBK","UTF-8",$q);
}
$Taoapi->page_no = $page;
$Taoapi->page_size = $page_size;
$Taoapi->start_credit = $shoplevelstart;
$Taoapi->end_credit  = $shoplevelend;
$Taoapi->start_commissionrate  = $stratmoneyKeys;
$Taoapi->end_commissionrate  = $endmoneyKeys;

if($ismall=="1")$Taoapi->only_mall = "true";
$TaoapiItems = $Taoapi->Send('get','xml')->getArrayData();

$taobaokeItem = $TaoapiItems["taobaoke_shops"]["taobaoke_shop"];
$totalResults = $TaoapiItems["total_results"];


$cat_name = Newiconv("UTF-8","GBK",$cat_name);

if($totalResults==1){
	$tparr = array();
	$tparr[] = $taobaokeItem;
	$taobaokeItem = $tparr;
}

//过滤标题
/*for($i = 0; $i < count($taobaokeItem); $i++) {
	if(!isset($taobaokeItem[$i]["shop_title"])) break;
	
	$taobaokeItem[$i]["shop_title"] =Newiconv("GBK","UTF-8", setsplitkeyword($searchkeypb,Newiconv("UTF-8","GBK",$taobaokeItem[$i]["shop_title"]),"***"));
	
	if(intval($taobaokeItem[$i]["seller_credit"])>=11 && intval($taobaokeItem[$i]["seller_credit"])<=15) { $taobaokeItem[$i]["seller_credit"] = $taobaokeItem[$i]["seller_credit"]-5; } 
	if(intval($taobaokeItem[$i]["seller_credit"])>=101 && intval($taobaokeItem[$i]["seller_credit"])<=105) { $taobaokeItem[$i]["seller_credit"] = $taobaokeItem[$i]["seller_credit"]-90; } 
	if(intval($taobaokeItem[$i]["seller_credit"])>=1001 && intval($taobaokeItem[$i]["seller_credit"])<=1005) { $taobaokeItem[$i]["seller_credit"] = $taobaokeItem[$i]["seller_credit"]-985; } 
}
*/
if($shopsearch_title=="")$shopsearch_title = "{类别名}{关键词}店铺榜_{网站名}";
if($shopsearch_keyword=="")$shopsearch_keyword = "{类别名}{关键词}主题店,淘宝{类别名}{关键词}主题店";
if($shopsearch_discription=="")$shopsearch_discription = "您所查看的是淘宝网{类别名}{关键词}主题店列表,{网站名}提醒您，使用支付宝交易，先收货后付款！";

$tihuanarr = array();
$tihuanarr["{类别名}"] = $cat_name;
$tihuanarr["{关键词}"] = $q;
$tihuanarr["{网站名}"] = $sitetitle;


$page_title = strtr($shopsearch_title,$tihuanarr); 
$page_keyword = strtr($shopsearch_keyword,$tihuanarr); 
$page_discription = strtr($shopsearch_discription,$tihuanarr); 



require_once WEBROOT.'include/functiondaohang.php';

require_once(WEBROOT."include/pages.php");

//加载模板
require_once WEBROOT.'template/'.$templatefolder.'/shopsearch.php';
showend();

?>
