BaseController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace hd\controllers;
  3. use biz\sj\classes\SjClass;
  4. use bizHd\admin\classes\AdminClass;
  5. use biz\shop\classes\ShopAdminClass;
  6. use biz\sj\classes\MerchantExtendClass;
  7. use bizHd\merchant\services\ShopService;
  8. use bizHd\shop\classes\MainClass;
  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, $shopAdminName, $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. //将石少华的号模拟成别人的号进行测试,有多处需要同步修改,关键词 simulate_other ssh 20250717
  30. $simulateKey = 'simulate_admin_id';
  31. $simulateId = Yii::$app->redis->executeCommand('GET', [$simulateKey]);
  32. if (!empty($simulateId) && $simulateId > 0) {
  33. if (getenv('YII_ENV') == 'production') {
  34. if ($adminId == 4) {
  35. $adminId = $simulateId;
  36. }
  37. } else {
  38. if ($adminId == 919) {
  39. $adminId = $simulateId;
  40. }
  41. }
  42. }
  43. if (empty($adminId) && in_array($action->id, $this->guestAccess) == false) {
  44. util::notLogin();
  45. }
  46. $admin = AdminClass::getById($adminId, true);
  47. if (empty($admin) && in_array($action->id, $this->guestAccess) == false) {
  48. util::notLogin();
  49. }
  50. $adminId = $admin->id ?? 0;
  51. $this->admin = $admin;
  52. $this->adminId = $adminId;
  53. //后台
  54. $currentShopId = $admin->currentShopId ?? 0;
  55. if (empty($currentShopId)) {
  56. if (in_array($action->id, $this->guestAccess) == false) {
  57. util::fail('请注册登录');
  58. }
  59. } else {
  60. $this->shopId = $currentShopId;
  61. $shop = ShopService::getById($currentShopId, true);
  62. if (empty($shop)) {
  63. util::fail('没有找到店铺');
  64. }
  65. $this->shop = $shop;
  66. $mainId = $shop->mainId ?? 0;
  67. $this->mainId = $mainId;
  68. $main = MainClass::getById($mainId, true);
  69. if (empty($main)) {
  70. util::fail('没有找到main信息');
  71. }
  72. $this->main = $main;
  73. $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId, 'delStatus' => 0], true);
  74. if (empty($shopAdmin)) {
  75. util::logout('没有找到员工信息');
  76. }
  77. if (isset($shopAdmin->delStatus) == false || $shopAdmin->delStatus == 1) {
  78. util::fail('您不是本店员工哦');
  79. }
  80. if (isset($shopAdmin->status) == false || $shopAdmin->status == 0) {
  81. util::fail('您已被平台禁止登录');
  82. }
  83. $this->shopAdmin = $shopAdmin;
  84. $this->shopAdminId = $shopAdmin->id ?? 0;
  85. $this->shopAdminName = $shopAdmin->name ?? '';
  86. $sjId = $shop->sjId;
  87. $this->sjId = $sjId;
  88. $sj = SjClass::getById($sjId, true);
  89. $this->sj = $sj;
  90. $sjExtend = MerchantExtendClass::getBySjId($sjId, true);
  91. $this->sjExtend = $sjExtend;
  92. }
  93. return parent::beforeAction($action);
  94. }
  95. }