feat: index - 首页及顶部导航处理
This commit is contained in:
@@ -3,10 +3,147 @@ declare (strict_types = 1);
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
class Index
|
||||
use app\index\model\ArticleModel;
|
||||
use app\index\model\FaqModel;
|
||||
use app\index\model\ProductModel;
|
||||
use app\index\model\SysBannerModel;
|
||||
use think\facade\View;
|
||||
|
||||
/**
|
||||
* 首页控制器
|
||||
*/
|
||||
class Index extends Common
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return '您好!这是一个[' . lang('home') . ']示例应用';
|
||||
// 获取banner数据
|
||||
$banner = $this->getBannerData();
|
||||
View::assign('focus_images', $banner['focus_images']);
|
||||
View::assign('product_categorys', $banner['product_categorys']);
|
||||
View::assign('featured_topics', $banner['featured_topics']);
|
||||
View::assign('video', array_shift($banner['video']));
|
||||
View::assign('scenes', $banner['scenes']);
|
||||
View::assign('brand_story', $banner['brand_story']);
|
||||
View::assign('data_statistics', $banner['data_statistics']);
|
||||
|
||||
// 获取明星产品/热点产品
|
||||
View::assign('featured_products', $this->getFeaturedProducts());
|
||||
|
||||
// 获取推荐文章
|
||||
View::assign('recommend_articles', $this->getRecommendArticles());
|
||||
|
||||
// 获取常见问题
|
||||
View::assign('recommend_faq', $this->getRecommendFAQ());
|
||||
|
||||
return View::fetch('index');
|
||||
}
|
||||
|
||||
// 获取banner数据
|
||||
private function getBannerData()
|
||||
{
|
||||
$banners = SysBannerModel::with(['items'])
|
||||
->uniqueLabel([
|
||||
'BANNER_67f61cd70e8e1',
|
||||
'BANNER_67f633023a5b3',
|
||||
'BANNER_67f63f8ab5029',
|
||||
'BANNER_67f724ed81b1e',
|
||||
'BANNER_67f7392b4d83a',
|
||||
'BANNER_67f7410e244fb',
|
||||
'BANNER_67f76a96545f9',
|
||||
])
|
||||
->language($this->lang_id)
|
||||
->recommend(true)
|
||||
->enabled(true)
|
||||
->select();
|
||||
$banner_map = [];
|
||||
foreach ($banners as $v) {
|
||||
$banner_map[$v->unique_label] = $v;
|
||||
}
|
||||
|
||||
// 处理焦点轮播图和产品分类
|
||||
$data['focus_images'] = []; // 焦点轮播图
|
||||
$data['product_categorys'] = []; // 产品分类信息
|
||||
$data['featured_topics'] = []; // 特色专题及公司实力
|
||||
$data['video'] = []; // 视频
|
||||
$data['scenes'] = []; // 场景介绍
|
||||
$data['brand_story'] = []; // 品牌故事
|
||||
$data['data_statistics'] = []; // 数据统计
|
||||
if (!empty($banner_map)) {
|
||||
$data['focus_images'] = $banner_map['BANNER_67f61cd70e8e1']->items->where('type', '=', 'image')->where('status', '=', 1)->order('sort', 'asc')->toArray();
|
||||
$data['product_categorys'] = $banner_map['BANNER_67f633023a5b3']->items->where('type', '=', 'image')->where('status', '=', 1)->order('sort', 'asc')->toArray();
|
||||
$data['product_categorys'] = $banner_map['BANNER_67f633023a5b3']->items->where('type', '=', 'image')->where('status', '=', 1)->order('sort', 'asc')->toArray();
|
||||
$data['featured_topics'] = $banner_map['BANNER_67f63f8ab5029']->items->where('type', '=', 'image')->where('status', '=', 1)->order('sort', 'asc')->toArray();
|
||||
$data['video'] = $banner_map['BANNER_67f724ed81b1e']->items->where('type', '=', 'video')->where('status', '=', 1)->order('sort', 'asc')->toArray();
|
||||
$data['scenes'] = $banner_map['BANNER_67f7392b4d83a']->items->where('type', '=', 'image')->where('status', '=', 1)->order('sort', 'asc')->toArray();
|
||||
$data['brand_story'] = $banner_map['BANNER_67f7410e244fb']->items->where('type', '=', 'image')->where('status', '=', 1)->order('sort', 'asc')->toArray();
|
||||
$data['data_statistics'] = $banner_map['BANNER_67f76a96545f9']->items->where('type', '=', 'image')->where('status', '=', 1)->order('sort', 'asc')->toArray();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// 获取明星/热点产品
|
||||
private function getFeaturedProducts()
|
||||
{
|
||||
$products = ProductModel::field([
|
||||
'id',
|
||||
'name',
|
||||
'short_name',
|
||||
'cover_image',
|
||||
])
|
||||
->language($this->lang_id)
|
||||
->enabled(true)
|
||||
->onSale(true)
|
||||
->onShelves(true)
|
||||
->hot(true)
|
||||
->order(['sort' => 'asc', 'id' => 'desc'])
|
||||
->select();
|
||||
if ($products->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $products->toArray();
|
||||
}
|
||||
|
||||
// 获取推荐文章
|
||||
private function getRecommendArticles()
|
||||
{
|
||||
$articles = ArticleModel::field([
|
||||
'id',
|
||||
'title',
|
||||
'desc',
|
||||
'image'
|
||||
])
|
||||
->language($this->lang_id)
|
||||
->enabled(true)
|
||||
->recommend(true)
|
||||
->order(['sort' => 'asc', 'id' => 'desc'])
|
||||
->limit(6)
|
||||
->select();
|
||||
if ($articles->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $articles->toArray();
|
||||
}
|
||||
|
||||
// 获取推荐问题
|
||||
private function getRecommendFAQ()
|
||||
{
|
||||
$faqs = FaqModel::field([
|
||||
'id',
|
||||
'question',
|
||||
'image',
|
||||
'answer'
|
||||
])
|
||||
->language($this->lang_id)
|
||||
->recommend(true)
|
||||
->order(['sort' => 'asc', 'id' => 'desc'])
|
||||
->limit(6)
|
||||
->select();
|
||||
if ($faqs->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
return $faqs->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user