AdvController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace addons\TinyBlog\api\modules\v1\controllers;
  3. use Yii;
  4. use yii\data\ActiveDataProvider;
  5. use common\enums\StatusEnum;
  6. use addons\TinyBlog\common\models\Adv;
  7. use api\controllers\OnAuthController;
  8. /**
  9. * Class AdvController
  10. * @package addons\TinyBlog\api\modules\v1\controllers
  11. * @author jianyan74 <751393839@qq.com>
  12. */
  13. class AdvController extends OnAuthController
  14. {
  15. /**
  16. * @var Adv
  17. */
  18. public $modelClass = Adv::class;
  19. /**
  20. * 不用进行登录验证的方法
  21. * 例如: ['index', 'update', 'create', 'view', 'delete']
  22. * 默认全部需要验证
  23. *
  24. * @var array
  25. */
  26. protected $authOptional = ['index'];
  27. /**
  28. * @return ActiveDataProvider
  29. */
  30. public function actionIndex()
  31. {
  32. // 默认为首页幻灯片
  33. return new ActiveDataProvider([
  34. 'query' => Adv::find()
  35. ->where(['status' => StatusEnum::ENABLED])
  36. ->andWhere(['<=', 'start_time', time()])
  37. ->andWhere(['>=', 'end_time', time()])
  38. ->andFilterWhere(['merchant_id' => $this->getMerchantId()])
  39. ->orderBy('sort asc')
  40. ->asArray()
  41. ]);
  42. }
  43. /**
  44. * 权限验证
  45. *
  46. * @param string $action 当前的方法
  47. * @param null $model 当前的模型类
  48. * @param array $params $_GET变量
  49. * @throws \yii\web\BadRequestHttpException
  50. */
  51. public function checkAccess($action, $model = null, $params = [])
  52. {
  53. // 方法名称
  54. if (in_array($action, ['delete', 'create', 'update', 'view'])) {
  55. throw new \yii\web\BadRequestHttpException('权限不足');
  56. }
  57. }
  58. }
粤ICP备19079148号