作者 lyh

gx

@@ -195,13 +195,44 @@ class BlogCategoryLogic extends BaseLogic @@ -195,13 +195,44 @@ class BlogCategoryLogic extends BaseLogic
195 * @time :2023/6/13 9:09 195 * @time :2023/6/13 9:09
196 */ 196 */
197 public function categoryTopList(){ 197 public function categoryTopList(){
198 - $map = [  
199 - 'project_id'=>$this->user['project_id'],  
200 - 'pid'=>0,  
201 - 'status'=>0,  
202 - ];  
203 - $list = $this->model->list($map);  
204 - return $this->success($list); 198 + $this->param['project_id'] = $this->user['project_id'];
  199 + $this->param['status'] = 0;
  200 + if(isset($this->param['id']) && !empty($this->param['id'])){
  201 + $str = [];
  202 + //排序掉当前id下所有子集
  203 + $str = $this->getAllSub($this->param['id'],$str);
  204 + $str[] = (int)$this->param['id'];
  205 + $this->param['id'] = ['not in',$str];
  206 + }
  207 + $menu = array();
  208 + $list = $this->model->list($this->param);
  209 + if(!empty($list)){
  210 + foreach ($list as $k => $v){
  211 + if($v['pid'] == 0){
  212 + $v['sub'] = _get_child($v['id'],$list);
  213 + $menu[] = $v;
  214 + }
  215 + }
  216 + }
  217 + return $this->success($menu);
  218 + }
  219 +
  220 + /**
  221 + * @remark :获取当前id下所有子集
  222 + * @name :getAllSub
  223 + * @author :lyh
  224 + * @method :post
  225 + * @time :2023/10/18 15:10
  226 + */
  227 + public function getAllSub($id,&$str = []){
  228 + $list = $this->model->list(['pid'=>$id,'status'=>0],['id','pid']);
  229 + if(!empty($list)){
  230 + foreach ($list as $v){
  231 + $str[] = $v['id'];
  232 + $this->getAllSub($v['id'],$str);
  233 + }
  234 + }
  235 + return $str;
205 } 236 }
206 237
207 /** 238 /**