diff --git a/app/index/controller/Common.php b/app/index/controller/Common.php index 703890c8..3a9faf46 100644 --- a/app/index/controller/Common.php +++ b/app/index/controller/Common.php @@ -38,10 +38,10 @@ abstract class Common extends BaseController } // 获取产品分类 - $categorys = $this->getProductCategory($this->lang_id); + $categorys = $this->getProductCategory($this->lang_id, true); // 输出产品分类 View::assign('header_categorys', $categorys); - +// dump($categorys);exit; // 获取热销产品 $hot_products = $this->getHotProducts($this->lang_id); // 输出热销产品 @@ -63,6 +63,15 @@ abstract class Common extends BaseController // 输出底部导航 View::assign('footer_navigation', $footer_navigation); } + private function handlerCategory($categorys) + { + foreach ($categorys as &$item) { + if ($item['children']) { + $item['children'] = $this->handlerCategory($item['children']); + } + } + return $categorys; + } // 获取当前语言 protected function getCurrentLanguage($languages) @@ -78,7 +87,7 @@ abstract class Common extends BaseController } // 获取产品分类 - protected function getProductCategory($language = 1) + protected function getProductCategory($language = 1, $with_recommends = false) { $categorys = ProductCategoryModel::field([ 'id', @@ -87,10 +96,17 @@ abstract class Common extends BaseController 'icon', 'level' ]) + ->when($with_recommends, function($query) { + $query->with(['recommends' => function($query) { + $query->field(['id', 'category_id', 'title', 'image', 'desc', 'link']) + ->order(['sort' => 'asc', 'id' => 'desc']); + }]); + }) ->language($language) ->displayed() ->order(['sort' => 'asc', 'id' => 'desc']) - ->select(); + ->select() + ->hidden(["recommends.category_id"]); if ($categorys->isEmpty()) { return []; } diff --git a/app/index/model/ProductCategoryModel.php b/app/index/model/ProductCategoryModel.php index a6ea7e5e..7846820a 100644 --- a/app/index/model/ProductCategoryModel.php +++ b/app/index/model/ProductCategoryModel.php @@ -17,6 +17,12 @@ class ProductCategoryModel extends ProductCategoryBaseModel // 软件删除时间字段 protected $deleteTime = 'deleted_at'; + // 关联产品推荐 + public function recommends() + { + return $this->hasMany(ProductCategoryRecommendModel::class, 'category_id', 'id'); + } + // 所属语言范围查询 public function scopeLanguage($query, $language) { diff --git a/app/index/model/ProductCategoryRecommendModel.php b/app/index/model/ProductCategoryRecommendModel.php new file mode 100644 index 00000000..122e4dc0 --- /dev/null +++ b/app/index/model/ProductCategoryRecommendModel.php @@ -0,0 +1,25 @@ +where($this->getTable() . '.language_id', '=', $language); + } +} diff --git a/app/index/view/pc/public/header.html.bak b/app/index/view/pc/public/header.html.bak new file mode 100644 index 00000000..c7ee9587 --- /dev/null +++ b/app/index/view/pc/public/header.html.bak @@ -0,0 +1,1618 @@ + + +
+