Browse Source

动态,是否点赞,我的回复

lizhen_gitee 3 years ago
parent
commit
2f234eed98
2 changed files with 62 additions and 23 deletions
  1. 33 12
      application/api/controller/Topicdongtai.php
  2. 29 11
      application/api/controller/Userdongtai.php

+ 33 - 12
application/api/controller/Topicdongtai.php

@@ -50,12 +50,42 @@ class Topicdongtai extends Api
             ->order('dt.id desc')->autopage()->select();
         $list = list_domain_image($list,['images','avatar']);
 
+        if(!empty($list)){
+            foreach($list as $key => $val){
+                $list[$key]['is_good'] = $this->is_good($val['id'],$this->auth->id);
+            }
+        }
+
         $this->success('success',$list);
     }
 
     //我回复的帖子列表
     public function answer_dt_lists(){
-        
+        $map = [
+            'answer.user_id' => $this->auth->id,
+            'answer.level' => 1,
+        ];
+        $lists = Db::name('topic_dongtai_answer')->alias('answer')
+            ->field('answer.id,answer.content as answer_content,answer.createtime,user.nickname,user.avatar,dt.content as dt_content')
+            ->join('user','answer.user_id = user.id','LEFT')
+            ->join('topic_dongtai dt','answer.dt_id = dt.id','LEFT')
+            ->where($map)->autopage()->select();
+
+        $this->success('success',$lists);
+    }
+
+    //是否点赞
+    private function is_good($dt_id,$uid){
+        $where = [
+            'dt_id' => $dt_id,
+            'user_id'  => $uid,
+        ];
+        $check = Db::name('topic_dongtai_good')->where($where)->find();
+        if($check){
+            return 1;
+        }else{
+            return 0;
+        }
     }
 
     //详情
@@ -70,17 +100,7 @@ class Topicdongtai extends Api
 
         //是否点赞过
         if($info){
-            $where = [
-                'dt_id' => $id,
-                'user_id'  => $this->auth->id,
-            ];
-            $check = Db::name('topic_dongtai_good')->where($where)->find();
-
-            if($check){
-                $info['isgood'] = 1;
-            }else{
-                $info['isgood'] = 0;
-            }
+            $info['isgood'] = $this->is_good($id,$this->auth->id);
         }
 
         //评论
@@ -204,6 +224,7 @@ class Topicdongtai extends Api
             }
             //追加到外循环
             $floor_list[$key]['childcount'] = 0;
+
             if(count($child) > 4){
                 $floor_list[$key]['childcount'] = count($child) - 4;
             }

+ 29 - 11
application/api/controller/Userdongtai.php

@@ -25,6 +25,12 @@ class Userdongtai extends Api
             ->order('dt.id desc')->autopage()->select();
         $list = list_domain_image($list,['images','avatar']);
 
+        if(!empty($list)){
+            foreach($list as $key => $val){
+                $list[$key]['is_good'] = $this->is_good($val['id'],$this->auth->id);
+            }
+        }
+
         $this->success('success',$list);
     }
 
@@ -62,9 +68,30 @@ class Userdongtai extends Api
             ->order('dt.id desc')->autopage()->select();
         $list = list_domain_image($list,['images','avatar']);
 
+        if(!empty($list)){
+            foreach($list as $key => $val){
+                $list[$key]['is_good'] = $this->is_good($val['id'],$this->auth->id);
+            }
+        }
+
         $this->success('success',$list);
     }
 
+    //是否点赞
+    private function is_good($dt_id,$uid){
+        $where = [
+            'dt_id' => $dt_id,
+            'user_id'  => $uid,
+        ];
+        $check = Db::name('user_dongtai_good')->where($where)->find();
+        if($check){
+            return 1;
+        }else{
+            return 0;
+        }
+    }
+
+
     //详情
     public function info(){
         $id = input('id');
@@ -75,19 +102,10 @@ class Userdongtai extends Api
             ->where('dt.id',$id)->find();
         $info = info_domain_image($info,['images','avatar']);
 
+
         //是否点赞过
         if($info){
-            $where = [
-                'dt_id' => $id,
-                'user_id'  => $this->auth->id,
-            ];
-            $check = Db::name('user_dongtai_good')->where($where)->find();
-
-            if($check){
-                $info['isgood'] = 1;
-            }else{
-                $info['isgood'] = 0;
-            }
+            $info['isgood'] = $this->is_good($id,$this->auth->id);
         }
 
         //评论