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']['description'] ?? 'product center'}
企业新闻
- {if isset($newsEnterprises) && count($newsEnterprises) > 0} - {foreach $newsEnterprises as $news} +{$newsCate.title ?? ''}
+ {if isset($newsCate['items']) && count($newsCate['items']) > 0} + {foreach $newsCate['items'] as $news}行业资讯
- {if isset($newsIndustries) && count($newsIndustries) > 0} - {foreach $newsIndustries as $news} -