diff --git a/app/controller/ResourceDirController.php b/app/controller/ResourceDirController.php index 34be190..4d1b9ee 100644 --- a/app/controller/ResourceDirController.php +++ b/app/controller/ResourceDirController.php @@ -125,6 +125,9 @@ class ResourceDirController Db::startTrans(); try { // 复制资源 + // $resource = Resource::find(1); + // dd($resource); + // die; $res = (new ResourceDirService())->copyTo($request->param('ids'), $request->param('to_id')); Db::commit(); } catch (\Exception $e) { diff --git a/app/service/ResourceDirService.php b/app/service/ResourceDirService.php index 21e2372..5af0173 100644 --- a/app/service/ResourceDirService.php +++ b/app/service/ResourceDirService.php @@ -127,12 +127,14 @@ class ResourceDirService extends Service */ 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); @@ -147,14 +149,14 @@ class ResourceDirService extends Service { foreach ($ids as $resource_id) { - // 复制源文件夹 + //获取源文件 和子文件 $resource = Resource::find($resource_id); + $children = Resource::with(['files', 'accredit_files'])->where('parent_id', $resource->id)->select(); + // 复制源文件夹 $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) { diff --git a/app/service/ResourceService.php b/app/service/ResourceService.php index 962c720..cbf1755 100644 --- a/app/service/ResourceService.php +++ b/app/service/ResourceService.php @@ -122,7 +122,8 @@ class ResourceService extends Service foreach ($resource['files'] as $key => $file) { unset($resource['files'][$key]['id']); unset($resource['files'][$key]['resource_id']); //去掉原来的关联关系 - + $resource['files'][$key]['create_time'] = date('Y-m-d H:i:s'); + $resource['files'][$key]['update_time'] = date('Y-m-d H:i:s'); } } @@ -130,6 +131,8 @@ class ResourceService extends Service foreach ($resource['accredit_files'] as $key => $file) { unset($resource['accredit_files'][$key]['id']); unset($resource['accredit_files'][$key]['resource_id']); //去掉原来的关联关系 + $resource['files'][$key]['create_time'] = date('Y-m-d H:i:s'); + $resource['files'][$key]['update_time'] = date('Y-m-d H:i:s'); } }