| 123456789101112131415161718192021222324252627282930313233343536373839 | <?phpnamespace app\api\controller;use app\common\model\Category as CategoryModel;use fast\Tree;use app\common\Enum\StatusEnum;/** * 商品分类 */class Category extends Base{    protected $noNeedLogin = ['index'];    //分类列表    public function index()    {            $tree = Tree::instance();        $categoryList = CategoryModel::field('id,pid,name,image')        ->order('weigh desc,id asc')        ->where('status',StatusEnum::ENABLED)        ->select();        $tree->init(collection($categoryList)->toArray(), 'pid');        $list = $tree->getTreeArray(0);              $this->success('获取成功', $list);    }    //  查询所有分类    public function getCategoryList()    {               $categoryList = CategoryModel::field('id,pid,name,image')        ->order('weigh asc,id asc')        ->where('status',StatusEnum::ENABLED)        ->select();               $this->success('获取成功', $categoryList);    }}
 |