AccountLogLists.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. /**
  60. * @notes 账户流水列表
  61. * @return array
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\DbException
  64. * @throws \think\db\exception\ModelNotFoundException
  65. * @author Tab
  66. * @date 2021/8/9 17:37
  67. */
  68. public function lists(): array
  69. {
  70. // 设置搜索条件
  71. $this->setWhere();
  72. $field = 'change_type,change_amount,action,create_time,remark';
  73. $lists = AccountLog::field($field)
  74. ->where($this->searchWhere)
  75. ->order('id', 'desc')
  76. ->limit($this->limitOffset, $this->limitLength)
  77. ->order('id', 'desc')
  78. ->select()
  79. ->toArray();
  80. foreach($lists as &$item) {
  81. $item['type_desc'] = AccountLogEnum::getChangeTypeDesc($item['change_type']);
  82. $item['change_amount_desc'] = $item['action'] == AccountLogEnum::DEC ? '-' . $item['change_amount'] : '+' . $item['change_amount'];
  83. }
  84. return $lists;
  85. }
  86. /**
  87. * @notes 账户流水记录数
  88. * @return int
  89. * @author Tab
  90. * @date 2021/8/9 17:36
  91. */
  92. public function count(): int
  93. {
  94. // 设置搜索条件
  95. $this->setWhere();
  96. $count = AccountLog::where($this->searchWhere)->count();
  97. return $count;
  98. }
  99. }