| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace app\api\controller\service;
- use app\common\controller\Api;
- /**
- * 首页接口
- */
- class Category extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 获取分类
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getList()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $type = input('type','');
- $list = model('app\api\model\service\Category')->field('id,name as label,pid,image')->where(['status'=>'normal','pid'=>0])->order('weigh desc')->select();
- if($type == 'all'){
- foreach ($list as &$val){
- $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();
- }
- }
- $this->success('分类信息返回成功',$list);
- }
- public function getSon()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $id = input('id/d','');
- $list = model('app\api\model\service\Category')->field('id,name as label,pid,image')->where(['status'=>'normal','pid'=>$id])->order('weigh desc')->select();
- $this->success('信息返回成功',$list);
- }
- }
|