<?php
class baseAction extends Action {
	protected function _initialize() {
		//获取通用信息
		$config_data = $this->get_config();
		$this->assign("config_data",$config_data);
		$user = '';
		if(cookie('feimao_xiaohua_username') == true){//有cookie状态
			$user = M('users')->where("username='". cookie('feimao_xiaohua_username') ."' or email = '". cookie('feimao_xiaohua_username') ."'")->find();
			$user['g'] = M('users_group')->where("min_integral <= ". $user['integral'] ."")->order("min_integral desc")->find();
		}
		$this->assign('user',$user);
		
	}
	protected function object2array(&$object) {
        $object =  json_decode( json_encode( $object),true);
        return  $object;
    }
	protected function user_info(){
		if(cookie('feimao_xiaohua_username') == true){//有cookie状态
			$user = M('users')->where("username='". cookie('feimao_xiaohua_username') ."'")->find();
			$user['g'] = M('users_group')->where("min_integral <= ". $user['integral'] ."")->order("min_integral desc")->find();
		}else{
			$user = '';
		}
		return $user;
	}
	/*获取通用网站设置信息
	web_setting*/
	protected function get_config(){
		/*获取网站通用信息 web_config*/
		if(cache('config_datas') == false) {
		$web_setting = M('web_setting')->select();
		foreach($web_setting as $k=>$v){
			$return[$v['name']] = $v['value'];
		}
		cache('config_datas',$return);
		}
		return cache('config_datas');
	}
	/*********
	获取商品分类
	**********/
	protected function get_store_category($fid='0'){
		if(cache('store_category_datas') == false) {
			$cate_data = D('store_category')->where("fid='".$fid."'")->order("listorder asc,id asc")->select();//获取商品分类
			foreach($cate_data as $k=>$v){
				$cate_data1 = D('store_category')->where("fid='".$v['id']."'")->order("listorder asc,id asc")->select();
				$cate_data[$k]['zi'] = $cate_data1;
				foreach($cate_data1 as $ks=>$vs) {
					$cate_data2 = D('store_category')->where("fid='".$vs['id']."'")->order("listorder asc,id asc")->select();
					$cate_data[$k]['zi'][$ks]['zi'] = $cate_data2;
				}
			}
			cache('store_category_datas',$cate_data);
		}

		return cache('store_category_datas');
	}
}
?>