Quellcode durchsuchen

取消满减 特价

shish vor 1 Monat
Ursprung
Commit
95e5fce34f
2 geänderte Dateien mit 128 neuen und 14 gelöschten Zeilen
  1. 84 9
      app-ghs/controllers/ProductController.php
  2. 44 5
      app-hd/controllers/ProductController.php

+ 84 - 9
app-ghs/controllers/ProductController.php

@@ -184,10 +184,47 @@ class ProductController extends BaseController
         $id = $get['id'] ?? 0;
         $info = ProductClass::getById($id, true);
         ProductClass::check($info, $this->mainId);
-        $info->reachNum = 0;
-        $info->reachNumDiscount = 0;
-        $info->save();
-        util::complete('取消成功');
+
+        $db = Yii::$app->db;
+        $transaction = $db->beginTransaction();
+        try {
+            $info->reachNum = 0;
+            $info->reachNumDiscount = 0;
+            $info->save();
+
+            // 如果当前在总店,则直营分店要同步取消
+            $currentShop = $this->shop;
+            if (isset($currentShop->default) && $currentShop->default == 1) {
+                $sjId = $currentShop->sjId ?? 0;
+                $ptItemId = $info->itemId ?? 0;
+                $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
+                if (!empty($chainShopList)) {
+                    foreach ($chainShopList as $chainShop) {
+                        $chainShopId = $chainShop->id ?? 0;
+                        if ($chainShopId == $this->shopId) {
+                            continue;
+                        }
+                        $isDefault = $chainShop->default ?? 0;
+                        $isJoin = $chainShop->join ?? 0;
+                        if ($isDefault == 0 && $isJoin == 0) {
+                            $chainMainId = $chainShop->mainId ?? 0;
+                            $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
+                            if (!empty($chainProduct)) {
+                                $chainProduct->reachNum = 0;
+                                $chainProduct->reachNumDiscount = 0;
+                                $chainProduct->save();
+                            }
+                        }
+                    }
+                }
+            }
+
+            $transaction->commit();
+            util::complete('取消成功');
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            util::fail('取消失败:' . $e->getMessage());
+        }
     }
 
     //取消特价 ssh 20220901
@@ -197,11 +234,49 @@ class ProductController extends BaseController
         $id = $get['id'] ?? 0;
         $info = ProductClass::getById($id, true);
         ProductClass::check($info, $this->mainId);
-        $info->discountPrice = 0;
-        $info->skDiscountPrice = 0;
-        $info->hjDiscountPrice = 0;
-        $info->save();
-        util::complete('取消成功');
+
+        $db = Yii::$app->db;
+        $transaction = $db->beginTransaction();
+        try {
+            $info->discountPrice = 0;
+            $info->skDiscountPrice = 0;
+            $info->hjDiscountPrice = 0;
+            $info->save();
+
+            // 如果当前在总店,则直营分店要同步取消特价
+            $currentShop = $this->shop;
+            if (isset($currentShop->default) && $currentShop->default == 1) {
+                $sjId = $currentShop->sjId ?? 0;
+                $ptItemId = $info->itemId ?? 0;
+                $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
+                if (!empty($chainShopList)) {
+                    foreach ($chainShopList as $chainShop) {
+                        $chainShopId = $chainShop->id ?? 0;
+                        if ($chainShopId == $this->shopId) {
+                            continue;
+                        }
+                        $isDefault = $chainShop->default ?? 0;
+                        $isJoin = $chainShop->join ?? 0;
+                        if ($isDefault == 0 && $isJoin == 0) {
+                            $chainMainId = $chainShop->mainId ?? 0;
+                            $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
+                            if (!empty($chainProduct)) {
+                                $chainProduct->discountPrice = 0;
+                                $chainProduct->skDiscountPrice = 0;
+                                $chainProduct->hjDiscountPrice = 0;
+                                $chainProduct->save();
+                            }
+                        }
+                    }
+                }
+            }
+
+            $transaction->commit();
+            util::complete('取消成功');
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            util::fail('取消失败:' . $e->getMessage());
+        }
     }
 
     //打印花材的标签 ssh 20220602

+ 44 - 5
app-hd/controllers/ProductController.php

@@ -1094,10 +1094,49 @@ class ProductController extends BaseController
         $id = $get['id'] ?? 0;
         $info = ProductClass::getById($id, true);
         ProductClass::check($info, $this->mainId);
-        $info->discountPrice = 0;
-        $info->skDiscountPrice = 0;
-        $info->hjDiscountPrice = 0;
-        $info->save();
-        util::complete('取消成功');
+
+        $db = Yii::$app->db;
+        $transaction = $db->beginTransaction();
+        try {
+            $info->discountPrice = 0;
+            $info->skDiscountPrice = 0;
+            $info->hjDiscountPrice = 0;
+            $info->save();
+
+            // 如果当前在总店,则直营分店要同步取消特价
+            $currentShop = $this->shop;
+            if (isset($currentShop->default) && $currentShop->default == 1) {
+                $sjId = $currentShop->sjId ?? 0;
+                $ptItemId = $info->itemId ?? 0;
+                $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
+                if (!empty($chainShopList)) {
+                    foreach ($chainShopList as $chainShop) {
+                        $chainShopId = $chainShop->id ?? 0;
+                        if ($chainShopId == $this->shopId) {
+                            continue;
+                        }
+                        $isDefault = $chainShop->default ?? 0;
+                        $isJoin = $chainShop->join ?? 0;
+                        if ($isDefault == 0 && $isJoin == 0) {
+                            $chainMainId = $chainShop->mainId ?? 0;
+                            $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
+                            if (!empty($chainProduct)) {
+                                $chainProduct->discountPrice = 0;
+                                $chainProduct->skDiscountPrice = 0;
+                                $chainProduct->hjDiscountPrice = 0;
+                                $chainProduct->save();
+                            }
+                        }
+                    }
+                }
+            }
+
+            $transaction->commit();
+            util::complete('取消成功');
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            util::fail('取消失败:' . $e->getMessage());
+        }
     }
+
 }