/category.php
PHP | 415 lines | 225 code | 39 blank | 151 comment | 25 complexity | b3b55b7eb694e41a320d7c2aecd24c5c MD5 | raw file
- <?php
- require(dirname(__FILE__) . '/includes/init.php');
- //??id????
- if(isset($_GET['id']))
- {
-
- $cat_id=intval($_GET['id']);
- //echo $cat_id;
- }else{
- //????
- exit;
- }
- //??id
- //isset($_GET['brand'])
- if(isset($_GET['brand']))
- {
- $brand=intval($_GET['brand']);
- }else
- {
- $brand=0;
- }
- //price_min???
- if(isset($_GET['price_min']))
- {
- $price_min=intval($_GET['price_min']);
- }else
- {
- $price_min=0;
- }
- //price_max???
- if(isset($_GET['price_max']))
- {
- $price_max=intval($_GET['price_max']);
- }else
- {
- $price_max=0;
- }
- //??
- $page = isset($_GET['page']) && intval($_GET['page']) > 1 ? intval($_GET['page']) : 1 ;
- /*if(isset($_GET['page']))
- {
- $page=intval($_GET['page']);
- if($page<1){
- $page=1;
- }
- }else
- {
- $page=1;
- }
- echo $page;*/
- //??filter_attr
- /*if(isset($_GET['filter_attr']))
- {
- $filter_attr=$_GET['filter_attr'];
- //$filter_arprint_r($filter_ar);
- }else{
- $filter_attr='0.0.0.0';
- }
- $filter_ar=explode('.',$filter_attr);*/
- //???????????,???????????
- $cat_info=get_category_info($cat_id);
- if(empty($cat_info)){
- //????
- echo '??????';
- exit;
- }
- //???????id?string
- $str_cat_id=get_children($cat_id);
- $str_id=$str_cat_id.$cat_id;
-
- //??????
- public_data();
-
- //????(return array)
- $smarty->assign('current_position',current_p($cat_info['cat_id']));
-
- //????(???????)
- $smarty->assign('category',get_category($cat_info['parent_id'],'category'));
-
- //????
- $smarty->assign('best_goods',get_best_goods($str_id));
-
- //begin????
- $sql="select b.brand_id,b.brand_name from ".$ecs->table('goods')." as g, ".$ecs->table('brand').
- " as b where g.brand_id=b.brand_id and g.cat_id in({$str_id}) and ".
- "g.brand_id > 0 and g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 group by b.brand_name ";
- $brand_filter_arr=$db->getAll($sql);
- //print_r($brand_filter_arr);
- foreach($brand_filter_arr as $key=>$val)
- {
- $tem_key=$key+1;
- $brand_filter_arr[$tem_key]['brand_id']=$val['brand_id'];
- $brand_filter_arr[$tem_key]['brand_name']=$val['brand_name'];
- $brand_filter_arr[$tem_key]['b_url']='category.php?id='.$cat_id."&brand=".$val['brand_id']."&price_min=".$price_min."&price_max=".$price_max."&page=1";
- if($brand == $val['brand_id'])
- {
- $brand_filter_arr[$tem_key]['selected']=1;
- }else {
- $brand_filter_arr[$tem_key]['selected']=0;
- }
- }
- //print_r($brand_filter_arr);
- $brand_filter_arr[0]['brand_name']=$_LANG['all_attribute'];
- $brand_filter_arr[0]['b_url']='category.php?id='.$cat_id."&price_min=".$price_min."&price_max=".$price_max."&page=1";
- $brand_filter_arr[0]['selected'] = empty($brand) ? 1 : 0;
- $smarty->assign('brand_list',$brand_filter_arr);
- //end????
- //begin??????
- $filter_grade_arr=array();
- if($cat_info['grade']==0 && $cat_info['parent_id']!=0)
- {
- //???????????
- $cat_info['grade']=get_parent_grade($cat_info['cat_id']);
- }
- if($cat_info['grade']>1){
- //??????????
- $sql="select min(shop_price) as min,max(shop_price) as max from ".$ecs->table('goods')." as g ".
- " where cat_id in({$str_id}) AND is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1 ";
- $filter_grade_arr=$db->getAll($sql);
- //print_r($grade_arr);
- if($filter_grade_arr[0]['max']!=$filter_grade_arr[0]['min'])
- {
- // ???????????????????????100???
- $price_grade = 0.0001;
- for($i=-2;$i<=log10($filter_grade_arr[0]['max']);$i++)
- {
- $price_grade*=10;
- }
- $dx = ceil(($filter_grade_arr[0]['max'] - $filter_grade_arr[0]['min'])/$price_grade/$cat_info['grade'])*$price_grade;
- $mi=floor($filter_grade_arr[0]['min']/$price_grade)*$price_grade;
- $ma=ceil($filter_grade_arr[0]['max']/$price_grade)*$price_grade;
- $mn=$mi;
- $i=1;
- while($mn<=$ma){
- $filter_grade_arr[$i]['min']=$mn;
- $mn=$mn+$dx;
- $filter_grade_arr[$i]['max']=$mn;
- $filter_grade_arr[$i]['price_range']=$filter_grade_arr[$i]['min']." - ".$filter_grade_arr[$i]['max'];
- $filter_grade_arr[$i]['p_url']='category.php?id='.$cat_id."&brand=".$brand."&price_min=".$filter_grade_arr[$i]['min']."&price_max=".$filter_grade_arr[$i]['max']."&page=1";
- if($filter_grade_arr[$i]['min']==$price_min && $filter_grade_arr[$i]['max']==$price_max)
- {
- $filter_grade_arr[$i]['selected']=1;
- }else{
- $filter_grade_arr[$i]['selected']=0;
- }
- $i++;
- }
- $filter_grade_arr[0]['price_range'] = $_LANG['all_attribute'];
- $filter_grade_arr[0]['p_url'] = 'category.php?id='.$cat_id."&brand=".$brand."&price_min=0&price_max=0&page=1";
- $filter_grade_arr[0]['selected'] = (empty($price_min)&&empty($price_max)) ? 1 : 0 ;
- }else{
- $filter_grade_arr=array();
- }
- }
- //print_r($filter_grade_arr);
- $smarty->assign('filter_grade_arr',$filter_grade_arr);
-
- //????$row['filter_attr']
- $f_a_a=array();
- $f_a=array();
- /*if(!empty($cat_info['filter_attr']) && $cat_info['filter_attr']>0)
- {
-
- //$f_a_a=get_filter_attr($cat_info['filter_attr']);
- $sql="select g_a.goods_attr_id,g_a.attr_id,g_a.attr_value,a.attr_name from ".$GLOBALS['ecs']->table('goods_attr')." as g_a, " .$GLOBALS['ecs']->table('attribute'). " as a where g_a.attr_id=a.attr_id and g_a.attr_id in ({$cat_info['filter_attr']}) group by attr_value ";
- $re=$GLOBALS['db']->query($sql);
- while($row=$GLOBALS['db']->fetchRow($re))
- {
- $f_a_a[$row['attr_id']]['attr_name']=$row['attr_name'];
-
- //$row['t_url']='category.php?id='.$cat_id."&brand=".$brand."&price_min=0&price_max=0&filter_attr";
- $f_a_a[$row['attr_id']]['attr_chr'][]=$row;
- //print_r($f_a_a[$row['attr_id']]['attr_chr']);
- //foreach($f_a_a[$row['attr_id']]['attr_chr'] as $key=>$val){
- //$tem_key_q=$key+1;
- //$f_a[$tem_key_q]=$val;
- //print_r($val);
- //$f_a_a[$row['attr_id']]['attr_chr'][$key]['attr_value']=$val['attr_value'];
- //}
- //$f_a_a[$row['attr_id']]['attr_chr']=$f_a;
- //$f_a=array();
- //$f_a[0]['goods_attr_id']=0;
- //$f_a[0]['attr_id']=0;
- //$f_a[0]['attr_value']=$_LANG['all_attribute'];
- //$arr[$row['attr_id']]['attr_name']=$row['attr_name'];
- //$arr[$row['attr_id']]['attr_chr'][]=$row;
- }
- print_r($f_a_a);
- $i=0;
- foreach($f_a_a as $key=>$val){
- $f_a[$key]['attr_name']=$val['attr_name'];
- $f_a[$key]['attr_chr'][0]['goods_attr_id']=0;
- $f_a[$key]['attr_chr'][0]['attr_id']=0;
- $f_a[$key]['attr_chr'][0]['attr_value']=$_LANG['all_attribute'];
-
- if($filter_ar[$i]==0)
- {
- $f_a[$key]['attr_chr'][0]['selected']=1;
- }else{
- $f_a[$key]['attr_chr'][0]['selected']=0;
- }
-
- foreach($val['attr_chr'] as $key1=>$val1)
- {
- $tem_key_q=$key1+1;
- //echo $filter_ar[$i];
- echo $val1['goods_attr_id'];
- if($filter_ar[$i]==$val1['goods_attr_id'])
- {
- $val1['selected']=1;
- }else{
- $val1['selected']=0;
- }
-
- if($filter_ar[$i]==0)
- {
- $f_a[$key]['attr_chr'][0]['selected']=1;
- }else{
- $f_a[$key]['attr_chr'][0]['selected']=0;
- }
- $f_a[$key]['attr_chr'][$tem_key_q]=$val1;
- }
- $i++;
- //$tem_key_q=$key+1;
- //$f_a[$tem_key_q]=$val;
- //print_r($val);
- //$f_a_a[$row['attr_id']]['attr_chr'][$key]['attr_value']=$val['attr_value'];
- }
-
- }*/
- //print_r($f_a);
- $smarty->assign('filter_attr_list',$f_a);
-
- //begin????
-
- $where='';
- $limit='';
- $page_string='';
- if($brand>0){
- $where.=' and brand_id='.$brand;
- }
- if($price_min>0){
- $where.=' and shop_price > '.$price_min;
- }
- if($price_max>0){
- $where.=' and shop_price < '.$price_max;
- }
- //?????
- $sql="select count(*) from ".$ecs->table('goods')." where cat_id in({$str_id}) ".$where;
- $total_num=$db->getOne($sql);
- //echo $total_num;
- //??????
- $page_size=2;
- if($total_num>$page_size)
- {//begin??-------
- //???
- $page_total=ceil($total_num/$page_size);
- $page=$page>$page_total?$page_total:$page;
- $page_string="<span style=\"margin-right: 10px;\" class=\"f_l f6\">".$_LANG['pager_1']." <b>".$total_num."</b> ".$_LANG['pager_2']."</span>";
- $page_current="<span class=\"page_now\">".$page."</span>";
- $page_first='';
- $page_prev='';
- $page_p='';
- $page_last='';
- $page_next='';
- $page_l='';
- if($page>1){
- $page_first="<a href=\"category.php?id=".$cat_id."&brand=".$brand."&price_min=".$price_min.
- "&price_max=".$price_max."&page=1\">".$_LANG['page_first']."</a>";
- $page_prev= "<a href=\"category.php?id=".$cat_id."&brand=".$brand."&price_min=".$price_min.
- "&price_max=".$price_max."&page=".($page-1)."\">".$_LANG['page_prev']."</a>";
- }
- if($page<$page_total)
- {
- $page_last="<a href=\"category.php?id=".$cat_id."&brand=".$brand."&price_min=".$price_min.
- "&price_max=".$price_max."&page=".$page_total."\">".$_LANG['page_last']."</a>";
- $page_next="<a href=\"category.php?id=".$cat_id."&brand=".$brand."&price_min=".$price_min.
- "&price_max=".$price_max."&page=".($page+1)."\">".$_LANG['page_next']."</a>";
- }
-
- $i=$page-1;
- $j=1;
- //??
- $p_prev=3;
- for($i;$i>0;$i--){
- if($j>$p_prev){break;}
- $page_p="<a href=\"category.php?id=".$cat_id."&brand=".$brand."&price_min=".$price_min.
- "&price_max=".$price_max."&page=".$i."\">[".$i."]</a>".$page_p;
- $j++;
- }
- $i=$page+1;
- $j=1;
- //??
- $p_last=4;
- for($i;$i<=$page_total;$i++)
- {
- if($j>$p_last){break;}
- $page_l.="<a href=\"category.php?id=".$cat_id."&brand=".$brand."&price_min=".$price_min.
- "&price_max=".$price_max."&page=".$i."\">[".$i."]</a>";
- $j++;
- }
- $page_string.=$page_first.$page_prev.$page_p.$page_current.$page_l.$page_next.$page_last;
-
- //end ??------
- $page_start=($page-1)*$page_size;
- $limit=' limit '.$page_start.' ,'.$page_size;
- }
-
-
-
- $sql="select goods_id,cat_id,goods_name,market_price,shop_price,goods_thumb,brand_id from ".$ecs->table('goods')." where cat_id in({$str_id}) ".$where.$limit;
- //echo $sql;
- $re=$db->query($sql);
- $goods_list=array();
-
-
- while($row=$db->fetchRow($re))
- {
- $row['g_url']=headle_url('goods', $row['goods_id']);
- $row['short_title']=sub_str($row['goods_name'],10,false);
- $row['goods_thumb']=empty($row['goods_thumb'])?'images/200905/thumb_img/23_thumb_G_1241971556399.jpg':$row['goods_thumb'];
- $goods_list[]=$row;
- }
- //print_r($goods_list);
- //??
- $smarty->assign('page_string',$page_string);
- $smarty->assign('goods_list',$goods_list);
- //end????
-
-
- $smarty->display('category.html');
-
- //private function
-
-
-
- /**
- * ??????
- * @param string $str_id ???????id?
- * @return array
- */
- function get_best_goods($str_id='')
- {
- $arr=array();
- $where= " where is_best=1 ";
- $where .=' and cat_id in ('.$str_id.') order by last_update desc limit 0, 5';
- $sql="select goods_id,goods_name,shop_price,goods_img,cat_id from ".$GLOBALS['ecs']->table('goods').$where;
- $re=$GLOBALS['db']->query($sql);
- while($row=$GLOBALS['db']->fetchRow($re))
- {
- $row['g_url']=headle_url('goods', $row['goods_id']);
- $row['short_title']=sub_str($row['goods_name'],10,false);
- $row['shop_price']=$GLOBALS['_LANG']['a'].$row['shop_price'].$GLOBALS['_LANG']['b'];
- $arr[]=$row;
- }
- return $arr;
- }
-
-
-
- /**
- * ????
- * @param string ?????????
- * @return array
- */
- function get_filter_attr($str='')
- {
- $arr=array();
- $sql="select g_a.goods_attr_id,g_a.attr_id,g_a.attr_value,a.attr_name from ".$GLOBALS['ecs']->table('goods_attr')." as g_a, " .$GLOBALS['ecs']->table('attribute'). " as a where g_a.attr_id=a.attr_id and g_a.attr_id in ({$str}) group by attr_value ";
- $re=$GLOBALS['db']->query($sql);
- while($row=$GLOBALS['db']->fetchRow($re))
- {
- $arr[$row['attr_id']]['attr_name']=$row['attr_name'];
- $arr[$row['attr_id']]['attr_chr'][]=$row;
- }
- return $arr;
- }
-
- /**
- * ??????
- * @param int $str_id ???????id?
- * @param int $grade ??????
- * @return array
- */
- function get_filter_grade($str_id='',$grade=2)
- {
- $price_grade_arr=array();
-
- return $price_grade_arr;
- }
-
- /**
- * ?????????
- * @param int $parent_id //?????cat_id
- * @return int
- */
- function get_parent_grade($parent_id)
- {
- $grade_arr=array();
- $sql="select grade from ".$GLOBALS['ecs']->table('category')." where cat_id = ".$parent_id;
- $grade_arr=$GLOBALS['db']->getRow($sql);
- return $grade_arr['grade'];
-
- }
-
-
-
-
- ?>
-
-
-
-
-
-