shish 2 anni fa
parent
commit
8963ce1168
2 ha cambiato i file con 48 aggiunte e 0 eliminazioni
  1. 21 0
      app-ghs/controllers/CpController.php
  2. 27 0
      biz-ghs/cp/classes/CpClass.php

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

@@ -96,6 +96,27 @@ class CpController extends BaseController
         }
     }
 
+    public function actionRecoverCp()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $cp = CpClass::getById($id, true);
+        if (isset($cp->mainId) == false || $cp->mainId != $this->mainId) {
+            util::fail('无法查看');
+        }
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            CpClass::recoverCp($cp, $this->shop);
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("删除失败原因:" . $e->getMessage());
+            util::fail('删除失败');
+        }
+    }
+
     public function actionDelCp()
     {
         $get = Yii::$app->request->get();

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

@@ -14,6 +14,33 @@ class CpClass extends BaseClass
 
     public static $baseFile = '\bizGhs\cp\models\Cp';
 
+    //恢复产品 ssh 20240222
+    public static function recoverCp($cp, $masterShop)
+    {
+        $ptCpId = $cp->ptCpId ?? 0;
+        $cp->delStatus = 0;
+        $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 = 0;
+                    $has->save();
+                }
+            }
+        }
+    }
+
     //删除产品 ssh 20240221
     public static function delCp($cp, $masterShop)
     {