BaseController.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace admin\controllers;
  3. use biz\admin\services\AdminToMerchantService;
  4. use biz\auth\services\MenuService;
  5. use biz\goods\services\CategoryRelateService;
  6. use biz\goods\services\UsageRelationService;
  7. use biz\merchant\services\AdminService;
  8. use biz\merchant\services\MerchantService;
  9. use common\components\error;
  10. use common\components\jwt;
  11. use common\components\stringUtil;
  12. use common\components\validate;
  13. use common\services\xhUserService;
  14. use Yii;
  15. use common\services\xhWxOpenService;
  16. use common\services\xhMerchantAssetService;
  17. use common\services\xhMerchantExtendService;
  18. use common\services\xhMerchantService;
  19. use common\services\xhAdminService;
  20. use common\components\util;
  21. use common\components\weixinUtil;
  22. use common\components\jsSDK;
  23. use common\services\xhAdminToMerchantService;
  24. use yii\web\Cookie;
  25. class BaseController extends PublicController
  26. {
  27. public $admin, $adminId, $adminAvatar, $account;
  28. public $merchantId = 0, $merchantName, $merchant, $merchantExtend, $merchantAsset, $merchantLogo, $signPackage;
  29. public $openMerchant, $openMerchantId;
  30. public $appId;
  31. public $isWeixin = false;
  32. public $isLogin = false;
  33. public $withoutLogin = [];//不需要登陆的方法名
  34. public $validate = true;
  35. public function beforeAction($action)
  36. {
  37. //token验证
  38. $adminId = jwt::getLoginId();
  39. if (empty($adminId)) {
  40. $this->validate = false;
  41. }
  42. //游客可以访问的方法
  43. if (in_array($action->id, $this->withoutLogin)) {
  44. $this->validate = true;
  45. }
  46. if ($this->validate == false) {
  47. util::notLogin();
  48. }
  49. $admin = AdminService::getById($adminId);
  50. if (empty($admin)) {
  51. util::fail('没有找到管理员');
  52. }
  53. $merchantId = AdminToMerchantService::getDefaultMerchant($adminId);
  54. if (empty($merchantId)) {
  55. util::fail('没有找到商家信息');
  56. }
  57. $merchant = MerchantService::getById($merchantId);
  58. Yii::$app->params['adminId'] = $adminId;
  59. Yii::$app->params['admin'] = $admin;
  60. Yii::$app->params['merchantId'] = $merchantId;
  61. Yii::$app->params['merchant'] = $merchant;
  62. $this->adminId = $adminId;
  63. $this->merchantId = $merchantId;
  64. return parent::beforeAction($action);
  65. }
  66. }