BaseController.php 2.6 KB

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