|
|
|
@ -31,7 +31,6 @@ class Posts extends BaseController |
|
|
|
$where = '(p.delete_time = 0 and p.privacy > 0 and p.status = 1) '; |
|
|
|
$where .= ' and ( p.user_id = ' . $this->uid; |
|
|
|
|
|
|
|
$prefix = config('database.connections.mysql.prefix'); |
|
|
|
$friendIds = Friend::getFriendIds($this->uid); |
|
|
|
|
|
|
|
if ($friendIds) { |
|
|
|
@ -39,18 +38,7 @@ class Posts extends BaseController |
|
|
|
$where .= ' or ( p.privacy = 1 and p.user_id in (' . $friendIdStr . '))'; |
|
|
|
|
|
|
|
// 可见 |
|
|
|
$where .= " or ( p.privacy = 2 and exists ( |
|
|
|
select 1 from {$prefix}posts_privacy_users pvu |
|
|
|
where pvu.posts_id = p.id and pvu.user_id = p.user_id |
|
|
|
and pvu.type = 1 and pvu.user_id in ({$this->uid}) |
|
|
|
))"; |
|
|
|
|
|
|
|
// 不可见 |
|
|
|
$where .= " or ( p.privacy = 4 and not exists ( |
|
|
|
select 1 from {$prefix}posts_privacy_users peu |
|
|
|
where peu.posts_id = p.id |
|
|
|
and peu.type = 2 and peu.user_id = {$this->uid} |
|
|
|
))"; |
|
|
|
$where = $this->getPostsWhereOr($where); |
|
|
|
} |
|
|
|
$where .= ')'; |
|
|
|
|
|
|
|
@ -96,21 +84,62 @@ class Posts extends BaseController |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
// 好友可见、不可见查询条件 |
|
|
|
protected function getPostsWhereOr($whereOr):string |
|
|
|
{ |
|
|
|
$prefix = config('database.connections.mysql.prefix'); |
|
|
|
|
|
|
|
$whereOr .= " or ( p.privacy = 2 and exists ( |
|
|
|
select 1 from {$prefix}posts_privacy_users pvu |
|
|
|
where pvu.posts_id = p.id and pvu.user_id = p.user_id |
|
|
|
and pvu.type = 1 and pvu.user_id in ({$this->uid}) |
|
|
|
))"; |
|
|
|
|
|
|
|
// 不可见 |
|
|
|
$whereOr .= " or ( p.privacy = 4 and not exists ( |
|
|
|
select 1 from {$prefix}posts_privacy_users peu |
|
|
|
where peu.posts_id = p.id |
|
|
|
and peu.type = 2 and peu.user_id = {$this->uid} |
|
|
|
))"; |
|
|
|
return $whereOr; |
|
|
|
} |
|
|
|
|
|
|
|
// 我的朋友圈列表 |
|
|
|
public function myPosts() |
|
|
|
{ |
|
|
|
$where = [ |
|
|
|
['user_id', '=', $this->uid], |
|
|
|
['privacy', 'in', [1,2,3,4]], |
|
|
|
['status', '=', 1], |
|
|
|
['delete_time', '=', 0] |
|
|
|
]; |
|
|
|
$user_id = $this->uid; |
|
|
|
// 好有朋友圈 |
|
|
|
$friendUserId = $this->request->param('friend_user_id', ''); |
|
|
|
|
|
|
|
$field = 'id,content,location,address,type,user_id,create_time,privacy,avatar'; |
|
|
|
$whereAnd = " ( p.status = 1 and p.delete_time = 0"; |
|
|
|
$whereOr = ''; |
|
|
|
|
|
|
|
if ($friendUserId) { |
|
|
|
// 验证是否为当前用户的好友 |
|
|
|
if (!is_numeric($friendUserId)) { |
|
|
|
return warning(lang('system.error')); |
|
|
|
} |
|
|
|
$friendIds = Friend::getFriendIds($this->uid); |
|
|
|
if (!in_array($friendUserId, $friendIds)) { |
|
|
|
return warning(lang('system.error')); |
|
|
|
} |
|
|
|
$user_id = $friendUserId; |
|
|
|
|
|
|
|
$whereOr .= ' and ( p.privacy = 1 '; |
|
|
|
$whereOr = $this->getPostsWhereOr($whereOr); |
|
|
|
$whereOr .= ')'; |
|
|
|
} else { |
|
|
|
$whereAnd .= ' and p.privacy in (1,2,3,4)'; |
|
|
|
} |
|
|
|
$whereAnd .= " and p.user_id = {$user_id} )"; |
|
|
|
|
|
|
|
$where = $whereAnd . $whereOr; |
|
|
|
|
|
|
|
$field = 'p.id,p.content,p.location,p.address,p.type,p.user_id,p.create_time,p.privacy,p.avatar'; |
|
|
|
$order = 'create_time desc'; |
|
|
|
$model = new PostsModel(); |
|
|
|
|
|
|
|
$list = $this->paginate($model->where($where)->field($field)->order($order)); |
|
|
|
$list = $this->paginate($model->alias('p')->where($where)->field($field)->order($order)); |
|
|
|
$data = []; |
|
|
|
if ($list) { |
|
|
|
$data = $list->toArray()['data']; |
|
|
|
@ -139,17 +168,31 @@ class Posts extends BaseController |
|
|
|
public function details() |
|
|
|
{ |
|
|
|
$posts_id = $this->request->param('posts_id'); |
|
|
|
$friendUserId = $this->request->param('friend_user_id', ''); |
|
|
|
if (empty($posts_id)) { |
|
|
|
return warning(lang('system.error')); |
|
|
|
} |
|
|
|
|
|
|
|
$where = [ |
|
|
|
['id', '=', $posts_id], |
|
|
|
['user_id', '=', $this->uid], |
|
|
|
['privacy', 'in', [1,2,3,4]], |
|
|
|
['status', '=', 1], |
|
|
|
['delete_time', '=', 0] |
|
|
|
]; |
|
|
|
if ($friendUserId) { |
|
|
|
// 验证是否为当前用户的好友 |
|
|
|
if (!is_numeric($friendUserId)) { |
|
|
|
return warning(lang('system.error')); |
|
|
|
} |
|
|
|
$friendIds = Friend::getFriendIds($this->uid); |
|
|
|
if (!in_array($friendUserId, $friendIds)) { |
|
|
|
return warning(lang('system.error')); |
|
|
|
} |
|
|
|
$where[] = ['user_id', '=', $friendUserId]; |
|
|
|
$where[] = ['privacy', 'in', [1,2,4]]; |
|
|
|
} else { |
|
|
|
$where[] = ['user_id', '=', $this->uid]; |
|
|
|
$where[] = ['privacy', 'in', [1,2,3,4]]; |
|
|
|
} |
|
|
|
$field = 'id,content,location,address,type,user_id,create_time,privacy'; |
|
|
|
$data = (new PostsModel())->where($where)->field($field)->find(); |
|
|
|
if (!$data) { |
|
|
|
|