<?php 
namespace app\common\model;

use think\Model;

class Area extends Model
{
	/**
	 * 获取所有
	 */
	public static function getSelect($where=[])
	{
		$auth=self::where($where)->order('id asc')->select();
		foreach ($auth as $k => $v) {
			$auth[$k]['hasChildren']=self::where(['pid'=>$v['id']])->count();
		}
		return $auth;
	}
	public static function getCate()
	{
        $cate=self::where(['pid'=>0])->field('id,title,letter')->order('id asc')->select();
        foreach ($cate as $k => $v) {
        	$cate[$k]['data']=self::where(['pid'=>$v['id']])->field('id,title,letter')->order('id asc')->select();
        }
        return $cate;
	}
	public static function getCateForStatus()
	{
        $cate=self::where(['pid'=>0,'status'=>1])->field('id,title,letter')->order('id asc')->select();
        foreach ($cate as $k => $v) {
        	$cate[$k]['disabled']=true;
        	$cate[$k]['data']=self::where(['pid'=>$v['id'],'status'=>1])->field('id,title,letter')->order('id asc')->select();
        }
        return $cate;
	}
	public static function getCache()
	{
        $cate=self::where(['pid'=>0,'status'=>1])->field('id,title,letter')->order('id asc')->select();
        foreach ($cate as $k => $v) {
        	$cate1=self::where(['pid'=>$v['id'],'status'=>1])->field('id,title,letter')->order('id asc')->select();
        	$cate[$k]['data']=$cate1;
        	foreach ($cate1 as $ke => $va) {
	        	$cate[$k]['data'][$ke]['data']=self::where(['pid'=>$va['id'],'status'=>1])->field('id,title,letter')->order('id asc')->select();
        	}
        }
        return $cate;
	}
}