<?php
/**
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */

namespace Member\Controller;
use Common\Controller\HanchaoController;
class BaseController extends HanchaoController{
	public function _initialize(){
		parent::_initialize ();
		define('MID',is_login(0));
		$this->assign('MID',MID);
        GLOBAL $GoodsCategory;
        if(empty($GoodsCategory))$GoodsCategory=getcache('GoodsCategory');
		$notauthmodule=array("Login","Oauth");
        if(!MID && !in_array(CONTROLLER_NAME,$notauthmodule)){// 还没登录 跳转到登录页面
			cookie('forward',U('Member/'.CONTROLLER_NAME.'/'.ACTION_NAME));
			$this->redirect('Home/Login/index');
		}
		$ismobile=is_mobile();$ismobile_cookie=$_COOKIE['ismobile'];
        if($ismobile && !$ismobile_cookie && !in_array(CONTROLLER_NAME,array('App','Pay','Weixin','Oauth','Ajax'))){ $this->redirect('Mobile/Member/index'); exit;}
        
		//初始化地区信息
		$result = D('Common/Area')->init();
		$regioncache = get_arearegion_cache(1);
		$result_format = D('Common/Area')->area_format($regioncache,1);//格式化省信息
		$this->assign('regioncache',$result_format);
		$this->assign('address_info_format',$result['address_info_format']);
		$province = Intval($result['address_info']['province']);
		$city = Intval($result['address_info']['city']);
		if($province>0){
			$regioncaches = get_arearegion_cache(0);
			$result_format = D('Common/Area')->area_format($regioncaches[$province]);//格式化市信息
			$this->assign('regioncitycache',$result_format);
			$this->assign('regioncityon',$province);
			if($city>0){
				$result_format = D('Common/Area')->area_format($regioncaches[$city]);//格式化区县信息
				$this->assign('regiondistrictcache',$result_format);
				$this->assign('regiondistricton',$city);
			}
		}
        //头部分类
        $header_cate=D("Common/GoodsCategory")->getcatelist();
        $this->assign('header_cates',$header_cate);
    }
}
?>