|
|
|
@ -445,11 +445,52 @@ class Posts extends BaseController |
|
|
|
|
|
|
|
if ($reply_user_id != $this->uid) { |
|
|
|
PostsNotice::optionNotice($posts_id, $id, $reply_user_id); |
|
|
|
// 向作者好友推送新的消息 |
|
|
|
$this->wsSendMsg($this->uid, $id, 'postsLikes'); |
|
|
|
$this->wsSendMsg($reply_user_id, 0, 'postsNotice'); |
|
|
|
} |
|
|
|
|
|
|
|
return success(lang('posts.success_like')); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param int $user_id // 推送数据 |
|
|
|
* @param int $id // 数据$id |
|
|
|
* @param string $type // 推送类型 postsComment 评论 postsLikes 点赞 postsNotice 提醒 |
|
|
|
* @return void |
|
|
|
*/ |
|
|
|
protected function wsSendMsg(int $user_id, int $id, string $type = 'postsComment') |
|
|
|
{ |
|
|
|
$userIds = []; |
|
|
|
$data = []; |
|
|
|
switch ($type) { |
|
|
|
case 'postsComment' : |
|
|
|
$comment = (new Comment())->where('id', $id)->field('id,content,user_id,reply_user_id')->find(); |
|
|
|
$data = Comment::dataOption($comment, $this->uid); |
|
|
|
break; |
|
|
|
case 'postsLikes' : |
|
|
|
$data = Likes::where('id', $id)->field('user_id')->find(); |
|
|
|
$friend = Friend::getFriendName($this, $data['user_id']); |
|
|
|
$data['nickname'] = $friend['nickname']; |
|
|
|
$data['avatar'] = $friend['avatar']; |
|
|
|
break; |
|
|
|
case 'postsNotice' : |
|
|
|
$count = PostsNotice::where(['user_id' => $this->uid, 'is_read' => 0])->count(); |
|
|
|
$data['count'] = $count ?? 0; |
|
|
|
$userIds[] = $user_id; |
|
|
|
break; |
|
|
|
} |
|
|
|
if (in_array($type, ['postsComment', 'postsLikes'])) { |
|
|
|
$userIds = Friend::getFriendIds($user_id); |
|
|
|
// 不推送给当前用户 |
|
|
|
// $key = array_search($this->uid, $userIds); |
|
|
|
// if ($key !== false) { |
|
|
|
// unset($userIds[$key]); |
|
|
|
// } |
|
|
|
} |
|
|
|
wsSendMsg($userIds,$type,$data); |
|
|
|
} |
|
|
|
|
|
|
|
// 评论帖子 |
|
|
|
public function comment() |
|
|
|
{ |
|
|
|
@ -484,6 +525,8 @@ class Posts extends BaseController |
|
|
|
} |
|
|
|
if ($reply_user_id != $this->uid) { |
|
|
|
PostsNotice::optionNotice($posts_id, $id, $reply_user_id, 2); |
|
|
|
$this->wsSendMsg($this->uid, $id); |
|
|
|
$this->wsSendMsg($reply_user_id, 0, 'postsNotice'); |
|
|
|
} |
|
|
|
return success(lang('system.success')); |
|
|
|
} |
|
|
|
|