BaseController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. $currentShopId = $admin->currentGhsShopId ?? 0;
  45. if (empty($currentShopId)) {
  46. if (in_array($action->id, $this->guestAccess) == false) {
  47. util::fail('请注册登录');
  48. }
  49. } else {
  50. $this->shopId = $currentShopId;
  51. $shop = ShopClass::getById($currentShopId, true);
  52. if (empty($shop)) {
  53. util::fail('没有找到您的门店');
  54. }
  55. $this->shop = $shop;
  56. $mainId = $shop->mainId ?? 0;
  57. $this->mainId = $mainId;
  58. $main = MainClass::getById($mainId, true);
  59. if (empty($main)) {
  60. util::fail('没有main信息,shopId:' . $this->shopId);
  61. }
  62. $this->main = $main;
  63. $shopExt = ShopExtClass::getByCondition(['shopId' => $currentShopId], true);
  64. if (empty($shopExt)) {
  65. util::fail('门店信息有问题,请联系管理员');
  66. }
  67. $this->shopExt = $shopExt;
  68. $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId, 'delStatus' => 0], true);
  69. if (empty($shopAdmin)) {
  70. util::logout('没有找到员工');
  71. }
  72. if (isset($shopAdmin->delStatus) && $shopAdmin->delStatus == 1) {
  73. util::fail('您还不是员工');
  74. }
  75. if (isset($shopAdmin->status) && $shopAdmin->status == 0) {
  76. util::fail('您的帐号已被禁用');
  77. }
  78. $this->shopAdmin = $shopAdmin;
  79. $this->shopAdminId = $shopAdmin->id ?? 0;
  80. $sjId = $shop->sjId;
  81. $this->sjId = $sjId;
  82. $sj = SjClass::getById($sjId, true);
  83. $this->sj = $sj;
  84. $sjExtend = MerchantExtendService::getBySjId($sjId, true);
  85. $this->sjExtend = $sjExtend;
  86. }
  87. return parent::beforeAction($action);
  88. }
  89. }