shish 2 éve
szülő
commit
df6a97bf3b

+ 0 - 1
app-ghs/controllers/ShopController.php

@@ -191,7 +191,6 @@ class ShopController extends BaseController
             $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
             $adminId = $admin['id'] ?? 0;
             $data['adminId'] = $adminId;
-
             ShopClass::addMainShop($data, $this->shop, $this->sj);
             $transaction->commit();
             util::complete();

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

@@ -3,6 +3,7 @@
 namespace bizGhs\cp\classes;
 
 use bizGhs\base\classes\BaseClass;
+use bizGhs\product\classes\ProductClass;
 use bizGhs\shop\classes\ShopClass;
 use common\components\imgUtil;
 use common\components\util;
@@ -13,6 +14,53 @@ class CpClass extends BaseClass
 
     public static $baseFile = '\bizGhs\cp\models\Cp';
 
+    public static function copyCp($oldMainId, $newMainId)
+    {
+        $oldCpClassList = CpClassClass::getAllByCondition(['mainId' => $oldMainId], null, '*');
+        if (empty($oldCpClassList)) {
+            return false;
+        }
+        foreach ($oldCpClassList as $oldCpClass) {
+            unset($oldCpClass['addTime']);
+            unset($oldCpClass['updateTime']);
+            unset($oldCpClass['id']);
+            $oldCpClass['mainId'] = $newMainId;
+            $newCpClass = CpClassClass::add($oldCpClass, true);
+            $newCpClassId = $newCpClass->id ?? 0;
+            $oldCpList = self::getAllByCondition(['mainId' => $oldMainId], null, '*');
+            if (!empty($oldCpList)) {
+                foreach ($oldCpList as $oldCp) {
+                    $oldCpId = $oldCp['id'];
+                    unset($oldCp['addTime']);
+                    unset($oldCp['updateTime']);
+                    unset($oldCp['id']);
+                    $oldCp['mainId'] = $newMainId;
+                    $oldCp['status'] = 2;
+                    $oldCp['classId'] = $newCpClassId;
+                    $newCp = self::add($oldCp, true);
+                    $newCpId = $newCp->id ?? 0;
+                    $oldCpItemList = CpItemClass::getAllByCondition(['cpId' => $oldCpId], null, '*', 'ptItemId');
+                    if (!empty($oldCpItemList)) {
+                        $ptItemIds = array_keys($oldCpItemList);
+                        $newProductList = ProductClass::getAllByCondition(['mainId' => $newMainId, 'itemId' => ['in', $ptItemIds]], null, '*', 'itemId');
+                        foreach ($oldCpItemList as $ptItemId => $oldCpItem) {
+                            if (isset($newProductList[$ptItemId])) {
+                                $currentProduct = $newProductList[$ptItemId];
+                                $currentProductId = $currentProduct['id'] ?? 0;
+                                unset($oldCpItem['id']);
+                                unset($oldCpItem['addTime']);
+                                unset($oldCpItem['updateTime']);
+                                $oldCpItem['productId'] = $currentProductId;
+                                $oldCpItem['cpId'] = $newCpId;
+                                CpItemClass::add($oldCpItem, true);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
     public static function getCpList($where)
     {
         $data = self::getList('*', $where, 'addTime DESC');

+ 4 - 1
biz-ghs/merchant/classes/ShopClass.php

@@ -2,6 +2,7 @@
 
 namespace bizGhs\merchant\classes;
 
+use bizGhs\cp\classes\CpClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\shop\classes\MainClass;
 use bizGhs\shop\classes\ShopAdminClass;
@@ -51,9 +52,11 @@ class ShopClass extends BaseClass
         if (empty($oldMainId)) {
             util::fail('没有找到main信息');
         }
-        //创建main复制花材
+        //创建main复制花材
         $main = MainClass::addMainCopyItem($oldMainId);
         $mainId = $main->id ?? 0;
+        //复制产品
+        CpClass::copyCp($oldMainId, $mainId);
         $data['mainId'] = $mainId;
 
         $newGhsShop = \bizGhs\shop\classes\ShopClass::addShop($data);