Browse Source

非超管角色增加角色菜单栏目显示的过滤

master
xiaodong 1 week ago
parent
commit
b86fda7881
  1. 30
      app/controller/backend/CategoryController.php
  2. 18
      app/service/RoleService.php

30
app/controller/backend/CategoryController.php

@ -374,11 +374,41 @@ class CategoryController extends BaseController
return jsonReturn(-1, $e->getError()); 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 = new Website();
$website = $Website->getAllCustomArrayData([['id','in',$param['site_id']],['seller_id','=',$this->admin['seller_id']]] $website = $Website->getAllCustomArrayData([['id','in',$param['site_id']],['seller_id','=',$this->admin['seller_id']]]
,'id asc','id,seller_id,title,domain')['data']; ,'id asc','id,seller_id,title,domain')['data'];
$website = getColumnForKeyArray($website,'id'); $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 = $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'); $category = getArrayGroupBy($category,'website_id');
$response = []; $response = [];

18
app/service/RoleService.php

@ -77,6 +77,24 @@ class RoleService
Cache::set('user-auth',$authKeyArr); Cache::set('user-auth',$authKeyArr);
Cache::set($authKey,$allowPath); 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 = []; $menu = [];
$dynamic = []; $dynamic = [];
foreach ($auth as $val){ foreach ($auth as $val){

Loading…
Cancel
Save