作者 lyh

gx

... ... @@ -36,18 +36,49 @@ class CategoryController extends BaseController
$filed = ['id', 'project_id', 'pid', 'title', 'image', 'keywords', 'describe', 'status','created_at'];
$list = $category->list($this->map,'id',$filed);
if(!empty($list)){
$data = array();
foreach ($list as $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = _get_child($v['id'], $list);
$data[] = $v;
}
foreach ($list as $k =>$v){
$v = $this->handleParam($category,$v);
$list[$k] = $v;
}
$data = $this->getListSon($list);
}
return $this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :分类处理参数
* @name :handleParam
* @author :lyh
* @method :post
* @time :2023/8/17 11:10
*/
public function handleParam(&$category,$v){
$v['url'] = $this->user['domain'] . $v['route'] ;
$cate_ids = $category->getChildIdsArr($v['id']);
$v['product_num'] = CategoryRelated::whereIn('cate_id', $cate_ids)->distinct()->count('product_id');
$v['image_link'] = getImageUrl($v['image']);
return $v;
}
/**
* @remark :无分页子集处理
* @name :getListSon
* @author :lyh
* @method :post
* @time :2023/8/17 11:12
*/
public function getListSon(&$list){
$data = array();
foreach ($list as $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = _get_child($v['id'], $list);
$data[] = $v;
}
}
return $data;
}
public function info(Request $request, CategoryLogic $logic){
$request->validate([
'id'=>'required'
... ...
... ... @@ -27,19 +27,19 @@ class CategoryLogic extends BaseLogic
$this->model = new Category();
}
// public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
// {
// $data = parent::getList($map, $sort, $columns, $limit);
// foreach ($data as &$v){
// $v['url'] = $this->getProjectDomain() . $v['route'] ;
// $v['product_num'] = $this->getProductNum($v['id']);
// $v['image_link'] = getImageUrl($v['image']);
// }
// if(!$map){
// $data = Arr::listToTree($data);
// }
// return $this->success($data);
// }
public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
{
$data = parent::getList($map, $sort, $columns, $limit);
foreach ($data as &$v){
$v['url'] = $this->getProjectDomain() . $v['route'] ;
$v['product_num'] = $this->getProductNum($v['id']);
$v['image_link'] = getImageUrl($v['image']);
}
if(!$map){
$data = Arr::listToTree($data);
}
return $this->success($data);
}
public function getInfo($id)
{
... ...