BaseController.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace ghs\controllers;
  3. use bizTy\shop\classes\ShopClass;
  4. use bizTy\sj\classes\MerchantExtendClass;
  5. use bizTy\sj\services\MerchantExtendService;
  6. use bizTy\sj\services\MerchantService;
  7. use bizGhs\merchant\services\ShopService;
  8. use biz\wx\services\WxOpenService;
  9. use bizGhs\admin\services\AdminService;
  10. use bizGhs\shop\services\ShopAdminService;
  11. use common\components\httpUtil;
  12. use common\components\jwt;
  13. use common\components\noticeUtil;
  14. use common\components\stringUtil;
  15. use Yii;
  16. use common\components\util;
  17. class BaseController extends PublicController
  18. {
  19. public $admin, $adminId, $adminAvatar, $account;
  20. public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0, $lookShopId = 0;
  21. public $appId;
  22. public $isWx = false;
  23. public $isLogin = false;
  24. public $guestAccessAction = [];//不需要登陆的方法名
  25. //shish 2020.3.8
  26. public function beforeAction($action)
  27. {
  28. //token验证
  29. $adminId = jwt::getLoginId();
  30. if (empty($adminId)) {
  31. util::notLogin();
  32. }
  33. $this->adminId = $adminId;
  34. $admin = AdminService::getById($adminId);
  35. if (empty($admin)) {
  36. util::fail('帐号无效');
  37. }
  38. $this->admin = $admin;
  39. $header = httpUtil::getHeader();
  40. $lookShopId = $header['shop-id'] ?? 0;
  41. if (!empty($lookShopId)) {
  42. //商城和下单页
  43. if (in_array($action->id, $this->guestAccessAction) == false) {
  44. util::fail('您没有权限访问哦~');
  45. }
  46. $shop = ShopClass::getById($lookShopId);
  47. if (empty($shop)) {
  48. util::fail('没有找到店铺');
  49. }
  50. $this->lookShopId = $lookShopId;
  51. $sjId = $shop['merchantId'] ?? 0;
  52. $sj = MerchantService::getMerchantById($sjId);
  53. $sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  54. } else {
  55. //后台
  56. $currentShopId = $admin['currentShopId'] ?? 0;
  57. if (empty($currentShopId) && in_array($action->id, $this->guestAccessAction) == false) {
  58. util::fail('您没有权限访问哦!');
  59. }
  60. $this->shopId = $currentShopId;
  61. $shop = ShopService::getById($currentShopId);
  62. if (empty($shop)) {
  63. util::fail('没有找到您管理的门店');
  64. }
  65. $sjId = $shop['merchantId'];
  66. $this->sjId = $sjId;
  67. $sj = MerchantService::getMerchantById($sjId);
  68. $this->sj = $sj;
  69. $sjExtend = MerchantExtendService::getByMerchantId($sjId);
  70. $this->sjExtend = $sjExtend;
  71. }
  72. return parent::beforeAction($action);
  73. }
  74. }