UserUserBillDao.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\User;
  15. use app\model\user\UserBill;
  16. /**
  17. *
  18. * Class UserUserBillDao
  19. * @package app\dao\user
  20. */
  21. class UserUserBillDao extends BaseDao
  22. {
  23. /**
  24. * 设置模型
  25. * @return string
  26. */
  27. protected function setModel(): string
  28. {
  29. return User::class;
  30. }
  31. public function joinModel(): string
  32. {
  33. return UserBill::class;
  34. }
  35. /**
  36. * 关联模型
  37. * @param string $alias
  38. * @param string $join_alias
  39. * @return \crmeb\basic\BaseModel
  40. */
  41. public function getModel(string $alias = 'u', string $join_alias = 'b', $join = 'left')
  42. {
  43. $this->alias = $alias;
  44. $this->join_alis = $join_alias;
  45. /** @var $userBiil $userBiil */
  46. $userBiil = app()->make($this->joinModel());
  47. $table = $userBiil->getName();
  48. return parent::getModel()->join($table . ' ' . $join_alias, $alias . '.uid = ' . $join_alias . '.uid', $join)->alias($alias);
  49. }
  50. /**
  51. * 组合条件模型查询列表
  52. * @param Model $model
  53. * @return array
  54. */
  55. public function getList(array $where, string $field = '', string $order = '', int $page = 0, int $limit = 0)
  56. {
  57. return $this->getModel()->where($where)->field($field)->group('u.uid')->order($order)->order('id desc')
  58. ->when($page && $limit, function ($query) use ($page, $limit) {
  59. $query->page($page, $limit);
  60. })->select()->toArray();
  61. }
  62. /**
  63. * 获取条数
  64. * @param array $where
  65. * @return mixed
  66. */
  67. public function getCount(array $where)
  68. {
  69. return $this->getModel()->where($where)->group('u.uid')->count();
  70. }
  71. }