增加banner后台管控

This commit is contained in:
2025-05-16 16:18:12 +08:00
parent 9df71d0faf
commit 92b79bf0b1
13 changed files with 1145 additions and 331 deletions
+31 -7
View File
@@ -16,6 +16,14 @@ class Index extends Base
*/
public function index()
{
// 获取banner列表
$bannerList = Db::name('yz_banner')
->where('delete_time', null)
->order('sort DESC, id DESC')
->select()
->toArray();
View::assign('bannerList', $bannerList);
return View::fetch();
}
@@ -30,17 +38,17 @@ class Index extends Base
->where('delete_time', null)
->select()
->toArray();
$articles = [];
$categoryData = [];
// 提取分类名称和ID用于前端tab显示
foreach ($categories as $category) {
$categoryData[] = [
'id' => $category['id'],
'name' => $category['name']
];
// 获取该分类下的文章,限制4条
$articles = Db::name('yz_article')
->where('cate', $category['id'])
@@ -51,12 +59,12 @@ class Index extends Base
->limit(4)
->select()
->toArray();
}
return json([
'code' => 1,
'msg' => '获取成功',
'code' => 1,
'msg' => '获取成功',
'articles' => $articles,
'categories' => $categoryData
]);
@@ -115,4 +123,20 @@ class Index extends Base
'categories' => $categoryData
]);
}
/**
* 获取banner列表
*/
public function bannerlist()
{
// 获取启用状态的banner列表,按排序倒序
$bannerList = Db::name('yz_banner')
->where('delete_time', null)
->order('sort DESC, id DESC')
->select()
->toArray();
return json(['code' => 1, 'msg' => '获取成功', 'banner' => $bannerList]);
}
}