UserExtractDao.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\dao\user;
  13. use app\dao\BaseDao;
  14. use app\model\user\UserExtract;
  15. /**
  16. *
  17. * Class UserExtractDao
  18. * @package app\dao\user
  19. */
  20. class UserExtractDao extends BaseDao
  21. {
  22. /**
  23. * 设置模型
  24. * @return string
  25. */
  26. protected function setModel(): string
  27. {
  28. return UserExtract::class;
  29. }
  30. /**
  31. * 获取列表
  32. * @param array $where
  33. * @param string $field
  34. * @param int $page
  35. * @param int $limit
  36. * @param array $typeWhere
  37. * @return array
  38. */
  39. public function getList(array $where, string $field = '*', array $with = [], int $page = 0, int $limit = 0)
  40. {
  41. return $this->search($where)->field($field)->when($with, function ($query) use ($with) {
  42. $query->with($with);
  43. })->when($page && $limit, function ($query) use ($page, $limit) {
  44. $query->page($page, $limit);
  45. })->order('id desc')->select()->toArray();
  46. }
  47. /**
  48. * 获取某个条件的提现总和
  49. * @param array $where
  50. * @return float
  51. */
  52. public function getWhereSum(array $where)
  53. {
  54. return $this->search($where)->field('(extract_price + extract_fee) as extract_price')->sum('extract_price');
  55. }
  56. /**
  57. * 获取某些条件总数组合列表
  58. * @param array $where
  59. * @param string $field
  60. * @param string $key
  61. * @return mixed
  62. */
  63. public function getWhereSumList(array $where, string $field = 'extract_price', string $key = 'uid')
  64. {
  65. return $this->search($where)->group($key)->column('(sum(extract_price) + sum(extract_fee)) as extract_price', $key);
  66. }
  67. /**
  68. * 获取提现列表
  69. * @param array $where
  70. * @param string $field
  71. * @param int $page
  72. * @param int $limit
  73. * @return array
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\DbException
  76. * @throws \think\db\exception\ModelNotFoundException
  77. */
  78. public function getExtractList(array $where, string $field = '*', int $page = 0, int $limit = 0)
  79. {
  80. return $this->search($where)->field($field)->with([
  81. 'user' => function ($query) {
  82. $query->field('uid,nickname');
  83. }])->page($page, $limit)->order('id desc')->select()->toArray();
  84. }
  85. /**
  86. * 获取某个字段总和
  87. * @param array $where
  88. * @param string $field
  89. * @return float
  90. */
  91. public function getWhereSumField(array $where, string $field)
  92. {
  93. return $this->search($where)
  94. ->when(isset($where['timeKey']), function ($query) use ($where) {
  95. $query->whereBetweenTime('add_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
  96. })
  97. ->sum($field);
  98. }
  99. /**
  100. * 根据某字段分组查询
  101. * @param array $where
  102. * @param string $field
  103. * @param string $group
  104. * @return mixed
  105. */
  106. public function getGroupField(array $where, string $field, string $group)
  107. {
  108. return $this->search($where)
  109. ->when(isset($where['timeKey']), function ($query) use ($where, $field, $group) {
  110. $query->whereBetweenTime('add_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
  111. if ($where['timeKey']['days'] == 1) {
  112. $timeUinx = "%H";
  113. } elseif ($where['timeKey']['days'] == 30) {
  114. $timeUinx = "%Y-%m-%d";
  115. } elseif ($where['timeKey']['days'] == 365) {
  116. $timeUinx = "%Y-%m";
  117. } elseif ($where['timeKey']['days'] > 1 && $where['timeKey']['days'] < 30) {
  118. $timeUinx = "%Y-%m-%d";
  119. } elseif ($where['timeKey']['days'] > 30 && $where['timeKey']['days'] < 365) {
  120. $timeUinx = "%Y-%m";
  121. } else {
  122. $timeUinx = "%Y-%m";
  123. }
  124. $query->field("sum($field) as number,FROM_UNIXTIME($group, '$timeUinx') as time");
  125. $query->group("FROM_UNIXTIME($group, '$timeUinx')");
  126. })
  127. ->order('add_time ASC')->select()->toArray();
  128. }
  129. /**
  130. * @param array $where
  131. * @param string $field
  132. * @return float
  133. */
  134. public function getExtractMoneyByWhere(array $where, string $field)
  135. {
  136. return $this->search($where)->sum($field);
  137. }
  138. }