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