Category.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\api\controller\service;
  3. use app\common\controller\Api;
  4. /**
  5. * 首页接口
  6. */
  7. class Category extends Api
  8. {
  9. protected $noNeedLogin = ['*'];
  10. protected $noNeedRight = ['*'];
  11. /**
  12. * 获取分类
  13. * @return void
  14. * @throws \think\db\exception\DataNotFoundException
  15. * @throws \think\db\exception\ModelNotFoundException
  16. * @throws \think\exception\DbException
  17. */
  18. public function getList()
  19. {
  20. if (!$this->request->isPost()) {
  21. $this->error('请求方式异常');
  22. }
  23. $type = input('type','');
  24. $list = model('app\api\model\service\Category')->field('id,name as label,pid,image')->where(['status'=>'normal','pid'=>0])->order('weigh desc')->select();
  25. if($type == 'all'){
  26. foreach ($list as &$val){
  27. $val['children'] = model('app\api\model\service\Category')->field('id,name as label,pid,image')->where(['status'=>'normal','pid'=>$val['id']])->order('weigh desc')->select();
  28. }
  29. }
  30. $this->success('分类信息返回成功',$list);
  31. }
  32. public function getSon()
  33. {
  34. if (!$this->request->isPost()) {
  35. $this->error('请求方式异常');
  36. }
  37. $id = input('id/d','');
  38. $list = model('app\api\model\service\Category')->field('id,name as label,pid,image')->where(['status'=>'normal','pid'=>$id])->order('weigh desc')->select();
  39. $this->success('信息返回成功',$list);
  40. }
  41. }