BaseController.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace open\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. class BaseController extends PublicController
  11. {
  12. public $validate = true;
  13. public $withoutLogin = [];//不需要登陆可以访问的方法
  14. public $userId, $user;
  15. public $merchantId, $merchant, $merchantExtend;
  16. public $isWeixin;
  17. public function beforeAction($action)
  18. {
  19. //token验证
  20. //$userId = jwt::getLoginId();
  21. $userId = 12536630;
  22. $account = 12358;
  23. if (empty($account)) {
  24. util::fail('商家无效');
  25. }
  26. $merchant = MerchantService::getById($account);
  27. if (empty($merchant)) {
  28. util::fail('商家信息无效');
  29. }
  30. $this->merchantId = $account;
  31. $this->merchant = $merchant;
  32. $this->merchantExtend = MerchantExtendService::getByMerchantId($account);
  33. $this->isWeixin = util::isWeixin();
  34. if (empty($userId)) {
  35. $this->validate = false;
  36. } else {
  37. $this->validate = true;
  38. $this->userId = $userId;
  39. $this->user = UserService::getById($userId);
  40. }
  41. //游客可以访问的方法
  42. if (in_array($action->id, $this->withoutLogin)) {
  43. $this->validate = true;
  44. }
  45. if ($this->validate == false) {
  46. util::notLogin();
  47. }
  48. return parent::beforeAction($action);
  49. }
  50. }