Skip to content

Commit

Permalink
fix: 修复推荐用户错误, 修复热门用户加载重复
Browse files Browse the repository at this point in the history
  • Loading branch information
boxshadow committed Apr 21, 2018
1 parent 67995b0 commit fb9b8b7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions app/Http/Controllers/APIs/V2/FindUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function populars(Request $request, UserExtraModel $userExtra, ResponseCo
'user',
])
->orderBy('followers_count', 'desc')
->orderBy('updated_at', 'desc')
->get();

return $response->json(
Expand Down Expand Up @@ -182,21 +183,21 @@ public function search(Request $request, UserModel $user, ResponseContract $resp
*/
public function findByTags(Request $request, TaggableModel $taggable, ResponseContract $response)
{
$u = $request->user('api');
$currentUser = $request->user('api');

if (! $u) {
if (! $currentUser) {
return response()->json([])->setStatusCode(200);
}

$limit = $request->input('limit', 15);
$offset = $request->input('offset', 0);
// $recommends = $users = [];

$tags = $u->tags()->select('tag_id')->get();
$tags = $currentUser->tags()->select('tag_id')->get();
$tags = array_pluck($tags, 'tag_id');
// 根据用户标签获取用户
$users = $taggable->whereIn('tag_id', $tags)
->where('taggable_id', '<>', $u)
->where('taggable_id', '<>', $currentUser->id)
->where('taggable_type', 'users')
->whereExists(function ($query) {
return $query->from('users')->whereRaw('users.id = taggables.taggable_id')->where('deleted_at', null);
Expand All @@ -211,9 +212,9 @@ public function findByTags(Request $request, TaggableModel $taggable, ResponseCo
->get();

return $response->json(
$users->map(function ($user) use ($u) {
$user->user->following = $user->user->hasFollwing($u);
$user->user->follower = $user->user->hasFollower($u);
$users->map(function ($user) use ($currentUser) {
$user->user->following = $user->user->hasFollwing($currentUser);
$user->user->follower = $user->user->hasFollower($currentUser);

return $user->user;
})
Expand Down

0 comments on commit fb9b8b7

Please sign in to comment.