<?php
/**
 * 分类
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaol <1094186793@sina.cn>
 */
namespace Mobile\Model;
use Think\Model;
class CateModel extends Model{
    protected $tableName = 'Goods';
    public function get_cat_index(){
        $map=array();
        $map['pid']=0;
        $map['status']=1;
        $category=array();
        $fir_cat=M('GoodsCategory')->where($map)->order('sort asc')->select();
        foreach($fir_cat as $k=>$v){
            $v=$this->format_cat_item($v);
            $category[$k]=$v;
            $fir_child_map=array();
            $fir_child_map['pid']=$v['id'];
            $fir_child_map['status']=1;
            $fir_cat_child=M('GoodsCategory')->where($fir_child_map)->select();
            foreach($fir_cat_child as $ke=>$va){
                $va=$this->format_cat_item($va);
                $category[$k]['child_cate'][$ke]=$va;
                $sec_child_map=array();
                $sec_child_map['pid']=$va['id'];
                $sec_child_map['status']=1;
                $sec_cat_child=M('GoodsCategory')->where($sec_child_map)->select();
                foreach($sec_cat_child as $key=>$val){
                    $category[$k]['child_cate'][$ke]['child_cate'][$key]=$this->format_cat_item($val);
                }
            }
        }
        return $category;
    }
    public function format_cat_item($data=array()){
        $return=array();
        $return['id']=$data['id'];
        $return['name']=$data['name'];
        $return['pid']=$data['pid'];
        $return['type_id']=$data['type_id'];
        $return['img']=thumb($data['img'],350,350,'noimg_186x186.png');
        $return['url']=geturl('Goods/index',array('cat_id'=>$data['id']));
        $return['integralurl']=geturl('Integral/index',array('cat_id'=>$data['id'],'is_integral'=>1));
        return $return;
    }
}