feat: mobile端classify页面
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 4s
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 4s
This commit is contained in:
@@ -149,7 +149,7 @@ class Product extends Common
|
||||
}
|
||||
}
|
||||
View::assign('list', $list);
|
||||
|
||||
|
||||
return View::fetch('category');
|
||||
}
|
||||
// 产品分类 - 查看子类
|
||||
@@ -267,6 +267,59 @@ class Product extends Common
|
||||
return View::fetch('subcategory');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 单纯分类页
|
||||
*/
|
||||
public function classify()
|
||||
{
|
||||
$pid = request()->param('id/d', 0);
|
||||
|
||||
// 获取当前选中的父分类
|
||||
$parent = ProductCategoryModel::field(['id', 'name'])->find($pid);
|
||||
View::assign('parent', $parent);
|
||||
|
||||
// 获取分类及产品信息
|
||||
$categorys = ProductCategoryModel::field(['id', 'pid', 'name', 'path', 'level'])
|
||||
->language($this->lang_id)
|
||||
->displayed(true)
|
||||
->children($pid)
|
||||
->order(['pid' => 'asc', 'sort' => 'asc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 组装第三级分类所属产品数据
|
||||
$lv3_id_arr = array_column(array_filter($categorys, fn($item)=> $item['level'] === 3), 'id');
|
||||
$products = ProductModel::field([
|
||||
'id',
|
||||
'category_id',
|
||||
'name',
|
||||
'short_name',
|
||||
'cover_image',
|
||||
'spu'
|
||||
])
|
||||
->byCategory($lv3_id_arr)
|
||||
->language($this->lang_id)
|
||||
->enabled(true)
|
||||
->onSale(true)
|
||||
->onShelves(true)
|
||||
->select()
|
||||
->toArray();
|
||||
$product_groups = [];
|
||||
foreach ($products as $product) {
|
||||
$product_groups[$product['category_id']][] = $product;
|
||||
}
|
||||
foreach ($categorys as $key => $category) {
|
||||
if ($category['level'] < 3) continue;
|
||||
$categorys[$key]['products'] = $product_groups[$category['id']] ?? [];
|
||||
}
|
||||
|
||||
$tree = array_to_tree($categorys, $pid);
|
||||
View::assign('categorys', $tree);
|
||||
|
||||
return View::fetch('classify');
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品搜索
|
||||
*/
|
||||
@@ -329,7 +382,7 @@ class Product extends Common
|
||||
->bypk($param['id'])
|
||||
->find();
|
||||
View::assign('product', $product);
|
||||
|
||||
|
||||
$product_categorys = [];
|
||||
$product_params = [];
|
||||
$product_skus = [];
|
||||
@@ -352,7 +405,7 @@ class Product extends Common
|
||||
->order(['id' => 'asc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
|
||||
// 获取产品参数信息
|
||||
$product_params = ProductParamsModel::field(['id', 'name', 'value'])
|
||||
->byProductId($product['id'])
|
||||
@@ -375,7 +428,7 @@ class Product extends Common
|
||||
$attrs = ProductAttrModel::bypks(array_unique(Arr::pluck($sku_attrs, 'attr_id')))->column(['attr_name'], 'id');
|
||||
foreach ($sku_attrs as $v) {
|
||||
if (empty($v['attr_value'])) continue;
|
||||
|
||||
|
||||
$v['attr_name'] = $attrs[$v['attr_id']]?? '';
|
||||
// 按属性分组
|
||||
$product_sku_attrs[$v['attr_id']]['attr_id'] = $v['attr_id'];
|
||||
@@ -422,8 +475,8 @@ class Product extends Common
|
||||
|
||||
// 获取询盘可选国家
|
||||
$config = $this->basic_config['optional_country_for_product_inquiry'];
|
||||
View::assign('country_list', explode(',', preg_replace('/\r?\n/', ',', $config['value']?? '')));
|
||||
|
||||
View::assign('country_list', explode(',', preg_replace('/\r?\n/', ',', $config['value']?? '')));
|
||||
|
||||
return View::fetch('detail');
|
||||
}
|
||||
|
||||
@@ -535,7 +588,7 @@ class Product extends Common
|
||||
if ($val['level'] != 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
foreach ($pro_map as $k => $pro) {
|
||||
if (in_array($val['id'], explode(',', strval($k)))) {
|
||||
$newpros[] = [
|
||||
@@ -549,7 +602,7 @@ class Product extends Common
|
||||
}
|
||||
}
|
||||
View::assign('newpros', $newpros);
|
||||
|
||||
|
||||
return View::fetch('newpro');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user