From c60a8ed350f3e63c73fd0a44259647fe18a9d454 Mon Sep 17 00:00:00 2001 From: zwesy Date: Thu, 3 Dec 2020 16:06:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9A=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/Index.php | 18 +++++++++++++----- app/model/Base.php | 10 ++++++++-- view/index/index.html | 31 +++++++++++-------------------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/app/controller/Index.php b/app/controller/Index.php index 85c7965..77c4e57 100644 --- a/app/controller/Index.php +++ b/app/controller/Index.php @@ -19,11 +19,19 @@ class Index extends Base // 网络营销栏目ID $this->data['marketingCId'] = Category::$CIdList['marketing']; // 关联产品中心 - $this->data['products'] = Article::getLatestByCategory(Category::$CIdList['products'], 4);; - // 关联企业新闻 - $this->data['newsEnterprises'] = Article::getLatestByCategory(Category::$CIdList['news_children']['enterprise'], 4); - // 关联行业资讯 - $this->data['newsIndustries'] = Article::getLatestByCategory(Category::$CIdList['news_children']['industry'], 4);; + $this->data['products'] = [ + 'category' => Category::getById(Category::$CIdList['products']), + 'items' => Article::getLatestByCategory(Category::$CIdList['products'], 4) + ]; + // 关联新闻 + $this->data['newsCenter'] = Category::getById(Category::$CIdList['news']); + $newsCIdList = [Category::$CIdList['news_children']['enterprise'], Category::$CIdList['news_children']['industry']]; + $newsList = Category::getListByIds($newsCIdList); + foreach ($newsList as &$cate) { + $cate['items'] = Article::getLatestByCategory($cate['id'], 4); + } + unset($cate); + $this->data['newsList'] = $newsList; return $this->view(); } } \ No newline at end of file diff --git a/app/model/Base.php b/app/model/Base.php index 210b1f7..e35ba66 100644 --- a/app/model/Base.php +++ b/app/model/Base.php @@ -7,12 +7,18 @@ class Base extends Model { protected $autoWriteTimestamp = false; //根据Id列表获取列表 - public static function getListByIds($ids) + public static function getListByIds($ids, $order = []) { if(count($ids) == 0 || empty($ids)) { return []; } - return self::where('id', 'in', $ids)->select()->toArray(); + if(empty($order)) { + $order = ['id'=>'asc']; + } + return self::where('id', 'in', $ids) + ->order($order) + ->select() + ->toArray(); } //根据ID获取单条数据 public static function getById($id) diff --git a/view/index/index.html b/view/index/index.html index 393a103..09b5d6c 100644 --- a/view/index/index.html +++ b/view/index/index.html @@ -22,11 +22,11 @@
-
产品中心

product center

+
{$products['category']['title'] ?? '产品中心'}

{$products['category']['description'] ?? 'product center'}

- {if isset($products) && count($products) > 0} + {if isset($products) && count($products['items']) > 0}