|
@@ -8,6 +8,7 @@
|
|
|
*/
|
|
|
namespace App\Repositories\Post;
|
|
|
|
|
|
+use App\Models\CategoryTopic;
|
|
|
use App\Models\Post;
|
|
|
use App\Models\PostComment;
|
|
|
use App\Models\PostData;
|
|
@@ -30,6 +31,7 @@ class PostRepository
|
|
|
PostComment $postComment,
|
|
|
PostImgs $postImgs,
|
|
|
PostLog $postLog,
|
|
|
+ CategoryTopic $categoryTopic,
|
|
|
Topic $topic)
|
|
|
{
|
|
|
$this->post = $post;
|
|
@@ -37,6 +39,7 @@ class PostRepository
|
|
|
$this->postComment = $postComment;
|
|
|
$this->postImgs = $postImgs;
|
|
|
$this->postLog = $postLog;
|
|
|
+ $this->categoryTopic = $categoryTopic;
|
|
|
$this->topic = $topic;
|
|
|
}
|
|
|
|
|
@@ -131,23 +134,58 @@ class PostRepository
|
|
|
{
|
|
|
$perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
$where = [];
|
|
|
- if(isset($request['up_status'])){
|
|
|
- $where[] = ['up_status', $request['up_status']];
|
|
|
+ if(isset($request['content'])){
|
|
|
+ $where[] = ['content', 'like', "%{$request['content']}%"];
|
|
|
}
|
|
|
- if(isset($request['total_stock'])){
|
|
|
- $where[] = ['total_stock', $request['total_stock']];
|
|
|
+ if(isset($request['is_suggest'])){
|
|
|
+ $where[] = ['is_suggest', $request['is_suggest']];
|
|
|
}
|
|
|
- if(isset($request['category_id1'])){
|
|
|
- $where[] = ['category_id1', $request['category_id1']];
|
|
|
+ if(isset($request['type'])){
|
|
|
+ $where[] = ['type', $request['type']];
|
|
|
}
|
|
|
|
|
|
- return $this->post->where($where)
|
|
|
+ $sort = 'post.id';
|
|
|
+ if(isset($request['sort']) && in_array($request['sort'], ['praise_count', 'share_count', 'pv', 'comment_count'])){
|
|
|
+ $sort = $request['sort'];
|
|
|
+ }
|
|
|
+
|
|
|
+ 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('name', 'like', "%{$request['keyword']}%")
|
|
|
- ->orWhere('spu_code', 'like', "%{$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($sort,'desc')
|
|
|
->paginate($perPage);
|
|
|
}
|
|
|
|