UserBrokerageFrozenDao.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. namespace app\dao\user;
  12. use app\dao\BaseDao;
  13. use app\model\user\UserBrokerageFrozen;
  14. /**
  15. * 佣金冻结
  16. * Class UserBrokerageFrozenDao
  17. * @package app\dao\user
  18. */
  19. class UserBrokerageFrozenDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return UserBrokerageFrozen::class;
  28. }
  29. /**
  30. * 搜索
  31. * @param array $where
  32. * @param bool $search
  33. * @return \crmeb\basic\BaseModel|mixed|\think\Model
  34. * @throws \ReflectionException
  35. */
  36. public function search(array $where = [], bool $search = false)
  37. {
  38. return parent::search($where, $search)->when(isset($where['isFrozen']), function ($query) use ($where) {
  39. if ($where['isFrozen']) {
  40. $query->where('frozen_time', '>', time());
  41. } else {
  42. $query->where('frozen_time', '<=', time());
  43. }
  44. });
  45. }
  46. /**
  47. * 获取某个账户下的冻结佣金
  48. * @param int $uid
  49. * @param bool $isFrozen 获取冻结之前或者冻结之后的总金额
  50. * @return array
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\DbException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. */
  55. public function getUserFrozenPrice(int $uid, bool $isFrozen = true)
  56. {
  57. return $this->search(['uid' => $uid, 'status' => 1, 'isFrozen' => $isFrozen])->column('price', 'id');
  58. }
  59. /**
  60. * 修改佣金冻结状态
  61. * @param string $orderId
  62. * @return \crmeb\basic\BaseModel
  63. */
  64. public function updateFrozen(string $orderId)
  65. {
  66. return $this->search(['order_id' => $orderId, 'isFrozen' => true])->update(['status' => 0]);
  67. }
  68. /**
  69. * 获取用户的冻结佣金数组
  70. * @return mixed
  71. */
  72. public function getFrozenBrokerage()
  73. {
  74. return $this->getModel()->where('frozen_time', '>', time())
  75. ->where('status', 1)
  76. ->group('uid')
  77. ->column('SUM(price) as sum_price', 'uid');
  78. }
  79. /**
  80. * @param $uids
  81. * @return float
  82. */
  83. public function getSumFrozenBrokerage($uids)
  84. {
  85. return $this->getModel()->whereIn('uid', $uids)->where('frozen_time', '>', time())->sum('price');
  86. }
  87. }