|
|
@@ -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');
|