ソースを参照

salt更新脚本

shish 1 ヶ月 前
コミット
4798ae5139
1 ファイル変更56 行追加0 行削除
  1. 56 0
      console/controllers/SaltController.php

+ 56 - 0
console/controllers/SaltController.php

@@ -25,6 +25,8 @@ use yii\console\ExitCode;
  *   php yii salt/fill --mode=pk --scanSize=1000
  *   php yii salt/fill-ghs-order
  *   php yii salt/fill-cg
+ *   php yii salt/fill-clear
+ *   php yii salt/fill-settle
  */
 class SaltController extends Controller
 {
@@ -93,6 +95,60 @@ class SaltController extends Controller
         ]);
     }
 
+    /**
+     * 补充 xhClear 结账单历史数据的 salt 字段
+     * 职责:查询全部 xhClear 记录,循环重新生成并设置 salt
+     */
+    public function actionFillClear()
+    {
+        $db = Yii::$app->db;
+        // 查询全部结账单 ID
+        $ids = $db->createCommand("SELECT id FROM xhClear ORDER BY id DESC")->queryColumn();
+        $count = 0;
+        foreach ($ids as $id) {
+            if ($this->dryRun) {
+                $this->stdout("[dry-run] xhClear id={$id}\n");
+                $count++;
+                continue;
+            }
+            // 重新生成 10 位随机 salt 并更新
+            $salt = stringUtil::charsShuffleLowerCase(10);
+            $db->createCommand("UPDATE xhClear SET salt = :salt WHERE id = :id")
+                ->bindValues([':salt' => $salt, ':id' => $id])
+                ->execute();
+            $count++;
+        }
+        $this->stdout("xhClear salt 全部重新设置完成,共处理 {$count} 条记录\n");
+        return ExitCode::OK;
+    }
+
+    /**
+     * 补充 xhSettle 结算单历史数据的 salt 字段
+     * 职责:查询全部 xhSettle 记录,循环重新生成并设置 salt
+     */
+    public function actionFillSettle()
+    {
+        $db = Yii::$app->db;
+        // 查询全部结算单 ID
+        $ids = $db->createCommand("SELECT id FROM xhSettle ORDER BY id DESC")->queryColumn();
+        $count = 0;
+        foreach ($ids as $id) {
+            if ($this->dryRun) {
+                $this->stdout("[dry-run] xhSettle id={$id}\n");
+                $count++;
+                continue;
+            }
+            // 重新生成 10 位随机 salt 并更新
+            $salt = stringUtil::charsShuffleLowerCase(10);
+            $db->createCommand("UPDATE xhSettle SET salt = :salt WHERE id = :id")
+                ->bindValues([':salt' => $salt, ':id' => $id])
+                ->execute();
+            $count++;
+        }
+        $this->stdout("xhSettle salt 全部重新设置完成,共处理 {$count} 条记录\n");
+        return ExitCode::OK;
+    }
+
     private function runFill(array $tables)
     {
         ini_set('memory_limit', '512M');