| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace mobile\controllers;
- use biz\merchant\services\MerchantService;
- use biz\user\services\UserService;
- use common\components\httpUtil;
- use common\components\jwt;
- use common\components\util;
- /**
- * Created by PhpStorm.
- * User: shish <shish@zhhinc.com>
- * Date: 2019/11/18 0018
- * Time: 14:58
- */
- class BaseController extends PublicController
- {
-
- public $validate = true;
- public $withoutLogin = [];//不需要登陆可以访问的方法
- public $userId, $user;
- public $merchantId, $merchant;
- public $isWeixin;
-
- public function beforeAction($action)
- {
- //token验证
- $userId = jwt::checkLogin();
-
- $header = httpUtil::getHeader();
- $account = isset($header['account']) ? $header['account'] : 0;
- if (empty($account)) {
- util::fail('商家无效');
- }
- $merchant = MerchantService::getById($account);
- if (empty($merchant)) {
- util::fail('商家信息无效');
- }
- $this->merchantId = $account;
- $this->merchant = $merchant;
-
- $this->isWeixin = util::isWeixin();
-
- 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);
- }
- }
|