MallController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace backend\controllers;
  3. use common\behaviors\ExpiredBehavior;
  4. use common\behaviors\LimitBehavior;
  5. use common\models\backend\Admin;
  6. use Exception;
  7. use Yii;
  8. use yii\web\ForbiddenHttpException;
  9. class MallController extends BaseController
  10. {
  11. /**
  12. * @return array
  13. */
  14. public function behaviors()
  15. {
  16. return [
  17. 'counter' => [
  18. 'class' => LimitBehavior::class,
  19. 'userId' => $this->admin['id'] ?? 0,
  20. ],
  21. [
  22. 'class' => ExpiredBehavior::class,
  23. 'mall_id' => $this->mall_id
  24. ],
  25. ];
  26. }
  27. public $layout = '@backend/views/layouts/mall';
  28. public $mall = null;
  29. public $mall_id = 0;
  30. public $admin = null;
  31. public function init()
  32. {
  33. parent::init();
  34. $this->admin = Yii::$app->user->identity;
  35. if (empty($this->admin)) {
  36. if ($this->request->isAjax) {
  37. return $this->error('对不起,您现在还没获此操作的权限');
  38. } else {
  39. throw new ForbiddenHttpException('对不起,您现在还没获此操作的权限');
  40. }
  41. }
  42. $mall = Yii::$app->session->get('mall');
  43. if(empty($mall)){
  44. // 商城session过期
  45. switch($this->admin->admin_type){
  46. case Admin::ADMIN_TYPE_SUPER:
  47. case Admin::ADMIN_TYPE_AGENT:
  48. return $this->redirect(['/admin/mall/index']);
  49. break;
  50. default:
  51. try{
  52. Yii::$app->user->logout();
  53. }catch(Exception $e){
  54. }
  55. return $this->redirect(['/admin/auth/login','login_type'=>base64_encode('mall')]);
  56. }
  57. }
  58. $this->mall = $mall;
  59. $this->mall_id = $mall['id'];
  60. }
  61. }