Browse Source

动态完善

lizhen_gitee 1 year ago
parent
commit
3449eeaecd

+ 121 - 25
application/api/controller/Topicdongtai.php

@@ -10,7 +10,7 @@ use app\common\library\Keyworld;
  */
 class Topicdongtai extends Api
 {
-    protected $noNeedLogin = ['info','floor_info','topic_list'];
+    protected $noNeedLogin = [];
     protected $noNeedRight = ['*'];
 
     //发布动态
@@ -91,6 +91,19 @@ class Topicdongtai extends Api
             return 0;
         }
     }
+    //回复是否点赞
+    private function answer_is_good($answer_id,$uid){
+        $where = [
+            'answer_id' => $answer_id,
+            'user_id'  => $uid,
+        ];
+        $check = Db::name('topic_answer_good')->where($where)->find();
+        if($check){
+            return 1;
+        }else{
+            return 0;
+        }
+    }
 
     //是否关注
     private function is_follow($user_id,$fans_id){
@@ -117,9 +130,11 @@ class Topicdongtai extends Api
             ->where('dt.id',$id)->find();
         $info = info_domain_image($info,['images','avatar']);
 
-        //是否点赞过
+
         if($info){
+            //是否点赞过
             $info['isgood'] = $this->is_good($id,$this->auth->id);
+
             //创建视频缩略图
             $info['images_thumb'] = '';
             if ($info['type'] == 2) {
@@ -128,10 +143,8 @@ class Topicdongtai extends Api
                 $info['images_thumb'] = join('.', $images_url) . '_0.jpg';
             }
             $info['createtime_text'] = $this->get_last_time($info['createtime']);
-        }
 
-        //评论
-        if($info){
+            //评论
             $info['answer'] = $this->answer_list($id);
         }
 
@@ -218,12 +231,80 @@ class Topicdongtai extends Api
         Db::startTrans();
         $rs = Db::name('topic_dongtai_answer')->insertGetId($data);
 
-        Db::name('topic_dongtai')->setInc('answernum');
+        Db::name('topic_dongtai')->where('id',$id)->setInc('answernum');
 
         Db::commit();
         $this->success('评价成功');
     }
 
+    //对评论点赞
+    public function answer_good(){
+        $dt_id = input('dt_id',0);
+        $answer_id = input('answer_id',0);
+
+        $where = [
+            'dt_id'     => $dt_id,
+            'answer_id' => $answer_id,
+            'user_id'   => $this->auth->id,
+        ];
+        $check = Db::name('topic_answer_good')->where($where)->find();
+
+        if($check){
+            $this->error('已经赞过了');
+        }
+
+        Db::startTrans();
+        $rs = Db::name('topic_answer_good')->insertGetId($where);
+        $up = Db::name('topic_dongtai_answer')->where('id',$answer_id)->setInc('goodnum');
+
+        if($rs && $up !== false){
+            Db::commit();
+            $this->success('点赞成功');
+        }
+        Db::rollback();
+        $this->error('点赞失败');
+    }
+
+    //举报枚举
+    public function report_enum(){
+        $arr = [
+            '侮辱谩骂',
+            '色情低俗',
+            '整治敏感',
+            '违法违规',
+            '其他',
+        ];
+        $this->success(1,$arr);
+    }
+
+    //举报
+    public function report(){
+        $field = ['dt_id','type','content','images'];
+        $data = request_post_hub($field);
+
+        $data['user_id']    = $this->auth->id;
+        $data['createtime'] = time();
+
+        Db::name('topic_dongtai_report')->insertGetId($data);
+        $this->success('举报成功');
+    }
+
+    //不感兴趣,屏蔽某条
+    public function screen(){
+        $data = [
+            'user_id' => $this->auth->id,
+            'dt_id'   => input('dt_id',0),
+        ];
+        $check = Db::name('topic_dongtai_screen')->where($data)->find();
+        if($check){
+            $this->success('操作成功');
+        }
+
+        Db::name('topic_dongtai_screen')->insertGetId($data);
+
+        $this->success('操作成功');
+    }
+
     //评论列表
     private function answer_list($dt_id){
         //楼
@@ -235,26 +316,30 @@ class Topicdongtai extends Api
         $floor_list = list_domain_image($floor_list,['avatar']);
 
         //追加子评论
-        foreach($floor_list as $key => &$val){
-            $val['childremark'] = '';
-
-            $map = [
-                'a.dt_id' => $dt_id,
-                'a.floor' => $val['floor'],
-                'a.level' => 2,
-            ];
-            $number = Db::name('topic_dongtai_answer')->alias('a')->where($map)->count();
-            if($number > 0){
-                $answer_info = Db::name('topic_dongtai_answer')
-                    ->alias('a')
-                    ->field('user.nickname')
-                    ->join('user','a.user_id = user.id','LEFT')
-                    ->where($map)->order('a.id desc')->find();
-
-                $val['childremark'] = $answer_info['nickname'].'...等人,共'.$number.'条回复';
-            }
-
+        if(!empty($floor_list)){
+            foreach($floor_list as $key => &$val){
+                //下面几条子回复,字符串
+                $val['childremark'] = '';
+
+                $map = [
+                    'a.dt_id' => $dt_id,
+                    'a.floor' => $val['floor'],
+                    'a.level' => 2,
+                ];
+                $number = Db::name('topic_dongtai_answer')->alias('a')->where($map)->count();
+                if($number > 0){
+                    $answer_info = Db::name('topic_dongtai_answer')
+                        ->alias('a')
+                        ->field('user.nickname')
+                        ->join('user','a.user_id = user.id','LEFT')
+                        ->where($map)->order('a.id desc')->find();
+
+                    $val['childremark'] = $answer_info['nickname'].'...等人,共'.$number.'条回复';
+                }
 
+                //回复是否已赞
+                $val['is_good'] = $this->answer_is_good($val['id'],$this->auth->id);
+            }
         }
 
         return $floor_list;
@@ -271,6 +356,8 @@ class Topicdongtai extends Api
             ->join('user','a.user_id = user.id','LEFT')
             ->where(['a.id'=>$floor_id])->find();
         $floor_info = info_domain_image($floor_info,['avatar']);
+        //回复是否已赞
+        $floor_info['is_good'] = $this->answer_is_good($floor_id,$this->auth->id);
 
         //层
         $floors = $floor_info['floor'];
@@ -280,6 +367,11 @@ class Topicdongtai extends Api
             ->join('user tuser','a.to_user_id = tuser.id','LEFT')
             ->where(['a.floor'=>$floors,'a.level'=>2])->order('id asc')->autopage()->select();
         $child_lists = list_domain_image($child_lists,['avatar','to_avatar']);
+        if(!empty($child_lists)){
+            foreach($child_lists as $key => &$answer){
+                $answer['is_good'] = $this->answer_is_good($answer['id'],$this->auth->id);
+            }
+        }
 
         //合并
         $floor_info['child'] = $child_lists;
@@ -308,6 +400,10 @@ class Topicdongtai extends Api
             $where['dt.user_id'] = ['IN',$follow_user_ids];
         }
 
+        //排除屏蔽的
+        $screen = 1;
+        //排除黑名单的
+
         $list = Db::name('topic_dongtai')->alias('dt')
             ->join('user','dt.user_id = user.id','LEFT')
             ->join('topic_hub topic','dt.topic_id = topic.id','LEFT')

+ 41 - 0
application/common.php

@@ -468,3 +468,44 @@ if (!function_exists('localpath_to_netpath')) {
         }
     }
 }
+
+//post接收参数中心,只接非必须
+function request_post_hub($field_array = [],$required = [],$noempty = []){
+    if(empty($field_array)){
+        return [];
+    }
+
+    $data = [];
+
+    foreach($field_array as $key => $field){
+
+        //接收
+        if(!request()->has($field,'post')){
+            continue;
+        }
+        $newone = request()->post($field);
+
+        //追加
+        $data[$field] = $newone;
+    }
+
+    //必传
+    if(!empty($required)){
+        foreach($required as $k => $mustone){
+            if(!isset($data[$mustone])){
+                return $mustone.' required';
+            }
+        }
+    }
+
+    //必传,且不能空
+    if(!empty($noempty)){
+        foreach($noempty as $havekey => $haveone){
+            if(!isset($data[$havekey]) || empty($data[$havekey])){
+                return $haveone.' 必填';
+            }
+        }
+    }
+
+    return $data;
+}

+ 3 - 0
application/common/controller/Api.php

@@ -172,6 +172,9 @@ class Api
      */
     protected function success($msg = '', $data = null, $code = 1, $type = null, array $header = [])
     {
+        if($msg == 1){
+            $msg = 'success';
+        }
         $this->result($msg, $data, $code, $type, $header);
     }