|
@@ -1164,7 +1164,7 @@ class PostRepository
|
|
$token = JWTAuth::decode(JWTAuth::getToken());
|
|
$token = JWTAuth::decode(JWTAuth::getToken());
|
|
if ($token['type'] != 1) {
|
|
if ($token['type'] != 1) {
|
|
return Response::create([
|
|
return Response::create([
|
|
- 'message' => '只有运营才能删除内容',
|
|
|
|
|
|
+ 'message' => '只有运营才能编辑内容话题',
|
|
'status_code' => 500
|
|
'status_code' => 500
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
@@ -1396,4 +1396,81 @@ class PostRepository
|
|
{
|
|
{
|
|
return $this->postStore->find($request['id']);
|
|
return $this->postStore->find($request['id']);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 内容列表(批量替换话题)
|
|
|
|
+ */
|
|
|
|
+ public function topicList($request)
|
|
|
|
+ {
|
|
|
|
+ $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
|
+
|
|
|
|
+ return $this->post
|
|
|
|
+ ->where(function ($query) use ($request) {
|
|
|
|
+ if (isset($request['topic_id']) && $request['topic_id']) {
|
|
|
|
+ $query->whereRaw('FIND_IN_SET(' . $request['topic_id'] . ',topic_ids)');
|
|
|
|
+ }else{
|
|
|
|
+ $query->where('id', 0);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ ->orderBy('id', 'desc')
|
|
|
|
+ ->paginate($perPage);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批量替换话题
|
|
|
|
+ */
|
|
|
|
+ public function TopicUpdate($request)
|
|
|
|
+ {
|
|
|
|
+ $token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
|
+ if ($token['type'] != 1) {
|
|
|
|
+ return Response::create([
|
|
|
|
+ 'message' => '只有运营才能替换内容话题',
|
|
|
|
+ 'status_code' => 500
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+ $uid = $token['user']->id;
|
|
|
|
+ $username = $token['user']->username;
|
|
|
|
+ $topicId = $request['topic_id'];
|
|
|
|
+ $toTopicId = $request['to_topic_id'];
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $this->post
|
|
|
|
+ ->whereIn('id',$request['ids'])
|
|
|
|
+ ->whereRaw('FIND_IN_SET(' . $topicId . ',topic_ids)')
|
|
|
|
+ ->chunk(100, function ($posts) use ($uid, $username, $topicId, $toTopicId) {
|
|
|
|
+ foreach($posts as $post){
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+ try {
|
|
|
|
+ $topicIds = explode(',', $post->topic_ids);
|
|
|
|
+ if(in_array($toTopicId, $topicIds)) continue;
|
|
|
|
+ foreach($topicIds as &$val){
|
|
|
|
+ if($val == $topicId) $val = $toTopicId;
|
|
|
|
+ }
|
|
|
|
+ $post->topic_ids = implode(',', $topicIds);
|
|
|
|
+ $post->save();
|
|
|
|
+ $this->postLog->create([
|
|
|
|
+ 'uid' => $uid,
|
|
|
|
+ 'operator_type' => 'admin',
|
|
|
|
+ 'post_id' => $post->id,
|
|
|
|
+ 'username' => $username,
|
|
|
|
+ 'log_type' => 'change_topic',
|
|
|
|
+ 'content' => json_encode(['change_topic' => "{$post->id}:{$topicId} => {$toTopicId}"]),
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Log::debug("post_id".$post->id);
|
|
|
|
+
|
|
|
|
+ DB::commit();
|
|
|
|
+ Redis::HSET('post_info_' . $post->id, 'topic_ids', $post->topic_ids);
|
|
|
|
+ Redis::zincrby('topic.just_use_count', 1, $toTopicId);
|
|
|
|
+
|
|
|
|
+ } catch (QueryException $exception) {
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ Log::debug('替换内容话题失败:' . $exception->getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Response::create();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|