|
|
@ -68,49 +68,16 @@ class Posts extends BaseController |
|
|
$item['location_address'] = trim(implode(" ", array_unique(\Ip::find($item['location'])))); |
|
|
$item['location_address'] = trim(implode(" ", array_unique(\Ip::find($item['location'])))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$fileWhere = [ |
|
|
$item['files'] = PostsFile::getPostsFile($item['id']); |
|
|
'posts_id' => $item['id'], |
|
|
|
|
|
'delete_time' => 0 |
|
|
|
|
|
]; |
|
|
|
|
|
$files = (new PostsFile()) |
|
|
|
|
|
->where($fileWhere) |
|
|
|
|
|
->field('file_id,type') |
|
|
|
|
|
->order('sort asc') |
|
|
|
|
|
->select() |
|
|
|
|
|
->toArray(); |
|
|
|
|
|
foreach ($files as $fileKey => $fileValue) { |
|
|
|
|
|
$files[$fileKey]['src'] = File::where(['file_id' => $fileValue['file_id']])->value('src'); |
|
|
|
|
|
} |
|
|
|
|
|
$item['files'] = $files; |
|
|
|
|
|
|
|
|
|
|
|
$userIdArr = $friendIds; |
|
|
$userIdArr = $friendIds; |
|
|
$userIdArr[] = $this->uid; |
|
|
$userIdArr[] = $this->uid; |
|
|
$playWhere = [ |
|
|
|
|
|
['type', '=', 1], |
|
|
|
|
|
['relevance_id', '=', $item['id']], |
|
|
|
|
|
['user_id', 'in', $userIdArr] |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
$item['is_like'] = 0; |
|
|
$likesData = Likes::getPostsLikes($item['id'], $this->uid, $userIdArr); |
|
|
$likes = Likes::where($playWhere)->field('user_id')->select(); |
|
|
$item['likes'] = $likesData['likes']; |
|
|
foreach ($likes as $likesKey => $likesValue) { |
|
|
$item['is_like'] = $likesData['is_like']; |
|
|
if ($likesValue['user_id'] == $this->uid) { |
|
|
|
|
|
$item['is_like'] = 1; |
|
|
$item['comment'] = Comment::getPostsComment($item['id'], $this->uid, $userIdArr); |
|
|
} |
|
|
|
|
|
$likes[$likesKey]['nickname'] = Friend::getFriendName($this->uid, $likesValue['user_id']); |
|
|
|
|
|
} |
|
|
|
|
|
$item['likes'] = $likes; |
|
|
|
|
|
|
|
|
|
|
|
$comment = Comment::where($playWhere)->field('id,content,user_id,reply_user_id')->select(); |
|
|
|
|
|
foreach ($comment as $commentKey => $commentValue) { |
|
|
|
|
|
$comment[$commentKey]['nickname'] = Friend::getFriendName($this->uid, $commentValue['user_id']); |
|
|
|
|
|
$comment[$commentKey]['reply_user_name'] = ''; |
|
|
|
|
|
if ($commentValue['reply_user_id']) { |
|
|
|
|
|
$comment[$commentKey]['reply_user_name'] = Friend::getFriendName($this->uid, $commentValue['reply_user_id']); |
|
|
|
|
|
} |
|
|
|
|
|
unset($comment[$commentKey]['reply_user_id']); |
|
|
|
|
|
} |
|
|
|
|
|
$item['comment'] = $comment; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return success('', $data,$list->total(),$list->currentPage()); |
|
|
return success('', $data,$list->total(),$list->currentPage()); |
|
|
@ -120,7 +87,7 @@ class Posts extends BaseController |
|
|
{ |
|
|
{ |
|
|
$where = [ |
|
|
$where = [ |
|
|
['user_id', '=', $this->uid], |
|
|
['user_id', '=', $this->uid], |
|
|
['privacy', '>', 0], |
|
|
['privacy', 'in', [1,2,3,4]], |
|
|
['delete_time', '=', 0] |
|
|
['delete_time', '=', 0] |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
@ -134,12 +101,69 @@ class Posts extends BaseController |
|
|
$data = $list->toArray()['data']; |
|
|
$data = $list->toArray()['data']; |
|
|
foreach ($data as &$item) { |
|
|
foreach ($data as &$item) { |
|
|
|
|
|
|
|
|
|
|
|
$item['files'] = PostsFile::getPostsFile($item['id']); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return success('', $data,$list->total(),$list->currentPage()); |
|
|
return success('', $data,$list->total(),$list->currentPage()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function details() |
|
|
|
|
|
{ |
|
|
|
|
|
$posts_id = $this->request->param('posts_id'); |
|
|
|
|
|
if (empty($posts_id)) { |
|
|
|
|
|
return warning(lang('system.error')); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$where = [ |
|
|
|
|
|
'id' => $posts_id, |
|
|
|
|
|
'user_id' => $this->uid, |
|
|
|
|
|
'delete_time' => 0 |
|
|
|
|
|
]; |
|
|
|
|
|
$field = 'id,content,location,type,user_id,create_time'; |
|
|
|
|
|
$data = (new PostsModel())->where($where)->field($field)->find(); |
|
|
|
|
|
if (!$data) { |
|
|
|
|
|
return warning(lang('system.error')); |
|
|
|
|
|
} |
|
|
|
|
|
$data['files'] = PostsFile::getPostsFile($data['id']); |
|
|
|
|
|
$friendIds = Friend::getFriendIds($this->uid); |
|
|
|
|
|
$friendIds[] = $this->uid; |
|
|
|
|
|
|
|
|
|
|
|
$likesData = Likes::getPostsLikes($data['id'], $this->uid, $friendIds); |
|
|
|
|
|
$data['likes'] = $likesData['likes']; |
|
|
|
|
|
$data['is_like'] = $likesData['is_like']; |
|
|
|
|
|
|
|
|
|
|
|
$data['comment'] = Comment::getPostsComment($data['id'], $this->uid, $friendIds); |
|
|
|
|
|
|
|
|
|
|
|
return success('', $data); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function del() |
|
|
|
|
|
{ |
|
|
|
|
|
try { |
|
|
|
|
|
$posts_id = $this->request->param('posts_id'); |
|
|
|
|
|
if (empty($posts_id)) { |
|
|
|
|
|
throw new \Exception(''); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$existsWhere = [ |
|
|
|
|
|
'id' => $posts_id, |
|
|
|
|
|
'user_id' => $this->uid, |
|
|
|
|
|
'delete_time' => 0 |
|
|
|
|
|
]; |
|
|
|
|
|
$exists = (new PostsModel())->where($existsWhere)->find(); |
|
|
|
|
|
if (!$exists) { |
|
|
|
|
|
throw new \Exception(''); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$exists->delete_time = time(); |
|
|
|
|
|
$exists->save(); |
|
|
|
|
|
return success(lang('system.success')); |
|
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
return warning(lang('system.error')); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function add() |
|
|
public function add() |
|
|
{ |
|
|
{ |
|
|
$content = $this->request->param('content', ''); |
|
|
$content = $this->request->param('content', ''); |
|
|
|