|
@@ -30,7 +30,36 @@ class ContainerController extends Controller
|
|
|
{
|
|
|
$containers = Container::query()->filter($request->all())->paginate();
|
|
|
|
|
|
- return ContainerResource::collection($containers);
|
|
|
+
|
|
|
+ $foldsCount = Folder::query()
|
|
|
+ ->where('object_type','container')
|
|
|
+ ->where('parent_id',0)
|
|
|
+ ->whereIn("object_id", $containers->pluck("id")->toArray())
|
|
|
+ ->selectRaw("count(*) as cut, object_id")
|
|
|
+ ->groupBy("object_id")
|
|
|
+ ->pluck("cut", "object_id");
|
|
|
+
|
|
|
+ $fileCount = File::query()
|
|
|
+ ->where('object_type','container')
|
|
|
+ ->whereIn('object_id',$containers->pluck("id")->toArray())
|
|
|
+ ->where("is_latest_version", 1)
|
|
|
+ ->selectRaw("count(*) as cut, object_id")
|
|
|
+ ->groupBy("object_id")
|
|
|
+ ->pluck("cut", "object_id");
|
|
|
+
|
|
|
+
|
|
|
+ $containers = $containers->map(function (Container $container) use ($foldsCount,$fileCount) {
|
|
|
+ $container->itemCount =$foldsCount->get($container->id, 0)+$fileCount->get($container->id, 0);
|
|
|
+ $container->type = 'container';
|
|
|
+ $container->uniId = $container->type . '_' . $container->id;
|
|
|
+ return $container;
|
|
|
+ });
|
|
|
+
|
|
|
+ return $this->success([
|
|
|
+ 'data' => $containers
|
|
|
+ ]);
|
|
|
+
|
|
|
+ //return ContainerResource::collection($containers);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -180,9 +209,6 @@ class ContainerController extends Controller
|
|
|
// 设置固定的type值
|
|
|
$items->type = 'container';
|
|
|
$items->uniId=$items->type.'_'.$items->id;
|
|
|
- $foldCount=Folder::query()->where('object_type',$items->type)->where('object_id',$items->id)->count();
|
|
|
- $filesCount=File::query()->where('object_type',$items->type)->where('object_id',$items->id)->where('is_latest_version',1)->count();
|
|
|
- $items->itemCount=$foldCount+$filesCount;
|
|
|
});
|
|
|
|
|
|
return $this->success([
|