evoxwht 4 лет назад
Родитель
Сommit
cd68d42a31

+ 3 - 1
crmeb/app/adminapi/controller/v1/file/SystemAttachmentCategory.php

@@ -38,8 +38,10 @@ class SystemAttachmentCategory extends AuthController
     public function index()
     {
         $where = $this->request->getMore([
-            ['name', '']
+            ['name', ''],
+            ['pid', 0]
         ]);
+        if ($where['name'] != '') $where['pid'] = '';
         return app('json')->success($this->service->getAll($where));
     }
 

+ 2 - 2
crmeb/app/model/system/attachment/SystemAttachmentCategory.php

@@ -44,7 +44,7 @@ class SystemAttachmentCategory extends BaseModel
      */
     public function searchNameAttr($query, $value)
     {
-        if ($value) $query->where('name', 'like', '%' . $value . '%');
+        if ($value != '') $query->where('name', 'like', '%' . $value . '%');
     }
 
     /**
@@ -54,7 +54,7 @@ class SystemAttachmentCategory extends BaseModel
      */
     public function searchPidAttr($query, $value)
     {
-        $query->where('pid', $value);
+        if ($value !== '') $query->where('pid', $value);
     }
 
 }

+ 6 - 14
crmeb/app/services/system/attachment/SystemAttachmentCategoryServices.php

@@ -8,7 +8,7 @@
 // +----------------------------------------------------------------------
 // | Author: CRMEB Team <admin@crmeb.com>
 // +----------------------------------------------------------------------
-declare (strict_types=1);
+declare (strict_types = 1);
 
 namespace app\services\system\attachment;
 
@@ -45,20 +45,12 @@ class SystemAttachmentCategoryServices extends BaseServices
      */
     public function getAll(array $where)
     {
-        $categoryList = $this->dao->getList($where);
-        if ($where['name'] != '') {
-            $pids = Arr::getUniqueKey($categoryList, 'pid');
-            $parentList = $this->dao->getList(['id' => $pids]);
-            $categoryList = array_merge($categoryList, $parentList);
-            foreach ($categoryList as $key => $item) {
-                $arr = $categoryList[$key];
-                unset($categoryList[$key]);
-                if (!in_array($arr, $categoryList)) {
-                    $categoryList[] = $arr;
-                }
-            }
+        $list = $this->dao->getList($where);
+        foreach ($list as &$item) {
+            $item['title'] = $item['name'];
+            $item['children'] = [];
+            if ($where['name'] == '' && $this->dao->count(['pid' => $item['id']])) $item['loading'] = false;
         }
-        $list = $this->tidyMenuTier($categoryList);
         return compact('list');
     }