wzq пре 5 година
родитељ
комит
38326ad826

+ 7 - 0
app/Http/Controllers/Topic/TopicController.php

@@ -130,4 +130,11 @@ class TopicController extends Controller {
         }
         return  $this->topicRepository->getTopics($request['ids']);
     }
+
+    /**
+     * 重置话题redis
+     */
+    public function resetRedis(){
+        return  $this->topicRepository->resetRedis();
+    }
 }

+ 24 - 0
app/Repositories/TopicRepository.php

@@ -14,6 +14,8 @@ use App\Models\Topic;
 use Dingo\Api\Http\Response;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Database\QueryException;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
 
 class TopicRepository {
     public function __construct(Topic $topic,CategoryTopic $categoryTopic){
@@ -78,6 +80,7 @@ class TopicRepository {
                 }
             }
             DB::commit();
+            Redis::zadd('topic.name', $topicInfo->name, $topicInfo->id);
             return Response::create();
         }catch (QueryException $exception){
             DB::rollBack();
@@ -183,4 +186,25 @@ class TopicRepository {
     public function getTopics($ids = []){
         return $this->topic->whereIn('id', $ids)->select('id','name')->get();
     }
+
+    /**
+     * 重置话题redis
+     */
+    public function resetRedis()
+    {
+        $TopicName = $this->topic->pluck('id', 'name')->toArray();
+
+        $res = Redis::zadd('topic.name', $TopicName);
+        if($res){
+            return Response::create([
+                'message'  => '重置话题成功',
+                'status_code'   => 500
+            ]);
+        }else{
+            return Response::create([
+                'message'  => '重置话题失败',
+                'status_code'   => 500
+            ]);
+        }
+    }
 }

+ 2 - 0
routes/api.php

@@ -60,6 +60,8 @@ $api->version('v1', [
 
         });
         $api->group(['namespace' => 'Topic'], function ($api) {
+            //重置话题redis
+            $api->put('topic/resetRedis', 'TopicController@resetRedis');
             //新增话题分类
             $api->post('topic/categoryCreate', 'CategoryController@create');
             //话题分类列表