BaseController.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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\services\MerchantExtendService;
  7. use biz\sj\services\MerchantService;
  8. use bizGhs\admin\services\AdminService;
  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;
  15. public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shop = [], $shopId = 0, $lookShopId = 0, $shopAdminId = 0, $shopAdmin = [];
  16. public $appId;
  17. public $isWx = false;
  18. public $isLogin = false;
  19. public $guestAccess = [];//不需要登陆的方法名
  20. //ssh 2020.3.8
  21. public function beforeAction($action)
  22. {
  23. //定义平台类型 1花店 2供货商
  24. Yii::$app->params['ptStyle'] = 2;
  25. //token验证
  26. $adminId = jwt::getLoginId();
  27. if (getenv('YII_ENV', 'local') != 'production') {
  28. //$adminId = 18;
  29. }
  30. if (empty($adminId)) {
  31. util::notLogin();
  32. }
  33. $this->adminId = $adminId;
  34. $admin = AdminService::getById($adminId);
  35. if (empty($admin)) {
  36. util::logout('帐号无效');
  37. }
  38. $this->admin = $admin;
  39. // 只能供货商访问
  40. if ($admin['style'] != AdminClass::STYLE_GHS) {
  41. util::fail('您没有权限访问哦!');
  42. }
  43. //后台
  44. $currentShopId = $admin['currentShopId'] ?? 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::getShopInfo($currentShopId);
  52. $this->shop = $shop;
  53. if (empty($shop)) {
  54. util::fail('没有找到您管理的门店');
  55. }
  56. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId, 'delStatus' => 0]);
  57. if (empty($shopAdmin)) {
  58. util::logout('没有找到员工信息');
  59. }
  60. if (isset($shopAdmin['delStatus']) && $shopAdmin['delStatus'] == 1) {
  61. util::fail('您还不是员工哦');
  62. }
  63. if (isset($shopAdmin['status']) && $shopAdmin['status'] == 0) {
  64. util::fail('您的帐号已被禁用');
  65. }
  66. $this->shopAdmin = $shopAdmin;
  67. $this->shopAdminId = $shopAdmin['id'] ?? 0;
  68. $sjId = $shop['merchantId'];
  69. $this->sjId = $sjId;
  70. $sj = MerchantService::getMerchantById($sjId);
  71. $this->sj = $sj;
  72. $sjExtend = MerchantExtendService::getByMerchantId($sjId);
  73. $this->sjExtend = $sjExtend;
  74. }
  75. return parent::beforeAction($action);
  76. }
  77. }