Parcourir la source

feat(feedback): 添加反馈列表中的用户回复状态查询功能

- 在 FeedbackRepository 中的 getList 方法中添加了对用户回复状态的查询逻辑
- 使用 Db 查询获取 feedback_reply 表中未读回复的信息
- 为每个反馈项添加 userReply 字段标识是否存在未读回复
- 优化了闭包函数的写法,统一了代码风格
- 保持原有的分页、排序和属性转换功能不变
shichen il y a 4 mois
Parent
commit
16a5307090
1 fichiers modifiés avec 12 ajouts et 2 suppressions
  1. 12 2
      app/common/repositories/user/FeedbackRepository.php

+ 12 - 2
app/common/repositories/user/FeedbackRepository.php

@@ -38,14 +38,24 @@ class FeedbackRepository extends BaseRepository
38
 
38
 
39
     public function getList(array $where, $page, $limit)
39
     public function getList(array $where, $page, $limit)
40
     {
40
     {
41
-        $query = $this->dao->search($where)->with(['type' => function($query){
41
+        $query = $this->dao->search($where)->with(['type' => function ($query) {
42
             $query->field('feedback_category_id,cate_name');
42
             $query->field('feedback_category_id,cate_name');
43
         }]);
43
         }]);
44
 
44
 
45
         $count = $query->count();
45
         $count = $query->count();
46
-        $list = $query->page($page, $limit)->order("feedback_id desc")->withAttr('images',function($val){
46
+        $list = $query->page($page, $limit)->order("feedback_id desc")->withAttr('images', function ($val) {
47
             return $val ? json_decode($val, true) : [];
47
             return $val ? json_decode($val, true) : [];
48
         })->select();
48
         })->select();
49
+
50
+        foreach ($list as &$item) {
51
+            $userReply = Db::name('feedback_reply')
52
+                ->where(['feedback_id' => $item['feedback_id']])
53
+                ->where(['admin_read' => 0])
54
+                ->field('content,reply_time')
55
+                ->find();
56
+            $item['userReply'] = $userReply ? 1 : 0;
57
+        }
58
+
49
         return compact('count', 'list');
59
         return compact('count', 'list');
50
     }
60
     }
51
 
61