<?php
// +----------------------------------------------------------------------
// | 前台函数库
// +----------------------------------------------------------------------
// | ThinkOAO （Online And Offline）
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.hanchao9999.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: xiaogg <xiaogg@sina.cn>
// +----------------------------------------------------------------------
/**
 * 获得首页推荐商品分类及下级分类和下级推荐商品
 商品同级的所有分类以及该分类下的子分类
 *
 * @access  public
 * @param   integer     $cat_pid     上级分类
 *          integer     $goods       调取商品的数量
 *          integer     $brand       调取商品品牌的数量
 *          integer     $son_info    是否调用子类的信息
 *          integer     $son_goods   按子类调用商品的数量
 *          integer     $son_brand   按子类调用商品品牌的数量
			Boolean		$cache	     缓存
 * @return  array
 */
function get_index_categories($cat_pid=0,$goods=0,$brand=0,$son_info=0,$son_goods=0,$son_brand=0,$cache=true){

    if($cache){
        $cachename='get_index_categories'.$cat_pid.$goods.$brand;
        $cachedata=S($cachename);
        if($cachedata)return $cachedata;
    }
    GLOBAL $GoodsCategory;
	$data = $GoodsCategory;
	if ($data){
		foreach($data as $key=> $value){
            if($cat_pid>0 && $value['pid']!=$cat_pid)continue;
			if( $value['pid']==$cat_pid  && $value['status'] == 1  ){
				if(!is_array($value['allson']))$value['allson']=explode(',',$value['allson']);
				array_shift($value['allson']);
				$home_category[$value['id']] =$value;
                if($goods){
                    $v_map=array();$v_map['cat_id']=$value['id'];
                    $v_goods=D('Common/Goods')->get_goods_list(0,$v_map,'','',1,$goods);
                    $home_category[$value['id']]['goods']=$v_goods['list'];
                }
                if($son_goods || $son_info){
                    foreach($value['allson'] as $sonk=>$sonv){
                        if($son_info)$home_category[$value['id']]['son_goods'][$sonv]=$GoodsCategory[$sonv];
				        if($son_goods){
                            $vv_map=array();$vv_map['cat_id']=$sonv;
                            $vv_goods=D('Common/Goods')->get_goods_list(0,$vv_map,'','',1,$son_goods);
                            $home_category[$value['id']]['son_goods'][$sonv]['goods'] =$vv_goods;
                        }
                    }
                }
			}unset($data[$key]);	
		}
	}
   // print_r($home_category);exit;
    //if($cache && $home_category){S($cachename,$home_category);};
    return $home_category;		
}
function historyback(){
    $url='javascript:history.back()';
    if($_SERVER['HTTP_REFERER']){
        $REFERER=strtr($_SERVER['HTTP_REFERER'],array('index.php'=>'','?'=>'','.html'=>''));
        $exp=explode('/',strtolower($_SERVER['HTTP_REFERER']));
        if($exp[3]=='mobile' && ($exp[4]=='index' || empty($exp[4])) && ($exp[4]=='index' || empty($exp[4]))){
            $url=U('Mobile/Index/index');
        }
    }else{
        $url=U('Mobile/Index/index');
    }
    return $url;
}
?>