13283339616 6 anni fa
parent
commit
862f7ccd61

+ 9 - 1
app/Api/V1/Controllers/FeaturesController.php

@@ -11,6 +11,7 @@ use App\Models\Tag;
11 11
 use App\Models\UserMessage;
12 12
 use App\Models\Special;
13 13
 use App\Models\News;
14
+use App\Models\NewsCategory;
14 15
 use Illuminate\Http\Request;
15 16
 use Solr;
16 17
 use DB;
@@ -278,12 +279,19 @@ class FeaturesController extends BaseController
278 279
     public function articleList(Request $request){
279 280
         $page=$request->has('page')?$request->input('page'):1;
280 281
         $start=intval((intval($page)-1)*intval(20));
281
-        $data=News::where('status',1)->select('id','imgurl','title','createTime')->orderBy('createTime','desc')->offset($start)->limit(20)->get();
282
+        $type=NewsCategory::pluck('name','abbreviation');
283
+        $data=News::where('status',1)->select('id','imgurl','title','createTime','category','readNum')->orderBy('createTime','desc')->offset($start)->limit(20)->get();
284
+        $data=json_decode(json_encode($data),true);
285
+        foreach($data as $key=>$item){
286
+            $data[$key]['category']=$type[$item['category']];
287
+        }
282 288
         return $this->response->array(self::returnValue(['data' => $data], 200));
283 289
     }
284 290
     public function articleDetail(Request $request){
285 291
         $id=$request->input('id');
286 292
         $articleDetail=News::where('id',$id)->first();
293
+        $type=NewsCategory::pluck('name','abbreviation');
294
+        $articleDetail['category']=$type[$articleDetail['category']];
287 295
         $articleDetail['content'] = str_replace(array("\r\n", "\r", "\n"), "", $articleDetail['content']);
288 296
         return $this->response->array(self::returnValue(['data' => $articleDetail], 200));
289 297
     }

+ 11 - 0
app/Models/NewsCategory.php

@@ -0,0 +1,11 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class NewsCategory extends Model
8
+{
9
+    protected $table   = 'news_category';
10
+    public $timestamps = false;
11
+}