|
@@ -54,7 +54,10 @@ class PostRepository
|
|
$topicIds = $this->topic->whereIn('id', explode(',', $request['topic_ids']))->pluck('id')->toArray();
|
|
$topicIds = $this->topic->whereIn('id', explode(',', $request['topic_ids']))->pluck('id')->toArray();
|
|
$topicCount = count($topicIds);
|
|
$topicCount = count($topicIds);
|
|
if($topicCount == 0 || $topicCount >= 5){
|
|
if($topicCount == 0 || $topicCount >= 5){
|
|
- throw new HttpException(500, '所选话题必须1-5个');
|
|
|
|
|
|
+ return Response::create([
|
|
|
|
+ 'message' => '所选话题必须1-5个',
|
|
|
|
+ 'status_code' => 500
|
|
|
|
+ ]);
|
|
}
|
|
}
|
|
$topicIds = implode(',', $topicIds);
|
|
$topicIds = implode(',', $topicIds);
|
|
|
|
|
|
@@ -189,4 +192,109 @@ class PostRepository
|
|
->paginate($perPage);
|
|
->paginate($perPage);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 推荐内容
|
|
|
|
+ */
|
|
|
|
+ public function suggest($request)
|
|
|
|
+ {
|
|
|
|
+ $post = $this->post->where('id', $request['id'])->first();
|
|
|
|
+ if(!$post){
|
|
|
|
+ return Response::create([
|
|
|
|
+ 'message' => '获取内容信息失败',
|
|
|
|
+ 'status_code' => 500
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if($post->is_suggest == 1){
|
|
|
|
+ $post->is_suggest = 0;
|
|
|
|
+ }else{
|
|
|
|
+ $post->is_suggest = 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+ try{
|
|
|
|
+ $post->save();
|
|
|
|
+
|
|
|
|
+ DB::commit();
|
|
|
|
+ return Response::create();
|
|
|
|
+
|
|
|
|
+ }catch (QueryException $exception){
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ Log::debug('推荐内容:'.$request['id'].$exception->getMessage());
|
|
|
|
+ return Response::create([
|
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
|
+ 'status_code' => 500
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除内容
|
|
|
|
+ */
|
|
|
|
+ public function delete($request)
|
|
|
|
+ {
|
|
|
|
+ $post = $this->post->where('id', $request['id'])->first();
|
|
|
|
+ if(!$post){
|
|
|
|
+ return Response::create([
|
|
|
|
+ 'message' => '获取内容信息失败',
|
|
|
|
+ 'status_code' => 500
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+ try{
|
|
|
|
+ $post->delete();
|
|
|
|
+
|
|
|
|
+ DB::commit();
|
|
|
|
+ return Response::create();
|
|
|
|
+
|
|
|
|
+ }catch (QueryException $exception){
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ Log::debug('删除内容:'.$request['id'].$exception->getMessage());
|
|
|
|
+ return Response::create([
|
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
|
+ 'status_code' => 500
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 隐藏内容
|
|
|
|
+ */
|
|
|
|
+ public function hide($request)
|
|
|
|
+ {
|
|
|
|
+ $post = $this->post->where('id', $request['id'])->first();
|
|
|
|
+ if(!$post){
|
|
|
|
+ return Response::create([
|
|
|
|
+ 'message' => '获取内容信息失败',
|
|
|
|
+ 'status_code' => 500
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if($post->is_hide == 1){
|
|
|
|
+ $post->is_hide = 0;
|
|
|
|
+ }else{
|
|
|
|
+ $post->is_hide = 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+ try{
|
|
|
|
+ $post->save();
|
|
|
|
+
|
|
|
|
+ DB::commit();
|
|
|
|
+ return Response::create();
|
|
|
|
+
|
|
|
|
+ }catch (QueryException $exception){
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ Log::debug('隐藏内容:'.$request['id'].$exception->getMessage());
|
|
|
|
+ return Response::create([
|
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
|
+ 'status_code' => 500
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|