|
@@ -32,58 +32,10 @@ class PostRepositories
|
|
|
public function suggestPost($request)
|
|
|
{
|
|
|
$perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
- $where = [];
|
|
|
- $where[] = ['is_hide', 0];
|
|
|
- if(isset($request['content'])){
|
|
|
- $where[] = ['content', 'like', "%{$request['content']}%"];
|
|
|
- }
|
|
|
- if(isset($request['is_suggest'])){
|
|
|
- $where[] = ['is_suggest', $request['is_suggest']];
|
|
|
- }
|
|
|
- if(isset($request['type'])){
|
|
|
- $where[] = ['type', $request['type']];
|
|
|
- }
|
|
|
-
|
|
|
- if(isset($request['uid'])){
|
|
|
- $where[] = ['uid', $request['uid']];
|
|
|
- }
|
|
|
|
|
|
return $this->post
|
|
|
->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
->select('post.*')
|
|
|
- ->where($where)
|
|
|
- ->where(function($query) use ($request){
|
|
|
- if(isset($request['keyword'])){
|
|
|
- $query->where('uid', '=', $request['keyword'])
|
|
|
- ->orWhere('username', 'like', "%{$request['keyword']}%")
|
|
|
- ->orWhere('mobile', 'like', "%{$request['keyword']}%");
|
|
|
- }
|
|
|
- })
|
|
|
- ->where(function($query) use ($request){
|
|
|
- if(isset($request['created_at'])){
|
|
|
- $time = explode('_', $request['created_at']);
|
|
|
- $query->whereBetween('post.created_at', $time);
|
|
|
- }
|
|
|
- })
|
|
|
- ->where(function ($query) use ($request){
|
|
|
- if(isset($request['category_ids']) || isset($request['topic_ids'])){
|
|
|
- $ids = [];
|
|
|
- if (isset($request['category_ids'])) {
|
|
|
- $categoryIds = explode('_', $request['category_ids']);
|
|
|
- $ids = $this->categoryTopic->whereIn('category_id', $categoryIds)->pluck('topic_id')->toArray();
|
|
|
- }
|
|
|
- if (isset($request['topic_ids'])) {
|
|
|
- $ids = array_merge($ids, explode('_', $request['topic_ids']));
|
|
|
- }
|
|
|
- foreach ($ids as $key=>$id) {
|
|
|
- if ($key==0) {
|
|
|
- $query = $query->whereRaw('FIND_IN_SET('.$id.',topic_ids)');
|
|
|
- } else {
|
|
|
- $query = $query->orWhereRaw('FIND_IN_SET('.$id.',topic_ids)');
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
->orderBy('weight','desc')
|
|
|
->paginate($perPage);
|
|
|
}
|