FansLists.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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\distribution;
  20. use app\adminapi\lists\BaseAdminDataLists;
  21. use app\common\lists\ListsExcelInterface;
  22. use app\common\lists\ListsExtendInterface;
  23. use app\common\model\DistributionLevel;
  24. use app\common\model\DistributionOrderGoods;
  25. use app\common\model\User;
  26. /**
  27. * 下级列表
  28. * Class FansLists
  29. * @package app\adminapi\lists\distribution
  30. */
  31. class FansLists extends BaseAdminDataLists implements ListsExtendInterface,ListsExcelInterface
  32. {
  33. /**
  34. * @notes 导出字段
  35. * @return array
  36. * @author Tab
  37. * @date 2021/9/22 14:44
  38. */
  39. public function setExcelFields(): array
  40. {
  41. return [
  42. 'user_info' => '用户信息',
  43. 'level_name' => '分销等级',
  44. 'earnings' => '已入账佣金',
  45. 'unreturned_commission' => '待结算佣金',
  46. 'first_leader_info' => '上级分销商',
  47. 'is_freeze_desc' => '分销状态',
  48. 'distribution_time' => '成为分销商时间',
  49. ];
  50. }
  51. /**
  52. * @notes 导出表名
  53. * @return string
  54. * @author Tab
  55. * @date 2021/9/22 14:44
  56. */
  57. public function setFileName(): string
  58. {
  59. return '下级列表';
  60. }
  61. /**
  62. * @notes 设置搜索
  63. * @return array
  64. * @author Tab
  65. * @date 2021/9/14 20:10
  66. */
  67. public function setSearch(): array
  68. {
  69. // 一级粉丝
  70. if (isset($this->params['level']) && $this->params['level'] == 1) {
  71. $this->searchWhere[] = ['u.first_leader', '=', $this->params['user_id']];
  72. }
  73. // 二级粉丝
  74. if (isset($this->params['level']) && $this->params['level'] == 2) {
  75. $this->searchWhere[] = ['u.second_leader', '=', $this->params['user_id']];
  76. }
  77. // 用户信息
  78. if (isset($this->params['user_info']) && !empty($this->params['user_info'])) {
  79. $this->searchWhere[] = ['u.nickname|u.sn', 'like', '%'.$this->params['user_info'].'%'];
  80. }
  81. return $this->searchWhere;
  82. }
  83. /**
  84. * @notes 统计信息
  85. * @return array
  86. * @author Tab
  87. * @date 2021/9/14 20:23
  88. */
  89. public function extend()
  90. {
  91. $one = User::getLevelOneFans($this->params['user_id']);
  92. $two = User::getLevelTwoFans($this->params['user_id']);
  93. return [
  94. 'one' => $one,
  95. 'two' => $two,
  96. ];
  97. }
  98. /**
  99. * @notes 列表
  100. * @return array
  101. * @author Tab
  102. * @date 2021/9/14 20:23
  103. */
  104. public function lists(): array
  105. {
  106. $this->setSearch();
  107. $field = [
  108. 'u.sn',
  109. 'u.avatar',
  110. 'u.nickname',
  111. 'u.first_leader',
  112. 'u.admin_update_leader',
  113. 'd.user_id',
  114. 'd.level_id',
  115. 'd.is_freeze',
  116. 'd.distribution_time',
  117. ];
  118. $lists = User::alias('u')
  119. ->leftJoin('distribution d', 'd.user_id = u.id')
  120. ->field($field)
  121. ->where($this->searchWhere)
  122. ->limit($this->limitOffset, $this->limitLength)
  123. ->select()
  124. ->toArray();
  125. foreach($lists as &$item) {
  126. $item['level_name'] = DistributionLevel::getLevelName($item['level_id']);
  127. $item['earnings'] = DistributionOrderGoods::getEarnings($item['user_id']);
  128. $item['unreturned_commission'] = DistributionOrderGoods::getUnReturnedCommission($item['user_id']);
  129. $item['first_leader_info'] = User::getFirstLeader($item)['name'];
  130. $item['distribution_time'] = empty($item['distribution_time']) ? '' : date('Y-m-d H:i:s', $item['distribution_time']);
  131. $item['user_info'] = $item['nickname'] . '(' . $item['sn'] . ')';
  132. $item['is_freeze_desc'] = $item['is_freeze'] ? '冻结' : '正常';
  133. }
  134. return $lists;
  135. }
  136. /**
  137. * @notes 记录数
  138. * @return int
  139. * @author Tab
  140. * @date 2021/9/14 20:22
  141. */
  142. public function count(): int
  143. {
  144. $this->setSearch();
  145. $count = User::alias('u')
  146. ->leftJoin('distribution d', 'd.user_id = u.id')
  147. ->where($this->searchWhere)
  148. ->count();
  149. return $count;
  150. }
  151. }