BaseController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopAdminClass;
  4. use biz\shop\classes\ShopClass;
  5. use biz\shop\classes\ShopExtClass;
  6. use biz\sj\classes\SjClass;
  7. use biz\sj\services\MerchantExtendService;
  8. use bizGhs\admin\services\AdminService;
  9. use bizGhs\shop\classes\MainClass;
  10. use common\components\dict;
  11. use common\components\jwt;
  12. use Yii;
  13. use common\components\util;
  14. class BaseController extends PublicController
  15. {
  16. public $admin, $adminId, $adminAvatar, $account;
  17. public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shop = [], $shopExt = [], $shopId = 0, $mainId = 0, $main = [], $lookShopId = 0, $shopAdminId = 0, $shopAdmin = [];
  18. public $appId;
  19. public $isWx = false;
  20. public $isLogin = false;
  21. //不需要登陆的方法名
  22. public $guestAccess = [];
  23. //ssh 2020.3.8
  24. public function beforeAction($action)
  25. {
  26. //定义平台类型 1花店 2供货商
  27. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  28. $headers = Yii::$app->getRequest()->getHeaders();
  29. $requestVersion = $headers->get('appVersion');
  30. $currentVersion = dict::getDict('appVersion');
  31. if ($requestVersion < $currentVersion) {
  32. util::fail('请先升级系统');
  33. }
  34. //token验证
  35. $adminId = jwt::getLoginId();
  36. if (getenv('YII_ENV', 'local') == 'local') {
  37. //$adminId = 730;
  38. }
  39. if (empty($adminId) && in_array($action->id, $this->guestAccess) == false) {
  40. util::notLogin();
  41. }
  42. $this->adminId = $adminId;
  43. $admin = AdminService::getById($adminId, true);
  44. if (empty($admin) && in_array($action->id, $this->guestAccess) == false) {
  45. util::logout('帐号无效');
  46. }
  47. $this->admin = $admin;
  48. //后台
  49. $currentShopId = $admin->currentGhsShopId ?? 0;
  50. if (empty($currentShopId)) {
  51. if (in_array($action->id, $this->guestAccess) == false) {
  52. util::fail('请注册登录');
  53. }
  54. } else {
  55. $this->shopId = $currentShopId;
  56. $shop = ShopClass::getById($currentShopId, true);
  57. if (empty($shop)) {
  58. util::fail('没有找到您的门店');
  59. }
  60. $this->shop = $shop;
  61. $mainId = $shop->mainId ?? 0;
  62. $this->mainId = $mainId;
  63. $main = MainClass::getById($mainId, true);
  64. if (empty($main)) {
  65. util::fail('没有main信息,shopId:' . $this->shopId);
  66. }
  67. $this->main = $main;
  68. $shopExt = ShopExtClass::getByCondition(['shopId' => $currentShopId], true);
  69. if (empty($shopExt)) {
  70. util::fail('门店信息有问题,请联系管理员');
  71. }
  72. $this->shopExt = $shopExt;
  73. $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId, 'delStatus' => 0], true);
  74. if (empty($shopAdmin)) {
  75. util::logout('没有找到员工');
  76. }
  77. if (isset($shopAdmin->delStatus) && $shopAdmin->delStatus == 1) {
  78. util::fail('您不是本店员工哦');
  79. }
  80. if (isset($shopAdmin->status) && $shopAdmin->status == 0) {
  81. util::fail('您已被平台禁止登录');
  82. }
  83. $this->shopAdmin = $shopAdmin;
  84. $this->shopAdminId = $shopAdmin->id ?? 0;
  85. $sjId = $shop->sjId;
  86. $this->sjId = $sjId;
  87. $sj = SjClass::getById($sjId, true);
  88. $this->sj = $sj;
  89. $sjExtend = MerchantExtendService::getBySjId($sjId, true);
  90. $this->sjExtend = $sjExtend;
  91. }
  92. return parent::beforeAction($action);
  93. }
  94. }