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.

47 lines
1.1 KiB

  1. <?php
  2. namespace api\controllers;
  3. use Yii;
  4. /**
  5. * @author iron
  6. * @email weiriron@gmail.com
  7. */
  8. class GoodsController extends CommonController
  9. {
  10. public $modelClass = 'backend\modules\goods\models\ars\Goods';
  11. public function actions()
  12. {
  13. $action = parent::actions();
  14. unset($action['delete']);
  15. $action['index'] = [
  16. 'class' => 'yii\rest\IndexAction',
  17. 'modelClass' => $this->modelClass,
  18. 'dataFilter' => $this->getFilter()
  19. ];
  20. return $action;
  21. }
  22. protected function getFilter()
  23. {
  24. $keyword = \Yii::$app->request->getBodyParam('keyword');
  25. $category = \Yii::$app->request->getBodyParam('category');
  26. $array = [];
  27. if ($keyword) {
  28. $array['name'] = ['like' => $keyword];
  29. }
  30. if ($category) {
  31. $array['cat_id'] = $category;
  32. }
  33. if (empty($array)) {
  34. return null;
  35. }
  36. return ['class' => 'yii\data\ActiveDataFilter',
  37. 'filter' => $array,
  38. 'searchModel' => ['class' => 'backend\modules\goods\models\searchs\GoodsSearch']];
  39. }
  40. }