diff --git a/app/controller/backend/CategoryController.php b/app/controller/backend/CategoryController.php index 2e8b51d..f723d86 100644 --- a/app/controller/backend/CategoryController.php +++ b/app/controller/backend/CategoryController.php @@ -374,11 +374,41 @@ class CategoryController extends BaseController return jsonReturn(-1, $e->getError()); } + // 非超管:从缓存读取 customContent 对应的栏目ID + $customContentCateIds = []; + if ($this->admin['uid'] != 1) { + $customContentCateIds = Cache::get('custom_cate_' . $this->admin['seller_id'] . '_' . $this->admin['uid'], []); + } + $Website = new Website(); $website = $Website->getAllCustomArrayData([['id','in',$param['site_id']],['seller_id','=',$this->admin['seller_id']]] ,'id asc','id,seller_id,title,domain')['data']; $website = getColumnForKeyArray($website,'id'); + // 有 customContent 菜单权限时,按栏目ID过滤;否则不限制 + if (!empty($customContentCateIds)) { + $category = $Category->getAllCustomArrayData([['id','in',$customContentCateIds],['seller_id','=',$this->admin['seller_id']],['lang','=',$param['lang']]],'id asc')['data']; + $cateArr = is_array($category) ? $category : $category->toArray(); + $websiteIds = array_unique(array_column($cateArr, 'website_id')); + $allCategory = $Category->getAllCustomArrayData([['website_id','in',implode(',',$websiteIds)],['seller_id','=',$this->admin['seller_id']],['lang','=',$param['lang']]],'id asc')['data']; + $allCategory = getArrayGroupBy($allCategory, 'website_id'); + $response = []; + foreach ($allCategory as $key => $cate) { + if (!isset($website[$key])) continue; + $tmpCategory = $this->makeTree($cate); + $tmpCategory = $this->imp($tmpCategory); + $tmpCategory = array_values(array_filter($tmpCategory, function($item) use ($customContentCateIds) { + return in_array((int)$item['id'], $customContentCateIds); + })); + if (!empty($tmpCategory)) { + $tmpCate = $website[$key]; + $tmpCate['category'] = $tmpCategory; + $response[] = $tmpCate; + } + } + return jsonReturn(0, lang('成功'), $response); + } + $category = $Category -> getAllCustomArrayData([['website_id','in',$param['site_id']],['seller_id','=',$this->admin['seller_id']],['lang','=',$param['lang']]],'id asc')['data']; $category = getArrayGroupBy($category,'website_id'); $response = []; diff --git a/app/service/RoleService.php b/app/service/RoleService.php index 7ab38e9..fbb9de4 100644 --- a/app/service/RoleService.php +++ b/app/service/RoleService.php @@ -77,6 +77,24 @@ class RoleService Cache::set('user-auth',$authKeyArr); Cache::set($authKey,$allowPath); + // 缓存 customContent 菜单对应的栏目ID + $customContentCateIds = []; + $customContentParentIds = []; + foreach ($auth as $value) { + if (isset($value['name']) && $value['name'] === 'customContent') { + $customContentParentIds[] = $value['id']; + } + } + foreach ($auth as $value) { + if (in_array($value['parent_id'], $customContentParentIds) && !empty($value['param'])) { + parse_str($value['param'], $parsed); + if (!empty($parsed['category_id'])) { + $customContentCateIds[] = (int)$parsed['category_id']; + } + } + } + Cache::set('custom_cate_' . $admin['seller_id'] . '_' . $admin['id'], $customContentCateIds, 10); + $menu = []; $dynamic = []; foreach ($auth as $val){