BaseController.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace hd\controllers;
  3. use biz\admin\classes\AdminClass as ClassesAdminClass;
  4. use biz\shop\classes\MainClass;
  5. use biz\sj\classes\SjClass;
  6. use bizHd\admin\classes\AdminClass;
  7. use biz\shop\classes\ShopAdminClass;
  8. use biz\sj\classes\MerchantExtendClass;
  9. use biz\sj\services\MerchantService;
  10. use bizHd\merchant\services\ShopService;
  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, $customId = 0, $custom;
  18. public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0, $mainId = 0, $main = [], $shop = [], $shopAdminId = 0, $shopAdmin = [];
  19. public $appId;
  20. public $isWx = false;
  21. public $isLogin = false;
  22. //游客可以访问的方法
  23. public $guestAccess = [];
  24. //ssh 2020.3.8
  25. public function beforeAction($action)
  26. {
  27. //定义平台类型 1花店 2供应商 3商城
  28. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  29. //token验证
  30. $adminId = jwt::getLoginId();
  31. if (getenv('YII_ENV', 'local') != 'production') {
  32. //$adminId = 253;
  33. }
  34. if (empty($adminId) && in_array($action->id, $this->guestAccess) == false) {
  35. util::notLogin();
  36. }
  37. $admin = AdminClass::getById($adminId, true);
  38. if (empty($admin) && in_array($action->id, $this->guestAccess) == false) {
  39. util::notLogin();
  40. }
  41. $adminId = $admin->id ?? 0;
  42. $this->admin = $admin;
  43. $this->adminId = $adminId;
  44. if (in_array($action->id, $this->guestAccess) == false) {
  45. if ($admin->style != AdminClass::STYLE_HD) {
  46. util::fail('您没有权限访问哦');
  47. }
  48. }
  49. //后台
  50. $currentShopId = $admin->currentShopId ?? 0;
  51. if (empty($currentShopId)) {
  52. if (in_array($action->id, $this->guestAccess) == false) {
  53. util::fail('请注册登录');
  54. }
  55. } else {
  56. $this->shopId = $currentShopId;
  57. $shop = ShopService::getById($currentShopId, true);
  58. if (empty($shop)) {
  59. util::fail('没有找到店铺');
  60. }
  61. $this->shop = $shop;
  62. $mainId = $shop->mainId ?? 0;
  63. $this->mainId = $mainId;
  64. $main = MainClass::getById($mainId, true);
  65. if (empty($main)) {
  66. util::fail('没有找到main信息');
  67. }
  68. $this->main = $main;
  69. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId], true);
  70. if (empty($shopAdmin)) {
  71. util::logout('没有找到员工信息');
  72. }
  73. if (isset($shopAdmin->delStatus) == false || $shopAdmin->delStatus == 1) {
  74. util::fail('您还不是员工哦');
  75. }
  76. if (isset($shopAdmin->status) == false || $shopAdmin->status == 0) {
  77. util::fail('您的帐号已被禁用');
  78. }
  79. $this->shopAdmin = $shopAdmin;
  80. $this->shopAdminId = $shopAdmin->id ?? 0;
  81. $sjId = $shop->sjId;
  82. $this->sjId = $sjId;
  83. $sj = SjClass::getById($sjId, true);
  84. $this->sj = $sj;
  85. $sjExtend = MerchantExtendClass::getBySjId($sjId, true);
  86. $this->sjExtend = $sjExtend;
  87. }
  88. return parent::beforeAction($action);
  89. }
  90. }