WIN-2308041133\Administrator 3 mesiacov pred
rodič
commit
6c81180497

+ 7 - 5
app/model/api/ForumComment.php

@@ -31,14 +31,16 @@ class ForumComment extends BaseModel
         // 默认只查询已审核的评论
         $where[] = ['c.status', '=', 1];
 
-        $total = $this->where($where)->count();
+        $query = $this->alias('c')
+            ->field('c.*, u.nickname as author_name, u.avatar as author_avatar')
+            ->leftJoin('user u', 'u.uid = c.uid')
+            ->where($where);
+
+        $total = $query->count();
         $list = [];
 
         if ($total > 0) {
-            $list = $this->alias('c')
-                ->field('c.*, u.nickname as author_name, u.avatar as author_avatar')
-                ->leftJoin('user u', 'u.uid = c.uid')
-                ->where($where)
+            $list = $query
                 ->order('c.create_time', 'asc')
                 ->page($page, $pageSize)
                 ->select();

+ 4 - 0
app/model/api/ForumPost.php

@@ -5,6 +5,7 @@ namespace app\model\api;
 
 use library\basic\BaseModel;
 use think\Model;
+use think\facade\Db;
 
 /**
  * 论坛帖子模型
@@ -110,6 +111,9 @@ class ForumPost extends BaseModel
         // 增加浏览次数
         $this->where('id', $id)->inc('view_count')->update();
 
+        // 获取评论列表
+        $post['comments'] = (new ForumComment())->getList(1, [['c.post_id', '=', $id]], 50);
+
         return $post;
     }