FeedbackRepository.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // 获取反馈信息
  46. $data = $this->dao->getWhere([$this->dao->getPk() => $id],'*',['getReply']);
  47. $type = app()->make(FeedBackCategoryRepository::class)->getWhere(['feedback_category_id' => $data['type']]);
  48. $parent = app()->make(FeedBackCategoryRepository::class)->getWhere(['feedback_category_id' => $type['pid']]);
  49. $data['type'] = $type['cate_name'];
  50. $data['category'] = $parent['cate_name'];
  51. // 更改已读状态
  52. $this->read($id, 'user_read');
  53. return $data;
  54. }
  55. /**
  56. * @param $feedbackId
  57. * @param $userId
  58. * @param $content
  59. * @return int|string
  60. * @author 史晨
  61. * @date 2026/3/17 14:15
  62. * 回复反馈
  63. */
  64. public function reply($feedbackId, $userId, $content)
  65. {
  66. $insert = [
  67. 'feedback_id' => $feedbackId,
  68. 'uid' => $userId,
  69. 'content' => $content,
  70. ];
  71. return FeedbackReply::insert($insert);
  72. }
  73. /**
  74. * @param $feedbackId
  75. * @param $type
  76. * @return void
  77. * @author 史晨
  78. * @date 2026/3/17 14:37
  79. * 更改已读状态
  80. */
  81. public function read($feedbackId, $type)
  82. {
  83. FeedbackReply::update([$type => 1], ['feedback_id' => $feedbackId]);
  84. }
  85. }