<?php 
namespace app\common\model;
use think\Model;
class JobsCate extends Model
{
    public static function getSelect($where=[])
    {
        $Data=self::where($where)->order('sort asc,id asc')->select();
        foreach ($Data as $k => $v) {
            $Data[$k]['hasChildren']=self::where(['pid'=>$v['id']])->count();
        }
        return $Data;
    }
    public static function getCateSelect()
    {
    $cate=self::field('id,pid,title,icon')->withAttr('icon',function($v,$data){
        return $v?config('web.imgurl').$v:'';
    })->order('sort asc,id asc')->select();
    return $cate;
    }
    public static function getCate()
    {
    $cate=self::where(['pid'=>0])->field('id,title,icon')->withAttr('icon',function($v,$data){
            return $v?config('web.imgurl').$v:'';
        })->order('sort asc,id asc')->select();
    foreach ($cate as $k => $v) {
        $cate[$k]['data']=self::where(['pid'=>$v['id']])->field('id,title,icon')->withAttr('icon',function($v,$data){
                return $v?config('web.imgurl').$v:'';
            })->order('sort asc,id asc')->select();
    }
    return $cate;
    }
    public static function getCache()
    {
    $cate=self::where(['pid'=>0,'status'=>1])->field('id,title,icon')->withAttr('icon',function($v,$data){
            return $v?config('web.imgurl').$v:'';
        })->order('sort asc,id asc')->select();
    foreach ($cate as $k => $v) {
        $cate1=self::where(['pid'=>$v['id'],'status'=>1])->field('id,title,icon')->withAttr('icon',function($v,$data){
            return $v?config('web.imgurl').$v:'';
        })->order('sort asc,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,icon')->withAttr('icon',function($v,$data){
                return $v?config('web.imgurl').$v:'';
            })->order('sort asc,id asc')->select();
        }
    }
    return $cate;
    }
}