FeedbackRepository.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\FeedbackDao;
  13. use app\common\repositories\BaseRepository;
  14. /**
  15. * Class FeedbackRepository
  16. * @package app\common\repositories\user
  17. * @author xaboy
  18. * @day 2020/5/28
  19. * @mixin FeedbackDao
  20. */
  21. class FeedbackRepository extends BaseRepository
  22. {
  23. /**
  24. * FeedbackRepository constructor.
  25. * @param FeedbackDao $dao
  26. */
  27. public function __construct(FeedbackDao $dao)
  28. {
  29. $this->dao = $dao;
  30. }
  31. public function getList(array $where, $page, $limit)
  32. {
  33. $query = $this->dao->search($where)->with(['type' => function($query){
  34. $query->field('feedback_category_id,cate_name');
  35. }]);
  36. $count = $query->count();
  37. $list = $query->page($page, $limit)->withAttr('images',function($val){
  38. return $val ? json_decode($val, true) : [];
  39. })->select();
  40. return compact('count', 'list');
  41. }
  42. public function get( $id)
  43. {
  44. $data = $this->dao->getWhere([$this->dao->getPk() => $id]);
  45. $type = app()->make(FeedBackCategoryRepository::class)->getWhere(['feedback_category_id' => $data['type']]);
  46. $parent = app()->make(FeedBackCategoryRepository::class)->getWhere(['feedback_category_id' => $type['pid']]);
  47. $data['type'] = $type['cate_name'];
  48. $data['category'] = $parent['cate_name'];
  49. return $data;
  50. }
  51. }