WIN-2308041133\Administrator 5 mesiacov pred
rodič
commit
ec6fdd5b9e

+ 12 - 2
app/api/controller/publics/ArticleCategoryController.php

@@ -2,6 +2,8 @@
 namespace app\api\controller\publics;
 
 use app\models\article\ArticleCategory;
+use app\Request;
+use crmeb\services\UtilService;
 
 /**
  * 文章分类类
@@ -17,9 +19,17 @@ class ArticleCategoryController
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\exception\DbException
      */
-   public function lst()
+   public function lst(Request $request)
    {
-       $cateInfo = ArticleCategory::getArticleCategory();
+       list($id) = UtilService::postMore([
+           ['id',0],//分类父id编号
+       ], $request, true);
+       if ($id>0){
+           $cateInfo = ArticleCategory::getIdArticleCategoryWithChildren($id);
+       }else{
+           $cateInfo = ArticleCategory::getArticleCategory();
+       }
+
        if($cateInfo) $cateInfo = $cateInfo->toArray();
        else $cateInfo = [];
        array_unshift($cateInfo,['id'=>0,'title'=>'热门']);

+ 16 - 0
app/models/article/ArticleCategory.php

@@ -38,6 +38,22 @@ class ArticleCategory extends BaseModel
     {
         return self::where('hidden', 0)->where('is_del', 0)->where('status', 1)->where('pid', 0)->order('sort DESC')->field('id,title')->select();
     }
+    public static function getIdArticleCategoryWithChildren($pid = 0)
+    {
+        $categories = self::where('hidden', 0)
+            ->where('is_del', 0)
+            ->where('status', 1)
+            ->where('pid', $pid)
+            ->order('sort DESC')
+            ->field('id,title,pid')
+            ->select();
+
+        foreach ($categories as &$category) {
+            $category['children'] = self::getIdArticleCategoryWithChildren($category['id']);
+        }
+
+        return $categories;
+    }
 
     /**
      * TODO  获取分类字段