BaseController.php 3.7 KB

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