BaseController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. //token验证
  31. $adminId = jwt::getLoginId();
  32. if (empty($adminId)) {
  33. util::notLogin();
  34. }
  35. $sjId = 0;
  36. $sj = [];
  37. $sjExtend = [];
  38. $currentShopId = 0;
  39. $admin = AdminClass::getAdminById($adminId, true);
  40. if (empty($admin)) {
  41. util::notLogin();
  42. }
  43. $adminId = $admin['id'];
  44. $this->admin = $admin;
  45. $this->adminId = $adminId;
  46. $header = httpUtil::getHeader();
  47. $shopId = $header['shop-id'] ?? 0;
  48. if (!empty($shopId)) {
  49. //商城
  50. if (in_array($action->id, $this->guestAccessAction) == false) {
  51. util::fail('您没有权限访问哦');
  52. }
  53. $shop = ShopClass::getById($shopId);
  54. if (empty($shop)) {
  55. util::fail('没有找到店铺');
  56. }
  57. $sjId = $shop['merchantId'] ?? 0;
  58. $custom = CustomClass::getCustom(['sjId' => $sjId, 'adminId' => $adminId]);
  59. $customId = $custom['id'] ?? 0;
  60. if (empty($customId)) {
  61. util::fail('没有找到客户信息');
  62. }
  63. $this->custom = $custom;
  64. $this->customId = $customId;
  65. $this->sjId = $sjId;
  66. $sj = MerchantService::getMerchantById($sjId);
  67. $this->sj = $sj;
  68. $this->sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  69. } else {
  70. //后台
  71. $currentShopId = $admin['currentShopId'] ?? 0;
  72. if (empty($currentShopId) && in_array($action->id, $this->guestAccessAction) == false) {
  73. util::fail('您没有权限访问哦~');
  74. }
  75. $this->shopId = $currentShopId;
  76. $shop = ShopService::getById($currentShopId);
  77. if (empty($shop)) {
  78. util::fail('没有找到店铺');
  79. }
  80. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId, 'delStatus' => 0]);
  81. if (empty($shopAdmin)) {
  82. util::fail('没有找到员工信息');
  83. }
  84. $this->shopAdmin = $shopAdmin;
  85. $this->shopAdminId = $shopAdmin['id'] ?? 0;
  86. $sjId = $shop['merchantId'];
  87. $this->sjId = $sjId;
  88. $sj = MerchantService::getMerchantById($sjId);
  89. $this->sj = $sj;
  90. $sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  91. $this->sjExtend = $sjExtend;
  92. }
  93. return parent::beforeAction($action);
  94. }
  95. }