Răsfoiți Sursa

删除产品

shish 2 ani în urmă
părinte
comite
5d74bb153d
2 a modificat fișierele cu 37 adăugiri și 0 ștergeri
  1. 10 0
      app-ghs/controllers/CpController.php
  2. 27 0
      biz-ghs/cp/classes/CpClass.php

+ 10 - 0
app-ghs/controllers/CpController.php

@@ -98,6 +98,16 @@ class CpController extends BaseController
         if (isset($cp['mainId']) == false || $cp['mainId'] != $this->mainId) {
             util::fail('无法查看');
         }
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            CpClass::delCp($cp, $this->shop);
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            util::fail('添加没有成功');
+        }
     }
 
     //查看详情 ssh 20240219

+ 27 - 0
biz-ghs/cp/classes/CpClass.php

@@ -14,6 +14,33 @@ class CpClass extends BaseClass
 
     public static $baseFile = '\bizGhs\cp\models\Cp';
 
+    //删除产品 ssh 20240221
+    public static function delCp($cp, $masterShop)
+    {
+        $ptCpId = $cp->ptCpId ?? 0;
+        $cp->delStatus = 1;
+        $cp->save();
+        if (isset($masterShop->default) && $masterShop->default == 1) {
+            $sjId = $masterShop->sjId ?? 0;
+            $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
+            if (!empty($shopList)) {
+                foreach ($shopList as $shop) {
+                    if ($shop->id == $masterShop->id) {
+                        continue;
+                    }
+                    $shopName = $shop->shopName ?? '';
+                    $chainMainId = $shop->mainId ?? 0;
+                    $has = self::getByCondition(['mainId' => $chainMainId, 'ptCpId' => $ptCpId, 'delStatus' => 0], true);
+                    if (empty($has)) {
+                        util::fail($shopName . '的产品没有找到');
+                    }
+                    $has->delStatus = 1;
+                    $has->save();
+                }
+            }
+        }
+    }
+
     public static function copyCp($oldMainId, $newMainId)
     {
         $oldCpClassList = CpClassClass::getAllByCondition(['mainId' => $oldMainId], null, '*');