AccountLogLists.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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\shopapi\lists;
  20. use app\common\enum\AccountLogEnum;
  21. use app\common\model\AccountLog;
  22. /**
  23. * 账户流水列表
  24. * Class AccountLogLists
  25. * @package app\shopapi\lists
  26. */
  27. class AccountLogLists extends BaseShopDataLists
  28. {
  29. /**
  30. * @notes 设置搜索条件
  31. * @author Tab
  32. * @date 2021/8/9 17:31
  33. */
  34. public function setWhere()
  35. {
  36. // 指定用户
  37. $this->searchWhere[] = ['user_id', '=', $this->userId];
  38. // 可提现金额类型
  39. if(isset($this->params['type']) && $this->params['type'] == 'bw') {
  40. $this->searchWhere[] = ['change_type', 'in', AccountLogEnum::getBwChangeType()];
  41. }
  42. // 不可提现金额类型-支出
  43. if(isset($this->params['type']) && $this->params['type'] == 'bnw_dec') {
  44. $this->searchWhere[] = ['change_type', 'in', AccountLogEnum::BNW_DEC];
  45. }
  46. // 不可提现金额类型-收入
  47. if(isset($this->params['type']) && $this->params['type'] == 'bnw_inc') {
  48. $this->searchWhere[] = ['change_type', 'in', AccountLogEnum::BNW_INC];
  49. }
  50. // 不可提现金额类型-支出 + 收入
  51. if(isset($this->params['type']) && $this->params['type'] == 'bnw') {
  52. $this->searchWhere[] = ['change_type', 'in', AccountLogEnum::getBnwChangeType()];
  53. }
  54. // 积分
  55. if(isset($this->params['type']) && $this->params['type'] == 'integral') {
  56. $this->searchWhere[] = ['change_type', 'in', AccountLogEnum::getIntegralChangeType()];
  57. }
  58. // 按日期查询
  59. if(isset($this->params['search_date']) && $this->params['search_date'] <> '') {
  60. $start_date = strtotime($this->params['search_date'].'-01 00:00:00');
  61. $end_date = strtotime(date('Y-m-t 23:59:59', $start_date)); // 获取当月最后一天
  62. $this->searchWhere[] = ['create_time', 'between', [$start_date,$end_date]];
  63. }
  64. }
  65. /**
  66. * @notes 账户流水列表
  67. * @return array
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\DbException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. * @author Tab
  72. * @date 2021/8/9 17:37
  73. */
  74. public function lists(): array
  75. {
  76. // 设置搜索条件
  77. $this->setWhere();
  78. $field = 'change_type,change_amount,left_amount,action,create_time,remark';
  79. $lists = AccountLog::field($field)
  80. ->where($this->searchWhere)
  81. ->order('id', 'desc')
  82. ->limit($this->limitOffset, $this->limitLength)
  83. ->order('id', 'desc')
  84. ->select()
  85. ->toArray();
  86. foreach($lists as &$item) {
  87. $item['type_desc'] = AccountLogEnum::getChangeTypeDesc($item['change_type']);
  88. $item['change_amount_desc'] = $item['action'] == AccountLogEnum::DEC ? '-' . $item['change_amount'] : '+' . $item['change_amount'];
  89. }
  90. return $lists;
  91. }
  92. /**
  93. * @notes 账户流水记录数
  94. * @return int
  95. * @author Tab
  96. * @date 2021/8/9 17:36
  97. */
  98. public function count(): int
  99. {
  100. // 设置搜索条件
  101. $this->setWhere();
  102. $count = AccountLog::where($this->searchWhere)->count();
  103. return $count;
  104. }
  105. }