xielin 5 роки тому
батько
коміт
12682fe053

+ 18 - 3
app/Http/Controllers/V1/CircleController.php

@@ -363,10 +363,25 @@ class CircleController extends Controller
         return $this->circleMessageRepository->messageAction($request);
     }
 
+
+    /**
+     * 删除提问
+     */
+    public function deleteMessage(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return jsonError($validator->errors()->first());
+        }
+        return $this->circleMessageRepository->deleteMessage($request->all());
+    }
+
     /**
-     * 删除内容
+     * 删除评论
      */
-    public function delete(Request $request)
+    public function deleteComment(Request $request)
     {
         $validator = Validator::make($request->all(), [
             'id' => 'required|integer',
@@ -374,7 +389,7 @@ class CircleController extends Controller
         if ($validator->fails()) {
             return jsonError($validator->errors()->first());
         }
-        return $this->postRepositories->delete($request->all());
+        return  $this->circleMessageRepository->commentDelete($request->all());
     }
 
 }

+ 92 - 9
app/Repositories/Circle/CircleMessageRepository.php

@@ -25,6 +25,7 @@ use Illuminate\Support\Carbon;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Redis;
+use Illuminate\Support\Str;
 
 class CircleMessageRepository
 {
@@ -117,7 +118,12 @@ class CircleMessageRepository
         if ($imgs) {
             $allImg = $imgs;
             foreach ($allImg as &$img) {
-                $img = $img . '&x-oss-process=image/resize,p_50/quality,Q_50';
+                if(Str::contains($img,'?')){
+                    $img = $img . '&x-oss-process=image/resize,p_50/quality,Q_50';
+                }else{
+                    $img = $img . '?x-oss-process=image/resize,p_50/quality,Q_50';
+                }
+
             }
             $detectionImageResult = $this->detectionService->checkImg($allImg);
             if ($detectionImageResult['code'] < 0) {
@@ -309,10 +315,10 @@ class CircleMessageRepository
     public function messageAction($request)
     {
         $userInfo = $this->getUserInfo();
-        $userInfo['sns_status']=1;
-        $userInfo['uid']=268;
-        $userInfo['username']='测试用户';
-        $userInfo['avatar']='';
+        $userInfo['sns_status'] = 1;
+        $userInfo['uid'] = 268;
+        $userInfo['username'] = '测试用户';
+        $userInfo['avatar'] = '';
         if (empty($userInfo)) {
             return jsonError('获取用户信息失败');
         }
@@ -327,10 +333,10 @@ class CircleMessageRepository
             $data['action'] = $request['action'];
 
             InterestCircleMessageRecord::insert($data);
-            if($request['action']==1){
-                InterestCircleMessage::where('id',$request['msg_id'])->increment('good');
-            }elseif($request['action']==-1){
-                InterestCircleMessage::where('id',$request['msg_id'])->increment('bad');
+            if ($request['action'] == 1) {
+                InterestCircleMessage::where('id', $request['msg_id'])->increment('good');
+            } elseif ($request['action'] == -1) {
+                InterestCircleMessage::where('id', $request['msg_id'])->increment('bad');
             }
 
             DB::commit();
@@ -341,4 +347,81 @@ class CircleMessageRepository
             return jsonError('操作失败,请重试');
         }
     }
+
+    /**
+     * 删除评论
+     */
+    public function commentDelete($request)
+    {
+        $userInfo = $this->getUserInfo();
+        if (empty($userInfo)) {
+            return jsonError('获取用户信息失败');
+        }
+        $comment = $this->interestCircleMessageComment->find($request['id']);
+        if (!$comment) {
+            return jsonError('获取评论信息失败');
+        }
+
+        if ($userInfo['uid'] != $comment->uid) {
+            return jsonError('只能删除自己的评论');
+        }
+
+        if ($comment->is_delete == 1) {
+            return jsonError('该评论已经删除');
+        }
+
+        DB::beginTransaction();
+        try {
+            $comment->is_delete = 1;
+            $comment->save();
+
+            DB::commit();
+            if (!$comment->parent_id) {
+                Redis::DEL('circle_message_new_comment_' . $comment->post_id);
+            } else {
+                Redis::DEL('circle_message_new_reply_' . $comment->id);
+            }
+            Redis::SADD('delete_circle_message_comment_ids', $comment->id);
+            return jsonSuccess('删除评论成功');
+
+        } catch (QueryException $exception) {
+            DB::rollBack();
+            Log::debug('删除评论:' . $request['id'] . $exception->getMessage());
+            return jsonError('删除评论失败');
+        }
+    }
+
+    /**
+     * 删除提问
+     */
+    public function deleteMessage($request)
+    {
+        //验证用户信息
+        $userInfo = $this->getUserInfo();
+        if (empty($userInfo)) {
+            return jsonError('获取用户信息失败');
+        }
+
+        $post = $this->interestCircleMessage->find($request['id']);
+        if (!$post) {
+            return jsonError('获取提问信息失败');
+        }
+        if ($post->uid != $userInfo['uid']) {
+            return jsonError('只能删除自己发布的提问');
+        }
+
+        DB::beginTransaction();
+        try {
+            $post->delete();
+            DB::commit();
+            Redis::SADD('delete_circle_message_ids', $request['id']);
+            Log::debug('删除提问失败:' . $request['id']);
+            return jsonSuccess('删除提问成功');
+
+        } catch (QueryException $exception) {
+            DB::rollBack();
+            Log::debug('删除提问失败:' . $request['id'] . $exception->getMessage());
+            return jsonError('删除提问失败,请重试');
+        }
+    }
 }

+ 4 - 0
routes/api.php

@@ -141,6 +141,10 @@ $api->version('v1', [
         $api->post('circle/comment', 'CircleController@comment');
         //提问顶踩
         $api->post('circle/message/action', 'CircleController@messageAction');
+        //删除提问
+        $api->delete('circle/message', 'CircleController@deleteMessage');
+        //删除评论
+        $api->delete('circle/comment', 'CircleController@deleteComment');
     });