UserInviterLists.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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\ListsSearchInterface;
  23. use app\common\model\User;
  24. use app\common\model\UserLevel;
  25. /**
  26. * 我邀请的人
  27. * Class UserInviterLists
  28. * @package app\adminapi\lists\user
  29. */
  30. class UserInviterLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
  31. {
  32. /**
  33. * @notes 导出表名
  34. * @return string
  35. * @author Tab
  36. * @date 2021/9/22 17:49
  37. */
  38. public function setFileName(): string
  39. {
  40. return '邀请列表';
  41. }
  42. /**
  43. * @notes 导出字段
  44. * @return array
  45. * @author Tab
  46. * @date 2021/9/22 17:50
  47. */
  48. public function setExcelFields(): array
  49. {
  50. return [
  51. 'sn' => '用户编号',
  52. 'nickname' => '用户昵称',
  53. 'level_name' => '用户等级',
  54. 'mobile' => '手机号码',
  55. 'user_money' => '钱包金额',
  56. 'total_order_amount' => '消费金额',
  57. 'login_time' => '最近登录时间',
  58. 'create_time' => '注册时间',
  59. ];
  60. }
  61. /**
  62. * @notes 设置搜索
  63. * @return \string[][]
  64. * @author Tab
  65. * @date 2021/9/22 17:48
  66. */
  67. public function setSearch(): array
  68. {
  69. return [
  70. '%like%' => ['sn', 'nickname']
  71. ];
  72. }
  73. /**
  74. * @notes 附加搜索
  75. * @author Tab
  76. * @date 2021/9/22 18:15
  77. */
  78. public function attachSearch()
  79. {
  80. $this->searchWhere[] = ['inviter_id', '=', $this->params['user_id']];
  81. }
  82. /**
  83. * @notes 列表
  84. * @return array
  85. * @throws \think\db\exception\DataNotFoundException
  86. * @throws \think\db\exception\DbException
  87. * @throws \think\db\exception\ModelNotFoundException
  88. * @author Tab
  89. * @date 2021/9/14 10:08
  90. */
  91. public function lists(): array
  92. {
  93. $this->attachSearch();
  94. $field = [
  95. 'sn',
  96. 'nickname',
  97. 'avatar',
  98. 'level',
  99. 'mobile',
  100. 'user_money',
  101. 'total_order_amount',
  102. 'login_time',
  103. 'create_time',
  104. ];
  105. $lists = User::field($field)
  106. ->where($this->searchWhere)
  107. ->limit($this->limitOffset, $this->limitLength)
  108. ->select()
  109. ->toArray();
  110. foreach($lists as &$item) {
  111. $item['level_name'] = UserLevel::getLevelName($item['level']);
  112. }
  113. return $lists;
  114. }
  115. /**
  116. * @notes 记录数
  117. * @return int
  118. * @author Tab
  119. * @date 2021/9/14 10:07
  120. */
  121. public function count(): int
  122. {
  123. $this->attachSearch();
  124. $field = [
  125. 'sn',
  126. 'nickname',
  127. 'avatar',
  128. 'level',
  129. 'mobile',
  130. 'user_money',
  131. 'total_order_amount',
  132. 'login_time',
  133. 'create_time',
  134. ];
  135. $count = User::field($field)
  136. ->where($this->searchWhere)
  137. ->count();
  138. return $count;
  139. }
  140. }