AdminLists.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\lists\auth;
  20. use app\adminapi\lists\BaseAdminDataLists;
  21. use app\common\lists\ListsExcelInterface;
  22. use app\common\lists\ListsExtendInterface;
  23. use app\common\lists\ListsSearchInterface;
  24. use app\common\lists\ListsSortInterface;
  25. use app\common\model\Admin;
  26. use app\common\model\Role;
  27. class AdminLists extends BaseAdminDataLists implements ListsExtendInterface, ListsSearchInterface, ListsSortInterface, ListsExcelInterface
  28. {
  29. /**
  30. * @notes 设置导出字段
  31. * @return string[]
  32. * @author 令狐冲
  33. * @date 2021/7/21 16:04
  34. */
  35. public function setExcelFields(): array
  36. {
  37. return [
  38. 'account' => '账号',
  39. 'name' => '名称',
  40. 'role_name' => '角色',
  41. 'create_time' => '创建时间',
  42. 'login_time' => '最后登录时间',
  43. 'login_ip' => '最后登录IP',
  44. 'disable_desc' => '状态',
  45. ];
  46. }
  47. /**
  48. * @notes 设置导出文件名
  49. * @return string
  50. * @author 令狐冲
  51. * @date 2021/7/26 17:49
  52. */
  53. public function setFileName(): string
  54. {
  55. return '管理员列表';
  56. }
  57. /**
  58. * @notes 设置搜索条件
  59. * @return \string[][]
  60. * @author 令狐冲
  61. * @date 2021/7/13 00:52
  62. */
  63. public function setSearch(): array
  64. {
  65. return [
  66. '%like%' => ['name', 'account'],
  67. '=' => ['role_id']
  68. ];
  69. }
  70. /**
  71. * @notes 设置支持排序字段
  72. * @return string[]
  73. * @author 令狐冲
  74. * @date 2021/7/15 23:40
  75. */
  76. public function setSortFields(): array
  77. {
  78. // 格式: ['前端传过来的字段名' => '数据库中的字段名'];
  79. return ['create_time' => 'create_time', 'id' => 'id'];
  80. }
  81. /**
  82. * @notes 设置默认排序
  83. * @return string[]
  84. * @author 令狐冲
  85. * @date 2021/7/16 00:04
  86. */
  87. public function setDefaultOrder(): array
  88. {
  89. return ['id' => 'desc'];
  90. }
  91. /**
  92. * @notes 获取管理列表
  93. * @return array
  94. * @throws \think\db\exception\DataNotFoundException
  95. * @throws \think\db\exception\DbException
  96. * @throws \think\db\exception\ModelNotFoundException
  97. * @author 令狐冲
  98. * @date 2021/7/13 00:52
  99. */
  100. public function lists(): array
  101. {
  102. $adminLists = Admin::field(['id', 'name','root', 'account', 'role_id', 'create_time', 'disable', 'login_time', 'login_ip', 'multipoint_login', 'avatar'])
  103. ->where($this->searchWhere)
  104. ->append(['disable_desc'])
  105. ->limit($this->limitOffset, $this->limitLength)
  106. ->order($this->sortOrder)
  107. ->select()
  108. ->toArray();
  109. //获取角色数组('角色id'=>'角色名称')
  110. $roleLists = Role::column('name', 'id');
  111. //管理员列表增加角色名称
  112. foreach ($adminLists as $k => $v) {
  113. $adminLists[$k]['role_name'] = $roleLists[$v['role_id']] ?? '';
  114. if($v['root']){
  115. $adminLists[$k]['role_name'] = '超级管理员';
  116. }
  117. }
  118. return $adminLists;
  119. }
  120. /**
  121. * @notes 获取数量
  122. * @return int
  123. * @author 令狐冲
  124. * @date 2021/7/13 00:52
  125. */
  126. public function count(): int
  127. {
  128. return Admin::where($this->searchWhere)->count();
  129. }
  130. public function extend()
  131. {
  132. return [];
  133. }
  134. }