DistributionApplyLists.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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\enum\DistributionApplyEnum;
  22. use app\common\lists\ListsExcelInterface;
  23. use app\common\lists\ListsExtendInterface;
  24. use app\common\lists\ListsSearchInterface;
  25. use app\common\model\DistributionApply;
  26. use app\common\model\UserLevel;
  27. use app\common\service\FileService;
  28. use app\common\service\RegionService;
  29. /**
  30. * 分销商申请列表
  31. * Class DistributionApplyLists
  32. * @package app\adminapi\lists\distribution
  33. */
  34. class DistributionApplyLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExtendInterface,ListsExcelInterface
  35. {
  36. /**
  37. * @notes 设置搜索条件
  38. * @return array
  39. * @author Tab
  40. * @date 2021/7/27 15:02
  41. */
  42. public function setSearch(): array
  43. {
  44. return [
  45. '=' => ['da.status'],
  46. 'between_time' => 'da.create_time'
  47. ];
  48. }
  49. /**
  50. * @notes 附加搜索
  51. * @author Tab
  52. * @date 2021/9/22 15:00
  53. */
  54. public function attachSearch()
  55. {
  56. // 用户信息
  57. if (isset($this->params['user_info']) && !empty($this->params['user_info'])) {
  58. $this->searchWhere[] = ['u.sn|u.nickname', 'like', '%' . $this->params['user_info'] . '%'];
  59. }
  60. }
  61. /**
  62. * @notes 统计数据
  63. * @return array
  64. * @author Tab
  65. * @date 2021/8/4 16:37
  66. */
  67. public function extend(): array
  68. {
  69. $all = DistributionApply::count();
  70. $wait = DistributionApply::where('status', DistributionApplyEnum::AUDIT_WAIT)->count();
  71. $pass = DistributionApply::where('status', DistributionApplyEnum::AUDIT_PASS)->count();
  72. $refuse = DistributionApply::where('status', DistributionApplyEnum::AUDIT_REFUSE)->count();
  73. return [
  74. 'all' => $all,
  75. 'wait' => $wait,
  76. 'pass' => $pass,
  77. 'refuse' => $refuse,
  78. ];
  79. }
  80. /**
  81. * @notes 设置默认导出表名
  82. * @return string
  83. * @author Tab
  84. * @date 2021/8/4 16:40
  85. */
  86. public function setFileName(): string
  87. {
  88. return '分销商申请表';
  89. }
  90. /**
  91. * @notes 设置导出字段名
  92. * @return string[]
  93. * @author Tab
  94. * @date 2021/8/4 16:47
  95. */
  96. public function setExcelFields(): array
  97. {
  98. return [
  99. 'user_info' => '用户信息',
  100. 'real_name' => '真实姓名',
  101. 'mobile' => '联系手机',
  102. 'address' => '所属区域',
  103. 'reason' => '申请原因',
  104. 'status_desc' => '申请状态',
  105. 'audit_remark' => '审核说明',
  106. 'create_time' => '申请时间',
  107. ];
  108. }
  109. /**
  110. * @notes 列表
  111. * @return array
  112. * @author Tab
  113. * @date 2021/7/27 15:18
  114. */
  115. public function lists(): array
  116. {
  117. $this->attachSearch();
  118. $field = 'da.id, da.real_name, da.mobile, da.province, da.city, da.district, da.reason, da.status, da.status as status_desc, da.audit_remark, da.create_time';
  119. $field .= ',u.id as user_id,u.avatar,u.sn,u.nickname, u.level';
  120. $this->sortOrder = ['id' => 'desc'];
  121. $lists = DistributionApply::alias('da')
  122. ->leftJoin('user u', 'u.id = da.user_id')
  123. ->field($field)
  124. ->where($this->searchWhere)
  125. ->order($this->sortOrder)
  126. ->limit($this->limitOffset, $this->limitLength)
  127. ->select()
  128. ->toArray();
  129. $userLevelLists = UserLevel::column('name', 'id');
  130. foreach ($lists as &$item) {
  131. $item['address'] = RegionService::getAddress([$item['province'], $item['city'], $item['district']]);
  132. $item['level_name'] = $userLevelLists[$item['level']] ?? '无等级';
  133. $item['avatar'] = trim($item['avatar']) ? FileService::getFileUrl($item['avatar']) : '';
  134. $item['user_info'] = $item['nickname'] . '(' . $item['sn'] . ')';
  135. }
  136. return $lists;
  137. }
  138. /**
  139. * @notes 记录数
  140. * @return int
  141. * @author Tab
  142. * @date 2021/7/27 15:19
  143. */
  144. public function count(): int
  145. {
  146. $this->attachSearch();
  147. $count = DistributionApply::alias('da')
  148. ->leftJoin('user u', 'u.id = da.user_id')
  149. ->where($this->searchWhere)
  150. ->count();
  151. return $count;
  152. }
  153. }