fix: bug修复

This commit is contained in:
2024-10-29 17:38:47 +08:00
parent 48bf3e6f33
commit 6df8d23686
31 changed files with 1032 additions and 664 deletions

View File

@@ -17,6 +17,14 @@ class BaseController extends Controller {
protected $country_code = 'US';
protected $customer_info = [];
protected $categoryList = [];
protected $country_list = [];
protected $productCategory = [];
protected $nav_header = [];
protected $nav_footer = [];
public function __construct() {
parent::__construct();
}
@@ -52,11 +60,66 @@ class BaseController extends Controller {
$this->view->assign('seo_description', (string) Config::get('website_seo_description'));
//$this->categoryList = $this->cacheGet('productCategoryList');
if (empty($this->productCategory)) {
$this->categoryList = Loader::model('ProductCategory')->getList(['stat' => 0, 'siteid' => $this->siteid,'isshow'=>1, 'country_code' => $this->country_code], ['sort' => 'asc', 'id' => 'asc'], ['id', 'pid', 'haschild', 'name', 'shortname', 'sort', 'description', 'isshow', 'recommend', 'picture', 'icon', 'image', 'm_icon', 'unique_id']);
// $this->categoryList = Loader::model('ProductCategory')->getList(['stat' => 0, 'siteid' => $this->siteid,'isshow'=>1, 'country_code' => $this->country_code], ['sort' => 'asc', 'id' => 'asc'], ['id', 'pid', 'haschild', 'name', 'shortname', 'sort', 'description', 'isshow', 'recommend', 'picture', 'icon', 'image', 'm_icon', 'unique_id']);
$this->categoryList = \think\Db::name('product_category')->alias('pc')
->field([
'pc.id',
'pc.pid',
'pc.haschild',
'pc.name',
'pc.shortname',
'pc.sort',
'pc.description',
'pc.isshow',
'pc.recommend',
'pc.picture',
'pc.icon',
'pc.image',
'pc.m_icon',
'pc.unique_id'
])
->where('pc.stat', '=', 0)
->where('pc.siteid', '=', $this->siteid)
->where('pc.isshow', '=', 1)
->where('pc.haschild', '=', 0)
->where('pc.country_code', '=', $this->country_code)
->whereExists(function ($query) {
$query->name('product')->alias('p')
->where('p.stat', '=', 0)
->where('p.is_show', '=', 0)
->where('p.country_code', '=', $this->country_code)
->where('p.cid=pc.id');
})
->union(function ($query) {
$query->name('product_category')->alias('uni_pc')
->field([
'uni_pc.id',
'uni_pc.pid',
'uni_pc.haschild',
'uni_pc.name',
'uni_pc.shortname',
'uni_pc.sort',
'uni_pc.description',
'uni_pc.isshow',
'uni_pc.recommend',
'uni_pc.picture',
'uni_pc.icon',
'uni_pc.image',
'uni_pc.m_icon',
'uni_pc.unique_id'
])
->where('uni_pc.stat', '=', 0)
->where('uni_pc.siteid', '=', $this->siteid)
->where('uni_pc.isshow', '=', 1)
->where('uni_pc.haschild', '=', 1)
->where('uni_pc.country_code', '=', $this->country_code);
})
->order(['sort' => 'asc', 'id' => 'asc'])
->select();
$this->cacheTag('ProductCategoryTag')->set('productCategoryList', $this->categoryList);
}
$this->categoryList = collection($this->categoryList);
$this->productCategory = $this->buildTreeForCategory($this->categoryList, 0);
if ($this->cacheHas('country_list')) {
$this->country_list = $this->cacheGet('country_list');
@@ -89,11 +152,30 @@ class BaseController extends Controller {
//echo $product_country_code."<pre>=="; print_r($this->nav_header);die;
//echo Loader::model('banner')->getlastsql();
$this->productCategory = $this->list_to_tree($this->categoryList);
$this->view->assign('productCategory', $this->productCategory);
$this->view->assign('allCategoryList', $this->categoryList);
}
// 组装分类树状结构
private function buildTreeForCategory($data, $pid = 0)
{
$tree = [];
foreach ($data as $val) {
if ($val['pid'] == $pid) {
$children = $this->buildTreeForCategory($data, $val['id']);
if (!empty($children)) {
$val['child'] = $children;
}
if (empty($children) && $val['haschild'] == 1) {
continue;
}
$tree[] = $val;
}
}
return $tree;
}
//导航初始化
private function navInit(){
// 读取缓存数据
@@ -171,7 +253,9 @@ class BaseController extends Controller {
// 商品分类
case 'goods_category':
$category = Loader::model('ProductCategory')->getRow(['stat' => 0, 'id' => $v['value'], 'country_code' => $this->country_code], null, ['id' => 'asc']);
if (empty($category)) {
continue;
}
if($category['pid'] == 0) {
$v['url'] = '/product/catelists/'.$v['value'].'.html';
}
@@ -184,6 +268,7 @@ class BaseController extends Controller {
$data[$k] = $v;
}
unset($v);
}
return $data;