BaseController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\shop\classes\ShopAdminClass;
  5. use biz\shop\classes\ShopClass;
  6. use biz\sj\classes\SjClass;
  7. use biz\sj\services\MerchantExtendService;
  8. use biz\sj\services\MerchantService;
  9. use bizGhs\admin\services\AdminService;
  10. use common\components\jwt;
  11. use Yii;
  12. use common\components\util;
  13. class BaseController extends PublicController
  14. {
  15. public $admin, $adminId, $adminAvatar, $account;
  16. public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shop = [], $shopId = 0, $lookShopId = 0, $shopAdminId = 0, $shopAdmin = [];
  17. public $appId;
  18. public $isWx = false;
  19. public $isLogin = false;
  20. public $guestAccess = [];//不需要登陆的方法名
  21. //ssh 2020.3.8
  22. public function beforeAction($action)
  23. {
  24. //定义平台类型 1花店 2供货商
  25. Yii::$app->params['ptStyle'] = 2;
  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. $this->adminId = $adminId;
  35. $admin = AdminService::getById($adminId, true);
  36. if (empty($admin)) {
  37. util::logout('帐号无效');
  38. }
  39. $this->admin = $admin;
  40. // 只能供货商访问
  41. if ($admin->style != AdminClass::STYLE_GHS) {
  42. util::fail('您没有权限访问哦!');
  43. }
  44. //后台
  45. $currentShopId = $admin->currentShopId ?? 0;
  46. if (empty($currentShopId)) {
  47. if (in_array($action->id, $this->guestAccess) == false) {
  48. util::fail('您没有权限访问哦!');
  49. }
  50. } else {
  51. $this->shopId = $currentShopId;
  52. $shop = ShopClass::getById($currentShopId, true);
  53. $this->shop = $shop;
  54. if (empty($shop)) {
  55. util::fail('没有找到您管理的门店');
  56. }
  57. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId, 'delStatus' => 0], true);
  58. if (empty($shopAdmin)) {
  59. util::logout('没有找到员工信息');
  60. }
  61. if (isset($shopAdmin->delStatus) && $shopAdmin->delStatus == 1) {
  62. util::fail('您还不是员工哦');
  63. }
  64. if (isset($shopAdmin->status) && $shopAdmin->status == 0) {
  65. util::fail('您的帐号已被禁用');
  66. }
  67. $this->shopAdmin = $shopAdmin;
  68. $this->shopAdminId = $shopAdmin->id ?? 0;
  69. $sjId = $shop->merchantId;
  70. $this->sjId = $sjId;
  71. $sj = SjClass::getById($sjId, true);
  72. $this->sj = $sj;
  73. $sjExtend = MerchantExtendService::getByMerchantId($sjId, true);
  74. $this->sjExtend = $sjExtend;
  75. }
  76. return parent::beforeAction($action);
  77. }
  78. }