Browse Source

数据恢复

shish 3 years ago
parent
commit
ed30fe7941
1 changed files with 65 additions and 0 deletions
  1. 65 0
      console/controllers/StatItemController.php

+ 65 - 0
console/controllers/StatItemController.php

@@ -0,0 +1,65 @@
+<?php
+
+namespace console\controllers;
+
+use biz\shop\classes\ShopClass;
+use biz\stat\classes\StatItemClass;
+use biz\stat\classes\StatItemMonthClass;
+use yii\console\Controller;
+use Yii;
+
+class StatItemController extends Controller
+{
+
+    // ./yii stat-item/bc
+    public function actionBc()
+    {
+
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+
+        $list = ShopClass::getAllByCondition(['id>' => 0], null, '*', 'id');
+        $map = [];
+        if (!empty($list)) {
+            foreach ($list as $shopId => $shop) {
+                $mainId = $shop['mainId'] ?? 0;
+                $map[$shopId] = $mainId;
+            }
+        }
+        $statList = StatItemClass::getAllByCondition(['id>' => 0], null, '*', null, true);
+        if (!empty($statList)) {
+            foreach ($statList as $stat) {
+                $currentMainId = $stat->mainId ?? 0;
+                if (!empty($currentMainId)) {
+                    continue;
+                }
+                $currentShopId = $stat->shopId ?? 0;
+                if (empty($currentShopId)) {
+                    continue;
+                }
+                $newMainId = $map[$currentShopId] ?? 0;
+                $stat->mainId = $newMainId;
+                $stat->save();
+            }
+        }
+
+        $statList = StatItemMonthClass::getAllByCondition(['id>' => 0], null, '*', null, true);
+        if (!empty($statList)) {
+            foreach ($statList as $stat) {
+                $currentMainId = $stat->mainId ?? 0;
+                if (!empty($currentMainId)) {
+                    continue;
+                }
+                $currentShopId = $stat->shopId ?? 0;
+                if (empty($currentShopId)) {
+                    continue;
+                }
+                $newMainId = $map[$currentShopId] ?? 0;
+                $stat->mainId = $newMainId;
+                $stat->save();
+            }
+        }
+
+    }
+
+}