From 400596259073f7635f70905fb4943ae1472ddda3 Mon Sep 17 00:00:00 2001 From: toogee Date: Sun, 5 Apr 2020 12:52:29 +0800 Subject: [PATCH] msg --- app/admin/controller/Notice.php | 4 ++-- app/common/model/Message.php | 4 ++-- app/index/controller/Message.php | 24 ++++++++++++------------ extend/taoler/com/Message.php | 2 +- view/index/user/message.html | 11 ++++++----- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/app/admin/controller/Notice.php b/app/admin/controller/Notice.php index 75e11d0..4828f53 100644 --- a/app/admin/controller/Notice.php +++ b/app/admin/controller/Notice.php @@ -79,8 +79,8 @@ class Notice extends AdminController public function delete($id) { if(Request::isAjax()){ - $msg = MessageModel::find($id); - $result = $msg->delete(); + $msg = MessageModel::with('messageto')->find($id); + $result = $msg->together(['messageto'])->delete(); if($result){ return json(['code'=>0,'msg'=>'删除成功']); diff --git a/app/common/model/Message.php b/app/common/model/Message.php index 5793840..4d09542 100644 --- a/app/common/model/Message.php +++ b/app/common/model/Message.php @@ -3,15 +3,15 @@ namespace app\common\model; use think\Model; use think\model\concern\SoftDelete; -use think\Db; - class Message extends Model { + use SoftDelete; protected $pk = 'id'; //主键 protected $autoWriteTimestamp = true; //开启自动时间戳 protected $createTime = 'create_time'; protected $updateTime = 'update_time'; + protected $deleteTime = 'delete_time'; //用户关联评论 public function user() diff --git a/app/index/controller/Message.php b/app/index/controller/Message.php index 23abce0..d92f783 100644 --- a/app/index/controller/Message.php +++ b/app/index/controller/Message.php @@ -49,35 +49,35 @@ class Message extends BaseController public function read() { $id =input('id'); - //$msg = Db::name('message_to')->where('id',$id)->save(['is_read'=>1]); if($id){ $msg = MessageTo::field('id,message_id')->with(['messages' => function($query){ $query->where('delete_time',0)->field('id,content'); }])->where('id',$id)->find(); //改变读状态 - $result = $msg->update(['id'=>$id,'is_read'=>1]); - if($result){ - $res=['status' =>0,'content'=>$msg['messages']['content']]; - return json($res); + if($msg->is_read == 0){ + $result = $msg->update(['id'=>$id,'is_read'=>1]); + if($result){ + $res=['status' =>0,'content'=>$msg['messages']['content']]; + return json($res); + } } - } else { return json(['status' =>0]); - } - - - + } } //消息删除 public function remove() { $uid = Session::get('user_id'); + $id = Request::only(['id']); if($id['id'] == 'true'){ - $msg = Db::name('message_to')->where(['receve_id'=>$uid,'delete_time'=>0])->useSoftDelete('delete_time',time())->delete(); + //删除所有此用户消息 + $msg = Db::name('message_to')->where(['receve_id'=>$uid,'delete_time'=>0])->delete(); } else { - $msg = Db::name('message_to')->where('id',$id['id'])->useSoftDelete('delete_time',time())->delete(); + //删除单条消息 + $msg = Db::name('message_to')->where('id',$id['id'])->delete(); } if($msg){ diff --git a/extend/taoler/com/Message.php b/extend/taoler/com/Message.php index c307bab..be68c64 100644 --- a/extend/taoler/com/Message.php +++ b/extend/taoler/com/Message.php @@ -39,7 +39,7 @@ class Message ->field('t.id as id,name,title,content,link,receve_id,t.create_time as create_time,message_type,is_read') ->where('t.receve_id',$uid) ->where(['t.delete_time'=>0]) - ->order(['t.create_time'=>'desc']) + ->order(['t.is_read'=>'asc','t.create_time'=>'desc']) ->select(); return $msg; } diff --git a/view/index/user/message.html b/view/index/user/message.html index 6654100..a4daf9d 100644 --- a/view/index/user/message.html +++ b/view/index/user/message.html @@ -22,7 +22,7 @@ }).extend({ fly: 'index' }).use('fly'); - //点开标题写入帖子已读 + //点开标题改变帖子已读状态 $('#LAY_minemsg').on('click','.art-title', function(){ var id = $(this).attr('id-data'); var othis = $(this); @@ -33,14 +33,15 @@ daType:"json", success:function (res){ if(res.status == 0){ - location.reload(); + othis.next().html('已读'); + //location.reload(); //othis.append('已读'); } } }); }); - //点开标题写入系统信已读 + //点开系统消息改变已读状态 $('#LAY_minemsg').on('click','.sys-title', function(){ var id = $(this).attr('id-data'); var othis = $(this); @@ -56,8 +57,8 @@ skin: 'layui-layer-rim', //加上边框 area: ['500px', '350px'], //宽高 content: '
'+ res.content +'
' - }); - //location.reload(); //数据刷新 + }), + othis.next().html('已读'); } } });