Przeglądaj źródła

红包 批量修改价格

shish 4 lat temu
rodzic
commit
1f81388bb7

+ 4 - 45
app-ghs/controllers/ProductController.php

@@ -223,15 +223,10 @@ class ProductController extends BaseController
                 if (isset($product->shopId) == false || $product->shopId != $this->shopId) {
                     util::fail('没有权限访问');
                 }
-
                 if (empty($price)) {
-                    //恢复自动调价
-                    $price = bcadd($product->cost, $product->addPrice, 2);
-                    ProductClass::changePrice($product, $price, ProductClass::PRICE_LABEL_AUTO);
-                } else {
-                    //改价
-                    ProductClass::changePrice($product, $price, ProductClass::PRICE_LABEL_CHANGE);
+                    continue;
                 }
+                ProductClass::changePrice($product, $price, ProductClass::PRICE_LABEL_CHANGE);
             }
             $transaction->commit();
             util::complete('修改成功');
@@ -368,45 +363,9 @@ class ProductController extends BaseController
                     continue;
                 }
                 if (empty($val)) {
-                    util::fail('请输入价格');
-                }
-                $shopAll = ShopClass::getAllShop($this->sjId);
-                if (!empty($shopAll)) {
-                    foreach ($shopAll as $currentShop) {
-                        $currentShopId = $currentShop['id'] ?? 0;
-                        if (empty($currentShopId)) {
-                            continue;
-                        }
-                        $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;
                 }
+                ProductClass::changePrice($product, $val, ProductClass::PRICE_LABEL_CHANGE);
                 continue;
             }
 

+ 45 - 9
biz-ghs/product/classes/ProductClass.php

@@ -545,17 +545,54 @@ class ProductClass extends BaseClass
     //修改价格 linqh 2021.1.28
     public static function changePrice($product, $price, $priceLabel)
     {
-        $id = $product->id ?? 0;
         $shopId = $product->shopId ?? 0;
 
-        //改价后取消特价 shish 20210902
-        $product->discountPrice = 0;
-        $product->save();
+        $shopInfo = ShopClass::getById($shopId, true);
+        $itemId = $product->itemId ?? 0;
 
-        //2021.7.6 linqh 首店改价,同步到各个分店
-        $res = ProductClass::updateByCondition(['id' => $id], ['price' => $price, 'priceLabel' => $priceLabel]);
-        self::updateSyncProduct($id, $shopId, ['price' => $price, 'priceLabel' => $priceLabel]);
-        return $res;
+        $sjId = $shopInfo->sjId ?? 0;
+        $shopAll = ShopClass::getAllShop($sjId);
+        if ($shopAll) {
+            foreach ($shopAll as $shop) {
+                $currentId = $shop['id'] ?? 0;
+                $currentInfo = ProductClass::getByCondition(['itemId' => $itemId, 'shopId' => $currentId], true);
+                if (empty($currentInfo)) {
+                    continue;
+                }
+
+                //改价后取消特价
+                $currentInfo->discountPrice = 0;
+                $currentInfo->price = $price;
+                $currentInfo->priceLabel = $priceLabel;
+                //会员价同步变化
+                $addPrice = $currentInfo->addPrice ?? 0;
+                $qtAddPrice = $currentInfo->qtAddPrice ?? 0;
+                $qt = bcsub($addPrice, $qtAddPrice, 2);
+                if ($qt > 0) {
+                    $currentInfo->qtPrice = bcsub($price, $qt, 2);
+                }
+                $byAddPrice = $currentInfo->byAddPrice ?? 0;
+                $by = bcsub($addPrice, $byAddPrice, 2);
+                if ($by > 0) {
+                    $currentInfo->byPrice = bcsub($price, $by, 2);
+                }
+                $hjAddPrice = $currentInfo->hjAddPrice ?? 0;
+                $hj = bcsub($addPrice, $hjAddPrice, 2);
+                if ($hj > 0) {
+                    $currentInfo->hjPrice = bcsub($price, $hj, 2);
+                }
+                $zsAddPrice = $currentInfo->zsAddPrice ?? 0;
+                $zs = bcsub($addPrice, $zsAddPrice, 2);
+                if ($zs > 0) {
+                    $currentInfo->zsPrice = bcsub($price, $zs, 2);
+                }
+                $currentInfo->save();
+
+            }
+        }
+
+
+        return true;
     }
 
     //2021.7.6 修改花材同步其他分店
@@ -565,7 +602,6 @@ class ProductClass extends BaseClass
         $productData = ProductClass::getById($productId);
         $itemId = $productData['itemId'];
         if ($shopInfo['default'] == 1) {
-            //首店
             $sjId = $shopInfo['sjId'];
             $shopAll = ShopClass::getAllShop($sjId);
             if ($shopAll) {