BaseController.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. $adminId = 1;
  40. if (empty($adminId)) {
  41. $this->validate = false;
  42. }
  43. //游客可以访问的方法
  44. if (in_array($action->id, $this->withoutLogin)) {
  45. $this->validate = true;
  46. }
  47. if ($this->validate == false) {
  48. util::notLogin();
  49. }
  50. $admin = AdminService::getById($adminId);
  51. if (empty($admin)) {
  52. util::fail('没有找到管理员');
  53. }
  54. $merchantId = AdminToMerchantService::getDefaultMerchant($adminId);
  55. if (empty($merchantId)) {
  56. util::fail('没有找到商家信息');
  57. }
  58. $merchant = MerchantService::getById($merchantId);
  59. Yii::$app->params['adminId'] = $adminId;
  60. Yii::$app->params['admin'] = $admin;
  61. Yii::$app->params['merchantId'] = $merchantId;
  62. Yii::$app->params['merchant'] = $merchant;
  63. $this->adminId = $adminId;
  64. $this->merchantId = $merchantId;
  65. return parent::beforeAction($action);
  66. }
  67. }