UserBrokerageFrozenDao.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. * @return \crmeb\basic\BaseModel|mixed|\think\Model
  33. */
  34. public function search(array $where = [])
  35. {
  36. return parent::search($where)->when(isset($where['isFrozen']), function ($query) use ($where) {
  37. if ($where['isFrozen']) {
  38. $query->where('frozen_time', '>', time());
  39. } else {
  40. $query->where('frozen_time', '<=', time());
  41. }
  42. });
  43. }
  44. /**
  45. * 获取某个账户下的冻结佣金
  46. * @param int $uid
  47. * @param bool $isFrozen 获取冻结之前或者冻结之后的总金额
  48. * @return array
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\DbException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. */
  53. public function getUserFrozenPrice(int $uid, bool $isFrozen = true)
  54. {
  55. return $this->search(['uid' => $uid, 'status' => 1, 'isFrozen' => $isFrozen])->column('price', 'id');
  56. }
  57. /**
  58. * 修改佣金冻结状态
  59. * @param string $orderId
  60. * @return \crmeb\basic\BaseModel
  61. */
  62. public function updateFrozen(string $orderId)
  63. {
  64. return $this->search(['order_id' => $orderId, 'isFrozen' => true])->update(['status' => 0]);
  65. }
  66. /**
  67. * 获取用户的冻结佣金数组
  68. * @return mixed
  69. */
  70. public function getFrozenBrokerage()
  71. {
  72. return $this->getModel()->where('frozen_time', '>', time())
  73. ->where('status', 1)
  74. ->group('uid')
  75. ->column('SUM(price) as sum_price', 'uid');
  76. }
  77. /**
  78. * @param $uids
  79. * @return float
  80. */
  81. public function getSumFrozenBrokerage($uids)
  82. {
  83. return $this->getModel()->whereIn('uid', $uids)->where('frozen_time', '>', time())->sum('price');
  84. }
  85. }