UserExtractDao.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. public function getExtractAll(array $where, string $field = '*')
  86. {
  87. return $this->search($where)->field($field)->with([
  88. 'user' => function ($query) {
  89. $query->field('uid,nickname');
  90. }])->order('id desc')->select()->toArray();
  91. }
  92. /**
  93. * 获取某个字段总和
  94. * @param array $where
  95. * @param string $field
  96. * @return float
  97. */
  98. public function getWhereSumField(array $where, string $field)
  99. {
  100. return $this->search($where)
  101. ->when(isset($where['timeKey']), function ($query) use ($where) {
  102. $query->whereBetweenTime('add_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
  103. })
  104. ->sum($field);
  105. }
  106. /**
  107. * 根据某字段分组查询
  108. * @param array $where
  109. * @param string $field
  110. * @param string $group
  111. * @return mixed
  112. */
  113. public function getGroupField(array $where, string $field, string $group)
  114. {
  115. return $this->search($where)
  116. ->when(isset($where['timeKey']), function ($query) use ($where, $field, $group) {
  117. $query->whereBetweenTime('add_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
  118. if ($where['timeKey']['days'] == 1) {
  119. $timeUinx = "%H";
  120. } elseif ($where['timeKey']['days'] == 30) {
  121. $timeUinx = "%Y-%m-%d";
  122. } elseif ($where['timeKey']['days'] == 365) {
  123. $timeUinx = "%Y-%m";
  124. } elseif ($where['timeKey']['days'] > 1 && $where['timeKey']['days'] < 30) {
  125. $timeUinx = "%Y-%m-%d";
  126. } elseif ($where['timeKey']['days'] > 30 && $where['timeKey']['days'] < 365) {
  127. $timeUinx = "%Y-%m";
  128. } else {
  129. $timeUinx = "%Y-%m";
  130. }
  131. $query->field("sum($field) as number,FROM_UNIXTIME($group, '$timeUinx') as time");
  132. $query->group("FROM_UNIXTIME($group, '$timeUinx')");
  133. })
  134. ->order('add_time ASC')->select()->toArray();
  135. }
  136. /**
  137. * @param array $where
  138. * @param string $field
  139. * @return float
  140. */
  141. public function getExtractMoneyByWhere(array $where, string $field)
  142. {
  143. return $this->search($where)->sum($field);
  144. }
  145. }