| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- /**
- * @package merchant
- *
- * @author xaboy
- * @day 2020/5/28
- *
- *
- */
- namespace app\common\repositories\user;
- use app\common\dao\user\FeedbackDao;
- use app\common\dao\user\FeedbackReplyDao;
- use app\common\model\user\Feedback;
- use app\common\model\user\FeedbackReply;
- use app\common\repositories\BaseRepository;
- use think\facade\Db;
- /**
- * Class FeedbackRepository
- * @package app\common\repositories\user
- * @author xaboy
- * @day 2020/5/28
- * @mixin FeedbackDao
- */
- class FeedbackRepository extends BaseRepository
- {
- /**
- * FeedbackRepository constructor.
- * @param FeedbackDao $dao
- */
- public function __construct(FeedbackDao $dao)
- {
- $this->dao = $dao;
- }
- public function getList(array $where, $page, $limit)
- {
- $query = $this->dao->search($where)->with(['type' => function ($query) {
- $query->field('feedback_category_id,cate_name');
- }]);
- $count = $query->count();
- $list = $query->page($page, $limit)->order("feedback_id desc")->withAttr('images', function ($val) {
- return $val ? json_decode($val, true) : [];
- })->select();
- foreach ($list as &$item) {
- $userReply = Db::name('feedback_reply')
- ->where(['feedback_id' => $item['feedback_id']])
- ->where(['admin_read' => 0])
- ->field('content,reply_time')
- ->find();
- $item['userReply'] = $userReply ? 1 : 0;
- }
- return compact('count', 'list');
- }
- public function getReplyList($userId, $page, $limit)
- {
- $feedbackIds = Db::name('feedback')
- ->alias('feed')
- ->leftJoin('feedback_reply reply', 'feed.feedback_id = reply.feedback_id')
- ->where(['feed.uid' => $userId,'reply.user_read' => 0])
- ->group('feed.feedback_id')
- ->field('feed.feedback_id')
- ->select()
- ->toArray();
- $feedbackIds = array_column($feedbackIds,'feedback_id');
- return $this->getList(['feedback_id'=>$feedbackIds], $page, $limit);
- }
- public function get( $id)
- {
- // 获取反馈信息
- $data = $this->dao->getWhere([$this->dao->getPk() => $id],'*',['getReply']);
- $type = app()->make(FeedBackCategoryRepository::class)->getWhere(['feedback_category_id' => $data['type']]);
- $parent = app()->make(FeedBackCategoryRepository::class)->getWhere(['feedback_category_id' => $type['pid']]);
- $data['type'] = $type['cate_name'];
- $data['category'] = $parent['cate_name'];
- // 更改已读状态
- $this->read($id, 'user_read');
- return $data;
- }
- /**
- * @param $feedbackId
- * @param $userId
- * @param $content
- * @return int|string
- * @author 史晨
- * @date 2026/3/17 14:15
- * 回复反馈
- */
- public function reply($feedbackId, $userId, $content)
- {
- $insert = [
- 'feedback_id' => $feedbackId,
- 'uid' => $userId,
- 'content' => $content,
- ];
- return FeedbackReply::insert($insert);
- }
- /**
- * @param $feedbackId
- * @param $type
- * @return void
- * @author 史晨
- * @date 2026/3/17 14:37
- * 更改已读状态
- */
- public function read($feedbackId, $type)
- {
- FeedbackReply::update([$type => 1], ['feedback_id' => $feedbackId]);
- }
- }
|