ExpiredBehavior.php 995 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace common\behaviors;
  3. use Yii;
  4. use Exception;
  5. use yii\base\Behavior;
  6. use yii\web\Controller;
  7. use common\models\mall\Mall;
  8. use yii\web\TooManyRequestsHttpException;
  9. /**
  10. * 商城过期
  11. *
  12. * Class ExpiredBehavior
  13. * @package common\behaviors
  14. * @author qimall
  15. */
  16. class ExpiredBehavior extends Behavior
  17. {
  18. /**
  19. * 请求方法
  20. *
  21. * @var string
  22. */
  23. public $action = "*";
  24. /**
  25. * @var int
  26. */
  27. public $mall_id;
  28. /**
  29. * @return array
  30. */
  31. public function events()
  32. {
  33. return [Controller::EVENT_BEFORE_ACTION => 'beforeAction'];
  34. }
  35. /**
  36. * @param $event
  37. * @throws TooManyRequestsHttpException
  38. */
  39. public function beforeAction($event)
  40. {
  41. // 检测站点是否过期
  42. if (Mall::getIsExpired($this->mall_id)) {
  43. $redirect_url = Yii::$app->urlManager->createAbsoluteUrl(['admin/auth/expired']);
  44. header(sprintf('Location: %s', $redirect_url));
  45. }
  46. }
  47. }