|
|
@ -17,6 +17,7 @@ class Posts extends BaseController |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
protected $url=''; |
|
|
protected $url=''; |
|
|
|
|
|
protected $privacyUserArr = [2,4]; |
|
|
|
|
|
|
|
|
public function __construct() |
|
|
public function __construct() |
|
|
{ |
|
|
{ |
|
|
@ -27,7 +28,7 @@ class Posts extends BaseController |
|
|
// 朋友圈列表 |
|
|
// 朋友圈列表 |
|
|
public function index() |
|
|
public function index() |
|
|
{ |
|
|
{ |
|
|
$where = '(p.delete_time = 0 and p.privacy > 0) '; |
|
|
$where = '(p.delete_time = 0 and p.privacy > 0 and p.status = 1) '; |
|
|
$where .= ' and ( p.user_id = ' . $this->uid; |
|
|
$where .= ' and ( p.user_id = ' . $this->uid; |
|
|
|
|
|
|
|
|
$prefix = config('database.connections.mysql.prefix'); |
|
|
$prefix = config('database.connections.mysql.prefix'); |
|
|
@ -41,17 +42,16 @@ class Posts extends BaseController |
|
|
$where .= " or ( p.privacy = 2 and exists ( |
|
|
$where .= " or ( p.privacy = 2 and exists ( |
|
|
select 1 from {$prefix}posts_privacy_users pvu |
|
|
select 1 from {$prefix}posts_privacy_users pvu |
|
|
where pvu.posts_id = p.id and pvu.user_id = p.user_id |
|
|
where pvu.posts_id = p.id and pvu.user_id = p.user_id |
|
|
and pvu.type = 1 and pvu.user_id in ({$friendIdStr}) |
|
|
and pvu.type = 1 and pvu.user_id in ({$this->uid}) |
|
|
))"; |
|
|
))"; |
|
|
|
|
|
|
|
|
} |
|
|
// 不可见 |
|
|
|
|
|
$where .= " or ( p.privacy = 4 and not exists ( |
|
|
// 不可见 |
|
|
|
|
|
$where .= " or ( p.privacy = 4 and not exists ( |
|
|
|
|
|
select 1 from {$prefix}posts_privacy_users peu |
|
|
select 1 from {$prefix}posts_privacy_users peu |
|
|
where peu.posts_id = p.id and peu.user_id = p.user_id |
|
|
where peu.posts_id = p.id and peu.user_id = p.user_id |
|
|
and peu.type = 2 and peu.user_id = {$this->uid} |
|
|
and peu.type = 2 and peu.user_id = {$this->uid} |
|
|
))"; |
|
|
))"; |
|
|
|
|
|
} |
|
|
$where .= ')'; |
|
|
$where .= ')'; |
|
|
|
|
|
|
|
|
$field = 'p.id,p.content,p.location,p.address as location_address,p.type,p.user_id,p.create_time'; |
|
|
$field = 'p.id,p.content,p.location,p.address as location_address,p.type,p.user_id,p.create_time'; |
|
|
@ -64,16 +64,7 @@ class Posts extends BaseController |
|
|
$data = $list->toArray()['data']; |
|
|
$data = $list->toArray()['data']; |
|
|
foreach ($data as &$item) { |
|
|
foreach ($data as &$item) { |
|
|
|
|
|
|
|
|
$friendNickname = Friend::where(['create_user' => $this->uid, 'friend_user_id' => $item['user_id'], 'status' => 1])->value('nickname'); |
|
|
$item['user'] = $this->getFriendUserInfo($item['user_id']); |
|
|
$user = User::getUserInfo(['user_id' => $item['user_id'], 'status' => 1], 'realname, avatar, user_id'); |
|
|
|
|
|
if (empty($friendNickname)) { |
|
|
|
|
|
$friendNickname = $user['realname']; |
|
|
|
|
|
} |
|
|
|
|
|
$item['user'] = [ |
|
|
|
|
|
'user_id' => $item['user_id'], |
|
|
|
|
|
'avatar' => $user['avatar'] ?: avatarUrl($user['avatar'], $user['realname'], $user['user_id'], 120), |
|
|
|
|
|
'nickname' => $friendNickname |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
$item['files'] = PostsFile::getPostsFile($item['id']); |
|
|
$item['files'] = PostsFile::getPostsFile($item['id']); |
|
|
|
|
|
|
|
|
@ -90,16 +81,32 @@ class Posts extends BaseController |
|
|
return success('', $data,$list->total(),$list->currentPage()); |
|
|
return success('', $data,$list->total(),$list->currentPage()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取好友用户信息 |
|
|
|
|
|
protected function getFriendUserInfo($user_id):array |
|
|
|
|
|
{ |
|
|
|
|
|
$friendNickname = Friend::where(['create_user' => $this->uid, 'friend_user_id' => $user_id, 'status' => 1])->value('nickname'); |
|
|
|
|
|
$user = User::getUserInfo(['user_id' => $user_id, 'status' => 1], 'realname, avatar, user_id'); |
|
|
|
|
|
if (empty($friendNickname)) { |
|
|
|
|
|
$friendNickname = $user['realname']; |
|
|
|
|
|
} |
|
|
|
|
|
return [ |
|
|
|
|
|
'user_id' => $user_id, |
|
|
|
|
|
'avatar' => $user['avatar'] ?: avatarUrl($user['avatar'], $user['realname'], $user['user_id'], 120), |
|
|
|
|
|
'nickname' => $friendNickname |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 我的朋友圈列表 |
|
|
// 我的朋友圈列表 |
|
|
public function myPosts() |
|
|
public function myPosts() |
|
|
{ |
|
|
{ |
|
|
$where = [ |
|
|
$where = [ |
|
|
['user_id', '=', $this->uid], |
|
|
['user_id', '=', $this->uid], |
|
|
['privacy', 'in', [1,2,3,4]], |
|
|
['privacy', 'in', [1,2,3,4]], |
|
|
|
|
|
['status', '=', 1], |
|
|
['delete_time', '=', 0] |
|
|
['delete_time', '=', 0] |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
$field = 'id,content,location,address,type,user_id,create_time'; |
|
|
$field = 'id,content,location,address,type,user_id,create_time,privacy'; |
|
|
$order = 'create_time desc'; |
|
|
$order = 'create_time desc'; |
|
|
$model = new PostsModel(); |
|
|
$model = new PostsModel(); |
|
|
|
|
|
|
|
|
@ -126,9 +133,11 @@ class Posts extends BaseController |
|
|
$where = [ |
|
|
$where = [ |
|
|
'id' => $posts_id, |
|
|
'id' => $posts_id, |
|
|
'user_id' => $this->uid, |
|
|
'user_id' => $this->uid, |
|
|
|
|
|
['privacy', 'in', [1,2,3,4]], |
|
|
|
|
|
['status', '=', 1], |
|
|
'delete_time' => 0 |
|
|
'delete_time' => 0 |
|
|
]; |
|
|
]; |
|
|
$field = 'id,content,location,address,type,user_id,create_time'; |
|
|
$field = 'id,content,location,address,type,user_id,create_time,privacy'; |
|
|
$data = (new PostsModel())->where($where)->field($field)->find(); |
|
|
$data = (new PostsModel())->where($where)->field($field)->find(); |
|
|
if (!$data) { |
|
|
if (!$data) { |
|
|
return warning(lang('system.error')); |
|
|
return warning(lang('system.error')); |
|
|
@ -184,8 +193,13 @@ class Posts extends BaseController |
|
|
$imgArr = $this->request->param('img_arr', []); |
|
|
$imgArr = $this->request->param('img_arr', []); |
|
|
$posts_id = $this->request->param('posts_id', ''); |
|
|
$posts_id = $this->request->param('posts_id', ''); |
|
|
$user_ids = $this->request->param('user_ids', []); |
|
|
$user_ids = $this->request->param('user_ids', []); |
|
|
|
|
|
$status = $this->request->param('status', '1'); |
|
|
|
|
|
|
|
|
$privacy_user_arr = [2,4]; |
|
|
if (!in_array($status, ['1','2'])) { |
|
|
|
|
|
return error(lang('posts.user_empty')); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$privacy_user_arr = $this->privacyUserArr; |
|
|
if (in_array($privacy, $privacy_user_arr)) { |
|
|
if (in_array($privacy, $privacy_user_arr)) { |
|
|
if (empty($user_ids) || !is_array($user_ids)) { |
|
|
if (empty($user_ids) || !is_array($user_ids)) { |
|
|
return error(lang('posts.user_empty')); |
|
|
return error(lang('posts.user_empty')); |
|
|
@ -205,7 +219,7 @@ class Posts extends BaseController |
|
|
if ($posts_id) { |
|
|
if ($posts_id) { |
|
|
$existsWhere = [ |
|
|
$existsWhere = [ |
|
|
'id' => $posts_id, |
|
|
'id' => $posts_id, |
|
|
'privacy' => 0, |
|
|
'status' => 2, |
|
|
'user_id' => $this->uid |
|
|
'user_id' => $this->uid |
|
|
]; |
|
|
]; |
|
|
$exists = (new PostsModel())->where($existsWhere)->find()->toArray(); |
|
|
$exists = (new PostsModel())->where($existsWhere)->find()->toArray(); |
|
|
@ -222,7 +236,8 @@ class Posts extends BaseController |
|
|
'content' => $content, |
|
|
'content' => $content, |
|
|
'privacy' => $privacy, |
|
|
'privacy' => $privacy, |
|
|
'location' => $location ?? '', |
|
|
'location' => $location ?? '', |
|
|
'address' => $address ?? '' |
|
|
'address' => $address ?? '', |
|
|
|
|
|
'status' => $status |
|
|
]; |
|
|
]; |
|
|
if ($posts_id) { |
|
|
if ($posts_id) { |
|
|
$info['update_time'] = time(); |
|
|
$info['update_time'] = time(); |
|
|
@ -318,8 +333,8 @@ class Posts extends BaseController |
|
|
// 获取上传草稿帖子数据 |
|
|
// 获取上传草稿帖子数据 |
|
|
public function getLastPosts() |
|
|
public function getLastPosts() |
|
|
{ |
|
|
{ |
|
|
$existsWhere = ['user_id' => $this->uid, 'privacy' => 0, 'delete_time' => 0]; |
|
|
$existsWhere = ['user_id' => $this->uid, 'status' => 2, 'delete_time' => 0]; |
|
|
$field = 'id as posts_id,content,type,location,address as location_address'; |
|
|
$field = 'id as posts_id,content,type,location,address as location_address,privacy'; |
|
|
$data = PostsModel::where($existsWhere)->field($field)->find(); |
|
|
$data = PostsModel::where($existsWhere)->field($field)->find(); |
|
|
if ($data) { |
|
|
if ($data) { |
|
|
$fileWhere = [ |
|
|
$fileWhere = [ |
|
|
@ -336,6 +351,14 @@ class Posts extends BaseController |
|
|
$files[$fileKey]['src'] = File::where(['file_id' => $fileValue['file_id']])->value('src'); |
|
|
$files[$fileKey]['src'] = File::where(['file_id' => $fileValue['file_id']])->value('src'); |
|
|
} |
|
|
} |
|
|
$data['files'] = $files; |
|
|
$data['files'] = $files; |
|
|
|
|
|
$privacy_user =[]; |
|
|
|
|
|
if (in_array($data['privacy'], $this->privacyUserArr)) { |
|
|
|
|
|
$PrivacyUsers = PostsPrivacyUsers::where(['posts_id' => $data['id']])->column('user_id'); |
|
|
|
|
|
foreach ($PrivacyUsers as $user_id) { |
|
|
|
|
|
$privacy_user[] = $this->getFriendUserInfo($user_id); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
$data['privacy_user'] = $privacy_user; |
|
|
} |
|
|
} |
|
|
return success('', $data); |
|
|
return success('', $data); |
|
|
} |
|
|
} |
|
|
|