Browse Source

动态与话题

lizhen_gitee 1 year ago
parent
commit
574024d91b
2 changed files with 120 additions and 47 deletions
  1. 80 47
      application/api/controller/Topicdongtai.php
  2. 40 0
      application/common.php

+ 80 - 47
application/api/controller/Topicdongtai.php

@@ -19,7 +19,10 @@ class Topicdongtai extends Api
     public function addone(){
         $content = input('content','');
         $images = input('images','');
+        $audio_file = input('audio_file','');
         $topic_ids = input('topic_ids','');
+        $aite = input('aite','');
+        $type = input('type',1);
         if(!$content && !$images){
             $this->error(__('Invalid parameters'));
         }
@@ -27,12 +30,23 @@ class Topicdongtai extends Api
         //关键字替换
         $content = Keyworld::sensitive($content);
 
+        //只保留一个
+        if($type == 1){
+            $audio_file = '';
+        }else{
+            $images = '';
+        }
+
         $data = [
             'topic_ids' => $topic_ids,
             'user_id' => $this->auth->id,
             'content' => $content,
             'images' => $images,
-            'type'  => input('type',1),
+            'audio_file' => $audio_file,
+            'type'  => $type,
+            'cityname'  => input('cityname',''),
+            'aite'  => $aite,
+            'is_public'  => input('is_public',1),
             'createtime' => time(),
             'updatetime' => time(),
         ];
@@ -41,7 +55,7 @@ class Topicdongtai extends Api
         Db::startTrans();
         $id = Db::name('topic_dongtai')->insertGetId($data);
         //圈子新增一个贴
-        $rs = Db::name('topic_hub')->where('id',$topic_id)->setInc('t_number');
+        $rs = Db::name('topic_hub')->where('id','IN',$topic_ids)->setInc('t_number');
 
         Db::commit();
 
@@ -119,7 +133,12 @@ class Topicdongtai extends Api
                 $this->error('更新话题数量失败');
             }
         }
-        //删除对应的评论,点赞,评论点赞
+        //删除对应的评论,
+        Db::name('topic_dongtai_answer')->where('dt_id',$id)->delete();
+        //点赞,
+        Db::name('topic_dongtai_good')->where('dt_id',$id)->delete();
+        //评论点赞
+        Db::name('topic_answer_good')->where('dt_id',$id)->delete();
 
         Db::commit();
         $this->success('删除成功');
@@ -195,6 +214,9 @@ class Topicdongtai extends Api
 
                 //话题
                 $val['topic_text'] = Db::name('topic_hub')->where('id','IN',$val['topic_ids'])->column('name');
+
+                //艾特了谁
+                $val['aite_user'] = Db::name('user')->where('id','IN',$val['aite'])->column('nickname');
             }
         }
 
@@ -369,7 +391,7 @@ class Topicdongtai extends Api
         $arr = [
             '侮辱谩骂',
             '色情低俗',
-            '治敏感',
+            '治敏感',
             '违法违规',
             '其他',
         ];
@@ -413,7 +435,7 @@ class Topicdongtai extends Api
         //楼
         $floor_list = Db::name('topic_dongtai_answer')
             ->alias('a')
-            ->field('a.*,user.nickname,user.avatar,user.gender')
+            ->field('a.*,user.nickname,user.avatar,user.gender,user.birthday,user.attribute')
             ->join('user','a.user_id = user.id','LEFT')
             ->where(['a.dt_id'=>$dt_id,'a.level'=>1])->order('a.id desc')->autopage()->select();
         $floor_list = list_domain_image($floor_list,['avatar']);
@@ -445,6 +467,10 @@ class Topicdongtai extends Api
 
                 //回复是否已赞
                 $val['is_good'] = $this->answer_is_good($val['id'],$this->auth->id);
+
+                //用户年龄
+                $val['age'] = birthtime_to_age($val['birthday']);
+                unset($val['birthday']);
             }
         }
 
@@ -458,11 +484,14 @@ class Topicdongtai extends Api
         //楼
         $floor_info = Db::name('topic_dongtai_answer')
             ->alias('a')
-            ->field('a.*,user.nickname,user.avatar,user.gender')
+            ->field('a.*,user.nickname,user.avatar,user.gender,user.birthday,user.attribute')
             ->join('user','a.user_id = user.id','LEFT')
             ->where(['a.id'=>$answer_id])->find();
         $floor_info = info_domain_image($floor_info,['avatar']);
         $floor_info['createtime_text'] = get_last_time($floor_info['createtime']);
+        //用户年龄
+        $floor_info['age'] = birthtime_to_age($floor_info['birthday']);
+        unset($floor_info['birthday']);
         //回复是否已赞
         $floor_info['is_good'] = $this->answer_is_good($answer_id,$this->auth->id);
         $floor_info['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$floor_info['dt_id'],'floor'=>$floor_info['floor'],'level'=>2])->count();
@@ -470,13 +499,16 @@ class Topicdongtai extends Api
         //层
         $floors = $floor_info['floor'];
         $child_lists = Db::name('topic_dongtai_answer')->alias('a')
-            ->field('a.*,user.nickname,user.avatar,user.gender,tuser.nickname as to_nickname,tuser.avatar as to_avatar,tuser.gender as to_gender')
+            ->field('a.*,user.nickname,user.avatar,user.gender,user.birthday,user.attribute')
             ->join('user','a.user_id = user.id','LEFT')
-            ->join('user tuser','a.to_user_id = tuser.id','LEFT')
             ->where(['a.dt_id'=>$floor_info['dt_id'],'a.floor'=>$floors,'a.level'=>2])->order('a.id desc')->autopage()->select();
         $child_lists = list_domain_image($child_lists,['avatar','to_avatar']);
         if(!empty($child_lists)){
             foreach($child_lists as $key => &$answer){
+                //用户年龄
+                $answer['age'] = birthtime_to_age($answer['birthday']);
+                unset($answer['birthday']);
+
                 $answer['is_good'] = $this->answer_is_good($answer['id'],$this->auth->id);
                 $answer['createtime_text'] = get_last_time($answer['createtime']);
             }
@@ -490,6 +522,46 @@ class Topicdongtai extends Api
     }
 
 
+    //是否点赞
+    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;
+        }
+    }
+    //回复是否点赞
+    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($uid,$follow_uid){
+        $where = [
+            'uid' => $uid,
+            'follow_uid' => $follow_uid,
+        ];
+        $check = Db::name('user_follow')->where($where)->find();
+        if($check){
+            return 1;
+        }else{
+            return 0;
+        }
+    }
 
     ////////////////////////////////////////////////////////////
 
@@ -539,45 +611,6 @@ class Topicdongtai extends Api
         $this->success(1,$list);
     }
 
-    //是否点赞
-    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;
-        }
-    }
-    //回复是否点赞
-    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($uid,$follow_uid){
-        $where = [
-            'uid' => $uid,
-            'follow_uid' => $follow_uid,
-        ];
-        $check = Db::name('user_follow')->where($where)->find();
-        if($check){
-            return 1;
-        }else{
-            return 0;
-        }
-    }
 
 }

+ 40 - 0
application/common.php

@@ -796,4 +796,44 @@ function get_last_time($time = NULL) {
     }
 
     return $text;
+}
+//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;
 }