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.3 KiB

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