BaseController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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\classes\ShopClass;
  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, $account, $customId = 0, $custom;
  16. public $sjId = 0, $sj = [], $sjExtend = [], $shopId = 0, $mainId = 0, $main, $shop, $shopAdminId = 0, $shopAdminName, $shopAdmin;
  17. public $appId;
  18. public $isWx = false;
  19. //游客可以访问的方法
  20. public $guestAccess = [];
  21. //ssh 2020.3.8
  22. public function beforeAction($action)
  23. {
  24. //定义平台类型 1花店 2供货商 3商城
  25. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  26. //token验证
  27. $adminId = jwt::getLoginId();
  28. //将石少华的号模拟成别人的号进行测试,有多处需要同步修改,关键词 simulate_other ssh 20250717
  29. $simulateKey = 'simulate_admin_id';
  30. $simulateId = Yii::$app->redis->executeCommand('GET', [$simulateKey]);
  31. if (!empty($simulateId) && $simulateId > 0) {
  32. if (getenv('YII_ENV') == 'production') {
  33. if ($adminId == 4) {
  34. $adminId = $simulateId;
  35. }
  36. } else {
  37. if ($adminId == 919) {
  38. $adminId = $simulateId;
  39. }
  40. }
  41. }
  42. if (empty($adminId) && !in_array($action->id, $this->guestAccess)) {
  43. util::notLogin();
  44. }
  45. $admin = AdminClass::getById($adminId, true);
  46. if (empty($admin) && !in_array($action->id, $this->guestAccess)) {
  47. util::notLogin();
  48. }
  49. $adminId = $admin ? intval($admin->id) : 0;
  50. $this->admin = $admin;
  51. $this->adminId = $adminId;
  52. //后台
  53. $currentShopId = $admin ? intval($admin->currentShopId) : 0;
  54. if (empty($currentShopId)) {
  55. if (in_array($action->id, $this->guestAccess) == false) {
  56. util::fail('请注册登录');
  57. }
  58. } else {
  59. $shop = ShopClass::getById($currentShopId, true);
  60. if (empty($shop)) {
  61. util::fail('没有找到店铺');
  62. }
  63. $this->shopId = $currentShopId;
  64. $this->shop = $shop;
  65. $mainId = intval($shop->mainId);
  66. $main = MainClass::getById($mainId, true);
  67. if (empty($main)) {
  68. util::fail('没有找到main信息');
  69. }
  70. $this->mainId = $mainId;
  71. $this->main = $main;
  72. $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId, 'delStatus' => 0], true); //xhStaff 表
  73. if (empty($shopAdmin)) {
  74. util::logout('没有找到员工信息');
  75. }
  76. if (isset($shopAdmin->delStatus) == false || $shopAdmin->delStatus == 1) {
  77. util::fail('您不是本店员工哦');
  78. }
  79. if (isset($shopAdmin->status) == false || $shopAdmin->status == 0) {
  80. util::fail('您已被平台禁止登录');
  81. }
  82. $this->shopAdmin = $shopAdmin;
  83. $this->shopAdminId = $shopAdmin->id ?? 0;
  84. $this->shopAdminName = $shopAdmin->name ?? '';
  85. $sjId = $shop->sjId;
  86. $sj = SjClass::getById($sjId, true);
  87. $this->sj = $sj;
  88. $this->sjId = $sjId;
  89. $sjExtend = MerchantExtendClass::getBySjId($sjId, true);
  90. $this->sjExtend = $sjExtend;
  91. }
  92. return parent::beforeAction($action);
  93. }
  94. }