afa 6 月之前
父節點
當前提交
f6c71c0472
共有 2 個文件被更改,包括 14 次插入4 次删除
  1. 6 4
      application/api/controller/Announcement.php
  2. 8 0
      application/common/model/AnnouncementType.php

+ 6 - 4
application/api/controller/Announcement.php

@@ -4,6 +4,7 @@ namespace app\api\controller;
 
 use app\common\controller\Api;
 use app\common\model\AnnouncementModel;
+use app\common\model\AnnouncementType;
 
 class Announcement extends Api
 {
@@ -25,15 +26,16 @@ class Announcement extends Api
     }
 
     //列表
-    public function list(AnnouncementModel $announcementModel)
+    public function list(AnnouncementModel $announcementModel, AnnouncementType $announcementType)
     {
         $typeId = $this->request->param('type_id', 1, 'intval');
         $paginator = $announcementModel->where('type_id', $typeId)
             ->where('status', 1)->where('to_lang', $this->lan)
-            ->field('id,to_lang,weigh,img_url,createtime,title as title,introduction,body')
-            ->order('weigh desc, id desc')
+            ->field('id,to_lang,weigh,img_url,createtime,title as title,introduction,body,is_top,sub_type_id')
+            ->order('is_top desc, weigh desc')
             ->paginate($this->pageSize);
-
+       
+        $paginator = $announcementType::getSubTypeById($paginator);  
         $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
     }
 

+ 8 - 0
application/common/model/AnnouncementType.php

@@ -28,7 +28,15 @@ class AnnouncementType extends Model
         'updatetime_text'
     ];
 
+    //获取子分类
+    public static function getSubTypeById(object $data){
 
+      foreach ($data as &$item) {
+           $item->sub_type_name = '';
+           if(!empty($item->sub_type_id)) $item->sub_type_name = self::whereIn('id', $item->sub_type_id)->column('id,title');
+      }
+      return $data;
+    }
 
 
     public function getCreatetimeTextAttr($value, $data)