Browse Source

新增删除推荐话题

zhangchangchun 5 years ago
parent
commit
d59f57a1cc

+ 11 - 0
app/Http/Controllers/V2/TopicGroupController.php

@@ -85,5 +85,16 @@ class TopicGroupController extends Controller {
         $info = $this->topicGroupRepository->view($data);
         return $this->response->item($info, new DetailTopicGroupTransformer());
     }
+    //删除
+    public function delete(Request $request){
+        $data = $request->only('id','status');
+        $validator = Validator::make($data, [
+            'id' => 'required|integer|max:12',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->topicGroupRepository->delete($data);
+    }
 
 }

+ 22 - 0
app/Repositories/TopicGroupRepository.php

@@ -120,4 +120,26 @@ class TopicGroupRepository {
     public function view($request){
        return $this->topicGroup->where(['id'=>$request['id']])->first();
     }
+    //删除
+    public function delete($request){
+        $topicGroup = $this->topicGroup->where(['id'=>$request['id']])->first();
+        DB::beginTransaction();
+        try{
+            if($topicGroup){
+                $res = $this->topicGroup->where(['id'=>$request['id']])->delete();
+                if($res){
+                    $this->topicGroupInfo->where(['topic_group_id'=>$topicGroup->id])->delete();
+                }
+            }
+        }catch (QueryException $exception){
+            DB::rollBack();
+            Log::debug('删除推荐话题组:'.$exception->getMessage());
+            return Response::create([
+                'message'  => '删除推荐话题组失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code'   => 500
+            ]);
+        }
+
+    }
 }

+ 2 - 0
routes/api.php

@@ -122,6 +122,8 @@ $api->version('v1', [
             $api->put('TopicGroupEdit', 'TopicGroupController@edit');
             //详情
             $api->get('TopicGroupView', 'TopicGroupController@view');
+            //删除
+            $api->delete('TopicGroupDelete', 'TopicGroupController@delete');
         });
 
     });