GoodsController.php 992 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace addons\Community\api\modules\v1\controllers;
  3. use addons\Community\common\service\GoodsService;
  4. use api\controllers\OnAuthController;
  5. use Yii;
  6. class GoodsController extends OnAuthController
  7. {
  8. public $modelClass = '';
  9. /**
  10. * 不用进行登录验证的方法
  11. *
  12. * 例如: ['index', 'update', 'create', 'view', 'delete']
  13. * 默认全部需要验证
  14. *
  15. * @var array
  16. */
  17. protected $authOptional = [];
  18. public function actionIndex()
  19. {
  20. $data = \Yii::$app->request->get();
  21. $valid = Yii::$app->services->validate->validate($data, [
  22. [['page', 'limit', 'cate_id'], 'integer'],
  23. [['type'], 'safe']
  24. ]);
  25. if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  26. $ret = (new GoodsService())->page($this->mall_id, $data, $this->user_id);
  27. return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
  28. }
  29. }