<?php
namespace homeh5\action;
use model\homecn\cate;
use \model\carmodelcn;
class indexAction extends baseAction
{
	function cache()
	{
		$Params = \mvc::$req;
		if(!empty($Params['css']))
		{
			switch($Params['css'])
			{
				case 'common':
					header("Content-type: text/css");
					$file = file_get_contents(\mvc::$cfg['SYS_ROOT'].'static/css/common.css');
					$file = str_replace('url(../', 'url('.\mvc::$cfg['path']['static'].'/', $file);
					if(!empty(\mvc::$cfg['shopInfo']['ssu_conf']['color']))
						$file = str_replace('#e7181e', \mvc::$cfg['shopInfo']['ssu_conf']['color'], $file);
					echo $file;
					exit;
				break;
			}
		}
	}


	function index()
	{
        // 获取热门中国车型
        $param = ['m_type' => 'hot'];
        $carmodelcn = new carmodelcn();
        $brandList = $carmodelcn->getBrandListByFilter($param);
        // 获取用户信息
        $user = $_SESSION['cnuser'];
        $banner = !empty(\mvc::$cfg['info']['homeBackgroundImgs'])? explode(',',\mvc::$cfg['info']['homeBackgroundImgs']):[];
        \view::set('banner',$banner);
        \view::Set('tagsArr',$brandList);
        \view::set('user', $user);
		\view::set('footMenu', 'index');
		\view::set('title', '首页');
		\view::put();
	}

    // 获取分类列表(国际车型 中国车型通用)
    function getCateLists()
    {
        $this->mustLogin();
        $req = \mvc::$req;
        $cate = new cate();
        $params = [];
        if(!empty($req['mm_id'])){
            $params['mm_id'] = $req['mm_id'];
        }
        if(!empty($req['mod3_id'])){
            $params['mod3_id'] = $req['mod3_id'];
        }
        if(!empty($req['number'])){
            $params['number'] = $req['number'];
        }
        $cateLists = $cate->getCateLists($_SESSION['cnuser']['u_id'],$params);
        $this->successJson($cateLists);
    }

    // 根据分类id获取产品列表
    function getProLists(){
        $this->mustLogin();
        $req = \mvc::$req;
        $cate = new cate();
        $data = $cate->getProList($req);
        $this->successJson($data);
    }

	/**设置微信的oppenid到session，并进行跳转**/
	function setWxOpenid()
	{
		$Params = \mvc::$req;
		if(!empty($Params['udata']))
		{
			$WXUserArr = json_decode(base64_decode($Params['udata']), true);
			if(!empty($WXUserArr['openid']))
			{
				$_SESSION['wx_oppenid'] = $WXUserArr['openid'];
			}
		}
		$backUrl = !empty($Params['backUrl'])? base64_decode($Params['backUrl']): \mvc::$cfg['SELF_URI'];
		Header("Location: ".$backUrl);
	}
}
