diff --git a/plugs/think-plugs-cms/src/controller/api/Tutorial.php b/plugs/think-plugs-cms/src/controller/api/Tutorial.php index 9b9f7b0..b4dbb1f 100644 --- a/plugs/think-plugs-cms/src/controller/api/Tutorial.php +++ b/plugs/think-plugs-cms/src/controller/api/Tutorial.php @@ -8,7 +8,13 @@ use think\admin\Controller; class Tutorial extends Controller { public function index() { + $categoryId = $this->request->get('cid'); $query = CmsTutorial::mk()->where('status', 1); + if ($categoryId > 0) { + $query->hasWhere('cateids', function ($subQuery) use ($categoryId) { + $subQuery->where('cid', $categoryId); + }); + } $articles = $query->order('sort asc,create_at desc')->paginate(); $this->success('获取文章列表', $articles); } diff --git a/plugs/think-plugs-cms/src/model/CmsTutorial.php b/plugs/think-plugs-cms/src/model/CmsTutorial.php index 6c63fa2..4ecdb9d 100644 --- a/plugs/think-plugs-cms/src/model/CmsTutorial.php +++ b/plugs/think-plugs-cms/src/model/CmsTutorial.php @@ -14,6 +14,10 @@ class CmsTutorial extends Model return $this->belongsToMany(CmsCategory::class, CmsTutorialCategory::class, 'cid', 'tid'); } + public function cateids() + { + return $this->hasMany(CmsTutorialCategory::class, 'tid'); + } /** * 获取分类ID列表 */