UserLists.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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\user;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\enum\user\UserTerminalEnum;
  17. use app\common\lists\ListsExcelInterface;
  18. use app\common\model\user\User;
  19. /**
  20. * 用户列表
  21. * Class UserLists
  22. * @package app\adminapi\lists\user
  23. */
  24. class UserLists extends BaseAdminDataLists implements ListsExcelInterface
  25. {
  26. /**
  27. * @notes 搜索条件
  28. * @return array
  29. * @author 段誉
  30. * @date 2022/9/22 15:50
  31. */
  32. public function setSearch(): array
  33. {
  34. $allowSearch = ['keyword', 'channel', 'create_time_start', 'create_time_end'];
  35. return array_intersect(array_keys($this->params), $allowSearch);
  36. }
  37. /**
  38. * @notes 获取用户列表
  39. * @return array
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\DbException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. * @author 段誉
  44. * @date 2022/9/22 15:50
  45. */
  46. public function lists(): array
  47. {
  48. $field = "id,sn,nickname,sex,avatar,account,mobile,channel,create_time";
  49. $lists = User::withSearch($this->setSearch(), $this->params)
  50. ->limit($this->limitOffset, $this->limitLength)
  51. ->field($field)
  52. ->order('id desc')
  53. ->select()->toArray();
  54. foreach ($lists as &$item) {
  55. $item['channel'] = UserTerminalEnum::getTermInalDesc($item['channel']);
  56. }
  57. return $lists;
  58. }
  59. /**
  60. * @notes 获取数量
  61. * @return int
  62. * @author 段誉
  63. * @date 2022/9/22 15:51
  64. */
  65. public function count(): int
  66. {
  67. return User::withSearch($this->setSearch(), $this->params)->count();
  68. }
  69. /**
  70. * @notes 导出文件名
  71. * @return string
  72. * @author 段誉
  73. * @date 2022/11/24 16:17
  74. */
  75. public function setFileName(): string
  76. {
  77. return '用户列表';
  78. }
  79. /**
  80. * @notes 导出字段
  81. * @return string[]
  82. * @author 段誉
  83. * @date 2022/11/24 16:17
  84. */
  85. public function setExcelFields(): array
  86. {
  87. return [
  88. 'sn' => '用户编号',
  89. 'nickname' => '用户昵称',
  90. 'account' => '账号',
  91. 'mobile' => '手机号码',
  92. 'channel' => '注册来源',
  93. 'create_time' => '注册时间',
  94. ];
  95. }
  96. }