BaseController.php 3.4 KB

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