<?php
defined('IN_TS') or die('Access Denied.');

if($TS_SITE['base']['isucenter']==1){
	//UC自动登录
	if($_SESSION['tsuser']['uid']){
		$syn= uc_user_synlogin($_SESSION['tsuser']['uid']);
		echo $syn;
		$_SESSION['tsuser']['uid']='';
	}
}
//首页幻灯

$indexslides = $db->fetch_all_assoc("select * from ".dbprefix."indexslide order by sort asc , addtime desc limit 7");
$i = 0;
foreach($indexslides as $key=>$item){
		$indexslide[] = $item;
		$indexslide[$key]['i'] = $i;
		$i++;
	}
	

//五个公告
$arrAnTopics = $db->fetch_all_assoc("select * from ".dbprefix."group_topics where groupid=4 order by uptime desc limit 5");

//五个推荐小组
$group_recommend = $db->fetch_all_assoc("select * from ".dbprefix."group where isrecommend='1' order by uptime limit 5");


//精华话题6个
$arrpTopics = $db->fetch_all_assoc("select * from ".dbprefix."group_topics where isposts=1 order by uptime desc limit 8");
	
	foreach($arrpTopics as $key=>$item){
		$arrpTopic[]=$item;
		
		$arrpTopic[$key]['user'] = aac('user')->getSimpleUser($item['userid']);
		
	}	

//热门分类标签
	$i=1;
foreach($TS_SITE['appnav'] as $key=>$item){

		$strcate = $db->once_fetch_assoc("select * from ".dbprefix."goods_cate where appname LIKE '%".$key."%' and parent_id=0");
		$cateid = intval($strcate['cate_id']);
		if ($i>3) {
			$catetags = aac('sharetag')->getObjTagByCateid($cateid,4,1);
		}else{

			$catetags = aac('sharetag')->getObjTagByCateid($cateid,8,1);

		}
		
		$cate_tag[] = array('cate' =>$item,'tag'=>$catetags,'appname'=>$key);
		$i++;
}





//推荐的四个主题
$arrthemes = $db->fetch_all_assoc("select * from ".dbprefix."theme  order by istop desc, goodsnum desc,addtime desc limit 4");
$i = 0;
foreach($arrthemes as $key=>$item){
		$arrtheme[] = $item;
		$goodsidarr = explode(',',$item['strgoodid']);
		
		foreach($goodsidarr as $k=>$v){
			if($k<9){
				if($v)
				$isgoods = $db->once_fetch_assoc("select img from ".dbprefix."share_goods where goods_id='".$v."'");
				$arrtheme[$key]['goodimg'][] = $isgoods['img'];
				$arrtheme[$key]['img'] = $isgoods['img'];
			}
		}
		
	}
//精选榜
$zhutitoparray = $db->fetch_all_assoc("select * from ".dbprefix."theme order by likenum desc,istop desc,uptime desc limit 0,10 ");
foreach($zhutitoparray as $key=>$item){

	$zhutitoparray[$key]['count'] = count(explode(',',$item['strgoodid']));
}

//精品直达

$jingarray = $db->fetch_all_assoc("select * from ".dbprefix."share_goods order by istop desc,count_like desc,uptime desc limit 0,24");

$i=0;
foreach($jingarray as $key=>$item){
	if($jingarray[0+$i]){
		$jing[] = array($jingarray[0+$i],$jingarray[1+$i],$jingarray[2+$i],$jingarray[3+$i],);
		$i=$i+4;
	}
}


//大家刚刚喜欢了
//达人推荐

$arrDarens = $db->fetch_all_assoc("select a.userid,a.goods_id,a.commentType,a.addtime from ".dbprefix."share_goods_like AS a LEFT JOIN ".dbprefix."user_info AS b ON a.userid = b.userid where a.commentType=0 and b.darenid>0 order by a.addtime desc limit 4");

$arrDaren = array();
foreach($arrDarens as $key=>$item){
	$arrDaren[]=$item;
	$isgoods = $db->once_fetch_assoc("select img,simg_170,name,count_like,price from ".dbprefix."share_goods where goods_id='".$item['goods_id']."'");
	if(is_array($isgoods)){
	$arrDaren[$key]['strgoods'] = $isgoods;
	$imgstr = aac('index')->cut_Img($isgoods['name'],'170','170');
	$arrDaren[$key]['simg_170']=$imgstr;
	$arrDaren[$key]['liketime']= getTime($item['addtime'],time());
	}
	
}




//推荐板块

$arrGroups = $db->fetch_all_assoc("select groupid from ".dbprefix."group order by isrecommend desc ,count_user desc limit 7");
	foreach($arrGroups as $key=>$item){
		$arrData[] = aac('group')->getOneGroup($item['groupid']);
	}
	foreach($arrData as $key=>$item){
		$arrRecommendGroup[] =  $item;
		$arrRecommendGroup[$key]['user'] = aac('user')->getSimpleUser($item['userid']);
		$arrRecommendGroup[$key]['groupdesc'] = getsubstrutf8(t($item['groupdesc']),0,35);
		$arrRecommendGroup[$key]['groupicon'] = $arrRecommendGroup[$key]['groupicon']?$arrRecommendGroup[$key]['groupicon']:'public/images/group.gif';
	}



//分类商品
$category = array();
foreach($TS_SITE['appnav'] as $key=>$item){
	
	$strcate = $db->once_fetch_assoc("select * from ".dbprefix."goods_cate where appname LIKE '%".$key."%' and parent_id=0");
	$cateid = intval($strcate['cate_id']);
	
	//悬浮导航
	$F_nav[$key] =aac('sharetag')->getObjTagByCateid_new($cateid,true);

	$catetags_1 = aac('sharetag')->getObjTagByCateid($cateid,'0,1','1');
	
		foreach($catetags_1 as $kkey=>$iitem){
			$imgstr = aac('index')->cut_Img($iitem['tag_name'],'230','230',$cateid);
			$catetags_1[$kkey]['imgstr'] = $imgstr;
		}

	$catetags_2 = aac('sharetag')->getObjTagByCateid($cateid,'1,12','1');
	foreach($catetags_2 as $kkey=>$iitem){
			$imgstr = aac('index')->cut_Img($iitem['tag_name'],'230','230',$cateid);	
			$catetags_2[$kkey]['imgstr'] = $imgstr;
		}
$catetags = aac('sharetag')->getObjTagByCateid_new($cateid);
	$category[]    = array(
	'appname'=>$key,
	'catetags'=>$catetags,
	'catename'=>$item,
	'cateid'=>$cateid,
	'catetags_1'=>$catetags_1,
	'catetags_2'=>$catetags_2,
	);

}


	//用户数据统计
	if($TS_USER['user']){
		$userid = intval($TS_USER['user']['userid']);
		require_once 's_count.php';
		
	}
	



//可根据SEO需求进行优化，如需帮助请到论坛讨论：bbs.tuntron.com
$title = $TS_SITE['base']['site_title'].' - '.$TS_SITE['base']['site_subtitle'];

	include template("index");