BaseController.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\shop\classes\ShopExtClass;
  7. use biz\sj\classes\SjClass;
  8. use biz\sj\services\MerchantExtendService;
  9. use biz\sj\services\MerchantService;
  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, $lookShopId = 0, $shopAdminId = 0, $shopAdmin = [];
  19. public $appId;
  20. public $isWx = false;
  21. public $isLogin = false;
  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. //token验证
  29. $adminId = jwt::getLoginId();
  30. if (getenv('YII_ENV', 'local') == 'local') {
  31. //$adminId = 730;
  32. }
  33. if (empty($adminId) && in_array($action->id, $this->guestAccess) == false) {
  34. util::notLogin();
  35. }
  36. $this->adminId = $adminId;
  37. $admin = AdminService::getById($adminId, true);
  38. if (empty($admin) && in_array($action->id, $this->guestAccess) == false) {
  39. util::logout('帐号无效');
  40. }
  41. $this->admin = $admin;
  42. // 只能供应商访问
  43. if (in_array($action->id, $this->guestAccess) == false) {
  44. if ($admin->style != AdminClass::STYLE_GHS) {
  45. util::fail('您没有权限访问哦');
  46. }
  47. }
  48. //后台
  49. $currentShopId = $admin->currentShopId ?? 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. $this->shop = $shop;
  58. if (empty($shop)) {
  59. util::fail('没有找到您管理的门店');
  60. }
  61. $shopExt = ShopExtClass::getByCondition(['shopId' => $currentShopId], true);
  62. if (empty($shopExt)) {
  63. util::fail('没有找到门店拓展信息');
  64. }
  65. $this->shopExt = $shopExt;
  66. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId, 'delStatus' => 0], true);
  67. if (empty($shopAdmin)) {
  68. util::logout('没有找到员工信息');
  69. }
  70. if (isset($shopAdmin->delStatus) && $shopAdmin->delStatus == 1) {
  71. util::fail('您还不是员工哦');
  72. }
  73. if (isset($shopAdmin->status) && $shopAdmin->status == 0) {
  74. util::fail('您的帐号已被禁用');
  75. }
  76. $this->shopAdmin = $shopAdmin;
  77. $this->shopAdminId = $shopAdmin->id ?? 0;
  78. $sjId = $shop->sjId;
  79. $this->sjId = $sjId;
  80. $sj = SjClass::getById($sjId, true);
  81. $this->sj = $sj;
  82. $sjExtend = MerchantExtendService::getBySjId($sjId, true);
  83. $this->sjExtend = $sjExtend;
  84. }
  85. return parent::beforeAction($action);
  86. }
  87. }