Browse Source

更新单位

shish 3 years ago
parent
commit
f927f51b4b
1 changed files with 30 additions and 0 deletions
  1. 30 0
      console/controllers/InitController.php

+ 30 - 0
console/controllers/InitController.php

@@ -2,9 +2,39 @@
 
 namespace console\controllers;
 
+use biz\item\classes\UnitClass;
+use biz\product\classes\ProductClass;
 use yii\console\Controller;
 
 class InitController extends Controller
 {
 
+    public function actionUnit()
+    {
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+
+        $arr = UnitClass::getAllByCondition(['id>' => 0], null, '*', 'id');
+        $data = [];
+        foreach ($arr as $item) {
+            $id = $item['id'] ?? 0;
+            $name = $item['name'] ?? '';
+            $data[$id] = $name;
+        }
+
+        $itemList = ProductClass::getAllByCondition(['id>'=>0], null, '*', null, true);
+        if (!empty($itemList)) {
+            foreach ($itemList as $item) {
+                $bigUnitId = $item->bigUnitId ?? 1;
+                $smallUnitId = $item->smallUnitId ?? 1;
+                $bigUnit = $data[$bigUnitId] ?? '扎';
+                $smallUnit = $data[$smallUnitId] ?? '支';
+                $item->bigUnit = $bigUnit;
+                $item->smallUnit = $smallUnit;
+                $item->save();
+            }
+        }
+
+    }
+
 }