UserExtractDao.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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. * @return float
  34. */
  35. public function getWhereSum(array $where)
  36. {
  37. return $this->search($where)->sum('extract_price');
  38. }
  39. /**
  40. * 获取某些条件总数组合列表
  41. * @param array $where
  42. * @param string $field
  43. * @param string $key
  44. * @return mixed
  45. */
  46. public function getWhereSumList(array $where, string $field = 'extract_price', string $key = 'uid')
  47. {
  48. return $this->search($where)->group($key)->column('sum(' . $field . ')', $key);
  49. }
  50. /**
  51. * 获取提现列表
  52. * @param array $where
  53. * @param string $field
  54. * @param int $page
  55. * @param int $limit
  56. * @return array
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\DbException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. */
  61. public function getExtractList(array $where, string $field = '*', int $page, int $limit)
  62. {
  63. return $this->search($where)->field($field)->with([
  64. 'user' => function ($query) {
  65. $query->field('uid,nickname');
  66. }])->page($page, $limit)->order('id desc')->select()->toArray();
  67. }
  68. /**
  69. * 获取某个字段总和
  70. * @param array $where
  71. * @param string $field
  72. * @return float
  73. */
  74. public function getWhereSumField(array $where, string $field)
  75. {
  76. return $this->search($where, false)
  77. ->when(isset($where['timeKey']), function ($query) use ($where) {
  78. $query->whereBetweenTime('add_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
  79. })
  80. ->sum($field);
  81. }
  82. /**根据某字段分组查询
  83. * @param array $where
  84. * @param string $field
  85. * @param string $group
  86. * @return mixed
  87. */
  88. public function getGroupField(array $where, string $field, string $group)
  89. {
  90. return $this->search($where, false)
  91. ->when(isset($where['timeKey']), function ($query) use ($where, $field, $group) {
  92. $query->whereBetweenTime('add_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
  93. $timeUinx = "%H";
  94. if ($where['timeKey']['days'] == 1) {
  95. $timeUinx = "%H";
  96. } elseif ($where['timeKey']['days'] == 30) {
  97. $timeUinx = "%Y-%m-%d";
  98. } elseif ($where['timeKey']['days'] == 365) {
  99. $timeUinx = "%Y-%m";
  100. } elseif ($where['timeKey']['days'] > 1 && $where['timeKey']['days'] < 30) {
  101. $timeUinx = "%Y-%m-%d";
  102. } elseif ($where['timeKey']['days'] > 30 && $where['timeKey']['days'] < 365) {
  103. $timeUinx = "%Y-%m";
  104. }
  105. $query->field("sum($field) as number,FROM_UNIXTIME($group, '$timeUinx') as time");
  106. $query->group("FROM_UNIXTIME($group, '$timeUinx')");
  107. })
  108. ->order('add_time ASC')->select()->toArray();
  109. }
  110. /**
  111. * @param array $where
  112. * @param string $field
  113. * @return float
  114. */
  115. public function getExtractMoneyByWhere(array $where, string $field)
  116. {
  117. return $this->search($where)->sum($field);
  118. }
  119. }