Przeglądaj źródła

wesmiler 报恩寺项目提交

wesmiler 4 lat temu
rodzic
commit
466521b7cc
1 zmienionych plików z 9 dodań i 2 usunięć
  1. 9 2
      app/Http/Controllers/Api/v1/IndexController.php

+ 9 - 2
app/Http/Controllers/Api/v1/IndexController.php

@@ -170,6 +170,12 @@ class IndexController extends BaseController
     public function calendar(){
         $apiUrl = env('FOLI_API');
         $type = request()->get('type', 0);
+        $cacheKey = "caches:calendar:".date('YmdH')."_{$type}";
+        $data = RedisService::get($cacheKey);
+        if($data){
+            return message(MESSAGE_OK, true, $data);
+        }
+
         if(empty($apiUrl)){
             return message('获取失败', false);
         }
@@ -193,8 +199,9 @@ class IndexController extends BaseController
         $ji = isset($ji[1])? $ji[1] : '';
         preg_match("/<td class=\"\">(.*)<\/td>\\n<td class=\"w_bg1\">/", $temp1, $yl);
         $yl = isset($yl[1])? $yl[1] : '';
-
-        return message(MESSAGE_OK, true, ['content'=> $content, 'result'=> $temp,'hl'=> $temp1,'date'=> date('m月d日'),'yl'=> $yl,'yl_day'=> mb_substr($yl, -2, 2,'utf-8'),'yi'=> $yi,'ji'=> $ji]);
+        $data = ['content'=> $content, 'result'=> $temp,'hl'=> $temp1,'date'=> date('m月d日'),'yl'=> $yl,'yl_day'=> mb_substr($yl, -2, 2,'utf-8'),'yi'=> $yi,'ji'=> $ji];
+        RedisService::set($cacheKey, $data, 48 *3600);
+        return message(MESSAGE_OK, true, $data);
 
     }
 }