finance-pay/app/adminapi/lists/auth/RoleLists.php

93 lines
2.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\auth;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\auth\AdminRole;
use app\common\model\auth\SystemRole;
/**
* 角色列表
* Class RoleLists
* @package app\adminapi\lists\auth
*/
class RoleLists extends BaseAdminDataLists
{
/**
* @notes 导出字段
* @return string[]
* @author Tab
* @date 2021/9/22 18:52
*/
public function setExcelFields(): array
{
return [
'name' => '角色名称',
'desc' => '备注',
'create_time' => '创建时间'
];
}
/**
* @notes 导出表名
* @return string
* @author Tab
* @date 2021/9/22 18:52
*/
public function setFileName(): string
{
return '角色表';
}
/**
* @notes 角色列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author cjhao
* @date 2021/8/25 18:00
*/
public function lists(): array
{
$lists = SystemRole::with(['role_menu_index'])
->field('id,name,desc,sort,create_time')
->limit($this->limitOffset, $this->limitLength)
->order(['sort' => 'desc', 'id' => 'desc'])
->select()
->toArray();
foreach ($lists as $key => $role) {
//使用角色的人数
$lists[$key]['num'] = AdminRole::where('role_id', $role['id'])->count();
$menuId = array_column($role['role_menu_index'], 'menu_id');
$lists[$key]['menu_id'] = $menuId;
unset($lists[$key]['role_menu_index']);
}
return $lists;
}
/**
* @notes 总记录数
* @return int
* @author Tab
* @date 2021/7/13 11:26
*/
public function count(): int
{
return SystemRole::count();
}
}