FeedbackRepository.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\dao\user\FeedbackReplyDao;
  13. use app\common\model\user\FeedbackReply;
  14. use app\common\repositories\BaseRepository;
  15. /**
  16. * Class FeedbackRepository
  17. * @package app\common\repositories\user
  18. * @author xaboy
  19. * @day 2020/5/28
  20. * @mixin FeedbackDao
  21. */
  22. class FeedbackRepository extends BaseRepository
  23. {
  24. /**
  25. * FeedbackRepository constructor.
  26. * @param FeedbackDao $dao
  27. */
  28. public function __construct(FeedbackDao $dao)
  29. {
  30. $this->dao = $dao;
  31. }
  32. public function getList(array $where, $page, $limit)
  33. {
  34. $query = $this->dao->search($where)->with(['type' => function($query){
  35. $query->field('feedback_category_id,cate_name');
  36. }]);
  37. $count = $query->count();
  38. $list = $query->page($page, $limit)->order("feedback_id desc")->withAttr('images',function($val){
  39. return $val ? json_decode($val, true) : [];
  40. })->select();
  41. return compact('count', 'list');
  42. }
  43. public function get( $id)
  44. {
  45. $data = $this->dao->getWhere([$this->dao->getPk() => $id]);
  46. $type = app()->make(FeedBackCategoryRepository::class)->getWhere(['feedback_category_id' => $data['type']]);
  47. $parent = app()->make(FeedBackCategoryRepository::class)->getWhere(['feedback_category_id' => $type['pid']]);
  48. $data['type'] = $type['cate_name'];
  49. $data['category'] = $parent['cate_name'];
  50. return $data;
  51. }
  52. /**
  53. * @param $feedbackId
  54. * @param $userId
  55. * @param $content
  56. * @return int|string
  57. * @author 史晨
  58. * @date 2026/3/17 14:15
  59. * 回复反馈
  60. */
  61. public function reply($feedbackId, $userId, $content)
  62. {
  63. $insert = [
  64. 'feedback_id' => $feedbackId,
  65. 'uid' => $userId,
  66. 'content' => $content,
  67. ];
  68. return FeedbackReply::insert($insert);
  69. }
  70. }