|
|
@@ -79,9 +79,55 @@ class CpClass extends BaseClass
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
+ //更新产品 ssh 20240221
|
|
|
public static function updateCp($data, $cp, $masterShop)
|
|
|
{
|
|
|
-
|
|
|
+ $id = $cp->id ?? 0;
|
|
|
+ $ptCpId = $cp->ptCpId ?? 0;
|
|
|
+ $classId = $data['classId'] ?? 0;
|
|
|
+ $cpClass = CpClassClass::getById($classId, true);
|
|
|
+ if (empty($cpClass)) {
|
|
|
+ util::fail('没有找到分类');
|
|
|
+ }
|
|
|
+ if ($cpClass->mainId != $cp->mainId) {
|
|
|
+ util::fail('不是你的产品哦');
|
|
|
+ }
|
|
|
+ $cpClassName = $cpClass->name ?? '';
|
|
|
+ self::updateById($id, $data);
|
|
|
+ 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 ?? '';
|
|
|
+ $mainId = $shop->mainId ?? 0;
|
|
|
+ $chainCp = self::getByCondition(['mainId' => $mainId, 'ptCpId' => $ptCpId], true);
|
|
|
+ if (empty($chainCp)) {
|
|
|
+ util::fail($shopName . ' 的产品没有找到');
|
|
|
+ }
|
|
|
+ $chainCpId = $chainCp->id ?? 0;
|
|
|
+ $cpClassList = CpClassClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0], null, '*', null, true);
|
|
|
+ $cpClassId = 0;
|
|
|
+ if (!empty($cpClassList)) {
|
|
|
+ foreach ($cpClassList as $cpClass) {
|
|
|
+ $currentCpClassId = $cpClass->id ?? 0;
|
|
|
+ if ($cpClass->name == $cpClassName) {
|
|
|
+ $cpClassId = $currentCpClassId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (empty($cpClassId)) {
|
|
|
+ util::fail($shopName . '的分类 ' . $cpClassName . ' 没有找到');
|
|
|
+ }
|
|
|
+ $chainData = $data;
|
|
|
+ $chainData['classId'] = $cpClassId;
|
|
|
+ self::updateById($chainCpId, $chainData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//添加产品 ssh 20240221
|