AisCity.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 联盟城市
  7. */
  8. namespace app\ais\model;
  9. use think\Model;
  10. use category\Tree;
  11. class AisCity extends Model{
  12. /**
  13. * 获取访问路径
  14. * @param int $parent_id
  15. */
  16. public static function selectPath($parent_id) {
  17. $pathMaps[] = ['name'=>'城市','url'=>url('admin.city/index')];
  18. $getPath = self::getPath($parent_id);
  19. foreach ($getPath as $value) {
  20. $pathMaps[] = ['name' => $value['name'],'url' => url('admin.city/index',['parent_id'=>$value['id']])];
  21. }
  22. return $pathMaps;
  23. }
  24. /**
  25. * 获取当前路径
  26. * @param type $parent_id
  27. * @return type
  28. */
  29. public static function getPath($parent_id){
  30. $result = self::field('id,name,parent_id')->select();
  31. $tree = new Tree(array('id','parent_id','name','title'));
  32. return $tree->getPath($result,$parent_id);
  33. }
  34. }