shish hace 4 años
padre
commit
78ef23ecb3
Se han modificado 1 ficheros con 29 adiciones y 7 borrados
  1. 29 7
      app-ghs/controllers/ProductController.php

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

@@ -367,13 +367,8 @@ class ProductController extends BaseController
                 if (empty($currentItemId)) {
                     continue;
                 }
-                //留空恢复自动调价
-                //所有门店同步调整
                 if (empty($val)) {
-                    $currentPrice = bcadd($product->cost, $product->addPrice, 2);
-                    $upData = ['priceLabel' => ProductClass::PRICE_LABEL_AUTO, 'price' => $currentPrice];
-                } else {
-                    $upData = ['priceLabel' => ProductClass::PRICE_LABEL_CHANGE, 'price' => $val];
+                    util::fail('请输入价格');
                 }
                 $shopAll = ShopClass::getAllShop($this->sjId);
                 if (!empty($shopAll)) {
@@ -382,7 +377,34 @@ class ProductController extends BaseController
                         if (empty($currentShopId)) {
                             continue;
                         }
-                        ProductClass::updateByCondition(['shopId' => $currentShopId, 'itemId' => $currentItemId], $upData);
+                        $productData = ProductClass::getByCondition(['shopId' => $currentShopId, 'itemId' => $currentItemId], true);
+                        if (empty($productData)) {
+                            continue;
+                        }
+                        $productData->priceLabel = ProductClass::PRICE_LABEL_CHANGE;
+                        $productData->price = $val;
+                        $addPrice = $productData->addPrice ?? 0;
+                        $qtAddPrice = $productData->qtAddPrice ?? 0;
+                        $qt = bcsub($addPrice, $qtAddPrice, 2);
+                        if ($qt > 0) {
+                            $productData->qtPrice = bcsub($val, $qt, 2);
+                        }
+                        $byAddPrice = $productData->byAddPrice ?? 0;
+                        $by = bcsub($addPrice, $byAddPrice, 2);
+                        if ($by > 0) {
+                            $productData->byPrice = bcsub($val, $by, 2);
+                        }
+                        $hjAddPrice = $productData->hjAddPrice ?? 0;
+                        $hj = bcsub($addPrice, $hjAddPrice, 2);
+                        if ($hj > 0) {
+                            $productData->hjPrice = bcsub($val, $hj, 2);
+                        }
+                        $zsAddPrice = $productData->zsAddPrice ?? 0;
+                        $zs = bcsub($addPrice, $zsAddPrice, 2);
+                        if ($zs > 0) {
+                            $productData->zsPrice = bcsub($val, $zs, 2);
+                        }
+                        $productData->save();
                     }
                 }
                 continue;