This commit is contained in:
toogee 2020-04-05 12:52:29 +08:00
parent 0a2b7e214f
commit 4005962590
5 changed files with 23 additions and 22 deletions

View File

@ -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'=>'删除成功']);

View File

@ -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()

View File

@ -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){

View File

@ -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;
}

View File

@ -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('<span class="float:right">已读</span>');
}
}
});
});
//点开标题写入系统信已读
//点开系统消息改变已读状态
$('#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: '<div class="layui-form" style="padding: 10px 20px 0 20px;"> '+ res.content +'</div>'
});
//location.reload(); //数据刷新
}),
othis.next().html('已读');
}
}
});