xiaogang 3 vuotta sitten
vanhempi
commit
6a49ccf20a

+ 12 - 0
app/Http/Controllers/Api/DynamicController.php

xqd
@@ -39,6 +39,18 @@ class DynamicController extends Controller
         return response()->json($data);
     }
 
+    /**
+     * 删除话题
+     */
+    public function del_tag(Request $request){
+        try {
+            $this->dynamicService->del_tag($request->id);
+        }catch (\Exception $exception){
+            return $this->response->errorForbidden($exception->getMessage());
+        }
+        return response()->json(['message'=>"删除成功"]);
+    }
+
 
     /**
      * 发布动态

+ 23 - 2
app/Services/DynamicService.php

xqd xqd xqd xqd
@@ -9,6 +9,7 @@ use App\Http\Params\DynamicParam;
 use App\Http\Params\DynamicZanParam;
 use App\Http\Params\UserReportParam;
 use App\Models\DynamicModel;
+use App\Models\DynamicTag;
 use App\Models\DynamicZanModel;
 use App\Models\User;
 use App\Models\UserBlacklistModel;
@@ -26,7 +27,7 @@ class DynamicService
         if(!empty($keyword)){
             $query = $query->where("title","like","%{$keyword}%");
         }
-        $query =  $query->where("type",$type)
+        $query =  $query->where(["type"=>$type,'is_delete'=>0])
             ->orderBy("hot","desc")
             ->limit(20)
             ->get();
@@ -39,6 +40,25 @@ class DynamicService
         return $query;
     }
 
+
+    //删除话题
+    public function del_tag($id){
+        $user = auth('api')->user();
+        if(empty($id)){
+            throw new Exception('参数错误');
+        }
+        $tag = DynamicTag::query()->where(['id'=>$id])->first();
+        if(!$tag){
+            throw new Exception('话题不存在');
+        }
+        if($tag->user_id!=$user->id){
+            throw new Exception('只能删除自己的话题');
+        }
+        $tag->delete = 1;
+        $tag->save();
+        return true;
+    }
+
     /**
      * 发布动态
      */
@@ -79,7 +99,8 @@ class DynamicService
                             $id = DB::table('dynamic_tag')->insertGetId([
                                 "title"=>htmlspecialchars($v['title']),
                                 "hot"=>1,
-                                "type"=>1
+                                "type"=>1,
+                                "user_id"=>$user->id,
                             ]);
                         }
                     }else{

+ 1 - 0
routes/api.php

xqd
@@ -133,6 +133,7 @@ $api->version('v1', [
         */
         $api->group(['prefix' => 'dynamic'], function ($api) {
             $api->post('/release', 'DynamicController@release')->name('dynamic.release');
+            $api->post('/del_tag', 'DynamicController@del_tag')->name('dynamic.del_tag');
             $api->post('/my_list', 'DynamicController@my_list')->name('dynamic.my_list');
             $api->post('/zan', 'DynamicController@zan')->name('dynamic.zan');
             $api->post('/del', 'DynamicController@del')->name('dynamic.del');