BaseController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace hd\controllers;
  3. use biz\admin\classes\AdminClass as ClassesAdminClass;
  4. use bizHd\admin\classes\AdminClass;
  5. use biz\shop\classes\ShopAdminClass;
  6. use biz\sj\classes\MerchantExtendClass;
  7. use biz\sj\services\MerchantService;
  8. use bizHd\merchant\services\ShopService;
  9. use common\components\jwt;
  10. use Yii;
  11. use common\components\util;
  12. class BaseController extends PublicController
  13. {
  14. public $admin, $adminId, $adminAvatar, $account, $customId = 0, $custom;
  15. public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0, $shop = [], $shopAdminId = 0, $shopAdmin = [];
  16. public $appId;
  17. public $isWx = false;
  18. public $isLogin = false;
  19. //游客可以访问的方法
  20. public $guestAccess = [];
  21. //ssh 2020.3.8
  22. public function beforeAction($action)
  23. {
  24. //定义平台类型 1花店 2供货商 3商城
  25. Yii::$app->params['ptStyle'] = 1;
  26. //token验证
  27. $adminId = jwt::getLoginId();
  28. if (getenv('YII_ENV', 'local') != 'production') {
  29. //$adminId = 18;
  30. }
  31. if (empty($adminId)) {
  32. util::notLogin();
  33. }
  34. $admin = AdminClass::getAdminById($adminId);
  35. if (empty($admin)) {
  36. util::notLogin();
  37. }
  38. $adminId = $admin['id'];
  39. $this->admin = $admin;
  40. $this->adminId = $adminId;
  41. // 只能供货商访问
  42. if ($admin['style'] != ClassesAdminClass::STYLE_HD) {
  43. util::fail('您没有权限访问哦!');
  44. }
  45. //后台
  46. $currentShopId = $admin['currentShopId'] ?? 0;
  47. if (empty($currentShopId)) {
  48. if (in_array($action->id, $this->guestAccess) == false) {
  49. util::fail('您不是员工没有权限访问');
  50. }
  51. } else {
  52. $this->shopId = $currentShopId;
  53. $shop = ShopService::getById($currentShopId);
  54. $this->shop = $shop;
  55. if (empty($shop)) {
  56. util::fail('没有找到店铺');
  57. }
  58. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId]);
  59. if (empty($shopAdmin)) {
  60. util::logout('没有找到员工信息');
  61. }
  62. if (isset($shopAdmin['delStatus']) && $shopAdmin['delStatus'] == 1) {
  63. util::fail('您还不是员工哦');
  64. }
  65. if (isset($shopAdmin['status']) && $shopAdmin['status'] == 0) {
  66. util::fail('您的帐号已被禁用');
  67. }
  68. $this->shopAdmin = $shopAdmin;
  69. $this->shopAdminId = $shopAdmin['id'] ?? 0;
  70. $sjId = $shop['merchantId'];
  71. $this->sjId = $sjId;
  72. $sj = MerchantService::getMerchantById($sjId);
  73. $this->sj = $sj;
  74. $sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  75. $this->sjExtend = $sjExtend;
  76. }
  77. return parent::beforeAction($action);
  78. }
  79. }