UserBrokerageDao.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\dao\user;
  12. use app\dao\BaseDao;
  13. use app\model\user\UserBrokerage;
  14. class UserBrokerageDao extends BaseDao
  15. {
  16. /**
  17. * 设置模型
  18. * @return string
  19. */
  20. protected function setModel(): string
  21. {
  22. return UserBrokerage::class;
  23. }
  24. /**
  25. * 获取列表
  26. * @param array $where
  27. * @param string $field
  28. * @param int $page
  29. * @param int $limit
  30. * @param array $typeWhere
  31. * @return array
  32. */
  33. public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $typeWhere = [])
  34. {
  35. return $this->search($where)->when(count($typeWhere) > 0, function ($query) use ($typeWhere) {
  36. $query->where($typeWhere);
  37. })->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
  38. $query->page($page, $limit);
  39. })->order('id desc')->select()->toArray();
  40. }
  41. /**
  42. * 查询列表
  43. * @param array $where
  44. * @return array
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\DbException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. */
  49. public function getUserBrokerageList(array $where)
  50. {
  51. return $this->search($where)->select()->toArray();
  52. }
  53. /**
  54. * 获取佣金排行
  55. * @param array $where
  56. * @param int $page
  57. * @param int $limit
  58. * @return array
  59. * @throws \think\db\exception\DataNotFoundException
  60. * @throws \think\db\exception\DbException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. */
  63. public function brokerageRankList(array $where, int $page = 0, int $limit = 0)
  64. {
  65. return $this->search($where)->field('uid,SUM(IF(pm=1,`number`,-`number`)) as brokerage_price')->with(['user' => function ($query) {
  66. $query->field('uid,avatar,nickname');
  67. }])->order('brokerage_price desc')->group('uid')->when($page && $limit, function ($query) use ($page, $limit) {
  68. $query->page($page, $limit);
  69. })->select()->toArray();
  70. }
  71. /**
  72. * 获取某些条件的佣金总数
  73. * @param array $where
  74. * @return mixed
  75. */
  76. public function getBrokerageSumColumn(array $where)
  77. {
  78. if (isset($where['uid']) && is_array($where['uid'])) {
  79. return $this->search($where)->group('uid')->column('sum(number) as num', 'uid');
  80. } else
  81. return $this->search($where)->sum('number');
  82. }
  83. /**
  84. * 获取某个账户下的冻结佣金
  85. * @param int $uid
  86. * @return float
  87. */
  88. public function getUserFrozenPrice(int $uid)
  89. {
  90. return $this->search(['uid' => $uid, 'status' => 1, 'pm' => 1])->where('frozen_time', '>', time())->sum('number');
  91. }
  92. }