|
@@ -10,6 +10,7 @@ namespace App\Repositories;
|
|
|
|
|
|
|
|
|
|
use App\Models\Behavior;
|
|
use App\Models\Behavior;
|
|
|
|
+use App\Models\Post;
|
|
use App\Models\PostCollect;
|
|
use App\Models\PostCollect;
|
|
use App\Models\PostData;
|
|
use App\Models\PostData;
|
|
use App\Models\PostLike;
|
|
use App\Models\PostLike;
|
|
@@ -18,8 +19,75 @@ use Illuminate\Support\Facades\Redis;
|
|
|
|
|
|
class PostRepositories
|
|
class PostRepositories
|
|
{
|
|
{
|
|
- public function __construct()
|
|
|
|
|
|
+ public function __construct(Post $post)
|
|
{
|
|
{
|
|
|
|
+ $this->post = $post;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 推荐内容列表
|
|
|
|
+ */
|
|
|
|
+ public function suggestPost($request)
|
|
|
|
+ {
|
|
|
|
+ $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
|
+ $where = [];
|
|
|
|
+ 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']];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $sort = 'post.id';
|
|
|
|
+ if(isset($request['sort']) && in_array($request['sort'], ['praise_count', 'share_count', 'pv', 'comment_count', 'create_bean'])){
|
|
|
|
+ $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('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);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|