BaseController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace shop\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\admin\services\ShopAdminService;
  5. use biz\custom\classes\CustomClass;
  6. use bizTy\sj\classes\MerchantExtendClass;
  7. use biz\merchant\classes\ShopClass;
  8. use biz\merchant\services\AdminService;
  9. use bizTy\sj\services\MerchantExtendService;
  10. use bizTy\sj\services\MerchantService;
  11. use biz\merchant\services\ShopService;
  12. use biz\wx\services\WxOpenService;
  13. use common\components\httpUtil;
  14. use common\components\jwt;
  15. use Yii;
  16. use common\components\util;
  17. class BaseController extends PublicController
  18. {
  19. public $admin, $adminId, $adminAvatar, $account, $customId = 0, $custom;
  20. public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0;
  21. public $appId;
  22. public $isWx = false;
  23. public $isLogin = false;
  24. //游客可以访问的方法
  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. $sjId = 0;
  35. $sj = [];
  36. $sjExtend = [];
  37. $currentShopId = 0;
  38. $admin = AdminClass::getAdminById($adminId, true);
  39. if (empty($admin)) {
  40. util::notLogin();
  41. }
  42. $adminId = $admin['id'];
  43. $this->admin = $admin;
  44. $this->adminId = $adminId;
  45. $header = httpUtil::getHeader();
  46. $shopId = $header['shop-id'] ?? 0;
  47. if (!empty($shopId)) {
  48. //商城
  49. if (in_array($action->id, $this->guestAccessAction) == false) {
  50. util::fail('您没有权限访问哦');
  51. }
  52. $shop = ShopClass::getById($shopId);
  53. if (empty($shop)) {
  54. util::fail('没有找到店铺');
  55. }
  56. $sjId = $shop['merchantId'] ?? 0;
  57. $custom = CustomClass::getCustom(['sjId' => $sjId, 'adminId' => $adminId]);
  58. $customId = $custom['id'] ?? 0;
  59. if (empty($customId)) {
  60. util::fail('没有找到客户信息');
  61. }
  62. $this->custom = $custom;
  63. $this->customId = $customId;
  64. $this->sjId = $sjId;
  65. $sj = MerchantService::getMerchantById($sjId);
  66. $this->sj = $sj;
  67. $this->sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  68. } else {
  69. //后台
  70. $currentShopId = $admin['currentShopId'] ?? 0;
  71. if (empty($currentShopId) && in_array($action->id, $this->guestAccessAction) == false) {
  72. util::fail('您没有权限访问哦~');
  73. }
  74. $this->shopId = $currentShopId;
  75. $shop = ShopService::getById($currentShopId);
  76. if (empty($shop)) {
  77. util::fail('没有找到店铺');
  78. }
  79. $sjId = $shop['merchantId'];
  80. $this->sjId = $sjId;
  81. $sj = MerchantService::getMerchantById($sjId);
  82. $this->sj = $sj;
  83. $sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  84. $this->sjExtend = $sjExtend;
  85. }
  86. return parent::beforeAction($action);
  87. }
  88. }