FeedbackRepository.php 1.5 KB

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