From b9422f9ee82ac50cfea0d530fea886699007c5d2 Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Fri, 18 Apr 2025 17:07:56 +0800 Subject: [PATCH] refactor: Index --- app/index/controller/Index.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index 252988d8..ab7610d2 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -44,7 +44,9 @@ class Index extends Common // 获取banner数据 private function getBannerData() { - $banners = SysBannerModel::with(['items']) + $banners = SysBannerModel::with(['items' => function($query) { + $query->where('type', '=', 'image')->where('status', '=', 1)->order(['sort' => 'asc', 'id' => 'desc']); + }]) ->uniqueLabel([ 'BANNER_67f61cd70e8e1', 'BANNER_67f633023a5b3', @@ -72,14 +74,14 @@ class Index extends Common $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(); + $data['focus_images'] = data_get($banner_map, 'BANNER_67f61cd70e8e1')?->items->toArray(); + $data['product_categorys'] = data_get($banner_map, 'BANNER_67f633023a5b3')?->items->toArray(); + $data['product_categorys'] = data_get($banner_map, 'BANNER_67f633023a5b3')?->items->toArray(); + $data['featured_topics'] = data_get($banner_map, 'BANNER_67f63f8ab5029')?->items->toArray(); + $data['video'] = data_get($banner_map, 'BANNER_67f724ed81b1e')?->items->toArray(); + $data['scenes'] = data_get($banner_map, 'BANNER_67f7392b4d83a')?->items->toArray(); + $data['brand_story'] = data_get($banner_map, 'BANNER_67f7410e244fb')?->items->toArray(); + $data['data_statistics'] = data_get($banner_map, 'BANNER_67f76a96545f9')?->items->toArray(); } return $data;