Index.php 1.4 KB
<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
/**
 * 分类接口**
 */
class Index extends Api
{
    protected  $noNeedLogin = [];
    protected $noNeedRight = '*';
    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * @ApiTitle    (获取分类列表)
     * @ApiSummary  (获取分类列表)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/index/getCategoryList)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiReturn ({
            "code": 1,
            "msg": "成功",
            "time": "1553831004",
            "data": [
                {
                    "id": 1,
                    "name": "废纸",//分类名称
                    "image": "/uploads/20190319/4a4c015ca04593f70a4836da45f2dea4.jpg"
                },
                {
                    "id": 2,
                    "name": "废塑料",
                    "image": "/uploads/20190319/4d82786ab0f7866110519f221cbf29a6.jpg"
                },
            ]
            })
     */
    public function getCategoryList(){
        if($this->request->isGet()){
            $data = Db::table('gc_category')
                ->where(['status'=>'normal'])
                ->field('id,name,image')
                ->select();
            $this->success('成功', $data);
        }else{
            $this->error('请求方式错误');
        }
    }
}