|
|
|
@ -17,7 +17,6 @@ class ResourceDirService extends Service |
|
|
|
{ |
|
|
|
try { |
|
|
|
$resource_dir = ResourceDir::create($param); |
|
|
|
|
|
|
|
//更新id_path
|
|
|
|
$resource_dir->id_path = $this->getResourceDirIdPath($resource_dir->id); |
|
|
|
$resource_dir->save(); |
|
|
|
@ -121,6 +120,75 @@ class ResourceDirService extends Service |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @param $ids 需要复制的文件夹资源ids |
|
|
|
* @param $to_id 文件夹资源id |
|
|
|
* @return array |
|
|
|
* 复制操作 |
|
|
|
*/ |
|
|
|
public function copyTo($ids, $to_id) |
|
|
|
{ |
|
|
|
// 更新 新的文件夹资源 以及所有父文件夹资源 大小和数量
|
|
|
|
foreach ($ids as $resource_id) { |
|
|
|
$resource = Resource::find($resource_id); |
|
|
|
(new ResourceDirService())->changeDirSizeAndCount($resource, $to_id, '+'); |
|
|
|
} |
|
|
|
|
|
|
|
//递归复制
|
|
|
|
$this->copyFolderRecursively($ids, $to_id); |
|
|
|
return dataReturn($this->sucCode, $this->copyMsg); |
|
|
|
} |
|
|
|
/** |
|
|
|
* @param $ids 需要复制的普通资源ids |
|
|
|
* @param $to_id 文件夹资源id |
|
|
|
* @return array |
|
|
|
* 递归复制资源文件夹及其内容 |
|
|
|
*/ |
|
|
|
public function copyFolderRecursively($ids, $to_id) |
|
|
|
{ |
|
|
|
|
|
|
|
foreach ($ids as $resource_id) { |
|
|
|
// 复制源文件夹
|
|
|
|
$resource = Resource::find($resource_id); |
|
|
|
|
|
|
|
$new_resource_dir = $this->copyResourceDir($resource->toArray(), $to_id); |
|
|
|
$new_resource_dir_id = $new_resource_dir['data']; |
|
|
|
|
|
|
|
// 复制子文件和子文件夹
|
|
|
|
$children = Resource::with(['files', 'accredit_files'])->where('parent_id', $resource->id)->select(); |
|
|
|
|
|
|
|
if ($children) { |
|
|
|
foreach ($children as $child) { |
|
|
|
if ($child['type'] == '2') { |
|
|
|
// 递归复制子文件夹
|
|
|
|
$this->copyFolderRecursively([$child['id']], $new_resource_dir_id); |
|
|
|
} else { |
|
|
|
// 复制文件
|
|
|
|
(new ResourceService())->copyResource($child->toArray(), $new_resource_dir_id); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @param $resource 资源数组(因为前台创建是数组 保持一致) |
|
|
|
* @param $to_id 复制到的文件夹id |
|
|
|
* @return array |
|
|
|
* 复制一个文件夹资源数据 |
|
|
|
*/ |
|
|
|
public function copyResourceDir($resource, $to_id) |
|
|
|
{ |
|
|
|
unset($resource['id']); |
|
|
|
$resource['create_time'] = date('Y-m-d H:i:s'); |
|
|
|
$resource['update_time'] = date('Y-m-d H:i:s'); |
|
|
|
$resource['parent_id'] = $to_id; |
|
|
|
|
|
|
|
//重新创建资源
|
|
|
|
return $this->addResourceDir($resource); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 递归更新文件夹的 id_path |
|
|
|
* |
|
|
|
* @param int $folderId 要更新的文件夹 ID |
|
|
|
|