<?php
define('IN_OUN', true); 
include_once( "./includes/command.php");
include_once( ROOT_PATH."includes/item_set.php"); 
include_once( ROOT_PATH."includes/shopcomm.php");  
//分类id与翻页在一个变量
if($prapcid > 0 ){
   $sql = "SELECT name from ".$pre."pravail_productcat where prapcid  = '".$prapcid."' and domain_id=".$_SESSION[$un_domain_id]." limit 1";
   $prapcneme = $oPub->getOne($sql);
}
/* 产品页显示的模块 */
$Ahome["nowNave"]  = '<A HREF="./">'.$Aconf['web_title'].'首页</A> > <A HREF="'.$rowpra['pravail_url'].'">商家列表</a>><a href="'.$rowpra['shop_url'].'">'.$rowpra[pra_name].'</a>> '.'<A HREF="'.$rowpra['shop_h'].'">热卖商品</A>> '.$prapcneme; 
$Aconf["header_title"] =  $prapcneme.'|热卖商品|'.$rowpra[pra_name].'|'.$Aconf['header_title'];  

/* 得到产品列表 */
$tmpStr = ($prapcid>0)?" AND prapcid='".$prapcid."'":'';
$where = "states=0 and  praid='".$praid."' AND domain_id = '".$_SESSION[$un_domain_id]."'".$tmpStr;
$sql = "SELECT COUNT(*) as count FROM ". $pre."pravail_producttxt WHERE 1 AND ". $where;
$count = $oPub->getOne($sql);  
$page = new ShowPage;
$page->PageSize = 30;
$page->Total = $count;
$pagenew = $page->PageNum();
$page->LinkAry = array('id'=>$praid.'a'.$prapcid); 
$strOffSet = $page->OffSet(); 
$Ahome["showpage"] = ($count > 30)?$page->ShowLink_num():''; 
$sql = "SELECT  prid, main_prid ,pacid,  name, shop_price,up_date,dateadd,comms,hots,min_thumb from ".$pre."pravail_producttxt    
		where  $where order by prid desc limit ". $strOffSet;
$rowproduct = $oPub->select($sql);
if( $rowproduct ) {      
   foreach ($rowproduct AS $key=>$val) {
		/* 查询是否为总站商品 */
		if($val[main_prid] > 0 ) {
			$db_table = $pre."producttxt";
			$where = " prid = '".$val[main_prid]."' and states=0 and domain_id = '".$_SESSION[$un_domain_id]."'";
			$sql = "SELECT name,shop_price,pacid,up_date,min_thumb FROM ".$db_table." as a where 1 and ". $where.' limit 1';
			$rowtmp = $oPub->getRow($sql);
			$rowproduct[$key]['name'] = $rowtmp[name];
			$rowproduct[$key]['shop_price'] = $rowtmp[shop_price];
			$rowproduct[$key]['pacid'] = $rowtmp[pacid];
			$rowproduct[$key]['min_thumb'] = $rowtmp[min_thumb];
			$rowproduct[$key]['up_date']  = ($rowtmp['up_date'])?date("y年m月d日", $rowtmp['up_date']):'';
		}else{
			$rowproduct[$key]['up_date']  = ($val['up_date'])?date("y年m月d日", $val['up_date']):'';
		}

		if($Aconf['rewrite']){ 
			$rowproduct[$key]['shop_ht'] = 'shop_ht-'.$praid.'-'.$val[prid].'.html';
		}else{ 
			$rowproduct[$key]['shop_ht'] = 'shop_ht.php?id='.$praid.'&prid='.$val[prid];
		}  
	}
}
$rowpra['prapro'] = $rowproduct;unset($rowproduct);
/* 找到所有的自定义分类 select start*/
$db_table = $pre."pravail_productcat";
$sql = "SELECT prapcid,name  FROM ".$db_table." where praid  = '".$praid."'  AND domain_id=".$_SESSION[$un_domain_id]." ORDER BY prapcid ASC";
$Strppcat = '';
$AnormAll = $oPub->select($sql);
while( @list( $key, $value ) = @each( $AnormAll) ) {
	$db_table = $pre."pravail_producttxt";
	$sql = "SELECT COUNT(*) as count FROM ".$db_table." 
            where prapcid  = '".$value[prapcid]."' 
	        AND domain_id='".$_SESSION[$un_domain_id]."'";
    $tmp = $oPub->getOne($sql);
	$count = ($tmp)?$tmp:0;
	if($Aconf['rewrite']){ 
		$AnormAll[$key]['shop_h'] = 'shop_h-'.$praid.'a'.$value[prapcid].'-0.html';
	}else{ 
		$AnormAll[$key]['shop_h'] = 'shop_h.php?id='.$praid.'a'.$value[prapcid];
	} 
	$AnormAll[$key]['count'] = $count;
}
$rowpra['productcat'] =  $AnormAll;unset($AnormAll);

$Ahome["pravail"] = $rowpra; unset($rowpra);
if ((DEBUG_MODE & 2) != 2) {
    $smarty->caching = true;
}

$cache_id = sprintf('%X', crc32($_SESSION[$un_domain_id].$prid));
if (!$smarty->is_cached($Aconf["displayFile"], $cache_id)) {
	assign_template($Aconf); 
	$smarty->assign('home', $Ahome ); 
	$smarty->assign('user_info', $_SESSION );
	unset($Ahome); 
}
$smarty->display($Aconf["displayFile"], $cache_id); 
?>
 