<?php
namespace app\model;

use think\Model;


class Category extends Model
{
	protected $table = "jm_category";

	public static function make_tree($list , $pk = 'id' , $pid = 'parent_id', $child = 'child' , $root = 0)
	{
		$tree = [];
		foreach($list as $key => $val)
		{
			if($val[$pid] == $root) {
				// 获取当前$pid所有子类
				unset($list[$key]);
				if(!empty($list)) {
					$child = self::make_tree($list , $pk , $pid , $child , $val[$pk]); // 找到子栏目
					if(!empty($child)) {
						$val['child'] = $child;
					}
				}
				$tree[] = $val;
			}
		}
		return $tree;
	}

}
