|
|
@@ -2,10 +2,15 @@
|
|
|
|
|
|
namespace bizGhs\cp\classes;
|
|
|
|
|
|
+use biz\cp\classes\PtCpItemClass;
|
|
|
+use biz\item\classes\PtItemClass;
|
|
|
use bizGhs\base\classes\BaseClass;
|
|
|
+use bizGhs\item\classes\ItemClassClass;
|
|
|
use bizGhs\product\classes\ProductClass;
|
|
|
use bizGhs\shop\classes\ShopClass;
|
|
|
use common\components\imgUtil;
|
|
|
+use common\components\noticeUtil;
|
|
|
+use common\components\stringUtil;
|
|
|
use common\components\util;
|
|
|
use Yii;
|
|
|
|
|
|
@@ -14,6 +19,97 @@ class CpClass extends BaseClass
|
|
|
|
|
|
public static $baseFile = '\bizGhs\cp\models\Cp';
|
|
|
|
|
|
+ //从平台导入产品 ssh 20240226
|
|
|
+ public static function importPtCp($ptCp, $currentShop)
|
|
|
+ {
|
|
|
+ $ptCpId = $ptCp->id ?? 0;
|
|
|
+ $mainId = $currentShop->mainId ?? 0;
|
|
|
+ $shopCp = CpClass::getByCondition(['ptCpId' => $ptCpId], true);
|
|
|
+ if (empty($shopCp)) {
|
|
|
+ $ptCpClassId = $ptCp->classId ?? 0;
|
|
|
+ $ptCpClass = PtCpClassClass::getById($ptCpClassId, true);
|
|
|
+ if (empty($ptCpClass)) {
|
|
|
+ util::fail('平台产品的分类没有找到');
|
|
|
+ }
|
|
|
+ $ptCpClassName = $ptCpClass->name ?? '';
|
|
|
+ $cpClassList = CpClassClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0], null, "*", null, true);
|
|
|
+ $defaultClassId = 0;
|
|
|
+ $currentClassId = 0;
|
|
|
+ if (!empty($cpClassList)) {
|
|
|
+ foreach ($cpClassList as $cpClass) {
|
|
|
+ if ($cpClass->isDefault == 1) {
|
|
|
+ $defaultClassId = $cpClass->id ?? 0;
|
|
|
+ }
|
|
|
+ if ($ptCpClassName == $cpClass->name) {
|
|
|
+ $currentClassId = $cpClass->id ?? 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (empty($defaultClassId) && empty($currentClassId)) {
|
|
|
+ util::fail('没有找到默认分类');
|
|
|
+ }
|
|
|
+ $currentClassId = !empty($currentClassId) ? $currentClassId : $defaultClassId;
|
|
|
+ $arr = $ptCp->attributes;
|
|
|
+ unset($arr['id']);
|
|
|
+ unset($arr['addTime']);
|
|
|
+ unset($arr['updateTime']);
|
|
|
+ unset($arr['classId']);
|
|
|
+ $arr['ptCpId'] = $ptCpId;
|
|
|
+ $arr['classId'] = $currentClassId;
|
|
|
+ $shopCp = self::addCp($arr, $currentShop);
|
|
|
+ }
|
|
|
+ if ($ptCp->auth == 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ $cpId = $shopCp->id ?? 0;
|
|
|
+ $ptCpItemList = PtCpItemClass::getAllByCondition(['cpId' => $ptCpId], null, '*', null, true);
|
|
|
+ foreach ($ptCpItemList as $ptCpItem) {
|
|
|
+ if ($ptCpItem->auth == 1) {
|
|
|
+ $ptItemId = $ptCpItem->itemId ?? 0;
|
|
|
+ $productInfo = ProductClass::getByCondition(['mainId' => $mainId, 'itemId' => $ptItemId], true);
|
|
|
+ if (empty($productInfo)) {
|
|
|
+ $ptItemInfo = PtItemClass::getById($ptItemId);
|
|
|
+ if (empty($ptItemInfo)) {
|
|
|
+ util::fail('平台花材没有找到哦');
|
|
|
+ }
|
|
|
+ $customDefaultClass = ItemClassClass::getByCondition(['mainId' => $mainId, 'isDefault' => 1], true);
|
|
|
+ if (empty($customDefaultClass)) {
|
|
|
+ noticeUtil::push("mainId:{$mainId} 导入平台产品和花材,没有找到花材默认分类", '15280215347');
|
|
|
+ util::fail('没有找到默认分类哈!');
|
|
|
+ }
|
|
|
+ $customDefaultClassId = $customDefaultClass->id ?? 0;
|
|
|
+ unset($ptItemInfo['id']);
|
|
|
+ $ptItemInfo['itemId'] = $ptItemId;
|
|
|
+ $ptItemInfo['hasCpId'] = 1;
|
|
|
+ $ptItemInfo['skPrice'] = 36;
|
|
|
+ $ptItemInfo['price'] = 36;
|
|
|
+ $ptItemInfo['hjPrice'] = 36;
|
|
|
+ $ptItemInfo['mainId'] = $mainId;
|
|
|
+ $ptItemInfo['py'] = stringUtil::py($ptItemInfo['name']);
|
|
|
+ $ptItemInfo['classId'] = $customDefaultClassId;
|
|
|
+ //有二个添加花材的地方,请搜索关键词add_item_place
|
|
|
+ $productInfo = ProductClass::add($ptItemInfo, true);
|
|
|
+ }
|
|
|
+ $shopItemId = $productInfo->id ?? 0;
|
|
|
+ $currentData = [
|
|
|
+ 'cpId' => $cpId,
|
|
|
+ 'ptCpId' => $ptCpId,
|
|
|
+ 'productId' => $shopItemId,
|
|
|
+ 'ptItemId' => $ptItemId,
|
|
|
+ 'name' => $productInfo->name ?? '',
|
|
|
+ 'py' => $productInfo->py ?? '',
|
|
|
+ 'cpName' => $shopCp->name ?? '',
|
|
|
+ 'cpPy' => $shopCp->py ?? '',
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'inTurn' => $ptCpItem->inTurn ?? 100,
|
|
|
+ 'auth' => $ptCpItem->auth ?? 0,
|
|
|
+ ];
|
|
|
+ CpItemClass::add($currentData,true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
//恢复产品 ssh 20240222
|
|
|
public static function recoverCp($cp, $masterShop)
|
|
|
{
|
|
|
@@ -205,35 +301,36 @@ class CpClass extends BaseClass
|
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
try {
|
|
|
-
|
|
|
- $ptData = $data;
|
|
|
- $ptCpClassId = 0;
|
|
|
- $ptCpClassDefaultId = 0;
|
|
|
- $ptCpClassList = PtCpClassClass::getAllByCondition(['delStatus' => 0], null, '*');
|
|
|
- if (!empty($ptCpClassList)) {
|
|
|
- foreach ($ptCpClassList as $ptCpClass) {
|
|
|
- $currentId = $ptCpClass['id'] ?? 0;
|
|
|
- if (isset($ptCpClass['name']) && $ptCpClass['name'] == $shopCpClassName) {
|
|
|
- $ptCpClassId = $currentId;
|
|
|
- }
|
|
|
- if (isset($ptCpClass['isDefault']) && $ptCpClass['isDefault'] == 1) {
|
|
|
- $ptCpClassDefaultId = $currentId;
|
|
|
+ if (isset($data['ptCpId']) == false || empty($data['ptCpId'])) {
|
|
|
+ $ptData = $data;
|
|
|
+ $ptCpClassId = 0;
|
|
|
+ $ptCpClassDefaultId = 0;
|
|
|
+ $ptCpClassList = PtCpClassClass::getAllByCondition(['delStatus' => 0], null, '*');
|
|
|
+ if (!empty($ptCpClassList)) {
|
|
|
+ foreach ($ptCpClassList as $ptCpClass) {
|
|
|
+ $currentId = $ptCpClass['id'] ?? 0;
|
|
|
+ if (isset($ptCpClass['name']) && $ptCpClass['name'] == $shopCpClassName) {
|
|
|
+ $ptCpClassId = $currentId;
|
|
|
+ }
|
|
|
+ if (isset($ptCpClass['isDefault']) && $ptCpClass['isDefault'] == 1) {
|
|
|
+ $ptCpClassDefaultId = $currentId;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ if (!empty($ptCpClassDefaultId)) {
|
|
|
+ $ptData['classId'] = $ptCpClassDefaultId;
|
|
|
+ }
|
|
|
+ if (!empty($ptCpClassId)) {
|
|
|
+ $ptData['classId'] = $ptCpClassId;
|
|
|
+ }
|
|
|
+ if (empty($ptCpClassDefaultId) && empty($ptCpClassId)) {
|
|
|
+ util::fail('没有找到平台的分类');
|
|
|
+ }
|
|
|
+ $respond = PtCpClass::addCp($ptData);
|
|
|
+ $ptCpId = $respond->id ?? 0;
|
|
|
+ $data['ptCpId'] = $ptCpId;
|
|
|
}
|
|
|
- if (!empty($ptCpClassDefaultId)) {
|
|
|
- $ptData['classId'] = $ptCpClassDefaultId;
|
|
|
- }
|
|
|
- if (!empty($ptCpClassId)) {
|
|
|
- $ptData['classId'] = $ptCpClassId;
|
|
|
- }
|
|
|
- if (empty($ptCpClassDefaultId) && empty($ptCpClassId)) {
|
|
|
- util::fail('没有找到平台的分类');
|
|
|
- }
|
|
|
- $respond = PtCpClass::addCp($ptData);
|
|
|
-
|
|
|
- $data['ptCpId'] = $respond->id ?? 0;
|
|
|
- self::add($data);
|
|
|
+ $result = self::add($data, true);
|
|
|
|
|
|
//在首店添加,则找到父级sj下的所有直营和加盟店,都进行同步
|
|
|
if (isset($currentShop->default) && $currentShop->default == 1) {
|
|
|
@@ -267,6 +364,7 @@ class CpClass extends BaseClass
|
|
|
}
|
|
|
}
|
|
|
$transaction->commit();
|
|
|
+ return $result;
|
|
|
} catch (\Exception $exception) {
|
|
|
$transaction->rollBack();
|
|
|
Yii::info('添加失败原因:' . $exception->getMessage());
|