BaseController.php 1.5 KB

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