作者 赵彬吉

update

... ... @@ -29,7 +29,10 @@ class CategoryController extends BaseController
foreach ($data as &$v){
$v['product_num'] = $logic->getProductNum($v['id']);
}
return $this->success(Arr::listToTree($data));
if(!$map){
$data = Arr::listToTree($data);
}
return $this->success($data);
}
public function info(Request $request, CategoryLogic $logic){
... ...
... ... @@ -25,7 +25,11 @@ class KeywordController extends BaseController
$map[] = ['title', 'like', "%{$this->param['search']}%"];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'title', 'route', 'status', 'created_at']);
$data = $logic->getList($map, $sort, ['id', 'title', 'seo_title', 'seo_keywords', 'seo_description', 'status', 'created_at']);
foreach ($data['list'] as &$v){
$v['product_num'] = $logic->getProductNum($v['title']);
$v['tdk'] = boolval($v['seo_title']) * boolval($v['seo_keywords']) * boolval($v['seo_description']);
}
return $this->success($data);
}
... ... @@ -36,7 +40,7 @@ class KeywordController extends BaseController
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'route', 'created_at']));
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'seo_title', 'seo_keywords', 'seo_description', 'created_at']));
}
public function save(KeywordRequest $request, KeywordLogic $logic)
... ...
... ... @@ -64,7 +64,8 @@ class CategoryLogic extends BaseLogic
* @date 2023/4/28
*/
public function getProductNum($cate_id){
$ids = $this->model->getChildIdsArr($cate_id);
return CategoryRelated::whereIn('cate_id', $ids)->count();
$cate_ids = $this->model->getChildIdsArr($cate_id);
$product_ids = CategoryRelated::whereIn('cate_id', $cate_ids)->pluck('id');
return Product::whereIn('id', $product_ids)->count();
}
}
... ...
... ... @@ -59,4 +59,8 @@ class KeywordLogic extends BaseLogic
return $this->success();
}
public function getProductNum($title){
return Product::whereRaw("find_in_set('{$title}',`keywords`)")->count();
}
}
... ...