msg
This commit is contained in:
parent
0a2b7e214f
commit
4005962590
@ -79,8 +79,8 @@ class Notice extends AdminController
|
|||||||
public function delete($id)
|
public function delete($id)
|
||||||
{
|
{
|
||||||
if(Request::isAjax()){
|
if(Request::isAjax()){
|
||||||
$msg = MessageModel::find($id);
|
$msg = MessageModel::with('messageto')->find($id);
|
||||||
$result = $msg->delete();
|
$result = $msg->together(['messageto'])->delete();
|
||||||
|
|
||||||
if($result){
|
if($result){
|
||||||
return json(['code'=>0,'msg'=>'删除成功']);
|
return json(['code'=>0,'msg'=>'删除成功']);
|
||||||
|
@ -3,15 +3,15 @@ namespace app\common\model;
|
|||||||
|
|
||||||
use think\Model;
|
use think\Model;
|
||||||
use think\model\concern\SoftDelete;
|
use think\model\concern\SoftDelete;
|
||||||
use think\Db;
|
|
||||||
|
|
||||||
|
|
||||||
class Message extends Model
|
class Message extends Model
|
||||||
{
|
{
|
||||||
|
use SoftDelete;
|
||||||
protected $pk = 'id'; //主键
|
protected $pk = 'id'; //主键
|
||||||
protected $autoWriteTimestamp = true; //开启自动时间戳
|
protected $autoWriteTimestamp = true; //开启自动时间戳
|
||||||
protected $createTime = 'create_time';
|
protected $createTime = 'create_time';
|
||||||
protected $updateTime = 'update_time';
|
protected $updateTime = 'update_time';
|
||||||
|
protected $deleteTime = 'delete_time';
|
||||||
|
|
||||||
//用户关联评论
|
//用户关联评论
|
||||||
public function user()
|
public function user()
|
||||||
|
@ -49,35 +49,35 @@ class Message extends BaseController
|
|||||||
public function read()
|
public function read()
|
||||||
{
|
{
|
||||||
$id =input('id');
|
$id =input('id');
|
||||||
//$msg = Db::name('message_to')->where('id',$id)->save(['is_read'=>1]);
|
|
||||||
if($id){
|
if($id){
|
||||||
$msg = MessageTo::field('id,message_id')->with(['messages' => function($query){
|
$msg = MessageTo::field('id,message_id')->with(['messages' => function($query){
|
||||||
$query->where('delete_time',0)->field('id,content');
|
$query->where('delete_time',0)->field('id,content');
|
||||||
}])->where('id',$id)->find();
|
}])->where('id',$id)->find();
|
||||||
//改变读状态
|
//改变读状态
|
||||||
$result = $msg->update(['id'=>$id,'is_read'=>1]);
|
if($msg->is_read == 0){
|
||||||
if($result){
|
$result = $msg->update(['id'=>$id,'is_read'=>1]);
|
||||||
$res=['status' =>0,'content'=>$msg['messages']['content']];
|
if($result){
|
||||||
return json($res);
|
$res=['status' =>0,'content'=>$msg['messages']['content']];
|
||||||
|
return json($res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return json(['status' =>0]);
|
return json(['status' =>0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//消息删除
|
//消息删除
|
||||||
public function remove()
|
public function remove()
|
||||||
{
|
{
|
||||||
$uid = Session::get('user_id');
|
$uid = Session::get('user_id');
|
||||||
|
|
||||||
$id = Request::only(['id']);
|
$id = Request::only(['id']);
|
||||||
if($id['id'] == 'true'){
|
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 {
|
} 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){
|
if($msg){
|
||||||
|
@ -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')
|
->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.receve_id',$uid)
|
||||||
->where(['t.delete_time'=>0])
|
->where(['t.delete_time'=>0])
|
||||||
->order(['t.create_time'=>'desc'])
|
->order(['t.is_read'=>'asc','t.create_time'=>'desc'])
|
||||||
->select();
|
->select();
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
}).extend({
|
}).extend({
|
||||||
fly: 'index'
|
fly: 'index'
|
||||||
}).use('fly');
|
}).use('fly');
|
||||||
//点开标题写入帖子已读
|
//点开标题改变帖子已读状态
|
||||||
$('#LAY_minemsg').on('click','.art-title', function(){
|
$('#LAY_minemsg').on('click','.art-title', function(){
|
||||||
var id = $(this).attr('id-data');
|
var id = $(this).attr('id-data');
|
||||||
var othis = $(this);
|
var othis = $(this);
|
||||||
@ -33,14 +33,15 @@
|
|||||||
daType:"json",
|
daType:"json",
|
||||||
success:function (res){
|
success:function (res){
|
||||||
if(res.status == 0){
|
if(res.status == 0){
|
||||||
location.reload();
|
othis.next().html('已读');
|
||||||
|
//location.reload();
|
||||||
//othis.append('<span class="float:right">已读</span>');
|
//othis.append('<span class="float:right">已读</span>');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//点开标题写入系统信已读
|
//点开系统消息改变已读状态
|
||||||
$('#LAY_minemsg').on('click','.sys-title', function(){
|
$('#LAY_minemsg').on('click','.sys-title', function(){
|
||||||
var id = $(this).attr('id-data');
|
var id = $(this).attr('id-data');
|
||||||
var othis = $(this);
|
var othis = $(this);
|
||||||
@ -56,8 +57,8 @@
|
|||||||
skin: 'layui-layer-rim', //加上边框
|
skin: 'layui-layer-rim', //加上边框
|
||||||
area: ['500px', '350px'], //宽高
|
area: ['500px', '350px'], //宽高
|
||||||
content: '<div class="layui-form" style="padding: 10px 20px 0 20px;"> '+ res.content +'</div>'
|
content: '<div class="layui-form" style="padding: 10px 20px 0 20px;"> '+ res.content +'</div>'
|
||||||
});
|
}),
|
||||||
//location.reload(); //数据刷新
|
othis.next().html('已读');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user