BaseController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. // 客户端协议版本:2=旧端金额字段合成;3=净余额(与 ghs 侧 AccountMoneyClass 一致)
  27. $headers = Yii::$app->getRequest()->getHeaders();
  28. Yii::$app->params['clientAppVersion'] = (int)$headers->get('appVersion', 2);
  29. //token验证
  30. $adminId = jwt::getLoginId();
  31. //将石少华的号模拟成别人的号进行测试,有多处需要同步修改,关键词 simulate_other ssh 20250717
  32. $simulateKey = 'simulate_admin_id';
  33. $simulateId = Yii::$app->redis->executeCommand('GET', [$simulateKey]);
  34. if (!empty($simulateId) && $simulateId > 0) {
  35. if (getenv('YII_ENV') == 'production') {
  36. if ($adminId == 4) {
  37. $adminId = $simulateId;
  38. }
  39. } else {
  40. if ($adminId == 919) {
  41. $adminId = $simulateId;
  42. }
  43. }
  44. }
  45. if (empty($adminId) && !in_array($action->id, $this->guestAccess)) {
  46. util::notLogin();
  47. }
  48. $admin = AdminClass::getById($adminId, true, 'password', true);
  49. if (empty($admin) && !in_array($action->id, $this->guestAccess)) {
  50. util::notLogin();
  51. }
  52. $adminId = $admin ? intval($admin->id) : 0;
  53. $this->admin = $admin;
  54. $this->adminId = $adminId;
  55. //后台
  56. $currentShopId = $admin ? intval($admin->currentShopId) : 0;
  57. if (empty($currentShopId)) {
  58. if (in_array($action->id, $this->guestAccess) == false) {
  59. util::fail('请注册登录');
  60. }
  61. } else {
  62. $shop = ShopClass::getById($currentShopId, true);
  63. if (empty($shop)) {
  64. util::fail('没有找到店铺');
  65. }
  66. $this->shopId = $currentShopId;
  67. $this->shop = $shop;
  68. $mainId = intval($shop->mainId);
  69. $main = MainClass::getById($mainId, true);
  70. if (empty($main)) {
  71. util::fail('没有找到main信息');
  72. }
  73. $this->mainId = $mainId;
  74. $this->main = $main;
  75. $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId, 'delStatus' => 0], true); //xhStaff 表
  76. if (empty($shopAdmin)) {
  77. util::logout('没有找到员工信息');
  78. }
  79. if (isset($shopAdmin->delStatus) == false || $shopAdmin->delStatus == 1) {
  80. util::fail('您不是本店员工哦');
  81. }
  82. if (isset($shopAdmin->status) == false || $shopAdmin->status == 0) {
  83. util::fail('您已被平台禁止登录');
  84. }
  85. $this->shopAdmin = $shopAdmin;
  86. $this->shopAdminId = $shopAdmin->id ?? 0;
  87. $this->shopAdminName = $shopAdmin->name ?? '';
  88. $sjId = $shop->sjId;
  89. $sj = SjClass::getById($sjId, true);
  90. $this->sj = $sj;
  91. $this->sjId = $sjId;
  92. $sjExtend = MerchantExtendClass::getBySjId($sjId, true);
  93. $this->sjExtend = $sjExtend;
  94. }
  95. return parent::beforeAction($action);
  96. }
  97. }