<?php
/**
* @author 龙虾 <15108148@qq.com>
* @version 1.13 2020-04-03
* @copyright 睿谷信息 <www.rgxx.com>
*/
namespace app\common\model;
use think\Model;
use app\common\model\Cmsmodels;

class Category extends Model
{
	protected $json = ['config'];
    protected $jsonAssoc = true;
	public static function getTree($model_id,$siteid,$id='')
	{
		$modelinfo = Cmsmodels::get($model_id);
		$data = [['title' => $modelinfo->title,'etitle' => $modelinfo->getData('name'),'pid' => -1,'id' => 0,'spread'=> true]];
		$list = self::when(!empty($id),function($query)use($id){
			$query->whereId('<>',$id);
		})->whereSiteId($siteid)->whereCmsmodelsId($model_id)->withAttr('spread',function(){
			return true;
		})->withAttr('disabled',function($value,$data){
			// if($data['status'] == 0) return true;
		})->append(['spread','disabled'])->order('torder asc')->select();
		if(!$list->isEmpty()){
			$data = array_merge($data,$list->toArray());
		}
		return json_encode(arr2tree($data,-1));
	}
}