<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 联盟城市
 */
namespace app\ais\model;
use think\Model;
use category\Tree;

class AisCity extends Model{
    

    /**
     * 获取访问路径
     * @param int $parent_id
     */
    public static function selectPath($parent_id) {
        $pathMaps[] = ['name'=>'城市','url'=>url('admin.city/index')];
        $getPath = self::getPath($parent_id);
        foreach ($getPath as $value) {
            $pathMaps[] = ['name' => $value['name'],'url' => url('admin.city/index',['parent_id'=>$value['id']])];
        }
        return $pathMaps;
    }

    /**
     * 获取当前路径
     * @param type $parent_id
     * @return type
     */
    public static function getPath($parent_id){
        $result = self::field('id,name,parent_id')->select();
        $tree =  new Tree(array('id','parent_id','name','title'));
        return $tree->getPath($result,$parent_id);
    }
}