StoreServiceReplyRepository.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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\store\service;
  12. use app\common\dao\store\service\StoreServiceReplyDao;
  13. use app\common\repositories\BaseRepository;
  14. /**
  15. * Class StoreServiceRepository
  16. * @package app\common\repositories\store\service
  17. * @author xaboy
  18. * @day 2020/5/29
  19. * @mixin StoreServiceReplyDao
  20. */
  21. class StoreServiceReplyRepository extends BaseRepository
  22. {
  23. /**
  24. * StoreServiceRepository constructor.
  25. * @param StoreServiceReplyDao $dao
  26. */
  27. public function __construct(StoreServiceReplyDao $dao)
  28. {
  29. $this->dao = $dao;
  30. }
  31. /**
  32. * 获取列表数据
  33. *
  34. * 根据给定的条件($where)、分页($page)和每页数据量($limit)来获取列表数据。
  35. * 此方法首先根据条件进行查询,然后计算总记录数,最后根据分页和数据量限制获取具体的数据列表。
  36. *
  37. * @param string|array $where 查询条件,可以是字符串或数组形式的条件。
  38. * @param int $page 当前页码,用于分页查询。
  39. * @param int $limit 每页的数据量,用于分页查询。
  40. * @return array 返回包含 'count' 和 'list' 两个元素的数组,'count' 表示总记录数,'list' 表示当前页的数据列表。
  41. */
  42. public function getList($where, $page, $limit)
  43. {
  44. // 根据条件进行查询
  45. $query = $this->search($where);
  46. // 计算总记录数
  47. $count = $query->count();
  48. // 根据当前页码和每页数据量进行分页查询,并获取数据列表
  49. $list = $query->page($page, $limit)->select();
  50. // 返回包含总记录数和数据列表的数组
  51. return compact('count', 'list');
  52. }
  53. /**
  54. * 创建新记录
  55. *
  56. * 本函数用于根据传入的数据创建新的记录。在创建之前,如果关键字数据是数组,
  57. * 则会将它们合并为一个以逗号分隔的字符串,这是为了满足数据库字段的格式要求。
  58. * 最后,通过调用DAO层的create方法来实际执行创建操作。
  59. *
  60. * @param array $data 包含新记录数据的数组。数组中可能包含一个名为'keyword'的字段,
  61. * 如果该字段是数组,则需要转换为字符串。
  62. * @return mixed 返回DAO层创建操作的结果。具体类型取决于DAO层的实现。
  63. */
  64. public function create($data)
  65. {
  66. // 检查$data中'keyword'字段是否为数组,如果是,则转换为逗号分隔的字符串
  67. if (is_array($data['keyword'])) {
  68. $data['keyword'] = implode(',', $data['keyword']);
  69. }
  70. // 调用DAO层的create方法,传入处理后的$data,创建新记录
  71. return $this->dao->create($data);
  72. }
  73. }