|
@@ -49,14 +49,27 @@ class Message extends Api |
|
@@ -49,14 +49,27 @@ class Message extends Api |
49
|
->whereOr('user_id','null')
|
49
|
->whereOr('user_id','null')
|
50
|
->order('is_read desc,createtime desc')
|
50
|
->order('is_read desc,createtime desc')
|
51
|
->select();
|
51
|
->select();
|
52
|
- $data['num'] = Db::name('message')
|
52
|
+
|
|
|
53
|
+ //查询出所有的平台信息
|
|
|
54
|
+ $read = Db::name('message')->where('user_id','null')->select();
|
|
|
55
|
+ //循环判断平台消息是否已读
|
|
|
56
|
+ $nums = 0;
|
|
|
57
|
+ foreach ($read as $val){
|
|
|
58
|
+ $info = Db::name('read')->where('user_id',$user_id)->where('message_id',$val['id'])->find();
|
|
|
59
|
+ if(empty($info)){
|
|
|
60
|
+ $nums += 1;
|
|
|
61
|
+ }
|
|
|
62
|
+ }
|
|
|
63
|
+ $num = Db::name('message')
|
53
|
->where('is_read',0)
|
64
|
->where('is_read',0)
|
54
|
- ->where(function ($query)use($user_id){
|
|
|
55
|
- $query->where('user_id',$user_id)
|
|
|
56
|
- ->whereOr('user_id','null');
|
|
|
57
|
- })
|
|
|
58
|
- ->order('is_read desc,createtime desc')
|
65
|
+ ->where('user_id',$user_id)
|
|
|
66
|
+// ->where(function ($query)use($user_id){
|
|
|
67
|
+// $query->where('user_id',$user_id)
|
|
|
68
|
+// ->whereOr('user_id','null');
|
|
|
69
|
+// })
|
59
|
->count();
|
70
|
->count();
|
|
|
71
|
+ $data['num'] = $num + $nums;
|
|
|
72
|
+ //通知数量
|
60
|
$data['total'] = Db::name('message')
|
73
|
$data['total'] = Db::name('message')
|
61
|
->where('user_id',$user_id)
|
74
|
->where('user_id',$user_id)
|
62
|
->whereOr('user_id','null')
|
75
|
->whereOr('user_id','null')
|
|
@@ -103,16 +116,22 @@ class Message extends Api |
|
@@ -103,16 +116,22 @@ class Message extends Api |
103
|
$read['user_id'] = $user_id;
|
116
|
$read['user_id'] = $user_id;
|
104
|
$read['message_id'] = $id;
|
117
|
$read['message_id'] = $id;
|
105
|
$read['createtime'] = time();
|
118
|
$read['createtime'] = time();
|
106
|
- Db::name('read')->insertGetId($read);
|
119
|
+ //判断该记录是否已经添加过了
|
|
|
120
|
+ $have = Db::name('read')->where('user_id',$read['user_id'])->where('message_id',$read['message_id'])->find();
|
|
|
121
|
+ if(empty($have)){
|
|
|
122
|
+ //没有添加过情况
|
|
|
123
|
+ Db::name('read')->insertGetId($read);
|
|
|
124
|
+ }
|
107
|
$data = Db::name('message')
|
125
|
$data = Db::name('message')
|
108
|
->where('id',$id)
|
126
|
->where('id',$id)
|
|
|
127
|
+ ->field('id,title,content,createtime')
|
109
|
->find();
|
128
|
->find();
|
110
|
- Db::name('message')->where('id',$id)->update(['is_read'=>1]);
|
|
|
111
|
$data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
|
129
|
$data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
|
112
|
}else{
|
130
|
}else{
|
113
|
//不是
|
131
|
//不是
|
114
|
$data = Db::name('message')
|
132
|
$data = Db::name('message')
|
115
|
->where('id',$id)
|
133
|
->where('id',$id)
|
|
|
134
|
+ ->field('id,title,content,createtime')
|
116
|
->find();
|
135
|
->find();
|
117
|
Db::name('message')->where('id',$id)->update(['is_read'=>1]);
|
136
|
Db::name('message')->where('id',$id)->update(['is_read'=>1]);
|
118
|
$data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
|
137
|
$data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
|