BaseController.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. if (empty($account)) {
  31. util::fail('商家无效');
  32. }
  33. $merchant = MerchantService::getById($account);
  34. if (empty($merchant)) {
  35. util::fail('商家信息无效');
  36. }
  37. $this->merchantId = $account;
  38. $this->merchant = $merchant;
  39. $this->merchantExtend = MerchantExtendService::getByMerchantId($account);
  40. Yii::$app->params['merchantId'] = $account;
  41. Yii::$app->params['merchant'] = $merchant;
  42. $this->isWeixin = util::isWeixin();
  43. if (empty($userId)) {
  44. $this->validate = false;
  45. } else {
  46. $this->validate = true;
  47. $this->userId = $userId;
  48. $this->user = UserService::getById($userId);
  49. }
  50. //游客可以访问的方法
  51. if (in_array($action->id, $this->withoutLogin)) {
  52. $this->validate = true;
  53. }
  54. if ($this->validate == false) {
  55. util::notLogin();
  56. }
  57. return parent::beforeAction($action);
  58. }
  59. }