RoleLists.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\lists\auth;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\model\auth\AdminRole;
  17. use app\common\model\auth\SystemRole;
  18. /**
  19. * 角色列表
  20. * Class RoleLists
  21. * @package app\adminapi\lists\auth
  22. */
  23. class RoleLists extends BaseAdminDataLists
  24. {
  25. /**
  26. * @notes 导出字段
  27. * @return string[]
  28. * @author Tab
  29. * @date 2021/9/22 18:52
  30. */
  31. public function setExcelFields(): array
  32. {
  33. return [
  34. 'name' => '角色名称',
  35. 'desc' => '备注',
  36. 'create_time' => '创建时间'
  37. ];
  38. }
  39. /**
  40. * @notes 导出表名
  41. * @return string
  42. * @author Tab
  43. * @date 2021/9/22 18:52
  44. */
  45. public function setFileName(): string
  46. {
  47. return '角色表';
  48. }
  49. /**
  50. * @notes 角色列表
  51. * @return array
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\DbException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. * @author cjhao
  56. * @date 2021/8/25 18:00
  57. */
  58. public function lists(): array
  59. {
  60. $lists = SystemRole::with(['role_menu_index'])
  61. ->field('id,name,desc,sort,create_time')
  62. ->limit($this->limitOffset, $this->limitLength)
  63. ->order(['sort' => 'desc', 'id' => 'desc'])
  64. ->select()
  65. ->toArray();
  66. foreach ($lists as $key => $role) {
  67. //使用角色的人数
  68. $lists[$key]['num'] = AdminRole::where('role_id', $role['id'])->count();
  69. $menuId = array_column($role['role_menu_index'], 'menu_id');
  70. $lists[$key]['menu_id'] = $menuId;
  71. unset($lists[$key]['role_menu_index']);
  72. }
  73. return $lists;
  74. }
  75. /**
  76. * @notes 总记录数
  77. * @return int
  78. * @author Tab
  79. * @date 2021/7/13 11:26
  80. */
  81. public function count(): int
  82. {
  83. return SystemRole::count();
  84. }
  85. }