shish 3 jaren geleden
bovenliggende
commit
77d8248ac4
1 gewijzigde bestanden met toevoegingen van 10 en 4 verwijderingen
  1. 10 4
      console/controllers/WorkController.php

+ 10 - 4
console/controllers/WorkController.php

@@ -10,21 +10,27 @@ use Yii;
 class WorkController extends Controller
 {
 
-
     public function actionInit()
     {
-        GoodsClass::updateByCondition(['id>' => 0], ['stock' => 0]);
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+        $goodsList = GoodsClass::getAllByCondition(['id>' => 0], null, '*', null, true);
+        if (!empty($goodsList)) {
+            foreach ($goodsList as $goods) {
+                $goods->stock = 0;
+                $goods->save();
+            }
+        }
         $workList = WorkClass::getAllByCondition(['status' => 0], null, '*', null, true);
         if (!empty($workList)) {
             foreach ($workList as $work) {
                 $num = $work->num ?? 0;
                 $goodsId = $work->goodsId ?? 0;
-                if(!empty($goodsId)){
+                if (!empty($goodsId)) {
                     GoodsClass::updateById($goodsId, ['stock' => $num]);
                 }
             }
         }
     }
 
-
 }