xiaogang 4 лет назад
Родитель
Сommit
6cbff9be82
1 измененных файлов с 15 добавлено и 4 удалено
  1. 15 4
      app/Services/DynamicService.php

+ 15 - 4
app/Services/DynamicService.php

xqd
@@ -58,10 +58,21 @@ class DynamicService
 
             foreach ($tag as $v){
                 if($v['id']==0){
-                    $id = DB::table('dynamic_tag')->insertGetId([
-                        "title"=>htmlspecialchars($v['title']),
-                        "hot"=>1
-                    ]);
+                    if(!empty($v['title'])){
+                        if($tag = DB::table('dynamic_tag')->where('title',$v['title'])->first()){
+                            DB::table('dynamic_tag')->where(['id'=>$tag->id])->increment('hot',1);
+                            $id = $tag->id;
+                        }else{
+                            $id = DB::table('dynamic_tag')->insertGetId([
+                                "title"=>htmlspecialchars($v['title']),
+                                "hot"=>1
+                            ]);
+                        }
+                    }else{
+                        throw new Exception("请输入话题内容");
+                    }
+
+
                     $tag_ins.= $id.',';
                 }else{
                     DB::table('dynamic_tag')->where(['id'=>$v['id']])->increment('hot',1);