wesmiler 6 bulan lalu
induk
melakukan
4e2fd066ea

+ 1 - 1
app/Http/Controllers/Api/v1/ArticleController.php

@@ -6,7 +6,7 @@ use App\Http\Controllers\Api\webApp;
 use App\Services\Api\ArticleService;
 
 /**
- * 文章管理
+ * 文章管理
  * Class ArticleController
  * @package App\Http\Controllers\Api
  */

+ 33 - 0
app/Http/Controllers/Api/v1/NoticeController.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Http\Controllers\Api\webApp;
+use App\Services\Api\ArticleService;
+use App\Services\Api\NoticeService;
+
+/**
+ * 公告管理
+ * @package App\Http\Controllers\Api
+ */
+class NoticeController extends webApp
+{
+
+    /**
+     * 详情
+     */
+    public function info()
+    {
+        $params = request()->all();
+        $id = isset($params['id'])? intval($params['id']) : 0;
+        if(empty($id)){
+            return message(1036, false);
+        }
+
+        if($info = NoticeService::make()->getInfo($id)){
+            return message(1010, true, $info);
+        }else{
+            return message(1009, false);
+        }
+    }
+}

+ 26 - 0
app/Services/Api/NoticeService.php

@@ -73,4 +73,30 @@ class NoticeService extends BaseService
 
         return $datas;
     }
+
+    /**
+     * 获取详情
+     * @param $id
+     * @return array|mixed
+     */
+    public function getInfo($id)
+    {
+        $cacheKey = "caches:notices:info_{$id}";
+        $info = RedisService::get($cacheKey);
+        if($info){
+            return $info;
+        }
+
+        $info = $this->model->where(['id'=> $id,'status'=>1,'mark'=>1])
+            ->select(['id','title','author','content','create_time','type'])
+            ->first();
+        $info = $info? $info->toArray() : [];
+        if($info){
+            $info['create_time'] = $info['create_time']? datetime($info['create_time'],'Y-m-d') : '';
+            $info['content'] = get_format_content($info['content']);
+            RedisService::set($cacheKey, $info, rand(5,10));
+        }
+
+        return $info;
+    }
 }

+ 2 - 0
routes/api.php

@@ -41,6 +41,8 @@ Route::prefix('v1')->group(function() {
     Route::get('/article/info', [\App\Http\Controllers\Api\v1\ArticleController::class, 'info']);
     Route::get('/article/page', [\App\Http\Controllers\Api\v1\ArticleController::class, 'page']);
 
+    Route::get('/notice/info', [\App\Http\Controllers\Api\v1\ArticleController::class, 'page']);
+
 });