作者 lyh

gx

... ... @@ -86,6 +86,17 @@ class CategoryController extends BaseController
}
/**
* @name :(添加/编辑时获取顶级分类)topList
* @author :lyh
* @method :post
* @time :2023/6/13 9:03
*/
public function categoryTopList(CategoryLogic $logic){
$list = $logic->categoryTopList();
$this->response('success',Code::SUCCESS,$list);
}
/**
* @remark :获取详情
* @name :info
* @author :lyh
... ...
... ... @@ -42,6 +42,53 @@ class CategoryLogic extends BaseLogic
}
/**
* @name :(添加/编辑分类时获取级分类)categoryTopList
* @author :lyh
* @method :post
* @time :2023/6/13 9:09
*/
public function categoryTopList(){
$this->param['project_id'] = $this->user['project_id'];
$this->param['status'] = 0;
if(isset($this->param['id']) && !empty($this->param['id'])){
$str = [];
//排序掉当前id下所有子集
$str = $this->getAllSub($this->param['id'],$str);
$str[] = (int)$this->param['id'];
$this->param['id'] = ['not in',$str];
}
$menu = array();
$list = $this->model->list($this->param);
if(!empty($list)){
foreach ($list as $k => $v){
if($v['pid'] == 0){
$v['sub'] = _get_child($v['id'],$list);
$menu[] = $v;
}
}
}
return $this->success($menu);
}
/**
* @remark :获取当前id下所有子集
* @name :getAllSub
* @author :lyh
* @method :post
* @time :2023/10/18 15:10
*/
public function getAllSub($id,&$str = []){
$list = $this->model->list(['pid'=>$id,'status'=>0],['id','pid']);
if(!empty($list)){
foreach ($list as $v){
$str[] = $v['id'];
$this->getAllSub($v['id'],$str);
}
}
return $str;
}
/**
* @remark :获取详情
* @name :getInfo
* @author :lyh
... ...
... ... @@ -193,6 +193,7 @@ Route::middleware(['bloginauth'])->group(function () {
//产品分类
Route::get('category', [\App\Http\Controllers\Bside\Product\CategoryController::class, 'index'])->name('product_category');
Route::get('category/info', [\App\Http\Controllers\Bside\Product\CategoryController::class, 'info'])->name('product_category_info');
Route::get('category/categoryTopList', [\App\Http\Controllers\Bside\Product\CategoryController::class, 'categoryTopList'])->name('product_category_categoryTopList');
Route::post('category/save', [\App\Http\Controllers\Bside\Product\CategoryController::class, 'save'])->name('product_category_save');
Route::post('category/sort', [\App\Http\Controllers\Bside\Product\CategoryController::class, 'sort'])->name('product_category_sort');
Route::any('category/delete', [\App\Http\Controllers\Bside\Product\CategoryController::class, 'delete'])->name('product_category_delete');
... ...