仪表盘路由
This commit is contained in:
@@ -2,8 +2,13 @@
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\model\Resource;
|
||||
use app\common\model\Role;
|
||||
use app\common\model\User;
|
||||
use app\common\model\UserGroup;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\UserDashboardRuleService;
|
||||
use Couchbase\Group;
|
||||
|
||||
class UserDashboardRuleController extends BaseController
|
||||
{
|
||||
@@ -22,12 +27,21 @@ class UserDashboardRuleController extends BaseController
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
// protected function indexFormat($data)
|
||||
// {
|
||||
// if (isset($data['created_at']))
|
||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
// if (isset($data['updated_at']))
|
||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
// return $data;
|
||||
// }
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
if (isset($data['resources_id']))
|
||||
$data['resources'] = Resource::where(['id' => $data['resources_id']])->first();
|
||||
if (isset($data['rule_type']) && $data['rule_type'] == 'role'){
|
||||
$data['related_rt'] = Role::where(['id' => $data['related']])->value('name');
|
||||
}elseif (isset($data['rule_type']) && $data['rule_type'] == 'user'){
|
||||
$data['related_rt'] = User::where(['id' => $data['related']])->value('name');
|
||||
}elseif (isset($data['rule_type']) && $data['rule_type'] == 'group'){
|
||||
$data['related_rt'] = UserGroup::where(['id' => $data['related']])->value('title');
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -24,11 +24,12 @@ class PermLogic
|
||||
|
||||
$all = collect();
|
||||
//获取仪表盘
|
||||
// $resources_id = (new UserDashboardRuleLogic)->getUserDashboard($userId);
|
||||
// if(!empty($resources_id)){
|
||||
// $resources = Resource::where('id', $resources_id)->first();
|
||||
// $all = $all->merge($resources);
|
||||
// }
|
||||
$resources_id = (new UserDashboardRuleLogic)->getUserDashboard($userId);
|
||||
if(!empty($resources_id)){
|
||||
$resources = Resource::where('id', $resources_id)->get();
|
||||
$all = $all->merge($resources);
|
||||
}
|
||||
return $all->unique('id')->values()->sortBy('sort');
|
||||
|
||||
// 遍历用户的所有角色,合并每个角色所拥有的资源
|
||||
foreach ($user->roles as $role) {
|
||||
|
||||
@@ -22,7 +22,7 @@ class UserDashboardRuleLogic
|
||||
$user = User::with('reportToInfo')->find($userId);;
|
||||
//获取用户所在分组
|
||||
$ugm = UserGroupMembers::where('user_id', $userId)->where('status', 1)->get();
|
||||
$group_id = $ugm?$ugm->group_id:0;
|
||||
$group_id = isset($ugm->group_id)?$ugm->group_id:0;
|
||||
|
||||
$roleRule = UserDashboardRule::orWhere(function ($query) use ($user) {
|
||||
$query->whereIn('related', $user->roles->pluck('id'))
|
||||
|
||||
Reference in New Issue
Block a user