Browse Source

文件夹复制。。已经晕了

master
unknown 1 year ago
parent
commit
0c2bc17947
  1. 3
      app/controller/ResourceDirController.php
  2. 8
      app/service/ResourceDirService.php
  3. 5
      app/service/ResourceService.php

3
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) {

8
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) {

5
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');
}
}

Loading…
Cancel
Save