UserSpreadLogRepository.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\repositories\user;
  12. use app\common\dao\user\UserSpreadLogDao;
  13. use app\common\repositories\BaseRepository;
  14. /**
  15. * @mixin UserSpreadLogDao
  16. */
  17. class UserSpreadLogRepository extends BaseRepository
  18. {
  19. public function __construct(UserSpreadLogDao $dao)
  20. {
  21. $this->dao = $dao;
  22. }
  23. /**
  24. * 根据条件获取列表数据
  25. *
  26. * 本函数用于根据给定的条件数组和分页信息,从数据库中检索并返回列表数据。
  27. * 它首先构造一个查询条件,然后计算符合条件的记录总数,最后根据分页信息和条件获取具体的数据列表。
  28. * 数据列表中还包括了传播者的信息,如uid,nickname和avatar。
  29. *
  30. * @param array $where 查询条件数组
  31. * @param int $page 当前页码
  32. * @param int $limit 每页显示的记录数
  33. * @return array 包含总数和列表数据的数组
  34. */
  35. public function getList(array $where, $page, $limit)
  36. {
  37. // 根据$where条件搜索数据
  38. $query = $this->dao->search($where);
  39. // 计算符合条件的记录总数
  40. $count = $query->count();
  41. // 分页获取数据,并且加载传播者(spread)的相关信息,但只获取指定的字段
  42. $list = $query->page($page, $limit)->with(['spread' => function ($query) {
  43. $query->field('uid,nickname,avatar');
  44. }])->select();
  45. // 返回包含总数和列表数据的数组
  46. return compact('count', 'list');
  47. }
  48. }