Kaynağa Gözat

点赞和评论和点评都要发系统消息

lizhen_gitee 1 yıl önce
ebeveyn
işleme
c1c76e839d

+ 20 - 0
application/api/controller/Topicdongtai.php

@@ -369,6 +369,7 @@ class Topicdongtai extends Api
             'user_id'  => $this->auth->id,
         ];
         $check = Db::name('topic_dongtai_good')->where($where)->find();
+        $dt_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
 
         if($check){
             Db::name('topic_dongtai_good')->where($where)->delete();
@@ -390,6 +391,8 @@ class Topicdongtai extends Api
                 $this->error('点赞失败');
             }
 
+            //系统消息
+            $msg_id = \app\common\model\Message::addMessage($dt_user_id,'动态点赞','有人赞了你的动态','dongtai_good',$id);
 
             Db::commit();
             $this->success('点赞成功');
@@ -452,6 +455,23 @@ class Topicdongtai extends Api
 
         Db::name('topic_dongtai')->where('id',$id)->setInc('answernum');
 
+        //系统消息
+        if($level == 1){
+            //发给动态用户
+            $msg_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
+            $msg_title = '动态评论';
+            $msg_content = '有人评论了你的动态';
+            $infotype_id = $rs;
+        }else{
+            //发给层主
+            $answer_info = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1,'floor'=>$floor])->find();
+            $msg_user_id = $answer_info['user_id'];
+            $msg_title = '动态评论点评';
+            $msg_content = '有人点评了你的动态评论';
+            $infotype_id = $answer_info['id'];
+        }
+        $msg_id = \app\common\model\Message::addMessage($msg_user_id,$msg_title,$msg_content,'dongtai_answer',$infotype_id);
+
         Db::commit();
         $this->success('评价成功');
     }

+ 3 - 1
application/common/model/Message.php

@@ -18,7 +18,7 @@ class Message extends Model
     /**
      * 添加系统消息
      */
-    public static function addMessage($user_id,$title,$content) {
+    public static function addMessage($user_id,$title,$content,$infotype = '',$infotype_id = 0) {
         if(!$user_id || !$title || !$content) {
             return false;
         }
@@ -28,6 +28,8 @@ class Message extends Model
         $data["content"] = $content;
         $data["createtime"] = time();
         $data["status"] = 0;
+        $data["infotype"] = $infotype;
+        $data["infotype_id"] = $infotype_id;
         return self::insertGetId($data);
     }