BaseController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace client\controllers;
  3. use Yii;
  4. use biz\merchant\services\MerchantExtendService;
  5. use biz\merchant\services\MerchantService;
  6. use biz\user\services\UserService;
  7. use common\components\httpUtil;
  8. use common\components\jwt;
  9. use common\components\util;
  10. /**
  11. * Created by PhpStorm.
  12. * User: shish <shish@zhhinc.com>
  13. * Date: 2019/11/18 0018
  14. * Time: 14:58
  15. */
  16. class BaseController extends PublicController
  17. {
  18. public $validate = true;
  19. public $withoutLogin = [];//不需要登陆可以访问的方法
  20. public $userId, $user;
  21. public $merchantId, $merchant, $merchantExtend;
  22. public $isWeixin;
  23. public function beforeAction($action)
  24. {
  25. //token验证
  26. //$userId = jwt::getLoginId();
  27. $userId = 12536630;
  28. $header = httpUtil::getHeader();
  29. $account = isset($header['account']) ? $header['account'] : 0;
  30. $account = 12358;
  31. if (empty($account)) {
  32. util::fail('商家无效');
  33. }
  34. $merchant = MerchantService::getMerchantById($account);
  35. if (empty($merchant)) {
  36. util::fail('商家信息无效');
  37. }
  38. $this->merchantId = $account;
  39. $this->merchant = $merchant;
  40. $this->merchantExtend = MerchantExtendService::getByMerchantId($account);
  41. Yii::$app->params['merchantId'] = $account;
  42. Yii::$app->params['merchant'] = $merchant;
  43. Yii::$app->params['userId'] = $userId;
  44. $this->isWeixin = util::isWeixin();
  45. if (empty($userId)) {
  46. $this->validate = false;
  47. } else {
  48. $this->validate = true;
  49. $this->userId = $userId;
  50. $this->user = UserService::getUserInfo($userId);
  51. }
  52. //游客可以访问的方法
  53. if (in_array($action->id, $this->withoutLogin)) {
  54. $this->validate = true;
  55. }
  56. if ($this->validate == false) {
  57. util::notLogin();
  58. }
  59. return parent::beforeAction($action);
  60. }
  61. }