first(); if ($data) { return $data->content; } return ''; } public static function getTemplateTree($appearance_id,$dist_id) { $data = Model::where('appearance_id', $appearance_id)->where('dist_id', $dist_id)->get(['id', 'file_name', 'parent_id','file_type','file_path']); return self::buildTree($data->toArray(),0); } public static function buildTree(array $elements, $parentId = 0) { $branch = []; foreach ($elements as $element) { if ($element['parent_id'] == $parentId) { $children = self::buildTree($elements, $element['id']); if ($children) { $element['children'] = $children; } $branch[] = $element; } } return $branch; } /* * 保存模板内容 */ public static function saveContent($id, $content) { $data = Model::where('id', $id)->first(); if ($data) { $data->content = $content; $data->save(); return true; } return false; } /* * 请空指定模板 */ public static function deleteTemplates($distId,$appearanceId) { $self = new self(); $self->model()->where('dist_id',$distId)->where('appearance_id',$appearanceId)->delete(); return true; } /* * 插入模版文件夹 */ public static function insertTemplateFolder($distId,$appearanceId,$filePath,$parentId) { $self = new self(); $model = $self->model(); $model->dist_id = $distId; $model->appearance_id = $appearanceId; $model->file_name = $filePath; $model->parent_id = $parentId; $model->file_type = 0; $model->file_path = $filePath; $model->save(); // 获取插入数据的 ID $insertedId = $model->id; return $insertedId; } /* * 插入模版文件内容 */ public static function insertTemplateContent($distId,$appearanceId,$filePath,$fileName,$parentId,$content) { $self = new self(); $model = $self->model(); $model->dist_id = $distId; $model->appearance_id = $appearanceId; $model->file_name = $fileName; $model->parent_id = $parentId; $model->file_type = 1; $model->file_path = $filePath; $model->content = $content; $model->save(); // 获取插入数据的 ID $insertedId = $model->id; return $insertedId; } }