Browse Source

朋友圈ws数据

master
wanghongjun 7 months ago
parent
commit
1df5f96b26
  1. 43
      app/enterprise/controller/Posts.php
  2. 25
      app/enterprise/model/Comment.php

43
app/enterprise/controller/Posts.php

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

25
app/enterprise/model/Comment.php

@ -20,19 +20,24 @@ class Comment extends Model
$comment = self::where($playWhere)->field('id,content,user_id,reply_user_id')->select();
foreach ($comment as &$commentValue) {
$commentValue = self::dataOption($commentValue,$uid);
}
return $comment;
}
$friend = Friend::getFriendName($uid, $commentValue['user_id']);
$commentValue['nickname'] = $friend['nickname'];
$commentValue['reply_user_name'] = '';
if ($commentValue['reply_user_id']) {
$friend = Friend::getFriendName($uid, $commentValue['reply_user_id']);
$commentValue['reply_user_name'] = $friend['nickname'];
}
public static function dataOption($commentValue,$uid)
{
$friend = Friend::getFriendName($uid, $commentValue['user_id']);
$commentValue['nickname'] = $friend['nickname'];
unset($commentValue['reply_user_id']);
$commentValue['reply_user_name'] = '';
if ($commentValue['reply_user_id']) {
$friend = Friend::getFriendName($uid, $commentValue['reply_user_id']);
$commentValue['reply_user_name'] = $friend['nickname'];
}
return $comment;
unset($commentValue['reply_user_id']);
return $commentValue;
}
}
Loading…
Cancel
Save