Kaynağa Gözat

自动修改库存

shish 1 yıl önce
ebeveyn
işleme
1f618ee021
1 değiştirilmiş dosya ile 26 ekleme ve 5 silme
  1. 26 5
      app-hd/controllers/PurchaseController.php

+ 26 - 5
app-hd/controllers/PurchaseController.php

@@ -195,6 +195,7 @@ class PurchaseController extends BaseController
         $post = Yii::$app->request->post();
 
         $version = $post['version']??0;
+        $direct = $post['direct']??0;
 
         //多颜色数据整理
         $colorItem = $post['xj'] ?? [];
@@ -285,7 +286,8 @@ class PurchaseController extends BaseController
                 $productId = $product['productId']??0;
                 $orderNum[$productId] = ['num'=>$bigNum];
             }
-            $lack = [];
+            $lackList = [];
+            $changeList = [];
 
             $ids = array_unique(array_filter(array_column($productList, 'productId')));
             $productInfoList = ProductClass::getByIds($ids, null, 'id');
@@ -333,7 +335,8 @@ class PurchaseController extends BaseController
                         $num = $orderNum[$productId] && $orderNum[$productId]['num'] ? $orderNum[$productId]['num'] : 0;
                         $num = floatval($num);
                         if($num>$stock){
-                            $lack[] = ['name'=>$productName,'stock'=>$stock];
+                            $lackList[] = ['name'=>$productName,'stock'=>$stock];
+                            $changeList[$productId] = $stock;
                         }
                     }
 
@@ -347,11 +350,29 @@ class PurchaseController extends BaseController
                 }
 
                 if($version >= 10){
-                    if(!empty($lack)){
-                        util::success(['lack'=>$lack,'hasLackError'=>1]);
+                    if($direct == 1){
+                        //直接更换库存并提交
+                        $allNoStock = true;
+                        foreach($productList as $pKey =>$pVal){
+                            $productId = $pVal['productId']??0;
+                            if(isset($changeList[$productId])){
+                                $changeStock = $changeList[$productId];
+                                $productList[$pKey]['bigNum'] = $changeStock;
+                            }
+                            if($productList[$pKey]['bigNum']>0){
+                                $allNoStock = false;
+                            }
+                        }
+                        if($allNoStock){
+                            util::fail('全部没库存了');
+                        }
+                    }else{
+                        //前台提示库存不足
+                        if(!empty($lackList)){
+                            util::success(['lackList'=>$lackList,'hasLackError'=>1]);
+                        }
                     }
                 }
-				die;
 
             } else {
                 util::fail('花材不存在');