diff --git a/crmeb/app/adminapi/controller/v1/file/SystemAttachmentCategory.php b/crmeb/app/adminapi/controller/v1/file/SystemAttachmentCategory.php index 40d9ef6ed..c25f21c91 100644 --- a/crmeb/app/adminapi/controller/v1/file/SystemAttachmentCategory.php +++ b/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)); } diff --git a/crmeb/app/model/system/attachment/SystemAttachmentCategory.php b/crmeb/app/model/system/attachment/SystemAttachmentCategory.php index 46034c26a..9a13d4a03 100644 --- a/crmeb/app/model/system/attachment/SystemAttachmentCategory.php +++ b/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); } } diff --git a/crmeb/app/services/system/attachment/SystemAttachmentCategoryServices.php b/crmeb/app/services/system/attachment/SystemAttachmentCategoryServices.php index 881ca3b86..4d3e8122f 100644 --- a/crmeb/app/services/system/attachment/SystemAttachmentCategoryServices.php +++ b/crmeb/app/services/system/attachment/SystemAttachmentCategoryServices.php @@ -8,7 +8,7 @@ // +---------------------------------------------------------------------- // | Author: CRMEB Team // +---------------------------------------------------------------------- -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'); }