|
@@ -14,9 +14,11 @@ class DistAppearanceTemplate extends EloquentRepository
|
|
|
*/
|
|
|
protected $eloquentClass = Model::class;
|
|
|
|
|
|
- public static function getContent($id)
|
|
|
+ public static function getContent($appearanceId,$distId,$templateCode)
|
|
|
{
|
|
|
- $data = Model::where('id', $id)->first();
|
|
|
+ $appearanceId = intval($appearanceId);
|
|
|
+ $distId = intval($distId);
|
|
|
+ $data = Model::where('appearance_id', $appearanceId)->where('dist_id', $distId)->where('template_code', $templateCode)->first();
|
|
|
if ($data) {
|
|
|
return $data->content;
|
|
|
}
|
|
@@ -24,35 +26,54 @@ class DistAppearanceTemplate extends EloquentRepository
|
|
|
}
|
|
|
public static function getTemplateTree($appearance_id,$dist_id)
|
|
|
{
|
|
|
- $data = Model::where('appearance_id', $appearance_id)->where('dist_id', $dist_id)->orderBy('file_type', 'desc')->orderBy('file_path', 'asc')->get(['id', 'file_name', 'parent_id','file_type','file_path']);
|
|
|
- return self::buildTree($data->toArray(),0);
|
|
|
+ $data = Model::where('appearance_id', $appearance_id)->where('dist_id', $dist_id)->orderBy('file_path', 'asc')->get(['id', 'file_name', 'file_path','template_code']);
|
|
|
+ return self::buildTree($data->toArray());
|
|
|
}
|
|
|
|
|
|
- public static function buildTree(array $elements, $parentId = 0) {
|
|
|
- $branch = [];
|
|
|
+ public static function buildTree(array $data) {
|
|
|
+ $result = [];
|
|
|
+ foreach ($data as $item) {
|
|
|
+ // Extract the path and file information
|
|
|
+ $path = $item['file_path'];
|
|
|
+ $id = $item['id'];
|
|
|
+ $file_name = $item['file_name'];
|
|
|
|
|
|
- foreach ($elements as $element) {
|
|
|
- if ($element['parent_id'] == $parentId) {
|
|
|
- $children = self::buildTree($elements, $element['id']);
|
|
|
- if ($children) {
|
|
|
- $element['children'] = $children;
|
|
|
- }
|
|
|
- $branch[] = $element;
|
|
|
+ // Initialize a new entry for this path if it doesn't exist
|
|
|
+ if (!isset($result[$path])) {
|
|
|
+ $result[$path] = [
|
|
|
+ 'id' => 0, // default, as there's no parent ID
|
|
|
+ 'dist_id' => 0, // assuming dist_id for path
|
|
|
+ 'file_name' => basename($path), // using the directory name for file_name
|
|
|
+ 'children' => []
|
|
|
+ ];
|
|
|
}
|
|
|
+
|
|
|
+ // Add the file to the children of the respective path
|
|
|
+ $result[$path]['children'][] = [
|
|
|
+ 'id' => $id,
|
|
|
+ 'dist_id' => 0, // assuming dist_id
|
|
|
+ 'file_name' => $file_name,
|
|
|
+ 'template_code' => $item['template_code']
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
- return $branch;
|
|
|
+ $result = array_values($result);
|
|
|
+ return $result;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* 保存模板内容
|
|
|
*/
|
|
|
- public static function saveContent($id, $content)
|
|
|
+ public static function saveContent($appearanceId,$distId,$templateCode, $content)
|
|
|
{
|
|
|
- $data = Model::where('id', $id)->first();
|
|
|
+ $appearanceId = intval($appearanceId);
|
|
|
+ $distId = intval($distId);
|
|
|
+ $data = Model::where('dist_id', $distId)->where('appearance_id', $appearanceId)->where('appearance_id', $appearanceId)->where('template_code', $templateCode)->first();
|
|
|
if ($data) {
|
|
|
$data->content = $content;
|
|
|
$data->save();
|
|
|
+ //加入模版修改日志
|
|
|
+ DistAppearanceTemplateLog::insertLog($appearanceId,$distId,$templateCode,$content);
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
@@ -70,33 +91,31 @@ class DistAppearanceTemplate extends EloquentRepository
|
|
|
/*
|
|
|
* 插入模版文件夹
|
|
|
*/
|
|
|
- public static function insertTemplateFolder($distId,$appearanceId,$filePath,$fileName,$parentId) {
|
|
|
- $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 = 0;
|
|
|
- $model->file_path = $filePath;
|
|
|
- $model->template_code = uniqueCode('');
|
|
|
- $model->save();
|
|
|
- // 获取插入数据的 ID
|
|
|
- $insertedId = $model->id;
|
|
|
- return $insertedId;
|
|
|
- }
|
|
|
+// public static function insertTemplateFolder($distId,$appearanceId,$filePath,$fileName,$parentId) {
|
|
|
+// $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 = 0;
|
|
|
+// $model->file_path = $filePath;
|
|
|
+// $model->template_code = uniqueCode('');
|
|
|
+// $model->save();
|
|
|
+// // 获取插入数据的 ID
|
|
|
+// $insertedId = $model->id;
|
|
|
+// return $insertedId;
|
|
|
+// }
|
|
|
|
|
|
/*
|
|
|
* 插入模版文件内容
|
|
|
*/
|
|
|
- public static function insertTemplateContent($distId,$appearanceId,$filePath,$fileName,$parentId,$content) {
|
|
|
+ public static function insertTemplateContent($distId,$appearanceId,$filePath,$fileName,$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->template_code = uniqueCode('');
|