BaseController.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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') != 'production') {
  31. //$adminId = 18;
  32. }
  33. if (empty($adminId)) {
  34. util::notLogin();
  35. }
  36. $this->adminId = $adminId;
  37. $admin = AdminService::getById($adminId, true);
  38. if (empty($admin)) {
  39. util::logout('帐号无效');
  40. }
  41. $this->admin = $admin;
  42. // 只能供应商访问
  43. if ($admin->style != AdminClass::STYLE_GHS) {
  44. util::fail('您没有权限访问哦');
  45. }
  46. //后台
  47. $currentShopId = $admin->currentShopId ?? 0;
  48. if (empty($currentShopId)) {
  49. if (in_array($action->id, $this->guestAccess) == false) {
  50. util::fail('您没有权限访问哦!');
  51. }
  52. } else {
  53. $this->shopId = $currentShopId;
  54. $shop = ShopClass::getById($currentShopId, true);
  55. $this->shop = $shop;
  56. if (empty($shop)) {
  57. util::fail('没有找到您管理的门店');
  58. }
  59. $shopExt = ShopExtClass::getByCondition(['shopId' => $currentShopId], true);
  60. if (empty($shopExt)) {
  61. util::fail('没有找到门店');
  62. }
  63. $this->shopExt = $shopExt;
  64. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId, 'delStatus' => 0], true);
  65. if (empty($shopAdmin)) {
  66. util::logout('没有找到员工信息');
  67. }
  68. if (isset($shopAdmin->delStatus) && $shopAdmin->delStatus == 1) {
  69. util::fail('您还不是员工哦');
  70. }
  71. if (isset($shopAdmin->status) && $shopAdmin->status == 0) {
  72. util::fail('您的帐号已被禁用');
  73. }
  74. $this->shopAdmin = $shopAdmin;
  75. $this->shopAdminId = $shopAdmin->id ?? 0;
  76. $sjId = $shop->sjId;
  77. $this->sjId = $sjId;
  78. $sj = SjClass::getById($sjId, true);
  79. $this->sj = $sj;
  80. $sjExtend = MerchantExtendService::getBySjId($sjId, true);
  81. $this->sjExtend = $sjExtend;
  82. }
  83. return parent::beforeAction($action);
  84. }
  85. }