You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

49 lines
1.3 KiB

<?php
namespace api\controllers;
use yii\filters\auth\HttpBearerAuth;
use yii\helpers\ArrayHelper;
use yii\rest\ActiveController;
/**
* @author iron
* @email weiriron@gmail.com
*/
class GoodsController extends CommonController
{
public $modelClass = 'antgoods\goods\models\ars\Goods';
public function actions()
{
$action = parent::actions();
unset($action['delete']);
unset($action['create']);
$action['index'] = [
'class' => 'yii\rest\IndexAction',
'modelClass' => $this->modelClass,
'dataFilter' => $this->getFilter()
];
return $action;
}
protected function getFilter()
{
$keyword = \Yii::$app->request->getBodyParam('keyword');
$category = \Yii::$app->request->getBodyParam('category');
if (empty($keyword) && empty($category)) {
return null;
}
$array = [];
if ($keyword) {
$array['name'] = ['like' => $keyword];
}
if ($category) {
$array['cat_id'] = $category;
}
$filter = ['class' => 'yii\data\ActiveDataFilter',
'filter' => $array,
'searchModel' => ['class' => 'antgoods\goods\models\searchs\GoodsSearch']];
return $filter;
}
}