CategoryData.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * 分类
  4. */
  5. namespace app\api\controller;
  6. use app\admin\model\Category;
  7. use app\common\controller\Api;
  8. class CategoryData extends Api{
  9. protected $noNeedLogin = '*';
  10. protected $noNeedRight = '*';
  11. /**
  12. * 点击查看排名
  13. */
  14. public function lookRanking(){
  15. $second_id = $this->request->post("second_id",0); //二级id
  16. $tertiary_id = $this->request->post("tertiary_id",0); //三级id
  17. if (empty($second_id)){
  18. $this->error('请填写二级id');
  19. }
  20. if(empty($tertiary_id)){
  21. $this->error('请填写三级id');
  22. }
  23. $CategoryModel = new Category();
  24. $pid = Category::where(array('id'=>$second_id))->value('pid');
  25. //查询一级分类
  26. $firCat = $CategoryModel->where(array('pid'=>0))->order('sort asc')->field('id,name,active')->select();
  27. if($firCat){
  28. foreach ($firCat as $key=>$value){
  29. if($pid == $value['id']){
  30. $firCat[$key]['active'] = 1;
  31. }else{
  32. $firCat[$key]['active'] = 0;
  33. }
  34. }
  35. }
  36. //查询二级的分类
  37. $secCat = Category::where(array('pid'=>$pid))->field('id,name,active')->order('sort asc')->select();
  38. if($secCat){
  39. foreach ($secCat as $key=>$value){
  40. if($value['id'] == $second_id){
  41. $secCat[$key]['active'] = 1;
  42. }else{
  43. $secCat[$key]['active'] = 0;
  44. }
  45. }
  46. }
  47. //查询三级的分类
  48. $thrCat = Category::where(array('pid'=>$second_id))->field('id,name,active')->order('sort asc')->select();
  49. if($thrCat){
  50. foreach ($thrCat as $key=>$value){
  51. if($value['id'] == $tertiary_id){
  52. $thrCat[$key]['active'] = 1;
  53. }else{
  54. $thrCat[$key]['active'] = 0;
  55. }
  56. }
  57. }
  58. $info['firCat'] = $firCat;
  59. $info['secCat'] = $secCat;
  60. $info['thrCat'] = $thrCat;
  61. $this->success('成功',$info);
  62. }
  63. }