BaseController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 $sjId = 0, $sj, $sjExtend, $signPackage, $shopId = 0;
  18. public $appId;
  19. public $isWx = false;
  20. public $isLogin = false;
  21. public $withoutLoginAction = [];//不需要登陆的方法名
  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. $sjId = 0;
  31. $sj = [];
  32. $sjExtend = [];
  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. //取不到门店id可能被清缓存,需要重新登陆,$shopId = 0 则表示非管理员,没有关联的门店,只可以访问官网
  42. $shopId = $admin['currentShopId'] ?? 0;
  43. if (is_numeric($shopId) == false) {
  44. util::notLogin('登陆已失效,请重新登陆');
  45. }
  46. if (!empty($shopId)) {
  47. $shop = ShopService::getById($shopId);
  48. if (empty($shop)) {
  49. util::fail('没有找到您的门店');
  50. }
  51. $sjId = $shop['merchantId'];
  52. $sj = MerchantService::getMerchantById($sjId);
  53. $sjExtend = MerchantExtendService::getByMerchantId($sjId);
  54. }
  55. $this->shopId = $shopId;
  56. }
  57. //游客可以访问的方法
  58. if (in_array($action->id, $this->withoutLoginAction)) {
  59. $this->validate = true;
  60. }
  61. if ($this->validate == false) {
  62. util::notLogin();
  63. }
  64. $this->admin = $admin;
  65. $this->adminId = $adminId;
  66. $this->sjId = $sjId;
  67. $this->sj = $sj;
  68. $this->sjExtend = $sjExtend;
  69. return parent::beforeAction($action);
  70. }
  71. }