|
@@ -1060,5 +1060,69 @@ class PostRepository
|
|
|
return $info;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 编辑内容话题
|
|
|
+ */
|
|
|
+ public function updateTopic($request)
|
|
|
+ {
|
|
|
+ $token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
+ if($token['type'] != 1){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '只有运营才能删除内容',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ $post = $this->post->where('id', $request['id'])->first();
|
|
|
+ if (!$post) {
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '获取内容信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //验证话题
|
|
|
+ $topicIdsArray = $this->topic->whereIn('id', explode(',', $request['topic_ids']))->pluck('id')->toArray();
|
|
|
+ $topicCount = count($topicIdsArray);
|
|
|
+ if ($topicCount == 0 || $topicCount > 5) {
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '所选话题必须1-5个',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ $topicIds = implode(',', $topicIdsArray);
|
|
|
+
|
|
|
+ $logData = [
|
|
|
+ 'uid' => $token['user']->id,
|
|
|
+ 'operator_type' => 'admin',
|
|
|
+ 'post_id' => $request['id'],
|
|
|
+ 'username' => $token['user']->username,
|
|
|
+ 'log_type' => 'update_topic',
|
|
|
+ 'content' => json_encode(['update_topic' => $request['id']]),
|
|
|
+ ];
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ $post->topic_ids = $topicIds;
|
|
|
+ $post->save();
|
|
|
+
|
|
|
+ $this->postLog->create($logData);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+
|
|
|
+ Redis::HSET('post_info_'.$request['id'], 'topic_ids', $topicIds);
|
|
|
+
|
|
|
+ return Response::create();
|
|
|
+
|
|
|
+ } catch (QueryException $exception) {
|
|
|
+ DB::rollBack();
|
|
|
+ Log::debug('编辑内容话题:'.$post->id . $exception->getMessage());
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '编辑失败,请重试',
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|