...
|
...
|
@@ -49,14 +49,27 @@ class Message extends Api |
|
|
->whereOr('user_id','null')
|
|
|
->order('is_read desc,createtime desc')
|
|
|
->select();
|
|
|
$data['num'] = Db::name('message')
|
|
|
|
|
|
//查询出所有的平台信息
|
|
|
$read = Db::name('message')->where('user_id','null')->select();
|
|
|
//循环判断平台消息是否已读
|
|
|
$nums = 0;
|
|
|
foreach ($read as $val){
|
|
|
$info = Db::name('read')->where('user_id',$user_id)->where('message_id',$val['id'])->find();
|
|
|
if(empty($info)){
|
|
|
$nums += 1;
|
|
|
}
|
|
|
}
|
|
|
$num = Db::name('message')
|
|
|
->where('is_read',0)
|
|
|
->where(function ($query)use($user_id){
|
|
|
$query->where('user_id',$user_id)
|
|
|
->whereOr('user_id','null');
|
|
|
})
|
|
|
->order('is_read desc,createtime desc')
|
|
|
->where('user_id',$user_id)
|
|
|
// ->where(function ($query)use($user_id){
|
|
|
// $query->where('user_id',$user_id)
|
|
|
// ->whereOr('user_id','null');
|
|
|
// })
|
|
|
->count();
|
|
|
$data['num'] = $num + $nums;
|
|
|
//通知数量
|
|
|
$data['total'] = Db::name('message')
|
|
|
->where('user_id',$user_id)
|
|
|
->whereOr('user_id','null')
|
...
|
...
|
@@ -103,16 +116,22 @@ class Message extends Api |
|
|
$read['user_id'] = $user_id;
|
|
|
$read['message_id'] = $id;
|
|
|
$read['createtime'] = time();
|
|
|
//判断该记录是否已经添加过了
|
|
|
$have = Db::name('read')->where('user_id',$read['user_id'])->where('message_id',$read['message_id'])->find();
|
|
|
if(empty($have)){
|
|
|
//没有添加过情况
|
|
|
Db::name('read')->insertGetId($read);
|
|
|
}
|
|
|
$data = Db::name('message')
|
|
|
->where('id',$id)
|
|
|
->field('id,title,content,createtime')
|
|
|
->find();
|
|
|
Db::name('message')->where('id',$id)->update(['is_read'=>1]);
|
|
|
$data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
|
|
|
}else{
|
|
|
//不是
|
|
|
$data = Db::name('message')
|
|
|
->where('id',$id)
|
|
|
->field('id,title,content,createtime')
|
|
|
->find();
|
|
|
Db::name('message')->where('id',$id)->update(['is_read'=>1]);
|
|
|
$data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
|
...
|
...
|
|