refactor: pc导航重构
Some checks failed
Gitea Actions Official-website / deploy-dev (push) Failing after 3s
Some checks failed
Gitea Actions Official-website / deploy-dev (push) Failing after 3s
This commit is contained in:
@@ -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 [];
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
25
app/index/model/ProductCategoryRecommendModel.php
Normal file
25
app/index/model/ProductCategoryRecommendModel.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\index\model;
|
||||
|
||||
use app\common\model\ProductCategoryRecommendBaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
/**
|
||||
* 产品分类推荐模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class ProductCategoryRecommendModel extends ProductCategoryRecommendBaseModel
|
||||
{
|
||||
// 启用软件删除
|
||||
use SoftDelete;
|
||||
// 软件删除时间字段
|
||||
protected $deleteTime = 'deleted_at';
|
||||
|
||||
// 所属语言范围查询
|
||||
public function scopeLanguage($query, $language)
|
||||
{
|
||||
$query->where($this->getTable() . '.language_id', '=', $language);
|
||||
}
|
||||
}
|
||||
1618
app/index/view/pc/public/header.html.bak
Normal file
1618
app/index/view/pc/public/header.html.bak
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user