Browse Source

模拟账号

shish 1 year ago
parent
commit
a3e1db4967
2 changed files with 36 additions and 3 deletions
  1. 15 2
      app-ghs/controllers/BaseController.php
  2. 21 1
      app-ghs/controllers/TestController.php

+ 15 - 2
app-ghs/controllers/BaseController.php

@@ -41,9 +41,22 @@ class BaseController extends PublicController
 
         //token验证
         $adminId = jwt::getLoginId();
-        if (getenv('YII_ENV', 'local') == 'local') {
-            //$adminId = 730;
+
+        //将石少华的号模拟成别人的号进行测试,有多处需要同步修改,关键词 simulate_other ssh 20250717
+        $simulateKey = 'simulate_admin_id';
+        $simulateId = Yii::$app->redis->executeCommand('GET', [$simulateKey]);
+        if (!empty($simulateId) && $simulateId > 0) {
+            if (getenv('YII_ENV') == 'production') {
+                if ($adminId == 4) {
+                    $adminId = $simulateId;
+                }
+            } else {
+                if ($adminId == 919) {
+                    $adminId = $simulateId;
+                }
+            }
         }
+
         if (empty($adminId) && in_array($action->id, $this->guestAccess) == false) {
             util::notLogin();
         }

+ 21 - 1
app-ghs/controllers/TestController.php

@@ -2,6 +2,7 @@
 
 namespace ghs\controllers;
 
+use biz\admin\classes\AdminClass;
 use biz\ghs\classes\GhsClass;
 use biz\shop\classes\ShopClass;
 use biz\sj\services\MerchantService;
@@ -40,7 +41,7 @@ use wkhtmltox\Image\Converter;
 class TestController extends BaseController
 {
 
-    public $guestAccess = ['fx', 'on', 'in', 'clear-query', 'ip', 'html', 'debt', 'apply', 'clear', 'ls-trade-query', 'ls-trade-refund', 'refund-query', 'inform', 'notice', 'order-query', 'add-order', 'index', 'get', 'trade-query', 'query', 'balance-query', 'refund', 'recharge-query'];
+    public $guestAccess = ['fx', 'on', 'in', 'clear-query', 'ip', 'html', 'debt', 'apply', 'clear', 'ls-trade-query', 'ls-trade-refund', 'refund-query', 'inform', 'notice', 'order-query', 'add-order', 'index', 'get', 'trade-query', 'query', 'balance-query', 'refund', 'recharge-query', 'simulate'];
 
     public function actionFx()
     {
@@ -1375,4 +1376,23 @@ class TestController extends BaseController
         $r = $producer->publish($msg, 'informExchange', 'informRoute');
     }
 
+    public function actionSimulate()
+    {
+        //将石少华的号模拟成别人的号进行测试,有多处需要同步修改,关键词 simulate_other ssh 20250717
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        if ($id == 0) {
+            Yii::$app->redis->executeCommand('DEL', [$simulateKey]);
+            util::stop('已将石少华账号清空');
+        }
+        $admin = AdminClass::getById($id, true);
+        if (empty($admin)) {
+            util::fail('管理员无效');
+        }
+        $adminName = $admin->name ?? '';
+        $simulateKey = 'simulate_admin_id';
+        Yii::$app->redis->executeCommand('SET', [$simulateKey, $id]);
+        echo "已将石少华账号设置为:" . $adminName;
+    }
+
 }