<?php /** * 分类 */ namespace app\api\controller; use app\admin\model\Category; use app\common\controller\Api; class CategoryData extends Api{ protected $noNeedLogin = '*'; protected $noNeedRight = '*'; /** * 点击查看排名 */ public function lookRanking(){ $second_id = $this->request->post("second_id",0); //二级id $tertiary_id = $this->request->post("tertiary_id",0); //三级id if (empty($second_id)){ $this->error('请填写二级id'); } if(empty($tertiary_id)){ $this->error('请填写三级id'); } $CategoryModel = new Category(); $pid = Category::where(array('id'=>$second_id))->value('pid'); //查询一级分类 $firCat = $CategoryModel->where(array('pid'=>0))->order('sort asc')->field('id,name,active')->select(); if($firCat){ foreach ($firCat as $key=>$value){ if($pid == $value['id']){ $firCat[$key]['active'] = 1; }else{ $firCat[$key]['active'] = 0; } } } //查询二级的分类 $secCat = Category::where(array('pid'=>$pid))->field('id,name,active')->order('sort asc')->select(); if($secCat){ foreach ($secCat as $key=>$value){ if($value['id'] == $second_id){ $secCat[$key]['active'] = 1; }else{ $secCat[$key]['active'] = 0; } } } //查询三级的分类 $thrCat = Category::where(array('pid'=>$second_id))->field('id,name,active')->order('sort asc')->select(); if($thrCat){ foreach ($thrCat as $key=>$value){ if($value['id'] == $tertiary_id){ $thrCat[$key]['active'] = 1; }else{ $thrCat[$key]['active'] = 0; } } } $info['firCat'] = $firCat; $info['secCat'] = $secCat; $info['thrCat'] = $thrCat; $this->success('成功',$info); } }