AccountLogLists.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\lists\finance;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\enum\user\AccountLogEnum;
  17. use app\common\lists\ListsSearchInterface;
  18. use app\common\model\user\UserAccountLog;
  19. use app\common\service\FileService;
  20. /**
  21. * 账记流水列表
  22. * Class AccountLogLists
  23. * @package app\adminapi\lists\finance
  24. */
  25. class AccountLogLists extends BaseAdminDataLists implements ListsSearchInterface
  26. {
  27. /**
  28. * @notes 搜索条件
  29. * @return array
  30. * @author 段誉
  31. * @date 2023/2/24 15:26
  32. */
  33. public function setSearch(): array
  34. {
  35. return [
  36. '=' => ['al.change_type'],
  37. ];
  38. }
  39. /**
  40. * @notes 搜索条件
  41. * @author 段誉
  42. * @date 2023/2/24 15:26
  43. */
  44. public function queryWhere()
  45. {
  46. $where = [];
  47. // 用户余额
  48. if (isset($this->params['type']) && $this->params['type'] == 'um') {
  49. $where[] = ['change_type', 'in', AccountLogEnum::getUserMoneyChangeType()];
  50. }
  51. if (!empty($this->params['user_info'])) {
  52. $where[] = ['u.sn|u.nickname|u.mobile|u.account', 'like', '%' . $this->params['user_info'] . '%'];
  53. }
  54. if (!empty($this->params['start_time'])) {
  55. $where[] = ['al.create_time', '>=', strtotime($this->params['start_time'])];
  56. }
  57. if (!empty($this->params['end_time'])) {
  58. $where[] = ['al.create_time', '<=', strtotime($this->params['end_time'])];
  59. }
  60. return $where;
  61. }
  62. /**
  63. * @notes 获取列表
  64. * @return array
  65. * @author 段誉
  66. * @date 2023/2/24 15:31
  67. */
  68. public function lists(): array
  69. {
  70. $field = 'u.nickname,u.account,u.sn,u.avatar,u.mobile,al.action,al.change_amount,al.left_amount,al.change_type,al.source_sn,al.create_time';
  71. $lists = UserAccountLog::alias('al')
  72. ->join('user u', 'u.id = al.user_id')
  73. ->field($field)
  74. ->where($this->searchWhere)
  75. ->where($this->queryWhere())
  76. ->order('al.id', 'desc')
  77. ->limit($this->limitOffset, $this->limitLength)
  78. ->select()
  79. ->toArray();
  80. foreach ($lists as &$item) {
  81. $item['avatar'] = FileService::getFileUrl($item['avatar']);
  82. $item['change_type_desc'] = AccountLogEnum::getChangeTypeDesc($item['change_type']);
  83. $symbol = $item['action'] == AccountLogEnum::INC ? '+' : '-';
  84. $item['change_amount'] = $symbol . $item['change_amount'];
  85. }
  86. return $lists;
  87. }
  88. /**
  89. * @notes 获取数量
  90. * @return int
  91. * @author 段誉
  92. * @date 2023/2/24 15:36
  93. */
  94. public function count(): int
  95. {
  96. return UserAccountLog::alias('al')
  97. ->join('user u', 'u.id = al.user_id')
  98. ->where($this->queryWhere())
  99. ->where($this->searchWhere)
  100. ->count();
  101. }
  102. }