Skip to content

Commit

Permalink
fix(*): 修复 RAW sql 字段标记错误
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Jul 25, 2018
1 parent efed1a0 commit be05d52
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
11 changes: 7 additions & 4 deletions packages/slimkit-plus-feed/src/API2/CommentPinnedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@ public function index(Request $request, FeedPinnedModel $model, FeedRepository $
$limit = $request->query('limit', 15);
$after = $request->query('after');

$grammar = $model->getConnection()->getQueryGrammar();
$pinneds = $model->with('comment')
->where('channel', 'comment')
->where('target_user', $user->id)
->when(boolval($after), function ($query) use ($after) {
return $query->where('id', '<', $after);
})
->orderByRaw(
->orderByRaw(str_replace(
'{expires_at}',
$grammar->wrap('expires_at'),
'CASE
WHEN isnull(`expires_at`) THEN 1
WHEN (`expires_at` is not null ) THEN 2
WHEN isnull({expires_at}) THEN 1
WHEN ({expires_at} is not null ) THEN 2
END ASC'
)
))
->orderBy('created_at', 'desc')
->limit($limit)
->get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,19 @@ public function index(Request $request, NewsPinnedModel $model)
$limit = $request->query('limit', 15);
$after = $request->query('after');

$grammar = $model->getConnection()->getQueryGrammar();
$pinneds = $model->with('comment')
->where('channel', 'news:comment')
->where('target_user', $user->id)
->when(boolval($after), function ($query) use ($after) {
return $query->where('id', '<', $after);
})
->orderByRaw('
->orderByRaw(str_replace('{state}', $grammar->wrap('state'), '
CASE
WHEN (`state` = 0) THEN 1
WHEN (`state` <> 0 ) THEN 2
WHEN ({state} = 0) THEN 1
WHEN ({state} != 0 ) THEN 2
END ASC
')
'))
->orderBy('created_at', 'desc')
->orderBy('id', 'desc')
->limit($limit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ public function testGetNewsCommentPinneds()
$response = $this
->actingAs($this->user, 'api')
->json('GET', '/api/v2/news/comments/pinneds');
dd($response);
$response
->assertStatus(200)
->assertJsonStructure([]);
->assertStatus(200);
}

/**
Expand Down

0 comments on commit be05d52

Please sign in to comment.