UserLists.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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\user;
  20. use app\adminapi\lists\BaseAdminDataLists;
  21. use app\common\lists\ListsExcelInterface;
  22. use app\common\lists\ListsExtendInterface;
  23. use app\common\model\User;
  24. /**
  25. * 用户列表
  26. * Class UserLists
  27. * @package app\adminapi\lists\user
  28. */
  29. class UserLists extends BaseAdminDataLists implements ListsExcelInterface
  30. {
  31. /**
  32. * @notes 搜索参数
  33. * @return array
  34. * @author cjhao
  35. * @date 2021/8/12 10:23
  36. */
  37. public function setSearch(): array
  38. {
  39. return array_intersect(array_keys($this->params),['disable','keyword','level','label_id','min_amount','max_amount','source','create_start_time','create_end_time']);
  40. }
  41. /**
  42. * @notes 搜索列表
  43. * @return array
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\DbException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. * @author cjhao
  48. * @date 2021/8/12 9:46
  49. */
  50. public function lists(): array
  51. {
  52. $lists = User::withSearch($this->setSearch(), $this->params)
  53. ->with(['user_level'])
  54. ->limit($this->limitOffset, $this->limitLength)
  55. ->field('id,sn,nickname,avatar,mobile,level,user_money+user_earnings as total_user_money,user_integral,total_order_amount,login_time,create_time,disable,user_delete')
  56. ->order('id desc')
  57. ->withAttr('user_money',function ($value){
  58. return '¥'.$value;
  59. })
  60. ->withAttr('total_order_amount',function ($value){
  61. return '¥'.$value;
  62. })
  63. ->select()
  64. ->toArray();
  65. return $lists;
  66. }
  67. /**
  68. * @notes 统计数据
  69. * @return int
  70. * @author cjhao
  71. * @date 2021/8/12 10:23
  72. */
  73. public function count(): int
  74. {
  75. return User::withSearch($this->setSearch(), $this->params)->count();
  76. }
  77. /**
  78. * @notes 设置excel表名
  79. * @return string
  80. * @author cjhao
  81. * @date 2021/9/23 16:58
  82. */
  83. public function setFileName(): string
  84. {
  85. return '用户列表';
  86. }
  87. /**
  88. * @notes 设置导出字段
  89. * @return array
  90. * @author cjhao
  91. * @date 2021/9/23 17:03
  92. */
  93. public function setExcelFields(): array
  94. {
  95. return [
  96. 'sn' => '用户编号',
  97. 'nickname' => '用户昵称',
  98. 'name' => '用户等级',
  99. 'mobile' => '手机号码',
  100. 'total_user_money' => '钱包余额',
  101. 'total_order_amount' => '消费金额',
  102. 'login_time' => '最后登录时间',
  103. 'create_time' => '注册时间',
  104. ];
  105. }
  106. }