|
|
@@ -1,17 +1,10 @@
|
|
|
<?php
|
|
|
+
|
|
|
namespace mobile\controllers;
|
|
|
|
|
|
-use biz\goods\services\CategoryRelateService;
|
|
|
-use biz\stat\services\VisitByDayService;
|
|
|
use biz\user\services\UserService;
|
|
|
-use common\components\error;
|
|
|
-use Yii;
|
|
|
-use common\services\xhMerchantExtendService;
|
|
|
-use common\services\xhUserService;
|
|
|
-use common\components\jsSDK;
|
|
|
-use common\components\weixinUtil;
|
|
|
+use common\components\jwt;
|
|
|
use common\components\util;
|
|
|
-use common\services\xhMerchantService;
|
|
|
|
|
|
/**
|
|
|
* Created by PhpStorm.
|
|
|
@@ -21,5 +14,29 @@ use common\services\xhMerchantService;
|
|
|
*/
|
|
|
class BaseController extends PublicController
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
+ public $validate = true;
|
|
|
+ public $withoutLogin = [];//不需要登陆可以访问的方法
|
|
|
+ public $userId, $user;
|
|
|
+
|
|
|
+ public function beforeAction($action)
|
|
|
+ {
|
|
|
+ //token验证
|
|
|
+ $userId = jwt::checkLogin();
|
|
|
+ if (empty($userId)) {
|
|
|
+ $this->validate = false;
|
|
|
+ } else {
|
|
|
+ $this->validate = true;
|
|
|
+ $this->userId = $userId;
|
|
|
+ $this->user = UserService::getById($userId);
|
|
|
+ }
|
|
|
+ //游客可以访问的方法
|
|
|
+ if (in_array($action->id, $this->withoutLogin)) {
|
|
|
+ $this->validate = true;
|
|
|
+ }
|
|
|
+ if ($this->validate == false) {
|
|
|
+ util::notLogin();
|
|
|
+ }
|
|
|
+ return parent::beforeAction($action);
|
|
|
+ }
|
|
|
}
|