shish 6 years ago
parent
commit
4c14dceb3b
1 changed files with 43 additions and 30 deletions
  1. 43 30
      app/www/controllers/BaseController.php

+ 43 - 30
app/www/controllers/BaseController.php

@@ -2,7 +2,11 @@
 
 namespace www\controllers;
 
+use biz\merchant\services\MerchantService;
 use biz\saas\services\StaffService;
+use biz\user\services\UserService;
+use biz\weixin\services\WxOpenService;
+use common\components\jwt;
 use common\components\util;
 use Yii;
 use yii\web\Controller;
@@ -12,35 +16,44 @@ use yii\web\Controller;
  */
 class BaseController extends PublicController
 {
-	
-	public $staff, $staffId, $userId, $user, $merchantId;
-	public $isLogin = false;
-	public $withoutLogin = [];//不需要登陆的方法名
-	public $validate = true;
-	
-	public function beforeAction($action)
-	{
-		//token验证
-		//$staffId = jwt::getLoginId();
-		$staffId = 12540901;
-		$userId = 12540901;
-		$staff = 12540901;
-		if (empty($staffId)) {
-			$this->validate = false;
-		}
-		//游客可以访问的方法
-		if (in_array($action->id, $this->withoutLogin)) {
-			$this->validate = true;
-		}
-		if ($this->validate == false) {
-			util::notLogin();
-		}
-		$this->staff = $staff;
-		$this->staffId = $staffId;
-		$this->user = $staff;
-		$this->userId = $userId;
-		$this->merchantId = 12359;
-		return parent::beforeAction($action);
-	}
+
+    public $staff, $staffId, $userId, $user, $merchantId, $merchant;
+    public $isLogin = false;
+    public $withoutLogin = [];//不需要登陆的方法名
+    public $validate = true;
+    public $wxOpenId = 1;
+    public $wxOpen;
+
+    public function beforeAction($action)
+    {
+        //token验证
+        $staffId = jwt::getLoginId();
+        $userId = $staffId;
+        if (empty($staffId)) {
+            $this->validate = false;
+        }
+        //游客可以访问的方法
+        if (in_array($action->id, $this->withoutLogin)) {
+            $this->validate = true;
+        }
+        if ($this->validate == false) {
+            util::notLogin();
+        }
+        if (!empty($userId)) {
+            $staff = UserService::getUserInfo($userId);
+            $this->staff = $staff;
+            $this->user = $staff;
+        }
+        $this->staffId = $staffId;
+        $this->userId = $userId;
+        $open = WxOpenService::getById($this->wxOpenId);
+        $this->wxOpen = $open;
+        $merchantId = isset($open['merchantId']) ? $open['merchantId'] : 0;
+        $this->merchantId = $merchantId;
+        if (!empty($merchantId)) {
+            $this->merchant = MerchantService::getById($merchantId);
+        }
+        return parent::beforeAction($action);
+    }
 
 }