AccountLogLists.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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\api\lists;
  15. use app\common\enum\user\AccountLogEnum;
  16. use app\common\model\user\UserAccountLog;
  17. /**
  18. * 账户流水列表
  19. * Class AccountLogLists
  20. * @package app\shopapi\lists
  21. */
  22. class AccountLogLists extends BaseApiDataLists
  23. {
  24. /**
  25. * @notes 搜索条件
  26. * @return array
  27. * @author 段誉
  28. * @date 2023/2/24 14:43
  29. */
  30. public function queryWhere()
  31. {
  32. // 指定用户
  33. $where[] = ['user_id', '=', $this->userId];
  34. // 用户月明细
  35. if (isset($this->params['type']) && $this->params['type'] == 'um') {
  36. $where[] = ['change_type', 'in', AccountLogEnum::getUserMoneyChangeType()];
  37. }
  38. // 变动类型
  39. if (!empty($this->params['action'])) {
  40. $where[] = ['action', '=', $this->params['action']];
  41. }
  42. return $where;
  43. }
  44. /**
  45. * @notes 获取列表
  46. * @return array
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\DbException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. * @author 段誉
  51. * @date 2023/2/24 14:43
  52. */
  53. public function lists(): array
  54. {
  55. $field = 'change_type,change_amount,action,create_time,remark';
  56. $lists = UserAccountLog::field($field)
  57. ->where($this->queryWhere())
  58. ->order('id', 'desc')
  59. ->limit($this->limitOffset, $this->limitLength)
  60. ->select()
  61. ->toArray();
  62. foreach ($lists as &$item) {
  63. $item['type_desc'] = AccountLogEnum::getChangeTypeDesc($item['change_type']);
  64. $symbol = $item['action'] == AccountLogEnum::DEC ? '-' : '+';
  65. $item['change_amount_desc'] = $symbol . $item['change_amount'];
  66. }
  67. return $lists;
  68. }
  69. /**
  70. * @notes 获取数量
  71. * @return int
  72. * @author 段誉
  73. * @date 2023/2/24 14:44
  74. */
  75. public function count(): int
  76. {
  77. return UserAccountLog::where($this->queryWhere())->count();
  78. }
  79. }