BaseController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\admin\classes\AdminClass;
  4. use bizHd\admin\services\ShopAdminService;
  5. use bizHd\custom\classes\CustomClass;
  6. use biz\shop\classes\ShopAdminClass;
  7. use biz\sj\classes\MerchantExtendClass;
  8. use bizHd\merchant\classes\ShopClass;
  9. use bizHd\merchant\services\AdminService;
  10. use biz\sj\services\MerchantExtendService;
  11. use biz\sj\services\MerchantService;
  12. use bizHd\merchant\services\ShopService;
  13. use bizHd\wx\services\WxOpenService;
  14. use common\components\httpUtil;
  15. use common\components\jwt;
  16. use Yii;
  17. use common\components\util;
  18. class BaseController extends PublicController
  19. {
  20. public $admin, $adminId, $adminAvatar, $account, $customId = 0, $custom;
  21. public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0, $shopAdminId = 0, $shopAdmin = [];
  22. public $appId;
  23. public $isWx = false;
  24. public $isLogin = false;
  25. //游客可以访问的方法
  26. public $guestAccessAction = [];
  27. //shish 2020.3.8
  28. public function beforeAction($action)
  29. {
  30. //定义平台类型 1花店 2供货商
  31. Yii::$app->params['ptStyle'] = 1;
  32. //token验证
  33. $adminId = jwt::getLoginId();
  34. if (empty($adminId)) {
  35. util::notLogin();
  36. }
  37. $sjId = 0;
  38. $sj = [];
  39. $sjExtend = [];
  40. $currentShopId = 0;
  41. $admin = AdminClass::getAdminById($adminId, true);
  42. if (empty($admin)) {
  43. util::notLogin();
  44. }
  45. $adminId = $admin['id'];
  46. $this->admin = $admin;
  47. $this->adminId = $adminId;
  48. $header = httpUtil::getHeader();
  49. $shopId = $header['shop-id'] ?? 0;
  50. if (!empty($shopId)) {
  51. //商城
  52. if (in_array($action->id, $this->guestAccessAction) == false) {
  53. util::fail('您没有权限访问哦');
  54. }
  55. $shop = ShopClass::getById($shopId);
  56. if (empty($shop)) {
  57. util::fail('没有找到店铺');
  58. }
  59. $sjId = $shop['merchantId'] ?? 0;
  60. $custom = CustomClass::getCustom(['sjId' => $sjId, 'adminId' => $adminId]);
  61. $customId = $custom['id'] ?? 0;
  62. if (empty($customId)) {
  63. util::fail('没有找到客户信息');
  64. }
  65. $this->custom = $custom;
  66. $this->customId = $customId;
  67. $this->sjId = $sjId;
  68. $sj = MerchantService::getMerchantById($sjId);
  69. $this->sj = $sj;
  70. $this->sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  71. } else {
  72. //后台
  73. $currentShopId = $admin['currentShopId'] ?? 0;
  74. if (empty($currentShopId) && in_array($action->id, $this->guestAccessAction) == false) {
  75. util::fail('您没有权限访问哦~');
  76. }
  77. $this->shopId = $currentShopId;
  78. $shop = ShopService::getById($currentShopId);
  79. if (empty($shop)) {
  80. util::fail('没有找到店铺');
  81. }
  82. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId, 'delStatus' => 0]);
  83. if (empty($shopAdmin)) {
  84. util::fail('没有找到员工信息');
  85. }
  86. $this->shopAdmin = $shopAdmin;
  87. $this->shopAdminId = $shopAdmin['id'] ?? 0;
  88. $sjId = $shop['merchantId'];
  89. $this->sjId = $sjId;
  90. $sj = MerchantService::getMerchantById($sjId);
  91. $this->sj = $sj;
  92. $sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  93. $this->sjExtend = $sjExtend;
  94. }
  95. return parent::beforeAction($action);
  96. }
  97. }