Bläddra i källkod

批量修改价格

shish 4 år sedan
förälder
incheckning
48bf45e0a6
1 ändrade filer med 27 tillägg och 2 borttagningar
  1. 27 2
      app-ghs/controllers/ProductController.php

+ 27 - 2
app-ghs/controllers/ProductController.php

@@ -380,14 +380,39 @@ class ProductController extends BaseController
 //            $data = [$type => $val];
 //            ProductClass::updateByCondition($where, $data);
 
+            $data = [$type => $val];
+
             $currentProduct = ProductClass::getById($id, true);
             if ($currentProduct->shopId != $this->shopId) {
                 util::fail('非常操作');
             }
             $currentProduct->$type = $val;
-            $currentProduct->save();
-            $data = [$type => $val];
+            if ($type == 'addPrice') {
+
+                $anotherAddPrice = $val > 2 ? $val - 1 : 1;
 
+                $qtAddPrice = $currentProduct->qtAddPrice;
+                if ($qtAddPrice <= 0) {
+                    $currentProduct->qtAddPrice = $anotherAddPrice;
+                    $data['qtAddPrice'] = $anotherAddPrice;
+                }
+                $byAddPrice = $currentProduct->byAddPrice;
+                if ($byAddPrice <= 0) {
+                    $currentProduct->byAddPrice = $anotherAddPrice;
+                    $data['byAddPrice'] = $anotherAddPrice;
+                }
+                $hjAddPrice = $currentProduct->hjAddPrice;
+                if ($hjAddPrice <= 0) {
+                    $currentProduct->hjAddPrice = $anotherAddPrice;
+                    $data['hjAddPrice'] = $anotherAddPrice;
+                }
+                $zsAddPrice = $currentProduct->zsAddPrice;
+                if ($zsAddPrice <= 0) {
+                    $currentProduct->zsAddPrice = $anotherAddPrice;
+                    $data['zsAddPrice'] = $anotherAddPrice;
+                }
+            }
+            $currentProduct->save();
 
             //2021.7.6 linqh 如果是首店,则更新全部分店
             ProductClass::updateSyncProduct($id, $this->shopId, $data);