BaseController.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 bizHd\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. //$adminId = 18;
  32. if (empty($adminId)) {
  33. util::notLogin();
  34. }
  35. $this->adminId = $adminId;
  36. $admin = AdminService::getById($adminId);
  37. if (empty($admin)) {
  38. util::fail('帐号无效');
  39. }
  40. $this->admin = $admin;
  41. $header = httpUtil::getHeader();
  42. $lookShopId = $header['shop-id'] ?? 0;
  43. if (!empty($lookShopId)) {
  44. //商城和下单页
  45. if (in_array($action->id, $this->guestAccessAction) == false) {
  46. util::fail('您没有权限访问哦~');
  47. }
  48. $shop = ShopClass::getById($lookShopId);
  49. if (empty($shop)) {
  50. util::fail('没有找到店铺');
  51. }
  52. $this->lookShopId = $lookShopId;
  53. $sjId = $shop['merchantId'] ?? 0;
  54. $sj = MerchantService::getMerchantById($sjId);
  55. $sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  56. } else {
  57. //后台
  58. $currentShopId = $admin['currentShopId'] ?? 0;
  59. if (empty($currentShopId) && in_array($action->id, $this->guestAccessAction) == false) {
  60. util::fail('您没有权限访问哦!');
  61. }
  62. $this->shopId = $currentShopId;
  63. $shop = ShopService::getById($currentShopId);
  64. if (empty($shop)) {
  65. util::fail('没有找到您管理的门店');
  66. }
  67. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId, 'delStatus' => 0]);
  68. if (empty($shopAdmin)) {
  69. util::fail('没有找到员工信息');
  70. }
  71. $this->shopAdmin = $shopAdmin;
  72. $this->shopAdminId = $shopAdmin['id'] ?? 0;
  73. $sjId = $shop['merchantId'];
  74. $this->sjId = $sjId;
  75. $sj = MerchantService::getMerchantById($sjId);
  76. $this->sj = $sj;
  77. $sjExtend = MerchantExtendService::getByMerchantId($sjId);
  78. $this->sjExtend = $sjExtend;
  79. }
  80. return parent::beforeAction($action);
  81. }
  82. }