AccountLogLists.php 5.9 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;
  20. use app\common\enum\AccountLogEnum;
  21. use app\common\lists\ListsExcelInterface;
  22. use app\common\lists\ListsSearchInterface;
  23. use app\common\model\AccountLog;
  24. /**
  25. * 账记流水列表
  26. * Class AccountLogLists
  27. * @package app\adminapi\lists
  28. */
  29. class AccountLogLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
  30. {
  31. /**
  32. * @notes 导出表名
  33. * @return string
  34. * @author Tab
  35. * @date 2021/9/22 18:40
  36. */
  37. public function setFileName(): string
  38. {
  39. if (isset($this->params['file_name'])) {
  40. return $this->params['file_name'];
  41. }
  42. // 可提现余额类型
  43. if(isset($this->params['type']) && $this->params['type'] == 'bw') {
  44. return '佣金明细';
  45. }
  46. // 不可提现余额类型
  47. if(isset($this->params['type']) && $this->params['type'] == 'bnw') {
  48. return '余额明细';
  49. }
  50. // 积分类型
  51. if(isset($this->params['type']) && $this->params['type'] == 'integral') {
  52. return '积分明细';
  53. }
  54. return '未知类型';
  55. }
  56. /**
  57. * @notes 导出字段
  58. * @return array
  59. * @author Tab
  60. * @date 2021/9/22 18:40
  61. */
  62. public function setExcelFields(): array
  63. {
  64. return [
  65. 'nickname' => '用户昵称',
  66. 'sn' => '用户编号',
  67. 'mobile' => '手机号码',
  68. 'change_amount' => '变动金额',
  69. 'left_amount' => '剩余金额',
  70. 'change_type_desc' => '变动类型',
  71. 'association_sn' => '来源单号',
  72. 'create_time' => '记录时间',
  73. ];
  74. }
  75. /**
  76. * @notes 设置搜索
  77. * @return array
  78. * @author Tab
  79. * @date 2021/8/12 15:32
  80. */
  81. public function setSearch(): array
  82. {
  83. return [
  84. '=' => ['u.sn', 'u.mobile', 'al.change_type'],
  85. '%like%' => ['u.nickname'],
  86. 'between_time' => 'al.create_time'
  87. ];
  88. }
  89. /**
  90. * @notes 自定义搜索
  91. * @author Tab
  92. * @date 2021/8/25 20:39
  93. */
  94. public function queryWhere()
  95. {
  96. // 可提现余额类型
  97. if(isset($this->params['type']) && $this->params['type'] == 'bw') {
  98. $this->searchWhere[] = ['change_type', 'in', AccountLogEnum::getBwChangeType()];
  99. }
  100. // 不可提现余额类型
  101. if(isset($this->params['type']) && $this->params['type'] == 'bnw') {
  102. $this->searchWhere[] = ['change_type', 'in', AccountLogEnum::getBnwChangeType()];
  103. }
  104. // 积分类型
  105. if(isset($this->params['type']) && $this->params['type'] == 'integral') {
  106. $this->searchWhere[] = ['change_type', 'in', AccountLogEnum::getIntegralChangeType()];
  107. }
  108. }
  109. /**
  110. * @notes 账户流水列表
  111. * @return array
  112. * @author Tab
  113. * @date 2021/8/12 15:32
  114. */
  115. public function lists(): array
  116. {
  117. $this->queryWhere();
  118. $field = 'u.nickname,u.sn,u.mobile,al.action,al.change_amount,al.left_amount,al.change_type,al.association_sn,al.create_time';
  119. $lists = AccountLog::alias('al')
  120. ->leftJoin('user u', 'u.id = al.user_id')
  121. ->field($field)
  122. ->where($this->searchWhere)
  123. ->order('al.id', 'desc')
  124. ->limit($this->limitOffset, $this->limitLength)
  125. ->select()
  126. ->toArray();
  127. foreach($lists as &$item) {
  128. $item['change_type_desc'] = AccountLogEnum::getChangeTypeDesc( $item['change_type']);
  129. $symbol = $item['action'] == AccountLogEnum::INC ? '+' : '-';
  130. // 积分、成长值转整型
  131. //$item['change_amount'] = in_array($item['change_type'], AccountLogEnum::getIntegralChangeType()) || in_array($item['change_type'], AccountLogEnum::getGrowthChangeType()) ? (int)$item['change_amount'] : $item['change_amount'];
  132. //$item['left_amount'] = in_array($item['change_type'], AccountLogEnum::getIntegralChangeType()) || in_array($item['change_type'], AccountLogEnum::getGrowthChangeType()) ? (int)$item['left_amount'] : $item['left_amount'];
  133. $item['change_amount'] = in_array($item['change_type'], AccountLogEnum::getGrowthChangeType()) ? (int)$item['change_amount'] : $item['change_amount'];
  134. $item['left_amount'] = in_array($item['change_type'], AccountLogEnum::getGrowthChangeType()) ? (int)$item['left_amount'] : $item['left_amount'];
  135. $item['change_amount'] = $symbol . $item['change_amount'];
  136. }
  137. return $lists;
  138. }
  139. /**
  140. * @notes 账户流水数量
  141. * @return int
  142. * @author Tab
  143. * @date 2021/8/12 15:33
  144. */
  145. public function count(): int
  146. {
  147. $this->queryWhere();
  148. $count = AccountLog::alias('al')
  149. ->leftJoin('user u', 'u.id = al.user_id')
  150. ->where($this->searchWhere)
  151. ->count();
  152. return $count;
  153. }
  154. }