|
@@ -17,6 +17,7 @@ use App\Models\PostData;
|
|
|
use App\Models\PostDislike;
|
|
|
use App\Models\PostImgs;
|
|
|
use App\Models\PostLike;
|
|
|
+use App\Models\PostLog;
|
|
|
use App\Models\PostShare;
|
|
|
use App\Models\Topic;
|
|
|
use App\Service\AliYunVodService;
|
|
@@ -43,6 +44,7 @@ class PostRepositories
|
|
|
PostComment $postComment,
|
|
|
PostCollect $postCollect,
|
|
|
PostShare $postShare,
|
|
|
+ PostLog $postLog,
|
|
|
DetectionService $detectionService,
|
|
|
AliYunVodService $aliYunVodService,
|
|
|
Topic $topic)
|
|
@@ -53,6 +55,7 @@ class PostRepositories
|
|
|
$this->postComment = $postComment;
|
|
|
$this->postCollect = $postCollect;
|
|
|
$this->postShare = $postShare;
|
|
|
+ $this->postLog = $postLog;
|
|
|
$this->detectionService = $detectionService;
|
|
|
$this->topic = $topic;
|
|
|
$this->aliYunVodService = $aliYunVodService;
|
|
@@ -372,11 +375,11 @@ class PostRepositories
|
|
|
$post = $this->post;
|
|
|
$order = 'post.id';
|
|
|
}elseif($type == 'collect'){
|
|
|
- $post = $this->post->join('post_collect', 'post_collect.post_id', '=', 'post.id');
|
|
|
+ $post = $this->post->withTrashed()->join('post_collect', 'post_collect.post_id', '=', 'post.id');
|
|
|
$where[] = ['post_collect.uid', $uid];
|
|
|
$order = 'post_collect.id';
|
|
|
}else{
|
|
|
- $post = $this->post->join('post_share', 'post_share.post_id', '=', 'post.id');
|
|
|
+ $post = $this->post->withTrashed()->join('post_share', 'post_share.post_id', '=', 'post.id');
|
|
|
$where[] = ['post_share.uid', $uid];
|
|
|
$order = 'post_share.updated_at';
|
|
|
}
|
|
@@ -472,13 +475,13 @@ class PostRepositories
|
|
|
$perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
|
|
|
$where = [];
|
|
|
- if(isset($request['category_id'])){
|
|
|
+ if(isset($request['category_id']) && $request['category_id']){
|
|
|
$topic = $this->topic->join('category_topic', 'category_topic.topic_id', '=', 'topic.id')->select('topic.*');
|
|
|
$where[] = ['category_topic.category_id', $request['category_id']];
|
|
|
}else{
|
|
|
$topic = $this->topic;
|
|
|
}
|
|
|
- if(isset($request['is_suggest'])){
|
|
|
+ if(isset($request['is_suggest']) && $request['is_suggest']){
|
|
|
$where[] = ['topic.is_hot', $request['is_suggest']];
|
|
|
}
|
|
|
|
|
@@ -619,4 +622,48 @@ class PostRepositories
|
|
|
return jsonSuccess($data);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 删除内容
|
|
|
+ */
|
|
|
+ public function delete($request)
|
|
|
+ {
|
|
|
+ //验证用户信息
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+ if (empty($userInfo)) {
|
|
|
+ return jsonError('获取用户信息失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ $post = $this->post->find($request['id']);
|
|
|
+ if(!$post){
|
|
|
+ return jsonError('获取内容信息失败');
|
|
|
+ }
|
|
|
+ if($post->uid != $userInfo['uid']){
|
|
|
+ return jsonError('只能删除自己发布的内容');
|
|
|
+ }
|
|
|
+ $logData = [
|
|
|
+ 'uid' => $userInfo['uid'],
|
|
|
+ 'operator_type' => 'user',
|
|
|
+ 'post_id' => $request['id'],
|
|
|
+ 'username' => $userInfo['username'],
|
|
|
+ 'log_type' => 'delete',
|
|
|
+ 'content' => json_encode(['delete' => $request['id']]),
|
|
|
+ ];
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ $post->delete();
|
|
|
+
|
|
|
+ $this->postLog->create($logData);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ Log::debug('删除内容失败:'.$request['id']);
|
|
|
+ return jsonSuccess('删除内容成功');
|
|
|
+
|
|
|
+ }catch (QueryException $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ Log::debug('删除内容失败:'.$request['id'].$exception->getMessage());
|
|
|
+ return jsonError('删除内容失败,请重试');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|