修改一级分类展示

This commit is contained in:
liaofei 2023-06-26 11:42:50 +08:00
parent ba60b74bf8
commit adccc4d130

View File

@ -127,6 +127,9 @@ class StoreProductServices extends BaseServices
/** @var StoreCategoryServices $categoryService */
$categoryService = app()->make(StoreCategoryServices::class);
$cateList = $categoryService->getCateParentAndChildName($cateIds);
$preantCateList = $categoryService->getColumn([
['id', 'in', $cateIds]
], 'cate_name', 'id');
foreach ($list as &$item) {
$cateName = array_filter($cateList, function ($val) use ($item) {
if (in_array($val['id'], explode(',', $item['cate_id']))) {
@ -137,6 +140,9 @@ class StoreProductServices extends BaseServices
foreach ($cateName as $k => $v) {
$item['cate_name'][] = $v['one'] . '/' . $v['two'];
}
if (!count($item['cate_name']) && isset($preantCateList[$item['cate_id']])) {
$item['cate_name'][] = $preantCateList[$item['cate_id']];
}
$item['cate_name'] = is_array($item['cate_name']) ? implode(',', $item['cate_name']) : '';
$item['stock_attr'] = $item['stock'] > 0;//库存
$item['product_type'] = $this->productType[$item['virtual_type']];