shish 4 лет назад
Родитель
Сommit
863a23a60b
1 измененных файлов с 29 добавлено и 27 удалено
  1. 29 27
      app-ghs/controllers/ProductController.php

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

@@ -369,35 +369,37 @@ class ProductController extends BaseController
 
                 //成本价需要修改的花材id
                 $costChangeIds = Yii::$app->request->post('costChangeIds', []);
-                $arrIds = json_decode($costChangeIds, true);
-                $costIds = is_array($arrIds) ? $arrIds : [];
-                if (!empty($costIds) && in_array($id, $costIds)) {
-                    $newAddPrice = bcsub($val, $product->cost, 2);
-                    $qtDiff = bcsub($product->addPrice, $product->qtAddPrice, 2);
-                    $newQtAddPrice = bcsub($newAddPrice, $qtDiff, 2);
-                    $byDiff = bcsub($product->addPrice, $product->byAddPrice, 2);
-                    $newByAddPrice = bcsub($newAddPrice, $byDiff, 2);
-                    $hjDiff = bcsub($product->addPrice, $product->hjAddPrice, 2);
-                    $newHjAddPrice = bcsub($newAddPrice, $hjDiff, 2);
-                    $zsDiff = bcsub($product->addPrice, $product->zsAddPrice, 2);
-                    $newZsAddPrice = bcsub($newAddPrice, $zsDiff, 2);
-                    $params = [];
-                    $params['addPrice'] = $newAddPrice;
-                    $params['qtAddPrice'] = $newQtAddPrice;
-                    $params['byAddPrice'] = $newByAddPrice;
-                    $params['hjAddPrice'] = $newHjAddPrice;
-                    $params['zsAddPrice'] = $newZsAddPrice;
-
-                    $sjId = $product->sjId ?? 0;
-                    $shopAll = ShopClass::getAllShop($sjId);
-                    if ($shopAll) {
-                        foreach ($shopAll as $shop) {
-                            $currentId = $shop['id'] ?? 0;
-                            $itemId = $product->itemId ?? 0;
-                            ProductClass::updateByCondition(['shopId' => $currentId, 'itemId' => $itemId], $params);
+                if (!empty($costChangeIds)) {
+                    $arrIds = json_decode($costChangeIds, true);
+                    $costIds = is_array($arrIds) ? $arrIds : [];
+                    if (!empty($costIds) && in_array($id, $costIds)) {
+                        $newAddPrice = bcsub($val, $product->cost, 2);
+                        $qtDiff = bcsub($product->addPrice, $product->qtAddPrice, 2);
+                        $newQtAddPrice = bcsub($newAddPrice, $qtDiff, 2);
+                        $byDiff = bcsub($product->addPrice, $product->byAddPrice, 2);
+                        $newByAddPrice = bcsub($newAddPrice, $byDiff, 2);
+                        $hjDiff = bcsub($product->addPrice, $product->hjAddPrice, 2);
+                        $newHjAddPrice = bcsub($newAddPrice, $hjDiff, 2);
+                        $zsDiff = bcsub($product->addPrice, $product->zsAddPrice, 2);
+                        $newZsAddPrice = bcsub($newAddPrice, $zsDiff, 2);
+                        $params = [];
+                        $params['addPrice'] = $newAddPrice;
+                        $params['qtAddPrice'] = $newQtAddPrice;
+                        $params['byAddPrice'] = $newByAddPrice;
+                        $params['hjAddPrice'] = $newHjAddPrice;
+                        $params['zsAddPrice'] = $newZsAddPrice;
+
+                        $sjId = $product->sjId ?? 0;
+                        $shopAll = ShopClass::getAllShop($sjId);
+                        if ($shopAll) {
+                            foreach ($shopAll as $shop) {
+                                $currentId = $shop['id'] ?? 0;
+                                $itemId = $product->itemId ?? 0;
+                                ProductClass::updateByCondition(['shopId' => $currentId, 'itemId' => $itemId], $params);
+                            }
                         }
-                    }
 
+                    }
                 }
                 ProductClass::changePrice($product, $val, ProductClass::PRICE_LABEL_CHANGE);
                 continue;