BaseController.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\merchant\services\MerchantExtendService;
  4. use biz\merchant\services\MerchantService;
  5. use bizGhs\merchant\services\ShopService;
  6. use biz\wx\services\WxOpenService;
  7. use bizGhs\admin\services\AdminService;
  8. use bizGhs\shop\services\ShopAdminService;
  9. use common\components\jwt;
  10. use common\components\noticeUtil;
  11. use common\components\stringUtil;
  12. use Yii;
  13. use common\components\util;
  14. class BaseController extends PublicController
  15. {
  16. public $admin, $adminId, $adminAvatar, $account;
  17. public $ghsId = 0, $ghsName, $ghs, $ghsExtend, $ghsLogo, $signPackage, $shopId = 0;
  18. public $appId;
  19. public $isWx = false;
  20. public $isLogin = false;
  21. public $withoutLogin = [];//不需要登陆的方法名
  22. public $validate = true;
  23. //shish 2020.3.8
  24. public function beforeAction($action)
  25. {
  26. //token验证
  27. //$adminId = jwt::getLoginId();
  28. //模拟用户
  29. $adminId = 1;
  30. $ghsId = 0;
  31. $ghs = [];
  32. $ghsExtend = [];
  33. $admin = [];
  34. if (empty($adminId)) {
  35. $this->validate = false;
  36. } else {
  37. $admin = AdminService::getById($adminId);
  38. if (empty($admin)) {
  39. util::fail('帐号无效');
  40. }
  41. $adminId = $admin['id'];
  42. //$shopId = Yii::$app->redis->executeCommand('GET', ['LOGIN_ADMIN_SHOP' . $adminId]);
  43. //取不到门店id可能被清缓存,需要重新登陆,$shopId = 0 则表示非管理员,没有关联的门店,只可以访问官网
  44. $staff = ShopAdminService::getByCondition(['adminId' => $adminId]);
  45. $shopId = isset($staff['shopId']) ? $staff['shopId'] : 0;
  46. if (is_numeric($shopId) == false) {
  47. util::notLogin('登陆已失效,请重新登陆');
  48. }
  49. if (!empty($shopId)) {
  50. $shop = ShopService::getById($shopId);
  51. if (empty($shop)) {
  52. util::fail('没有找到门店');
  53. }
  54. $ghsId = $shop['ghsId'];
  55. $ghs = MerchantService::getMerchantById($ghsId);
  56. $ghsExtend = MerchantExtendService::getByMerchantId($ghsId);
  57. }
  58. $this->shopId = $shopId;
  59. }
  60. //游客可以访问的方法
  61. if (in_array($action->id, $this->withoutLogin)) {
  62. $this->validate = true;
  63. }
  64. if ($this->validate == false) {
  65. util::notLogin('您还没有登陆哦');
  66. }
  67. $this->admin = $admin;
  68. $this->adminId = $adminId;
  69. $this->ghsId = $ghsId;
  70. $this->ghs = $ghs;
  71. $this->ghsExtend = $ghsExtend;
  72. return parent::beforeAction($action);
  73. }
  74. }