1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- /**
- * Created by PhpStorm.
- * Author: 莫名疯
- * DateTime: 2017/3/8 10:09
- * Description:
- */
- namespace api\modules\v1\controllers;
- use api\common\controllers\Controller;
- use api\modules\v1\models\Category;
- use common\helpers\Tree;
- use yii\helpers\ArrayHelper;
- use api\common\behaviors\QueryParamAuth;
- class CategoryController extends Controller {
- public function behaviors()
- {
- return ArrayHelper::merge(parent::behaviors(), [
- [
- 'class' => QueryParamAuth::className(),
- 'tokenParam' => 'token',
- 'optional' => ['index']
- ]
- ]);
- }
- /**
- * @api {get} /v1/categorys 列表
- * @apiVersion 1.0.0
- * @apiName index
- * @apiGroup Category
- *
- *
- */
- public function actionIndex()
- {
- $lists = Category::find()->active()->orderBy(['sort' => SORT_ASC])->all();
- $lists = ArrayHelper::toArray($lists);
- $lists = Tree::build($lists);
- //添加热门推荐
- // array_unshift($lists, [
- // 'title' => '热门推荐',
- // 'children' => Cat::find()->hot()->all()
- // ]);
- return ['data' => $lists];
- }
- /**
- * @api {get} /v1/category/id:\d+ 分类详情
- * @apiVersion 1.0.0
- * @apiName view
- * @apiGroup Category
- *
- */
- public function actionView($id)
- {
- $model = Category::find()->where(['id' => $id])->one();
- return ['data' => $model];
- }
- }
|