FeedbackRepository.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\common\repositories\user;
  3. use app\common\dao\user\FeedbackDao;
  4. use app\common\repositories\BaseRepository;
  5. /**
  6. * Class FeedbackRepository
  7. * @package app\common\repositories\user
  8. * @author zfy
  9. * @day 2020/5/28
  10. * @mixin FeedbackDao
  11. */
  12. class FeedbackRepository extends BaseRepository
  13. {
  14. /**
  15. * FeedbackRepository constructor.
  16. * @param FeedbackDao $dao
  17. */
  18. public function __construct(FeedbackDao $dao)
  19. {
  20. $this->dao = $dao;
  21. }
  22. public function getList(array $where, $page, $limit)
  23. {
  24. $query = $this->dao->search($where)->with(['type' => function($query){
  25. $query->field('feedback_category_id,cate_name');
  26. }]);
  27. $count = $query->count();
  28. $list = $query->page($page, $limit)->withAttr('images',function($val){
  29. return $val ? json_decode($val, true) : [];
  30. })->select();
  31. return compact('count', 'list');
  32. }
  33. public function get( $id)
  34. {
  35. $data = $this->dao->getWhere([$this->dao->getPk() => $id]);
  36. $type = app()->make(FeedBackCategoryRepository::class)->getWhere(['feedback_category_id' => $data['type']]);
  37. $parent = app()->make(FeedBackCategoryRepository::class)->getWhere(['feedback_category_id' => $type['pid']]);
  38. $data['type'] = $type['cate_name'];
  39. $data['category'] = $parent['cate_name'];
  40. return $data;
  41. }
  42. }