Selaa lähdekoodia

动态互动通知

lizhen 2 päivää sitten
vanhempi
commit
72e23a8329

+ 0 - 2
application/admin/model/Topicdongtai.php

@@ -45,11 +45,9 @@ class Topicdongtai extends Model
 
                 if ($changed['auditstatus'] == 2) {
                     //驳回
-                    $msg_id = \app\common\model\Message::addMessage($row['user_id'],'动态审核','动态审核不通过:'.$row['auditremark']);
 
                 } elseif($changed['auditstatus'] == 1) {
                     //通过
-                    //$msg_id = \app\common\model\Message::addMessage($row['user_id'],'动态审核','动态审核通过');
                 }
             }
         });

+ 102 - 0
application/api/controller/Message.php

@@ -0,0 +1,102 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 消息
+ */
+class Message extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+
+    //个人消息全部改为已读
+    public function message_read(){
+        Db::startTrans();
+        //读取即为已读
+        $map = [
+            'user_id'  => $this->auth->id,
+            'status'   => 0,
+        ];
+        $rs = Db::name('message')->where($map)->update(['status'=>1]);
+        if($rs === false){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+
+
+        //系统消息
+        //全部未读
+        $rs = Db::name('user_messagesys')->where('user_id',$this->auth->id)->delete();
+        if($rs === false){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+
+        //循环全部已读
+        $list = Db::name('message_sys')->column('id');
+        if(!empty($list)){
+            $newall = [];
+            foreach($list as $key => $msg_id){
+                $newall[] = [
+                    'user_id' => $this->auth->id,
+                    'msg_id' => $msg_id,
+                ];
+            }
+            if(!empty($newall)){
+                $rs = Db::name('user_messagesys')->insertAll($newall);
+                if($rs === false){
+                    Db::rollback();
+                    $this->error('操作失败');
+                }
+            }
+        }
+
+        Db::commit();
+        $this->success();
+    }
+
+    //我的个人消息列表
+    public function mylist(){
+        $list = Db::name('message')
+            ->field('message.*,user.nickname,user.avatar,topic_dongtai.images')
+            ->join('user','user.id = message.user_id','LEFT')
+            ->join('topic_dongtai','topic_dongtai.id = message.dt_id','LEFT')
+            ->where('message.to_user_id',$this->auth->id)
+            ->autopage()->order('message.id desc')->select();
+
+        if(!empty($list)){
+
+            foreach($list as $key => $value){
+
+                $dongtai_image = explode(',',$value['images']);
+                $value['dongtai_image'] = isset($dongtai_image[0]) ? localpath_to_netpath($dongtai_image[0]) : '';
+
+                if($value['infotype'] == 'dongtai_answer'){
+                    $value['content'] = Db::name('topic_dongtai_answer')->where('id',$value['infotype_id'])->value('content');
+                }
+
+                $value['createtime_text'] = get_last_time($value['createtime']);
+
+                $list[$key] = $value;
+            }
+
+        }
+
+        //读取即为已读
+        $map = [
+            'to_user_id' => $this->auth->id,
+            'status' => 0,
+        ];
+        Db::name('message')->where($map)->update(['status'=>1]);
+        $this->success('success',$list);
+    }
+
+
+
+
+
+}

+ 11 - 3
application/api/controller/Topicdongtai.php

@@ -225,7 +225,7 @@ class Topicdongtai extends Api
 
             //系统消息
             if($dt_user_id != $this->auth->id){
-                $msg_id = \app\common\model\Message::addMessage($dt_user_id,'动态点赞',$this->auth->nickname.'('.$this->auth->username.')赞了你的动态','dongtai_good',$id);
+                $msg_id = \app\common\model\Message::addMessage($id,$dt_user_id,$dt_user_id, $this->auth->id,'动态点赞','点赞了你的帖子','dongtai_good',$id);
             }
 
             Db::commit();
@@ -254,6 +254,11 @@ class Topicdongtai extends Api
             $this->error('楼层错误');
         }
 
+        $topic_dongtai = Db::name('topic_dongtai')->where('id',$id)->find();
+        if(empty($topic_dongtai)){
+            $this->error('帖子不存在');
+        }
+
         //关键字替换
         $content = Keyworld::sensitive($content);
 
@@ -296,7 +301,7 @@ class Topicdongtai extends Api
         //系统消息
         if($level == 1){
             //发给动态用户
-            $msg_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
+            $msg_user_id = $topic_dongtai['user_id'];
             $msg_title = '动态评论';
             $msg_content = $this->auth->nickname.'评论了你的动态';
             $infotype_id = $rs;
@@ -308,7 +313,10 @@ class Topicdongtai extends Api
             $msg_content = $this->auth->nickname.'点评了你的动态评论';
             $infotype_id = $answer_info['id'];
         }
-        $msg_id = \app\common\model\Message::addMessage($msg_user_id,$msg_title,$msg_content,'dongtai_answer',$infotype_id);
+
+        if($msg_content != $this->auth->id){
+            $msg_id = \app\common\model\Message::addMessage($id,$topic_dongtai['user_id'],$msg_user_id,$this->auth->id,$msg_title,$msg_content,'dongtai_answer',$infotype_id);
+        }
 
         Db::commit();
         $this->success('评论成功');

+ 2 - 2
application/common.php

@@ -640,9 +640,9 @@ if (!function_exists('get_last_time')) {
         $t = $nowtime - $time; //时间差 (秒)
         $y = date('Y', $time)-date('Y', $nowtime);//是否跨年
         switch($t){
-            case $t == 0:
+            /*case $t == 0:
                 $text = '刚刚';
-                break;
+                break;*/
             case $t < 60:
                 $text = $t . '秒前'; // 一分钟内
                 break;

+ 2 - 1
application/common/library/Auth.php

@@ -389,7 +389,8 @@ class Auth
 
         unset($userinfo['wxmini_openid']);
 
-        //是否弹出未领取的优惠券
+        //动态消息未读数量
+        $userinfo['msg_unread_num'] = Db::name('message')->where('to_user_id',$this->id)->where('status',0)->count();
 
         return $userinfo;
     }

+ 5 - 5
application/common/model/Message.php

@@ -18,16 +18,16 @@ class Message extends Model
     /**
      * 添加系统消息
      */
-    public static function addMessage($user_id,$title,$content,$infotype = '',$infotype_id = 0) {
-        if(!$user_id || !$title || !$content) {
+    public static function addMessage($dt_id,$dt_user_id,$to_user_id,$user_id,$title,$content,$infotype = '',$infotype_id = 0) {
+        if(!$to_user_id || !$user_id || !$title || !$content) {
             return false;
         }
-        //推送
-        //$easemob = new Easemob();
-        //$easemob->push_text($user_id,$title,$content);
 
         //入库
         $data = [];
+        $data["dt_id"] = $dt_id;
+        $data["dt_user_id"] = $dt_user_id;
+        $data["to_user_id"] = $to_user_id;
         $data["user_id"] = $user_id;
         $data["title"] = $title;
         $data["content"] = $content;