FeedbackRepository.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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\Feedback;
  14. use app\common\model\user\FeedbackReply;
  15. use app\common\repositories\BaseRepository;
  16. use think\facade\Db;
  17. /**
  18. * Class FeedbackRepository
  19. * @package app\common\repositories\user
  20. * @author xaboy
  21. * @day 2020/5/28
  22. * @mixin FeedbackDao
  23. */
  24. class FeedbackRepository extends BaseRepository
  25. {
  26. /**
  27. * FeedbackRepository constructor.
  28. * @param FeedbackDao $dao
  29. */
  30. public function __construct(FeedbackDao $dao)
  31. {
  32. $this->dao = $dao;
  33. }
  34. public function getList(array $where, $page, $limit)
  35. {
  36. $query = $this->dao->search($where)->with(['type' => function($query){
  37. $query->field('feedback_category_id,cate_name');
  38. }]);
  39. $count = $query->count();
  40. $list = $query->page($page, $limit)->order("feedback_id desc")->withAttr('images',function($val){
  41. return $val ? json_decode($val, true) : [];
  42. })->select();
  43. return compact('count', 'list');
  44. }
  45. public function getReplyList($userId, $page, $limit)
  46. {
  47. $feedbackIds = Db::name('feedback')
  48. ->alias('feed')
  49. ->leftJoin('feedback_reply reply', 'feed.feedback_id = reply.feedback_id')
  50. ->where(['feed.uid' => $userId,'reply.user_read' => 0])
  51. ->group('feed.feedback_id')
  52. ->field('feed.feedback_id')
  53. ->select()
  54. ->toArray();
  55. $feedbackIds = array_column($feedbackIds,'feedback_id');
  56. return $this->getList(['feedback_id'=>$feedbackIds], $page, $limit);
  57. }
  58. public function get( $id)
  59. {
  60. // 获取反馈信息
  61. $data = $this->dao->getWhere([$this->dao->getPk() => $id],'*',['getReply']);
  62. $type = app()->make(FeedBackCategoryRepository::class)->getWhere(['feedback_category_id' => $data['type']]);
  63. $parent = app()->make(FeedBackCategoryRepository::class)->getWhere(['feedback_category_id' => $type['pid']]);
  64. $data['type'] = $type['cate_name'];
  65. $data['category'] = $parent['cate_name'];
  66. // 更改已读状态
  67. $this->read($id, 'user_read');
  68. return $data;
  69. }
  70. /**
  71. * @param $feedbackId
  72. * @param $userId
  73. * @param $content
  74. * @return int|string
  75. * @author 史晨
  76. * @date 2026/3/17 14:15
  77. * 回复反馈
  78. */
  79. public function reply($feedbackId, $userId, $content)
  80. {
  81. $insert = [
  82. 'feedback_id' => $feedbackId,
  83. 'uid' => $userId,
  84. 'content' => $content,
  85. ];
  86. return FeedbackReply::insert($insert);
  87. }
  88. /**
  89. * @param $feedbackId
  90. * @param $type
  91. * @return void
  92. * @author 史晨
  93. * @date 2026/3/17 14:37
  94. * 更改已读状态
  95. */
  96. public function read($feedbackId, $type)
  97. {
  98. FeedbackReply::update([$type => 1], ['feedback_id' => $feedbackId]);
  99. }
  100. }